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