blob: e6a77455ab919e493728d30413661d6f6a4be9b3 [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
A R Karthicke7232092017-09-07 18:01:33 -070047from VolthaCtrl import VolthaCtrl
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000048import threading, random
49from threading import current_thread
50log_test.setLevel('INFO')
51
52class dhcpl2relay_exchange(CordLogger):
53
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070054 VOLTHA_HOST = None
A R Karthicke7232092017-09-07 18:01:33 -070055 VOLTHA_REST_PORT = VolthaCtrl.REST_PORT
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070056 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
57 VOLTHA_OLT_TYPE = 'simulated_olt'
58 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
59 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
60
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000061 app = 'org.opencord.dhcpl2relay'
62 sadis_app = 'org.opencord.sadis'
63 app_dhcp = 'org.onosproject.dhcp'
64 relay_interfaces_last = ()
65 interface_to_mac_map = {}
66 host_ip_map = {}
67 test_path = os.path.dirname(os.path.realpath(__file__))
68 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070069 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
70 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
71 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 +000072 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
73 default_options = [ ('subnet-mask', '255.255.255.0'),
74 ('broadcast-address', '192.168.1.255'),
75 ('domain-name-servers', '192.168.1.1'),
76 ('domain-name', '"mydomain.cord-tester"'),
77 ]
78 default_subnet_config = [ ('192.168.1.2',
79'''
80subnet 192.168.1.0 netmask 255.255.255.0 {
81 range 192.168.1.10 192.168.1.100;
82}
83'''), ]
84
85 lock = threading.Condition()
86 ip_count = 0
87 failure_count = 0
88 start_time = 0
89 diff = 0
90
91 transaction_count = 0
92 transactions = 0
93 running_time = 0
94 total_success = 0
95 total_failure = 0
96 #just in case we want to reset ONOS to default network cfg after relay tests
97 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
98 configs = {}
99
100 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700101 def update_apps_version(cls):
102 version = Onos.getVersion()
103 major = int(version.split('.')[0])
104 minor = int(version.split('.')[1])
105 dhcpl2_app_version = '1.0.0'
106 sadis_app_version = '1.0.0-SNAPSHOT'
107# sadis-app-1.0.0-SNAPSHOT.oar
108# if major > 1:
109# cordigmp_app_version = '3.0-SNAPSHOT'
110# olt_app_version = '2.0-SNAPSHOT'
111# elif major == 1:
112# if minor > 10:
113# cordigmp_app_version = '3.0-SNAPSHOT'
114# olt_app_version = '2.0-SNAPSHOT'
115# elif minor <= 8:
116# olt_app_version = '1.1-SNAPSHOT'
117 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
118 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
119
120
121 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000122 def setUpClass(cls):
123 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700124 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000125 OnosCtrl(cls.app_dhcp).deactivate()
126 time.sleep(3)
127 cls.onos_ctrl = OnosCtrl(cls.app)
128 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700129 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000130 time.sleep(3)
131 cls.onos_ctrl = OnosCtrl(cls.sadis_app)
132 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700133 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000134 time.sleep(3)
135 cls.dhcp_l2_relay_setup()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700136 cls.cord_sadis_load()
137 cls.cord_l2_relay_load()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000138 ##start dhcpd initially with default config
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700139 #cls.dhcpd_start()
140
141 def setUp(self):
142 super(dhcpl2relay_exchange, self).setUp()
143
144 def tearDown(self):
145 super(dhcpl2relay_exchange, self).tearDown()
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700146 OnosCtrl.uninstall_app(self.dhcpl2_app_file)
147 OnosCtrl.uninstall_app(self.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000148
149 @classmethod
150 def tearDownClass(cls):
151 '''Deactivate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700152 #try:
153 # os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
154 # os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
155 #except: pass
156 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
157 OnosCtrl.uninstall_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000158 cls.onos_ctrl.deactivate()
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700159 OnosCtrl(cls.app).deactivate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700160 #cls.dhcpd_stop()
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700161 #cls.dhcp_l2_relay_cleanup()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000162
163 @classmethod
164 def dhcp_l2_relay_setup(cls):
165 did = OnosCtrl.get_device_id()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700166 #cls.relay_device_id = did
167 ### Have to change hard coded value in relay device variable on later merges
168 cls.relay_device_id = 'of:000012b722fd4948'
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000169 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
170 cls.port_map, _ = cls.olt.olt_port_map()
171 if cls.port_map:
172 ##Per subscriber, we use 1 relay port
173 try:
174 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
175 except:
176 relay_port = cls.port_map['uplink']
177 cls.relay_interface_port = relay_port
178 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
179 else:
180 cls.relay_interface_port = 100
181 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
182 cls.relay_interfaces_last = cls.relay_interfaces
183 if cls.port_map:
184 ##generate a ip/mac client virtual interface config for onos
185 interface_list = []
186 for port in cls.port_map['ports']:
187 port_num = cls.port_map[port]
188 if port_num == cls.port_map['uplink']:
189 continue
190 ip = cls.get_host_ip(port_num)
191 mac = cls.get_mac(port)
192 interface_list.append((port_num, ip, mac))
193
194 #configure dhcp server virtual interface on the same subnet as first client interface
195 relay_ip = cls.get_host_ip(interface_list[0][0])
196 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
197 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700198 #cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000199
200 @classmethod
201 def dhcp_l2_relay_cleanup(cls):
202 ##reset the ONOS port configuration back to default
203 for config in cls.configs.items():
204 OnosCtrl.delete(config)
205 # if cls.onos_restartable is True:
206 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
207 # return cord_test_onos_restart(config = {})
208
209 @classmethod
210 def onos_load_config(cls, config):
211 status, code = OnosCtrl.config(config)
212 if status is False:
213 log_test.info('JSON request returned status %d' %code)
214 assert_equal(status, True)
215 time.sleep(3)
216
217 @classmethod
218 def onos_interface_load(cls, interface_list):
219 interface_dict = { 'ports': {} }
220 for port_num, ip, mac in interface_list:
221 port_map = interface_dict['ports']
222 port = '{}/{}'.format(cls.relay_device_id, port_num)
223 port_map[port] = { 'interfaces': [] }
224 interface_list = port_map[port]['interfaces']
225 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
226 'mac' : mac,
227 'name': 'vir-{}'.format(port_num)
228 }
229 interface_list.append(interface_map)
230
231 cls.onos_load_config(interface_dict)
232 cls.configs['interface_config'] = interface_dict
233
234 @classmethod
235 def cord_l2_relay_load(cls):
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700236 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
237 #relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700238 relay_device_map = "{}/12".format(cls.relay_device_id)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700239 print relay_device_map
240 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
241 {"dhcpserverConnectPoint":[relay_device_map]}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000242 }
243 }
244 }
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700245 print "---------------------------------------------"
246 print dhcp_dict
247 print "---------------------------------------------"
248 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
249 OnosCtrl.install_app(cls.dhcpl2_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000250 cls.onos_load_config(dhcp_dict)
251 cls.configs['relay_config'] = dhcp_dict
252
253 @classmethod
254 def cord_sadis_load(cls):
255 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700256 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000257 "org.opencord.sadis": {
258 "sadis": {
259 "integration": {
260 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700261 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000262 "maxsize": 50,
263 "ttl": "PT1m"
264 }
265 },
266 "entries": [{
267 "id": "uni-254",
268 "cTag": 202,
269 "sTag": 222,
270 "nasPortId": "uni-254"
271 },
272 {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700273 "id": "67cc7ae085204e3091493db645e8ae63",
274 "hardwareIdentifier": "00:0c:e2:31:05:00",
275 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000276 "nasId": "B100-NASID"
277 }
278 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700279 }
280 }
281 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000282 }
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700283 OnosCtrl.uninstall_app(cls.sadis_app_file)
284 OnosCtrl.install_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000285 cls.onos_load_config(sadis_dict)
286 cls.configs['relay_config'] = sadis_dict
287
288 @classmethod
289 def get_host_ip(cls, port):
290 if cls.host_ip_map.has_key(port):
291 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700292 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000293 return cls.host_ip_map[port]
294
295 @classmethod
296 def host_load(cls, iface):
297 '''Have ONOS discover the hosts for dhcp-relay responses'''
298 port = g_subscriber_port_map[iface]
299 host = '173.17.1.{}'.format(port)
300 cmds = ( 'ifconfig {} 0'.format(iface),
301 'ifconfig {0} {1}'.format(iface, host),
302 'arping -I {0} {1} -c 2'.format(iface, host),
303 'ifconfig {} 0'.format(iface), )
304 for c in cmds:
305 os.system(c)
306
307 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000308 def get_mac(cls, iface):
309 if cls.interface_to_mac_map.has_key(iface):
310 return cls.interface_to_mac_map[iface]
311 mac = get_mac(iface, pad = 0)
312 cls.interface_to_mac_map[iface] = mac
313 return mac
314
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000315 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000316
317 self.ip_count = 0
318 self.failure_count = 0
319 self.start_time = 0
320 self.diff = 0
321 self.transaction_count = 0
322
323 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000324 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
325 self.start_time = time.time()
326
327 while self.diff <= 60:
328
329 if only_discover:
330 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
331 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
332 (cip, sip, mac))
333 else:
334 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
335
336 if cip:
337 self.ip_count +=1
338 elif cip == None:
339 self.failure_count += 1
340 log_test.info('Failed to get ip')
341 if success_rate and self.ip_count > 0:
342 break
343
344 self.diff = round(time.time() - self.start_time, 0)
345
346 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
347 self.transactions += (self.ip_count+self.failure_count)
348 self.running_time += self.diff
349 self.total_success += self.ip_count
350 self.total_failure += self.failure_count
351
352 def send_recv(self, mac=None, update_seed = False, validate = True):
353 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
354 if validate:
355 assert_not_equal(cip, None)
356 assert_not_equal(sip, None)
357 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
358 (cip, sip, self.dhcp.get_mac(cip)[0]))
359 return cip,sip
360
361 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
362 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000363 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
364 self.send_recv(mac=mac)
365
Chetan Gaonker891302d2017-09-05 15:09:26 +0000366 def test_dhcpl2relay_app_install(self):
367 pass
368
369 def test_dhcpl2relay_netcfg(self):
370 pass
371
372 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self):
373 pass
374
375 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self):
376 pass
377
378 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self):
379 pass
380
381 def test_dhcpl2relay_without_sadis_app(self):
382 pass
383
384 def test_dhcpl2relay_with_sadis_app(self):
385 pass
386
387 def test_dhcpl2relay_with_option_82(self):
388 pass
389
390 def test_dhcpl2relay_without_option_82(self):
391 pass
392
393 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self):
394 pass
395
396 def test_dhcpl2relay_with_uni_port_entry_sadis_config(self):
397 pass
398
399 def test_dhcpl2relay_with_wrong_ctag_options(self):
400 pass
401
402 def test_dhcpl2relay_with_wrong_stag_options(self):
403 pass
404
405 def test_dhcpl2relay_with_nasportid_option_in_sadis(self):
406 pass
407
408 def test_dhcpl2relay_with_nasportid_different_from_id(self):
409 pass
410
411 def test_dhcpl2relay_with_serial_id_of_olt(self):
412 pass
413
414 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self):
415 pass
416
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000417 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
418 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000419 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
420 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
421 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000422 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000423
424 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
425 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000426 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
427 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
428 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000429 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000430
431 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
432 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000433 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
434 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
435 assert_equal(cip,None)
436 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
437
438 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
439 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700440 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000441 ip_map = {}
442 for i in range(requests):
443 #mac = RandMAC()._fix()
444 #log_test.info('mac is %s'%mac)
445 cip, sip = self.send_recv(update_seed = True)
446 if ip_map.has_key(cip):
447 log_test.info('IP %s given out multiple times' %cip)
448 assert_equal(False, ip_map.has_key(cip))
449 ip_map[cip] = sip
450 time.sleep(1)
451
452 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
453 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000454 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
455 cip, sip = self.send_recv(mac=mac)
456 log_test.info('Releasing ip %s to server %s' %(cip, sip))
457 assert_equal(self.dhcp.release(cip), True)
458 log_test.info('Triggering DHCP discover again after release')
459 cip2, sip2 = self.send_recv(mac=mac)
460 log_test.info('Verifying released IP was given back on rediscover')
461 assert_equal(cip, cip2)
462 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
463 assert_equal(self.dhcp.release(cip2), True)
464
465 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
466 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000467 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
468 ip_map = {}
469 for i in range(10):
470 cip, sip = self.send_recv(mac=mac, update_seed = True)
471 if ip_map.has_key(cip):
472 log_test.info('IP %s given out multiple times' %cip)
473 assert_equal(False, ip_map.has_key(cip))
474 ip_map[cip] = sip
475
476 for ip in ip_map.keys():
477 log_test.info('Releasing IP %s' %ip)
478 assert_equal(self.dhcp.release(ip), True)
479
480 ip_map2 = {}
481 log_test.info('Triggering DHCP discover again after release')
482 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
483 for i in range(len(ip_map.keys())):
484 cip, sip = self.send_recv(mac=mac, update_seed = True)
485 ip_map2[cip] = sip
486
487 log_test.info('Verifying released IPs were given back on rediscover')
488 if ip_map != ip_map2:
489 log_test.info('Map before release %s' %ip_map)
490 log_test.info('Map after release %s' %ip_map2)
491 assert_equal(ip_map, ip_map2)
492
493 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
494 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000495 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
496 log_test.info('Verifying 1 ')
497 count = 0
498 while True:
499 #mac = RandMAC()._fix()
500 cip, sip = self.send_recv(update_seed = True,validate = False)
501 if cip is None:
502 break
503 else:
504 count += 1
505 assert_equal(count,91)
506 log_test.info('Verifying 2 ')
507 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
508 assert_equal(cip, None)
509 assert_equal(sip, None)
510
511 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
512 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000513 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
514 cip, sip, mac, _ = self.dhcp.only_discover()
515 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
516 (cip, sip, mac) )
517 assert_not_equal(cip, None)
518 log_test.info('Triggering DHCP discover again.')
519 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
520 assert_equal(new_cip, cip)
521 log_test.info('got same ip to smae the client when sent discover again, as expected')
522
523 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
524 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000525 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
526 log_test.info('Sending DHCP discover and DHCP request.')
527 cip, sip = self.send_recv(mac=mac)
528 mac = self.dhcp.get_mac(cip)[0]
529 log_test.info("Sending DHCP request again.")
530 new_cip, new_sip = self.dhcp.only_request(cip, mac)
531 assert_equal(new_cip, cip)
532 log_test.info('got same ip to smae the client when sent request again, as expected')
533
534 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
535 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000536 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
537 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
538 assert_equal(cip,self.dhcp.seed_ip)
539 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
540 (cip, sip, mac) )
541
542 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
543 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000544 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
545 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
546 assert_not_equal(cip,None)
547 assert_not_equal(cip,self.dhcp.seed_ip)
548 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
549
550 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
551 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000552 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
553 cip, sip, mac, _ = self.dhcp.only_discover()
554 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
555 (cip, sip, mac) )
556 assert_not_equal(cip, None)
557 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
558 assert_equal(new_cip, None)
559 log_test.info('server sent NAK packet when requested other IP than that server offered')
560
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000561 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 +0000562 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000563 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
564 self.dhcp.return_option = 'lease'
565 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
566 assert_equal(lval, lease_time)
567 log_test.info('dhcp server offered IP address with client requested lease time')
568
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000569 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000570 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000571 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
572 cip, sip, mac, _ = self.dhcp.only_discover()
573 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
574 (cip, sip, mac) )
575 assert_not_equal(cip, None)
576 new_cip, new_sip = self.dhcp.only_request(cip, mac)
577 log_test.info('client rebooting...')
578 os.system('ifconfig '+iface+' down')
579 time.sleep(5)
580 os.system('ifconfig '+iface+' up')
581 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
582 assert_equal(new_cip2, cip)
583 log_test.info('client got same IP after reboot, as expected')
584
585
586 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
587 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000588 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
589 cip, sip, mac, _ = self.dhcp.only_discover()
590 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
591 (cip, sip, mac) )
592 assert_not_equal(cip, None)
593 new_cip, new_sip = self.dhcp.only_request(cip, mac)
594 log_test.info('server rebooting...')
595 self.tearDownClass()
596 new_cip, new_sip = self.dhcp.only_request(cip, mac)
597 assert_equal(new_cip,None)
598 self.setUpClass()
599 new_cip, new_sip = self.dhcp.only_request(cip, mac)
600 assert_equal(new_cip, cip)
601 log_test.info('client got same IP after server rebooted, as expected')
602
603 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
604 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000605 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
606 self.dhcp.return_option = 'lease'
607 log_test.info('Sending DHCP discover with lease time of 700')
608 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
609 assert_equal(lval,lease_time)
610 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
611 assert_equal(new_cip,cip)
612 assert_not_equal(lval, lease_time) #Negative Test Case
613 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
614
615 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
616 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000617 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
618 cip, sip, mac, _ = self.dhcp.only_discover()
619 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
620 assert_equal(new_cip,cip)
621 assert_equal(lval, lease_time)
622 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
623
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000624 def test_dhcpl2relay_with_client_renew_time(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 cip, sip, mac, _ = self.dhcp.only_discover()
628 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
629 (cip, sip, mac) )
630 assert_not_equal(cip,None)
631 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
632 log_test.info('waiting for renew time..')
633 time.sleep(lval)
634 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
635 assert_equal(latest_cip, cip)
636 log_test.info('server renewed client IP when client sends request after renew time, as expected')
637
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000638 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000639 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000640 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
641 cip, sip, mac, _ = self.dhcp.only_discover()
642 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
643 (cip, sip, mac) )
644 assert_not_equal(cip,None)
645 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
646 log_test.info('waiting for rebind time..')
647 time.sleep(lval)
648 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
649 assert_equal(latest_cip, cip)
650 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
651
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000652 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000653 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000654 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
655 expected_subnet = '255.255.255.0'
656 self.dhcp.return_option = 'subnet'
657
658 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
659 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
660 (cip, sip, mac) )
661 assert_equal(subnet_mask,expected_subnet)
662 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
663
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000664 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000665 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000666 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
667
668 cip, sip, mac, _ = self.dhcp.only_discover()
669 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
670 (cip, sip, mac) )
671 assert_not_equal(cip,None)
672 self.dhcp.send_different_option = 'subnet'
673 new_cip, new_sip = self.dhcp.only_request(cip, mac)
674 assert_equal(new_cip, cip)
675 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
676
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000677 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000678 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000679 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
680 expected_router_address = '20.20.20.1'
681 self.dhcp.return_option = 'router'
682
683 cip, sip, mac, router_address_value = self.dhcp.only_discover()
684 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
685 (cip, sip, mac) )
686 assert_equal(expected_router_address, router_address_value)
687 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
688
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000689 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000690 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000691 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
692
693 cip, sip, mac, _ = self.dhcp.only_discover()
694 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
695 (cip, sip, mac) )
696 assert_not_equal(cip,None)
697 self.dhcp.send_different_option = 'router'
698 new_cip, new_sip = self.dhcp.only_request(cip, mac)
699 assert_equal(new_cip, cip)
700 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
701
702 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
703 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000704 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
705 expected_broadcast_address = '192.168.1.255'
706 self.dhcp.return_option = 'broadcast_address'
707
708 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
709 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
710 (cip, sip, mac) )
711 assert_equal(expected_broadcast_address, broadcast_address_value)
712 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
713
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000714 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000715 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000716 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
717
718 cip, sip, mac, _ = self.dhcp.only_discover()
719 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
720 (cip, sip, mac) )
721 assert_not_equal(cip,None)
722 self.dhcp.send_different_option = 'broadcast_address'
723 new_cip, new_sip = self.dhcp.only_request(cip, mac)
724 assert_equal(new_cip, cip)
725 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
726
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000727 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000728 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000729 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
730 expected_dns_address = '192.168.1.1'
731 self.dhcp.return_option = 'dns'
732
733 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
734 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
735 (cip, sip, mac) )
736 assert_equal(expected_dns_address, dns_address_value)
737 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
738
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000739 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000740 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000741 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
742
743 cip, sip, mac, _ = self.dhcp.only_discover()
744 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
745 (cip, sip, mac) )
746 assert_not_equal(cip,None)
747 self.dhcp.send_different_option = 'dns'
748 new_cip, new_sip = self.dhcp.only_request(cip, mac)
749 assert_equal(new_cip, cip)
750 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
751
752
753 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
754
755 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000756 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000757 log_test.info("Statistics for run %d",i)
758 log_test.info("----------------------------------------------------------------------------------")
759 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
760 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
761 log_test.info("----------------------------------------------------------------------------------")
762 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
763
764 log_test.info("Final Statistics for total transactions")
765 log_test.info("----------------------------------------------------------------------------------")
766 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
767 log_test.info(" %d %d %d %d" %(self.transactions,
768 self.total_success, self.total_failure, self.running_time))
769 log_test.info("----------------------------------------------------------------------------------")
770 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
771
772 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
773
774 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000775 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000776 log_test.info("Statistics for run %d",i)
777 log_test.info("----------------------------------------------------------------------------------")
778 log_test.info("No. of consecutive successful transactions Running Time ")
779 log_test.info(" %d %d " %(self.ip_count, self.diff))
780 log_test.info("----------------------------------------------------------------------------------")
781 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
782 log_test.info("----------------------------------------------------------------------------------")
783
784 log_test.info("Final Statistics for total successful transactions")
785 log_test.info("----------------------------------------------------------------------------------")
786 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
787 log_test.info(" %d %d %d " %(self.transactions,
788 self.total_success, self.running_time))
789 log_test.info("----------------------------------------------------------------------------------")
790 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
791 log_test.info("----------------------------------------------------------------------------------")
792
793 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
794
795 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000796 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000797 log_test.info("----------------------------------------------------------------------------------")
798 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
799 log_test.info("----------------------------------------------------------------------------------")
800 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
801 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
802 log_test.info("----------------------------------------------------------------------------------")
803 log_test.info("No. of clients per second in run %d:%f "
804 %(i, self.transaction_count))
805 log_test.info("----------------------------------------------------------------------------------")
806 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
807 log_test.info("----------------------------------------------------------------------------------")
808 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
809 log_test.info(" %d %d %d %d" %(self.transactions,
810 self.total_success, self.total_failure, self.running_time))
811 log_test.info("----------------------------------------------------------------------------------")
812 log_test.info("Average no. of clients per second: %d ",
813 round(self.transactions/self.running_time,0))
814 log_test.info("----------------------------------------------------------------------------------")
815
816 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
817
818 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000819 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000820 log_test.info("----------------------------------------------------------------------------------")
821 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
822 log_test.info("----------------------------------------------------------------------------------")
823 log_test.info("No. of consecutive successful transactions Running Time ")
824 log_test.info(" %d %d " %(self.ip_count, self.diff))
825 log_test.info("----------------------------------------------------------------------------------")
826 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
827 log_test.info("----------------------------------------------------------------------------------")
828
829 log_test.info("Final Statistics for total successful transactions")
830 log_test.info("----------------------------------------------------------------------------------")
831 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
832 log_test.info(" %d %d %d " %(self.transactions,
833 self.total_success, self.running_time))
834 log_test.info("----------------------------------------------------------------------------------")
835 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
836 log_test.info("----------------------------------------------------------------------------------")
837
838 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000839 for key in (key for key in g_subscriber_port_map if key < 100):
840 self.host_load(g_subscriber_port_map[key])
841
842 def thread_fun(i):
843 mac = self.get_mac('veth{}'.format(i))
844 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
845 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
846 self.lock.acquire()
847
848 if cip:
849 self.ip_count += 1
850
851 elif cip is None:
852 self.failure_count += 1
853
854 self.lock.notify_all()
855 self.lock.release()
856
857 for i in range (1,4):
858 self.ip_count = 0
859 self.failure_count = 0
860 self.start_time = 0
861 self.diff = 0
862 self.transaction_count = 0
863 self.start_time = time.time()
864
865 while self.diff <= 60:
866 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
867 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
868 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
869 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
870 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
871 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
872
873 t.start()
874 t1.start()
875 t2.start()
876 t3.start()
877 t4.start()
878 t5.start()
879
880 t.join()
881 t1.join()
882 t2.join()
883 t3.join()
884 t4.join()
885 t5.join()
886
887 self.diff = round(time.time() - self.start_time, 0)
888
889 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
890
891 self.transactions += (self.ip_count+self.failure_count)
892 self.running_time += self.diff
893 self.total_success += self.ip_count
894 self.total_failure += self.failure_count
895
896
897 log_test.info("----------------------------------------------------------------------------------")
898 log_test.info("Statistics for run %d",i)
899 log_test.info("----------------------------------------------------------------------------------")
900 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
901 log_test.info(" %d %d %d %d"
902 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
903 log_test.info("----------------------------------------------------------------------------------")
904 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
905 log_test.info("----------------------------------------------------------------------------------")
906
907 log_test.info("----------------------------------------------------------------------------------")
908 log_test.info("Final Statistics for total transactions")
909 log_test.info("----------------------------------------------------------------------------------")
910 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
911 log_test.info(" %d %d %d %d" %(self.transactions,
912 self.total_success, self.total_failure, self.running_time))
913
914 log_test.info("----------------------------------------------------------------------------------")
915 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
916 log_test.info("----------------------------------------------------------------------------------")
917
918 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000919 failure_dir = {}
920
921 for key in (key for key in g_subscriber_port_map if key != 100):
922 self.host_load(g_subscriber_port_map[key])
923
924 def thread_fun(i, j):
925# log_test.info("Thread Name:%s",current_thread().name)
926# failure_dir[current_thread().name] = True
927 while failure_dir.has_key(current_thread().name) is False:
928 mac = RandMAC()._fix()
929 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
930 i += 2
931 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
932 self.lock.acquire()
933
934 if cip:
935 self.ip_count += 1
936 self.lock.notify_all()
937 self.lock.release()
938 elif cip is None:
939 self.failure_count += 1
940 failure_dir[current_thread().name] = True
941 self.lock.notify_all()
942 self.lock.release()
943 break
944# self.lock.notify_all()
945# self.lock.release()
946
947 for i in range (1,4):
948 failure_dir = {}
949 self.ip_count = 0
950 self.failure_count = 0
951 self.start_time = 0
952 self.diff = 0
953 self.transaction_count = 0
954 self.start_time = time.time()
955
956 while len(failure_dir) != 6:
957 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
958 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
959 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
960 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
961 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
962 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
963
964 t.start()
965 t1.start()
966 t2.start()
967 t3.start()
968 t4.start()
969 t5.start()
970
971 t.join()
972 t1.join()
973 t2.join()
974 t3.join()
975 t4.join()
976 t5.join()
977
978 self.diff = round(time.time() - self.start_time, 0)
979 self.transaction_count = round((self.ip_count)/self.diff, 2)
980
981 self.transactions += (self.ip_count+self.failure_count)
982 self.running_time += self.diff
983 self.total_success += self.ip_count
984 self.total_failure += self.failure_count
985
986
987 log_test.info("Statistics for run %d",i)
988 log_test.info("----------------------------------------------------------------------------------")
989 log_test.info("No. of consecutive successful transactions Running Time ")
990 log_test.info(" %d %d " %(self.ip_count, self.diff))
991 log_test.info("----------------------------------------------------------------------------------")
992 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
993 log_test.info("----------------------------------------------------------------------------------")
994
995 log_test.info("Final Statistics for total successful transactions")
996 log_test.info("----------------------------------------------------------------------------------")
997 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
998 log_test.info(" %d %d %d " %(self.transactions,
999 self.total_success, self.running_time))
1000 log_test.info("----------------------------------------------------------------------------------")
1001 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1002 log_test.info("----------------------------------------------------------------------------------")
1003
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001004 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001005 for key in (key for key in g_subscriber_port_map if key < 100):
1006 self.host_load(g_subscriber_port_map[key])
1007
1008 def thread_fun(i):
1009# mac = self.get_mac('veth{}'.format(i))
1010 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1011 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1012 self.lock.acquire()
1013
1014 if cip:
1015 self.ip_count += 1
1016 elif cip is None:
1017 self.failure_count += 1
1018
1019 self.lock.notify_all()
1020 self.lock.release()
1021
1022 for i in range (1,4):
1023 self.ip_count = 0
1024 self.failure_count = 0
1025 self.start_time = 0
1026 self.diff = 0
1027 self.transaction_count = 0
1028 self.start_time = time.time()
1029
1030 while self.diff <= 60:
1031 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1032 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1033 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1034 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1035 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1036 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1037
1038 t.start()
1039 t1.start()
1040 t2.start()
1041 t3.start()
1042 t4.start()
1043 t5.start()
1044
1045 t.join()
1046 t1.join()
1047 t2.join()
1048 t3.join()
1049 t4.join()
1050 t5.join()
1051
1052 self.diff = round(time.time() - self.start_time, 0)
1053 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1054 self.transactions += (self.ip_count+self.failure_count)
1055 self.running_time += self.diff
1056 self.total_success += self.ip_count
1057 self.total_failure += self.failure_count
1058
1059 log_test.info("----------------------------------------------------------------------------------")
1060 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1061 log_test.info("----------------------------------------------------------------------------------")
1062 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1063 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1064 log_test.info("----------------------------------------------------------------------------------")
1065 log_test.info("No. of clients per second in run %d:%f "
1066 %(i, self.transaction_count))
1067 log_test.info("----------------------------------------------------------------------------------")
1068
1069 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1070 log_test.info("----------------------------------------------------------------------------------")
1071 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1072 log_test.info(" %d %d %d %d" %(self.transactions,
1073 self.total_success, self.total_failure, self.running_time))
1074 log_test.info("----------------------------------------------------------------------------------")
1075 log_test.info("Average no. of clients per second: %d ",
1076 round(self.transactions/self.running_time,0))
1077 log_test.info("----------------------------------------------------------------------------------")
1078
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001079 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001080 mac = self.get_mac(iface)
1081 self.host_load(iface)
1082 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1083 cip, sip, mac, _ = self.dhcp.only_discover()
1084 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1085 (cip, sip, mac) )
1086 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1087 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1088 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1089 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1090 (new_cip, new_sip, new_mac) )
1091 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1092 log_test.info("Now sending DHCP Request for old DHCP discover.")
1093 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1094 if new_cip is None:
1095 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1096 %(new_cip, new_sip, new_mac) )
1097 elif new_cip:
1098 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.'
1099 %(new_cip, new_sip, new_mac, new_cip) )
1100 assert_equal(new_cip, None)