blob: 935fe97d5c7c6804a3aec3cdb2a86edeb372b52e [file] [log] [blame]
Chetan Gaonkercfcce782016-05-10 10:10:42 -07001#
2# 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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# 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
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080024from OnosCtrl import OnosCtrl
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080025log.setLevel('INFO')
26
27class dhcp_exchange(unittest.TestCase):
28
29 dhcp_server_config = {
30 "ip": "10.1.11.50",
31 "mac": "ca:fe:ca:fe:ca:fe",
32 "subnet": "255.255.252.0",
33 "broadcast": "10.1.11.255",
34 "router": "10.1.8.1",
35 "domain": "8.8.8.8",
36 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080037 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080038 "startip": "10.1.11.51",
39 "endip": "10.1.11.100"
40 }
41
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080042 app = 'org.onosproject.dhcp'
43
44 def setUp(self):
45 ''' Activate the dhcp app'''
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080046 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080047 self.onos_ctrl = OnosCtrl(self.app)
48 status, _ = self.onos_ctrl.activate()
49 assert_equal(status, True)
50 time.sleep(3)
51
52 def teardown(self):
53 '''Deactivate the dhcp app'''
54 self.onos_ctrl.deactivate()
55
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080056 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070057 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080058 if status is False:
59 log.info('JSON request returned status %d' %code)
60 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080061 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080062
63 def onos_dhcp_table_load(self, config = None):
64 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
65 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
66 if config:
67 for k in config.keys():
68 if dhcp_config.has_key(k):
69 dhcp_config[k] = config[k]
70 self.onos_load_config(dhcp_dict)
71
Chetan Gaonker6c68e912016-04-15 17:22:14 -070072 def send_recv(self, mac = None, update_seed = False, validate = True):
73 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
74 if validate:
75 assert_not_equal(cip, None)
76 assert_not_equal(sip, None)
77 log.info('Got dhcp client IP %s from server %s for mac %s' %
78 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080079 return cip,sip
80
81 def test_dhcp_1request(self, iface = 'veth0'):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080082 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
83 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080084 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
85 self.onos_dhcp_table_load(config)
86 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
87 self.send_recv()
88
89 def test_dhcp_Nrequest(self, iface = 'veth0'):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080090 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080091 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
92 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
93 self.onos_dhcp_table_load(config)
94 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
95 ip_map = {}
96 for i in range(10):
97 cip, sip = self.send_recv(update_seed = True)
98 if ip_map.has_key(cip):
99 log.info('IP %s given out multiple times' %cip)
100 assert_equal(False, ip_map.has_key(cip))
101 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800102
103 def test_dhcp_1release(self, iface = 'veth0'):
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800104 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
105 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
106 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800107 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800108 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800109 cip, sip = self.send_recv()
110 log.info('Releasing ip %s to server %s' %(cip, sip))
111 assert_equal(self.dhcp.release(cip), True)
112 log.info('Triggering DHCP discover again after release')
113 cip2, sip2 = self.send_recv(update_seed = True)
114 log.info('Verifying released IP was given back on rediscover')
115 assert_equal(cip, cip2)
116 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
117 assert_equal(self.dhcp.release(cip2), True)
118
119 def test_dhcp_Nrelease(self, iface = 'veth0'):
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800120 config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
121 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
122 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800123 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800124 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800125 ip_map = {}
126 for i in range(10):
127 cip, sip = self.send_recv(update_seed = True)
128 if ip_map.has_key(cip):
129 log.info('IP %s given out multiple times' %cip)
130 assert_equal(False, ip_map.has_key(cip))
131 ip_map[cip] = sip
132
133 for ip in ip_map.keys():
134 log.info('Releasing IP %s' %ip)
135 assert_equal(self.dhcp.release(ip), True)
136
137 ip_map2 = {}
138 log.info('Triggering DHCP discover again after release')
139 for i in range(len(ip_map.keys())):
140 cip, sip = self.send_recv(update_seed = True)
141 ip_map2[cip] = sip
142
143 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800144 if ip_map != ip_map2:
145 log.info('Map before release %s' %ip_map)
146 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800147 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700148
149
150 def test_dhcp_starvation(self, iface = 'veth0'):
151 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
152 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
153 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
154 self.onos_dhcp_table_load(config)
155 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
156 ip_map = {}
157 for i in range(10):
158 cip, sip = self.send_recv(update_seed = True)
159 if ip_map.has_key(cip):
160 log.info('IP %s given out multiple times' %cip)
161 assert_equal(False, ip_map.has_key(cip))
162 ip_map[cip] = sip
163
164
165 def test_dhcp_starvation(self, iface = 'veth0'):
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700166 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
167 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
168 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
169 self.onos_dhcp_table_load(config)
170 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
171 log.info('Verifying 1 ')
172 for x in xrange(50):
173 mac = RandMAC()._fix()
174 self.send_recv(mac = mac)
175 log.info('Verifying 2 ')
176 cip, sip = self.send_recv(update_seed = True, validate = False)
177 assert_equal(cip, None)
178 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700179
180
181 def test_dhcp_same_client_multiple_discover(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700182 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
183 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
184 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
185 self.onos_dhcp_table_load(config)
186 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
187 cip, sip, mac = self.dhcp.only_discover()
188 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
189 (cip, sip, mac) )
190 log.info('Triggering DHCP discover again.')
191 new_cip, new_sip, new_mac = self.dhcp.only_discover()
192 if cip == new_cip:
193 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
194 % (new_cip, new_sip, new_mac) )
195 elif cip != new_cip:
196 log.info('Ip after 1st discover %s' %cip)
197 log.info('Map after 2nd discover %s' %new_cip)
198 assert_equal(cip, new_cip)
199
200
201 def test_dhcp_same_client_multiple_request(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700202 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
203 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
204 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
205 self.onos_dhcp_table_load(config)
206 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
207 log.info('Sending DHCP discover and DHCP request.')
208 cip, sip = self.send_recv()
209 mac = self.dhcp.get_mac(cip)[0]
210 log.info("Sending DHCP request again.")
211 new_cip, new_sip = self.dhcp.only_request(cip, mac)
212 if (new_cip,new_sip) == (cip,sip):
213
214 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
215 % (new_cip, new_sip, mac) )
216 elif (new_cip,new_sip):
217
218 log.info('No DHCP ACK')
219 assert_equal(new_cip, None)
220 assert_equal(new_sip, None)
221 else:
222 print "Something went wrong."
223
224 def test_dhcp_client_desired_address(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700225 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
226 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
227 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
228 self.onos_dhcp_table_load(config)
229 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface)
230 cip, sip, mac = self.dhcp.only_discover(desired = True)
231 log.info('Got dhcp client IP %s from server %s for mac %s .' %
232 (cip, sip, mac) )
233 if cip == self.dhcp.seed_ip:
234 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
235 (cip, sip, mac) )
236 elif cip != self.dhcp.seed_ip:
237 log.info('Got dhcp client IP %s from server %s for mac %s .' %
238 (cip, sip, mac) )
239 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
240 assert_equal(cip, self.dhcp.seed_ip)
241
242
243 def test_dhcp_client_desired_address_out_of_pool(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700244 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
245 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
246 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
247 self.onos_dhcp_table_load(config)
248 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
249 cip, sip, mac = self.dhcp.only_discover(desired = True)
250 log.info('Got dhcp client IP %s from server %s for mac %s .' %
251 (cip, sip, mac) )
252 if cip == self.dhcp.seed_ip:
253 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
254 (cip, sip, mac) )
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700255 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
256
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700257 elif cip != self.dhcp.seed_ip:
258 log.info('Got dhcp client IP %s from server %s for mac %s .' %
259 (cip, sip, mac) )
260 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700261 assert_not_equal(cip, self.dhcp.seed_ip)
262
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700263 elif cip == None:
264 log.info('Got DHCP NAK')
265
266
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700267 def test_dhcp_server_nak_packet(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700268 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
269 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
270 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
271 self.onos_dhcp_table_load(config)
272 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
273 cip, sip, mac = self.dhcp.only_discover()
274 log.info('Got dhcp client IP %s from server %s for mac %s .' %
275 (cip, sip, mac) )
276
277 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
278 if (cip == None and mac != None):
279 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
280 assert_not_equal(cip, None)
281 else:
282 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
283 if new_cip == None:
284
285 log.info("Got DHCP server NAK.")
286 assert_equal(new_cip, None) #Negative Test Case
287
288
289 def test_dhcp_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700290 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
291 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
292 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
293 self.onos_dhcp_table_load(config)
294 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
295 log.info('Sending DHCP discover with lease time of 700')
296 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
297
298 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
299 if (cip == None and mac != None):
300 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
301 assert_not_equal(cip, None)
302 elif lval != 700:
303 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
304 (cip, sip, mac, lval) )
305 assert_not_equal(lval, 700)
306
307 def test_dhcp_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700308
309 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
310 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
311 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
312 self.onos_dhcp_table_load(config)
313 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
314 cip, sip, mac = self.dhcp.only_discover()
315 log.info('Got dhcp client IP %s from server %s for mac %s .' %
316 (cip, sip, mac) )
317
318 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
319
320 if (cip == None and mac != None):
321 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
322 assert_not_equal(cip, None)
323
324 else:
325 new_cip, new_sip = self.dhcp.only_request(cip, mac)
326 if new_cip == None:
327 log.info("Got DHCP server NAK.")
328 os.system('ifconfig '+iface+' down')
329 log.info('Client goes down.')
330 log.info('Delay for 5 seconds.')
331
332 time.sleep(5)
333
334 os.system('ifconfig '+iface+' up')
335 log.info('Client is up now.')
336
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700337 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700338 if new_cip == None:
339 log.info("Got DHCP server NAK.")
340 assert_not_equal(new_cip, None)
341 elif new_cip != None:
342 log.info("Got DHCP ACK.")
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700343 os.system('ifconfig '+iface+' up')
344
345
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700346
347
348 def test_dhcp_server_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700349 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
350 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
351 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
352 self.onos_dhcp_table_load(config)
353 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
354 cip, sip, mac = self.dhcp.only_discover()
355 log.info('Got dhcp client IP %s from server %s for mac %s .' %
356 (cip, sip, mac) )
357
358 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
359
360 if (cip == None and mac != None):
361 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
362 assert_not_equal(cip, None)
363
364 else:
365 new_cip, new_sip = self.dhcp.only_request(cip, mac)
366 if new_cip == None:
367 log.info("Got DHCP server NAK.")
368 assert_not_equal(new_cip, None)
369 log.info('Getting DHCP server Down.')
370
371 self.onos_ctrl.deactivate()
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700372
373 for i in range(0,4):
374 log.info("Sending DHCP Request.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700375 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700376 new_cip, new_sip = self.dhcp.only_request(cip, mac)
377 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700378 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700379 log.info("DHCP Request timed out.")
380 elif new_cip and new_sip:
381 log.info("Got Reply from DHCP server.")
382 assert_equal(new_cip,None) #Neagtive Test Case
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700383
384 log.info('Getting DHCP server Up.')
385
386 status, _ = self.onos_ctrl.activate()
387 assert_equal(status, True)
388 time.sleep(3)
389
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700390 for i in range(0,4):
391 log.info("Sending DHCP Request after DHCP server is up.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700392 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700393 new_cip, new_sip = self.dhcp.only_request(cip, mac)
394 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700395 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700396 log.info("DHCP Request timed out.")
397 elif new_cip and new_sip:
398 log.info("Got Reply from DHCP server.")
399 assert_equal(new_cip,None) #Neagtive Test Case
400
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700401
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700402 def test_dhcp_specific_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700403 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
404 '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)
407 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
408 log.info('Sending DHCP discover with lease time of 700')
409 cip, sip, mac = self.dhcp.only_discover(lease_time = True)
410 log.info('Got dhcp client IP %s from server %s for mac %s .' %
411 (cip, sip, mac) )
412
413 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
414 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)
417 elif cip and sip and mac:
418
419 log.info("Triggering DHCP Request.")
420 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
421 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
422 (new_cip, new_sip, mac, lval) )
423 assert_not_equal(lval, 700) #Negative Test Case
424
425
426
427 def test_dhcp_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700428 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
429 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
430 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
431 self.onos_dhcp_table_load(config)
432 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
433 cip, sip, mac = self.dhcp.only_discover()
434 log.info('Got dhcp client IP %s from server %s for mac %s .' %
435 (cip, sip, mac) )
436
437 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
438 if (cip == None and mac != None):
439 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
440 assert_not_equal(cip, None)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700441
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700442 elif cip and sip and mac:
443
444 log.info("Triggering DHCP Request.")
445 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
446 if lval == 600:
447 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
448 (new_cip, new_sip, mac, lval) )
449 else:
450 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
451 (new_cip, new_sip, mac, lval) )
452 log.info('The lease time suppossed to be 600 secs or 10 mins.')
453 assert_equal(lval, 600)
454
455 def test_dhcp_client_renew_time(self, iface = 'veth0'):
456
457 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
458 '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)
461 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
462 cip, sip, mac = self.dhcp.only_discover()
463 log.info('Got dhcp client IP %s from server %s for mac %s .' %
464 (cip, sip, mac) )
465
466 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
467 if (cip == None and mac != None):
468 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
469 assert_not_equal(cip, None)
470
471 elif cip and sip and mac:
472
473 log.info("Triggering DHCP Request.")
474 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
475
476 if new_cip and new_sip and lval:
477
478 log.info("Clinet 's Renewal time is :%s",lval)
479 log.info("Generating delay till renewal time.")
480 time.sleep(lval)
481
482 log.info("Client Sending Unicast DHCP request.")
483 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
484
485 if latest_cip and latest_sip:
486 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
487 (latest_cip, mac, latest_sip) )
488
489 elif latest_cip == None:
490 log.info("Got DHCP NAK. Lease not renewed.")
491
492 elif new_cip == None or new_sip == None or lval == None:
493
494 log.info("Got DHCP NAK.")
495
496
497
498 def test_dhcp_client_rebind_time(self, iface = 'veth0'):
499
500 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
501 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
502 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
503 self.onos_dhcp_table_load(config)
504 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
505 cip, sip, mac = self.dhcp.only_discover()
506 log.info('Got dhcp client IP %s from server %s for mac %s .' %
507 (cip, sip, mac) )
508
509 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
510 if (cip == None and mac != None):
511 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
512 assert_not_equal(cip, None)
513
514 elif cip and sip and mac:
515
516 log.info("Triggering DHCP Request.")
517 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
518
519 if new_cip and new_sip and lval:
520
521 log.info("Clinet 's Rebind time is :%s",lval)
522 log.info("Generating delay till rebind time.")
523 time.sleep(lval)
524
525 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
526
527 for i in range(0,4):
528 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
529
530 if latest_cip and latest_sip:
531 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
532 (latest_cip, mac, latest_sip) )
533
534 elif latest_cip == None:
535 log.info("Got DHCP NAK. Lease not renewed.")
536 assert_not_equal(latest_cip, None)
537 elif new_cip == None or new_sip == None or lval == None:
538
539 log.info("Got DHCP NAK.Lease not Renewed.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700540
Chetan Gaonker717b2942016-05-13 17:42:59 -0700541
542 def test_dhcp_client_expected_subnet_mask(self, iface = 'veth0'):
543
544 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
545 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
546 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
547 self.onos_dhcp_table_load(config)
548 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
549 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700550 self.dhcp.return_option = 'subnet'
Chetan Gaonker717b2942016-05-13 17:42:59 -0700551
552 cip, sip, mac, subnet_value = self.dhcp.only_discover()
553 log.info('Got dhcp client IP %s from server %s for mac %s .' %
554 (cip, sip, mac) )
555
556 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
557 if (cip == None and mac != None):
558 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
559 assert_not_equal(cip, None)
560
561 elif cip and sip and mac:
562
563 if expected_subnet == subnet_value:
564 log.info("Got same subnet as passed in DHCP server configuration.")
565
566 elif expected_subnet != subnet_value:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700567 log.info("Not getting same subnet as passed in DHCP server configuration.")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700568 assert_equal(expected_subnet, subnet_value)
569
570
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700571 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
572
573 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
574 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
575 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
576 self.onos_dhcp_table_load(config)
577 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
578
579 cip, sip, mac = self.dhcp.only_discover()
580 log.info('Got dhcp client IP %s from server %s for mac %s .' %
581 (cip, sip, mac) )
582
583 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
584 if (cip == None and mac != None):
585 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
586 assert_not_equal(cip, None)
587
588 elif cip and sip and mac:
589
590 self.dhcp.send_different_option = 'subnet'
591 log.info("Sending DHCP Request with wrong subnet mask.")
592 new_cip, new_sip = self.dhcp.only_request(cip, mac)
593 if new_cip == None:
594
595 log.info("Got DHCP NAK.")
596 assert_not_equal(new_cip, None)
597
598 elif new_cip and new_sip:
599
600 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
601 log.info("Getting subnet mask as per server 's configuration.")
602
603
604 def test_dhcp_client_expected_router_address(self, iface = 'veth0'):
605
606 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
607 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
608 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
609 self.onos_dhcp_table_load(config)
610 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
611 expected_router_address = '20.20.20.1'
612 self.dhcp.return_option = 'router'
613
614 cip, sip, mac, router_address_value = self.dhcp.only_discover()
615 log.info('Got dhcp client IP %s from server %s for mac %s .' %
616 (cip, sip, mac) )
617
618 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
619 if (cip == None and mac != None):
620 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
621 assert_not_equal(cip, None)
622
623 elif cip and sip and mac:
624
625 if expected_router_address == router_address_value:
626 log.info("Got same router address as passed in DHCP server configuration.")
627
628 elif expected_router_address != router_address_value:
629 log.info("Not getting same router address as passed in DHCP server configuration.")
630 assert_equal(expected_router_address, router_address_value)
631
632
633 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
634
635 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
636 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
637 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
638 self.onos_dhcp_table_load(config)
639 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
640
641 cip, sip, mac = self.dhcp.only_discover()
642 log.info('Got dhcp client IP %s from server %s for mac %s .' %
643 (cip, sip, mac) )
644
645 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
646 if (cip == None and mac != None):
647 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
648 assert_not_equal(cip, None)
649
650 elif cip and sip and mac:
651
652 self.dhcp.send_different_option = 'router'
653 log.info("Sending DHCP Request with wrong router address.")
654 new_cip, new_sip = self.dhcp.only_request(cip, mac)
655 if new_cip == None:
656
657 log.info("Got DHCP NAK.")
658 assert_not_equal(new_cip, None)
659
660 elif new_cip and new_sip:
661
662 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
663 log.info("Getting Router Address as per server 's configuration.")
664
665
666 def test_dhcp_client_expected_broadcast_address(self, iface = 'veth0'):
667
668 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
669 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
670 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
671 self.onos_dhcp_table_load(config)
672 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
673 expected_broadcast_address = '20.20.20.255'
674 self.dhcp.return_option = 'broadcast_address'
675
676 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
677 log.info('Got dhcp client IP %s from server %s for mac %s .' %
678 (cip, sip, mac) )
679
680 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
681 if (cip == None and mac != None):
682 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
683 assert_not_equal(cip, None)
684
685 elif cip and sip and mac:
686
687 if expected_broadcast_address == broadcast_address_value:
688 log.info("Got same router address as passed in DHCP server configuration.")
689
690 elif expected_broadcast_address != broadcast_address_value:
691 log.info("Not getting same router address as passed in DHCP server configuration.")
692 assert_equal(expected_broadcast_address, broadcast_address_value)
693
694
695 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
696
697 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
698 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
699 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
700 self.onos_dhcp_table_load(config)
701 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
702
703 cip, sip, mac = self.dhcp.only_discover()
704 log.info('Got dhcp client IP %s from server %s for mac %s .' %
705 (cip, sip, mac) )
706
707 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
708 if (cip == None and mac != None):
709 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
710 assert_not_equal(cip, None)
711
712 elif cip and sip and mac:
713
714 self.dhcp.send_different_option = 'broadcast_address'
715 log.info("Sending DHCP Request with wrong broadcast address.")
716 new_cip, new_sip = self.dhcp.only_request(cip, mac)
717 if new_cip == None:
718
719 log.info("Got DHCP NAK.")
720 assert_not_equal(new_cip, None)
721
722 elif new_cip and new_sip:
723
724 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
725 log.info("Getting Broadcast Address as per server 's configuration.")
726
727 def test_dhcp_client_expected_dns_address(self, iface = 'veth0'):
728
729 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
730 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
731 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
732 self.onos_dhcp_table_load(config)
733 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
734 expected_dns_address = '8.8.8.8'
735 self.dhcp.return_option = 'dns'
736
737 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
738 log.info('Got dhcp client IP %s from server %s for mac %s .' %
739 (cip, sip, mac) )
740
741 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
742 if (cip == None and mac != None):
743 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
744 assert_not_equal(cip, None)
745
746 elif cip and sip and mac:
747
748 if expected_dns_address == dns_address_value:
749 log.info("Got same DNS address as passed in DHCP server configuration.")
750
751 elif expected_dns_address != dns_address_value:
752 log.info("Not getting same DNS address as passed in DHCP server configuration.")
753 assert_equal(expected_dns_address, dns_address_value)
754
755
756 def test_dhcp_client_sends_dhcp_request_with_wrong_dns_address(self, iface = 'veth0'):
757
758 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
759 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
760 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
761 self.onos_dhcp_table_load(config)
762 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
763
764 cip, sip, mac = self.dhcp.only_discover()
765 log.info('Got dhcp client IP %s from server %s for mac %s .' %
766 (cip, sip, mac) )
767
768 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
769 if (cip == None and mac != None):
770 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
771 assert_not_equal(cip, None)
772
773 elif cip and sip and mac:
774
775 self.dhcp.send_different_option = 'dns'
776 log.info("Sending DHCP Request with wrong DNS address.")
777 new_cip, new_sip = self.dhcp.only_request(cip, mac)
778 if new_cip == None:
779
780 log.info("Got DHCP NAK.")
781 assert_not_equal(new_cip, None)
782
783 elif new_cip and new_sip:
784
785 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
786 log.info("Getting DNS Address as per server 's configuration.")
787
Chetan Gaonker717b2942016-05-13 17:42:59 -0700788