blob: e2cceb5ca4d99dddd3163adef8e0fec76053e12f [file] [log] [blame]
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001
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
17#
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,
28# WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied.
29# 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
36import time
37import os, sys
38from DHCP import DHCPTest
39from CordTestUtils import get_mac, log_test
40from OnosCtrl import OnosCtrl
41from OltConfig import OltConfig
42from CordTestServer import cord_test_onos_restart
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070043from CordTestConfig import setup_module, teardown_module
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000044from CordLogger import CordLogger
45from portmaps import g_subscriber_port_map
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070046from CordContainer import Onos
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000047import threading, random
48from threading import current_thread
49log_test.setLevel('INFO')
50
51class dhcpl2relay_exchange(CordLogger):
52
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070053 VOLTHA_HOST = None
54 VOLTHA_REST_PORT = 8881
55 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
56 VOLTHA_OLT_TYPE = 'simulated_olt'
57 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
58 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
59
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000060 app = 'org.opencord.dhcpl2relay'
61 sadis_app = 'org.opencord.sadis'
62 app_dhcp = 'org.onosproject.dhcp'
63 relay_interfaces_last = ()
64 interface_to_mac_map = {}
65 host_ip_map = {}
66 test_path = os.path.dirname(os.path.realpath(__file__))
67 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070068 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
69 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
70 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config_voltha_local.json'))
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000071 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
72 default_options = [ ('subnet-mask', '255.255.255.0'),
73 ('broadcast-address', '192.168.1.255'),
74 ('domain-name-servers', '192.168.1.1'),
75 ('domain-name', '"mydomain.cord-tester"'),
76 ]
77 default_subnet_config = [ ('192.168.1.2',
78'''
79subnet 192.168.1.0 netmask 255.255.255.0 {
80 range 192.168.1.10 192.168.1.100;
81}
82'''), ]
83
84 lock = threading.Condition()
85 ip_count = 0
86 failure_count = 0
87 start_time = 0
88 diff = 0
89
90 transaction_count = 0
91 transactions = 0
92 running_time = 0
93 total_success = 0
94 total_failure = 0
95 #just in case we want to reset ONOS to default network cfg after relay tests
96 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
97 configs = {}
98
99 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700100 def update_apps_version(cls):
101 version = Onos.getVersion()
102 major = int(version.split('.')[0])
103 minor = int(version.split('.')[1])
104 dhcpl2_app_version = '1.0.0'
105 sadis_app_version = '1.0.0-SNAPSHOT'
106# sadis-app-1.0.0-SNAPSHOT.oar
107# if major > 1:
108# cordigmp_app_version = '3.0-SNAPSHOT'
109# olt_app_version = '2.0-SNAPSHOT'
110# elif major == 1:
111# if minor > 10:
112# cordigmp_app_version = '3.0-SNAPSHOT'
113# olt_app_version = '2.0-SNAPSHOT'
114# elif minor <= 8:
115# olt_app_version = '1.1-SNAPSHOT'
116 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
117 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
118
119
120 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000121 def setUpClass(cls):
122 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700123 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000124 OnosCtrl(cls.app_dhcp).deactivate()
125 time.sleep(3)
126 cls.onos_ctrl = OnosCtrl(cls.app)
127 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700128 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000129 time.sleep(3)
130 cls.onos_ctrl = OnosCtrl(cls.sadis_app)
131 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700132 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000133 time.sleep(3)
134 cls.dhcp_l2_relay_setup()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700135 cls.cord_sadis_load()
136 cls.cord_l2_relay_load()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000137 ##start dhcpd initially with default config
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700138 #cls.dhcpd_start()
139
140 def setUp(self):
141 super(dhcpl2relay_exchange, self).setUp()
142
143 def tearDown(self):
144 super(dhcpl2relay_exchange, self).tearDown()
145 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
146 OnosCtrl.uninstall_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000147
148 @classmethod
149 def tearDownClass(cls):
150 '''Deactivate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700151 #try:
152 # os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
153 # os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
154 #except: pass
155 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
156 OnosCtrl.uninstall_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000157 cls.onos_ctrl.deactivate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700158 #cls.dhcpd_stop()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000159 cls.dhcp_l2_relay_cleanup()
160
161 @classmethod
162 def dhcp_l2_relay_setup(cls):
163 did = OnosCtrl.get_device_id()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700164 #cls.relay_device_id = did
165 ### Have to change hard coded value in relay device variable on later merges
166 cls.relay_device_id = 'of:000012b722fd4948'
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000167 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
168 cls.port_map, _ = cls.olt.olt_port_map()
169 if cls.port_map:
170 ##Per subscriber, we use 1 relay port
171 try:
172 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
173 except:
174 relay_port = cls.port_map['uplink']
175 cls.relay_interface_port = relay_port
176 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
177 else:
178 cls.relay_interface_port = 100
179 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
180 cls.relay_interfaces_last = cls.relay_interfaces
181 if cls.port_map:
182 ##generate a ip/mac client virtual interface config for onos
183 interface_list = []
184 for port in cls.port_map['ports']:
185 port_num = cls.port_map[port]
186 if port_num == cls.port_map['uplink']:
187 continue
188 ip = cls.get_host_ip(port_num)
189 mac = cls.get_mac(port)
190 interface_list.append((port_num, ip, mac))
191
192 #configure dhcp server virtual interface on the same subnet as first client interface
193 relay_ip = cls.get_host_ip(interface_list[0][0])
194 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
195 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700196 #cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000197
198 @classmethod
199 def dhcp_l2_relay_cleanup(cls):
200 ##reset the ONOS port configuration back to default
201 for config in cls.configs.items():
202 OnosCtrl.delete(config)
203 # if cls.onos_restartable is True:
204 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
205 # return cord_test_onos_restart(config = {})
206
207 @classmethod
208 def onos_load_config(cls, config):
209 status, code = OnosCtrl.config(config)
210 if status is False:
211 log_test.info('JSON request returned status %d' %code)
212 assert_equal(status, True)
213 time.sleep(3)
214
215 @classmethod
216 def onos_interface_load(cls, interface_list):
217 interface_dict = { 'ports': {} }
218 for port_num, ip, mac in interface_list:
219 port_map = interface_dict['ports']
220 port = '{}/{}'.format(cls.relay_device_id, port_num)
221 port_map[port] = { 'interfaces': [] }
222 interface_list = port_map[port]['interfaces']
223 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
224 'mac' : mac,
225 'name': 'vir-{}'.format(port_num)
226 }
227 interface_list.append(interface_map)
228
229 cls.onos_load_config(interface_dict)
230 cls.configs['interface_config'] = interface_dict
231
232 @classmethod
233 def cord_l2_relay_load(cls):
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700234 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
235 #relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
236 relay_device_map = "{}/veth42".format(cls.relay_device_id)
237 print relay_device_map
238 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
239 {"dhcpserverConnectPoint":[relay_device_map]}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000240 }
241 }
242 }
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700243 print "---------------------------------------------"
244 print dhcp_dict
245 print "---------------------------------------------"
246 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
247 OnosCtrl.install_app(cls.dhcpl2_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000248 cls.onos_load_config(dhcp_dict)
249 cls.configs['relay_config'] = dhcp_dict
250
251 @classmethod
252 def cord_sadis_load(cls):
253 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700254 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000255 "org.opencord.sadis": {
256 "sadis": {
257 "integration": {
258 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700259 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000260 "maxsize": 50,
261 "ttl": "PT1m"
262 }
263 },
264 "entries": [{
265 "id": "uni-254",
266 "cTag": 202,
267 "sTag": 222,
268 "nasPortId": "uni-254"
269 },
270 {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700271 "id": "67cc7ae085204e3091493db645e8ae63",
272 "hardwareIdentifier": "00:0c:e2:31:05:00",
273 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000274 "nasId": "B100-NASID"
275 }
276 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700277 }
278 }
279 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000280 }
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700281 OnosCtrl.uninstall_app(cls.sadis_app_file)
282 OnosCtrl.install_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000283 cls.onos_load_config(sadis_dict)
284 cls.configs['relay_config'] = sadis_dict
285
286 @classmethod
287 def get_host_ip(cls, port):
288 if cls.host_ip_map.has_key(port):
289 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700290 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000291 return cls.host_ip_map[port]
292
293 @classmethod
294 def host_load(cls, iface):
295 '''Have ONOS discover the hosts for dhcp-relay responses'''
296 port = g_subscriber_port_map[iface]
297 host = '173.17.1.{}'.format(port)
298 cmds = ( 'ifconfig {} 0'.format(iface),
299 'ifconfig {0} {1}'.format(iface, host),
300 'arping -I {0} {1} -c 2'.format(iface, host),
301 'ifconfig {} 0'.format(iface), )
302 for c in cmds:
303 os.system(c)
304
305 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000306 def get_mac(cls, iface):
307 if cls.interface_to_mac_map.has_key(iface):
308 return cls.interface_to_mac_map[iface]
309 mac = get_mac(iface, pad = 0)
310 cls.interface_to_mac_map[iface] = mac
311 return mac
312
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000313 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000314
315 self.ip_count = 0
316 self.failure_count = 0
317 self.start_time = 0
318 self.diff = 0
319 self.transaction_count = 0
320
321 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000322 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
323 self.start_time = time.time()
324
325 while self.diff <= 60:
326
327 if only_discover:
328 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
329 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
330 (cip, sip, mac))
331 else:
332 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
333
334 if cip:
335 self.ip_count +=1
336 elif cip == None:
337 self.failure_count += 1
338 log_test.info('Failed to get ip')
339 if success_rate and self.ip_count > 0:
340 break
341
342 self.diff = round(time.time() - self.start_time, 0)
343
344 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
345 self.transactions += (self.ip_count+self.failure_count)
346 self.running_time += self.diff
347 self.total_success += self.ip_count
348 self.total_failure += self.failure_count
349
350 def send_recv(self, mac=None, update_seed = False, validate = True):
351 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
352 if validate:
353 assert_not_equal(cip, None)
354 assert_not_equal(sip, None)
355 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
356 (cip, sip, self.dhcp.get_mac(cip)[0]))
357 return cip,sip
358
359 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
360 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000361 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
362 self.send_recv(mac=mac)
363
Chetan Gaonker891302d2017-09-05 15:09:26 +0000364 def test_dhcpl2relay_app_install(self):
365 pass
366
367 def test_dhcpl2relay_netcfg(self):
368 pass
369
370 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self):
371 pass
372
373 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self):
374 pass
375
376 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self):
377 pass
378
379 def test_dhcpl2relay_without_sadis_app(self):
380 pass
381
382 def test_dhcpl2relay_with_sadis_app(self):
383 pass
384
385 def test_dhcpl2relay_with_option_82(self):
386 pass
387
388 def test_dhcpl2relay_without_option_82(self):
389 pass
390
391 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self):
392 pass
393
394 def test_dhcpl2relay_with_uni_port_entry_sadis_config(self):
395 pass
396
397 def test_dhcpl2relay_with_wrong_ctag_options(self):
398 pass
399
400 def test_dhcpl2relay_with_wrong_stag_options(self):
401 pass
402
403 def test_dhcpl2relay_with_nasportid_option_in_sadis(self):
404 pass
405
406 def test_dhcpl2relay_with_nasportid_different_from_id(self):
407 pass
408
409 def test_dhcpl2relay_with_serial_id_of_olt(self):
410 pass
411
412 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self):
413 pass
414
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000415 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
416 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000417 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
418 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
419 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000420 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000421
422 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
423 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000424 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
425 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
426 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000427 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000428
429 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
430 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000431 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
432 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
433 assert_equal(cip,None)
434 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
435
436 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
437 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700438 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000439 ip_map = {}
440 for i in range(requests):
441 #mac = RandMAC()._fix()
442 #log_test.info('mac is %s'%mac)
443 cip, sip = self.send_recv(update_seed = True)
444 if ip_map.has_key(cip):
445 log_test.info('IP %s given out multiple times' %cip)
446 assert_equal(False, ip_map.has_key(cip))
447 ip_map[cip] = sip
448 time.sleep(1)
449
450 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
451 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000452 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
453 cip, sip = self.send_recv(mac=mac)
454 log_test.info('Releasing ip %s to server %s' %(cip, sip))
455 assert_equal(self.dhcp.release(cip), True)
456 log_test.info('Triggering DHCP discover again after release')
457 cip2, sip2 = self.send_recv(mac=mac)
458 log_test.info('Verifying released IP was given back on rediscover')
459 assert_equal(cip, cip2)
460 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
461 assert_equal(self.dhcp.release(cip2), True)
462
463 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
464 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000465 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
466 ip_map = {}
467 for i in range(10):
468 cip, sip = self.send_recv(mac=mac, update_seed = True)
469 if ip_map.has_key(cip):
470 log_test.info('IP %s given out multiple times' %cip)
471 assert_equal(False, ip_map.has_key(cip))
472 ip_map[cip] = sip
473
474 for ip in ip_map.keys():
475 log_test.info('Releasing IP %s' %ip)
476 assert_equal(self.dhcp.release(ip), True)
477
478 ip_map2 = {}
479 log_test.info('Triggering DHCP discover again after release')
480 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
481 for i in range(len(ip_map.keys())):
482 cip, sip = self.send_recv(mac=mac, update_seed = True)
483 ip_map2[cip] = sip
484
485 log_test.info('Verifying released IPs were given back on rediscover')
486 if ip_map != ip_map2:
487 log_test.info('Map before release %s' %ip_map)
488 log_test.info('Map after release %s' %ip_map2)
489 assert_equal(ip_map, ip_map2)
490
491 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
492 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000493 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
494 log_test.info('Verifying 1 ')
495 count = 0
496 while True:
497 #mac = RandMAC()._fix()
498 cip, sip = self.send_recv(update_seed = True,validate = False)
499 if cip is None:
500 break
501 else:
502 count += 1
503 assert_equal(count,91)
504 log_test.info('Verifying 2 ')
505 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
506 assert_equal(cip, None)
507 assert_equal(sip, None)
508
509 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
510 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000511 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
512 cip, sip, mac, _ = self.dhcp.only_discover()
513 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
514 (cip, sip, mac) )
515 assert_not_equal(cip, None)
516 log_test.info('Triggering DHCP discover again.')
517 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
518 assert_equal(new_cip, cip)
519 log_test.info('got same ip to smae the client when sent discover again, as expected')
520
521 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
522 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000523 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
524 log_test.info('Sending DHCP discover and DHCP request.')
525 cip, sip = self.send_recv(mac=mac)
526 mac = self.dhcp.get_mac(cip)[0]
527 log_test.info("Sending DHCP request again.")
528 new_cip, new_sip = self.dhcp.only_request(cip, mac)
529 assert_equal(new_cip, cip)
530 log_test.info('got same ip to smae the client when sent request again, as expected')
531
532 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
533 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000534 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
535 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
536 assert_equal(cip,self.dhcp.seed_ip)
537 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
538 (cip, sip, mac) )
539
540 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
541 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000542 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
543 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
544 assert_not_equal(cip,None)
545 assert_not_equal(cip,self.dhcp.seed_ip)
546 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
547
548 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
549 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000550 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
551 cip, sip, mac, _ = self.dhcp.only_discover()
552 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
553 (cip, sip, mac) )
554 assert_not_equal(cip, None)
555 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
556 assert_equal(new_cip, None)
557 log_test.info('server sent NAK packet when requested other IP than that server offered')
558
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000559 def test_dhcpl2relay_with_client_requests_with_specific_lease_time_in_discover_message(self, iface = 'veth0',lease_time=700):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000560 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000561 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
562 self.dhcp.return_option = 'lease'
563 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
564 assert_equal(lval, lease_time)
565 log_test.info('dhcp server offered IP address with client requested lease time')
566
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000567 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000568 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000569 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
570 cip, sip, mac, _ = self.dhcp.only_discover()
571 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
572 (cip, sip, mac) )
573 assert_not_equal(cip, None)
574 new_cip, new_sip = self.dhcp.only_request(cip, mac)
575 log_test.info('client rebooting...')
576 os.system('ifconfig '+iface+' down')
577 time.sleep(5)
578 os.system('ifconfig '+iface+' up')
579 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
580 assert_equal(new_cip2, cip)
581 log_test.info('client got same IP after reboot, as expected')
582
583
584 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
585 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000586 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
587 cip, sip, mac, _ = self.dhcp.only_discover()
588 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
589 (cip, sip, mac) )
590 assert_not_equal(cip, None)
591 new_cip, new_sip = self.dhcp.only_request(cip, mac)
592 log_test.info('server rebooting...')
593 self.tearDownClass()
594 new_cip, new_sip = self.dhcp.only_request(cip, mac)
595 assert_equal(new_cip,None)
596 self.setUpClass()
597 new_cip, new_sip = self.dhcp.only_request(cip, mac)
598 assert_equal(new_cip, cip)
599 log_test.info('client got same IP after server rebooted, as expected')
600
601 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
602 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000603 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
604 self.dhcp.return_option = 'lease'
605 log_test.info('Sending DHCP discover with lease time of 700')
606 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
607 assert_equal(lval,lease_time)
608 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
609 assert_equal(new_cip,cip)
610 assert_not_equal(lval, lease_time) #Negative Test Case
611 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
612
613 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
614 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000615 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
616 cip, sip, mac, _ = self.dhcp.only_discover()
617 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
618 assert_equal(new_cip,cip)
619 assert_equal(lval, lease_time)
620 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
621
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000622 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000623 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000624 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
625 cip, sip, mac, _ = self.dhcp.only_discover()
626 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
627 (cip, sip, mac) )
628 assert_not_equal(cip,None)
629 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
630 log_test.info('waiting for renew time..')
631 time.sleep(lval)
632 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
633 assert_equal(latest_cip, cip)
634 log_test.info('server renewed client IP when client sends request after renew time, as expected')
635
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000636 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000637 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000638 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
639 cip, sip, mac, _ = self.dhcp.only_discover()
640 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
641 (cip, sip, mac) )
642 assert_not_equal(cip,None)
643 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
644 log_test.info('waiting for rebind time..')
645 time.sleep(lval)
646 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
647 assert_equal(latest_cip, cip)
648 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
649
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000650 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000651 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000652 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
653 expected_subnet = '255.255.255.0'
654 self.dhcp.return_option = 'subnet'
655
656 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
657 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
658 (cip, sip, mac) )
659 assert_equal(subnet_mask,expected_subnet)
660 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
661
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000662 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000663 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000664 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
665
666 cip, sip, mac, _ = self.dhcp.only_discover()
667 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
668 (cip, sip, mac) )
669 assert_not_equal(cip,None)
670 self.dhcp.send_different_option = 'subnet'
671 new_cip, new_sip = self.dhcp.only_request(cip, mac)
672 assert_equal(new_cip, cip)
673 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
674
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000675 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000676 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000677 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
678 expected_router_address = '20.20.20.1'
679 self.dhcp.return_option = 'router'
680
681 cip, sip, mac, router_address_value = self.dhcp.only_discover()
682 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
683 (cip, sip, mac) )
684 assert_equal(expected_router_address, router_address_value)
685 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
686
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000687 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000688 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000689 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
690
691 cip, sip, mac, _ = self.dhcp.only_discover()
692 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
693 (cip, sip, mac) )
694 assert_not_equal(cip,None)
695 self.dhcp.send_different_option = 'router'
696 new_cip, new_sip = self.dhcp.only_request(cip, mac)
697 assert_equal(new_cip, cip)
698 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
699
700 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
701 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000702 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
703 expected_broadcast_address = '192.168.1.255'
704 self.dhcp.return_option = 'broadcast_address'
705
706 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
707 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
708 (cip, sip, mac) )
709 assert_equal(expected_broadcast_address, broadcast_address_value)
710 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
711
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000712 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000713 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000714 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
715
716 cip, sip, mac, _ = self.dhcp.only_discover()
717 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
718 (cip, sip, mac) )
719 assert_not_equal(cip,None)
720 self.dhcp.send_different_option = 'broadcast_address'
721 new_cip, new_sip = self.dhcp.only_request(cip, mac)
722 assert_equal(new_cip, cip)
723 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
724
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000725 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000726 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000727 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
728 expected_dns_address = '192.168.1.1'
729 self.dhcp.return_option = 'dns'
730
731 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
732 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
733 (cip, sip, mac) )
734 assert_equal(expected_dns_address, dns_address_value)
735 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
736
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000737 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000738 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000739 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
740
741 cip, sip, mac, _ = self.dhcp.only_discover()
742 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
743 (cip, sip, mac) )
744 assert_not_equal(cip,None)
745 self.dhcp.send_different_option = 'dns'
746 new_cip, new_sip = self.dhcp.only_request(cip, mac)
747 assert_equal(new_cip, cip)
748 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
749
750
751 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
752
753 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000754 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000755 log_test.info("Statistics for run %d",i)
756 log_test.info("----------------------------------------------------------------------------------")
757 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
758 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
759 log_test.info("----------------------------------------------------------------------------------")
760 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
761
762 log_test.info("Final Statistics for total transactions")
763 log_test.info("----------------------------------------------------------------------------------")
764 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
765 log_test.info(" %d %d %d %d" %(self.transactions,
766 self.total_success, self.total_failure, self.running_time))
767 log_test.info("----------------------------------------------------------------------------------")
768 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
769
770 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
771
772 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000773 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000774 log_test.info("Statistics for run %d",i)
775 log_test.info("----------------------------------------------------------------------------------")
776 log_test.info("No. of consecutive successful transactions Running Time ")
777 log_test.info(" %d %d " %(self.ip_count, self.diff))
778 log_test.info("----------------------------------------------------------------------------------")
779 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
780 log_test.info("----------------------------------------------------------------------------------")
781
782 log_test.info("Final Statistics for total successful transactions")
783 log_test.info("----------------------------------------------------------------------------------")
784 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
785 log_test.info(" %d %d %d " %(self.transactions,
786 self.total_success, self.running_time))
787 log_test.info("----------------------------------------------------------------------------------")
788 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
789 log_test.info("----------------------------------------------------------------------------------")
790
791 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
792
793 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000794 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000795 log_test.info("----------------------------------------------------------------------------------")
796 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
797 log_test.info("----------------------------------------------------------------------------------")
798 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
799 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
800 log_test.info("----------------------------------------------------------------------------------")
801 log_test.info("No. of clients per second in run %d:%f "
802 %(i, self.transaction_count))
803 log_test.info("----------------------------------------------------------------------------------")
804 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
805 log_test.info("----------------------------------------------------------------------------------")
806 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
807 log_test.info(" %d %d %d %d" %(self.transactions,
808 self.total_success, self.total_failure, self.running_time))
809 log_test.info("----------------------------------------------------------------------------------")
810 log_test.info("Average no. of clients per second: %d ",
811 round(self.transactions/self.running_time,0))
812 log_test.info("----------------------------------------------------------------------------------")
813
814 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
815
816 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000817 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000818 log_test.info("----------------------------------------------------------------------------------")
819 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
820 log_test.info("----------------------------------------------------------------------------------")
821 log_test.info("No. of consecutive successful transactions Running Time ")
822 log_test.info(" %d %d " %(self.ip_count, self.diff))
823 log_test.info("----------------------------------------------------------------------------------")
824 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
825 log_test.info("----------------------------------------------------------------------------------")
826
827 log_test.info("Final Statistics for total successful transactions")
828 log_test.info("----------------------------------------------------------------------------------")
829 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
830 log_test.info(" %d %d %d " %(self.transactions,
831 self.total_success, self.running_time))
832 log_test.info("----------------------------------------------------------------------------------")
833 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
834 log_test.info("----------------------------------------------------------------------------------")
835
836 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000837 for key in (key for key in g_subscriber_port_map if key < 100):
838 self.host_load(g_subscriber_port_map[key])
839
840 def thread_fun(i):
841 mac = self.get_mac('veth{}'.format(i))
842 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
843 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
844 self.lock.acquire()
845
846 if cip:
847 self.ip_count += 1
848
849 elif cip is None:
850 self.failure_count += 1
851
852 self.lock.notify_all()
853 self.lock.release()
854
855 for i in range (1,4):
856 self.ip_count = 0
857 self.failure_count = 0
858 self.start_time = 0
859 self.diff = 0
860 self.transaction_count = 0
861 self.start_time = time.time()
862
863 while self.diff <= 60:
864 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
865 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
866 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
867 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
868 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
869 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
870
871 t.start()
872 t1.start()
873 t2.start()
874 t3.start()
875 t4.start()
876 t5.start()
877
878 t.join()
879 t1.join()
880 t2.join()
881 t3.join()
882 t4.join()
883 t5.join()
884
885 self.diff = round(time.time() - self.start_time, 0)
886
887 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
888
889 self.transactions += (self.ip_count+self.failure_count)
890 self.running_time += self.diff
891 self.total_success += self.ip_count
892 self.total_failure += self.failure_count
893
894
895 log_test.info("----------------------------------------------------------------------------------")
896 log_test.info("Statistics for run %d",i)
897 log_test.info("----------------------------------------------------------------------------------")
898 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
899 log_test.info(" %d %d %d %d"
900 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
901 log_test.info("----------------------------------------------------------------------------------")
902 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
903 log_test.info("----------------------------------------------------------------------------------")
904
905 log_test.info("----------------------------------------------------------------------------------")
906 log_test.info("Final Statistics for total transactions")
907 log_test.info("----------------------------------------------------------------------------------")
908 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
909 log_test.info(" %d %d %d %d" %(self.transactions,
910 self.total_success, self.total_failure, self.running_time))
911
912 log_test.info("----------------------------------------------------------------------------------")
913 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
914 log_test.info("----------------------------------------------------------------------------------")
915
916 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000917 failure_dir = {}
918
919 for key in (key for key in g_subscriber_port_map if key != 100):
920 self.host_load(g_subscriber_port_map[key])
921
922 def thread_fun(i, j):
923# log_test.info("Thread Name:%s",current_thread().name)
924# failure_dir[current_thread().name] = True
925 while failure_dir.has_key(current_thread().name) is False:
926 mac = RandMAC()._fix()
927 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
928 i += 2
929 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
930 self.lock.acquire()
931
932 if cip:
933 self.ip_count += 1
934 self.lock.notify_all()
935 self.lock.release()
936 elif cip is None:
937 self.failure_count += 1
938 failure_dir[current_thread().name] = True
939 self.lock.notify_all()
940 self.lock.release()
941 break
942# self.lock.notify_all()
943# self.lock.release()
944
945 for i in range (1,4):
946 failure_dir = {}
947 self.ip_count = 0
948 self.failure_count = 0
949 self.start_time = 0
950 self.diff = 0
951 self.transaction_count = 0
952 self.start_time = time.time()
953
954 while len(failure_dir) != 6:
955 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
956 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
957 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
958 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
959 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
960 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
961
962 t.start()
963 t1.start()
964 t2.start()
965 t3.start()
966 t4.start()
967 t5.start()
968
969 t.join()
970 t1.join()
971 t2.join()
972 t3.join()
973 t4.join()
974 t5.join()
975
976 self.diff = round(time.time() - self.start_time, 0)
977 self.transaction_count = round((self.ip_count)/self.diff, 2)
978
979 self.transactions += (self.ip_count+self.failure_count)
980 self.running_time += self.diff
981 self.total_success += self.ip_count
982 self.total_failure += self.failure_count
983
984
985 log_test.info("Statistics for run %d",i)
986 log_test.info("----------------------------------------------------------------------------------")
987 log_test.info("No. of consecutive successful transactions Running Time ")
988 log_test.info(" %d %d " %(self.ip_count, self.diff))
989 log_test.info("----------------------------------------------------------------------------------")
990 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
991 log_test.info("----------------------------------------------------------------------------------")
992
993 log_test.info("Final Statistics for total successful transactions")
994 log_test.info("----------------------------------------------------------------------------------")
995 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
996 log_test.info(" %d %d %d " %(self.transactions,
997 self.total_success, self.running_time))
998 log_test.info("----------------------------------------------------------------------------------")
999 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1000 log_test.info("----------------------------------------------------------------------------------")
1001
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001002 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001003 for key in (key for key in g_subscriber_port_map if key < 100):
1004 self.host_load(g_subscriber_port_map[key])
1005
1006 def thread_fun(i):
1007# mac = self.get_mac('veth{}'.format(i))
1008 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1009 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1010 self.lock.acquire()
1011
1012 if cip:
1013 self.ip_count += 1
1014 elif cip is None:
1015 self.failure_count += 1
1016
1017 self.lock.notify_all()
1018 self.lock.release()
1019
1020 for i in range (1,4):
1021 self.ip_count = 0
1022 self.failure_count = 0
1023 self.start_time = 0
1024 self.diff = 0
1025 self.transaction_count = 0
1026 self.start_time = time.time()
1027
1028 while self.diff <= 60:
1029 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1030 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1031 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1032 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1033 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1034 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1035
1036 t.start()
1037 t1.start()
1038 t2.start()
1039 t3.start()
1040 t4.start()
1041 t5.start()
1042
1043 t.join()
1044 t1.join()
1045 t2.join()
1046 t3.join()
1047 t4.join()
1048 t5.join()
1049
1050 self.diff = round(time.time() - self.start_time, 0)
1051 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1052 self.transactions += (self.ip_count+self.failure_count)
1053 self.running_time += self.diff
1054 self.total_success += self.ip_count
1055 self.total_failure += self.failure_count
1056
1057 log_test.info("----------------------------------------------------------------------------------")
1058 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1059 log_test.info("----------------------------------------------------------------------------------")
1060 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1061 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1062 log_test.info("----------------------------------------------------------------------------------")
1063 log_test.info("No. of clients per second in run %d:%f "
1064 %(i, self.transaction_count))
1065 log_test.info("----------------------------------------------------------------------------------")
1066
1067 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1068 log_test.info("----------------------------------------------------------------------------------")
1069 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1070 log_test.info(" %d %d %d %d" %(self.transactions,
1071 self.total_success, self.total_failure, self.running_time))
1072 log_test.info("----------------------------------------------------------------------------------")
1073 log_test.info("Average no. of clients per second: %d ",
1074 round(self.transactions/self.running_time,0))
1075 log_test.info("----------------------------------------------------------------------------------")
1076
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001077 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001078 mac = self.get_mac(iface)
1079 self.host_load(iface)
1080 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1081 cip, sip, mac, _ = self.dhcp.only_discover()
1082 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1083 (cip, sip, mac) )
1084 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1085 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1086 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1087 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1088 (new_cip, new_sip, new_mac) )
1089 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1090 log_test.info("Now sending DHCP Request for old DHCP discover.")
1091 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1092 if new_cip is None:
1093 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1094 %(new_cip, new_sip, new_mac) )
1095 elif new_cip:
1096 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.'
1097 %(new_cip, new_sip, new_mac, new_cip) )
1098 assert_equal(new_cip, None)