blob: 20d3097c5db5d1b5873975ac0ea556860415fc05 [file] [log] [blame]
A R Karthick8cf29ac2016-06-30 16:25:14 -07001#
2# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +000012# WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied.
A R Karthick8cf29ac2016-06-30 16:25:14 -070013# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
A R Karthick8cf29ac2016-06-30 16:25:14 -070020import time
ChetanGaonker5b984cb2016-07-12 15:50:49 -070021import os, sys
A R Karthick8cf29ac2016-06-30 16:25:14 -070022from DHCP import DHCPTest
A R Karthick76a497a2017-04-12 10:59:39 -070023from CordTestUtils import get_mac, log_test
A.R Karthickbe7768c2017-03-17 11:39:41 -070024from OnosCtrl import OnosCtrl
A R Karthickb03cecd2016-07-27 10:27:55 -070025from 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 Karthick76a497a2017-04-12 10:59:39 -070031log_test.setLevel('INFO')
A R Karthick8cf29ac2016-06-30 16:25:14 -070032
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)))
A R Karthickbd82f362016-11-10 15:08:52 -080071 configs = {}
ChetanGaonker5860c182016-07-05 16:33:06 -070072
A R Karthick8cf29ac2016-06-30 16:25:14 -070073 @classmethod
74 def setUpClass(cls):
75 ''' Activate the dhcprelay app'''
76 OnosCtrl(cls.app_dhcp).deactivate()
77 time.sleep(3)
78 cls.onos_ctrl = OnosCtrl(cls.app)
79 status, _ = cls.onos_ctrl.activate()
80 assert_equal(status, True)
81 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070082 cls.dhcp_relay_setup()
A R Karthick8cf29ac2016-06-30 16:25:14 -070083 ##start dhcpd initially with default config
84 cls.dhcpd_start()
A R Karthick8cf29ac2016-06-30 16:25:14 -070085
86 @classmethod
87 def tearDownClass(cls):
88 '''Deactivate the dhcp relay app'''
89 try:
90 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
91 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
92 except: pass
93 cls.onos_ctrl.deactivate()
94 cls.dhcpd_stop()
A R Karthick4e0c0912016-08-17 16:57:42 -070095 cls.dhcp_relay_cleanup()
A R Karthick8cf29ac2016-06-30 16:25:14 -070096
97 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -070098 def dhcp_relay_setup(cls):
99 did = OnosCtrl.get_device_id()
100 cls.relay_device_id = did
A R Karthick3026e482016-08-12 16:02:40 -0700101 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
A R Karthickb03cecd2016-07-27 10:27:55 -0700102 cls.port_map, _ = cls.olt.olt_port_map()
103 if cls.port_map:
A R Karthick36cfcef2016-08-18 15:20:07 -0700104 ##Per subscriber, we use 1 relay port
105 try:
106 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
107 except:
108 relay_port = cls.port_map['uplink']
109 cls.relay_interface_port = relay_port
A R Karthickb03cecd2016-07-27 10:27:55 -0700110 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
111 else:
112 cls.relay_interface_port = 100
113 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
114 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick3026e482016-08-12 16:02:40 -0700115 if cls.port_map:
116 ##generate a ip/mac client virtual interface config for onos
117 interface_list = []
118 for port in cls.port_map['ports']:
119 port_num = cls.port_map[port]
120 if port_num == cls.port_map['uplink']:
A R Karthick36cfcef2016-08-18 15:20:07 -0700121 continue
122 ip = cls.get_host_ip(port_num)
A R Karthick3026e482016-08-12 16:02:40 -0700123 mac = cls.get_mac(port)
124 interface_list.append((port_num, ip, mac))
125
A R Karthick36cfcef2016-08-18 15:20:07 -0700126 #configure dhcp server virtual interface on the same subnet as first client interface
127 relay_ip = cls.get_host_ip(interface_list[0][0])
128 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
129 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthick3026e482016-08-12 16:02:40 -0700130 cls.onos_interface_load(interface_list)
A R Karthickb03cecd2016-07-27 10:27:55 -0700131
132 @classmethod
A R Karthick4e0c0912016-08-17 16:57:42 -0700133 def dhcp_relay_cleanup(cls):
134 ##reset the ONOS port configuration back to default
A R Karthickbd82f362016-11-10 15:08:52 -0800135 for config in cls.configs.items():
136 OnosCtrl.delete(config)
137 # if cls.onos_restartable is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700138 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
A R Karthickbd82f362016-11-10 15:08:52 -0800139 # return cord_test_onos_restart(config = {})
A R Karthick4e0c0912016-08-17 16:57:42 -0700140
141 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700142 def onos_load_config(cls, config):
143 status, code = OnosCtrl.config(config)
144 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700145 log_test.info('JSON request returned status %d' %code)
A R Karthick8cf29ac2016-06-30 16:25:14 -0700146 assert_equal(status, True)
147 time.sleep(3)
148
149 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700150 def onos_interface_load(cls, interface_list):
151 interface_dict = { 'ports': {} }
152 for port_num, ip, mac in interface_list:
153 port_map = interface_dict['ports']
154 port = '{}/{}'.format(cls.relay_device_id, port_num)
155 port_map[port] = { 'interfaces': [] }
156 interface_list = port_map[port]['interfaces']
157 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
158 'mac' : mac,
159 'name': 'vir-{}'.format(port_num)
160 }
161 interface_list.append(interface_map)
162
163 cls.onos_load_config(interface_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800164 cls.configs['interface_config'] = interface_dict
A R Karthick3026e482016-08-12 16:02:40 -0700165
166 @classmethod
167 def onos_dhcp_relay_load(cls, server_ip, server_mac):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700168 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
169 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
A R Karthick3026e482016-08-12 16:02:40 -0700170 {'dhcpserverConnectPoint':relay_device_map,
171 'serverip':server_ip,
172 'servermac':server_mac
173 }
174 }
175 }
176 }
A R Karthick8cf29ac2016-06-30 16:25:14 -0700177 cls.onos_load_config(dhcp_dict)
A R Karthickbd82f362016-11-10 15:08:52 -0800178 cls.configs['relay_config'] = dhcp_dict
A R Karthick8cf29ac2016-06-30 16:25:14 -0700179
180 @classmethod
A R Karthick3026e482016-08-12 16:02:40 -0700181 def get_host_ip(cls, port):
182 if cls.host_ip_map.has_key(port):
183 return cls.host_ip_map[port]
184 cls.host_ip_map[port] = '192.168.1.{}'.format(port)
185 return cls.host_ip_map[port]
186
187 @classmethod
A R Karthick8cf29ac2016-06-30 16:25:14 -0700188 def host_load(cls, iface):
189 '''Have ONOS discover the hosts for dhcp-relay responses'''
190 port = g_subscriber_port_map[iface]
191 host = '173.17.1.{}'.format(port)
192 cmds = ( 'ifconfig {} 0'.format(iface),
193 'ifconfig {0} {1}'.format(iface, host),
194 'arping -I {0} {1} -c 2'.format(iface, host),
195 'ifconfig {} 0'.format(iface), )
196 for c in cmds:
197 os.system(c)
198
199 @classmethod
200 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
201 subnet = default_subnet_config):
202 conf = ''
203 for k, v in config.items():
204 conf += '{} {};\n'.format(k, v)
205
206 opts = ''
207 for k, v in options:
208 opts += 'option {} {};\n'.format(k, v)
209
210 subnet_config = ''
211 for _, v in subnet:
212 subnet_config += '{}\n'.format(v)
213
214 return '{}{}{}'.format(conf, opts, subnet_config)
215
216 @classmethod
A R Karthickb03cecd2016-07-27 10:27:55 -0700217 def dhcpd_start(cls, intf_list = None,
A R Karthick8cf29ac2016-06-30 16:25:14 -0700218 config = default_config, options = default_options,
219 subnet = default_subnet_config):
220 '''Start the dhcpd server by generating the conf file'''
A R Karthickb03cecd2016-07-27 10:27:55 -0700221 if intf_list is None:
222 intf_list = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700223 ##stop dhcpd if already running
224 cls.dhcpd_stop()
225 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
226 subnet = subnet)
227 ##first touch dhcpd.leases if it doesn't exist
228 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
229 if os.access(lease_file, os.F_OK) is False:
230 with open(lease_file, 'w') as fd: pass
231
232 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
233 with open(conf_file, 'w') as fd:
234 fd.write(dhcp_conf)
235
236 #now configure the dhcpd interfaces for various subnets
237 index = 0
A R Karthick3026e482016-08-12 16:02:40 -0700238 intf_info = []
A R Karthick8cf29ac2016-06-30 16:25:14 -0700239 for ip,_ in subnet:
240 intf = intf_list[index]
A R Karthick3026e482016-08-12 16:02:40 -0700241 mac = cls.get_mac(intf)
242 intf_info.append((ip, mac))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700243 index += 1
244 os.system('ifconfig {} {}'.format(intf, ip))
245
246 intf_str = ','.join(intf_list)
247 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 -0700248 log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
A R Karthick8cf29ac2016-06-30 16:25:14 -0700249 ret = os.system(dhcpd_cmd)
250 assert_equal(ret, 0)
251 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -0700252 cls.relay_interfaces_last = cls.relay_interfaces
A R Karthick8cf29ac2016-06-30 16:25:14 -0700253 cls.relay_interfaces = intf_list
A R Karthick3026e482016-08-12 16:02:40 -0700254 cls.onos_dhcp_relay_load(*intf_info[0])
A R Karthick8cf29ac2016-06-30 16:25:14 -0700255
256 @classmethod
257 def dhcpd_stop(cls):
258 os.system('pkill -9 dhcpd')
259 for intf in cls.relay_interfaces:
260 os.system('ifconfig {} 0'.format(intf))
261
A R Karthickb03cecd2016-07-27 10:27:55 -0700262 cls.relay_interfaces = cls.relay_interfaces_last
263
A R Karthick3026e482016-08-12 16:02:40 -0700264 @classmethod
265 def get_mac(cls, iface):
266 if cls.interface_to_mac_map.has_key(iface):
267 return cls.interface_to_mac_map[iface]
A R Karthick8cf29ac2016-06-30 16:25:14 -0700268 mac = get_mac(iface, pad = 0)
A R Karthick3026e482016-08-12 16:02:40 -0700269 cls.interface_to_mac_map[iface] = mac
A R Karthick8cf29ac2016-06-30 16:25:14 -0700270 return mac
271
ChetanGaonker5860c182016-07-05 16:33:06 -0700272 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
273
274 self.ip_count = 0
275 self.failure_count = 0
276 self.start_time = 0
277 self.diff = 0
278 self.transaction_count = 0
279
280 mac = self.get_mac(iface)
281 self.host_load(iface)
282 ##we use the defaults for this test that serves as an example for others
283 ##You don't need to restart dhcpd server if retaining default config
284 config = self.default_config
285 options = self.default_options
286 subnet = self.default_subnet_config
287 dhcpd_interface_list = self.relay_interfaces
288 self.dhcpd_start(intf_list = dhcpd_interface_list,
289 config = config,
290 options = options,
291 subnet = subnet)
292 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
293 self.start_time = time.time()
294
295 while self.diff <= 60:
296
297 if only_discover:
298 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700299 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700300 (cip, sip, mac))
301 else:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000302 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700303
304 if cip:
305 self.ip_count +=1
306 elif cip == None:
307 self.failure_count += 1
A R Karthick76a497a2017-04-12 10:59:39 -0700308 log_test.info('Failed to get ip')
ChetanGaonker5860c182016-07-05 16:33:06 -0700309 if success_rate and self.ip_count > 0:
310 break
311
312 self.diff = round(time.time() - self.start_time, 0)
313
ChetanGaonker5860c182016-07-05 16:33:06 -0700314 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
315 self.transactions += (self.ip_count+self.failure_count)
316 self.running_time += self.diff
317 self.total_success += self.ip_count
318 self.total_failure += self.failure_count
319
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000320 def send_recv(self, mac=None, update_seed = False, validate = True):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700321 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
322 if validate:
323 assert_not_equal(cip, None)
324 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700325 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700326 (cip, sip, self.dhcp.get_mac(cip)[0]))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700327 return cip,sip
328
ChetanGaonker5860c182016-07-05 16:33:06 -0700329 def test_dhcpRelay_1request(self, iface = 'veth0'):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700330 mac = self.get_mac(iface)
331 self.host_load(iface)
332 ##we use the defaults for this test that serves as an example for others
333 ##You don't need to restart dhcpd server if retaining default config
334 config = self.default_config
335 options = self.default_options
336 subnet = self.default_subnet_config
337 dhcpd_interface_list = self.relay_interfaces
338 self.dhcpd_start(intf_list = dhcpd_interface_list,
339 config = config,
340 options = options,
341 subnet = subnet)
342 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000343 self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700344
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000345 def test_dhcpRelay_1request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
346 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)
359 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
360 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700361 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000362
363 def test_dhcpRelay_1request_with_invalid_source_mac_multicast(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.10.1', iface = iface)
377 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
378 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700379 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000380
381 def test_dhcpRelay_1request_with_invalid_source_mac_zero(self, iface = 'veth0'):
382 mac = self.get_mac(iface)
383 self.host_load(iface)
384 ##we use the defaults for this test that serves as an example for others
385 ##You don't need to restart dhcpd server if retaining default config
386 config = self.default_config
387 options = self.default_options
388 subnet = self.default_subnet_config
389 dhcpd_interface_list = self.relay_interfaces
390 self.dhcpd_start(intf_list = dhcpd_interface_list,
391 config = config,
392 options = options,
393 subnet = subnet)
394 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
395 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
396 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700397 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000398
399 def test_dhcpRelay_Nrequest(self, iface = 'veth0',requests=10):
ChetanGaonker5860c182016-07-05 16:33:06 -0700400 mac = self.get_mac(iface)
401 self.host_load(iface)
402 ##we use the defaults for this test that serves as an example for others
403 ##You don't need to restart dhcpd server if retaining default config
404 config = self.default_config
405 options = self.default_options
406 subnet = self.default_subnet_config
407 dhcpd_interface_list = self.relay_interfaces
408 self.dhcpd_start(intf_list = dhcpd_interface_list,
409 config = config,
410 options = options,
411 subnet = subnet)
412 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
413 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000414 for i in range(requests):
415 #mac = RandMAC()._fix()
A R Karthick76a497a2017-04-12 10:59:39 -0700416 #log_test.info('mac is %s'%mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000417 cip, sip = self.send_recv(update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700418 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700419 log_test.info('IP %s given out multiple times' %cip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700420 assert_equal(False, ip_map.has_key(cip))
421 ip_map[cip] = sip
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000422 time.sleep(1)
ChetanGaonker5860c182016-07-05 16:33:06 -0700423
424 def test_dhcpRelay_1release(self, iface = 'veth0'):
425 mac = self.get_mac(iface)
426 self.host_load(iface)
427 ##we use the defaults for this test that serves as an example for others
428 ##You don't need to restart dhcpd server if retaining default config
429 config = self.default_config
430 options = self.default_options
431 subnet = self.default_subnet_config
432 dhcpd_interface_list = self.relay_interfaces
433 self.dhcpd_start(intf_list = dhcpd_interface_list,
434 config = config,
435 options = options,
436 subnet = subnet)
437 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000438 cip, sip = self.send_recv(mac=mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700439 log_test.info('Releasing ip %s to server %s' %(cip, sip))
ChetanGaonker5860c182016-07-05 16:33:06 -0700440 assert_equal(self.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -0700441 log_test.info('Triggering DHCP discover again after release')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000442 cip2, sip2 = self.send_recv(mac=mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700443 log_test.info('Verifying released IP was given back on rediscover')
ChetanGaonker5860c182016-07-05 16:33:06 -0700444 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -0700445 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
ChetanGaonker5860c182016-07-05 16:33:06 -0700446 assert_equal(self.dhcp.release(cip2), True)
447
448 def test_dhcpRelay_Nrelease(self, iface = 'veth0'):
A R Karthickb03cecd2016-07-27 10:27:55 -0700449 mac = None
ChetanGaonker5860c182016-07-05 16:33:06 -0700450 self.host_load(iface)
451 ##we use the defaults for this test that serves as an example for others
452 ##You don't need to restart dhcpd server if retaining default config
453 config = self.default_config
454 options = self.default_options
455 subnet = self.default_subnet_config
456 dhcpd_interface_list = self.relay_interfaces
457 self.dhcpd_start(intf_list = dhcpd_interface_list,
458 config = config,
459 options = options,
460 subnet = subnet)
461 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
462 ip_map = {}
463 for i in range(10):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000464 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700465 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700466 log_test.info('IP %s given out multiple times' %cip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700467 assert_equal(False, ip_map.has_key(cip))
468 ip_map[cip] = sip
469
470 for ip in ip_map.keys():
A R Karthick76a497a2017-04-12 10:59:39 -0700471 log_test.info('Releasing IP %s' %ip)
ChetanGaonker5860c182016-07-05 16:33:06 -0700472 assert_equal(self.dhcp.release(ip), True)
473
474 ip_map2 = {}
A R Karthick76a497a2017-04-12 10:59:39 -0700475 log_test.info('Triggering DHCP discover again after release')
ChetanGaonker5860c182016-07-05 16:33:06 -0700476 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
477 for i in range(len(ip_map.keys())):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000478 cip, sip = self.send_recv(mac=mac, update_seed = True)
ChetanGaonker5860c182016-07-05 16:33:06 -0700479 ip_map2[cip] = sip
480
A R Karthick76a497a2017-04-12 10:59:39 -0700481 log_test.info('Verifying released IPs were given back on rediscover')
ChetanGaonker5860c182016-07-05 16:33:06 -0700482 if ip_map != ip_map2:
A R Karthick76a497a2017-04-12 10:59:39 -0700483 log_test.info('Map before release %s' %ip_map)
484 log_test.info('Map after release %s' %ip_map2)
ChetanGaonker5860c182016-07-05 16:33:06 -0700485 assert_equal(ip_map, ip_map2)
486
487 def test_dhcpRelay_starvation(self, iface = 'veth0'):
488 mac = self.get_mac(iface)
489 self.host_load(iface)
490 ##we use the defaults for this test that serves as an example for others
491 ##You don't need to restart dhcpd server if retaining default config
492 config = self.default_config
493 options = self.default_options
494 subnet = self.default_subnet_config
495 dhcpd_interface_list = self.relay_interfaces
496 self.dhcpd_start(intf_list = dhcpd_interface_list,
497 config = config,
498 options = options,
499 subnet = subnet)
ChetanGaonker5860c182016-07-05 16:33:06 -0700500 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700501 log_test.info('Verifying 1 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000502 count = 0
ChetanGaonker5860c182016-07-05 16:33:06 -0700503 while True:
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000504 #mac = RandMAC()._fix()
505 cip, sip = self.send_recv(update_seed = True,validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700506 if cip is None:
507 break
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000508 else:
509 count += 1
510 assert_equal(count,91)
A R Karthick76a497a2017-04-12 10:59:39 -0700511 log_test.info('Verifying 2 ')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000512 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
ChetanGaonker5860c182016-07-05 16:33:06 -0700513 assert_equal(cip, None)
514 assert_equal(sip, None)
515
516 def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'):
517 mac = self.get_mac(iface)
518 self.host_load(iface)
519 ##we use the defaults for this test that serves as an example for others
520 ##You don't need to restart dhcpd server if retaining default config
521 config = self.default_config
522 options = self.default_options
523 subnet = self.default_subnet_config
524 dhcpd_interface_list = self.relay_interfaces
525 self.dhcpd_start(intf_list = dhcpd_interface_list,
526 config = config,
527 options = options,
528 subnet = subnet)
529 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
530 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700531 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 -0700532 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000533 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700534 log_test.info('Triggering DHCP discover again.')
ChetanGaonker5860c182016-07-05 16:33:06 -0700535 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000536 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700537 log_test.info('got same ip to smae the client when sent discover again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700538
539 def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'):
540 mac = self.get_mac(iface)
541 self.host_load(iface)
542 ##we use the defaults for this test that serves as an example for others
543 ##You don't need to restart dhcpd server if retaining default config
544 config = self.default_config
545 options = self.default_options
546 subnet = self.default_subnet_config
547 dhcpd_interface_list = self.relay_interfaces
548 self.dhcpd_start(intf_list = dhcpd_interface_list,
549 config = config,
550 options = options,
551 subnet = subnet)
552 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700553 log_test.info('Sending DHCP discover and DHCP request.')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000554 cip, sip = self.send_recv(mac=mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700555 mac = self.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -0700556 log_test.info("Sending DHCP request again.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700557 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000558 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700559 log_test.info('got same ip to smae the client when sent request again, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700560
561 def test_dhcpRelay_client_desired_address(self, iface = 'veth0'):
562 mac = self.get_mac(iface)
563 self.host_load(iface)
564 ##we use the defaults for this test that serves as an example for others
565 ##You don't need to restart dhcpd server if retaining default config
566 config = self.default_config
567 options = self.default_options
568 subnet = self.default_subnet_config
569 dhcpd_interface_list = self.relay_interfaces
570 self.dhcpd_start(intf_list = dhcpd_interface_list,
571 config = config,
572 options = options,
573 subnet = subnet)
574 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
575 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000576 assert_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700577 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700578 (cip, sip, mac) )
ChetanGaonker5860c182016-07-05 16:33:06 -0700579
580 def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'):
581 mac = self.get_mac(iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000582
ChetanGaonker5860c182016-07-05 16:33:06 -0700583 self.host_load(iface)
584 ##we use the defaults for this test that serves as an example for others
585 ##You don't need to restart dhcpd server if retaining default config
586 config = self.default_config
587 options = self.default_options
588 subnet = self.default_subnet_config
589 dhcpd_interface_list = self.relay_interfaces
590 self.dhcpd_start(intf_list = dhcpd_interface_list,
591 config = config,
592 options = options,
593 subnet = subnet)
594 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
595 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000596 assert_not_equal(cip,None)
597 assert_not_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700598 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700599
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700600 def test_dhcpRelay_nak_packet(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700601 mac = self.get_mac(iface)
602 self.host_load(iface)
603 ##we use the defaults for this test that serves as an example for others
604 ##You don't need to restart dhcpd server if retaining default config
605 config = self.default_config
606 options = self.default_options
607 subnet = self.default_subnet_config
608 dhcpd_interface_list = self.relay_interfaces
609 self.dhcpd_start(intf_list = dhcpd_interface_list,
610 config = config,
611 options = options,
612 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000613 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
ChetanGaonker5860c182016-07-05 16:33:06 -0700614 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700615 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700616 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000617 assert_not_equal(cip, None)
618 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
619 assert_equal(new_cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700620 log_test.info('server sent NAK packet when requested other IP than that server offered')
ChetanGaonker5860c182016-07-05 16:33:06 -0700621
622
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000623 def test_dhcpRelay_client_requests_specific_lease_time_in_discover(self, iface = 'veth0',lease_time=700):
ChetanGaonker5860c182016-07-05 16:33:06 -0700624 mac = self.get_mac(iface)
625 self.host_load(iface)
626 ##we use the defaults for this test that serves as an example for others
627 ##You don't need to restart dhcpd server if retaining default config
628 config = self.default_config
629 options = self.default_options
630 subnet = self.default_subnet_config
631 dhcpd_interface_list = self.relay_interfaces
632 self.dhcpd_start(intf_list = dhcpd_interface_list,
633 config = config,
634 options = options,
635 subnet = subnet)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000636 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
637 self.dhcp.return_option = 'lease'
638 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
639 assert_equal(lval, lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700640 log_test.info('dhcp server offered IP address with client requested lease time')
ChetanGaonker5860c182016-07-05 16:33:06 -0700641
642 def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'):
643 mac = self.get_mac(iface)
644 self.host_load(iface)
645 ##we use the defaults for this test that serves as an example for others
646 ##You don't need to restart dhcpd server if retaining default config
647 config = self.default_config
648 options = self.default_options
649 subnet = self.default_subnet_config
650 dhcpd_interface_list = self.relay_interfaces
651 self.dhcpd_start(intf_list = dhcpd_interface_list,
652 config = config,
653 options = options,
654 subnet = subnet)
655 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
656 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700657 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700658 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000659 assert_not_equal(cip, None)
660 new_cip, new_sip = self.dhcp.only_request(cip, mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700661 log_test.info('client rebooting...')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000662 os.system('ifconfig '+iface+' down')
663 time.sleep(5)
664 os.system('ifconfig '+iface+' up')
665 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
666 assert_equal(new_cip2, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700667 log_test.info('client got same IP after reboot, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700668
ChetanGaonker5860c182016-07-05 16:33:06 -0700669
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000670 def test_dhcpRelay_after_server_reboot(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700671 mac = self.get_mac(iface)
672 self.host_load(iface)
673 ##we use the defaults for this test that serves as an example for others
674 ##You don't need to restart dhcpd server if retaining default config
675 config = self.default_config
676 options = self.default_options
677 subnet = self.default_subnet_config
678 dhcpd_interface_list = self.relay_interfaces
679 self.dhcpd_start(intf_list = dhcpd_interface_list,
680 config = config,
681 options = options,
682 subnet = subnet)
683 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
684 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700685 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700686 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000687 assert_not_equal(cip, None)
688 new_cip, new_sip = self.dhcp.only_request(cip, mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700689 log_test.info('server rebooting...')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000690 self.tearDownClass()
691 new_cip, new_sip = self.dhcp.only_request(cip, mac)
692 assert_equal(new_cip,None)
693 self.setUpClass()
694 new_cip, new_sip = self.dhcp.only_request(cip, mac)
695 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700696 log_test.info('client got same IP after server rebooted, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700697
698
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000699 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 -0700700 mac = self.get_mac(iface)
701 self.host_load(iface)
702 ##we use the defaults for this test that serves as an example for others
703 ##You don't need to restart dhcpd server if retaining default config
704 config = self.default_config
705 options = self.default_options
706 subnet = self.default_subnet_config
707 dhcpd_interface_list = self.relay_interfaces
708 self.dhcpd_start(intf_list = dhcpd_interface_list,
709 config = config,
710 options = options,
711 subnet = subnet)
712 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000713 self.dhcp.return_option = 'lease'
A R Karthick76a497a2017-04-12 10:59:39 -0700714 log_test.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000715 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
716 assert_equal(lval,lease_time)
717 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
718 assert_equal(new_cip,cip)
719 assert_not_equal(lval, lease_time) #Negative Test Case
A R Karthick76a497a2017-04-12 10:59:39 -0700720 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 -0700721
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000722 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 -0700723 mac = self.get_mac(iface)
724 self.host_load(iface)
725 ##we use the defaults for this test that serves as an example for others
726 ##You don't need to restart dhcpd server if retaining default config
727 config = self.default_config
728 options = self.default_options
729 subnet = self.default_subnet_config
730 dhcpd_interface_list = self.relay_interfaces
731 self.dhcpd_start(intf_list = dhcpd_interface_list,
732 config = config,
733 options = options,
734 subnet = subnet)
735 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
736 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000737 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
738 assert_equal(new_cip,cip)
739 assert_equal(lval, lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700740 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700741
742 def test_dhcpRelay_client_renew_time(self, iface = 'veth0'):
743 mac = self.get_mac(iface)
744 self.host_load(iface)
745 ##we use the defaults for this test that serves as an example for others
746 ##You don't need to restart dhcpd server if retaining default config
747 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000748 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700749 options = self.default_options + new_options
750 subnet = self.default_subnet_config
751 dhcpd_interface_list = self.relay_interfaces
752 self.dhcpd_start(intf_list = dhcpd_interface_list,
753 config = config,
754 options = options,
755 subnet = subnet)
756 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
757 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700758 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700759 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000760 assert_not_equal(cip,None)
761 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700762 log_test.info('waiting for renew time..')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000763 time.sleep(lval)
764 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
765 assert_equal(latest_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700766 log_test.info('server renewed client IP when client sends request after renew time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700767
768
769 def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'):
770 mac = self.get_mac(iface)
771 self.host_load(iface)
772 ##we use the defaults for this test that serves as an example for others
773 ##You don't need to restart dhcpd server if retaining default config
774 config = self.default_config
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000775 new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)]
ChetanGaonker5860c182016-07-05 16:33:06 -0700776 options = self.default_options + new_options
777 subnet = self.default_subnet_config
778 dhcpd_interface_list = self.relay_interfaces
779 self.dhcpd_start(intf_list = dhcpd_interface_list,
780 config = config,
781 options = options,
782 subnet = subnet)
783 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
784 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700785 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700786 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000787 assert_not_equal(cip,None)
788 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700789 log_test.info('waiting for rebind time..')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000790 time.sleep(lval)
791 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
792 assert_equal(latest_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700793 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
ChetanGaonker5860c182016-07-05 16:33:06 -0700794
795
796 def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'):
797 mac = self.get_mac(iface)
798 self.host_load(iface)
799 ##we use the defaults for this test that serves as an example for others
800 ##You don't need to restart dhcpd server if retaining default config
801 config = self.default_config
802 options = self.default_options
803 subnet = self.default_subnet_config
804 dhcpd_interface_list = self.relay_interfaces
805 self.dhcpd_start(intf_list = dhcpd_interface_list,
806 config = config,
807 options = options,
808 subnet = subnet)
809 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
810 expected_subnet = '255.255.255.0'
811 self.dhcp.return_option = 'subnet'
812
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000813 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700814 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700815 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000816 assert_equal(subnet_mask,expected_subnet)
A R Karthick76a497a2017-04-12 10:59:39 -0700817 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700818
819
820 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
821 mac = self.get_mac(iface)
822 self.host_load(iface)
823 ##we use the defaults for this test that serves as an example for others
824 ##You don't need to restart dhcpd server if retaining default config
825 config = self.default_config
826 options = self.default_options
827 subnet = self.default_subnet_config
828 dhcpd_interface_list = self.relay_interfaces
829 self.dhcpd_start(intf_list = dhcpd_interface_list,
830 config = config,
831 options = options,
832 subnet = subnet)
833 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
834
835 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700836 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700837 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000838 assert_not_equal(cip,None)
839 self.dhcp.send_different_option = 'subnet'
840 new_cip, new_sip = self.dhcp.only_request(cip, mac)
841 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700842 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700843
844
845 def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'):
846 mac = self.get_mac(iface)
847 self.host_load(iface)
848 ##we use the defaults for this test that serves as an example for others
849 ##You don't need to restart dhcpd server if retaining default config
850 config = self.default_config
851 config = self.default_config
852 new_options = [('routers', '20.20.20.1')]
853 options = self.default_options + new_options
854 subnet = self.default_subnet_config
855 dhcpd_interface_list = self.relay_interfaces
856 self.dhcpd_start(intf_list = dhcpd_interface_list,
857 config = config,
858 options = options,
859 subnet = subnet)
860 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
861 expected_router_address = '20.20.20.1'
862 self.dhcp.return_option = 'router'
863
864 cip, sip, mac, router_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700865 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700866 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000867 assert_equal(expected_router_address, router_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700868 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700869
870
871 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
872 mac = self.get_mac(iface)
873 self.host_load(iface)
874 ##we use the defaults for this test that serves as an example for others
875 ##You don't need to restart dhcpd server if retaining default config
876 config = self.default_config
877 options = self.default_options
878 subnet = self.default_subnet_config
879 dhcpd_interface_list = self.relay_interfaces
880 self.dhcpd_start(intf_list = dhcpd_interface_list,
881 config = config,
882 options = options,
883 subnet = subnet)
884 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
885
886 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700887 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700888 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000889 assert_not_equal(cip,None)
890 self.dhcp.send_different_option = 'router'
891 new_cip, new_sip = self.dhcp.only_request(cip, mac)
892 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700893 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700894
895
896 def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'):
897 mac = self.get_mac(iface)
898 self.host_load(iface)
899 ##we use the defaults for this test that serves as an example for others
900 ##You don't need to restart dhcpd server if retaining default config
901 config = self.default_config
902 options = self.default_options
903 subnet = self.default_subnet_config
904 dhcpd_interface_list = self.relay_interfaces
905 self.dhcpd_start(intf_list = dhcpd_interface_list,
906 config = config,
907 options = options,
908 subnet = subnet)
909 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
910 expected_broadcast_address = '192.168.1.255'
911 self.dhcp.return_option = 'broadcast_address'
912
913 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700914 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700915 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000916 assert_equal(expected_broadcast_address, broadcast_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700917 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700918
919 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
920 mac = self.get_mac(iface)
921 self.host_load(iface)
922 ##we use the defaults for this test that serves as an example for others
923 ##You don't need to restart dhcpd server if retaining default config
924 config = self.default_config
925 options = self.default_options
926 subnet = self.default_subnet_config
927 dhcpd_interface_list = self.relay_interfaces
928 self.dhcpd_start(intf_list = dhcpd_interface_list,
929 config = config,
930 options = options,
931 subnet = subnet)
932 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
933
934 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700935 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700936 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000937 assert_not_equal(cip,None)
938 self.dhcp.send_different_option = 'broadcast_address'
939 new_cip, new_sip = self.dhcp.only_request(cip, mac)
940 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700941 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700942
ChetanGaonker5860c182016-07-05 16:33:06 -0700943
944 def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'):
945 mac = self.get_mac(iface)
946 self.host_load(iface)
947 ##we use the defaults for this test that serves as an example for others
948 ##You don't need to restart dhcpd server if retaining default config
949 config = self.default_config
950 options = self.default_options
951 subnet = self.default_subnet_config
952 dhcpd_interface_list = self.relay_interfaces
953 self.dhcpd_start(intf_list = dhcpd_interface_list,
954 config = config,
955 options = options,
956 subnet = subnet)
957 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
958 expected_dns_address = '192.168.1.1'
959 self.dhcp.return_option = 'dns'
960
961 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700962 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700963 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000964 assert_equal(expected_dns_address, dns_address_value)
A R Karthick76a497a2017-04-12 10:59:39 -0700965 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
ChetanGaonker5860c182016-07-05 16:33:06 -0700966
967 def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
968 mac = self.get_mac(iface)
969 self.host_load(iface)
970 ##we use the defaults for this test that serves as an example for others
971 ##You don't need to restart dhcpd server if retaining default config
972 config = self.default_config
973 options = self.default_options
974 subnet = self.default_subnet_config
975 dhcpd_interface_list = self.relay_interfaces
976 self.dhcpd_start(intf_list = dhcpd_interface_list,
977 config = config,
978 options = options,
979 subnet = subnet)
980 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
981
982 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700983 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker5860c182016-07-05 16:33:06 -0700984 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000985 assert_not_equal(cip,None)
986 self.dhcp.send_different_option = 'dns'
987 new_cip, new_sip = self.dhcp.only_request(cip, mac)
988 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700989 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker5860c182016-07-05 16:33:06 -0700990
ChetanGaonker5860c182016-07-05 16:33:06 -0700991
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700992 def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -0700993
994 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -0700995 self.stats()
A R Karthick76a497a2017-04-12 10:59:39 -0700996 log_test.info("Statistics for run %d",i)
997 log_test.info("----------------------------------------------------------------------------------")
998 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
999 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1000 log_test.info("----------------------------------------------------------------------------------")
1001 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker5860c182016-07-05 16:33:06 -07001002
A R Karthick76a497a2017-04-12 10:59:39 -07001003 log_test.info("Final Statistics for total transactions")
1004 log_test.info("----------------------------------------------------------------------------------")
1005 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1006 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001007 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001008 log_test.info("----------------------------------------------------------------------------------")
1009 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
ChetanGaonker5860c182016-07-05 16:33:06 -07001010
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001011 def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001012
1013 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001014 self.stats(success_rate = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001015 log_test.info("Statistics for run %d",i)
1016 log_test.info("----------------------------------------------------------------------------------")
1017 log_test.info("No. of consecutive successful transactions Running Time ")
1018 log_test.info(" %d %d " %(self.ip_count, self.diff))
1019 log_test.info("----------------------------------------------------------------------------------")
1020 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1021 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001022
A R Karthick76a497a2017-04-12 10:59:39 -07001023 log_test.info("Final Statistics for total successful transactions")
1024 log_test.info("----------------------------------------------------------------------------------")
1025 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1026 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001027 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001028 log_test.info("----------------------------------------------------------------------------------")
1029 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1030 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001031
1032
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001033 def test_dhcpRelay_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001034
1035 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001036 self.stats(only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001037 log_test.info("----------------------------------------------------------------------------------")
1038 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1039 log_test.info("----------------------------------------------------------------------------------")
1040 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1041 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1042 log_test.info("----------------------------------------------------------------------------------")
1043 log_test.info("No. of clients per second in run %d:%f "
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001044 %(i, self.transaction_count))
A R Karthick76a497a2017-04-12 10:59:39 -07001045 log_test.info("----------------------------------------------------------------------------------")
1046 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1047 log_test.info("----------------------------------------------------------------------------------")
1048 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1049 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001050 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001051 log_test.info("----------------------------------------------------------------------------------")
1052 log_test.info("Average no. of clients per second: %d ",
ChetanGaonker5860c182016-07-05 16:33:06 -07001053 round(self.transactions/self.running_time,0))
A R Karthick76a497a2017-04-12 10:59:39 -07001054 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001055
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001056 def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
ChetanGaonker5860c182016-07-05 16:33:06 -07001057
1058 for i in range(1,4):
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001059 self.stats(success_rate = True, only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001060 log_test.info("----------------------------------------------------------------------------------")
1061 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1062 log_test.info("----------------------------------------------------------------------------------")
1063 log_test.info("No. of consecutive successful transactions Running Time ")
1064 log_test.info(" %d %d " %(self.ip_count, self.diff))
1065 log_test.info("----------------------------------------------------------------------------------")
1066 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1067 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001068
A R Karthick76a497a2017-04-12 10:59:39 -07001069 log_test.info("Final Statistics for total successful transactions")
1070 log_test.info("----------------------------------------------------------------------------------")
1071 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1072 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5860c182016-07-05 16:33:06 -07001073 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001074 log_test.info("----------------------------------------------------------------------------------")
1075 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1076 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5860c182016-07-05 16:33:06 -07001077
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001078 def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'):
1079
1080 config = self.default_config
1081 options = self.default_options
1082 subnet = [ ('192.168.1.2',
1083'''
1084subnet 192.168.0.0 netmask 255.255.0.0 {
1085 range 192.168.1.10 192.168.2.100;
1086}
1087'''), ]
1088
1089 dhcpd_interface_list = self.relay_interfaces
1090 self.dhcpd_start(intf_list = dhcpd_interface_list,
1091 config = config,
1092 options = options,
1093 subnet = subnet)
1094
1095 for key in (key for key in g_subscriber_port_map if key < 100):
1096 self.host_load(g_subscriber_port_map[key])
1097
1098 def thread_fun(i):
1099 mac = self.get_mac('veth{}'.format(i))
1100 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001101 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001102 self.lock.acquire()
1103
1104 if cip:
1105 self.ip_count += 1
1106
1107 elif cip is None:
1108 self.failure_count += 1
1109
1110 self.lock.notify_all()
1111 self.lock.release()
1112
1113 for i in range (1,4):
1114 self.ip_count = 0
1115 self.failure_count = 0
1116 self.start_time = 0
1117 self.diff = 0
1118 self.transaction_count = 0
1119 self.start_time = time.time()
1120
1121 while self.diff <= 60:
1122 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1123 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1124 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1125 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1126 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1127 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1128
1129 t.start()
1130 t1.start()
1131 t2.start()
1132 t3.start()
1133 t4.start()
1134 t5.start()
1135
1136 t.join()
1137 t1.join()
1138 t2.join()
1139 t3.join()
1140 t4.join()
1141 t5.join()
1142
1143 self.diff = round(time.time() - self.start_time, 0)
1144
1145 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1146
1147 self.transactions += (self.ip_count+self.failure_count)
1148 self.running_time += self.diff
1149 self.total_success += self.ip_count
1150 self.total_failure += self.failure_count
1151
1152
A R Karthick76a497a2017-04-12 10:59:39 -07001153 log_test.info("----------------------------------------------------------------------------------")
1154 log_test.info("Statistics for run %d",i)
1155 log_test.info("----------------------------------------------------------------------------------")
1156 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1157 log_test.info(" %d %d %d %d"
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001158 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
A R Karthick76a497a2017-04-12 10:59:39 -07001159 log_test.info("----------------------------------------------------------------------------------")
1160 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1161 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001162
A R Karthick76a497a2017-04-12 10:59:39 -07001163 log_test.info("----------------------------------------------------------------------------------")
1164 log_test.info("Final Statistics for total transactions")
1165 log_test.info("----------------------------------------------------------------------------------")
1166 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1167 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001168 self.total_success, self.total_failure, self.running_time))
1169
A R Karthick76a497a2017-04-12 10:59:39 -07001170 log_test.info("----------------------------------------------------------------------------------")
1171 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1172 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001173
1174 def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
1175
1176 config = self.default_config
1177 options = self.default_options
1178 subnet = [ ('192.168.1.2',
1179'''
1180subnet 192.168.0.0 netmask 255.255.0.0 {
1181 range 192.168.1.10 192.168.2.100;
1182}
1183'''), ]
1184
1185 dhcpd_interface_list = self.relay_interfaces
1186 self.dhcpd_start(intf_list = dhcpd_interface_list,
1187 config = config,
1188 options = options,
1189 subnet = subnet)
1190 failure_dir = {}
1191
1192 for key in (key for key in g_subscriber_port_map if key != 100):
1193 self.host_load(g_subscriber_port_map[key])
1194
1195 def thread_fun(i, j):
A R Karthick76a497a2017-04-12 10:59:39 -07001196# log_test.info("Thread Name:%s",current_thread().name)
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001197# failure_dir[current_thread().name] = True
1198 while failure_dir.has_key(current_thread().name) is False:
1199 mac = RandMAC()._fix()
1200 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1201 i += 2
A R Karthick76a497a2017-04-12 10:59:39 -07001202 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001203 self.lock.acquire()
1204
1205 if cip:
1206 self.ip_count += 1
1207 self.lock.notify_all()
1208 self.lock.release()
1209 elif cip is None:
1210 self.failure_count += 1
1211 failure_dir[current_thread().name] = True
1212 self.lock.notify_all()
1213 self.lock.release()
1214 break
1215# self.lock.notify_all()
1216# self.lock.release()
1217
1218 for i in range (1,4):
1219 failure_dir = {}
1220 self.ip_count = 0
1221 self.failure_count = 0
1222 self.start_time = 0
1223 self.diff = 0
1224 self.transaction_count = 0
1225 self.start_time = time.time()
1226
1227 while len(failure_dir) != 6:
1228 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1229 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1230 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1231 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1232 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1233 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1234
1235 t.start()
1236 t1.start()
1237 t2.start()
1238 t3.start()
1239 t4.start()
1240 t5.start()
1241
1242 t.join()
1243 t1.join()
1244 t2.join()
1245 t3.join()
1246 t4.join()
1247 t5.join()
1248
1249 self.diff = round(time.time() - self.start_time, 0)
1250 self.transaction_count = round((self.ip_count)/self.diff, 2)
1251
1252 self.transactions += (self.ip_count+self.failure_count)
1253 self.running_time += self.diff
1254 self.total_success += self.ip_count
1255 self.total_failure += self.failure_count
1256
1257
A R Karthick76a497a2017-04-12 10:59:39 -07001258 log_test.info("Statistics for run %d",i)
1259 log_test.info("----------------------------------------------------------------------------------")
1260 log_test.info("No. of consecutive successful transactions Running Time ")
1261 log_test.info(" %d %d " %(self.ip_count, self.diff))
1262 log_test.info("----------------------------------------------------------------------------------")
1263 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1264 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001265
A R Karthick76a497a2017-04-12 10:59:39 -07001266 log_test.info("Final Statistics for total successful transactions")
1267 log_test.info("----------------------------------------------------------------------------------")
1268 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1269 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001270 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001271 log_test.info("----------------------------------------------------------------------------------")
1272 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1273 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001274
1275 def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'):
1276
1277 config = self.default_config
1278 options = self.default_options
1279 subnet = [ ('192.168.1.2',
1280'''
1281subnet 192.168.0.0 netmask 255.255.0.0 {
1282 range 192.168.1.10 192.168.2.100;
1283}
1284'''), ]
1285
1286 dhcpd_interface_list = self.relay_interfaces
1287 self.dhcpd_start(intf_list = dhcpd_interface_list,
1288 config = config,
1289 options = options,
1290 subnet = subnet)
1291
1292 for key in (key for key in g_subscriber_port_map if key < 100):
1293 self.host_load(g_subscriber_port_map[key])
1294
1295 def thread_fun(i):
1296# mac = self.get_mac('veth{}'.format(i))
1297 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
A R Karthick76a497a2017-04-12 10:59:39 -07001298 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001299 self.lock.acquire()
1300
1301 if cip:
1302 self.ip_count += 1
1303 elif cip is None:
1304 self.failure_count += 1
1305
1306 self.lock.notify_all()
1307 self.lock.release()
1308
1309 for i in range (1,4):
1310 self.ip_count = 0
1311 self.failure_count = 0
1312 self.start_time = 0
1313 self.diff = 0
1314 self.transaction_count = 0
1315 self.start_time = time.time()
1316
1317 while self.diff <= 60:
1318 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1319 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1320 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1321 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1322 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1323 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1324
1325 t.start()
1326 t1.start()
1327 t2.start()
1328 t3.start()
1329 t4.start()
1330 t5.start()
1331
1332 t.join()
1333 t1.join()
1334 t2.join()
1335 t3.join()
1336 t4.join()
1337 t5.join()
1338
1339 self.diff = round(time.time() - self.start_time, 0)
1340 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1341 self.transactions += (self.ip_count+self.failure_count)
1342 self.running_time += self.diff
1343 self.total_success += self.ip_count
1344 self.total_failure += self.failure_count
1345
A R Karthick76a497a2017-04-12 10:59:39 -07001346 log_test.info("----------------------------------------------------------------------------------")
1347 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1348 log_test.info("----------------------------------------------------------------------------------")
1349 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1350 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1351 log_test.info("----------------------------------------------------------------------------------")
1352 log_test.info("No. of clients per second in run %d:%f "
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001353 %(i, self.transaction_count))
A R Karthick76a497a2017-04-12 10:59:39 -07001354 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001355
A R Karthick76a497a2017-04-12 10:59:39 -07001356 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1357 log_test.info("----------------------------------------------------------------------------------")
1358 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1359 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001360 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -07001361 log_test.info("----------------------------------------------------------------------------------")
1362 log_test.info("Average no. of clients per second: %d ",
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001363 round(self.transactions/self.running_time,0))
A R Karthick76a497a2017-04-12 10:59:39 -07001364 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001365
1366
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001367 def test_dhcpRelay_client_conflict(self, iface = 'veth0'):
1368 mac = self.get_mac(iface)
1369 self.host_load(iface)
1370 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1371 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07001372 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001373 (cip, sip, mac) )
1374 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1375 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1376 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001377 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001378 (new_cip, new_sip, new_mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07001379 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1380 log_test.info("Now sending DHCP Request for old DHCP discover.")
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001381 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1382 if new_cip is None:
A R Karthick76a497a2017-04-12 10:59:39 -07001383 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
ChetanGaonker5b984cb2016-07-12 15:50:49 -07001384 %(new_cip, new_sip, new_mac) )
1385 elif new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07001386 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 -07001387 %(new_cip, new_sip, new_mac, new_cip) )
1388 assert_equal(new_cip, None)