blob: 3b95586165f50b750619130514eb79170e6ee5e6 [file] [log] [blame]
A R Karthick8cf29ac2016-06-30 16:25:14 -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#
16import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from scapy.all import *
21import time
ChetanGaonker5b984cb2016-07-12 15:50:49 -070022import os, sys
A R Karthick8cf29ac2016-06-30 16:25:14 -070023from DHCP import DHCPTest
24from OnosCtrl import OnosCtrl
25from OnosFlowCtrl import get_mac
26from portmaps import g_subscriber_port_map
ChetanGaonker5b984cb2016-07-12 15:50:49 -070027import threading, random
28from threading import current_thread
A R Karthick8cf29ac2016-06-30 16:25:14 -070029log.setLevel('INFO')
30
31class dhcprelay_exchange(unittest.TestCase):
32
33 app = 'org.onosproject.dhcprelay'
34 app_dhcp = 'org.onosproject.dhcp'
35 relay_device_id = 'of:' + get_mac('ovsbr0')
36 relay_interface_port = 100
37 relay_interfaces = (g_subscriber_port_map[relay_interface_port],)
38 interface_to_mac_map = {}
39 dhcp_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'setup')
40 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
41 default_options = [ ('subnet-mask', '255.255.255.0'),
42 ('broadcast-address', '192.168.1.255'),
43 ('domain-name-servers', '192.168.1.1'),
44 ('domain-name', '"mydomain.cord-tester"'),
45 ]
46 ##specify the IP for the dhcp interface matching the subnet and subnet config
47 ##this is done for each interface dhcpd server would be listening on
48 default_subnet_config = [ ('192.168.1.2',
49'''
50subnet 192.168.1.0 netmask 255.255.255.0 {
51 range 192.168.1.10 192.168.1.100;
52}
53'''), ]
ChetanGaonker5b984cb2016-07-12 15:50:49 -070054
55 lock = threading.Condition()
ChetanGaonker5860c182016-07-05 16:33:06 -070056 ip_count = 0
57 failure_count = 0
58 start_time = 0
59 diff = 0
60
61 transaction_count = 0
62 transactions = 0
63 running_time = 0
64 total_success = 0
65 total_failure = 0
66
A R Karthick8cf29ac2016-06-30 16:25:14 -070067
68 @classmethod
69 def setUpClass(cls):
70 ''' Activate the dhcprelay app'''
71 OnosCtrl(cls.app_dhcp).deactivate()
72 time.sleep(3)
73 cls.onos_ctrl = OnosCtrl(cls.app)
74 status, _ = cls.onos_ctrl.activate()
75 assert_equal(status, True)
76 time.sleep(3)
77 ##start dhcpd initially with default config
78 cls.dhcpd_start()
79 cls.onos_dhcp_relay_load()
80
81 @classmethod
82 def tearDownClass(cls):
83 '''Deactivate the dhcp relay app'''
84 try:
85 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
86 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
87 except: pass
88 cls.onos_ctrl.deactivate()
89 cls.dhcpd_stop()
90
91 @classmethod
92 def onos_load_config(cls, config):
93 status, code = OnosCtrl.config(config)
94 if status is False:
95 log.info('JSON request returned status %d' %code)
96 assert_equal(status, True)
97 time.sleep(3)
98
99 @classmethod
100 def onos_dhcp_relay_load(cls):
101 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
102 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
103 {'dhcpserverConnectPoint':relay_device_map}}}}
104 cls.onos_load_config(dhcp_dict)
105
106 @classmethod
107 def host_load(cls, iface):
108 '''Have ONOS discover the hosts for dhcp-relay responses'''
109 port = g_subscriber_port_map[iface]
110 host = '173.17.1.{}'.format(port)
111 cmds = ( 'ifconfig {} 0'.format(iface),
112 'ifconfig {0} {1}'.format(iface, host),
113 'arping -I {0} {1} -c 2'.format(iface, host),
114 'ifconfig {} 0'.format(iface), )
115 for c in cmds:
116 os.system(c)
117
118 @classmethod
119 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
120 subnet = default_subnet_config):
121 conf = ''
122 for k, v in config.items():
123 conf += '{} {};\n'.format(k, v)
124
125 opts = ''
126 for k, v in options:
127 opts += 'option {} {};\n'.format(k, v)
128
129 subnet_config = ''
130 for _, v in subnet:
131 subnet_config += '{}\n'.format(v)
132
133 return '{}{}{}'.format(conf, opts, subnet_config)
134
135 @classmethod
136 def dhcpd_start(cls, intf_list = relay_interfaces,
137 config = default_config, options = default_options,
138 subnet = default_subnet_config):
139 '''Start the dhcpd server by generating the conf file'''
140 ##stop dhcpd if already running
141 cls.dhcpd_stop()
142 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
143 subnet = subnet)
144 ##first touch dhcpd.leases if it doesn't exist
145 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
146 if os.access(lease_file, os.F_OK) is False:
147 with open(lease_file, 'w') as fd: pass
148
149 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
150 with open(conf_file, 'w') as fd:
151 fd.write(dhcp_conf)
152
153 #now configure the dhcpd interfaces for various subnets
154 index = 0
155 for ip,_ in subnet:
156 intf = intf_list[index]
157 index += 1
158 os.system('ifconfig {} {}'.format(intf, ip))
159
160 intf_str = ','.join(intf_list)
161 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str)
162 log.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
163 ret = os.system(dhcpd_cmd)
164 assert_equal(ret, 0)
165 time.sleep(3)
166 cls.relay_interfaces = intf_list
167
168 @classmethod
169 def dhcpd_stop(cls):
170 os.system('pkill -9 dhcpd')
171 for intf in cls.relay_interfaces:
172 os.system('ifconfig {} 0'.format(intf))
173
174 def get_mac(self, iface):
175 if self.interface_to_mac_map.has_key(iface):
176 return self.interface_to_mac_map[iface]
177 mac = get_mac(iface, pad = 0)
178 self.interface_to_mac_map[iface] = mac
179 return mac
180
ChetanGaonker5860c182016-07-05 16:33:06 -0700181 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
182
183 self.ip_count = 0
184 self.failure_count = 0
185 self.start_time = 0
186 self.diff = 0
187 self.transaction_count = 0
188
189 mac = self.get_mac(iface)
190 self.host_load(iface)
191 ##we use the defaults for this test that serves as an example for others
192 ##You don't need to restart dhcpd server if retaining default config
193 config = self.default_config
194 options = self.default_options
195 subnet = self.default_subnet_config
196 dhcpd_interface_list = self.relay_interfaces
197 self.dhcpd_start(intf_list = dhcpd_interface_list,
198 config = config,
199 options = options,
200 subnet = subnet)
201 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
202 self.start_time = time.time()
203
204 while self.diff <= 60:
205
206 if only_discover:
207 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
208 log.info('Got dhcp client IP %s from server %s for mac %s' %
209 (cip, sip, mac))
210 else:
211 cip, sip = self.send_recv(mac, update_seed = True, validate = False)
212
213 if cip:
214 self.ip_count +=1
215 elif cip == None:
216 self.failure_count += 1
217 log.info('Failed to get ip')
218 if success_rate and self.ip_count > 0:
219 break
220
221 self.diff = round(time.time() - self.start_time, 0)
222
ChetanGaonker5860c182016-07-05 16:33:06 -0700223 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
224 self.transactions += (self.ip_count+self.failure_count)
225 self.running_time += self.diff
226 self.total_success += self.ip_count
227 self.total_failure += self.failure_count
228
229
230
A R Karthick8cf29ac2016-06-30 16:25:14 -0700231 def send_recv(self, mac, update_seed = False, validate = True):
232 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
233 if validate:
234 assert_not_equal(cip, None)
235 assert_not_equal(sip, None)
ChetanGaonker5860c182016-07-05 16:33:06 -0700236 log.info('Got dhcp client IP %s from server %s for mac %s' %
237 (cip, sip, self.dhcp.get_mac(cip)[0]))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700238 return cip,sip
239
ChetanGaonker5860c182016-07-05 16:33:06 -0700240 def test_dhcpRelay_1request(self, iface = 'veth0'):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700241 mac = self.get_mac(iface)
242 self.host_load(iface)
243 ##we use the defaults for this test that serves as an example for others
244 ##You don't need to restart dhcpd server if retaining default config
245 config = self.default_config
246 options = self.default_options
247 subnet = self.default_subnet_config
248 dhcpd_interface_list = self.relay_interfaces
249 self.dhcpd_start(intf_list = dhcpd_interface_list,
250 config = config,
251 options = options,
252 subnet = subnet)
253 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
254 self.send_recv(mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700255
256 def test_dhcpRelay_Nrequest(self, iface = 'veth0'):
257 mac = self.get_mac(iface)
258 self.host_load(iface)
259 ##we use the defaults for this test that serves as an example for others
260 ##You don't need to restart dhcpd server if retaining default config
261 config = self.default_config
262 options = self.default_options
263 subnet = self.default_subnet_config
264 dhcpd_interface_list = self.relay_interfaces
265 self.dhcpd_start(intf_list = dhcpd_interface_list,
266 config = config,
267 options = options,
268 subnet = subnet)
269 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
270 ip_map = {}
271 for i in range(10):
272 cip, sip = self.send_recv(mac, update_seed = True)
273 if ip_map.has_key(cip):
274 log.info('IP %s given out multiple times' %cip)
275 assert_equal(False, ip_map.has_key(cip))
276 ip_map[cip] = sip
277
278 def test_dhcpRelay_1release(self, iface = 'veth0'):
279 mac = self.get_mac(iface)
280 self.host_load(iface)
281 ##we use the defaults for this test that serves as an example for others
282 ##You don't need to restart dhcpd server if retaining default config
283 config = self.default_config
284 options = self.default_options
285 subnet = self.default_subnet_config
286 dhcpd_interface_list = self.relay_interfaces
287 self.dhcpd_start(intf_list = dhcpd_interface_list,
288 config = config,
289 options = options,
290 subnet = subnet)
291 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
292 cip, sip = self.send_recv(mac)
293 log.info('Releasing ip %s to server %s' %(cip, sip))
294 assert_equal(self.dhcp.release(cip), True)
295 log.info('Triggering DHCP discover again after release')
296 cip2, sip2 = self.send_recv(mac)
297 log.info('Verifying released IP was given back on rediscover')
298 assert_equal(cip, cip2)
299 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
300 assert_equal(self.dhcp.release(cip2), True)
301
302 def test_dhcpRelay_Nrelease(self, iface = 'veth0'):
303 mac = self.get_mac(iface)
304 self.host_load(iface)
305 ##we use the defaults for this test that serves as an example for others
306 ##You don't need to restart dhcpd server if retaining default config
307 config = self.default_config
308 options = self.default_options
309 subnet = self.default_subnet_config
310 dhcpd_interface_list = self.relay_interfaces
311 self.dhcpd_start(intf_list = dhcpd_interface_list,
312 config = config,
313 options = options,
314 subnet = subnet)
315 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
316 ip_map = {}
317 for i in range(10):
318 cip, sip = self.send_recv(mac, update_seed = True)
319 if ip_map.has_key(cip):
320 log.info('IP %s given out multiple times' %cip)
321 assert_equal(False, ip_map.has_key(cip))
322 ip_map[cip] = sip
323
324 for ip in ip_map.keys():
325 log.info('Releasing IP %s' %ip)
326 assert_equal(self.dhcp.release(ip), True)
327
328 ip_map2 = {}
329 log.info('Triggering DHCP discover again after release')
330 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
331 for i in range(len(ip_map.keys())):
332 cip, sip = self.send_recv(mac, update_seed = True)
333 ip_map2[cip] = sip
334
335 log.info('Verifying released IPs were given back on rediscover')
336 if ip_map != ip_map2:
337 log.info('Map before release %s' %ip_map)
338 log.info('Map after release %s' %ip_map2)
339 assert_equal(ip_map, ip_map2)
340
341 def test_dhcpRelay_starvation(self, iface = 'veth0'):
342 mac = self.get_mac(iface)
343 self.host_load(iface)
344 ##we use the defaults for this test that serves as an example for others
345 ##You don't need to restart dhcpd server if retaining default config
346 config = self.default_config
347 options = self.default_options
348 subnet = self.default_subnet_config
349 dhcpd_interface_list = self.relay_interfaces
350 self.dhcpd_start(intf_list = dhcpd_interface_list,
351 config = config,
352 options = options,
353 subnet = subnet)
354 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
355 ip_map = {}
356 for i in range(10):
357 cip, sip = self.send_recv(mac, update_seed = True)
358 if ip_map.has_key(cip):
359 log.info('IP %s given out multiple times' %cip)
360 assert_equal(False, ip_map.has_key(cip))
361 ip_map[cip] = sip
362
363
364 def test_dhcpRelay_starvation(self, iface = 'veth0'):
365 mac = self.get_mac(iface)
366 self.host_load(iface)
367 ##we use the defaults for this test that serves as an example for others
368 ##You don't need to restart dhcpd server if retaining default config
369 config = self.default_config
370 options = self.default_options
371 subnet = self.default_subnet_config
372 dhcpd_interface_list = self.relay_interfaces
373 self.dhcpd_start(intf_list = dhcpd_interface_list,
374 config = config,
375 options = options,
376 subnet = subnet)
377 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
378 log.info('Verifying 1 ')
379 while True:
380 mac = RandMAC()._fix()
381 cip, sip = self.send_recv(mac = mac, validate = False)
382 if cip is None:
383 break
384 log.info('Verifying 2 ')
385 cip, sip = self.send_recv(mac, update_seed = True, validate = False)
386 assert_equal(cip, None)
387 assert_equal(sip, None)
388
389 def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'):
390 mac = self.get_mac(iface)
391 self.host_load(iface)
392 ##we use the defaults for this test that serves as an example for others
393 ##You don't need to restart dhcpd server if retaining default config
394 config = self.default_config
395 options = self.default_options
396 subnet = self.default_subnet_config
397 dhcpd_interface_list = self.relay_interfaces
398 self.dhcpd_start(intf_list = dhcpd_interface_list,
399 config = config,
400 options = options,
401 subnet = subnet)
402 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
403 cip, sip, mac, _ = self.dhcp.only_discover()
404 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
405 (cip, sip, mac) )
406 log.info('Triggering DHCP discover again.')
407 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
408 if cip == new_cip:
409 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
410 % (new_cip, new_sip, new_mac) )
411 elif cip != new_cip:
412 log.info('Ip after 1st discover %s' %cip)
413 log.info('Map after 2nd discover %s' %new_cip)
414 assert_equal(cip, new_cip)
415
416
417 def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'):
418 mac = self.get_mac(iface)
419 self.host_load(iface)
420 ##we use the defaults for this test that serves as an example for others
421 ##You don't need to restart dhcpd server if retaining default config
422 config = self.default_config
423 options = self.default_options
424 subnet = self.default_subnet_config
425 dhcpd_interface_list = self.relay_interfaces
426 self.dhcpd_start(intf_list = dhcpd_interface_list,
427 config = config,
428 options = options,
429 subnet = subnet)
430 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
431 log.info('Sending DHCP discover and DHCP request.')
432 cip, sip = self.send_recv(mac)
433 mac = self.dhcp.get_mac(cip)[0]
434 log.info("Sending DHCP request again.")
435 new_cip, new_sip = self.dhcp.only_request(cip, mac)
436 if (new_cip,new_sip) == (cip,sip):
437 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
438 % (new_cip, new_sip, mac) )
439 elif (new_cip,new_sip):
440 log.info('No DHCP ACK')
441 assert_equal(new_cip, None)
442 assert_equal(new_sip, None)
443 else:
444 log.info('Something went wrong.')
445
446 def test_dhcpRelay_client_desired_address(self, iface = 'veth0'):
447 mac = self.get_mac(iface)
448 self.host_load(iface)
449 ##we use the defaults for this test that serves as an example for others
450 ##You don't need to restart dhcpd server if retaining default config
451 config = self.default_config
452 options = self.default_options
453 subnet = self.default_subnet_config
454 dhcpd_interface_list = self.relay_interfaces
455 self.dhcpd_start(intf_list = dhcpd_interface_list,
456 config = config,
457 options = options,
458 subnet = subnet)
459 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
460 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
461 log.info('Got dhcp client IP %s from server %s for mac %s .' %
462 (cip, sip, mac) )
463 if cip == self.dhcp.seed_ip:
464 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
465 (cip, sip, mac) )
466 elif cip != self.dhcp.seed_ip:
467 log.info('Got dhcp client IP %s from server %s for mac %s .' %
468 (cip, sip, mac) )
469 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
470 assert_equal(cip, self.dhcp.seed_ip)
471
472 def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'):
473 mac = self.get_mac(iface)
474 self.host_load(iface)
475 ##we use the defaults for this test that serves as an example for others
476 ##You don't need to restart dhcpd server if retaining default config
477 config = self.default_config
478 options = self.default_options
479 subnet = self.default_subnet_config
480 dhcpd_interface_list = self.relay_interfaces
481 self.dhcpd_start(intf_list = dhcpd_interface_list,
482 config = config,
483 options = options,
484 subnet = subnet)
485 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
486 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
487 log.info('Got dhcp client IP %s from server %s for mac %s .' %
488 (cip, sip, mac) )
489 if cip == self.dhcp.seed_ip:
490 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
491 (cip, sip, mac) )
492 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
493 elif cip != self.dhcp.seed_ip:
494 log.info('Got dhcp client IP %s from server %s for mac %s .' %
495 (cip, sip, mac) )
496 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
497 assert_not_equal(cip, self.dhcp.seed_ip)
498 elif cip == None:
499 log.info('Got DHCP NAK')
500
501
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700502 def test_dhcpRelay_nak_packet(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700503 mac = self.get_mac(iface)
504 self.host_load(iface)
505 ##we use the defaults for this test that serves as an example for others
506 ##You don't need to restart dhcpd server if retaining default config
507 config = self.default_config
508 options = self.default_options
509 subnet = self.default_subnet_config
510 dhcpd_interface_list = self.relay_interfaces
511 self.dhcpd_start(intf_list = dhcpd_interface_list,
512 config = config,
513 options = options,
514 subnet = subnet)
515 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
516 cip, sip, mac, _ = self.dhcp.only_discover()
517 log.info('Got dhcp client IP %s from server %s for mac %s .' %
518 (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.")
523 assert_not_equal(cip, None)
524 else:
525 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
526 if new_cip == None:
527
528 log.info("Got DHCP server NAK.")
529 assert_equal(new_cip, None) #Negative Test Case
530
531
532 def test_dhcpRelay_specific_lease_packet(self, iface = 'veth0'):
533 mac = self.get_mac(iface)
534 self.host_load(iface)
535 ##we use the defaults for this test that serves as an example for others
536 ##You don't need to restart dhcpd server if retaining default config
537 config = self.default_config
538 options = self.default_options
539 subnet = self.default_subnet_config
540 dhcpd_interface_list = self.relay_interfaces
541 self.dhcpd_start(intf_list = dhcpd_interface_list,
542 config = config,
543 options = options,
544 subnet = subnet)
545 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
546 cip, sip, mac, _ = self.dhcp.only_discover()
547
548 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
549 if (cip == None and mac != None):
550 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
551 assert_not_equal(cip, None)
552 elif cip != None:
553 self.dhcp.specific_lease = 800
554 log.info('Sending DHCP request with specific lease time of %s', self.dhcp.specific_lease)
555 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac)
556 if new_cip == None:
557
558 log.info("Got DHCP server NAK.")
559 assert_equal(new_cip, None) #Negative Test Case
560 assert_equal(lval, self.dhcp.specific_lease)
561
562 def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'):
563 mac = self.get_mac(iface)
564 self.host_load(iface)
565 ##we use the defaults for this test that serves as an example for others
566 ##You don't need to restart dhcpd server if retaining default config
567 config = self.default_config
568 options = self.default_options
569 subnet = self.default_subnet_config
570 dhcpd_interface_list = self.relay_interfaces
571 self.dhcpd_start(intf_list = dhcpd_interface_list,
572 config = config,
573 options = options,
574 subnet = subnet)
575 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
576 cip, sip, mac, _ = self.dhcp.only_discover()
577 log.info('Got dhcp client IP %s from server %s for mac %s .' %
578 (cip, sip, mac) )
579
580 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
581
582 if (cip == None and mac != None):
583 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
584 assert_not_equal(cip, None)
585
586 else:
587 new_cip, new_sip = self.dhcp.only_request(cip, mac)
588 if new_cip == None:
589 log.info("Got DHCP server NAK.")
590 os.system('ifconfig '+iface+' down')
591 log.info('Client goes down.')
592 log.info('Delay for 5 seconds.')
593
594 time.sleep(5)
595
596 os.system('ifconfig '+iface+' up')
597 log.info('Client is up now.')
598
599 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
600 if new_cip == None:
601 log.info("Got DHCP server NAK.")
602 assert_not_equal(new_cip, None)
603 elif new_cip != None:
604 log.info("Got DHCP ACK.")
605 os.system('ifconfig '+iface+' up')
606
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700607 def test_dhcpRelay_after_reboot(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700608 mac = self.get_mac(iface)
609 self.host_load(iface)
610 ##we use the defaults for this test that serves as an example for others
611 ##You don't need to restart dhcpd server if retaining default config
612 config = self.default_config
613 options = self.default_options
614 subnet = self.default_subnet_config
615 dhcpd_interface_list = self.relay_interfaces
616 self.dhcpd_start(intf_list = dhcpd_interface_list,
617 config = config,
618 options = options,
619 subnet = subnet)
620 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
621 cip, sip, mac, _ = self.dhcp.only_discover()
622 log.info('Got dhcp client IP %s from server %s for mac %s .' %
623 (cip, sip, mac) )
624
625 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
626
627 if (cip == None and mac != None):
628 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
629 assert_not_equal(cip, None)
630
631 else:
632 new_cip, new_sip = self.dhcp.only_request(cip, mac)
633 if new_cip == None:
634 log.info("Got DHCP server NAK.")
635 assert_not_equal(new_cip, None)
636 log.info('Getting DHCP server Down.')
637
638 self.tearDownClass()
639
640 for i in range(0,4):
641 log.info("Sending DHCP Request.")
642 log.info('')
643 new_cip, new_sip = self.dhcp.only_request(cip, mac)
644 if new_cip == None and new_sip == None:
645 log.info('')
646 log.info("DHCP Request timed out.")
647 elif new_cip and new_sip:
648 log.info("Got Reply from DHCP server.")
649 assert_equal(new_cip,None) #Neagtive Test Case
650
651 log.info('Getting DHCP server Up.')
652
653 self.setUpClass()
654
655 for i in range(0,4):
656 log.info("Sending DHCP Request after DHCP server is up.")
657 log.info('')
658 new_cip, new_sip = self.dhcp.only_request(cip, mac)
659 if new_cip == None and new_sip == None:
660 log.info('')
661 log.info("DHCP Request timed out.")
662 elif new_cip and new_sip:
663 log.info("Got Reply from DHCP server.")
664 assert_equal(new_cip, cip)
665
666
667 def test_dhcpRelay_specific_lease_packet_in_dhcp_discover(self, iface = 'veth0'):
668 mac = self.get_mac(iface)
669 self.host_load(iface)
670 ##we use the defaults for this test that serves as an example for others
671 ##You don't need to restart dhcpd server if retaining default config
672 config = self.default_config
673 options = self.default_options
674 subnet = self.default_subnet_config
675 dhcpd_interface_list = self.relay_interfaces
676 self.dhcpd_start(intf_list = dhcpd_interface_list,
677 config = config,
678 options = options,
679 subnet = subnet)
680 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
681 log.info('Sending DHCP discover with lease time of 700')
682 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
683 log.info('Got dhcp client IP %s from server %s for mac %s .' %
684 (cip, sip, mac) )
685
686 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
687 if (cip == None and mac != None):
688 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
689 assert_not_equal(cip, None)
690 elif cip and sip and mac:
691
692 log.info("Triggering DHCP Request.")
693 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
694 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
695 (new_cip, new_sip, mac, lval) )
696 assert_not_equal(lval, 700) #Negative Test Case
697
698
699
700 def test_dhcpRelay_default_lease_time(self, iface = 'veth0'):
701 mac = self.get_mac(iface)
702 self.host_load(iface)
703 ##we use the defaults for this test that serves as an example for others
704 ##You don't need to restart dhcpd server if retaining default config
705 config = self.default_config
706 options = self.default_options
707 subnet = self.default_subnet_config
708 dhcpd_interface_list = self.relay_interfaces
709 self.dhcpd_start(intf_list = dhcpd_interface_list,
710 config = config,
711 options = options,
712 subnet = subnet)
713 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
714 cip, sip, mac, _ = self.dhcp.only_discover()
715 log.info('Got dhcp client IP %s from server %s for mac %s .' %
716 (cip, sip, mac) )
717
718 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
719 if (cip == None and mac != None):
720 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
721 assert_not_equal(cip, None)
722
723 elif cip and sip and mac:
724
725 log.info("Triggering DHCP Request.")
726 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
727 if lval == 600:
728 log.info('Getting dhcp client IP %s from server %s for mac %s with defualt lease time %s.' %
729 (new_cip, new_sip, mac, lval) )
730 else:
731 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
732 (new_cip, new_sip, mac, lval) )
733 log.info('The lease time suppossed to be 600 secs or 10 mins.')
734 assert_equal(lval, 600)
735
736 def test_dhcpRelay_client_renew_time(self, iface = 'veth0'):
737 mac = self.get_mac(iface)
738 self.host_load(iface)
739 ##we use the defaults for this test that serves as an example for others
740 ##You don't need to restart dhcpd server if retaining default config
741 config = self.default_config
742 new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)]
743 options = self.default_options + new_options
744 subnet = self.default_subnet_config
745 dhcpd_interface_list = self.relay_interfaces
746 self.dhcpd_start(intf_list = dhcpd_interface_list,
747 config = config,
748 options = options,
749 subnet = subnet)
750 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
751 cip, sip, mac, _ = self.dhcp.only_discover()
752 log.info('Got dhcp client IP %s from server %s for mac %s .' %
753 (cip, sip, mac) )
754
755 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
756 if (cip == None and mac != None):
757 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
758 assert_not_equal(cip, None)
759
760 elif cip and sip and mac:
761
762 log.info("Triggering DHCP Request.")
763 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
764
765 if new_cip and new_sip and lval:
766
767 log.info("Clinet 's Renewal time is :%s",lval)
768 log.info("Generating delay till renewal time.")
769 time.sleep(lval)
770
771 log.info("Client Sending Unicast DHCP request.")
772 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
773
774 if latest_cip and latest_sip:
775 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
776 (latest_cip, mac, latest_sip) )
777
778 elif latest_cip == None:
779 log.info("Got DHCP NAK. Lease not renewed.")
780
781 elif new_cip == None or new_sip == None or lval == None:
782
783 log.info("Got DHCP NAK.")
784
785
786
787 def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'):
788 mac = self.get_mac(iface)
789 self.host_load(iface)
790 ##we use the defaults for this test that serves as an example for others
791 ##You don't need to restart dhcpd server if retaining default config
792 config = self.default_config
793 new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)]
794 options = self.default_options + new_options
795 subnet = self.default_subnet_config
796 dhcpd_interface_list = self.relay_interfaces
797 self.dhcpd_start(intf_list = dhcpd_interface_list,
798 config = config,
799 options = options,
800 subnet = subnet)
801 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
802 cip, sip, mac, _ = self.dhcp.only_discover()
803 log.info('Got dhcp client IP %s from server %s for mac %s .' %
804 (cip, sip, mac) )
805
806 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
807 if (cip == None and mac != None):
808 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
809 assert_not_equal(cip, None)
810
811 elif cip and sip and mac:
812
813 log.info("Triggering DHCP Request.")
814 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
815
816 if new_cip and new_sip and lval:
817
818 log.info("Clinet 's Rebind time is :%s",lval)
819 log.info("Generating delay till rebind time.")
820 time.sleep(lval)
821
822 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
823
824 for i in range(0,4):
825 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
826
827 if latest_cip and latest_sip:
828 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
829 (latest_cip, mac, latest_sip) )
830 break
831
832 elif latest_cip == None:
833 log.info("Got DHCP NAK. Lease not renewed.")
834 assert_not_equal(latest_cip, None)
835 elif new_cip == None or new_sip == None or lval == None:
836
837 log.info("Got DHCP NAK.Lease not Renewed.")
838
839
840 def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'):
841 mac = self.get_mac(iface)
842 self.host_load(iface)
843 ##we use the defaults for this test that serves as an example for others
844 ##You don't need to restart dhcpd server if retaining default config
845 config = self.default_config
846 options = self.default_options
847 subnet = self.default_subnet_config
848 dhcpd_interface_list = self.relay_interfaces
849 self.dhcpd_start(intf_list = dhcpd_interface_list,
850 config = config,
851 options = options,
852 subnet = subnet)
853 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
854 expected_subnet = '255.255.255.0'
855 self.dhcp.return_option = 'subnet'
856
857 cip, sip, mac, subnet_value = self.dhcp.only_discover()
858 log.info('Got dhcp client IP %s from server %s for mac %s .' %
859 (cip, sip, mac) )
860
861 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
862 if (cip == None and mac != None):
863 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
864 assert_not_equal(cip, None)
ChetanGaonker5860c182016-07-05 16:33:06 -0700865 elif cip and sip and mac:
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700866 if expected_subnet == subnet_value:
867 log.info("Got same subnet as passed in DHCP server configuration.")
868 elif expected_subnet != subnet_value:
869 log.info("Not getting same subnet as passed in DHCP server configuration.")
870 assert_equal(expected_subnet, subnet_value)
ChetanGaonker5860c182016-07-05 16:33:06 -0700871
872
873 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
874 mac = self.get_mac(iface)
875 self.host_load(iface)
876 ##we use the defaults for this test that serves as an example for others
877 ##You don't need to restart dhcpd server if retaining default config
878 config = self.default_config
879 options = self.default_options
880 subnet = self.default_subnet_config
881 dhcpd_interface_list = self.relay_interfaces
882 self.dhcpd_start(intf_list = dhcpd_interface_list,
883 config = config,
884 options = options,
885 subnet = subnet)
886 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
887
888 cip, sip, mac, _ = self.dhcp.only_discover()
889 log.info('Got dhcp client IP %s from server %s for mac %s .' %
890 (cip, sip, mac) )
891
892 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
893 if (cip == None and mac != None):
894 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
895 assert_not_equal(cip, None)
896
897 elif cip and sip and mac:
898
899 self.dhcp.send_different_option = 'subnet'
900 log.info("Sending DHCP Request with wrong subnet mask.")
901 new_cip, new_sip = self.dhcp.only_request(cip, mac)
902 if new_cip == None:
903
904 log.info("Got DHCP NAK.")
905 assert_not_equal(new_cip, None)
906
907 elif new_cip and new_sip:
908
909 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
910 log.info("Getting subnet mask as per server 's configuration.")
911
912
913 def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'):
914 mac = self.get_mac(iface)
915 self.host_load(iface)
916 ##we use the defaults for this test that serves as an example for others
917 ##You don't need to restart dhcpd server if retaining default config
918 config = self.default_config
919 config = self.default_config
920 new_options = [('routers', '20.20.20.1')]
921 options = self.default_options + new_options
922 subnet = self.default_subnet_config
923 dhcpd_interface_list = self.relay_interfaces
924 self.dhcpd_start(intf_list = dhcpd_interface_list,
925 config = config,
926 options = options,
927 subnet = subnet)
928 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
929 expected_router_address = '20.20.20.1'
930 self.dhcp.return_option = 'router'
931
932 cip, sip, mac, router_address_value = self.dhcp.only_discover()
933 log.info('Got dhcp client IP %s from server %s for mac %s .' %
934 (cip, sip, mac) )
935
936 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
937 if (cip == None and mac != None):
938 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
939 assert_not_equal(cip, None)
940
941 elif cip and sip and mac:
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700942 if expected_router_address == router_address_value:
943 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700944
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700945 elif expected_router_address != router_address_value:
ChetanGaonker5860c182016-07-05 16:33:06 -0700946 log.info("Not getting same router address as passed in DHCP server configuration.")
947 assert_equal(expected_router_address, router_address_value)
948
949
950 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
951 mac = self.get_mac(iface)
952 self.host_load(iface)
953 ##we use the defaults for this test that serves as an example for others
954 ##You don't need to restart dhcpd server if retaining default config
955 config = self.default_config
956 options = self.default_options
957 subnet = self.default_subnet_config
958 dhcpd_interface_list = self.relay_interfaces
959 self.dhcpd_start(intf_list = dhcpd_interface_list,
960 config = config,
961 options = options,
962 subnet = subnet)
963 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
964
965 cip, sip, mac, _ = self.dhcp.only_discover()
966 log.info('Got dhcp client IP %s from server %s for mac %s .' %
967 (cip, sip, mac) )
968
969 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
970 if (cip == None and mac != None):
971 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
972 assert_not_equal(cip, None)
973
974 elif cip and sip and mac:
975
976 self.dhcp.send_different_option = 'router'
977 log.info("Sending DHCP Request with wrong router address.")
978 new_cip, new_sip = self.dhcp.only_request(cip, mac)
979 if new_cip == None:
980
981 log.info("Got DHCP NAK.")
982 assert_not_equal(new_cip, None)
983
984 elif new_cip and new_sip:
985
986 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
987 log.info("Getting Router Address as per server 's configuration.")
988
989
990 def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'):
991 mac = self.get_mac(iface)
992 self.host_load(iface)
993 ##we use the defaults for this test that serves as an example for others
994 ##You don't need to restart dhcpd server if retaining default config
995 config = self.default_config
996 options = self.default_options
997 subnet = self.default_subnet_config
998 dhcpd_interface_list = self.relay_interfaces
999 self.dhcpd_start(intf_list = dhcpd_interface_list,
1000 config = config,
1001 options = options,
1002 subnet = subnet)
1003 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1004 expected_broadcast_address = '192.168.1.255'
1005 self.dhcp.return_option = 'broadcast_address'
1006
1007 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
1008 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1009 (cip, sip, mac) )
1010
1011 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1012 if (cip == None and mac != None):
1013 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1014 assert_not_equal(cip, None)
1015
1016 elif cip and sip and mac:
1017
1018 if expected_broadcast_address == broadcast_address_value:
1019 log.info("Got same router address as passed in DHCP server configuration.")
1020
1021 elif expected_broadcast_address != broadcast_address_value:
1022 log.info("Not getting same router address as passed in DHCP server configuration.")
1023 assert_equal(expected_broadcast_address, broadcast_address_value)
1024
1025
1026 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
1027 mac = self.get_mac(iface)
1028 self.host_load(iface)
1029 ##we use the defaults for this test that serves as an example for others
1030 ##You don't need to restart dhcpd server if retaining default config
1031 config = self.default_config
1032 options = self.default_options
1033 subnet = self.default_subnet_config
1034 dhcpd_interface_list = self.relay_interfaces
1035 self.dhcpd_start(intf_list = dhcpd_interface_list,
1036 config = config,
1037 options = options,
1038 subnet = subnet)
1039 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1040
1041 cip, sip, mac, _ = self.dhcp.only_discover()
1042 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1043 (cip, sip, mac) )
1044
1045 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1046 if (cip == None and mac != None):
1047 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1048 assert_not_equal(cip, None)
1049
1050 elif cip and sip and mac:
1051
1052 self.dhcp.send_different_option = 'broadcast_address'
1053 log.info("Sending DHCP Request with wrong broadcast address.")
1054 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1055 if new_cip == None:
1056
1057 log.info("Got DHCP NAK.")
1058 assert_not_equal(new_cip, None)
1059
1060 elif new_cip and new_sip:
1061
1062 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1063 log.info("Getting Broadcast Address as per server 's configuration.")
1064
1065 def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'):
1066 mac = self.get_mac(iface)
1067 self.host_load(iface)
1068 ##we use the defaults for this test that serves as an example for others
1069 ##You don't need to restart dhcpd server if retaining default config
1070 config = self.default_config
1071 options = self.default_options
1072 subnet = self.default_subnet_config
1073 dhcpd_interface_list = self.relay_interfaces
1074 self.dhcpd_start(intf_list = dhcpd_interface_list,
1075 config = config,
1076 options = options,
1077 subnet = subnet)
1078 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1079 expected_dns_address = '192.168.1.1'
1080 self.dhcp.return_option = 'dns'
1081
1082 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1083 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1084 (cip, sip, mac) )
1085
1086 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1087 if (cip == None and mac != None):
1088 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1089 assert_not_equal(cip, None)
1090
1091 elif cip and sip and mac:
1092
1093 if expected_dns_address == dns_address_value:
1094 log.info("Got same DNS address as passed in DHCP server configuration.")
1095
1096 elif expected_dns_address != dns_address_value:
1097 log.info("Not getting same DNS address as passed in DHCP server configuration.")
1098 assert_equal(expected_dns_address, dns_address_value)
1099
1100
1101 def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
1102 mac = self.get_mac(iface)
1103 self.host_load(iface)
1104 ##we use the defaults for this test that serves as an example for others
1105 ##You don't need to restart dhcpd server if retaining default config
1106 config = self.default_config
1107 options = self.default_options
1108 subnet = self.default_subnet_config
1109 dhcpd_interface_list = self.relay_interfaces
1110 self.dhcpd_start(intf_list = dhcpd_interface_list,
1111 config = config,
1112 options = options,
1113 subnet = subnet)
1114 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1115
1116 cip, sip, mac, _ = self.dhcp.only_discover()
1117 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1118 (cip, sip, mac) )
1119
1120 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1121 if (cip == None and mac != None):
1122 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1123 assert_not_equal(cip, None)
1124
1125 elif cip and sip and mac:
1126
1127 self.dhcp.send_different_option = 'dns'
1128 log.info("Sending DHCP Request with wrong DNS address.")
1129 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1130 if new_cip == None:
1131 log.info("Got DHCP NAK.")
1132 assert_not_equal(new_cip, None)
1133 elif new_cip and new_sip:
1134 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1135 log.info("Getting DNS Address as per server 's configuration.")
1136
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001137 def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001138
1139 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001140 self.stats()
1141 log.info("Statistics for run %d",i)
1142 log.info("----------------------------------------------------------------------------------")
1143 log.info("No. of transactions No. of successes No. of failures Running Time ")
1144 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1145 log.info("----------------------------------------------------------------------------------")
1146 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker5860c182016-07-05 16:33:06 -07001147
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001148 log.info("Final Statistics for total transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001149 log.info("----------------------------------------------------------------------------------")
1150 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1151 log.info(" %d %d %d %d" %(self.transactions,
1152 self.total_success, self.total_failure, self.running_time))
1153 log.info("----------------------------------------------------------------------------------")
1154 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1155
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001156 def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001157
1158 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001159 self.stats(success_rate = True)
1160 log.info("Statistics for run %d",i)
1161 log.info("----------------------------------------------------------------------------------")
1162 log.info("No. of consecutive successful transactions Running Time ")
1163 log.info(" %d %d " %(self.ip_count, self.diff))
1164 log.info("----------------------------------------------------------------------------------")
1165 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1166 log.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001167
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001168 log.info("Final Statistics for total successful transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001169 log.info("----------------------------------------------------------------------------------")
1170 log.info("Total transactions Total No. of consecutive successes Running Time ")
1171 log.info(" %d %d %d " %(self.transactions,
1172 self.total_success, self.running_time))
1173 log.info("----------------------------------------------------------------------------------")
1174 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1175 log.info("----------------------------------------------------------------------------------")
1176
1177
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001178 def test_dhcpRelay_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001179
1180 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001181 self.stats(only_discover = True)
1182 log.info("----------------------------------------------------------------------------------")
1183 log.info("Statistics for run %d of sending only DHCP Discover",i)
1184 log.info("----------------------------------------------------------------------------------")
1185 log.info("No. of transactions No. of successes No. of failures Running Time ")
1186 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1187 log.info("----------------------------------------------------------------------------------")
1188 log.info("No. of clients per second in run %d:%f "
1189 %(i, self.transaction_count))
1190 log.info("----------------------------------------------------------------------------------")
1191 log.info("Final Statistics for total transactions of sending only DHCP Discover")
ChetanGaonker5860c182016-07-05 16:33:06 -07001192 log.info("----------------------------------------------------------------------------------")
1193 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1194 log.info(" %d %d %d %d" %(self.transactions,
1195 self.total_success, self.total_failure, self.running_time))
1196 log.info("----------------------------------------------------------------------------------")
1197 log.info("Average no. of clients per second: %d ",
1198 round(self.transactions/self.running_time,0))
1199 log.info("----------------------------------------------------------------------------------")
1200
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001201 def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001202
1203 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001204 self.stats(success_rate = True, only_discover = True)
1205 log.info("----------------------------------------------------------------------------------")
1206 log.info("Statistics for run %d for sending only DHCP Discover",i)
1207 log.info("----------------------------------------------------------------------------------")
1208 log.info("No. of consecutive successful transactions Running Time ")
1209 log.info(" %d %d " %(self.ip_count, self.diff))
1210 log.info("----------------------------------------------------------------------------------")
1211 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1212 log.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001213
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001214 log.info("Final Statistics for total successful transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001215 log.info("----------------------------------------------------------------------------------")
1216 log.info("Total transactions Total No. of consecutive successes Running Time ")
1217 log.info(" %d %d %d " %(self.transactions,
1218 self.total_success, self.running_time))
1219 log.info("----------------------------------------------------------------------------------")
1220 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1221 log.info("----------------------------------------------------------------------------------")
1222
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001223 def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'):
1224
1225 config = self.default_config
1226 options = self.default_options
1227 subnet = [ ('192.168.1.2',
1228'''
1229subnet 192.168.0.0 netmask 255.255.0.0 {
1230 range 192.168.1.10 192.168.2.100;
1231}
1232'''), ]
1233
1234 dhcpd_interface_list = self.relay_interfaces
1235 self.dhcpd_start(intf_list = dhcpd_interface_list,
1236 config = config,
1237 options = options,
1238 subnet = subnet)
1239
1240 for key in (key for key in g_subscriber_port_map if key < 100):
1241 self.host_load(g_subscriber_port_map[key])
1242
1243 def thread_fun(i):
1244 mac = self.get_mac('veth{}'.format(i))
1245 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1246 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1247 self.lock.acquire()
1248
1249 if cip:
1250 self.ip_count += 1
1251
1252 elif cip is None:
1253 self.failure_count += 1
1254
1255 self.lock.notify_all()
1256 self.lock.release()
1257
1258 for i in range (1,4):
1259 self.ip_count = 0
1260 self.failure_count = 0
1261 self.start_time = 0
1262 self.diff = 0
1263 self.transaction_count = 0
1264 self.start_time = time.time()
1265
1266 while self.diff <= 60:
1267 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1268 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1269 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1270 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1271 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1272 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1273
1274 t.start()
1275 t1.start()
1276 t2.start()
1277 t3.start()
1278 t4.start()
1279 t5.start()
1280
1281 t.join()
1282 t1.join()
1283 t2.join()
1284 t3.join()
1285 t4.join()
1286 t5.join()
1287
1288 self.diff = round(time.time() - self.start_time, 0)
1289
1290 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1291
1292 self.transactions += (self.ip_count+self.failure_count)
1293 self.running_time += self.diff
1294 self.total_success += self.ip_count
1295 self.total_failure += self.failure_count
1296
1297
1298 log.info("----------------------------------------------------------------------------------")
1299 log.info("Statistics for run %d",i)
1300 log.info("----------------------------------------------------------------------------------")
1301 log.info("No. of transactions No. of successes No. of failures Running Time ")
1302 log.info(" %d %d %d %d"
1303 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1304 log.info("----------------------------------------------------------------------------------")
1305 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1306 log.info("----------------------------------------------------------------------------------")
1307
1308 log.info("----------------------------------------------------------------------------------")
1309 log.info("Final Statistics for total transactions")
1310 log.info("----------------------------------------------------------------------------------")
1311 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1312 log.info(" %d %d %d %d" %(self.transactions,
1313 self.total_success, self.total_failure, self.running_time))
1314
1315 log.info("----------------------------------------------------------------------------------")
1316 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1317 log.info("----------------------------------------------------------------------------------")
1318
1319 def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
1320
1321 config = self.default_config
1322 options = self.default_options
1323 subnet = [ ('192.168.1.2',
1324'''
1325subnet 192.168.0.0 netmask 255.255.0.0 {
1326 range 192.168.1.10 192.168.2.100;
1327}
1328'''), ]
1329
1330 dhcpd_interface_list = self.relay_interfaces
1331 self.dhcpd_start(intf_list = dhcpd_interface_list,
1332 config = config,
1333 options = options,
1334 subnet = subnet)
1335 failure_dir = {}
1336
1337 for key in (key for key in g_subscriber_port_map if key != 100):
1338 self.host_load(g_subscriber_port_map[key])
1339
1340 def thread_fun(i, j):
1341# log.info("Thread Name:%s",current_thread().name)
1342# failure_dir[current_thread().name] = True
1343 while failure_dir.has_key(current_thread().name) is False:
1344 mac = RandMAC()._fix()
1345 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1346 i += 2
1347 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1348 self.lock.acquire()
1349
1350 if cip:
1351 self.ip_count += 1
1352 self.lock.notify_all()
1353 self.lock.release()
1354 elif cip is None:
1355 self.failure_count += 1
1356 failure_dir[current_thread().name] = True
1357 self.lock.notify_all()
1358 self.lock.release()
1359 break
1360# self.lock.notify_all()
1361# self.lock.release()
1362
1363 for i in range (1,4):
1364 failure_dir = {}
1365 self.ip_count = 0
1366 self.failure_count = 0
1367 self.start_time = 0
1368 self.diff = 0
1369 self.transaction_count = 0
1370 self.start_time = time.time()
1371
1372 while len(failure_dir) != 6:
1373 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1374 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1375 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1376 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1377 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1378 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1379
1380 t.start()
1381 t1.start()
1382 t2.start()
1383 t3.start()
1384 t4.start()
1385 t5.start()
1386
1387 t.join()
1388 t1.join()
1389 t2.join()
1390 t3.join()
1391 t4.join()
1392 t5.join()
1393
1394 self.diff = round(time.time() - self.start_time, 0)
1395 self.transaction_count = round((self.ip_count)/self.diff, 2)
1396
1397 self.transactions += (self.ip_count+self.failure_count)
1398 self.running_time += self.diff
1399 self.total_success += self.ip_count
1400 self.total_failure += self.failure_count
1401
1402
1403 log.info("Statistics for run %d",i)
1404 log.info("----------------------------------------------------------------------------------")
1405 log.info("No. of consecutive successful transactions Running Time ")
1406 log.info(" %d %d " %(self.ip_count, self.diff))
1407 log.info("----------------------------------------------------------------------------------")
1408 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1409 log.info("----------------------------------------------------------------------------------")
1410
1411 log.info("Final Statistics for total successful transactions")
1412 log.info("----------------------------------------------------------------------------------")
1413 log.info("Total transactions Total No. of consecutive successes Running Time ")
1414 log.info(" %d %d %d " %(self.transactions,
1415 self.total_success, self.running_time))
1416 log.info("----------------------------------------------------------------------------------")
1417 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1418 log.info("----------------------------------------------------------------------------------")
1419
1420 def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'):
1421
1422 config = self.default_config
1423 options = self.default_options
1424 subnet = [ ('192.168.1.2',
1425'''
1426subnet 192.168.0.0 netmask 255.255.0.0 {
1427 range 192.168.1.10 192.168.2.100;
1428}
1429'''), ]
1430
1431 dhcpd_interface_list = self.relay_interfaces
1432 self.dhcpd_start(intf_list = dhcpd_interface_list,
1433 config = config,
1434 options = options,
1435 subnet = subnet)
1436
1437 for key in (key for key in g_subscriber_port_map if key < 100):
1438 self.host_load(g_subscriber_port_map[key])
1439
1440 def thread_fun(i):
1441# mac = self.get_mac('veth{}'.format(i))
1442 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1443 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1444 self.lock.acquire()
1445
1446 if cip:
1447 self.ip_count += 1
1448 elif cip is None:
1449 self.failure_count += 1
1450
1451 self.lock.notify_all()
1452 self.lock.release()
1453
1454 for i in range (1,4):
1455 self.ip_count = 0
1456 self.failure_count = 0
1457 self.start_time = 0
1458 self.diff = 0
1459 self.transaction_count = 0
1460 self.start_time = time.time()
1461
1462 while self.diff <= 60:
1463 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1464 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1465 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1466 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1467 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1468 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1469
1470 t.start()
1471 t1.start()
1472 t2.start()
1473 t3.start()
1474 t4.start()
1475 t5.start()
1476
1477 t.join()
1478 t1.join()
1479 t2.join()
1480 t3.join()
1481 t4.join()
1482 t5.join()
1483
1484 self.diff = round(time.time() - self.start_time, 0)
1485 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1486 self.transactions += (self.ip_count+self.failure_count)
1487 self.running_time += self.diff
1488 self.total_success += self.ip_count
1489 self.total_failure += self.failure_count
1490
1491 log.info("----------------------------------------------------------------------------------")
1492 log.info("Statistics for run %d of sending only DHCP Discover",i)
1493 log.info("----------------------------------------------------------------------------------")
1494 log.info("No. of transactions No. of successes No. of failures Running Time ")
1495 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1496 log.info("----------------------------------------------------------------------------------")
1497 log.info("No. of clients per second in run %d:%f "
1498 %(i, self.transaction_count))
1499 log.info("----------------------------------------------------------------------------------")
1500
1501 log.info("Final Statistics for total transactions of sending only DHCP Discover")
1502 log.info("----------------------------------------------------------------------------------")
1503 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1504 log.info(" %d %d %d %d" %(self.transactions,
1505 self.total_success, self.total_failure, self.running_time))
1506 log.info("----------------------------------------------------------------------------------")
1507 log.info("Average no. of clients per second: %d ",
1508 round(self.transactions/self.running_time,0))
1509 log.info("----------------------------------------------------------------------------------")
1510
1511
1512 @nottest
1513 def test_dhcpRelay_inform_packet(self, iface = 'veth0'):
1514 mac = self.get_mac(iface)
1515 self.host_load(iface)
1516 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1517 self.send_recv(mac, inform_packet = True)
1518
1519 def test_dhcpRelay_client_conflict(self, iface = 'veth0'):
1520 mac = self.get_mac(iface)
1521 self.host_load(iface)
1522 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1523 cip, sip, mac, _ = self.dhcp.only_discover()
1524 log.info('Got dhcp client IP %s from server %s for mac %s.' %
1525 (cip, sip, mac) )
1526 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1527 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1528 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1529 log.info('Got dhcp client IP %s from server %s for mac %s.' %
1530 (new_cip, new_sip, new_mac) )
1531 log.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1532 log.info("Now sending DHCP Request for old DHCP discover.")
1533 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1534 if new_cip is None:
1535 log.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1536 %(new_cip, new_sip, new_mac) )
1537 elif new_cip:
1538 log.info('Got dhcp client IP %s from server %s for mac %s.Which is not expected behavior as IP %s is already consumed.'
1539 %(new_cip, new_sip, new_mac, new_cip) )
1540 assert_equal(new_cip, None)
1541
1542
ChetanGaonker5860c182016-07-05 16:33:06 -07001543