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