blob: a269f75801cc64ad1a8e6d46da2f08a9fea0a60b [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'
Thangavelu K S905e5482017-09-12 06:48:02 -070064 app_olt = 'org.onosproject.olt'
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000065 relay_interfaces_last = ()
66 interface_to_mac_map = {}
67 host_ip_map = {}
68 test_path = os.path.dirname(os.path.realpath(__file__))
69 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070070 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
Thangavelu K S905e5482017-09-12 06:48:02 -070071 olt_app_file = os.path.join(test_path, '..', 'apps/olt-app-1.3.0-SNAPSHOT.oar')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070072 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
73 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 +000074 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
75 default_options = [ ('subnet-mask', '255.255.255.0'),
76 ('broadcast-address', '192.168.1.255'),
77 ('domain-name-servers', '192.168.1.1'),
78 ('domain-name', '"mydomain.cord-tester"'),
79 ]
80 default_subnet_config = [ ('192.168.1.2',
81'''
82subnet 192.168.1.0 netmask 255.255.255.0 {
83 range 192.168.1.10 192.168.1.100;
84}
85'''), ]
86
87 lock = threading.Condition()
88 ip_count = 0
89 failure_count = 0
90 start_time = 0
91 diff = 0
92
93 transaction_count = 0
94 transactions = 0
95 running_time = 0
96 total_success = 0
97 total_failure = 0
98 #just in case we want to reset ONOS to default network cfg after relay tests
99 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
100 configs = {}
Thangavelu K S905e5482017-09-12 06:48:02 -0700101 sadis_configs = {}
102 default_onos_netcfg = {}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000103
104 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700105 def update_apps_version(cls):
106 version = Onos.getVersion()
107 major = int(version.split('.')[0])
108 minor = int(version.split('.')[1])
109 dhcpl2_app_version = '1.0.0'
110 sadis_app_version = '1.0.0-SNAPSHOT'
111# sadis-app-1.0.0-SNAPSHOT.oar
112# if major > 1:
113# cordigmp_app_version = '3.0-SNAPSHOT'
114# olt_app_version = '2.0-SNAPSHOT'
115# elif major == 1:
116# if minor > 10:
117# cordigmp_app_version = '3.0-SNAPSHOT'
118# olt_app_version = '2.0-SNAPSHOT'
119# elif minor <= 8:
120# olt_app_version = '1.1-SNAPSHOT'
121 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
122 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
123
124
125 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000126 def setUpClass(cls):
127 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700128 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000129 OnosCtrl(cls.app_dhcp).deactivate()
130 time.sleep(3)
131 cls.onos_ctrl = OnosCtrl(cls.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.onos_ctrl = OnosCtrl(cls.sadis_app)
136 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700137 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000138 time.sleep(3)
139 cls.dhcp_l2_relay_setup()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700140 cls.cord_sadis_load()
141 cls.cord_l2_relay_load()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000142 ##start dhcpd initially with default config
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700143 #cls.dhcpd_start()
144
145 def setUp(self):
Thangavelu K S905e5482017-09-12 06:48:02 -0700146 self.default_onos_netcfg = OnosCtrl.get_config()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700147 super(dhcpl2relay_exchange, self).setUp()
Thangavelu K S905e5482017-09-12 06:48:02 -0700148 self.dhcp_l2_relay_setup()
149 self.cord_sadis_load()
150 self.cord_l2_relay_load()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700151
152 def tearDown(self):
153 super(dhcpl2relay_exchange, self).tearDown()
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700154 OnosCtrl.uninstall_app(self.dhcpl2_app_file)
155 OnosCtrl.uninstall_app(self.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700156 OnosCtrl.uninstall_app(self.olt_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000157
158 @classmethod
159 def tearDownClass(cls):
160 '''Deactivate the cord dhcpl2relay app'''
Thangavelu K S905e5482017-09-12 06:48:02 -0700161# OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
162# OnosCtrl.uninstall_app(cls.sadis_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000163 cls.onos_ctrl.deactivate()
Thangavelu K S905e5482017-09-12 06:48:02 -0700164 # OnosCtrl(cls.app).deactivate()
165 OnosCtrl(cls.sadis_app).deactivate()
166 OnosCtrl(cls.app_olt).deactivate()
Thangavelu K Saf3a1512017-09-06 06:34:14 -0700167 #cls.dhcp_l2_relay_cleanup()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000168
169 @classmethod
170 def dhcp_l2_relay_setup(cls):
Thangavelu K S905e5482017-09-12 06:48:02 -0700171 did = OnosCtrl.get_device_ids()
172 device_details = OnosCtrl.get_devices()
173 if device_details is not None:
174 for device in device_details:
175 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
176 if device['available'] is True and device['driver'] == 'ovs':
177 did_ovs = device['id']
178 else:
179 log_test.info('On this DHCPl2relay setup, onos does not have ovs device where external DHCP server is have connect point, so return with false status')
180 return False
181 cls.relay_device_id = did_ovs
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000182 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
183 cls.port_map, _ = cls.olt.olt_port_map()
184 if cls.port_map:
185 ##Per subscriber, we use 1 relay port
186 try:
187 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
188 except:
189 relay_port = cls.port_map['uplink']
190 cls.relay_interface_port = relay_port
191 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
192 else:
193 cls.relay_interface_port = 100
194 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
195 cls.relay_interfaces_last = cls.relay_interfaces
196 if cls.port_map:
197 ##generate a ip/mac client virtual interface config for onos
198 interface_list = []
199 for port in cls.port_map['ports']:
200 port_num = cls.port_map[port]
201 if port_num == cls.port_map['uplink']:
202 continue
203 ip = cls.get_host_ip(port_num)
204 mac = cls.get_mac(port)
205 interface_list.append((port_num, ip, mac))
206
207 #configure dhcp server virtual interface on the same subnet as first client interface
208 relay_ip = cls.get_host_ip(interface_list[0][0])
209 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
210 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700211 #cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000212
213 @classmethod
214 def dhcp_l2_relay_cleanup(cls):
215 ##reset the ONOS port configuration back to default
216 for config in cls.configs.items():
217 OnosCtrl.delete(config)
Thangavelu K S905e5482017-09-12 06:48:02 -0700218 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000219 # if cls.onos_restartable is True:
220 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
221 # return cord_test_onos_restart(config = {})
222
223 @classmethod
224 def onos_load_config(cls, config):
225 status, code = OnosCtrl.config(config)
226 if status is False:
227 log_test.info('JSON request returned status %d' %code)
228 assert_equal(status, True)
229 time.sleep(3)
230
231 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700232 def onos_delete_config(cls, config):
233 status, code = OnosCtrl.delete(config)
234 if status is False:
235 log_test.info('JSON request returned status %d' %code)
236 assert_equal(status, True)
237 time.sleep(3)
238
239 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000240 def onos_interface_load(cls, interface_list):
241 interface_dict = { 'ports': {} }
242 for port_num, ip, mac in interface_list:
243 port_map = interface_dict['ports']
244 port = '{}/{}'.format(cls.relay_device_id, port_num)
245 port_map[port] = { 'interfaces': [] }
246 interface_list = port_map[port]['interfaces']
247 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
248 'mac' : mac,
249 'name': 'vir-{}'.format(port_num)
250 }
251 interface_list.append(interface_map)
252
253 cls.onos_load_config(interface_dict)
254 cls.configs['interface_config'] = interface_dict
255
256 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700257 def cord_l2_relay_load(cls,dhcp_server_connectPoint = None, delete = False):
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700258 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
259 #relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700260 #### We have to work on later versions by removing these hard coded values
261 relay_device_map = "{}/1".format(cls.relay_device_id)
262 relay_device_map3 = "{}/3".format(cls.relay_device_id)
263 relay_device_map4 = "{}/4".format(cls.relay_device_id)
264 relay_device_map5 = "{}/5".format(cls.relay_device_id)
265 relay_device_map6 = "{}/6".format(cls.relay_device_id)
266 relay_device_map7 = "{}/7".format(cls.relay_device_id)
267 relay_device_map8 = "{}/8".format(cls.relay_device_id)
268 relay_device_map9 = "{}/9".format(cls.relay_device_id)
269 relay_device_map10 = "{}/10".format(cls.relay_device_id)
270 relay_device_map11 = "{}/11".format(cls.relay_device_id)
271 relay_device_map12 = "{}/12".format(cls.relay_device_id)
272 if dhcp_server_connectPoint is None:
273 dhcp_server_connectPoint = [relay_device_map,relay_device_map3,relay_device_map4,relay_device_map5,relay_device_map6,relay_device_map7,relay_device_map8,relay_device_map9,relay_device_map10,relay_device_map11,relay_device_map12]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700274 print relay_device_map
275 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
Thangavelu K S905e5482017-09-12 06:48:02 -0700276 {"dhcpserverConnectPoint":dhcp_server_connectPoint}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000277 }
278 }
279 }
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700280 print "---------------------------------------------"
281 print dhcp_dict
282 print "---------------------------------------------"
Thangavelu K S905e5482017-09-12 06:48:02 -0700283 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700284 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700285 if delete == False:
286 cls.onos_load_config(dhcp_dict)
287 else:
288 cls.onos_delete_config(dhcp_dict)
289 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000290 cls.configs['relay_config'] = dhcp_dict
291
292 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700293 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000294 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700295 device_details = OnosCtrl.get_devices()
296 if device_details is not None:
297 for device in device_details:
298 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
299 if device['available'] is True and device['driver'] == 'pmc-olt':
300 cls.olt_serial_id = "{}".format(device['serial'])
301 else:
302 cls.olt_serial_id = " "
303 else:
304 log_test.info('On this DHCPl2relay setup, onos does not have Tibit device where DHCP client is connected on UNI point, so return with false status')
305 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700306 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000307 "org.opencord.sadis": {
308 "sadis": {
309 "integration": {
310 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700311 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000312 "maxsize": 50,
313 "ttl": "PT1m"
314 }
315 },
316 "entries": [{
317 "id": "uni-254",
318 "cTag": 202,
319 "sTag": 222,
320 "nasPortId": "uni-254"
321 },
322 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700323 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700324 "hardwareIdentifier": "00:0c:e2:31:05:00",
325 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000326 "nasId": "B100-NASID"
327 }
328 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700329 }
330 }
331 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000332 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700333 #OnosCtrl.uninstall_app(cls.olt_app_file)
334 OnosCtrl.install_app(cls.olt_app_file)
335 time.sleep(5)
336 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700337 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700338 if sadis_info:
339 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000340 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700341 cls.sadis_configs['relay_config'] = sadis_dict
342
343 def sadis_info_dict(self, subscriber_port_id =None, c_tag = None, s_tag = None, nas_port_id =None,olt_serial_id =None,olt_mac=None,olt_ip =None,olt_nas_id=None):
344 ### Need to work on these hard coded values on later merges
345 if subscriber_port_id is None:
346 subscriber_port_id = "uni-254"
347 if c_tag is None:
348 c_tag = 202
349 if s_tag is None:
350 s_tag = 222
351 if nas_port_id is None:
352 nas_port_id = "uni-254"
353 if olt_serial_id is None:
354 olt_serial_id = self.olt_serial_id
355 if olt_mac is None:
356 olt_mac = "00:0c:e2:31:05:00"
357 if olt_ip is None:
358 olt_ip = "172.17.0.1"
359 if olt_nas_id is None:
360 olt_nas_id = "B100-NASID"
361 sadis_dict = { "apps": {
362 "org.opencord.sadis": {
363 "sadis": {
364 "integration": {
365 "cache": {
366 "enabled": "true",
367 "maxsize": 50,
368 "ttl": "PT1m"
369 }
370 },
371 "entries": [{
372 "id": subscriber_port_id,
373 "cTag": c_tag,
374 "sTag": s_tag,
375 "nasPortId": nas_port_id
376 },
377 {
378 "id": olt_serial_id,
379 "hardwareIdentifier": olt_mac,
380 "ipAddress": olt_ip,
381 "nasId": olt_nas_id
382 }
383 ]
384 }
385 }
386 }
387 }
388 return sadis_dict
389
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000390
391 @classmethod
392 def get_host_ip(cls, port):
393 if cls.host_ip_map.has_key(port):
394 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700395 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000396 return cls.host_ip_map[port]
397
398 @classmethod
399 def host_load(cls, iface):
400 '''Have ONOS discover the hosts for dhcp-relay responses'''
401 port = g_subscriber_port_map[iface]
402 host = '173.17.1.{}'.format(port)
403 cmds = ( 'ifconfig {} 0'.format(iface),
404 'ifconfig {0} {1}'.format(iface, host),
405 'arping -I {0} {1} -c 2'.format(iface, host),
406 'ifconfig {} 0'.format(iface), )
407 for c in cmds:
408 os.system(c)
409
410 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000411 def get_mac(cls, iface):
412 if cls.interface_to_mac_map.has_key(iface):
413 return cls.interface_to_mac_map[iface]
414 mac = get_mac(iface, pad = 0)
415 cls.interface_to_mac_map[iface] = mac
416 return mac
417
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000418 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000419
420 self.ip_count = 0
421 self.failure_count = 0
422 self.start_time = 0
423 self.diff = 0
424 self.transaction_count = 0
425
426 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000427 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
428 self.start_time = time.time()
429
430 while self.diff <= 60:
431
432 if only_discover:
433 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
434 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
435 (cip, sip, mac))
436 else:
437 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
438
439 if cip:
440 self.ip_count +=1
441 elif cip == None:
442 self.failure_count += 1
443 log_test.info('Failed to get ip')
444 if success_rate and self.ip_count > 0:
445 break
446
447 self.diff = round(time.time() - self.start_time, 0)
448
449 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
450 self.transactions += (self.ip_count+self.failure_count)
451 self.running_time += self.diff
452 self.total_success += self.ip_count
453 self.total_failure += self.failure_count
454
455 def send_recv(self, mac=None, update_seed = False, validate = True):
456 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
457 if validate:
458 assert_not_equal(cip, None)
459 assert_not_equal(sip, None)
460 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
461 (cip, sip, self.dhcp.get_mac(cip)[0]))
462 return cip,sip
463
464 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
465 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000466 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
467 self.send_recv(mac=mac)
468
Thangavelu K S905e5482017-09-12 06:48:02 -0700469 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000470 mac = self.get_mac(iface)
471 onos_netcfg = OnosCtrl.get_config()
472 app_status = False
473 app_name = 'org.opencord.dhcpl2relay'
474 for app in onos_netcfg['apps']:
475 if app == app_name:
476 log_test.info('%s app is being installed'%app)
477 app_status = True
478 if app_status is not True:
479 log_test.info('%s app is not being installed'%app_name)
480 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000481
Thangavelu K S905e5482017-09-12 06:48:02 -0700482 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000483 mac = self.get_mac(iface)
484 onos_netcfg = OnosCtrl.get_config()
485 app_status = False
486 app_name = 'org.opencord.sadis'
487 for app in onos_netcfg['apps']:
488 if app == app_name:
489 log_test.info('%s app is being installed'%app)
490 app_status = True
491 if app_status is not True:
492 log_test.info('%s app is not being installed'%app_name)
493 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000494
Thangavelu K S905e5482017-09-12 06:48:02 -0700495 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000496 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700497 onos_netcfg = OnosCtrl.get_config()
498 app_status = False
499 app_name = 'org.opencord.dhcpl2relay'
500 for app in onos_netcfg['apps']:
501 if app == app_name:
502 log_test.info('%s app is being installed'%app)
503 if onos_netcfg['apps'][app_name] == {}:
504 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
505 else:
506 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
507 app_status = True
508 if app_status is not True:
509 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
510 assert_equal(True, False)
511
512 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
513 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000514 onos_netcfg = OnosCtrl.get_config()
515 app_status = False
516 app_name = 'org.opencord.sadis'
517 for app in onos_netcfg['apps']:
518 if app == app_name:
519 log_test.info('%s app is being installed'%app)
520 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700521 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
522 else:
523 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
Thangavelu K S46063d02017-09-08 21:13:24 +0000524 app_status = True
525 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700526 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
527 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000528
Thangavelu K S905e5482017-09-12 06:48:02 -0700529 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
530 relay_device_map = '{}/{}'.format(self.relay_device_id, self.relay_interface_port)
531 relay_device_map1 = '{}/1'.format(self.relay_device_id)
532 relay_device_map2 = '{}/9'.format(self.relay_device_id)
533 relay_device_map3 = '{}/6'.format(self.relay_device_id)
534 relay_device_map4 = '{}/7'.format(self.relay_device_id)
535 dhcp_server_array_connectPoints = [relay_device_map,relay_device_map1,relay_device_map2,relay_device_map3,relay_device_map4]
Thangavelu K S46063d02017-09-08 21:13:24 +0000536 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700537 self.onos_delete_config(self.configs['relay_config'])
538 self.onos_load_config(self.default_onos_netcfg)
539 self.cord_l2_relay_load(dhcp_server_connectPoint = dhcp_server_array_connectPoints, delete = False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000540 onos_netcfg = OnosCtrl.get_config()
541 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -0700542 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +0000543 for app in onos_netcfg['apps']:
544 if app == app_name:
545 log_test.info('%s app is being installed'%app)
546 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700547 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000548 elif onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'] == dhcp_server_array_connectPoints:
Thangavelu K S905e5482017-09-12 06:48:02 -0700549 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'])
Thangavelu K S46063d02017-09-08 21:13:24 +0000550 app_status = True
551 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700552 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
553 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000554 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000555 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000556
Chetan Gaonker891302d2017-09-05 15:09:26 +0000557
Thangavelu K S905e5482017-09-12 06:48:02 -0700558 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000559 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700560 c_tag = 600
561 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
562 self.cord_sadis_load(sadis_info = invalid_sadis_info)
563 onos_netcfg = OnosCtrl.get_config()
564 app_status = False
565 app_name = 'org.opencord.sadis'
566 for app in onos_netcfg['apps']:
567 if app == app_name:
568 log_test.info('%s app is being installed'%app)
569 if onos_netcfg['apps'][app_name] == {}:
570 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
571 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
572 log_test.info('The S Tag and C Tag info from network configuration are %s and %s respectively '%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'],onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag']))
573 app_status = True
574 if app_status is not True:
575 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
576 assert_equal(True, False)
577 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
578 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
579 assert_equal(cip,None)
580
581 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
582 iterations = 15
583 for i in range(iterations):
584 self.onos_ctrl.deactivate()
585 time.sleep(3)
586 self.onos_ctrl.activate()
587 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
588 mac = self.get_mac(iface)
589 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
590 self.send_recv(mac=mac)
591
592 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
593 mac = self.get_mac(iface)
594 OnosCtrl.uninstall_app(self.sadis_app_file)
595 OnosCtrl(self.sadis_app).deactivate()
596 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
597 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
598 assert_equal(cip,None)
599
600 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
601 mac = self.get_mac(iface)
602 OnosCtrl.uninstall_app(self.sadis_app_file)
603 OnosCtrl(self.sadis_app).deactivate()
604 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
605 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
606 assert_equal(cip,None)
607 OnosCtrl.uninstall_app(self.sadis_app_file)
608 OnosCtrl(self.sadis_app).deactivate()
609 #self.onos_load_config(self.sadis_configs['relay_config'])
610 self.send_recv(mac=mac)
611
612 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
613 pass
614
615 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
616 pass
617
618 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
619 pass
620
621 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
622 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000623 subscriber_port_id = "uni-200"
624 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
625 self.cord_sadis_load(sadis_info = invalid_sadis_info)
626 onos_netcfg = OnosCtrl.get_config()
627 app_status = False
628 app_name = 'org.opencord.sadis'
629 for app in onos_netcfg['apps']:
630 if app == app_name:
631 log_test.info('%s app is being installed'%app)
632 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700633 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000634 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700635 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000636 app_status = True
637 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700638 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
639
Thangavelu K S46063d02017-09-08 21:13:24 +0000640 assert_equal(True, False)
641 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
642 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
643 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000644
Thangavelu K S905e5482017-09-12 06:48:02 -0700645 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000646 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700647 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +0000648 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
649 self.cord_sadis_load(sadis_info = invalid_sadis_info)
650 onos_netcfg = OnosCtrl.get_config()
651 app_status = False
652 app_name = 'org.opencord.sadis'
653 for app in onos_netcfg['apps']:
654 if app == app_name:
655 log_test.info('%s app is being installed'%app)
656 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700657 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000658 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700659 log_test.info('The C Tag info from network configuration is = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000660 app_status = True
661 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700662 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000663 assert_equal(True, False)
664 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
665 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
666 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000667
Thangavelu K S905e5482017-09-12 06:48:02 -0700668 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000669 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000670 s_tag = 600
671 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
672 self.cord_sadis_load(sadis_info = invalid_sadis_info)
673 onos_netcfg = OnosCtrl.get_config()
674 app_status = False
675 app_name = 'org.opencord.sadis'
676 for app in onos_netcfg['apps']:
677 if app == app_name:
678 log_test.info('%s app is being installed'%app)
679 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700680 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000681 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700682 log_test.info('The S Tag info from the network configuration is = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000683 app_status = True
684 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700685 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000686 assert_equal(True, False)
687 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
688 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
689 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000690
Thangavelu K S905e5482017-09-12 06:48:02 -0700691 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000692 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000693 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
694 self.cord_sadis_load(sadis_info = invalid_sadis_info)
695 onos_netcfg = OnosCtrl.get_config()
696 app_status = False
697 app_name = 'org.opencord.sadis'
698 for app in onos_netcfg['apps']:
699 if app == app_name:
700 log_test.info('%s app is being installed'%app)
701 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700702 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000703 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700704 log_test.info('The nasPortId info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000705 app_status = True
706 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700707 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000708 assert_equal(True, False)
709 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
710 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
711 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000712
Thangavelu K S905e5482017-09-12 06:48:02 -0700713 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000714 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000715 nas_port_id = "uni-509"
716 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
717 self.cord_sadis_load(sadis_info = invalid_sadis_info)
718 onos_netcfg = OnosCtrl.get_config()
719 app_status = False
720 app_name = 'org.opencord.sadis'
721 for app in onos_netcfg['apps']:
722 if app == app_name:
723 log_test.info('%s app is being installed'%app)
724 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700725 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000726 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700727 log_test.info('The nasPortId info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000728 app_status = True
729 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700730 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000731 assert_equal(True, False)
732 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
733 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
734 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000735
Thangavelu K S905e5482017-09-12 06:48:02 -0700736 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000737 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000738 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
739 self.cord_sadis_load(sadis_info = invalid_sadis_info)
740 onos_netcfg = OnosCtrl.get_config()
741 app_status = False
742 app_name = 'org.opencord.sadis'
743 for app in onos_netcfg['apps']:
744 if app == app_name:
745 log_test.info('%s app is being installed'%app)
746 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700747 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000748 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700749 log_test.info('The serial Id info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000750 app_status = True
751 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700752 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000753 assert_equal(True, False)
754 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
755 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
756 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000757
Thangavelu K S905e5482017-09-12 06:48:02 -0700758 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000759 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000760 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
761 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
762 self.cord_sadis_load(sadis_info = invalid_sadis_info)
763 onos_netcfg = OnosCtrl.get_config()
764 app_status = False
765 app_name = 'org.opencord.sadis'
766 for app in onos_netcfg['apps']:
767 if app == app_name:
768 log_test.info('%s app is being installed'%app)
769 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700770 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000771 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700772 log_test.info('The serial Id info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id']))
Thangavelu K S46063d02017-09-08 21:13:24 +0000773 app_status = True
774 if app_status is not True:
775 assert_equal(True, False)
776 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
777 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
778 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000779
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000780 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
781 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000782 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
783 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
784 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000785 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000786
787 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
788 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000789 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
790 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
791 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000792 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000793
794 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
795 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000796 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
797 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
798 assert_equal(cip,None)
799 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
800
801 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
802 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700803 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000804 ip_map = {}
805 for i in range(requests):
806 #mac = RandMAC()._fix()
807 #log_test.info('mac is %s'%mac)
808 cip, sip = self.send_recv(update_seed = True)
809 if ip_map.has_key(cip):
810 log_test.info('IP %s given out multiple times' %cip)
811 assert_equal(False, ip_map.has_key(cip))
812 ip_map[cip] = sip
813 time.sleep(1)
814
815 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
816 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000817 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
818 cip, sip = self.send_recv(mac=mac)
819 log_test.info('Releasing ip %s to server %s' %(cip, sip))
820 assert_equal(self.dhcp.release(cip), True)
821 log_test.info('Triggering DHCP discover again after release')
822 cip2, sip2 = self.send_recv(mac=mac)
823 log_test.info('Verifying released IP was given back on rediscover')
824 assert_equal(cip, cip2)
825 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
826 assert_equal(self.dhcp.release(cip2), True)
827
828 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
829 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000830 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
831 ip_map = {}
832 for i in range(10):
833 cip, sip = self.send_recv(mac=mac, update_seed = True)
834 if ip_map.has_key(cip):
835 log_test.info('IP %s given out multiple times' %cip)
836 assert_equal(False, ip_map.has_key(cip))
837 ip_map[cip] = sip
838
839 for ip in ip_map.keys():
840 log_test.info('Releasing IP %s' %ip)
841 assert_equal(self.dhcp.release(ip), True)
842
843 ip_map2 = {}
844 log_test.info('Triggering DHCP discover again after release')
845 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
846 for i in range(len(ip_map.keys())):
847 cip, sip = self.send_recv(mac=mac, update_seed = True)
848 ip_map2[cip] = sip
849
850 log_test.info('Verifying released IPs were given back on rediscover')
851 if ip_map != ip_map2:
852 log_test.info('Map before release %s' %ip_map)
853 log_test.info('Map after release %s' %ip_map2)
854 assert_equal(ip_map, ip_map2)
855
856 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
857 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000858 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
859 log_test.info('Verifying 1 ')
860 count = 0
861 while True:
862 #mac = RandMAC()._fix()
863 cip, sip = self.send_recv(update_seed = True,validate = False)
864 if cip is None:
865 break
866 else:
867 count += 1
868 assert_equal(count,91)
869 log_test.info('Verifying 2 ')
870 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
871 assert_equal(cip, None)
872 assert_equal(sip, None)
873
874 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
875 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000876 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
877 cip, sip, mac, _ = self.dhcp.only_discover()
878 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
879 (cip, sip, mac) )
880 assert_not_equal(cip, None)
881 log_test.info('Triggering DHCP discover again.')
882 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
883 assert_equal(new_cip, cip)
884 log_test.info('got same ip to smae the client when sent discover again, as expected')
885
886 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
887 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000888 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
889 log_test.info('Sending DHCP discover and DHCP request.')
890 cip, sip = self.send_recv(mac=mac)
891 mac = self.dhcp.get_mac(cip)[0]
892 log_test.info("Sending DHCP request again.")
893 new_cip, new_sip = self.dhcp.only_request(cip, mac)
894 assert_equal(new_cip, cip)
895 log_test.info('got same ip to smae the client when sent request again, as expected')
896
897 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
898 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000899 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
900 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
901 assert_equal(cip,self.dhcp.seed_ip)
902 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
903 (cip, sip, mac) )
904
905 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
906 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000907 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
908 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
909 assert_not_equal(cip,None)
910 assert_not_equal(cip,self.dhcp.seed_ip)
911 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
912
913 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
914 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000915 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
916 cip, sip, mac, _ = self.dhcp.only_discover()
917 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
918 (cip, sip, mac) )
919 assert_not_equal(cip, None)
920 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
921 assert_equal(new_cip, None)
922 log_test.info('server sent NAK packet when requested other IP than that server offered')
923
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000924 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 +0000925 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000926 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
927 self.dhcp.return_option = 'lease'
928 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
929 assert_equal(lval, lease_time)
930 log_test.info('dhcp server offered IP address with client requested lease time')
931
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000932 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000933 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000934 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
935 cip, sip, mac, _ = self.dhcp.only_discover()
936 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
937 (cip, sip, mac) )
938 assert_not_equal(cip, None)
939 new_cip, new_sip = self.dhcp.only_request(cip, mac)
940 log_test.info('client rebooting...')
941 os.system('ifconfig '+iface+' down')
942 time.sleep(5)
943 os.system('ifconfig '+iface+' up')
944 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
945 assert_equal(new_cip2, cip)
946 log_test.info('client got same IP after reboot, as expected')
947
948
949 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
950 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000951 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
952 cip, sip, mac, _ = self.dhcp.only_discover()
953 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
954 (cip, sip, mac) )
955 assert_not_equal(cip, None)
956 new_cip, new_sip = self.dhcp.only_request(cip, mac)
957 log_test.info('server rebooting...')
958 self.tearDownClass()
959 new_cip, new_sip = self.dhcp.only_request(cip, mac)
960 assert_equal(new_cip,None)
961 self.setUpClass()
962 new_cip, new_sip = self.dhcp.only_request(cip, mac)
963 assert_equal(new_cip, cip)
964 log_test.info('client got same IP after server rebooted, as expected')
965
966 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
967 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000968 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
969 self.dhcp.return_option = 'lease'
970 log_test.info('Sending DHCP discover with lease time of 700')
971 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
972 assert_equal(lval,lease_time)
973 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
974 assert_equal(new_cip,cip)
975 assert_not_equal(lval, lease_time) #Negative Test Case
976 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
977
978 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
979 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000980 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
981 cip, sip, mac, _ = self.dhcp.only_discover()
982 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
983 assert_equal(new_cip,cip)
984 assert_equal(lval, lease_time)
985 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
986
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000987 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000988 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000989 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
990 cip, sip, mac, _ = self.dhcp.only_discover()
991 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
992 (cip, sip, mac) )
993 assert_not_equal(cip,None)
994 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
995 log_test.info('waiting for renew time..')
996 time.sleep(lval)
997 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
998 assert_equal(latest_cip, cip)
999 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1000
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001001 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001002 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001003 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1004 cip, sip, mac, _ = self.dhcp.only_discover()
1005 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1006 (cip, sip, mac) )
1007 assert_not_equal(cip,None)
1008 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1009 log_test.info('waiting for rebind time..')
1010 time.sleep(lval)
1011 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1012 assert_equal(latest_cip, cip)
1013 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1014
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001015 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001016 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001017 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1018 expected_subnet = '255.255.255.0'
1019 self.dhcp.return_option = 'subnet'
1020
1021 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
1022 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1023 (cip, sip, mac) )
1024 assert_equal(subnet_mask,expected_subnet)
1025 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1026
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001027 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001028 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001029 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1030
1031 cip, sip, mac, _ = self.dhcp.only_discover()
1032 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1033 (cip, sip, mac) )
1034 assert_not_equal(cip,None)
1035 self.dhcp.send_different_option = 'subnet'
1036 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1037 assert_equal(new_cip, cip)
1038 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1039
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001040 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001041 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001042 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1043 expected_router_address = '20.20.20.1'
1044 self.dhcp.return_option = 'router'
1045
1046 cip, sip, mac, router_address_value = self.dhcp.only_discover()
1047 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1048 (cip, sip, mac) )
1049 assert_equal(expected_router_address, router_address_value)
1050 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1051
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001052 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001053 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001054 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1055
1056 cip, sip, mac, _ = self.dhcp.only_discover()
1057 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1058 (cip, sip, mac) )
1059 assert_not_equal(cip,None)
1060 self.dhcp.send_different_option = 'router'
1061 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1062 assert_equal(new_cip, cip)
1063 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1064
1065 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1066 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001067 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1068 expected_broadcast_address = '192.168.1.255'
1069 self.dhcp.return_option = 'broadcast_address'
1070
1071 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
1072 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1073 (cip, sip, mac) )
1074 assert_equal(expected_broadcast_address, broadcast_address_value)
1075 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1076
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001077 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001078 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001079 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1080
1081 cip, sip, mac, _ = self.dhcp.only_discover()
1082 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1083 (cip, sip, mac) )
1084 assert_not_equal(cip,None)
1085 self.dhcp.send_different_option = 'broadcast_address'
1086 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1087 assert_equal(new_cip, cip)
1088 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1089
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001090 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001091 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001092 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1093 expected_dns_address = '192.168.1.1'
1094 self.dhcp.return_option = 'dns'
1095
1096 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1097 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1098 (cip, sip, mac) )
1099 assert_equal(expected_dns_address, dns_address_value)
1100 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1101
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001102 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001103 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001104 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1105
1106 cip, sip, mac, _ = self.dhcp.only_discover()
1107 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1108 (cip, sip, mac) )
1109 assert_not_equal(cip,None)
1110 self.dhcp.send_different_option = 'dns'
1111 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1112 assert_equal(new_cip, cip)
1113 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1114
1115
1116 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1117
1118 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001119 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001120 log_test.info("Statistics for run %d",i)
1121 log_test.info("----------------------------------------------------------------------------------")
1122 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1123 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1124 log_test.info("----------------------------------------------------------------------------------")
1125 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1126
1127 log_test.info("Final Statistics for total transactions")
1128 log_test.info("----------------------------------------------------------------------------------")
1129 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1130 log_test.info(" %d %d %d %d" %(self.transactions,
1131 self.total_success, self.total_failure, self.running_time))
1132 log_test.info("----------------------------------------------------------------------------------")
1133 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1134
1135 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1136
1137 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001138 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001139 log_test.info("Statistics for run %d",i)
1140 log_test.info("----------------------------------------------------------------------------------")
1141 log_test.info("No. of consecutive successful transactions Running Time ")
1142 log_test.info(" %d %d " %(self.ip_count, self.diff))
1143 log_test.info("----------------------------------------------------------------------------------")
1144 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1145 log_test.info("----------------------------------------------------------------------------------")
1146
1147 log_test.info("Final Statistics for total successful transactions")
1148 log_test.info("----------------------------------------------------------------------------------")
1149 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1150 log_test.info(" %d %d %d " %(self.transactions,
1151 self.total_success, self.running_time))
1152 log_test.info("----------------------------------------------------------------------------------")
1153 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1154 log_test.info("----------------------------------------------------------------------------------")
1155
1156 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1157
1158 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001159 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001160 log_test.info("----------------------------------------------------------------------------------")
1161 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1162 log_test.info("----------------------------------------------------------------------------------")
1163 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1164 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1165 log_test.info("----------------------------------------------------------------------------------")
1166 log_test.info("No. of clients per second in run %d:%f "
1167 %(i, self.transaction_count))
1168 log_test.info("----------------------------------------------------------------------------------")
1169 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1170 log_test.info("----------------------------------------------------------------------------------")
1171 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1172 log_test.info(" %d %d %d %d" %(self.transactions,
1173 self.total_success, self.total_failure, self.running_time))
1174 log_test.info("----------------------------------------------------------------------------------")
1175 log_test.info("Average no. of clients per second: %d ",
1176 round(self.transactions/self.running_time,0))
1177 log_test.info("----------------------------------------------------------------------------------")
1178
1179 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1180
1181 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001182 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001183 log_test.info("----------------------------------------------------------------------------------")
1184 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1185 log_test.info("----------------------------------------------------------------------------------")
1186 log_test.info("No. of consecutive successful transactions Running Time ")
1187 log_test.info(" %d %d " %(self.ip_count, self.diff))
1188 log_test.info("----------------------------------------------------------------------------------")
1189 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1190 log_test.info("----------------------------------------------------------------------------------")
1191
1192 log_test.info("Final Statistics for total successful transactions")
1193 log_test.info("----------------------------------------------------------------------------------")
1194 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1195 log_test.info(" %d %d %d " %(self.transactions,
1196 self.total_success, self.running_time))
1197 log_test.info("----------------------------------------------------------------------------------")
1198 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1199 log_test.info("----------------------------------------------------------------------------------")
1200
1201 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001202 for key in (key for key in g_subscriber_port_map if key < 100):
1203 self.host_load(g_subscriber_port_map[key])
1204
1205 def thread_fun(i):
1206 mac = self.get_mac('veth{}'.format(i))
1207 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1208 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1209 self.lock.acquire()
1210
1211 if cip:
1212 self.ip_count += 1
1213
1214 elif cip is None:
1215 self.failure_count += 1
1216
1217 self.lock.notify_all()
1218 self.lock.release()
1219
1220 for i in range (1,4):
1221 self.ip_count = 0
1222 self.failure_count = 0
1223 self.start_time = 0
1224 self.diff = 0
1225 self.transaction_count = 0
1226 self.start_time = time.time()
1227
1228 while self.diff <= 60:
1229 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1230 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1231 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1232 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1233 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1234 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1235
1236 t.start()
1237 t1.start()
1238 t2.start()
1239 t3.start()
1240 t4.start()
1241 t5.start()
1242
1243 t.join()
1244 t1.join()
1245 t2.join()
1246 t3.join()
1247 t4.join()
1248 t5.join()
1249
1250 self.diff = round(time.time() - self.start_time, 0)
1251
1252 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1253
1254 self.transactions += (self.ip_count+self.failure_count)
1255 self.running_time += self.diff
1256 self.total_success += self.ip_count
1257 self.total_failure += self.failure_count
1258
1259
1260 log_test.info("----------------------------------------------------------------------------------")
1261 log_test.info("Statistics for run %d",i)
1262 log_test.info("----------------------------------------------------------------------------------")
1263 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1264 log_test.info(" %d %d %d %d"
1265 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1266 log_test.info("----------------------------------------------------------------------------------")
1267 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1268 log_test.info("----------------------------------------------------------------------------------")
1269
1270 log_test.info("----------------------------------------------------------------------------------")
1271 log_test.info("Final Statistics for total transactions")
1272 log_test.info("----------------------------------------------------------------------------------")
1273 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1274 log_test.info(" %d %d %d %d" %(self.transactions,
1275 self.total_success, self.total_failure, self.running_time))
1276
1277 log_test.info("----------------------------------------------------------------------------------")
1278 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1279 log_test.info("----------------------------------------------------------------------------------")
1280
1281 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001282 failure_dir = {}
1283
1284 for key in (key for key in g_subscriber_port_map if key != 100):
1285 self.host_load(g_subscriber_port_map[key])
1286
1287 def thread_fun(i, j):
1288# log_test.info("Thread Name:%s",current_thread().name)
1289# failure_dir[current_thread().name] = True
1290 while failure_dir.has_key(current_thread().name) is False:
1291 mac = RandMAC()._fix()
1292 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1293 i += 2
1294 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1295 self.lock.acquire()
1296
1297 if cip:
1298 self.ip_count += 1
1299 self.lock.notify_all()
1300 self.lock.release()
1301 elif cip is None:
1302 self.failure_count += 1
1303 failure_dir[current_thread().name] = True
1304 self.lock.notify_all()
1305 self.lock.release()
1306 break
1307# self.lock.notify_all()
1308# self.lock.release()
1309
1310 for i in range (1,4):
1311 failure_dir = {}
1312 self.ip_count = 0
1313 self.failure_count = 0
1314 self.start_time = 0
1315 self.diff = 0
1316 self.transaction_count = 0
1317 self.start_time = time.time()
1318
1319 while len(failure_dir) != 6:
1320 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1321 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1322 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1323 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1324 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1325 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1326
1327 t.start()
1328 t1.start()
1329 t2.start()
1330 t3.start()
1331 t4.start()
1332 t5.start()
1333
1334 t.join()
1335 t1.join()
1336 t2.join()
1337 t3.join()
1338 t4.join()
1339 t5.join()
1340
1341 self.diff = round(time.time() - self.start_time, 0)
1342 self.transaction_count = round((self.ip_count)/self.diff, 2)
1343
1344 self.transactions += (self.ip_count+self.failure_count)
1345 self.running_time += self.diff
1346 self.total_success += self.ip_count
1347 self.total_failure += self.failure_count
1348
1349
1350 log_test.info("Statistics for run %d",i)
1351 log_test.info("----------------------------------------------------------------------------------")
1352 log_test.info("No. of consecutive successful transactions Running Time ")
1353 log_test.info(" %d %d " %(self.ip_count, self.diff))
1354 log_test.info("----------------------------------------------------------------------------------")
1355 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1356 log_test.info("----------------------------------------------------------------------------------")
1357
1358 log_test.info("Final Statistics for total successful transactions")
1359 log_test.info("----------------------------------------------------------------------------------")
1360 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1361 log_test.info(" %d %d %d " %(self.transactions,
1362 self.total_success, self.running_time))
1363 log_test.info("----------------------------------------------------------------------------------")
1364 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1365 log_test.info("----------------------------------------------------------------------------------")
1366
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001367 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001368 for key in (key for key in g_subscriber_port_map if key < 100):
1369 self.host_load(g_subscriber_port_map[key])
1370
1371 def thread_fun(i):
1372# mac = self.get_mac('veth{}'.format(i))
1373 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1374 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1375 self.lock.acquire()
1376
1377 if cip:
1378 self.ip_count += 1
1379 elif cip is None:
1380 self.failure_count += 1
1381
1382 self.lock.notify_all()
1383 self.lock.release()
1384
1385 for i in range (1,4):
1386 self.ip_count = 0
1387 self.failure_count = 0
1388 self.start_time = 0
1389 self.diff = 0
1390 self.transaction_count = 0
1391 self.start_time = time.time()
1392
1393 while self.diff <= 60:
1394 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1395 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1396 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1397 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1398 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1399 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1400
1401 t.start()
1402 t1.start()
1403 t2.start()
1404 t3.start()
1405 t4.start()
1406 t5.start()
1407
1408 t.join()
1409 t1.join()
1410 t2.join()
1411 t3.join()
1412 t4.join()
1413 t5.join()
1414
1415 self.diff = round(time.time() - self.start_time, 0)
1416 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1417 self.transactions += (self.ip_count+self.failure_count)
1418 self.running_time += self.diff
1419 self.total_success += self.ip_count
1420 self.total_failure += self.failure_count
1421
1422 log_test.info("----------------------------------------------------------------------------------")
1423 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1424 log_test.info("----------------------------------------------------------------------------------")
1425 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1426 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1427 log_test.info("----------------------------------------------------------------------------------")
1428 log_test.info("No. of clients per second in run %d:%f "
1429 %(i, self.transaction_count))
1430 log_test.info("----------------------------------------------------------------------------------")
1431
1432 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1433 log_test.info("----------------------------------------------------------------------------------")
1434 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1435 log_test.info(" %d %d %d %d" %(self.transactions,
1436 self.total_success, self.total_failure, self.running_time))
1437 log_test.info("----------------------------------------------------------------------------------")
1438 log_test.info("Average no. of clients per second: %d ",
1439 round(self.transactions/self.running_time,0))
1440 log_test.info("----------------------------------------------------------------------------------")
1441
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001442 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001443 mac = self.get_mac(iface)
1444 self.host_load(iface)
1445 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1446 cip, sip, mac, _ = self.dhcp.only_discover()
1447 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1448 (cip, sip, mac) )
1449 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1450 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1451 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1452 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1453 (new_cip, new_sip, new_mac) )
1454 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1455 log_test.info("Now sending DHCP Request for old DHCP discover.")
1456 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1457 if new_cip is None:
1458 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1459 %(new_cip, new_sip, new_mac) )
1460 elif new_cip:
1461 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.'
1462 %(new_cip, new_sip, new_mac, new_cip) )
1463 assert_equal(new_cip, None)