blob: f294ccfb1d5d8d06079167c07be9274094bd5ddb [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
364 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
365 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000366 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
367 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
368 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000369 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000370
371 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
372 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000373 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
374 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
375 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000376 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000377
378 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
379 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000380 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
381 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
382 assert_equal(cip,None)
383 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
384
385 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
386 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700387 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000388 ip_map = {}
389 for i in range(requests):
390 #mac = RandMAC()._fix()
391 #log_test.info('mac is %s'%mac)
392 cip, sip = self.send_recv(update_seed = True)
393 if ip_map.has_key(cip):
394 log_test.info('IP %s given out multiple times' %cip)
395 assert_equal(False, ip_map.has_key(cip))
396 ip_map[cip] = sip
397 time.sleep(1)
398
399 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
400 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000401 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
402 cip, sip = self.send_recv(mac=mac)
403 log_test.info('Releasing ip %s to server %s' %(cip, sip))
404 assert_equal(self.dhcp.release(cip), True)
405 log_test.info('Triggering DHCP discover again after release')
406 cip2, sip2 = self.send_recv(mac=mac)
407 log_test.info('Verifying released IP was given back on rediscover')
408 assert_equal(cip, cip2)
409 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
410 assert_equal(self.dhcp.release(cip2), True)
411
412 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
413 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000414 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
415 ip_map = {}
416 for i in range(10):
417 cip, sip = self.send_recv(mac=mac, update_seed = True)
418 if ip_map.has_key(cip):
419 log_test.info('IP %s given out multiple times' %cip)
420 assert_equal(False, ip_map.has_key(cip))
421 ip_map[cip] = sip
422
423 for ip in ip_map.keys():
424 log_test.info('Releasing IP %s' %ip)
425 assert_equal(self.dhcp.release(ip), True)
426
427 ip_map2 = {}
428 log_test.info('Triggering DHCP discover again after release')
429 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
430 for i in range(len(ip_map.keys())):
431 cip, sip = self.send_recv(mac=mac, update_seed = True)
432 ip_map2[cip] = sip
433
434 log_test.info('Verifying released IPs were given back on rediscover')
435 if ip_map != ip_map2:
436 log_test.info('Map before release %s' %ip_map)
437 log_test.info('Map after release %s' %ip_map2)
438 assert_equal(ip_map, ip_map2)
439
440 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
441 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000442 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
443 log_test.info('Verifying 1 ')
444 count = 0
445 while True:
446 #mac = RandMAC()._fix()
447 cip, sip = self.send_recv(update_seed = True,validate = False)
448 if cip is None:
449 break
450 else:
451 count += 1
452 assert_equal(count,91)
453 log_test.info('Verifying 2 ')
454 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
455 assert_equal(cip, None)
456 assert_equal(sip, None)
457
458 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
459 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000460 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
461 cip, sip, mac, _ = self.dhcp.only_discover()
462 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
463 (cip, sip, mac) )
464 assert_not_equal(cip, None)
465 log_test.info('Triggering DHCP discover again.')
466 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
467 assert_equal(new_cip, cip)
468 log_test.info('got same ip to smae the client when sent discover again, as expected')
469
470 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
471 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000472 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
473 log_test.info('Sending DHCP discover and DHCP request.')
474 cip, sip = self.send_recv(mac=mac)
475 mac = self.dhcp.get_mac(cip)[0]
476 log_test.info("Sending DHCP request again.")
477 new_cip, new_sip = self.dhcp.only_request(cip, mac)
478 assert_equal(new_cip, cip)
479 log_test.info('got same ip to smae the client when sent request again, as expected')
480
481 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
482 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000483 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
484 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
485 assert_equal(cip,self.dhcp.seed_ip)
486 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
487 (cip, sip, mac) )
488
489 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
490 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000491 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
492 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
493 assert_not_equal(cip,None)
494 assert_not_equal(cip,self.dhcp.seed_ip)
495 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
496
497 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
498 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000499 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
500 cip, sip, mac, _ = self.dhcp.only_discover()
501 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
502 (cip, sip, mac) )
503 assert_not_equal(cip, None)
504 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
505 assert_equal(new_cip, None)
506 log_test.info('server sent NAK packet when requested other IP than that server offered')
507
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000508 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 +0000509 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000510 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
511 self.dhcp.return_option = 'lease'
512 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
513 assert_equal(lval, lease_time)
514 log_test.info('dhcp server offered IP address with client requested lease time')
515
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000516 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000517 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000518 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
519 cip, sip, mac, _ = self.dhcp.only_discover()
520 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
521 (cip, sip, mac) )
522 assert_not_equal(cip, None)
523 new_cip, new_sip = self.dhcp.only_request(cip, mac)
524 log_test.info('client rebooting...')
525 os.system('ifconfig '+iface+' down')
526 time.sleep(5)
527 os.system('ifconfig '+iface+' up')
528 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
529 assert_equal(new_cip2, cip)
530 log_test.info('client got same IP after reboot, as expected')
531
532
533 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
534 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000535 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
536 cip, sip, mac, _ = self.dhcp.only_discover()
537 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
538 (cip, sip, mac) )
539 assert_not_equal(cip, None)
540 new_cip, new_sip = self.dhcp.only_request(cip, mac)
541 log_test.info('server rebooting...')
542 self.tearDownClass()
543 new_cip, new_sip = self.dhcp.only_request(cip, mac)
544 assert_equal(new_cip,None)
545 self.setUpClass()
546 new_cip, new_sip = self.dhcp.only_request(cip, mac)
547 assert_equal(new_cip, cip)
548 log_test.info('client got same IP after server rebooted, as expected')
549
550 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
551 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000552 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
553 self.dhcp.return_option = 'lease'
554 log_test.info('Sending DHCP discover with lease time of 700')
555 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
556 assert_equal(lval,lease_time)
557 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
558 assert_equal(new_cip,cip)
559 assert_not_equal(lval, lease_time) #Negative Test Case
560 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
561
562 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
563 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000564 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
565 cip, sip, mac, _ = self.dhcp.only_discover()
566 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
567 assert_equal(new_cip,cip)
568 assert_equal(lval, lease_time)
569 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
570
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000571 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000572 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000573 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
574 cip, sip, mac, _ = self.dhcp.only_discover()
575 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
576 (cip, sip, mac) )
577 assert_not_equal(cip,None)
578 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
579 log_test.info('waiting for renew time..')
580 time.sleep(lval)
581 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
582 assert_equal(latest_cip, cip)
583 log_test.info('server renewed client IP when client sends request after renew time, as expected')
584
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000585 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000586 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000587 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
588 cip, sip, mac, _ = self.dhcp.only_discover()
589 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
590 (cip, sip, mac) )
591 assert_not_equal(cip,None)
592 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
593 log_test.info('waiting for rebind time..')
594 time.sleep(lval)
595 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
596 assert_equal(latest_cip, cip)
597 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
598
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000599 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000600 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000601 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
602 expected_subnet = '255.255.255.0'
603 self.dhcp.return_option = 'subnet'
604
605 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
606 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
607 (cip, sip, mac) )
608 assert_equal(subnet_mask,expected_subnet)
609 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
610
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000611 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000612 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000613 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
614
615 cip, sip, mac, _ = self.dhcp.only_discover()
616 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
617 (cip, sip, mac) )
618 assert_not_equal(cip,None)
619 self.dhcp.send_different_option = 'subnet'
620 new_cip, new_sip = self.dhcp.only_request(cip, mac)
621 assert_equal(new_cip, cip)
622 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
623
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000624 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000625 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000626 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
627 expected_router_address = '20.20.20.1'
628 self.dhcp.return_option = 'router'
629
630 cip, sip, mac, router_address_value = self.dhcp.only_discover()
631 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
632 (cip, sip, mac) )
633 assert_equal(expected_router_address, router_address_value)
634 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
635
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000636 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(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
640 cip, sip, mac, _ = self.dhcp.only_discover()
641 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
642 (cip, sip, mac) )
643 assert_not_equal(cip,None)
644 self.dhcp.send_different_option = 'router'
645 new_cip, new_sip = self.dhcp.only_request(cip, mac)
646 assert_equal(new_cip, cip)
647 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
648
649 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
650 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000651 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
652 expected_broadcast_address = '192.168.1.255'
653 self.dhcp.return_option = 'broadcast_address'
654
655 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
656 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
657 (cip, sip, mac) )
658 assert_equal(expected_broadcast_address, broadcast_address_value)
659 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
660
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000661 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000662 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000663 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
664
665 cip, sip, mac, _ = self.dhcp.only_discover()
666 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
667 (cip, sip, mac) )
668 assert_not_equal(cip,None)
669 self.dhcp.send_different_option = 'broadcast_address'
670 new_cip, new_sip = self.dhcp.only_request(cip, mac)
671 assert_equal(new_cip, cip)
672 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
673
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000674 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000675 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000676 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
677 expected_dns_address = '192.168.1.1'
678 self.dhcp.return_option = 'dns'
679
680 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
681 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
682 (cip, sip, mac) )
683 assert_equal(expected_dns_address, dns_address_value)
684 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
685
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000686 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000687 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000688 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
689
690 cip, sip, mac, _ = self.dhcp.only_discover()
691 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
692 (cip, sip, mac) )
693 assert_not_equal(cip,None)
694 self.dhcp.send_different_option = 'dns'
695 new_cip, new_sip = self.dhcp.only_request(cip, mac)
696 assert_equal(new_cip, cip)
697 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
698
699
700 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
701
702 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000703 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000704 log_test.info("Statistics for run %d",i)
705 log_test.info("----------------------------------------------------------------------------------")
706 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
707 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
708 log_test.info("----------------------------------------------------------------------------------")
709 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
710
711 log_test.info("Final Statistics for total transactions")
712 log_test.info("----------------------------------------------------------------------------------")
713 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
714 log_test.info(" %d %d %d %d" %(self.transactions,
715 self.total_success, self.total_failure, self.running_time))
716 log_test.info("----------------------------------------------------------------------------------")
717 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
718
719 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
720
721 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000722 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000723 log_test.info("Statistics for run %d",i)
724 log_test.info("----------------------------------------------------------------------------------")
725 log_test.info("No. of consecutive successful transactions Running Time ")
726 log_test.info(" %d %d " %(self.ip_count, self.diff))
727 log_test.info("----------------------------------------------------------------------------------")
728 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
729 log_test.info("----------------------------------------------------------------------------------")
730
731 log_test.info("Final Statistics for total successful transactions")
732 log_test.info("----------------------------------------------------------------------------------")
733 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
734 log_test.info(" %d %d %d " %(self.transactions,
735 self.total_success, self.running_time))
736 log_test.info("----------------------------------------------------------------------------------")
737 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
738 log_test.info("----------------------------------------------------------------------------------")
739
740 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
741
742 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000743 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000744 log_test.info("----------------------------------------------------------------------------------")
745 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
746 log_test.info("----------------------------------------------------------------------------------")
747 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
748 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
749 log_test.info("----------------------------------------------------------------------------------")
750 log_test.info("No. of clients per second in run %d:%f "
751 %(i, self.transaction_count))
752 log_test.info("----------------------------------------------------------------------------------")
753 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
754 log_test.info("----------------------------------------------------------------------------------")
755 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
756 log_test.info(" %d %d %d %d" %(self.transactions,
757 self.total_success, self.total_failure, self.running_time))
758 log_test.info("----------------------------------------------------------------------------------")
759 log_test.info("Average no. of clients per second: %d ",
760 round(self.transactions/self.running_time,0))
761 log_test.info("----------------------------------------------------------------------------------")
762
763 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
764
765 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000766 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000767 log_test.info("----------------------------------------------------------------------------------")
768 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
769 log_test.info("----------------------------------------------------------------------------------")
770 log_test.info("No. of consecutive successful transactions Running Time ")
771 log_test.info(" %d %d " %(self.ip_count, self.diff))
772 log_test.info("----------------------------------------------------------------------------------")
773 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
774 log_test.info("----------------------------------------------------------------------------------")
775
776 log_test.info("Final Statistics for total successful transactions")
777 log_test.info("----------------------------------------------------------------------------------")
778 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
779 log_test.info(" %d %d %d " %(self.transactions,
780 self.total_success, self.running_time))
781 log_test.info("----------------------------------------------------------------------------------")
782 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
783 log_test.info("----------------------------------------------------------------------------------")
784
785 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000786 for key in (key for key in g_subscriber_port_map if key < 100):
787 self.host_load(g_subscriber_port_map[key])
788
789 def thread_fun(i):
790 mac = self.get_mac('veth{}'.format(i))
791 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
792 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
793 self.lock.acquire()
794
795 if cip:
796 self.ip_count += 1
797
798 elif cip is None:
799 self.failure_count += 1
800
801 self.lock.notify_all()
802 self.lock.release()
803
804 for i in range (1,4):
805 self.ip_count = 0
806 self.failure_count = 0
807 self.start_time = 0
808 self.diff = 0
809 self.transaction_count = 0
810 self.start_time = time.time()
811
812 while self.diff <= 60:
813 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
814 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
815 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
816 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
817 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
818 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
819
820 t.start()
821 t1.start()
822 t2.start()
823 t3.start()
824 t4.start()
825 t5.start()
826
827 t.join()
828 t1.join()
829 t2.join()
830 t3.join()
831 t4.join()
832 t5.join()
833
834 self.diff = round(time.time() - self.start_time, 0)
835
836 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
837
838 self.transactions += (self.ip_count+self.failure_count)
839 self.running_time += self.diff
840 self.total_success += self.ip_count
841 self.total_failure += self.failure_count
842
843
844 log_test.info("----------------------------------------------------------------------------------")
845 log_test.info("Statistics for run %d",i)
846 log_test.info("----------------------------------------------------------------------------------")
847 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
848 log_test.info(" %d %d %d %d"
849 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
850 log_test.info("----------------------------------------------------------------------------------")
851 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
852 log_test.info("----------------------------------------------------------------------------------")
853
854 log_test.info("----------------------------------------------------------------------------------")
855 log_test.info("Final Statistics for total transactions")
856 log_test.info("----------------------------------------------------------------------------------")
857 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
858 log_test.info(" %d %d %d %d" %(self.transactions,
859 self.total_success, self.total_failure, self.running_time))
860
861 log_test.info("----------------------------------------------------------------------------------")
862 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
863 log_test.info("----------------------------------------------------------------------------------")
864
865 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000866 failure_dir = {}
867
868 for key in (key for key in g_subscriber_port_map if key != 100):
869 self.host_load(g_subscriber_port_map[key])
870
871 def thread_fun(i, j):
872# log_test.info("Thread Name:%s",current_thread().name)
873# failure_dir[current_thread().name] = True
874 while failure_dir.has_key(current_thread().name) is False:
875 mac = RandMAC()._fix()
876 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
877 i += 2
878 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
879 self.lock.acquire()
880
881 if cip:
882 self.ip_count += 1
883 self.lock.notify_all()
884 self.lock.release()
885 elif cip is None:
886 self.failure_count += 1
887 failure_dir[current_thread().name] = True
888 self.lock.notify_all()
889 self.lock.release()
890 break
891# self.lock.notify_all()
892# self.lock.release()
893
894 for i in range (1,4):
895 failure_dir = {}
896 self.ip_count = 0
897 self.failure_count = 0
898 self.start_time = 0
899 self.diff = 0
900 self.transaction_count = 0
901 self.start_time = time.time()
902
903 while len(failure_dir) != 6:
904 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
905 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
906 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
907 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
908 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
909 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
910
911 t.start()
912 t1.start()
913 t2.start()
914 t3.start()
915 t4.start()
916 t5.start()
917
918 t.join()
919 t1.join()
920 t2.join()
921 t3.join()
922 t4.join()
923 t5.join()
924
925 self.diff = round(time.time() - self.start_time, 0)
926 self.transaction_count = round((self.ip_count)/self.diff, 2)
927
928 self.transactions += (self.ip_count+self.failure_count)
929 self.running_time += self.diff
930 self.total_success += self.ip_count
931 self.total_failure += self.failure_count
932
933
934 log_test.info("Statistics for run %d",i)
935 log_test.info("----------------------------------------------------------------------------------")
936 log_test.info("No. of consecutive successful transactions Running Time ")
937 log_test.info(" %d %d " %(self.ip_count, self.diff))
938 log_test.info("----------------------------------------------------------------------------------")
939 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
940 log_test.info("----------------------------------------------------------------------------------")
941
942 log_test.info("Final Statistics for total successful transactions")
943 log_test.info("----------------------------------------------------------------------------------")
944 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
945 log_test.info(" %d %d %d " %(self.transactions,
946 self.total_success, self.running_time))
947 log_test.info("----------------------------------------------------------------------------------")
948 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
949 log_test.info("----------------------------------------------------------------------------------")
950
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000951 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000952 for key in (key for key in g_subscriber_port_map if key < 100):
953 self.host_load(g_subscriber_port_map[key])
954
955 def thread_fun(i):
956# mac = self.get_mac('veth{}'.format(i))
957 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
958 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
959 self.lock.acquire()
960
961 if cip:
962 self.ip_count += 1
963 elif cip is None:
964 self.failure_count += 1
965
966 self.lock.notify_all()
967 self.lock.release()
968
969 for i in range (1,4):
970 self.ip_count = 0
971 self.failure_count = 0
972 self.start_time = 0
973 self.diff = 0
974 self.transaction_count = 0
975 self.start_time = time.time()
976
977 while self.diff <= 60:
978 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
979 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
980 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
981 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
982 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
983 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
984
985 t.start()
986 t1.start()
987 t2.start()
988 t3.start()
989 t4.start()
990 t5.start()
991
992 t.join()
993 t1.join()
994 t2.join()
995 t3.join()
996 t4.join()
997 t5.join()
998
999 self.diff = round(time.time() - self.start_time, 0)
1000 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1001 self.transactions += (self.ip_count+self.failure_count)
1002 self.running_time += self.diff
1003 self.total_success += self.ip_count
1004 self.total_failure += self.failure_count
1005
1006 log_test.info("----------------------------------------------------------------------------------")
1007 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1008 log_test.info("----------------------------------------------------------------------------------")
1009 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1010 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1011 log_test.info("----------------------------------------------------------------------------------")
1012 log_test.info("No. of clients per second in run %d:%f "
1013 %(i, self.transaction_count))
1014 log_test.info("----------------------------------------------------------------------------------")
1015
1016 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1017 log_test.info("----------------------------------------------------------------------------------")
1018 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1019 log_test.info(" %d %d %d %d" %(self.transactions,
1020 self.total_success, self.total_failure, self.running_time))
1021 log_test.info("----------------------------------------------------------------------------------")
1022 log_test.info("Average no. of clients per second: %d ",
1023 round(self.transactions/self.running_time,0))
1024 log_test.info("----------------------------------------------------------------------------------")
1025
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001026 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001027 mac = self.get_mac(iface)
1028 self.host_load(iface)
1029 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1030 cip, sip, mac, _ = self.dhcp.only_discover()
1031 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1032 (cip, sip, mac) )
1033 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1034 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1035 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1036 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1037 (new_cip, new_sip, new_mac) )
1038 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1039 log_test.info("Now sending DHCP Request for old DHCP discover.")
1040 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1041 if new_cip is None:
1042 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1043 %(new_cip, new_sip, new_mac) )
1044 elif new_cip:
1045 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.'
1046 %(new_cip, new_sip, new_mac, new_cip) )
1047 assert_equal(new_cip, None)