blob: db4dd3c75e0edb73332b877cd257965613367045 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
16
A R Karthick8cf29ac2016-06-30 16:25:14 -070017#
18# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
23#
24# http://www.apache.org/licenses/LICENSE-2.0
25#
26# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +000028# WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied.
A R Karthick8cf29ac2016-06-30 16:25:14 -070029# See the License for the specific language governing permissions and
30# limitations under the License.
31#
32import unittest
33from nose.tools import *
34from nose.twistedtools import reactor, deferred
35from twisted.internet import defer
A R Karthick8cf29ac2016-06-30 16:25:14 -070036import time
ChetanGaonker5b984cb2016-07-12 15:50:49 -070037import os, sys
A R Karthick8cf29ac2016-06-30 16:25:14 -070038from DHCP import DHCPTest
A R Karthick76a497a2017-04-12 10:59:39 -070039from CordTestUtils import get_mac, log_test
A.R Karthickbe7768c2017-03-17 11:39:41 -070040from OnosCtrl import OnosCtrl
A R Karthickb03cecd2016-07-27 10:27:55 -070041from OltConfig import OltConfig
A R Karthick4e0c0912016-08-17 16:57:42 -070042from CordTestServer import cord_test_onos_restart
A R Karthick9313b762016-11-07 13:14:35 -080043from CordLogger import CordLogger
A R Karthick8cf29ac2016-06-30 16:25:14 -070044from portmaps import g_subscriber_port_map
ChetanGaonker5b984cb2016-07-12 15:50:49 -070045import threading, random
46from threading import current_thread
A R Karthick76a497a2017-04-12 10:59:39 -070047log_test.setLevel('INFO')
A R Karthick8cf29ac2016-06-30 16:25:14 -070048
A R Karthick9313b762016-11-07 13:14:35 -080049class dhcprelay_exchange(CordLogger):
A R Karthick8cf29ac2016-06-30 16:25:14 -070050
51 app = 'org.onosproject.dhcprelay'
52 app_dhcp = 'org.onosproject.dhcp'
A R Karthickb03cecd2016-07-27 10:27:55 -070053 relay_interfaces_last = ()
A R Karthick8cf29ac2016-06-30 16:25:14 -070054 interface_to_mac_map = {}
A R Karthick3026e482016-08-12 16:02:40 -070055 host_ip_map = {}
56 test_path = os.path.dirname(os.path.realpath(__file__))
57 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
A.R Karthick5968e0d2017-05-16 14:50:46 -070058 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
A R Karthick8cf29ac2016-06-30 16:25:14 -070059 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
60 default_options = [ ('subnet-mask', '255.255.255.0'),
61 ('broadcast-address', '192.168.1.255'),
62 ('domain-name-servers', '192.168.1.1'),
63 ('domain-name', '"mydomain.cord-tester"'),
64 ]
65 ##specify the IP for the dhcp interface matching the subnet and subnet config
66 ##this is done for each interface dhcpd server would be listening on
67 default_subnet_config = [ ('192.168.1.2',
68'''
69subnet 192.168.1.0 netmask 255.255.255.0 {
70 range 192.168.1.10 192.168.1.100;
71}
72'''), ]
ChetanGaonker5b984cb2016-07-12 15:50:49 -070073
74 lock = threading.Condition()
ChetanGaonker5860c182016-07-05 16:33:06 -070075 ip_count = 0
76 failure_count = 0
77 start_time = 0
78 diff = 0
79
80 transaction_count = 0
81 transactions = 0
82 running_time = 0
83 total_success = 0
84 total_failure = 0
A R Karthick4e0c0912016-08-17 16:57:42 -070085 #just in case we want to reset ONOS to default network cfg after relay tests
86 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
A R Karthickbd82f362016-11-10 15:08:52 -080087 configs = {}
ChetanGaonker5860c182016-07-05 16:33:06 -070088
A R Karthick8cf29ac2016-06-30 16:25:14 -070089 @classmethod
90 def setUpClass(cls):
91 ''' Activate the dhcprelay app'''
92 OnosCtrl(cls.app_dhcp).deactivate()
93 time.sleep(3)
94 cls.onos_ctrl = OnosCtrl(cls.app)
95 status, _ = cls.onos_ctrl.activate()
96 assert_equal(status, True)
97 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070098 cls.dhcp_relay_setup()
A R Karthick8cf29ac2016-06-30 16:25:14 -070099 ##start dhcpd initially with default config
100 cls.dhcpd_start()
A R Karthick8cf29ac2016-06-30 16:25:14 -0700101
102 @classmethod
103 def tearDownClass(cls):
104 '''Deactivate the dhcp relay app'''
105 try:
106 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
107 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
108 except: pass
109 cls.onos_ctrl.deactivate()
110 cls.dhcpd_stop()
A R Karthick4e0c0912016-08-17 16:57:42 -0700111 cls.dhcp_relay_cleanup()
A R Karthick8cf29ac2016-06-30 16:25:14 -0700112
113 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -0700114 def dhcp_relay_setup(cls):
115 did = OnosCtrl.get_device_id()
116 cls.relay_device_id = did
A R Karthick3026e482016-08-12 16:02:40 -0700117 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
A R Karthickb03cecd2016-07-27 10:27:55 -0700118 cls.port_map, _ = cls.olt.olt_port_map()
119 if cls.port_map:
A R Karthick36cfcef2016-08-18 15:20:07 -0700120 ##Per subscriber, we use 1 relay port
121 try:
122 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
123 except:
124 relay_port = cls.port_map['uplink']
125 cls.relay_interface_port = relay_port
A R Karthickb03cecd2016-07-27 10:27:55 -0700126 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
127 else:
128 cls.relay_interface_port = 100
129 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
130 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick3026e482016-08-12 16:02:40 -0700131 if cls.port_map:
132 ##generate a ip/mac client virtual interface config for onos
133 interface_list = []
134 for port in cls.port_map['ports']:
135 port_num = cls.port_map[port]
136 if port_num == cls.port_map['uplink']:
A R Karthick36cfcef2016-08-18 15:20:07 -0700137 continue
138 ip = cls.get_host_ip(port_num)
A R Karthick3026e482016-08-12 16:02:40 -0700139 mac = cls.get_mac(port)
140 interface_list.append((port_num, ip, mac))
141
A R Karthick36cfcef2016-08-18 15:20:07 -0700142 #configure dhcp server virtual interface on the same subnet as first client interface
143 relay_ip = cls.get_host_ip(interface_list[0][0])
144 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
145 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthick3026e482016-08-12 16:02:40 -0700146 cls.onos_interface_load(interface_list)
A R Karthickb03cecd2016-07-27 10:27:55 -0700147
148 @classmethod
A R Karthick4e0c0912016-08-17 16:57:42 -0700149 def dhcp_relay_cleanup(cls):
150 ##reset the ONOS port configuration back to default
A R Karthickbd82f362016-11-10 15:08:52 -0800151 for config in cls.configs.items():
152 OnosCtrl.delete(config)
153 # if cls.onos_restartable is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700154 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
A R Karthickbd82f362016-11-10 15:08:52 -0800155 # return cord_test_onos_restart(config = {})
A R Karthick4e0c0912016-08-17 16:57:42 -0700156
157 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700158 def onos_load_config(cls, config):
159 status, code = OnosCtrl.config(config)
160 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700161 log_test.info('JSON request returned status %d' %code)
A R Karthick8cf29ac2016-06-30 16:25:14 -0700162 assert_equal(status, True)
163 time.sleep(3)
164
165 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700166 def onos_interface_load(cls, interface_list):
167 interface_dict = { 'ports': {} }
168 for port_num, ip, mac in interface_list:
169 port_map = interface_dict['ports']
170 port = '{}/{}'.format(cls.relay_device_id, port_num)
171 port_map[port] = { 'interfaces': [] }
172 interface_list = port_map[port]['interfaces']
173 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
174 'mac' : mac,
175 'name': 'vir-{}'.format(port_num)
176 }
177 interface_list.append(interface_map)
178
179 cls.onos_load_config(interface_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800180 cls.configs['interface_config'] = interface_dict
A R Karthick3026e482016-08-12 16:02:40 -0700181
182 @classmethod
183 def onos_dhcp_relay_load(cls, server_ip, server_mac):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700184 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
185 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
A R Karthick3026e482016-08-12 16:02:40 -0700186 {'dhcpserverConnectPoint':relay_device_map,
187 'serverip':server_ip,
188 'servermac':server_mac
189 }
190 }
191 }
192 }
A R Karthick8cf29ac2016-06-30 16:25:14 -0700193 cls.onos_load_config(dhcp_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800194 cls.configs['relay_config'] = dhcp_dict
A R Karthick8cf29ac2016-06-30 16:25:14 -0700195
196 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700197 def get_host_ip(cls, port):
198 if cls.host_ip_map.has_key(port):
199 return cls.host_ip_map[port]
200 cls.host_ip_map[port] = '192.168.1.{}'.format(port)
201 return cls.host_ip_map[port]
202
203 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700204 def host_load(cls, iface):
205 '''Have ONOS discover the hosts for dhcp-relay responses'''
206 port = g_subscriber_port_map[iface]
207 host = '173.17.1.{}'.format(port)
208 cmds = ( 'ifconfig {} 0'.format(iface),
209 'ifconfig {0} {1}'.format(iface, host),
210 'arping -I {0} {1} -c 2'.format(iface, host),
211 'ifconfig {} 0'.format(iface), )
212 for c in cmds:
213 os.system(c)
214
215 @classmethod
216 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
217 subnet = default_subnet_config):
218 conf = ''
219 for k, v in config.items():
220 conf += '{} {};\n'.format(k, v)
221
222 opts = ''
223 for k, v in options:
224 opts += 'option {} {};\n'.format(k, v)
225
226 subnet_config = ''
227 for _, v in subnet:
228 subnet_config += '{}\n'.format(v)
229
230 return '{}{}{}'.format(conf, opts, subnet_config)
231
232 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -0700233 def dhcpd_start(cls, intf_list = None,
A R Karthick8cf29ac2016-06-30 16:25:14 -0700234 config = default_config, options = default_options,
235 subnet = default_subnet_config):
236 '''Start the dhcpd server by generating the conf file'''
A R Karthickb03cecd2016-07-27 10:27:55 -0700237 if intf_list is None:
238 intf_list = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700239 ##stop dhcpd if already running
240 cls.dhcpd_stop()
241 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
242 subnet = subnet)
243 ##first touch dhcpd.leases if it doesn't exist
244 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
245 if os.access(lease_file, os.F_OK) is False:
246 with open(lease_file, 'w') as fd: pass
247
248 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
249 with open(conf_file, 'w') as fd:
250 fd.write(dhcp_conf)
251
252 #now configure the dhcpd interfaces for various subnets
253 index = 0
A R Karthick3026e482016-08-12 16:02:40 -0700254 intf_info = []
A R Karthick8cf29ac2016-06-30 16:25:14 -0700255 for ip,_ in subnet:
256 intf = intf_list[index]
A R Karthick3026e482016-08-12 16:02:40 -0700257 mac = cls.get_mac(intf)
258 intf_info.append((ip, mac))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700259 index += 1
260 os.system('ifconfig {} {}'.format(intf, ip))
261
262 intf_str = ','.join(intf_list)
263 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str)
A R Karthick76a497a2017-04-12 10:59:39 -0700264 log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
A R Karthick8cf29ac2016-06-30 16:25:14 -0700265 ret = os.system(dhcpd_cmd)
266 assert_equal(ret, 0)
267 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -0700268 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700269 cls.relay_interfaces = intf_list
A R Karthick3026e482016-08-12 16:02:40 -0700270 cls.onos_dhcp_relay_load(*intf_info[0])
A R Karthick8cf29ac2016-06-30 16:25:14 -0700271
272 @classmethod
273 def dhcpd_stop(cls):
274 os.system('pkill -9 dhcpd')
275 for intf in cls.relay_interfaces:
276 os.system('ifconfig {} 0'.format(intf))
277
A R Karthickb03cecd2016-07-27 10:27:55 -0700278 cls.relay_interfaces = cls.relay_interfaces_last
279
A R Karthick3026e482016-08-12 16:02:40 -0700280 @classmethod
281 def get_mac(cls, iface):
282 if cls.interface_to_mac_map.has_key(iface):
283 return cls.interface_to_mac_map[iface]
A R Karthick8cf29ac2016-06-30 16:25:14 -0700284 mac = get_mac(iface, pad = 0)
A R Karthick3026e482016-08-12 16:02:40 -0700285 cls.interface_to_mac_map[iface] = mac
A R Karthick8cf29ac2016-06-30 16:25:14 -0700286 return mac
287
ChetanGaonker5860c182016-07-05 16:33:06 -0700288 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
289
290 self.ip_count = 0
291 self.failure_count = 0
292 self.start_time = 0
293 self.diff = 0
294 self.transaction_count = 0
295
296 mac = self.get_mac(iface)
297 self.host_load(iface)
298 ##we use the defaults for this test that serves as an example for others
299 ##You don't need to restart dhcpd server if retaining default config
300 config = self.default_config
301 options = self.default_options
302 subnet = self.default_subnet_config
303 dhcpd_interface_list = self.relay_interfaces
304 self.dhcpd_start(intf_list = dhcpd_interface_list,
305 config = config,
306 options = options,
307 subnet = subnet)
308 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
309 self.start_time = time.time()
310
311 while self.diff <= 60:
312
313 if only_discover:
314 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700315 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700316 (cip, sip, mac))
317 else:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000318 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700319
320 if cip:
321 self.ip_count +=1
322 elif cip == None:
323 self.failure_count += 1
A R Karthick76a497a2017-04-12 10:59:39 -0700324 log_test.info('Failed to get ip')
ChetanGaonker5860c182016-07-05 16:33:06 -0700325 if success_rate and self.ip_count > 0:
326 break
327
328 self.diff = round(time.time() - self.start_time, 0)
329
ChetanGaonker5860c182016-07-05 16:33:06 -0700330 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
331 self.transactions += (self.ip_count+self.failure_count)
332 self.running_time += self.diff
333 self.total_success += self.ip_count
334 self.total_failure += self.failure_count
335
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000336 def send_recv(self, mac=None, update_seed = False, validate = True):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700337 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
338 if validate:
339 assert_not_equal(cip, None)
340 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700341 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700342 (cip, sip, self.dhcp.get_mac(cip)[0]))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700343 return cip,sip
344
ChetanGaonker5860c182016-07-05 16:33:06 -0700345 def test_dhcpRelay_1request(self, iface = 'veth0'):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700346 mac = self.get_mac(iface)
347 self.host_load(iface)
348 ##we use the defaults for this test that serves as an example for others
349 ##You don't need to restart dhcpd server if retaining default config
350 config = self.default_config
351 options = self.default_options
352 subnet = self.default_subnet_config
353 dhcpd_interface_list = self.relay_interfaces
354 self.dhcpd_start(intf_list = dhcpd_interface_list,
355 config = config,
356 options = options,
357 subnet = subnet)
358 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000359 self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700360
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000361 def test_dhcpRelay_1request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
362 mac = self.get_mac(iface)
363 self.host_load(iface)
364 ##we use the defaults for this test that serves as an example for others
365 ##You don't need to restart dhcpd server if retaining default config
366 config = self.default_config
367 options = self.default_options
368 subnet = self.default_subnet_config
369 dhcpd_interface_list = self.relay_interfaces
370 self.dhcpd_start(intf_list = dhcpd_interface_list,
371 config = config,
372 options = options,
373 subnet = subnet)
374 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
375 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
376 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700377 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000378
379 def test_dhcpRelay_1request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
380 mac = self.get_mac(iface)
381 self.host_load(iface)
382 ##we use the defaults for this test that serves as an example for others
383 ##You don't need to restart dhcpd server if retaining default config
384 config = self.default_config
385 options = self.default_options
386 subnet = self.default_subnet_config
387 dhcpd_interface_list = self.relay_interfaces
388 self.dhcpd_start(intf_list = dhcpd_interface_list,
389 config = config,
390 options = options,
391 subnet = subnet)
392 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
393 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
394 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700395 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000396
397 def test_dhcpRelay_1request_with_invalid_source_mac_zero(self, iface = 'veth0'):
398 mac = self.get_mac(iface)
399 self.host_load(iface)
400 ##we use the defaults for this test that serves as an example for others
401 ##You don't need to restart dhcpd server if retaining default config
402 config = self.default_config
403 options = self.default_options
404 subnet = self.default_subnet_config
405 dhcpd_interface_list = self.relay_interfaces
406 self.dhcpd_start(intf_list = dhcpd_interface_list,
407 config = config,
408 options = options,
409 subnet = subnet)
410 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
411 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
412 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700413 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000414
415 def test_dhcpRelay_Nrequest(self, iface = 'veth0',requests=10):
ChetanGaonker5860c182016-07-05 16:33:06 -0700416 mac = self.get_mac(iface)
417 self.host_load(iface)
418 ##we use the defaults for this test that serves as an example for others
419 ##You don't need to restart dhcpd server if retaining default config
420 config = self.default_config
421 options = self.default_options
422 subnet = self.default_subnet_config
423 dhcpd_interface_list = self.relay_interfaces
424 self.dhcpd_start(intf_list = dhcpd_interface_list,
425 config = config,
426 options = options,
427 subnet = subnet)
428 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
429 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000430 for i in range(requests):
431 #mac = RandMAC()._fix()
A R Karthick76a497a2017-04-12 10:59:39 -0700432 #log_test.info('mac is %s'%mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000433 cip, sip = self.send_recv(update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700434 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700435 log_test.info('IP %s given out multiple times' %cip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700436 assert_equal(False, ip_map.has_key(cip))
437 ip_map[cip] = sip
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000438 time.sleep(1)
ChetanGaonker5860c182016-07-05 16:33:06 -0700439
440 def test_dhcpRelay_1release(self, iface = 'veth0'):
441 mac = self.get_mac(iface)
442 self.host_load(iface)
443 ##we use the defaults for this test that serves as an example for others
444 ##You don't need to restart dhcpd server if retaining default config
445 config = self.default_config
446 options = self.default_options
447 subnet = self.default_subnet_config
448 dhcpd_interface_list = self.relay_interfaces
449 self.dhcpd_start(intf_list = dhcpd_interface_list,
450 config = config,
451 options = options,
452 subnet = subnet)
453 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000454 cip, sip = self.send_recv(mac=mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700455 log_test.info('Releasing ip %s to server %s' %(cip, sip))
ChetanGaonker5860c182016-07-05 16:33:06 -0700456 assert_equal(self.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -0700457 log_test.info('Triggering DHCP discover again after release')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000458 cip2, sip2 = self.send_recv(mac=mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700459 log_test.info('Verifying released IP was given back on rediscover')
ChetanGaonker5860c182016-07-05 16:33:06 -0700460 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -0700461 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
ChetanGaonker5860c182016-07-05 16:33:06 -0700462 assert_equal(self.dhcp.release(cip2), True)
463
464 def test_dhcpRelay_Nrelease(self, iface = 'veth0'):
A R Karthickb03cecd2016-07-27 10:27:55 -0700465 mac = None
ChetanGaonker5860c182016-07-05 16:33:06 -0700466 self.host_load(iface)
467 ##we use the defaults for this test that serves as an example for others
468 ##You don't need to restart dhcpd server if retaining default config
469 config = self.default_config
470 options = self.default_options
471 subnet = self.default_subnet_config
472 dhcpd_interface_list = self.relay_interfaces
473 self.dhcpd_start(intf_list = dhcpd_interface_list,
474 config = config,
475 options = options,
476 subnet = subnet)
477 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
478 ip_map = {}
479 for i in range(10):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000480 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700481 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700482 log_test.info('IP %s given out multiple times' %cip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700483 assert_equal(False, ip_map.has_key(cip))
484 ip_map[cip] = sip
485
486 for ip in ip_map.keys():
A R Karthick76a497a2017-04-12 10:59:39 -0700487 log_test.info('Releasing IP %s' %ip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700488 assert_equal(self.dhcp.release(ip), True)
489
490 ip_map2 = {}
A R Karthick76a497a2017-04-12 10:59:39 -0700491 log_test.info('Triggering DHCP discover again after release')
ChetanGaonker5860c182016-07-05 16:33:06 -0700492 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
493 for i in range(len(ip_map.keys())):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000494 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700495 ip_map2[cip] = sip
496
A R Karthick76a497a2017-04-12 10:59:39 -0700497 log_test.info('Verifying released IPs were given back on rediscover')
ChetanGaonker5860c182016-07-05 16:33:06 -0700498 if ip_map != ip_map2:
A R Karthick76a497a2017-04-12 10:59:39 -0700499 log_test.info('Map before release %s' %ip_map)
500 log_test.info('Map after release %s' %ip_map2)
ChetanGaonker5860c182016-07-05 16:33:06 -0700501 assert_equal(ip_map, ip_map2)
502
503 def test_dhcpRelay_starvation(self, iface = 'veth0'):
504 mac = self.get_mac(iface)
505 self.host_load(iface)
506 ##we use the defaults for this test that serves as an example for others
507 ##You don't need to restart dhcpd server if retaining default config
508 config = self.default_config
509 options = self.default_options
510 subnet = self.default_subnet_config
511 dhcpd_interface_list = self.relay_interfaces
512 self.dhcpd_start(intf_list = dhcpd_interface_list,
513 config = config,
514 options = options,
515 subnet = subnet)
ChetanGaonker5860c182016-07-05 16:33:06 -0700516 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700517 log_test.info('Verifying 1 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000518 count = 0
ChetanGaonker5860c182016-07-05 16:33:06 -0700519 while True:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000520 #mac = RandMAC()._fix()
521 cip, sip = self.send_recv(update_seed = True,validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700522 if cip is None:
523 break
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000524 else:
525 count += 1
526 assert_equal(count,91)
A R Karthick76a497a2017-04-12 10:59:39 -0700527 log_test.info('Verifying 2 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000528 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700529 assert_equal(cip, None)
530 assert_equal(sip, None)
531
532 def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'):
533 mac = self.get_mac(iface)
534 self.host_load(iface)
535 ##we use the defaults for this test that serves as an example for others
536 ##You don't need to restart dhcpd server if retaining default config
537 config = self.default_config
538 options = self.default_options
539 subnet = self.default_subnet_config
540 dhcpd_interface_list = self.relay_interfaces
541 self.dhcpd_start(intf_list = dhcpd_interface_list,
542 config = config,
543 options = options,
544 subnet = subnet)
545 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
546 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700547 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700548 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000549 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700550 log_test.info('Triggering DHCP discover again.')
ChetanGaonker5860c182016-07-05 16:33:06 -0700551 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000552 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700553 log_test.info('got same ip to smae the client when sent discover again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700554
555 def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'):
556 mac = self.get_mac(iface)
557 self.host_load(iface)
558 ##we use the defaults for this test that serves as an example for others
559 ##You don't need to restart dhcpd server if retaining default config
560 config = self.default_config
561 options = self.default_options
562 subnet = self.default_subnet_config
563 dhcpd_interface_list = self.relay_interfaces
564 self.dhcpd_start(intf_list = dhcpd_interface_list,
565 config = config,
566 options = options,
567 subnet = subnet)
568 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700569 log_test.info('Sending DHCP discover and DHCP request.')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000570 cip, sip = self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700571 mac = self.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -0700572 log_test.info("Sending DHCP request again.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700573 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000574 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700575 log_test.info('got same ip to smae the client when sent request again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700576
577 def test_dhcpRelay_client_desired_address(self, iface = 'veth0'):
578 mac = self.get_mac(iface)
579 self.host_load(iface)
580 ##we use the defaults for this test that serves as an example for others
581 ##You don't need to restart dhcpd server if retaining default config
582 config = self.default_config
583 options = self.default_options
584 subnet = self.default_subnet_config
585 dhcpd_interface_list = self.relay_interfaces
586 self.dhcpd_start(intf_list = dhcpd_interface_list,
587 config = config,
588 options = options,
589 subnet = subnet)
590 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
591 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000592 assert_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700593 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700594 (cip, sip, mac) )
ChetanGaonker5860c182016-07-05 16:33:06 -0700595
596 def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'):
597 mac = self.get_mac(iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000598
ChetanGaonker5860c182016-07-05 16:33:06 -0700599 self.host_load(iface)
600 ##we use the defaults for this test that serves as an example for others
601 ##You don't need to restart dhcpd server if retaining default config
602 config = self.default_config
603 options = self.default_options
604 subnet = self.default_subnet_config
605 dhcpd_interface_list = self.relay_interfaces
606 self.dhcpd_start(intf_list = dhcpd_interface_list,
607 config = config,
608 options = options,
609 subnet = subnet)
610 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
611 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000612 assert_not_equal(cip,None)
613 assert_not_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700614 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700615
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700616 def test_dhcpRelay_nak_packet(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700617 mac = self.get_mac(iface)
618 self.host_load(iface)
619 ##we use the defaults for this test that serves as an example for others
620 ##You don't need to restart dhcpd server if retaining default config
621 config = self.default_config
622 options = self.default_options
623 subnet = self.default_subnet_config
624 dhcpd_interface_list = self.relay_interfaces
625 self.dhcpd_start(intf_list = dhcpd_interface_list,
626 config = config,
627 options = options,
628 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000629 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
ChetanGaonker5860c182016-07-05 16:33:06 -0700630 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700631 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700632 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000633 assert_not_equal(cip, None)
634 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
635 assert_equal(new_cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700636 log_test.info('server sent NAK packet when requested other IP than that server offered')
ChetanGaonker5860c182016-07-05 16:33:06 -0700637
638
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000639 def test_dhcpRelay_client_requests_specific_lease_time_in_discover(self, iface = 'veth0',lease_time=700):
ChetanGaonker5860c182016-07-05 16:33:06 -0700640 mac = self.get_mac(iface)
641 self.host_load(iface)
642 ##we use the defaults for this test that serves as an example for others
643 ##You don't need to restart dhcpd server if retaining default config
644 config = self.default_config
645 options = self.default_options
646 subnet = self.default_subnet_config
647 dhcpd_interface_list = self.relay_interfaces
648 self.dhcpd_start(intf_list = dhcpd_interface_list,
649 config = config,
650 options = options,
651 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000652 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
653 self.dhcp.return_option = 'lease'
654 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
655 assert_equal(lval, lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700656 log_test.info('dhcp server offered IP address with client requested lease time')
ChetanGaonker5860c182016-07-05 16:33:06 -0700657
658 def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'):
659 mac = self.get_mac(iface)
660 self.host_load(iface)
661 ##we use the defaults for this test that serves as an example for others
662 ##You don't need to restart dhcpd server if retaining default config
663 config = self.default_config
664 options = self.default_options
665 subnet = self.default_subnet_config
666 dhcpd_interface_list = self.relay_interfaces
667 self.dhcpd_start(intf_list = dhcpd_interface_list,
668 config = config,
669 options = options,
670 subnet = subnet)
671 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
672 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700673 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700674 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000675 assert_not_equal(cip, None)
676 new_cip, new_sip = self.dhcp.only_request(cip, mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700677 log_test.info('client rebooting...')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000678 os.system('ifconfig '+iface+' down')
679 time.sleep(5)
680 os.system('ifconfig '+iface+' up')
681 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
682 assert_equal(new_cip2, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700683 log_test.info('client got same IP after reboot, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700684
ChetanGaonker5860c182016-07-05 16:33:06 -0700685
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000686 def test_dhcpRelay_after_server_reboot(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700687 mac = self.get_mac(iface)
688 self.host_load(iface)
689 ##we use the defaults for this test that serves as an example for others
690 ##You don't need to restart dhcpd server if retaining default config
691 config = self.default_config
692 options = self.default_options
693 subnet = self.default_subnet_config
694 dhcpd_interface_list = self.relay_interfaces
695 self.dhcpd_start(intf_list = dhcpd_interface_list,
696 config = config,
697 options = options,
698 subnet = subnet)
699 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
700 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700701 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700702 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000703 assert_not_equal(cip, None)
704 new_cip, new_sip = self.dhcp.only_request(cip, mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700705 log_test.info('server rebooting...')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000706 self.tearDownClass()
707 new_cip, new_sip = self.dhcp.only_request(cip, mac)
708 assert_equal(new_cip,None)
709 self.setUpClass()
710 new_cip, new_sip = self.dhcp.only_request(cip, mac)
711 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700712 log_test.info('client got same IP after server rebooted, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700713
714
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000715 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 -0700716 mac = self.get_mac(iface)
717 self.host_load(iface)
718 ##we use the defaults for this test that serves as an example for others
719 ##You don't need to restart dhcpd server if retaining default config
720 config = self.default_config
721 options = self.default_options
722 subnet = self.default_subnet_config
723 dhcpd_interface_list = self.relay_interfaces
724 self.dhcpd_start(intf_list = dhcpd_interface_list,
725 config = config,
726 options = options,
727 subnet = subnet)
728 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000729 self.dhcp.return_option = 'lease'
A R Karthick76a497a2017-04-12 10:59:39 -0700730 log_test.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000731 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
732 assert_equal(lval,lease_time)
733 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
734 assert_equal(new_cip,cip)
735 assert_not_equal(lval, lease_time) #Negative Test Case
A R Karthick76a497a2017-04-12 10:59:39 -0700736 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700737
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000738 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 -0700739 mac = self.get_mac(iface)
740 self.host_load(iface)
741 ##we use the defaults for this test that serves as an example for others
742 ##You don't need to restart dhcpd server if retaining default config
743 config = self.default_config
744 options = self.default_options
745 subnet = self.default_subnet_config
746 dhcpd_interface_list = self.relay_interfaces
747 self.dhcpd_start(intf_list = dhcpd_interface_list,
748 config = config,
749 options = options,
750 subnet = subnet)
751 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
752 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000753 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
754 assert_equal(new_cip,cip)
755 assert_equal(lval, lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700756 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700757
758 def test_dhcpRelay_client_renew_time(self, iface = 'veth0'):
759 mac = self.get_mac(iface)
760 self.host_load(iface)
761 ##we use the defaults for this test that serves as an example for others
762 ##You don't need to restart dhcpd server if retaining default config
763 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000764 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700765 options = self.default_options + new_options
766 subnet = self.default_subnet_config
767 dhcpd_interface_list = self.relay_interfaces
768 self.dhcpd_start(intf_list = dhcpd_interface_list,
769 config = config,
770 options = options,
771 subnet = subnet)
772 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
773 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700774 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700775 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000776 assert_not_equal(cip,None)
777 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700778 log_test.info('waiting for renew time..')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000779 time.sleep(lval)
780 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
781 assert_equal(latest_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700782 log_test.info('server renewed client IP when client sends request after renew time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700783
784
785 def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'):
786 mac = self.get_mac(iface)
787 self.host_load(iface)
788 ##we use the defaults for this test that serves as an example for others
789 ##You don't need to restart dhcpd server if retaining default config
790 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000791 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700792 options = self.default_options + new_options
793 subnet = self.default_subnet_config
794 dhcpd_interface_list = self.relay_interfaces
795 self.dhcpd_start(intf_list = dhcpd_interface_list,
796 config = config,
797 options = options,
798 subnet = subnet)
799 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
800 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700801 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700802 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000803 assert_not_equal(cip,None)
804 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700805 log_test.info('waiting for rebind time..')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000806 time.sleep(lval)
807 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
808 assert_equal(latest_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700809 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700810
811
812 def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'):
813 mac = self.get_mac(iface)
814 self.host_load(iface)
815 ##we use the defaults for this test that serves as an example for others
816 ##You don't need to restart dhcpd server if retaining default config
817 config = self.default_config
818 options = self.default_options
819 subnet = self.default_subnet_config
820 dhcpd_interface_list = self.relay_interfaces
821 self.dhcpd_start(intf_list = dhcpd_interface_list,
822 config = config,
823 options = options,
824 subnet = subnet)
825 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
826 expected_subnet = '255.255.255.0'
827 self.dhcp.return_option = 'subnet'
828
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000829 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700830 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700831 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000832 assert_equal(subnet_mask,expected_subnet)
A R Karthick76a497a2017-04-12 10:59:39 -0700833 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700834
835
836 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
837 mac = self.get_mac(iface)
838 self.host_load(iface)
839 ##we use the defaults for this test that serves as an example for others
840 ##You don't need to restart dhcpd server if retaining default config
841 config = self.default_config
842 options = self.default_options
843 subnet = self.default_subnet_config
844 dhcpd_interface_list = self.relay_interfaces
845 self.dhcpd_start(intf_list = dhcpd_interface_list,
846 config = config,
847 options = options,
848 subnet = subnet)
849 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
850
851 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700852 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700853 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000854 assert_not_equal(cip,None)
855 self.dhcp.send_different_option = 'subnet'
856 new_cip, new_sip = self.dhcp.only_request(cip, mac)
857 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700858 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700859
860
861 def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'):
862 mac = self.get_mac(iface)
863 self.host_load(iface)
864 ##we use the defaults for this test that serves as an example for others
865 ##You don't need to restart dhcpd server if retaining default config
866 config = self.default_config
867 config = self.default_config
868 new_options = [('routers', '20.20.20.1')]
869 options = self.default_options + new_options
870 subnet = self.default_subnet_config
871 dhcpd_interface_list = self.relay_interfaces
872 self.dhcpd_start(intf_list = dhcpd_interface_list,
873 config = config,
874 options = options,
875 subnet = subnet)
876 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
877 expected_router_address = '20.20.20.1'
878 self.dhcp.return_option = 'router'
879
880 cip, sip, mac, router_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700881 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700882 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000883 assert_equal(expected_router_address, router_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700884 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700885
886
887 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
888 mac = self.get_mac(iface)
889 self.host_load(iface)
890 ##we use the defaults for this test that serves as an example for others
891 ##You don't need to restart dhcpd server if retaining default config
892 config = self.default_config
893 options = self.default_options
894 subnet = self.default_subnet_config
895 dhcpd_interface_list = self.relay_interfaces
896 self.dhcpd_start(intf_list = dhcpd_interface_list,
897 config = config,
898 options = options,
899 subnet = subnet)
900 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
901
902 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700903 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700904 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000905 assert_not_equal(cip,None)
906 self.dhcp.send_different_option = 'router'
907 new_cip, new_sip = self.dhcp.only_request(cip, mac)
908 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700909 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700910
911
912 def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'):
913 mac = self.get_mac(iface)
914 self.host_load(iface)
915 ##we use the defaults for this test that serves as an example for others
916 ##You don't need to restart dhcpd server if retaining default config
917 config = self.default_config
918 options = self.default_options
919 subnet = self.default_subnet_config
920 dhcpd_interface_list = self.relay_interfaces
921 self.dhcpd_start(intf_list = dhcpd_interface_list,
922 config = config,
923 options = options,
924 subnet = subnet)
925 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
926 expected_broadcast_address = '192.168.1.255'
927 self.dhcp.return_option = 'broadcast_address'
928
929 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700930 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700931 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000932 assert_equal(expected_broadcast_address, broadcast_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700933 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700934
935 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(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()
A R Karthick76a497a2017-04-12 10:59:39 -0700951 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700952 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000953 assert_not_equal(cip,None)
954 self.dhcp.send_different_option = 'broadcast_address'
955 new_cip, new_sip = self.dhcp.only_request(cip, mac)
956 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700957 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700958
ChetanGaonker5860c182016-07-05 16:33:06 -0700959
960 def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'):
961 mac = self.get_mac(iface)
962 self.host_load(iface)
963 ##we use the defaults for this test that serves as an example for others
964 ##You don't need to restart dhcpd server if retaining default config
965 config = self.default_config
966 options = self.default_options
967 subnet = self.default_subnet_config
968 dhcpd_interface_list = self.relay_interfaces
969 self.dhcpd_start(intf_list = dhcpd_interface_list,
970 config = config,
971 options = options,
972 subnet = subnet)
973 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
974 expected_dns_address = '192.168.1.1'
975 self.dhcp.return_option = 'dns'
976
977 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700978 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700979 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000980 assert_equal(expected_dns_address, dns_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700981 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700982
983 def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
984 mac = self.get_mac(iface)
985 self.host_load(iface)
986 ##we use the defaults for this test that serves as an example for others
987 ##You don't need to restart dhcpd server if retaining default config
988 config = self.default_config
989 options = self.default_options
990 subnet = self.default_subnet_config
991 dhcpd_interface_list = self.relay_interfaces
992 self.dhcpd_start(intf_list = dhcpd_interface_list,
993 config = config,
994 options = options,
995 subnet = subnet)
996 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
997
998 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700999 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -07001000 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +00001001 assert_not_equal(cip,None)
1002 self.dhcp.send_different_option = 'dns'
1003 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1004 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -07001005 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -07001006
ChetanGaonker5860c182016-07-05 16:33:06 -07001007
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001008 def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001009
1010 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001011 self.stats()
A R Karthick76a497a2017-04-12 10:59:39 -07001012 log_test.info("Statistics for run %d",i)
1013 log_test.info("----------------------------------------------------------------------------------")
1014 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1015 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1016 log_test.info("----------------------------------------------------------------------------------")
1017 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker5860c182016-07-05 16:33:06 -07001018
A R Karthick76a497a2017-04-12 10:59:39 -07001019 log_test.info("Final Statistics for total transactions")
1020 log_test.info("----------------------------------------------------------------------------------")
1021 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1022 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001023 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001024 log_test.info("----------------------------------------------------------------------------------")
1025 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
ChetanGaonker5860c182016-07-05 16:33:06 -07001026
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001027 def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001028
1029 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001030 self.stats(success_rate = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001031 log_test.info("Statistics for run %d",i)
1032 log_test.info("----------------------------------------------------------------------------------")
1033 log_test.info("No. of consecutive successful transactions Running Time ")
1034 log_test.info(" %d %d " %(self.ip_count, self.diff))
1035 log_test.info("----------------------------------------------------------------------------------")
1036 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1037 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001038
A R Karthick76a497a2017-04-12 10:59:39 -07001039 log_test.info("Final Statistics for total successful transactions")
1040 log_test.info("----------------------------------------------------------------------------------")
1041 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1042 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001043 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001044 log_test.info("----------------------------------------------------------------------------------")
1045 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1046 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001047
1048
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001049 def test_dhcpRelay_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001050
1051 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001052 self.stats(only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001053 log_test.info("----------------------------------------------------------------------------------")
1054 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1055 log_test.info("----------------------------------------------------------------------------------")
1056 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1057 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1058 log_test.info("----------------------------------------------------------------------------------")
1059 log_test.info("No. of clients per second in run %d:%f "
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001060 %(i, self.transaction_count))
A R Karthick76a497a2017-04-12 10:59:39 -07001061 log_test.info("----------------------------------------------------------------------------------")
1062 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1063 log_test.info("----------------------------------------------------------------------------------")
1064 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1065 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001066 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001067 log_test.info("----------------------------------------------------------------------------------")
1068 log_test.info("Average no. of clients per second: %d ",
ChetanGaonker5860c182016-07-05 16:33:06 -07001069 round(self.transactions/self.running_time,0))
A R Karthick76a497a2017-04-12 10:59:39 -07001070 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001071
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001072 def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001073
1074 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001075 self.stats(success_rate = True, only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001076 log_test.info("----------------------------------------------------------------------------------")
1077 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1078 log_test.info("----------------------------------------------------------------------------------")
1079 log_test.info("No. of consecutive successful transactions Running Time ")
1080 log_test.info(" %d %d " %(self.ip_count, self.diff))
1081 log_test.info("----------------------------------------------------------------------------------")
1082 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1083 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001084
A R Karthick76a497a2017-04-12 10:59:39 -07001085 log_test.info("Final Statistics for total successful transactions")
1086 log_test.info("----------------------------------------------------------------------------------")
1087 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1088 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001089 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001090 log_test.info("----------------------------------------------------------------------------------")
1091 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1092 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001093
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001094 def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'):
1095
1096 config = self.default_config
1097 options = self.default_options
1098 subnet = [ ('192.168.1.2',
1099'''
1100subnet 192.168.0.0 netmask 255.255.0.0 {
1101 range 192.168.1.10 192.168.2.100;
1102}
1103'''), ]
1104
1105 dhcpd_interface_list = self.relay_interfaces
1106 self.dhcpd_start(intf_list = dhcpd_interface_list,
1107 config = config,
1108 options = options,
1109 subnet = subnet)
1110
1111 for key in (key for key in g_subscriber_port_map if key < 100):
1112 self.host_load(g_subscriber_port_map[key])
1113
1114 def thread_fun(i):
1115 mac = self.get_mac('veth{}'.format(i))
1116 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001117 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001118 self.lock.acquire()
1119
1120 if cip:
1121 self.ip_count += 1
1122
1123 elif cip is None:
1124 self.failure_count += 1
1125
1126 self.lock.notify_all()
1127 self.lock.release()
1128
1129 for i in range (1,4):
1130 self.ip_count = 0
1131 self.failure_count = 0
1132 self.start_time = 0
1133 self.diff = 0
1134 self.transaction_count = 0
1135 self.start_time = time.time()
1136
1137 while self.diff <= 60:
1138 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1139 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1140 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1141 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1142 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1143 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1144
1145 t.start()
1146 t1.start()
1147 t2.start()
1148 t3.start()
1149 t4.start()
1150 t5.start()
1151
1152 t.join()
1153 t1.join()
1154 t2.join()
1155 t3.join()
1156 t4.join()
1157 t5.join()
1158
1159 self.diff = round(time.time() - self.start_time, 0)
1160
1161 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1162
1163 self.transactions += (self.ip_count+self.failure_count)
1164 self.running_time += self.diff
1165 self.total_success += self.ip_count
1166 self.total_failure += self.failure_count
1167
1168
A R Karthick76a497a2017-04-12 10:59:39 -07001169 log_test.info("----------------------------------------------------------------------------------")
1170 log_test.info("Statistics for run %d",i)
1171 log_test.info("----------------------------------------------------------------------------------")
1172 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1173 log_test.info(" %d %d %d %d"
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001174 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
A R Karthick76a497a2017-04-12 10:59:39 -07001175 log_test.info("----------------------------------------------------------------------------------")
1176 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1177 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001178
A R Karthick76a497a2017-04-12 10:59:39 -07001179 log_test.info("----------------------------------------------------------------------------------")
1180 log_test.info("Final Statistics for total transactions")
1181 log_test.info("----------------------------------------------------------------------------------")
1182 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1183 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001184 self.total_success, self.total_failure, self.running_time))
1185
A R Karthick76a497a2017-04-12 10:59:39 -07001186 log_test.info("----------------------------------------------------------------------------------")
1187 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1188 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001189
1190 def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
1191
1192 config = self.default_config
1193 options = self.default_options
1194 subnet = [ ('192.168.1.2',
1195'''
1196subnet 192.168.0.0 netmask 255.255.0.0 {
1197 range 192.168.1.10 192.168.2.100;
1198}
1199'''), ]
1200
1201 dhcpd_interface_list = self.relay_interfaces
1202 self.dhcpd_start(intf_list = dhcpd_interface_list,
1203 config = config,
1204 options = options,
1205 subnet = subnet)
1206 failure_dir = {}
1207
1208 for key in (key for key in g_subscriber_port_map if key != 100):
1209 self.host_load(g_subscriber_port_map[key])
1210
1211 def thread_fun(i, j):
A R Karthick76a497a2017-04-12 10:59:39 -07001212# log_test.info("Thread Name:%s",current_thread().name)
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001213# failure_dir[current_thread().name] = True
1214 while failure_dir.has_key(current_thread().name) is False:
1215 mac = RandMAC()._fix()
1216 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1217 i += 2
A R Karthick76a497a2017-04-12 10:59:39 -07001218 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001219 self.lock.acquire()
1220
1221 if cip:
1222 self.ip_count += 1
1223 self.lock.notify_all()
1224 self.lock.release()
1225 elif cip is None:
1226 self.failure_count += 1
1227 failure_dir[current_thread().name] = True
1228 self.lock.notify_all()
1229 self.lock.release()
1230 break
1231# self.lock.notify_all()
1232# self.lock.release()
1233
1234 for i in range (1,4):
1235 failure_dir = {}
1236 self.ip_count = 0
1237 self.failure_count = 0
1238 self.start_time = 0
1239 self.diff = 0
1240 self.transaction_count = 0
1241 self.start_time = time.time()
1242
1243 while len(failure_dir) != 6:
1244 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1245 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1246 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1247 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1248 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1249 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1250
1251 t.start()
1252 t1.start()
1253 t2.start()
1254 t3.start()
1255 t4.start()
1256 t5.start()
1257
1258 t.join()
1259 t1.join()
1260 t2.join()
1261 t3.join()
1262 t4.join()
1263 t5.join()
1264
1265 self.diff = round(time.time() - self.start_time, 0)
1266 self.transaction_count = round((self.ip_count)/self.diff, 2)
1267
1268 self.transactions += (self.ip_count+self.failure_count)
1269 self.running_time += self.diff
1270 self.total_success += self.ip_count
1271 self.total_failure += self.failure_count
1272
1273
A R Karthick76a497a2017-04-12 10:59:39 -07001274 log_test.info("Statistics for run %d",i)
1275 log_test.info("----------------------------------------------------------------------------------")
1276 log_test.info("No. of consecutive successful transactions Running Time ")
1277 log_test.info(" %d %d " %(self.ip_count, self.diff))
1278 log_test.info("----------------------------------------------------------------------------------")
1279 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1280 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001281
A R Karthick76a497a2017-04-12 10:59:39 -07001282 log_test.info("Final Statistics for total successful transactions")
1283 log_test.info("----------------------------------------------------------------------------------")
1284 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1285 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001286 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001287 log_test.info("----------------------------------------------------------------------------------")
1288 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1289 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001290
1291 def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'):
1292
1293 config = self.default_config
1294 options = self.default_options
1295 subnet = [ ('192.168.1.2',
1296'''
1297subnet 192.168.0.0 netmask 255.255.0.0 {
1298 range 192.168.1.10 192.168.2.100;
1299}
1300'''), ]
1301
1302 dhcpd_interface_list = self.relay_interfaces
1303 self.dhcpd_start(intf_list = dhcpd_interface_list,
1304 config = config,
1305 options = options,
1306 subnet = subnet)
1307
1308 for key in (key for key in g_subscriber_port_map if key < 100):
1309 self.host_load(g_subscriber_port_map[key])
1310
1311 def thread_fun(i):
1312# mac = self.get_mac('veth{}'.format(i))
1313 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
A R Karthick76a497a2017-04-12 10:59:39 -07001314 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001315 self.lock.acquire()
1316
1317 if cip:
1318 self.ip_count += 1
1319 elif cip is None:
1320 self.failure_count += 1
1321
1322 self.lock.notify_all()
1323 self.lock.release()
1324
1325 for i in range (1,4):
1326 self.ip_count = 0
1327 self.failure_count = 0
1328 self.start_time = 0
1329 self.diff = 0
1330 self.transaction_count = 0
1331 self.start_time = time.time()
1332
1333 while self.diff <= 60:
1334 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1335 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1336 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1337 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1338 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1339 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1340
1341 t.start()
1342 t1.start()
1343 t2.start()
1344 t3.start()
1345 t4.start()
1346 t5.start()
1347
1348 t.join()
1349 t1.join()
1350 t2.join()
1351 t3.join()
1352 t4.join()
1353 t5.join()
1354
1355 self.diff = round(time.time() - self.start_time, 0)
1356 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1357 self.transactions += (self.ip_count+self.failure_count)
1358 self.running_time += self.diff
1359 self.total_success += self.ip_count
1360 self.total_failure += self.failure_count
1361
A R Karthick76a497a2017-04-12 10:59:39 -07001362 log_test.info("----------------------------------------------------------------------------------")
1363 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1364 log_test.info("----------------------------------------------------------------------------------")
1365 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1366 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1367 log_test.info("----------------------------------------------------------------------------------")
1368 log_test.info("No. of clients per second in run %d:%f "
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001369 %(i, self.transaction_count))
A R Karthick76a497a2017-04-12 10:59:39 -07001370 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001371
A R Karthick76a497a2017-04-12 10:59:39 -07001372 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1373 log_test.info("----------------------------------------------------------------------------------")
1374 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1375 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001376 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001377 log_test.info("----------------------------------------------------------------------------------")
1378 log_test.info("Average no. of clients per second: %d ",
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001379 round(self.transactions/self.running_time,0))
A R Karthick76a497a2017-04-12 10:59:39 -07001380 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001381
1382
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001383 def test_dhcpRelay_client_conflict(self, iface = 'veth0'):
1384 mac = self.get_mac(iface)
1385 self.host_load(iface)
1386 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1387 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07001388 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001389 (cip, sip, mac) )
1390 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1391 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1392 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001393 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001394 (new_cip, new_sip, new_mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07001395 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1396 log_test.info("Now sending DHCP Request for old DHCP discover.")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001397 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1398 if new_cip is None:
A R Karthick76a497a2017-04-12 10:59:39 -07001399 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001400 %(new_cip, new_sip, new_mac) )
1401 elif new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07001402 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is not expected behavior as IP %s is already consumed.'
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001403 %(new_cip, new_sip, new_mac, new_cip) )
1404 assert_equal(new_cip, None)