blob: 38eb8398ca03231efd6b1a8a8084af1a45237d92 [file] [log] [blame]
ChetanGaonker42d75812016-06-06 16:32:52 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
ChetanGaonker42d75812016-06-06 16:32:52 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonker42d75812016-06-06 16:32:52 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080016import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from scapy.all import *
21import time
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080022import copy
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080023from DHCP import DHCPTest
A R Karthick10fe00e2016-07-12 16:13:16 -070024from OltConfig import *
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080025from OnosCtrl import OnosCtrl
A R Karthick10fe00e2016-07-12 16:13:16 -070026from portmaps import g_subscriber_port_map
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080027log.setLevel('INFO')
28
29class dhcp_exchange(unittest.TestCase):
30
31 dhcp_server_config = {
32 "ip": "10.1.11.50",
33 "mac": "ca:fe:ca:fe:ca:fe",
34 "subnet": "255.255.252.0",
35 "broadcast": "10.1.11.255",
36 "router": "10.1.8.1",
37 "domain": "8.8.8.8",
38 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080039 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080040 "startip": "10.1.11.51",
41 "endip": "10.1.11.100"
42 }
ChetanGaonker42d75812016-06-06 16:32:52 -070043
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080044 app = 'org.onosproject.dhcp'
45
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070046 ip_count = 0
47 failure_count = 0
48 start_time = 0
49 diff = 0
50
51 transaction_count = 0
52 transactions = 0
53 running_time = 0
54 total_success = 0
55 total_failure = 0
56
A R Karthick10fe00e2016-07-12 16:13:16 -070057 @classmethod
58 def setUpClass(cls):
59 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070060 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick10fe00e2016-07-12 16:13:16 -070061 if not cls.port_map:
62 cls.port_map = g_subscriber_port_map
63 cls.iface = cls.port_map[1]
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070064
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080065 def setUp(self):
66 ''' Activate the dhcp app'''
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080067 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080068 self.onos_ctrl = OnosCtrl(self.app)
69 status, _ = self.onos_ctrl.activate()
70 assert_equal(status, True)
71 time.sleep(3)
72
73 def teardown(self):
74 '''Deactivate the dhcp app'''
75 self.onos_ctrl.deactivate()
76
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080077 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070078 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080079 if status is False:
80 log.info('JSON request returned status %d' %code)
81 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080082 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080083
84 def onos_dhcp_table_load(self, config = None):
85 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
86 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
87 if config:
88 for k in config.keys():
89 if dhcp_config.has_key(k):
90 dhcp_config[k] = config[k]
91 self.onos_load_config(dhcp_dict)
92
Chetan Gaonker6c68e912016-04-15 17:22:14 -070093 def send_recv(self, mac = None, update_seed = False, validate = True):
94 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
95 if validate:
96 assert_not_equal(cip, None)
97 assert_not_equal(sip, None)
98 log.info('Got dhcp client IP %s from server %s for mac %s' %
99 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800100 return cip,sip
101
A R Karthick10fe00e2016-07-12 16:13:16 -0700102 def stats(self,success_rate = False, only_discover = False):
ChetanGaonker42d75812016-06-06 16:32:52 -0700103
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700104 self.ip_count = 0
105 self.failure_count = 0
106 self.start_time = 0
107 self.diff = 0
108 self.transaction_count = 0
ChetanGaonker42d75812016-06-06 16:32:52 -0700109 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700110 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
111 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
112 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700113 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700114 self.start_time = time.time()
115
116 while self.diff <= 60:
ChetanGaonker42d75812016-06-06 16:32:52 -0700117 if only_discover:
118 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
119 log.info('Got dhcp client IP %s from server %s for mac %s' %
120 (cip, sip, mac))
121 else:
122 cip, sip = self.send_recv(update_seed = True, validate = False)
123
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700124 if cip:
125 self.ip_count +=1
126 elif cip == None:
127 self.failure_count += 1
128 log.info('Failed to get ip')
ChetanGaonker42d75812016-06-06 16:32:52 -0700129 if success_rate and self.ip_count > 0:
130 break
131 self.diff = round(time.time() - self.start_time, 0)
132
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700133
134 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
135
136 self.transactions += (self.ip_count+self.failure_count)
137 self.running_time += self.diff
138 self.total_success += self.ip_count
139 self.total_failure += self.failure_count
140
A R Karthick10fe00e2016-07-12 16:13:16 -0700141 def test_dhcp_1request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700142 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800143 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800144 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
145 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700146 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800147 self.send_recv()
148
A R Karthick10fe00e2016-07-12 16:13:16 -0700149 def test_dhcp_Nrequest(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700150 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800151 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
152 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
153 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700154 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800155 ip_map = {}
156 for i in range(10):
157 cip, sip = self.send_recv(update_seed = True)
158 if ip_map.has_key(cip):
159 log.info('IP %s given out multiple times' %cip)
160 assert_equal(False, ip_map.has_key(cip))
161 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800162
A R Karthick10fe00e2016-07-12 16:13:16 -0700163 def test_dhcp_1release(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700164 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800165 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
166 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800167 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700168 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800169 cip, sip = self.send_recv()
170 log.info('Releasing ip %s to server %s' %(cip, sip))
171 assert_equal(self.dhcp.release(cip), True)
172 log.info('Triggering DHCP discover again after release')
173 cip2, sip2 = self.send_recv(update_seed = True)
174 log.info('Verifying released IP was given back on rediscover')
175 assert_equal(cip, cip2)
176 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
177 assert_equal(self.dhcp.release(cip2), True)
178
A R Karthick10fe00e2016-07-12 16:13:16 -0700179 def test_dhcp_Nrelease(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700180 config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800181 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
182 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800183 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700184 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800185 ip_map = {}
186 for i in range(10):
187 cip, sip = self.send_recv(update_seed = True)
188 if ip_map.has_key(cip):
189 log.info('IP %s given out multiple times' %cip)
190 assert_equal(False, ip_map.has_key(cip))
191 ip_map[cip] = sip
192
193 for ip in ip_map.keys():
194 log.info('Releasing IP %s' %ip)
195 assert_equal(self.dhcp.release(ip), True)
196
197 ip_map2 = {}
198 log.info('Triggering DHCP discover again after release')
199 for i in range(len(ip_map.keys())):
200 cip, sip = self.send_recv(update_seed = True)
201 ip_map2[cip] = sip
202
203 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800204 if ip_map != ip_map2:
205 log.info('Map before release %s' %ip_map)
206 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800207 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700208
209
A R Karthick10fe00e2016-07-12 16:13:16 -0700210 def test_dhcp_starvation(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700211 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700212 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
213 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
214 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700215 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700216 ip_map = {}
217 for i in range(10):
218 cip, sip = self.send_recv(update_seed = True)
219 if ip_map.has_key(cip):
220 log.info('IP %s given out multiple times' %cip)
221 assert_equal(False, ip_map.has_key(cip))
222 ip_map[cip] = sip
223
224
A R Karthick10fe00e2016-07-12 16:13:16 -0700225 def test_dhcp_starvation(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700226 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700227 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
228 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
229 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700230 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700231 log.info('Verifying 1 ')
232 for x in xrange(50):
233 mac = RandMAC()._fix()
234 self.send_recv(mac = mac)
235 log.info('Verifying 2 ')
236 cip, sip = self.send_recv(update_seed = True, validate = False)
237 assert_equal(cip, None)
238 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700239
240
A R Karthick10fe00e2016-07-12 16:13:16 -0700241 def test_dhcp_same_client_multiple_discover(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700242 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700243 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
244 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
245 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700246 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700247 cip, sip, mac, _ = self.dhcp.only_discover()
248 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700249 (cip, sip, mac) )
250 log.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700251 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700252 if cip == new_cip:
253 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
254 % (new_cip, new_sip, new_mac) )
255 elif cip != new_cip:
256 log.info('Ip after 1st discover %s' %cip)
257 log.info('Map after 2nd discover %s' %new_cip)
258 assert_equal(cip, new_cip)
259
260
A R Karthick10fe00e2016-07-12 16:13:16 -0700261 def test_dhcp_same_client_multiple_request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700262 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700263 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
264 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
265 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700266 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700267 log.info('Sending DHCP discover and DHCP request.')
268 cip, sip = self.send_recv()
269 mac = self.dhcp.get_mac(cip)[0]
270 log.info("Sending DHCP request again.")
271 new_cip, new_sip = self.dhcp.only_request(cip, mac)
272 if (new_cip,new_sip) == (cip,sip):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700273 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
274 % (new_cip, new_sip, mac) )
275 elif (new_cip,new_sip):
ChetanGaonker42d75812016-06-06 16:32:52 -0700276 log.info('No DHCP ACK')
277 assert_equal(new_cip, None)
278 assert_equal(new_sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700279 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700280 log.info('Something went wrong.')
281
A R Karthick10fe00e2016-07-12 16:13:16 -0700282 def test_dhcp_client_desired_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700283 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700284 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
285 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
286 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700287 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700288 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
289 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700290 (cip, sip, mac) )
291 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700292 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700293 (cip, sip, mac) )
294 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700295 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700296 (cip, sip, mac) )
297 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
298 assert_equal(cip, self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700299
A R Karthick10fe00e2016-07-12 16:13:16 -0700300 def test_dhcp_client_desired_address_out_of_pool(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700301 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700302 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
303 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
304 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700305 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700306 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
307 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700308 (cip, sip, mac) )
309 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700310 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700311 (cip, sip, mac) )
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700312 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700313 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700314 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700315 (cip, sip, mac) )
316 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700317 assert_not_equal(cip, self.dhcp.seed_ip)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700318 elif cip == None:
319 log.info('Got DHCP NAK')
ChetanGaonker42d75812016-06-06 16:32:52 -0700320
321
A R Karthick10fe00e2016-07-12 16:13:16 -0700322 def test_dhcp_server_nak_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700323 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700324 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
325 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
326 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700327 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700328 cip, sip, mac, _ = self.dhcp.only_discover()
329 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700330 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700331
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700332 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
333 if (cip == None and mac != None):
334 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
335 assert_not_equal(cip, None)
336 else:
337 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
338 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700339
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700340 log.info("Got DHCP server NAK.")
341 assert_equal(new_cip, None) #Negative Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700342
343
A R Karthick10fe00e2016-07-12 16:13:16 -0700344 def test_dhcp_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700345 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700346 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
347 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
348 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700349 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700350 log.info('Sending DHCP discover with lease time of 700')
351 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
352
353 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
354 if (cip == None and mac != None):
355 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
356 assert_not_equal(cip, None)
357 elif lval != 700:
ChetanGaonker42d75812016-06-06 16:32:52 -0700358 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700359 (cip, sip, mac, lval) )
360 assert_not_equal(lval, 700)
361
A R Karthick10fe00e2016-07-12 16:13:16 -0700362 def test_dhcp_client_request_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700363 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700364 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
365 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
366 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700367 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700368 cip, sip, mac, _ = self.dhcp.only_discover()
369 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700370 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700371
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700372 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700373
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700374 if (cip == None and mac != None):
375 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
376 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700377
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700378 else:
379 new_cip, new_sip = self.dhcp.only_request(cip, mac)
380 if new_cip == None:
381 log.info("Got DHCP server NAK.")
A R Karthick10fe00e2016-07-12 16:13:16 -0700382 os.system('ifconfig '+self.iface+' down')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700383 log.info('Client goes down.')
384 log.info('Delay for 5 seconds.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700385
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700386 time.sleep(5)
ChetanGaonker42d75812016-06-06 16:32:52 -0700387
A R Karthick10fe00e2016-07-12 16:13:16 -0700388 os.system('ifconfig '+self.iface+' up')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700389 log.info('Client is up now.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700390
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700391 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700392 if new_cip == None:
393 log.info("Got DHCP server NAK.")
394 assert_not_equal(new_cip, None)
395 elif new_cip != None:
396 log.info("Got DHCP ACK.")
A R Karthick10fe00e2016-07-12 16:13:16 -0700397 os.system('ifconfig '+self.iface+' up')
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700398
ChetanGaonker42d75812016-06-06 16:32:52 -0700399
400
401
A R Karthick10fe00e2016-07-12 16:13:16 -0700402 def test_dhcp_server_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700403 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700404 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
405 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
406 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700407 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700408 cip, sip, mac, _ = self.dhcp.only_discover()
409 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700410 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700411
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700412 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700413
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700414 if (cip == None and mac != None):
415 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
416 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700417
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700418 else:
419 new_cip, new_sip = self.dhcp.only_request(cip, mac)
420 if new_cip == None:
421 log.info("Got DHCP server NAK.")
422 assert_not_equal(new_cip, None)
423 log.info('Getting DHCP server Down.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700424
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700425 self.onos_ctrl.deactivate()
ChetanGaonker42d75812016-06-06 16:32:52 -0700426
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700427 for i in range(0,4):
428 log.info("Sending DHCP Request.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700429 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700430 new_cip, new_sip = self.dhcp.only_request(cip, mac)
431 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700432 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700433 log.info("DHCP Request timed out.")
434 elif new_cip and new_sip:
435 log.info("Got Reply from DHCP server.")
436 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700437
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700438 log.info('Getting DHCP server Up.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700439
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700440 status, _ = self.onos_ctrl.activate()
441 assert_equal(status, True)
442 time.sleep(3)
ChetanGaonker42d75812016-06-06 16:32:52 -0700443
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700444 for i in range(0,4):
445 log.info("Sending DHCP Request after DHCP server is up.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700446 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700447 new_cip, new_sip = self.dhcp.only_request(cip, mac)
448 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700449 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700450 log.info("DHCP Request timed out.")
451 elif new_cip and new_sip:
452 log.info("Got Reply from DHCP server.")
453 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700454
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700455
A R Karthick10fe00e2016-07-12 16:13:16 -0700456 def test_dhcp_specific_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700457 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700458 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
459 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
460 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700461 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700462 log.info('Sending DHCP discover with lease time of 700')
ChetanGaonker42d75812016-06-06 16:32:52 -0700463 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
464 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700465 (cip, sip, mac) )
466
467 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
468 if (cip == None and mac != None):
469 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700470 assert_not_equal(cip, None)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700471 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700472
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700473 log.info("Triggering DHCP Request.")
474 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700475 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700476 (new_cip, new_sip, mac, lval) )
477 assert_not_equal(lval, 700) #Negative Test Case
478
479
ChetanGaonker42d75812016-06-06 16:32:52 -0700480
A R Karthick10fe00e2016-07-12 16:13:16 -0700481 def test_dhcp_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700482 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700483 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
484 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
485 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700486 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700487 cip, sip, mac, _ = self.dhcp.only_discover()
488 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700489 (cip, sip, mac) )
490
491 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
492 if (cip == None and mac != None):
493 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700494 assert_not_equal(cip, None)
495
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700496 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700497
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700498 log.info("Triggering DHCP Request.")
499 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
500 if lval == 600:
ChetanGaonker42d75812016-06-06 16:32:52 -0700501 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
502 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700503 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700504 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
505 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700506 log.info('The lease time suppossed to be 600 secs or 10 mins.')
507 assert_equal(lval, 600)
ChetanGaonker42d75812016-06-06 16:32:52 -0700508
A R Karthick10fe00e2016-07-12 16:13:16 -0700509 def test_dhcp_client_renew_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700510
511 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700512 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
513 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
514 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700515 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700516 cip, sip, mac, _ = self.dhcp.only_discover()
517 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700518 (cip, sip, mac) )
519
520 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
521 if (cip == None and mac != None):
522 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700523 assert_not_equal(cip, None)
524
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700525 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700526
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700527 log.info("Triggering DHCP Request.")
528 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700529
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700530 if new_cip and new_sip and lval:
531
532 log.info("Clinet 's Renewal time is :%s",lval)
533 log.info("Generating delay till renewal time.")
534 time.sleep(lval)
535
536 log.info("Client Sending Unicast DHCP request.")
537 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
538
539 if latest_cip and latest_sip:
540 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
541 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700542
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700543 elif latest_cip == None:
544 log.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700545
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700546 elif new_cip == None or new_sip == None or lval == None:
547
548 log.info("Got DHCP NAK.")
549
ChetanGaonker42d75812016-06-06 16:32:52 -0700550
551
A R Karthick10fe00e2016-07-12 16:13:16 -0700552 def test_dhcp_client_rebind_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700553
554 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700555 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
556 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
557 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700558 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700559 cip, sip, mac, _ = self.dhcp.only_discover()
560 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700561 (cip, sip, mac) )
562
563 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
564 if (cip == None and mac != None):
565 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700566 assert_not_equal(cip, None)
567
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700568 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700569
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700570 log.info("Triggering DHCP Request.")
571 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700572
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700573 if new_cip and new_sip and lval:
574
575 log.info("Clinet 's Rebind time is :%s",lval)
576 log.info("Generating delay till rebind time.")
577 time.sleep(lval)
578
579 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700580
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700581 for i in range(0,4):
582 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
583
584 if latest_cip and latest_sip:
585 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
586 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700587 break
588
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700589 elif latest_cip == None:
590 log.info("Got DHCP NAK. Lease not renewed.")
591 assert_not_equal(latest_cip, None)
592 elif new_cip == None or new_sip == None or lval == None:
593
594 log.info("Got DHCP NAK.Lease not Renewed.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700595
Chetan Gaonker717b2942016-05-13 17:42:59 -0700596
A R Karthick10fe00e2016-07-12 16:13:16 -0700597 def test_dhcp_client_expected_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700598
599 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -0700600 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
601 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
602 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700603 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700604 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700605 self.dhcp.return_option = 'subnet'
ChetanGaonker42d75812016-06-06 16:32:52 -0700606
Chetan Gaonker717b2942016-05-13 17:42:59 -0700607 cip, sip, mac, subnet_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700608 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700609 (cip, sip, mac) )
610
611 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
612 if (cip == None and mac != None):
613 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700614 assert_not_equal(cip, None)
615
Chetan Gaonker717b2942016-05-13 17:42:59 -0700616 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700617
Chetan Gaonker717b2942016-05-13 17:42:59 -0700618 if expected_subnet == subnet_value:
619 log.info("Got same subnet as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700620
Chetan Gaonker717b2942016-05-13 17:42:59 -0700621 elif expected_subnet != subnet_value:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700622 log.info("Not getting same subnet as passed in DHCP server configuration.")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700623 assert_equal(expected_subnet, subnet_value)
624
625
A R Karthick10fe00e2016-07-12 16:13:16 -0700626 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700627
628 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700629 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
630 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
631 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700632 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700633
634 cip, sip, mac, _ = self.dhcp.only_discover()
635 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700636 (cip, sip, mac) )
637
638 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
639 if (cip == None and mac != None):
640 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700641 assert_not_equal(cip, None)
642
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700643 elif cip and sip and mac:
644
645 self.dhcp.send_different_option = 'subnet'
646 log.info("Sending DHCP Request with wrong subnet mask.")
647 new_cip, new_sip = self.dhcp.only_request(cip, mac)
648 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700649
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700650 log.info("Got DHCP NAK.")
651 assert_not_equal(new_cip, None)
652
653 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700654
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700655 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
656 log.info("Getting subnet mask as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700657
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700658
A R Karthick10fe00e2016-07-12 16:13:16 -0700659 def test_dhcp_client_expected_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700660
661 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700662 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
663 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
664 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700665 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700666 expected_router_address = '20.20.20.1'
667 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700668
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700669 cip, sip, mac, router_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700670 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700671 (cip, sip, mac) )
672
673 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
674 if (cip == None and mac != None):
675 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700676 assert_not_equal(cip, None)
677
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700678 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700679
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700680 if expected_router_address == router_address_value:
681 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700682
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700683 elif expected_router_address != router_address_value:
684 log.info("Not getting same router address as passed in DHCP server configuration.")
685 assert_equal(expected_router_address, router_address_value)
686
687
A R Karthick10fe00e2016-07-12 16:13:16 -0700688 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700689
690 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700691 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
692 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
693 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700694 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700695
696 cip, sip, mac, _ = self.dhcp.only_discover()
697 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700698 (cip, sip, mac) )
699
700 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
701 if (cip == None and mac != None):
702 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700703 assert_not_equal(cip, None)
704
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700705 elif cip and sip and mac:
706
707 self.dhcp.send_different_option = 'router'
708 log.info("Sending DHCP Request with wrong router address.")
709 new_cip, new_sip = self.dhcp.only_request(cip, mac)
710 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700711
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700712 log.info("Got DHCP NAK.")
713 assert_not_equal(new_cip, None)
714
715 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700716
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700717 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
718 log.info("Getting Router Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700719
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700720
A R Karthick10fe00e2016-07-12 16:13:16 -0700721 def test_dhcp_client_expected_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700722
723 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700724 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
725 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
726 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700727 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700728 expected_broadcast_address = '20.20.20.255'
729 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700730
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700731 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700732 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700733 (cip, sip, mac) )
734
735 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
736 if (cip == None and mac != None):
737 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700738 assert_not_equal(cip, None)
739
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700740 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700741
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700742 if expected_broadcast_address == broadcast_address_value:
743 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700744
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700745 elif expected_broadcast_address != broadcast_address_value:
746 log.info("Not getting same router address as passed in DHCP server configuration.")
747 assert_equal(expected_broadcast_address, broadcast_address_value)
748
749
A R Karthick10fe00e2016-07-12 16:13:16 -0700750 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700751
752 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700753 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
754 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
755 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700756 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700757
758 cip, sip, mac, _ = self.dhcp.only_discover()
759 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700760 (cip, sip, mac) )
761
762 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
763 if (cip == None and mac != None):
764 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700765 assert_not_equal(cip, None)
766
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700767 elif cip and sip and mac:
768
769 self.dhcp.send_different_option = 'broadcast_address'
770 log.info("Sending DHCP Request with wrong broadcast address.")
771 new_cip, new_sip = self.dhcp.only_request(cip, mac)
772 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700773
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700774 log.info("Got DHCP NAK.")
775 assert_not_equal(new_cip, None)
776
777 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700778
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700779 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
780 log.info("Getting Broadcast Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700781
A R Karthick10fe00e2016-07-12 16:13:16 -0700782 def test_dhcp_client_expected_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700783
784 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700785 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
786 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
787 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700788 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700789 expected_dns_address = '8.8.8.8'
790 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700791
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700792 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700793 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700794 (cip, sip, mac) )
795
796 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
797 if (cip == None and mac != None):
798 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700799 assert_not_equal(cip, None)
800
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700801 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700802
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700803 if expected_dns_address == dns_address_value:
804 log.info("Got same DNS address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700805
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700806 elif expected_dns_address != dns_address_value:
807 log.info("Not getting same DNS address as passed in DHCP server configuration.")
808 assert_equal(expected_dns_address, dns_address_value)
809
810
A R Karthick10fe00e2016-07-12 16:13:16 -0700811 def test_dhcp_client_sends_request_with_wrong_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700812
813 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700814 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
815 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
816 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700817 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700818
819 cip, sip, mac, _ = self.dhcp.only_discover()
820 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700821 (cip, sip, mac) )
822
823 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
824 if (cip == None and mac != None):
825 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700826 assert_not_equal(cip, None)
827
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700828 elif cip and sip and mac:
829
830 self.dhcp.send_different_option = 'dns'
831 log.info("Sending DHCP Request with wrong DNS address.")
832 new_cip, new_sip = self.dhcp.only_request(cip, mac)
833 if new_cip == None:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700834 log.info("Got DHCP NAK.")
835 assert_not_equal(new_cip, None)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700836 elif new_cip and new_sip:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700837 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
838 log.info("Getting DNS Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700839
A R Karthick10fe00e2016-07-12 16:13:16 -0700840 def test_dhcp_server_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700841
842 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700843 self.stats()
ChetanGaonker42d75812016-06-06 16:32:52 -0700844 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700845 log.info("----------------------------------------------------------------------------------")
846 log.info("No. of transactions No. of successes No. of failures Running Time ")
847 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
848 log.info("----------------------------------------------------------------------------------")
849 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
850
ChetanGaonker42d75812016-06-06 16:32:52 -0700851 log.info("Final Statistics for total transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700852 log.info("----------------------------------------------------------------------------------")
853 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700854 log.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700855 self.total_success, self.total_failure, self.running_time))
856 log.info("----------------------------------------------------------------------------------")
857 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
858
A R Karthick10fe00e2016-07-12 16:13:16 -0700859 def test_dhcp_server_consecutive_successes_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700860
861 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700862 self.stats(success_rate = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700863 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700864 log.info("----------------------------------------------------------------------------------")
865 log.info("No. of consecutive successful transactions Running Time ")
866 log.info(" %d %d " %(self.ip_count, self.diff))
867 log.info("----------------------------------------------------------------------------------")
868 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker42d75812016-06-06 16:32:52 -0700869 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700870
ChetanGaonker42d75812016-06-06 16:32:52 -0700871 log.info("Final Statistics for total successful transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700872 log.info("----------------------------------------------------------------------------------")
873 log.info("Total transactions Total No. of consecutive successes Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700874 log.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700875 self.total_success, self.running_time))
876 log.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700877 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
878 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700879
ChetanGaonker42d75812016-06-06 16:32:52 -0700880
A R Karthick10fe00e2016-07-12 16:13:16 -0700881 def test_dhcp_server_client_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700882
883 for i in range(1,4):
884 self.stats(only_discover = True)
885 log.info("----------------------------------------------------------------------------------")
886 log.info("Stats for run %d of sending only DHCP Discover",i)
887 log.info("----------------------------------------------------------------------------------")
888 log.info("No. of transactions No. of successes No. of failures Running Time ")
889 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
890 log.info("----------------------------------------------------------------------------------")
891 log.info("No. of clients per second in run %d:%f "
892 %(i, self.transaction_count))
893 log.info("----------------------------------------------------------------------------------")
894 log.info("Final Statistics for total transactions of sending only DHCP Discover")
895 log.info("----------------------------------------------------------------------------------")
896 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
897 log.info(" %d %d %d %d" %(self.transactions,
898 self.total_success, self.total_failure, self.running_time))
899 log.info("----------------------------------------------------------------------------------")
900 log.info("Average no. of clients per second: %d ",
901 round(self.transactions/self.running_time,0))
902 log.info("----------------------------------------------------------------------------------")
903
A R Karthick10fe00e2016-07-12 16:13:16 -0700904 def test_dhcp_server_consecutive_successful_clients_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700905
906 for i in range(1,4):
907 self.stats(success_rate = True, only_discover = True)
908 log.info("----------------------------------------------------------------------------------")
909 log.info("Stats for run %d for sending only DHCP Discover",i)
910 log.info("----------------------------------------------------------------------------------")
911 log.info("No. of consecutive successful transactions Running Time ")
912 log.info(" %d %d " %(self.ip_count, self.diff))
913 log.info("----------------------------------------------------------------------------------")
914 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
915 log.info("----------------------------------------------------------------------------------")
916
917 log.info("Final Statistics for total successful transactions")
918 log.info("----------------------------------------------------------------------------------")
919 log.info("Total transactions Total No. of consecutive successes Running Time ")
920 log.info(" %d %d %d " %(self.transactions,
921 self.total_success, self.running_time))
922 log.info("----------------------------------------------------------------------------------")
923 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
924 log.info("----------------------------------------------------------------------------------")