blob: 2cfb4beefe9a3f6f45e9036475c7808c71121f05 [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,
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +000012# WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied.
A R Karthick8cf29ac2016-06-30 16:25:14 -070013# 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 Karthickbe7768c2017-03-17 11:39:41 -070024from CordTestUtils import get_mac
25from OnosCtrl import OnosCtrl
A R Karthickb03cecd2016-07-27 10:27:55 -070026from OltConfig import OltConfig
A R Karthick4e0c0912016-08-17 16:57:42 -070027from CordTestServer import cord_test_onos_restart
A R Karthick9313b762016-11-07 13:14:35 -080028from CordLogger import CordLogger
A R Karthick8cf29ac2016-06-30 16:25:14 -070029from portmaps import g_subscriber_port_map
ChetanGaonker5b984cb2016-07-12 15:50:49 -070030import threading, random
31from threading import current_thread
A R Karthick8cf29ac2016-06-30 16:25:14 -070032log.setLevel('INFO')
33
A R Karthick9313b762016-11-07 13:14:35 -080034class dhcprelay_exchange(CordLogger):
A R Karthick8cf29ac2016-06-30 16:25:14 -070035
36 app = 'org.onosproject.dhcprelay'
37 app_dhcp = 'org.onosproject.dhcp'
A R Karthickb03cecd2016-07-27 10:27:55 -070038 relay_interfaces_last = ()
A R Karthick8cf29ac2016-06-30 16:25:14 -070039 interface_to_mac_map = {}
A R Karthick3026e482016-08-12 16:02:40 -070040 host_ip_map = {}
41 test_path = os.path.dirname(os.path.realpath(__file__))
42 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
43 olt_conf_file = os.path.join(test_path, '..', 'setup/olt_config.json')
A R Karthick8cf29ac2016-06-30 16:25:14 -070044 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
45 default_options = [ ('subnet-mask', '255.255.255.0'),
46 ('broadcast-address', '192.168.1.255'),
47 ('domain-name-servers', '192.168.1.1'),
48 ('domain-name', '"mydomain.cord-tester"'),
49 ]
50 ##specify the IP for the dhcp interface matching the subnet and subnet config
51 ##this is done for each interface dhcpd server would be listening on
52 default_subnet_config = [ ('192.168.1.2',
53'''
54subnet 192.168.1.0 netmask 255.255.255.0 {
55 range 192.168.1.10 192.168.1.100;
56}
57'''), ]
ChetanGaonker5b984cb2016-07-12 15:50:49 -070058
59 lock = threading.Condition()
ChetanGaonker5860c182016-07-05 16:33:06 -070060 ip_count = 0
61 failure_count = 0
62 start_time = 0
63 diff = 0
64
65 transaction_count = 0
66 transactions = 0
67 running_time = 0
68 total_success = 0
69 total_failure = 0
A R Karthick4e0c0912016-08-17 16:57:42 -070070 #just in case we want to reset ONOS to default network cfg after relay tests
71 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
A R Karthickbd82f362016-11-10 15:08:52 -080072 configs = {}
ChetanGaonker5860c182016-07-05 16:33:06 -070073
A R Karthick8cf29ac2016-06-30 16:25:14 -070074 @classmethod
75 def setUpClass(cls):
76 ''' Activate the dhcprelay app'''
77 OnosCtrl(cls.app_dhcp).deactivate()
78 time.sleep(3)
79 cls.onos_ctrl = OnosCtrl(cls.app)
80 status, _ = cls.onos_ctrl.activate()
81 assert_equal(status, True)
82 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070083 cls.dhcp_relay_setup()
A R Karthick8cf29ac2016-06-30 16:25:14 -070084 ##start dhcpd initially with default config
85 cls.dhcpd_start()
A R Karthick8cf29ac2016-06-30 16:25:14 -070086
87 @classmethod
88 def tearDownClass(cls):
89 '''Deactivate the dhcp relay app'''
90 try:
91 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
92 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
93 except: pass
94 cls.onos_ctrl.deactivate()
95 cls.dhcpd_stop()
A R Karthick4e0c0912016-08-17 16:57:42 -070096 cls.dhcp_relay_cleanup()
A R Karthick8cf29ac2016-06-30 16:25:14 -070097
98 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -070099 def dhcp_relay_setup(cls):
100 did = OnosCtrl.get_device_id()
101 cls.relay_device_id = did
A R Karthick3026e482016-08-12 16:02:40 -0700102 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
A R Karthickb03cecd2016-07-27 10:27:55 -0700103 cls.port_map, _ = cls.olt.olt_port_map()
104 if cls.port_map:
A R Karthick36cfcef2016-08-18 15:20:07 -0700105 ##Per subscriber, we use 1 relay port
106 try:
107 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
108 except:
109 relay_port = cls.port_map['uplink']
110 cls.relay_interface_port = relay_port
A R Karthickb03cecd2016-07-27 10:27:55 -0700111 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
112 else:
113 cls.relay_interface_port = 100
114 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
115 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick3026e482016-08-12 16:02:40 -0700116 if cls.port_map:
117 ##generate a ip/mac client virtual interface config for onos
118 interface_list = []
119 for port in cls.port_map['ports']:
120 port_num = cls.port_map[port]
121 if port_num == cls.port_map['uplink']:
A R Karthick36cfcef2016-08-18 15:20:07 -0700122 continue
123 ip = cls.get_host_ip(port_num)
A R Karthick3026e482016-08-12 16:02:40 -0700124 mac = cls.get_mac(port)
125 interface_list.append((port_num, ip, mac))
126
A R Karthick36cfcef2016-08-18 15:20:07 -0700127 #configure dhcp server virtual interface on the same subnet as first client interface
128 relay_ip = cls.get_host_ip(interface_list[0][0])
129 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
130 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthick3026e482016-08-12 16:02:40 -0700131 cls.onos_interface_load(interface_list)
A R Karthickb03cecd2016-07-27 10:27:55 -0700132
133 @classmethod
A R Karthick4e0c0912016-08-17 16:57:42 -0700134 def dhcp_relay_cleanup(cls):
135 ##reset the ONOS port configuration back to default
A R Karthickbd82f362016-11-10 15:08:52 -0800136 for config in cls.configs.items():
137 OnosCtrl.delete(config)
138 # if cls.onos_restartable is True:
139 # log.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
140 # return cord_test_onos_restart(config = {})
A R Karthick4e0c0912016-08-17 16:57:42 -0700141
142 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700143 def onos_load_config(cls, config):
144 status, code = OnosCtrl.config(config)
145 if status is False:
146 log.info('JSON request returned status %d' %code)
147 assert_equal(status, True)
148 time.sleep(3)
149
150 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700151 def onos_interface_load(cls, interface_list):
152 interface_dict = { 'ports': {} }
153 for port_num, ip, mac in interface_list:
154 port_map = interface_dict['ports']
155 port = '{}/{}'.format(cls.relay_device_id, port_num)
156 port_map[port] = { 'interfaces': [] }
157 interface_list = port_map[port]['interfaces']
158 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
159 'mac' : mac,
160 'name': 'vir-{}'.format(port_num)
161 }
162 interface_list.append(interface_map)
163
164 cls.onos_load_config(interface_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800165 cls.configs['interface_config'] = interface_dict
A R Karthick3026e482016-08-12 16:02:40 -0700166
167 @classmethod
168 def onos_dhcp_relay_load(cls, server_ip, server_mac):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700169 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
170 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
A R Karthick3026e482016-08-12 16:02:40 -0700171 {'dhcpserverConnectPoint':relay_device_map,
172 'serverip':server_ip,
173 'servermac':server_mac
174 }
175 }
176 }
177 }
A R Karthick8cf29ac2016-06-30 16:25:14 -0700178 cls.onos_load_config(dhcp_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800179 cls.configs['relay_config'] = dhcp_dict
A R Karthick8cf29ac2016-06-30 16:25:14 -0700180
181 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700182 def get_host_ip(cls, port):
183 if cls.host_ip_map.has_key(port):
184 return cls.host_ip_map[port]
185 cls.host_ip_map[port] = '192.168.1.{}'.format(port)
186 return cls.host_ip_map[port]
187
188 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700189 def host_load(cls, iface):
190 '''Have ONOS discover the hosts for dhcp-relay responses'''
191 port = g_subscriber_port_map[iface]
192 host = '173.17.1.{}'.format(port)
193 cmds = ( 'ifconfig {} 0'.format(iface),
194 'ifconfig {0} {1}'.format(iface, host),
195 'arping -I {0} {1} -c 2'.format(iface, host),
196 'ifconfig {} 0'.format(iface), )
197 for c in cmds:
198 os.system(c)
199
200 @classmethod
201 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
202 subnet = default_subnet_config):
203 conf = ''
204 for k, v in config.items():
205 conf += '{} {};\n'.format(k, v)
206
207 opts = ''
208 for k, v in options:
209 opts += 'option {} {};\n'.format(k, v)
210
211 subnet_config = ''
212 for _, v in subnet:
213 subnet_config += '{}\n'.format(v)
214
215 return '{}{}{}'.format(conf, opts, subnet_config)
216
217 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -0700218 def dhcpd_start(cls, intf_list = None,
A R Karthick8cf29ac2016-06-30 16:25:14 -0700219 config = default_config, options = default_options,
220 subnet = default_subnet_config):
221 '''Start the dhcpd server by generating the conf file'''
A R Karthickb03cecd2016-07-27 10:27:55 -0700222 if intf_list is None:
223 intf_list = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700224 ##stop dhcpd if already running
225 cls.dhcpd_stop()
226 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
227 subnet = subnet)
228 ##first touch dhcpd.leases if it doesn't exist
229 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
230 if os.access(lease_file, os.F_OK) is False:
231 with open(lease_file, 'w') as fd: pass
232
233 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
234 with open(conf_file, 'w') as fd:
235 fd.write(dhcp_conf)
236
237 #now configure the dhcpd interfaces for various subnets
238 index = 0
A R Karthick3026e482016-08-12 16:02:40 -0700239 intf_info = []
A R Karthick8cf29ac2016-06-30 16:25:14 -0700240 for ip,_ in subnet:
241 intf = intf_list[index]
A R Karthick3026e482016-08-12 16:02:40 -0700242 mac = cls.get_mac(intf)
243 intf_info.append((ip, mac))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700244 index += 1
245 os.system('ifconfig {} {}'.format(intf, ip))
246
247 intf_str = ','.join(intf_list)
248 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str)
249 log.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
250 ret = os.system(dhcpd_cmd)
251 assert_equal(ret, 0)
252 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -0700253 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700254 cls.relay_interfaces = intf_list
A R Karthick3026e482016-08-12 16:02:40 -0700255 cls.onos_dhcp_relay_load(*intf_info[0])
A R Karthick8cf29ac2016-06-30 16:25:14 -0700256
257 @classmethod
258 def dhcpd_stop(cls):
259 os.system('pkill -9 dhcpd')
260 for intf in cls.relay_interfaces:
261 os.system('ifconfig {} 0'.format(intf))
262
A R Karthickb03cecd2016-07-27 10:27:55 -0700263 cls.relay_interfaces = cls.relay_interfaces_last
264
A R Karthick3026e482016-08-12 16:02:40 -0700265 @classmethod
266 def get_mac(cls, iface):
267 if cls.interface_to_mac_map.has_key(iface):
268 return cls.interface_to_mac_map[iface]
A R Karthick8cf29ac2016-06-30 16:25:14 -0700269 mac = get_mac(iface, pad = 0)
A R Karthick3026e482016-08-12 16:02:40 -0700270 cls.interface_to_mac_map[iface] = mac
A R Karthick8cf29ac2016-06-30 16:25:14 -0700271 return mac
272
ChetanGaonker5860c182016-07-05 16:33:06 -0700273 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
274
275 self.ip_count = 0
276 self.failure_count = 0
277 self.start_time = 0
278 self.diff = 0
279 self.transaction_count = 0
280
281 mac = self.get_mac(iface)
282 self.host_load(iface)
283 ##we use the defaults for this test that serves as an example for others
284 ##You don't need to restart dhcpd server if retaining default config
285 config = self.default_config
286 options = self.default_options
287 subnet = self.default_subnet_config
288 dhcpd_interface_list = self.relay_interfaces
289 self.dhcpd_start(intf_list = dhcpd_interface_list,
290 config = config,
291 options = options,
292 subnet = subnet)
293 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
294 self.start_time = time.time()
295
296 while self.diff <= 60:
297
298 if only_discover:
299 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
300 log.info('Got dhcp client IP %s from server %s for mac %s' %
301 (cip, sip, mac))
302 else:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000303 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700304
305 if cip:
306 self.ip_count +=1
307 elif cip == None:
308 self.failure_count += 1
309 log.info('Failed to get ip')
310 if success_rate and self.ip_count > 0:
311 break
312
313 self.diff = round(time.time() - self.start_time, 0)
314
ChetanGaonker5860c182016-07-05 16:33:06 -0700315 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
316 self.transactions += (self.ip_count+self.failure_count)
317 self.running_time += self.diff
318 self.total_success += self.ip_count
319 self.total_failure += self.failure_count
320
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000321 def send_recv(self, mac=None, update_seed = False, validate = True):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700322 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
323 if validate:
324 assert_not_equal(cip, None)
325 assert_not_equal(sip, None)
ChetanGaonker5860c182016-07-05 16:33:06 -0700326 log.info('Got dhcp client IP %s from server %s for mac %s' %
327 (cip, sip, self.dhcp.get_mac(cip)[0]))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700328 return cip,sip
329
ChetanGaonker5860c182016-07-05 16:33:06 -0700330 def test_dhcpRelay_1request(self, iface = 'veth0'):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700331 mac = self.get_mac(iface)
332 self.host_load(iface)
333 ##we use the defaults for this test that serves as an example for others
334 ##You don't need to restart dhcpd server if retaining default config
335 config = self.default_config
336 options = self.default_options
337 subnet = self.default_subnet_config
338 dhcpd_interface_list = self.relay_interfaces
339 self.dhcpd_start(intf_list = dhcpd_interface_list,
340 config = config,
341 options = options,
342 subnet = subnet)
343 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000344 self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700345
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000346 def test_dhcpRelay_1request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
347 mac = self.get_mac(iface)
348 self.host_load(iface)
349 ##we use the defaults for this test that serves as an example for others
350 ##You don't need to restart dhcpd server if retaining default config
351 config = self.default_config
352 options = self.default_options
353 subnet = self.default_subnet_config
354 dhcpd_interface_list = self.relay_interfaces
355 self.dhcpd_start(intf_list = dhcpd_interface_list,
356 config = config,
357 options = options,
358 subnet = subnet)
359 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
360 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
361 assert_equal(cip,None)
362 log.info('dhcp server rejected client discover with invalid source mac, as expected')
363
364 def test_dhcpRelay_1request_with_invalid_source_mac_multicast(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 = '10.10.10.1', iface = iface)
378 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
379 assert_equal(cip,None)
380 log.info('dhcp server rejected client discover with invalid source mac, as expected')
381
382 def test_dhcpRelay_1request_with_invalid_source_mac_zero(self, iface = 'veth0'):
383 mac = self.get_mac(iface)
384 self.host_load(iface)
385 ##we use the defaults for this test that serves as an example for others
386 ##You don't need to restart dhcpd server if retaining default config
387 config = self.default_config
388 options = self.default_options
389 subnet = self.default_subnet_config
390 dhcpd_interface_list = self.relay_interfaces
391 self.dhcpd_start(intf_list = dhcpd_interface_list,
392 config = config,
393 options = options,
394 subnet = subnet)
395 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
396 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
397 assert_equal(cip,None)
398 log.info('dhcp server rejected client discover with invalid source mac, as expected')
399
400 def test_dhcpRelay_Nrequest(self, iface = 'veth0',requests=10):
ChetanGaonker5860c182016-07-05 16:33:06 -0700401 mac = self.get_mac(iface)
402 self.host_load(iface)
403 ##we use the defaults for this test that serves as an example for others
404 ##You don't need to restart dhcpd server if retaining default config
405 config = self.default_config
406 options = self.default_options
407 subnet = self.default_subnet_config
408 dhcpd_interface_list = self.relay_interfaces
409 self.dhcpd_start(intf_list = dhcpd_interface_list,
410 config = config,
411 options = options,
412 subnet = subnet)
413 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
414 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000415 for i in range(requests):
416 #mac = RandMAC()._fix()
417 #log.info('mac is %s'%mac)
418 cip, sip = self.send_recv(update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700419 if ip_map.has_key(cip):
420 log.info('IP %s given out multiple times' %cip)
421 assert_equal(False, ip_map.has_key(cip))
422 ip_map[cip] = sip
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000423 time.sleep(1)
ChetanGaonker5860c182016-07-05 16:33:06 -0700424
425 def test_dhcpRelay_1release(self, iface = 'veth0'):
426 mac = self.get_mac(iface)
427 self.host_load(iface)
428 ##we use the defaults for this test that serves as an example for others
429 ##You don't need to restart dhcpd server if retaining default config
430 config = self.default_config
431 options = self.default_options
432 subnet = self.default_subnet_config
433 dhcpd_interface_list = self.relay_interfaces
434 self.dhcpd_start(intf_list = dhcpd_interface_list,
435 config = config,
436 options = options,
437 subnet = subnet)
438 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000439 cip, sip = self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700440 log.info('Releasing ip %s to server %s' %(cip, sip))
441 assert_equal(self.dhcp.release(cip), True)
442 log.info('Triggering DHCP discover again after release')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000443 cip2, sip2 = self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700444 log.info('Verifying released IP was given back on rediscover')
445 assert_equal(cip, cip2)
446 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
447 assert_equal(self.dhcp.release(cip2), True)
448
449 def test_dhcpRelay_Nrelease(self, iface = 'veth0'):
A R Karthickb03cecd2016-07-27 10:27:55 -0700450 mac = None
ChetanGaonker5860c182016-07-05 16:33:06 -0700451 self.host_load(iface)
452 ##we use the defaults for this test that serves as an example for others
453 ##You don't need to restart dhcpd server if retaining default config
454 config = self.default_config
455 options = self.default_options
456 subnet = self.default_subnet_config
457 dhcpd_interface_list = self.relay_interfaces
458 self.dhcpd_start(intf_list = dhcpd_interface_list,
459 config = config,
460 options = options,
461 subnet = subnet)
462 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
463 ip_map = {}
464 for i in range(10):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000465 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700466 if ip_map.has_key(cip):
467 log.info('IP %s given out multiple times' %cip)
468 assert_equal(False, ip_map.has_key(cip))
469 ip_map[cip] = sip
470
471 for ip in ip_map.keys():
472 log.info('Releasing IP %s' %ip)
473 assert_equal(self.dhcp.release(ip), True)
474
475 ip_map2 = {}
476 log.info('Triggering DHCP discover again after release')
477 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
478 for i in range(len(ip_map.keys())):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000479 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700480 ip_map2[cip] = sip
481
482 log.info('Verifying released IPs were given back on rediscover')
483 if ip_map != ip_map2:
484 log.info('Map before release %s' %ip_map)
485 log.info('Map after release %s' %ip_map2)
486 assert_equal(ip_map, ip_map2)
487
488 def test_dhcpRelay_starvation(self, iface = 'veth0'):
489 mac = self.get_mac(iface)
490 self.host_load(iface)
491 ##we use the defaults for this test that serves as an example for others
492 ##You don't need to restart dhcpd server if retaining default config
493 config = self.default_config
494 options = self.default_options
495 subnet = self.default_subnet_config
496 dhcpd_interface_list = self.relay_interfaces
497 self.dhcpd_start(intf_list = dhcpd_interface_list,
498 config = config,
499 options = options,
500 subnet = subnet)
ChetanGaonker5860c182016-07-05 16:33:06 -0700501 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
502 log.info('Verifying 1 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000503 count = 0
ChetanGaonker5860c182016-07-05 16:33:06 -0700504 while True:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000505 #mac = RandMAC()._fix()
506 cip, sip = self.send_recv(update_seed = True,validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700507 if cip is None:
508 break
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000509 else:
510 count += 1
511 assert_equal(count,91)
ChetanGaonker5860c182016-07-05 16:33:06 -0700512 log.info('Verifying 2 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000513 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700514 assert_equal(cip, None)
515 assert_equal(sip, None)
516
517 def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'):
518 mac = self.get_mac(iface)
519 self.host_load(iface)
520 ##we use the defaults for this test that serves as an example for others
521 ##You don't need to restart dhcpd server if retaining default config
522 config = self.default_config
523 options = self.default_options
524 subnet = self.default_subnet_config
525 dhcpd_interface_list = self.relay_interfaces
526 self.dhcpd_start(intf_list = dhcpd_interface_list,
527 config = config,
528 options = options,
529 subnet = subnet)
530 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
531 cip, sip, mac, _ = self.dhcp.only_discover()
532 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
533 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000534 assert_not_equal(cip, None)
ChetanGaonker5860c182016-07-05 16:33:06 -0700535 log.info('Triggering DHCP discover again.')
536 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000537 assert_equal(new_cip, cip)
538 log.info('got same ip to smae the client when sent discover again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700539
540 def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'):
541 mac = self.get_mac(iface)
542 self.host_load(iface)
543 ##we use the defaults for this test that serves as an example for others
544 ##You don't need to restart dhcpd server if retaining default config
545 config = self.default_config
546 options = self.default_options
547 subnet = self.default_subnet_config
548 dhcpd_interface_list = self.relay_interfaces
549 self.dhcpd_start(intf_list = dhcpd_interface_list,
550 config = config,
551 options = options,
552 subnet = subnet)
553 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
554 log.info('Sending DHCP discover and DHCP request.')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000555 cip, sip = self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700556 mac = self.dhcp.get_mac(cip)[0]
557 log.info("Sending DHCP request again.")
558 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000559 assert_equal(new_cip, cip)
560 log.info('got same ip to smae the client when sent request again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700561
562 def test_dhcpRelay_client_desired_address(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 = '192.168.1.31', iface = iface)
576 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000577 assert_equal(cip,self.dhcp.seed_ip)
578 log.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700579 (cip, sip, mac) )
ChetanGaonker5860c182016-07-05 16:33:06 -0700580
581 def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'):
582 mac = self.get_mac(iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000583
ChetanGaonker5860c182016-07-05 16:33:06 -0700584 self.host_load(iface)
585 ##we use the defaults for this test that serves as an example for others
586 ##You don't need to restart dhcpd server if retaining default config
587 config = self.default_config
588 options = self.default_options
589 subnet = self.default_subnet_config
590 dhcpd_interface_list = self.relay_interfaces
591 self.dhcpd_start(intf_list = dhcpd_interface_list,
592 config = config,
593 options = options,
594 subnet = subnet)
595 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
596 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000597 assert_not_equal(cip,None)
598 assert_not_equal(cip,self.dhcp.seed_ip)
599 log.info('server offered IP from its pool when requested out of pool IP, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700600
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700601 def test_dhcpRelay_nak_packet(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700602 mac = self.get_mac(iface)
603 self.host_load(iface)
604 ##we use the defaults for this test that serves as an example for others
605 ##You don't need to restart dhcpd server if retaining default config
606 config = self.default_config
607 options = self.default_options
608 subnet = self.default_subnet_config
609 dhcpd_interface_list = self.relay_interfaces
610 self.dhcpd_start(intf_list = dhcpd_interface_list,
611 config = config,
612 options = options,
613 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000614 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
ChetanGaonker5860c182016-07-05 16:33:06 -0700615 cip, sip, mac, _ = self.dhcp.only_discover()
616 log.info('Got dhcp client IP %s from server %s for mac %s .' %
617 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000618 assert_not_equal(cip, None)
619 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
620 assert_equal(new_cip, None)
621 log.info('server sent NAK packet when requested other IP than that server offered')
ChetanGaonker5860c182016-07-05 16:33:06 -0700622
623
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000624 def test_dhcpRelay_client_requests_specific_lease_time_in_discover(self, iface = 'veth0',lease_time=700):
ChetanGaonker5860c182016-07-05 16:33:06 -0700625 mac = self.get_mac(iface)
626 self.host_load(iface)
627 ##we use the defaults for this test that serves as an example for others
628 ##You don't need to restart dhcpd server if retaining default config
629 config = self.default_config
630 options = self.default_options
631 subnet = self.default_subnet_config
632 dhcpd_interface_list = self.relay_interfaces
633 self.dhcpd_start(intf_list = dhcpd_interface_list,
634 config = config,
635 options = options,
636 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000637 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
638 self.dhcp.return_option = 'lease'
639 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
640 assert_equal(lval, lease_time)
641 log.info('dhcp server offered IP address with client requested lease time')
ChetanGaonker5860c182016-07-05 16:33:06 -0700642
643 def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'):
644 mac = self.get_mac(iface)
645 self.host_load(iface)
646 ##we use the defaults for this test that serves as an example for others
647 ##You don't need to restart dhcpd server if retaining default config
648 config = self.default_config
649 options = self.default_options
650 subnet = self.default_subnet_config
651 dhcpd_interface_list = self.relay_interfaces
652 self.dhcpd_start(intf_list = dhcpd_interface_list,
653 config = config,
654 options = options,
655 subnet = subnet)
656 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
657 cip, sip, mac, _ = self.dhcp.only_discover()
658 log.info('Got dhcp client IP %s from server %s for mac %s .' %
659 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000660 assert_not_equal(cip, None)
661 new_cip, new_sip = self.dhcp.only_request(cip, mac)
662 log.info('client rebooting...')
663 os.system('ifconfig '+iface+' down')
664 time.sleep(5)
665 os.system('ifconfig '+iface+' up')
666 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
667 assert_equal(new_cip2, cip)
668 log.info('client got same IP after reboot, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700669
ChetanGaonker5860c182016-07-05 16:33:06 -0700670
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000671 def test_dhcpRelay_after_server_reboot(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700672 mac = self.get_mac(iface)
673 self.host_load(iface)
674 ##we use the defaults for this test that serves as an example for others
675 ##You don't need to restart dhcpd server if retaining default config
676 config = self.default_config
677 options = self.default_options
678 subnet = self.default_subnet_config
679 dhcpd_interface_list = self.relay_interfaces
680 self.dhcpd_start(intf_list = dhcpd_interface_list,
681 config = config,
682 options = options,
683 subnet = subnet)
684 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
685 cip, sip, mac, _ = self.dhcp.only_discover()
686 log.info('Got dhcp client IP %s from server %s for mac %s .' %
687 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000688 assert_not_equal(cip, None)
689 new_cip, new_sip = self.dhcp.only_request(cip, mac)
690 log.info('server rebooting...')
691 self.tearDownClass()
692 new_cip, new_sip = self.dhcp.only_request(cip, mac)
693 assert_equal(new_cip,None)
694 self.setUpClass()
695 new_cip, new_sip = self.dhcp.only_request(cip, mac)
696 assert_equal(new_cip, cip)
697 log.info('client got same IP after server rebooted, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700698
699
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000700 def test_dhcpRelay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
ChetanGaonker5860c182016-07-05 16:33:06 -0700701 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)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000714 self.dhcp.return_option = 'lease'
ChetanGaonker5860c182016-07-05 16:33:06 -0700715 log.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000716 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
717 assert_equal(lval,lease_time)
718 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
719 assert_equal(new_cip,cip)
720 assert_not_equal(lval, lease_time) #Negative Test Case
721 log.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700722
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000723 def test_dhcpRelay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
ChetanGaonker5860c182016-07-05 16:33:06 -0700724 mac = self.get_mac(iface)
725 self.host_load(iface)
726 ##we use the defaults for this test that serves as an example for others
727 ##You don't need to restart dhcpd server if retaining default config
728 config = self.default_config
729 options = self.default_options
730 subnet = self.default_subnet_config
731 dhcpd_interface_list = self.relay_interfaces
732 self.dhcpd_start(intf_list = dhcpd_interface_list,
733 config = config,
734 options = options,
735 subnet = subnet)
736 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
737 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000738 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
739 assert_equal(new_cip,cip)
740 assert_equal(lval, lease_time)
741 log.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700742
743 def test_dhcpRelay_client_renew_time(self, iface = 'veth0'):
744 mac = self.get_mac(iface)
745 self.host_load(iface)
746 ##we use the defaults for this test that serves as an example for others
747 ##You don't need to restart dhcpd server if retaining default config
748 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000749 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700750 options = self.default_options + new_options
751 subnet = self.default_subnet_config
752 dhcpd_interface_list = self.relay_interfaces
753 self.dhcpd_start(intf_list = dhcpd_interface_list,
754 config = config,
755 options = options,
756 subnet = subnet)
757 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
758 cip, sip, mac, _ = self.dhcp.only_discover()
759 log.info('Got dhcp client IP %s from server %s for mac %s .' %
760 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000761 assert_not_equal(cip,None)
762 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
763 log.info('waiting for renew time..')
764 time.sleep(lval)
765 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
766 assert_equal(latest_cip, cip)
767 log.info('server renewed client IP when client sends request after renew time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700768
769
770 def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'):
771 mac = self.get_mac(iface)
772 self.host_load(iface)
773 ##we use the defaults for this test that serves as an example for others
774 ##You don't need to restart dhcpd server if retaining default config
775 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000776 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700777 options = self.default_options + new_options
778 subnet = self.default_subnet_config
779 dhcpd_interface_list = self.relay_interfaces
780 self.dhcpd_start(intf_list = dhcpd_interface_list,
781 config = config,
782 options = options,
783 subnet = subnet)
784 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
785 cip, sip, mac, _ = self.dhcp.only_discover()
786 log.info('Got dhcp client IP %s from server %s for mac %s .' %
787 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000788 assert_not_equal(cip,None)
789 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
790 log.info('waiting for rebind time..')
791 time.sleep(lval)
792 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
793 assert_equal(latest_cip, cip)
794 log.info('server renewed client IP when client sends request after rebind time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700795
796
797 def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'):
798 mac = self.get_mac(iface)
799 self.host_load(iface)
800 ##we use the defaults for this test that serves as an example for others
801 ##You don't need to restart dhcpd server if retaining default config
802 config = self.default_config
803 options = self.default_options
804 subnet = self.default_subnet_config
805 dhcpd_interface_list = self.relay_interfaces
806 self.dhcpd_start(intf_list = dhcpd_interface_list,
807 config = config,
808 options = options,
809 subnet = subnet)
810 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
811 expected_subnet = '255.255.255.0'
812 self.dhcp.return_option = 'subnet'
813
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000814 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
ChetanGaonker5860c182016-07-05 16:33:06 -0700815 log.info('Got dhcp client IP %s from server %s for mac %s .' %
816 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000817 assert_equal(subnet_mask,expected_subnet)
818 log.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700819
820
821 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
822 mac = self.get_mac(iface)
823 self.host_load(iface)
824 ##we use the defaults for this test that serves as an example for others
825 ##You don't need to restart dhcpd server if retaining default config
826 config = self.default_config
827 options = self.default_options
828 subnet = self.default_subnet_config
829 dhcpd_interface_list = self.relay_interfaces
830 self.dhcpd_start(intf_list = dhcpd_interface_list,
831 config = config,
832 options = options,
833 subnet = subnet)
834 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
835
836 cip, sip, mac, _ = self.dhcp.only_discover()
837 log.info('Got dhcp client IP %s from server %s for mac %s .' %
838 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000839 assert_not_equal(cip,None)
840 self.dhcp.send_different_option = 'subnet'
841 new_cip, new_sip = self.dhcp.only_request(cip, mac)
842 assert_equal(new_cip, cip)
843 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700844
845
846 def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'):
847 mac = self.get_mac(iface)
848 self.host_load(iface)
849 ##we use the defaults for this test that serves as an example for others
850 ##You don't need to restart dhcpd server if retaining default config
851 config = self.default_config
852 config = self.default_config
853 new_options = [('routers', '20.20.20.1')]
854 options = self.default_options + new_options
855 subnet = self.default_subnet_config
856 dhcpd_interface_list = self.relay_interfaces
857 self.dhcpd_start(intf_list = dhcpd_interface_list,
858 config = config,
859 options = options,
860 subnet = subnet)
861 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
862 expected_router_address = '20.20.20.1'
863 self.dhcp.return_option = 'router'
864
865 cip, sip, mac, router_address_value = self.dhcp.only_discover()
866 log.info('Got dhcp client IP %s from server %s for mac %s .' %
867 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000868 assert_equal(expected_router_address, router_address_value)
869 log.info('router address in server offer packet is same as configured router address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700870
871
872 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
873 mac = self.get_mac(iface)
874 self.host_load(iface)
875 ##we use the defaults for this test that serves as an example for others
876 ##You don't need to restart dhcpd server if retaining default config
877 config = self.default_config
878 options = self.default_options
879 subnet = self.default_subnet_config
880 dhcpd_interface_list = self.relay_interfaces
881 self.dhcpd_start(intf_list = dhcpd_interface_list,
882 config = config,
883 options = options,
884 subnet = subnet)
885 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
886
887 cip, sip, mac, _ = self.dhcp.only_discover()
888 log.info('Got dhcp client IP %s from server %s for mac %s .' %
889 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000890 assert_not_equal(cip,None)
891 self.dhcp.send_different_option = 'router'
892 new_cip, new_sip = self.dhcp.only_request(cip, mac)
893 assert_equal(new_cip, cip)
894 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700895
896
897 def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'):
898 mac = self.get_mac(iface)
899 self.host_load(iface)
900 ##we use the defaults for this test that serves as an example for others
901 ##You don't need to restart dhcpd server if retaining default config
902 config = self.default_config
903 options = self.default_options
904 subnet = self.default_subnet_config
905 dhcpd_interface_list = self.relay_interfaces
906 self.dhcpd_start(intf_list = dhcpd_interface_list,
907 config = config,
908 options = options,
909 subnet = subnet)
910 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
911 expected_broadcast_address = '192.168.1.255'
912 self.dhcp.return_option = 'broadcast_address'
913
914 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
915 log.info('Got dhcp client IP %s from server %s for mac %s .' %
916 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000917 assert_equal(expected_broadcast_address, broadcast_address_value)
918 log.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700919
920 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
921 mac = self.get_mac(iface)
922 self.host_load(iface)
923 ##we use the defaults for this test that serves as an example for others
924 ##You don't need to restart dhcpd server if retaining default config
925 config = self.default_config
926 options = self.default_options
927 subnet = self.default_subnet_config
928 dhcpd_interface_list = self.relay_interfaces
929 self.dhcpd_start(intf_list = dhcpd_interface_list,
930 config = config,
931 options = options,
932 subnet = subnet)
933 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
934
935 cip, sip, mac, _ = self.dhcp.only_discover()
936 log.info('Got dhcp client IP %s from server %s for mac %s .' %
937 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000938 assert_not_equal(cip,None)
939 self.dhcp.send_different_option = 'broadcast_address'
940 new_cip, new_sip = self.dhcp.only_request(cip, mac)
941 assert_equal(new_cip, cip)
942 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700943
ChetanGaonker5860c182016-07-05 16:33:06 -0700944
945 def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'):
946 mac = self.get_mac(iface)
947 self.host_load(iface)
948 ##we use the defaults for this test that serves as an example for others
949 ##You don't need to restart dhcpd server if retaining default config
950 config = self.default_config
951 options = self.default_options
952 subnet = self.default_subnet_config
953 dhcpd_interface_list = self.relay_interfaces
954 self.dhcpd_start(intf_list = dhcpd_interface_list,
955 config = config,
956 options = options,
957 subnet = subnet)
958 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
959 expected_dns_address = '192.168.1.1'
960 self.dhcp.return_option = 'dns'
961
962 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
963 log.info('Got dhcp client IP %s from server %s for mac %s .' %
964 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000965 assert_equal(expected_dns_address, dns_address_value)
966 log.info('dns address in server offer packet is same as configured dns address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700967
968 def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
969 mac = self.get_mac(iface)
970 self.host_load(iface)
971 ##we use the defaults for this test that serves as an example for others
972 ##You don't need to restart dhcpd server if retaining default config
973 config = self.default_config
974 options = self.default_options
975 subnet = self.default_subnet_config
976 dhcpd_interface_list = self.relay_interfaces
977 self.dhcpd_start(intf_list = dhcpd_interface_list,
978 config = config,
979 options = options,
980 subnet = subnet)
981 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
982
983 cip, sip, mac, _ = self.dhcp.only_discover()
984 log.info('Got dhcp client IP %s from server %s for mac %s .' %
985 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000986 assert_not_equal(cip,None)
987 self.dhcp.send_different_option = 'dns'
988 new_cip, new_sip = self.dhcp.only_request(cip, mac)
989 assert_equal(new_cip, cip)
990 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700991
ChetanGaonker5860c182016-07-05 16:33:06 -0700992
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700993 def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700994
995 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700996 self.stats()
997 log.info("Statistics for run %d",i)
998 log.info("----------------------------------------------------------------------------------")
999 log.info("No. of transactions No. of successes No. of failures Running Time ")
1000 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1001 log.info("----------------------------------------------------------------------------------")
1002 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker5860c182016-07-05 16:33:06 -07001003
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001004 log.info("Final Statistics for total transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001005 log.info("----------------------------------------------------------------------------------")
1006 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1007 log.info(" %d %d %d %d" %(self.transactions,
1008 self.total_success, self.total_failure, self.running_time))
1009 log.info("----------------------------------------------------------------------------------")
1010 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1011
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001012 def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001013
1014 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001015 self.stats(success_rate = True)
1016 log.info("Statistics for run %d",i)
1017 log.info("----------------------------------------------------------------------------------")
1018 log.info("No. of consecutive successful transactions Running Time ")
1019 log.info(" %d %d " %(self.ip_count, self.diff))
1020 log.info("----------------------------------------------------------------------------------")
1021 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1022 log.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001023
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001024 log.info("Final Statistics for total successful transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001025 log.info("----------------------------------------------------------------------------------")
1026 log.info("Total transactions Total No. of consecutive successes Running Time ")
1027 log.info(" %d %d %d " %(self.transactions,
1028 self.total_success, self.running_time))
1029 log.info("----------------------------------------------------------------------------------")
1030 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1031 log.info("----------------------------------------------------------------------------------")
1032
1033
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001034 def test_dhcpRelay_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001035
1036 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001037 self.stats(only_discover = True)
1038 log.info("----------------------------------------------------------------------------------")
1039 log.info("Statistics for run %d of sending only DHCP Discover",i)
1040 log.info("----------------------------------------------------------------------------------")
1041 log.info("No. of transactions No. of successes No. of failures Running Time ")
1042 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1043 log.info("----------------------------------------------------------------------------------")
1044 log.info("No. of clients per second in run %d:%f "
1045 %(i, self.transaction_count))
1046 log.info("----------------------------------------------------------------------------------")
1047 log.info("Final Statistics for total transactions of sending only DHCP Discover")
ChetanGaonker5860c182016-07-05 16:33:06 -07001048 log.info("----------------------------------------------------------------------------------")
1049 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1050 log.info(" %d %d %d %d" %(self.transactions,
1051 self.total_success, self.total_failure, self.running_time))
1052 log.info("----------------------------------------------------------------------------------")
1053 log.info("Average no. of clients per second: %d ",
1054 round(self.transactions/self.running_time,0))
1055 log.info("----------------------------------------------------------------------------------")
1056
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001057 def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001058
1059 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001060 self.stats(success_rate = True, only_discover = True)
1061 log.info("----------------------------------------------------------------------------------")
1062 log.info("Statistics for run %d for sending only DHCP Discover",i)
1063 log.info("----------------------------------------------------------------------------------")
1064 log.info("No. of consecutive successful transactions Running Time ")
1065 log.info(" %d %d " %(self.ip_count, self.diff))
1066 log.info("----------------------------------------------------------------------------------")
1067 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1068 log.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001069
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001070 log.info("Final Statistics for total successful transactions")
ChetanGaonker5860c182016-07-05 16:33:06 -07001071 log.info("----------------------------------------------------------------------------------")
1072 log.info("Total transactions Total No. of consecutive successes Running Time ")
1073 log.info(" %d %d %d " %(self.transactions,
1074 self.total_success, self.running_time))
1075 log.info("----------------------------------------------------------------------------------")
1076 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1077 log.info("----------------------------------------------------------------------------------")
1078
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001079 def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'):
1080
1081 config = self.default_config
1082 options = self.default_options
1083 subnet = [ ('192.168.1.2',
1084'''
1085subnet 192.168.0.0 netmask 255.255.0.0 {
1086 range 192.168.1.10 192.168.2.100;
1087}
1088'''), ]
1089
1090 dhcpd_interface_list = self.relay_interfaces
1091 self.dhcpd_start(intf_list = dhcpd_interface_list,
1092 config = config,
1093 options = options,
1094 subnet = subnet)
1095
1096 for key in (key for key in g_subscriber_port_map if key < 100):
1097 self.host_load(g_subscriber_port_map[key])
1098
1099 def thread_fun(i):
1100 mac = self.get_mac('veth{}'.format(i))
1101 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1102 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1103 self.lock.acquire()
1104
1105 if cip:
1106 self.ip_count += 1
1107
1108 elif cip is None:
1109 self.failure_count += 1
1110
1111 self.lock.notify_all()
1112 self.lock.release()
1113
1114 for i in range (1,4):
1115 self.ip_count = 0
1116 self.failure_count = 0
1117 self.start_time = 0
1118 self.diff = 0
1119 self.transaction_count = 0
1120 self.start_time = time.time()
1121
1122 while self.diff <= 60:
1123 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1124 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1125 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1126 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1127 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1128 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1129
1130 t.start()
1131 t1.start()
1132 t2.start()
1133 t3.start()
1134 t4.start()
1135 t5.start()
1136
1137 t.join()
1138 t1.join()
1139 t2.join()
1140 t3.join()
1141 t4.join()
1142 t5.join()
1143
1144 self.diff = round(time.time() - self.start_time, 0)
1145
1146 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1147
1148 self.transactions += (self.ip_count+self.failure_count)
1149 self.running_time += self.diff
1150 self.total_success += self.ip_count
1151 self.total_failure += self.failure_count
1152
1153
1154 log.info("----------------------------------------------------------------------------------")
1155 log.info("Statistics for run %d",i)
1156 log.info("----------------------------------------------------------------------------------")
1157 log.info("No. of transactions No. of successes No. of failures Running Time ")
1158 log.info(" %d %d %d %d"
1159 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1160 log.info("----------------------------------------------------------------------------------")
1161 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1162 log.info("----------------------------------------------------------------------------------")
1163
1164 log.info("----------------------------------------------------------------------------------")
1165 log.info("Final Statistics for total transactions")
1166 log.info("----------------------------------------------------------------------------------")
1167 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1168 log.info(" %d %d %d %d" %(self.transactions,
1169 self.total_success, self.total_failure, self.running_time))
1170
1171 log.info("----------------------------------------------------------------------------------")
1172 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1173 log.info("----------------------------------------------------------------------------------")
1174
1175 def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
1176
1177 config = self.default_config
1178 options = self.default_options
1179 subnet = [ ('192.168.1.2',
1180'''
1181subnet 192.168.0.0 netmask 255.255.0.0 {
1182 range 192.168.1.10 192.168.2.100;
1183}
1184'''), ]
1185
1186 dhcpd_interface_list = self.relay_interfaces
1187 self.dhcpd_start(intf_list = dhcpd_interface_list,
1188 config = config,
1189 options = options,
1190 subnet = subnet)
1191 failure_dir = {}
1192
1193 for key in (key for key in g_subscriber_port_map if key != 100):
1194 self.host_load(g_subscriber_port_map[key])
1195
1196 def thread_fun(i, j):
1197# log.info("Thread Name:%s",current_thread().name)
1198# failure_dir[current_thread().name] = True
1199 while failure_dir.has_key(current_thread().name) is False:
1200 mac = RandMAC()._fix()
1201 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1202 i += 2
1203 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1204 self.lock.acquire()
1205
1206 if cip:
1207 self.ip_count += 1
1208 self.lock.notify_all()
1209 self.lock.release()
1210 elif cip is None:
1211 self.failure_count += 1
1212 failure_dir[current_thread().name] = True
1213 self.lock.notify_all()
1214 self.lock.release()
1215 break
1216# self.lock.notify_all()
1217# self.lock.release()
1218
1219 for i in range (1,4):
1220 failure_dir = {}
1221 self.ip_count = 0
1222 self.failure_count = 0
1223 self.start_time = 0
1224 self.diff = 0
1225 self.transaction_count = 0
1226 self.start_time = time.time()
1227
1228 while len(failure_dir) != 6:
1229 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1230 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1231 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1232 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1233 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1234 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1235
1236 t.start()
1237 t1.start()
1238 t2.start()
1239 t3.start()
1240 t4.start()
1241 t5.start()
1242
1243 t.join()
1244 t1.join()
1245 t2.join()
1246 t3.join()
1247 t4.join()
1248 t5.join()
1249
1250 self.diff = round(time.time() - self.start_time, 0)
1251 self.transaction_count = round((self.ip_count)/self.diff, 2)
1252
1253 self.transactions += (self.ip_count+self.failure_count)
1254 self.running_time += self.diff
1255 self.total_success += self.ip_count
1256 self.total_failure += self.failure_count
1257
1258
1259 log.info("Statistics for run %d",i)
1260 log.info("----------------------------------------------------------------------------------")
1261 log.info("No. of consecutive successful transactions Running Time ")
1262 log.info(" %d %d " %(self.ip_count, self.diff))
1263 log.info("----------------------------------------------------------------------------------")
1264 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1265 log.info("----------------------------------------------------------------------------------")
1266
1267 log.info("Final Statistics for total successful transactions")
1268 log.info("----------------------------------------------------------------------------------")
1269 log.info("Total transactions Total No. of consecutive successes Running Time ")
1270 log.info(" %d %d %d " %(self.transactions,
1271 self.total_success, self.running_time))
1272 log.info("----------------------------------------------------------------------------------")
1273 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1274 log.info("----------------------------------------------------------------------------------")
1275
1276 def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'):
1277
1278 config = self.default_config
1279 options = self.default_options
1280 subnet = [ ('192.168.1.2',
1281'''
1282subnet 192.168.0.0 netmask 255.255.0.0 {
1283 range 192.168.1.10 192.168.2.100;
1284}
1285'''), ]
1286
1287 dhcpd_interface_list = self.relay_interfaces
1288 self.dhcpd_start(intf_list = dhcpd_interface_list,
1289 config = config,
1290 options = options,
1291 subnet = subnet)
1292
1293 for key in (key for key in g_subscriber_port_map if key < 100):
1294 self.host_load(g_subscriber_port_map[key])
1295
1296 def thread_fun(i):
1297# mac = self.get_mac('veth{}'.format(i))
1298 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1299 log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1300 self.lock.acquire()
1301
1302 if cip:
1303 self.ip_count += 1
1304 elif cip is None:
1305 self.failure_count += 1
1306
1307 self.lock.notify_all()
1308 self.lock.release()
1309
1310 for i in range (1,4):
1311 self.ip_count = 0
1312 self.failure_count = 0
1313 self.start_time = 0
1314 self.diff = 0
1315 self.transaction_count = 0
1316 self.start_time = time.time()
1317
1318 while self.diff <= 60:
1319 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1320 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1321 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1322 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1323 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1324 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1325
1326 t.start()
1327 t1.start()
1328 t2.start()
1329 t3.start()
1330 t4.start()
1331 t5.start()
1332
1333 t.join()
1334 t1.join()
1335 t2.join()
1336 t3.join()
1337 t4.join()
1338 t5.join()
1339
1340 self.diff = round(time.time() - self.start_time, 0)
1341 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1342 self.transactions += (self.ip_count+self.failure_count)
1343 self.running_time += self.diff
1344 self.total_success += self.ip_count
1345 self.total_failure += self.failure_count
1346
1347 log.info("----------------------------------------------------------------------------------")
1348 log.info("Statistics for run %d of sending only DHCP Discover",i)
1349 log.info("----------------------------------------------------------------------------------")
1350 log.info("No. of transactions No. of successes No. of failures Running Time ")
1351 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1352 log.info("----------------------------------------------------------------------------------")
1353 log.info("No. of clients per second in run %d:%f "
1354 %(i, self.transaction_count))
1355 log.info("----------------------------------------------------------------------------------")
1356
1357 log.info("Final Statistics for total transactions of sending only DHCP Discover")
1358 log.info("----------------------------------------------------------------------------------")
1359 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1360 log.info(" %d %d %d %d" %(self.transactions,
1361 self.total_success, self.total_failure, self.running_time))
1362 log.info("----------------------------------------------------------------------------------")
1363 log.info("Average no. of clients per second: %d ",
1364 round(self.transactions/self.running_time,0))
1365 log.info("----------------------------------------------------------------------------------")
1366
1367
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001368 def test_dhcpRelay_client_conflict(self, iface = 'veth0'):
1369 mac = self.get_mac(iface)
1370 self.host_load(iface)
1371 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1372 cip, sip, mac, _ = self.dhcp.only_discover()
1373 log.info('Got dhcp client IP %s from server %s for mac %s.' %
1374 (cip, sip, mac) )
1375 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1376 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1377 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1378 log.info('Got dhcp client IP %s from server %s for mac %s.' %
1379 (new_cip, new_sip, new_mac) )
1380 log.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1381 log.info("Now sending DHCP Request for old DHCP discover.")
1382 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1383 if new_cip is None:
1384 log.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1385 %(new_cip, new_sip, new_mac) )
1386 elif new_cip:
1387 log.info('Got dhcp client IP %s from server %s for mac %s.Which is not expected behavior as IP %s is already consumed.'
1388 %(new_cip, new_sip, new_mac, new_cip) )
1389 assert_equal(new_cip, None)