blob: 3917a456a9d47e73d9dd4d88a180dc112d414e32 [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
A R Karthickc0a008f2017-10-04 18:35:25 -070039from CordTestUtils import get_mac, log_test, getstatusoutput, get_controller
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000040from OnosCtrl import OnosCtrl
41from OltConfig import OltConfig
A R Karthickc0a008f2017-10-04 18:35:25 -070042from CordTestServer import cord_test_onos_restart, cord_test_ovs_flow_add
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
A R Karthickc0a008f2017-10-04 18:35:25 -070050import requests
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000051log_test.setLevel('INFO')
52
53class dhcpl2relay_exchange(CordLogger):
54
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070055 VOLTHA_HOST = None
A R Karthicke7232092017-09-07 18:01:33 -070056 VOLTHA_REST_PORT = VolthaCtrl.REST_PORT
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070057 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
58 VOLTHA_OLT_TYPE = 'simulated_olt'
59 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
60 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
61
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000062 app = 'org.opencord.dhcpl2relay'
63 sadis_app = 'org.opencord.sadis'
64 app_dhcp = 'org.onosproject.dhcp'
Thangavelu K S905e5482017-09-12 06:48:02 -070065 app_olt = 'org.onosproject.olt'
A R Karthickc0a008f2017-10-04 18:35:25 -070066 relay_interfaces = ()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000067 relay_interfaces_last = ()
68 interface_to_mac_map = {}
A R Karthickc0a008f2017-10-04 18:35:25 -070069 relay_vlan_map = {}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000070 host_ip_map = {}
71 test_path = os.path.dirname(os.path.realpath(__file__))
72 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070073 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
A R Karthickc0a008f2017-10-04 18:35:25 -070074 olt_app_file = os.path.join(test_path, '..', 'apps/olt-app-3.0-SNAPSHOT.oar')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070075 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
76 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 +000077 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
78 default_options = [ ('subnet-mask', '255.255.255.0'),
79 ('broadcast-address', '192.168.1.255'),
80 ('domain-name-servers', '192.168.1.1'),
81 ('domain-name', '"mydomain.cord-tester"'),
82 ]
83 default_subnet_config = [ ('192.168.1.2',
84'''
85subnet 192.168.1.0 netmask 255.255.255.0 {
86 range 192.168.1.10 192.168.1.100;
87}
88'''), ]
89
90 lock = threading.Condition()
91 ip_count = 0
92 failure_count = 0
93 start_time = 0
94 diff = 0
95
96 transaction_count = 0
97 transactions = 0
98 running_time = 0
99 total_success = 0
100 total_failure = 0
101 #just in case we want to reset ONOS to default network cfg after relay tests
102 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
103 configs = {}
Thangavelu K S905e5482017-09-12 06:48:02 -0700104 sadis_configs = {}
105 default_onos_netcfg = {}
A R Karthickc0a008f2017-10-04 18:35:25 -0700106 voltha_switch_map = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000107
108 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700109 def update_apps_version(cls):
110 version = Onos.getVersion()
111 major = int(version.split('.')[0])
112 minor = int(version.split('.')[1])
113 dhcpl2_app_version = '1.0.0'
A R Karthickc0a008f2017-10-04 18:35:25 -0700114 sadis_app_version = '3.0-SNAPSHOT'
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700115 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
116 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
117
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700118 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000119 def setUpClass(cls):
120 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700121 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000122 OnosCtrl(cls.app_dhcp).deactivate()
123 time.sleep(3)
124 cls.onos_ctrl = OnosCtrl(cls.app)
125 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700126 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000127 time.sleep(3)
A R Karthickc0a008f2017-10-04 18:35:25 -0700128 status, _ = OnosCtrl(cls.sadis_app).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)
A R Karthickc0a008f2017-10-04 18:35:25 -0700131 cls.setup_dhcpd()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700132
133 def setUp(self):
Thangavelu K S905e5482017-09-12 06:48:02 -0700134 self.default_onos_netcfg = OnosCtrl.get_config()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700135 super(dhcpl2relay_exchange, self).setUp()
A R Karthickc0a008f2017-10-04 18:35:25 -0700136 #self.dhcp_l2_relay_setup()
137 #self.cord_sadis_load()
138 #self.cord_l2_relay_load()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700139
140 def tearDown(self):
141 super(dhcpl2relay_exchange, self).tearDown()
A R Karthickc0a008f2017-10-04 18:35:25 -0700142 #OnosCtrl.uninstall_app(self.dhcpl2_app_file)
143 #OnosCtrl.uninstall_app(self.sadis_app_file)
144 #OnosCtrl.uninstall_app(self.olt_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000145
146 @classmethod
147 def tearDownClass(cls):
148 '''Deactivate the cord dhcpl2relay app'''
A R Karthickc0a008f2017-10-04 18:35:25 -0700149 #cls.onos_ctrl.deactivate()
150 #OnosCtrl(cls.sadis_app).deactivate()
151 #OnosCtrl(cls.app_olt).deactivate()
152
153 @classmethod
154 def setup_dhcpd(cls, boot_delay = 5):
155 if cls.service_running("/usr/sbin/dhcpd"):
156 print('DHCPD already running in container')
157 return True
158 setup_for_relay = cls.dhcp_l2_relay_setup()
159 cls.cord_l2_relay_load()
160 cls.voltha_setup()
161 dhcp_start_status = cls.dhcpd_start()
162 if setup_for_relay and dhcp_start_status:
163 return True
164 return False
165
166 @classmethod
167 def config_olt(cls, switch_map):
168 controller = get_controller()
169 auth = ('karaf', 'karaf')
170 #configure subscriber for every port on all the voltha devices
171 for device, device_map in switch_map.iteritems():
172 uni_ports = device_map['ports']
173 uplink_vlan = device_map['uplink_vlan']
174 for port in uni_ports:
175 vlan = port
176 rest_url = 'http://{}:8181/onos/olt/oltapp/{}/{}/{}'.format(controller,
177 device,
178 port,
179 vlan)
180 requests.post(rest_url, auth = auth)
181
182 @classmethod
183 def voltha_setup(cls):
184 s_tag_map = {}
185 #configure olt app to provision dhcp flows
186 cls.config_olt(cls.voltha_switch_map)
187 for switch, switch_map in cls.voltha_switch_map.iteritems():
188 s_tag_map[int(switch_map['uplink_vlan'])] = map(lambda p: int(p), switch_map['ports'])
189
190 cmd_list = []
191 relay_interface = cls.relay_interfaces[0]
192 cls.relay_vlan_map[relay_interface] = []
193 for s_tag, ports in s_tag_map.iteritems():
194 vlan_stag_intf = '{}.{}'.format(relay_interface, s_tag)
195 cmd = 'ip link add link %s name %s type vlan id %d' %(relay_interface, vlan_stag_intf, s_tag)
196 cmd_list.append(cmd)
197 cmd = 'ip link set %s up' %(vlan_stag_intf)
198 cmd_list.append(cmd)
199 for port in ports:
200 vlan_ctag_intf = '{}.{}.{}'.format(relay_interface, s_tag, port)
201 cmd = 'ip link add link %s name %s type vlan id %d' %(vlan_stag_intf, vlan_ctag_intf, port)
202 cmd_list.append(cmd)
203 cmd = 'ip link set %s up' %(vlan_ctag_intf)
204 cmd_list.append(cmd)
205 cls.relay_vlan_map[relay_interface].append(vlan_ctag_intf)
206 cls.relay_vlan_map[relay_interface].append(vlan_stag_intf)
207
208 for cmd in cmd_list:
209 log_test.info('Running command: %s' %cmd)
210 os.system(cmd)
211
212 cord_test_ovs_flow_add(cls.relay_interface_port)
213 for s_tag in s_tag_map.keys():
214 log_test.info('Configuring OVS flow for port %d, s_tag %d' %(cls.relay_interface_port, s_tag))
215 cord_test_ovs_flow_add(cls.relay_interface_port, s_tag)
216
217 @classmethod
218 def service_running(cls, pattern):
219 st, _ = getstatusoutput('pgrep -f "{}"'.format(pattern))
220 return True if st == 0 else False
221
222 @classmethod
223 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
224 subnet = default_subnet_config):
225 conf = ''
226 for k, v in config.items():
227 conf += '{} {};\n'.format(k, v)
228
229 opts = ''
230 for k, v in options:
231 opts += 'option {} {};\n'.format(k, v)
232
233 subnet_config = ''
234 for _, v in subnet:
235 subnet_config += '{}\n'.format(v)
236
237 return '{}{}{}'.format(conf, opts, subnet_config)
238
239 @classmethod
240 def dhcpd_start(cls, intf_list = None,
241 config = default_config, options = default_options,
242 subnet = default_subnet_config):
243 '''Start the dhcpd server by generating the conf file'''
244 if intf_list is None:
245 intf_list = cls.relay_interfaces
246 intf_list = list(intf_list)
247 ##stop dhcpd if already running
248 #cls.dhcpd_stop()
249 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
250 subnet = subnet)
251 ##first touch dhcpd.leases if it doesn't exist
252 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
253 if os.access(lease_file, os.F_OK) is False:
254 with open(lease_file, 'w') as fd: pass
255
256 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
257 with open(conf_file, 'w') as fd:
258 fd.write(dhcp_conf)
259
260 #now configure the dhcpd interfaces for various subnets
261 index = 0
262 intf_info = []
263 vlan_intf_list = []
264 for ip,_ in subnet:
265 vlan_intf = None
266 intf = intf_list[index]
267 if intf in cls.relay_vlan_map:
268 vlan_intf = cls.relay_vlan_map[intf][0]
269 vlan_intf_list.append(vlan_intf)
270 mac = cls.get_mac(intf)
271 intf_info.append((ip, mac))
272 index += 1
273 cmd = 'ifconfig {} {}'.format(intf, ip)
274 status = os.system(cmd)
275 if vlan_intf:
276 cmd = 'ifconfig {} {}'.format(vlan_intf, ip)
277 os.system(cmd)
278
279 intf_str = ','.join(intf_list)
280 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format('/root/test/src/test/setup/dhcpd.conf','/root/test/src/test/setup/dhcpd.leases', intf_str)
281 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
282 status = os.system(dhcpd_cmd)
283 vlan_intf_str = ','.join(vlan_intf_list)
284 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format('/root/test/src/test/setup/dhcpd.conf','/root/test/src/test/setup/dhcpd.leases', vlan_intf_str)
285 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
286 status = os.system(dhcpd_cmd)
287 if status > 255:
288 status = 1
289 else:
290 return False
291 time.sleep(3)
292 cls.relay_interfaces_last = cls.relay_interfaces
293 cls.relay_interfaces = intf_list
294 return True
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000295
296 @classmethod
297 def dhcp_l2_relay_setup(cls):
A R Karthickc0a008f2017-10-04 18:35:25 -0700298 device_details = OnosCtrl.get_devices(mfr = 'Nicira')
Thangavelu K S905e5482017-09-12 06:48:02 -0700299 if device_details is not None:
A R Karthickc0a008f2017-10-04 18:35:25 -0700300 did_ovs = device_details[0]['id']
Thangavelu K S905e5482017-09-12 06:48:02 -0700301 else:
302 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')
303 return False
304 cls.relay_device_id = did_ovs
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000305 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
306 cls.port_map, _ = cls.olt.olt_port_map()
307 if cls.port_map:
308 ##Per subscriber, we use 1 relay port
309 try:
310 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
311 except:
312 relay_port = cls.port_map['uplink']
313 cls.relay_interface_port = relay_port
314 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
315 else:
316 cls.relay_interface_port = 100
317 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
318 cls.relay_interfaces_last = cls.relay_interfaces
319 if cls.port_map:
320 ##generate a ip/mac client virtual interface config for onos
321 interface_list = []
322 for port in cls.port_map['ports']:
323 port_num = cls.port_map[port]
324 if port_num == cls.port_map['uplink']:
325 continue
326 ip = cls.get_host_ip(port_num)
327 mac = cls.get_mac(port)
328 interface_list.append((port_num, ip, mac))
329
330 #configure dhcp server virtual interface on the same subnet as first client interface
331 relay_ip = cls.get_host_ip(interface_list[0][0])
332 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
333 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthickc0a008f2017-10-04 18:35:25 -0700334 cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000335
336 @classmethod
337 def dhcp_l2_relay_cleanup(cls):
338 ##reset the ONOS port configuration back to default
339 for config in cls.configs.items():
340 OnosCtrl.delete(config)
Thangavelu K S905e5482017-09-12 06:48:02 -0700341 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000342 # if cls.onos_restartable is True:
343 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
344 # return cord_test_onos_restart(config = {})
345
346 @classmethod
347 def onos_load_config(cls, config):
348 status, code = OnosCtrl.config(config)
349 if status is False:
350 log_test.info('JSON request returned status %d' %code)
351 assert_equal(status, True)
352 time.sleep(3)
353
354 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700355 def onos_delete_config(cls, config):
356 status, code = OnosCtrl.delete(config)
357 if status is False:
358 log_test.info('JSON request returned status %d' %code)
359 assert_equal(status, True)
360 time.sleep(3)
361
362 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000363 def onos_interface_load(cls, interface_list):
364 interface_dict = { 'ports': {} }
365 for port_num, ip, mac in interface_list:
366 port_map = interface_dict['ports']
367 port = '{}/{}'.format(cls.relay_device_id, port_num)
368 port_map[port] = { 'interfaces': [] }
369 interface_list = port_map[port]['interfaces']
370 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
371 'mac' : mac,
372 'name': 'vir-{}'.format(port_num)
373 }
374 interface_list.append(interface_map)
375
376 cls.onos_load_config(interface_dict)
377 cls.configs['interface_config'] = interface_dict
378
379 @classmethod
A R Karthickc0a008f2017-10-04 18:35:25 -0700380 def cord_l2_relay_load(cls, dhcp_server_connectPoint = None, delete = False):
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700381 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
A R Karthickc0a008f2017-10-04 18:35:25 -0700382 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700383 #### We have to work on later versions by removing these hard coded values
Thangavelu K S905e5482017-09-12 06:48:02 -0700384 if dhcp_server_connectPoint is None:
A R Karthickc0a008f2017-10-04 18:35:25 -0700385 dhcp_server_connectPoint = [relay_device_map]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700386 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
A R Karthickc0a008f2017-10-04 18:35:25 -0700387 {"dhcpServerConnectPoints":dhcp_server_connectPoint}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000388 }
389 }
390 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700391 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700392 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700393 if delete == False:
394 cls.onos_load_config(dhcp_dict)
395 else:
396 cls.onos_delete_config(dhcp_dict)
397 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000398 cls.configs['relay_config'] = dhcp_dict
399
400 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700401 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000402 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700403 device_details = OnosCtrl.get_devices()
404 if device_details is not None:
405 for device in device_details:
406 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
407 if device['available'] is True and device['driver'] == 'pmc-olt':
408 cls.olt_serial_id = "{}".format(device['serial'])
409 else:
410 cls.olt_serial_id = " "
411 else:
412 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')
413 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700414 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000415 "org.opencord.sadis": {
416 "sadis": {
417 "integration": {
418 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700419 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000420 "maxsize": 50,
421 "ttl": "PT1m"
422 }
423 },
424 "entries": [{
425 "id": "uni-254",
426 "cTag": 202,
427 "sTag": 222,
428 "nasPortId": "uni-254"
429 },
430 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700431 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700432 "hardwareIdentifier": "00:0c:e2:31:05:00",
433 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000434 "nasId": "B100-NASID"
435 }
436 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700437 }
438 }
439 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000440 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700441 #OnosCtrl.uninstall_app(cls.olt_app_file)
442 OnosCtrl.install_app(cls.olt_app_file)
443 time.sleep(5)
444 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700445 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700446 if sadis_info:
447 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000448 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700449 cls.sadis_configs['relay_config'] = sadis_dict
450
451 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):
452 ### Need to work on these hard coded values on later merges
453 if subscriber_port_id is None:
454 subscriber_port_id = "uni-254"
455 if c_tag is None:
456 c_tag = 202
457 if s_tag is None:
458 s_tag = 222
459 if nas_port_id is None:
460 nas_port_id = "uni-254"
461 if olt_serial_id is None:
462 olt_serial_id = self.olt_serial_id
463 if olt_mac is None:
464 olt_mac = "00:0c:e2:31:05:00"
465 if olt_ip is None:
466 olt_ip = "172.17.0.1"
467 if olt_nas_id is None:
468 olt_nas_id = "B100-NASID"
469 sadis_dict = { "apps": {
470 "org.opencord.sadis": {
471 "sadis": {
472 "integration": {
473 "cache": {
474 "enabled": "true",
475 "maxsize": 50,
476 "ttl": "PT1m"
477 }
478 },
479 "entries": [{
480 "id": subscriber_port_id,
481 "cTag": c_tag,
482 "sTag": s_tag,
483 "nasPortId": nas_port_id
484 },
485 {
486 "id": olt_serial_id,
487 "hardwareIdentifier": olt_mac,
488 "ipAddress": olt_ip,
489 "nasId": olt_nas_id
490 }
491 ]
492 }
493 }
494 }
495 }
496 return sadis_dict
497
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000498
499 @classmethod
500 def get_host_ip(cls, port):
501 if cls.host_ip_map.has_key(port):
502 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700503 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000504 return cls.host_ip_map[port]
505
506 @classmethod
507 def host_load(cls, iface):
508 '''Have ONOS discover the hosts for dhcp-relay responses'''
509 port = g_subscriber_port_map[iface]
510 host = '173.17.1.{}'.format(port)
511 cmds = ( 'ifconfig {} 0'.format(iface),
512 'ifconfig {0} {1}'.format(iface, host),
513 'arping -I {0} {1} -c 2'.format(iface, host),
514 'ifconfig {} 0'.format(iface), )
515 for c in cmds:
516 os.system(c)
517
518 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000519 def get_mac(cls, iface):
520 if cls.interface_to_mac_map.has_key(iface):
521 return cls.interface_to_mac_map[iface]
522 mac = get_mac(iface, pad = 0)
523 cls.interface_to_mac_map[iface] = mac
524 return mac
525
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000526 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000527
528 self.ip_count = 0
529 self.failure_count = 0
530 self.start_time = 0
531 self.diff = 0
532 self.transaction_count = 0
533
534 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000535 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
536 self.start_time = time.time()
537
538 while self.diff <= 60:
539
540 if only_discover:
541 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
542 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
543 (cip, sip, mac))
544 else:
545 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
546
547 if cip:
548 self.ip_count +=1
549 elif cip == None:
550 self.failure_count += 1
551 log_test.info('Failed to get ip')
552 if success_rate and self.ip_count > 0:
553 break
554
555 self.diff = round(time.time() - self.start_time, 0)
556
557 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
558 self.transactions += (self.ip_count+self.failure_count)
559 self.running_time += self.diff
560 self.total_success += self.ip_count
561 self.total_failure += self.failure_count
562
563 def send_recv(self, mac=None, update_seed = False, validate = True):
564 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
565 if validate:
566 assert_not_equal(cip, None)
567 assert_not_equal(sip, None)
568 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
569 (cip, sip, self.dhcp.get_mac(cip)[0]))
570 return cip,sip
571
A R Karthickc0a008f2017-10-04 18:35:25 -0700572 def test_dhcpl2relay_initialize(self):
573 '''Setup and configure the DHCP L2 relay app'''
574 pass
575
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000576 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
577 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000578 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
579 self.send_recv(mac=mac)
580
Thangavelu K S905e5482017-09-12 06:48:02 -0700581 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000582 mac = self.get_mac(iface)
583 onos_netcfg = OnosCtrl.get_config()
584 app_status = False
585 app_name = 'org.opencord.dhcpl2relay'
586 for app in onos_netcfg['apps']:
587 if app == app_name:
588 log_test.info('%s app is being installed'%app)
589 app_status = True
590 if app_status is not True:
591 log_test.info('%s app is not being installed'%app_name)
592 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000593
Thangavelu K S905e5482017-09-12 06:48:02 -0700594 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000595 mac = self.get_mac(iface)
596 onos_netcfg = OnosCtrl.get_config()
597 app_status = False
598 app_name = 'org.opencord.sadis'
599 for app in onos_netcfg['apps']:
600 if app == app_name:
601 log_test.info('%s app is being installed'%app)
602 app_status = True
603 if app_status is not True:
604 log_test.info('%s app is not being installed'%app_name)
605 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000606
Thangavelu K S905e5482017-09-12 06:48:02 -0700607 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000608 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700609 onos_netcfg = OnosCtrl.get_config()
610 app_status = False
611 app_name = 'org.opencord.dhcpl2relay'
612 for app in onos_netcfg['apps']:
613 if app == app_name:
614 log_test.info('%s app is being installed'%app)
615 if onos_netcfg['apps'][app_name] == {}:
616 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
617 else:
618 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
619 app_status = True
620 if app_status is not True:
621 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
622 assert_equal(True, False)
623
624 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
625 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000626 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])
634 else:
635 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
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 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000640
Thangavelu K S905e5482017-09-12 06:48:02 -0700641 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
642 relay_device_map = '{}/{}'.format(self.relay_device_id, self.relay_interface_port)
643 relay_device_map1 = '{}/1'.format(self.relay_device_id)
644 relay_device_map2 = '{}/9'.format(self.relay_device_id)
645 relay_device_map3 = '{}/6'.format(self.relay_device_id)
646 relay_device_map4 = '{}/7'.format(self.relay_device_id)
647 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 +0000648 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700649 self.onos_delete_config(self.configs['relay_config'])
650 self.onos_load_config(self.default_onos_netcfg)
651 self.cord_l2_relay_load(dhcp_server_connectPoint = dhcp_server_array_connectPoints, delete = False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000652 onos_netcfg = OnosCtrl.get_config()
653 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -0700654 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +0000655 for app in onos_netcfg['apps']:
656 if app == app_name:
657 log_test.info('%s app is being installed'%app)
658 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700659 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000660 elif onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'] == dhcp_server_array_connectPoints:
Thangavelu K S905e5482017-09-12 06:48:02 -0700661 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'])
Thangavelu K S46063d02017-09-08 21:13:24 +0000662 app_status = True
663 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700664 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
665 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000666 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000667 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000668
Chetan Gaonker891302d2017-09-05 15:09:26 +0000669
Thangavelu K S905e5482017-09-12 06:48:02 -0700670 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000671 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700672 c_tag = 600
673 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
674 self.cord_sadis_load(sadis_info = invalid_sadis_info)
675 onos_netcfg = OnosCtrl.get_config()
676 app_status = False
677 app_name = 'org.opencord.sadis'
678 for app in onos_netcfg['apps']:
679 if app == app_name:
680 log_test.info('%s app is being installed'%app)
681 if onos_netcfg['apps'][app_name] == {}:
682 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
683 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
684 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']))
685 app_status = True
686 if app_status is not True:
687 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
688 assert_equal(True, False)
689 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
690 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
691 assert_equal(cip,None)
692
693 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
694 iterations = 15
695 for i in range(iterations):
696 self.onos_ctrl.deactivate()
697 time.sleep(3)
698 self.onos_ctrl.activate()
699 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
700 mac = self.get_mac(iface)
701 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
702 self.send_recv(mac=mac)
703
704 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
705 mac = self.get_mac(iface)
706 OnosCtrl.uninstall_app(self.sadis_app_file)
707 OnosCtrl(self.sadis_app).deactivate()
708 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
709 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
710 assert_equal(cip,None)
711
712 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
713 mac = self.get_mac(iface)
714 OnosCtrl.uninstall_app(self.sadis_app_file)
715 OnosCtrl(self.sadis_app).deactivate()
716 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
717 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
718 assert_equal(cip,None)
719 OnosCtrl.uninstall_app(self.sadis_app_file)
720 OnosCtrl(self.sadis_app).deactivate()
721 #self.onos_load_config(self.sadis_configs['relay_config'])
722 self.send_recv(mac=mac)
723
724 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
725 pass
726
727 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
728 pass
729
730 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
731 pass
732
733 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
734 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000735 subscriber_port_id = "uni-200"
736 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
737 self.cord_sadis_load(sadis_info = invalid_sadis_info)
738 onos_netcfg = OnosCtrl.get_config()
739 app_status = False
740 app_name = 'org.opencord.sadis'
741 for app in onos_netcfg['apps']:
742 if app == app_name:
743 log_test.info('%s app is being installed'%app)
744 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700745 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000746 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700747 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 +0000748 app_status = True
749 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700750 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
751
Thangavelu K S46063d02017-09-08 21:13:24 +0000752 assert_equal(True, False)
753 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
754 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
755 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000756
Thangavelu K S905e5482017-09-12 06:48:02 -0700757 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000758 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700759 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +0000760 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
761 self.cord_sadis_load(sadis_info = invalid_sadis_info)
762 onos_netcfg = OnosCtrl.get_config()
763 app_status = False
764 app_name = 'org.opencord.sadis'
765 for app in onos_netcfg['apps']:
766 if app == app_name:
767 log_test.info('%s app is being installed'%app)
768 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700769 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000770 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700771 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 +0000772 app_status = True
773 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700774 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000775 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
Thangavelu K S905e5482017-09-12 06:48:02 -0700780 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000781 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000782 s_tag = 600
783 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
784 self.cord_sadis_load(sadis_info = invalid_sadis_info)
785 onos_netcfg = OnosCtrl.get_config()
786 app_status = False
787 app_name = 'org.opencord.sadis'
788 for app in onos_netcfg['apps']:
789 if app == app_name:
790 log_test.info('%s app is being installed'%app)
791 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700792 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000793 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700794 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 +0000795 app_status = True
796 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700797 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000798 assert_equal(True, False)
799 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
800 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
801 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000802
Thangavelu K S905e5482017-09-12 06:48:02 -0700803 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000804 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000805 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
806 self.cord_sadis_load(sadis_info = invalid_sadis_info)
807 onos_netcfg = OnosCtrl.get_config()
808 app_status = False
809 app_name = 'org.opencord.sadis'
810 for app in onos_netcfg['apps']:
811 if app == app_name:
812 log_test.info('%s app is being installed'%app)
813 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700814 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000815 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700816 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 +0000817 app_status = True
818 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700819 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000820 assert_equal(True, False)
821 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
822 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
823 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000824
Thangavelu K S905e5482017-09-12 06:48:02 -0700825 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000826 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000827 nas_port_id = "uni-509"
828 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
829 self.cord_sadis_load(sadis_info = invalid_sadis_info)
830 onos_netcfg = OnosCtrl.get_config()
831 app_status = False
832 app_name = 'org.opencord.sadis'
833 for app in onos_netcfg['apps']:
834 if app == app_name:
835 log_test.info('%s app is being installed'%app)
836 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700837 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000838 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700839 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 +0000840 app_status = True
841 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700842 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000843 assert_equal(True, False)
844 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
845 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
846 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000847
Thangavelu K S905e5482017-09-12 06:48:02 -0700848 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000849 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000850 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
851 self.cord_sadis_load(sadis_info = invalid_sadis_info)
852 onos_netcfg = OnosCtrl.get_config()
853 app_status = False
854 app_name = 'org.opencord.sadis'
855 for app in onos_netcfg['apps']:
856 if app == app_name:
857 log_test.info('%s app is being installed'%app)
858 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700859 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000860 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700861 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 +0000862 app_status = True
863 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700864 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000865 assert_equal(True, False)
866 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
867 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
868 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000869
Thangavelu K S905e5482017-09-12 06:48:02 -0700870 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000871 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000872 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
873 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
874 self.cord_sadis_load(sadis_info = invalid_sadis_info)
875 onos_netcfg = OnosCtrl.get_config()
876 app_status = False
877 app_name = 'org.opencord.sadis'
878 for app in onos_netcfg['apps']:
879 if app == app_name:
880 log_test.info('%s app is being installed'%app)
881 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700882 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000883 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700884 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 +0000885 app_status = True
886 if app_status is not True:
887 assert_equal(True, False)
888 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
889 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
890 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000891
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000892 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
893 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000894 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
895 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
896 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000897 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000898
899 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
900 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000901 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
902 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
903 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000904 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000905
906 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
907 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000908 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
909 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
910 assert_equal(cip,None)
911 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
912
913 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
914 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700915 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000916 ip_map = {}
917 for i in range(requests):
918 #mac = RandMAC()._fix()
919 #log_test.info('mac is %s'%mac)
920 cip, sip = self.send_recv(update_seed = True)
921 if ip_map.has_key(cip):
922 log_test.info('IP %s given out multiple times' %cip)
923 assert_equal(False, ip_map.has_key(cip))
924 ip_map[cip] = sip
925 time.sleep(1)
926
927 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
928 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000929 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
930 cip, sip = self.send_recv(mac=mac)
931 log_test.info('Releasing ip %s to server %s' %(cip, sip))
932 assert_equal(self.dhcp.release(cip), True)
933 log_test.info('Triggering DHCP discover again after release')
934 cip2, sip2 = self.send_recv(mac=mac)
935 log_test.info('Verifying released IP was given back on rediscover')
936 assert_equal(cip, cip2)
937 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
938 assert_equal(self.dhcp.release(cip2), True)
939
940 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
941 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000942 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
943 ip_map = {}
944 for i in range(10):
945 cip, sip = self.send_recv(mac=mac, update_seed = True)
946 if ip_map.has_key(cip):
947 log_test.info('IP %s given out multiple times' %cip)
948 assert_equal(False, ip_map.has_key(cip))
949 ip_map[cip] = sip
950
951 for ip in ip_map.keys():
952 log_test.info('Releasing IP %s' %ip)
953 assert_equal(self.dhcp.release(ip), True)
954
955 ip_map2 = {}
956 log_test.info('Triggering DHCP discover again after release')
957 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
958 for i in range(len(ip_map.keys())):
959 cip, sip = self.send_recv(mac=mac, update_seed = True)
960 ip_map2[cip] = sip
961
962 log_test.info('Verifying released IPs were given back on rediscover')
963 if ip_map != ip_map2:
964 log_test.info('Map before release %s' %ip_map)
965 log_test.info('Map after release %s' %ip_map2)
966 assert_equal(ip_map, ip_map2)
967
968 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
969 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000970 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
971 log_test.info('Verifying 1 ')
972 count = 0
973 while True:
974 #mac = RandMAC()._fix()
975 cip, sip = self.send_recv(update_seed = True,validate = False)
976 if cip is None:
977 break
978 else:
979 count += 1
980 assert_equal(count,91)
981 log_test.info('Verifying 2 ')
982 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
983 assert_equal(cip, None)
984 assert_equal(sip, None)
985
986 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
987 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000988 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
989 cip, sip, mac, _ = self.dhcp.only_discover()
990 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
991 (cip, sip, mac) )
992 assert_not_equal(cip, None)
993 log_test.info('Triggering DHCP discover again.')
994 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
995 assert_equal(new_cip, cip)
996 log_test.info('got same ip to smae the client when sent discover again, as expected')
997
998 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
999 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001000 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1001 log_test.info('Sending DHCP discover and DHCP request.')
1002 cip, sip = self.send_recv(mac=mac)
1003 mac = self.dhcp.get_mac(cip)[0]
1004 log_test.info("Sending DHCP request again.")
1005 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1006 assert_equal(new_cip, cip)
1007 log_test.info('got same ip to smae the client when sent request again, as expected')
1008
1009 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
1010 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001011 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
1012 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1013 assert_equal(cip,self.dhcp.seed_ip)
1014 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
1015 (cip, sip, mac) )
1016
1017 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
1018 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001019 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
1020 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1021 assert_not_equal(cip,None)
1022 assert_not_equal(cip,self.dhcp.seed_ip)
1023 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
1024
1025 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
1026 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001027 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1028 cip, sip, mac, _ = self.dhcp.only_discover()
1029 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1030 (cip, sip, mac) )
1031 assert_not_equal(cip, None)
1032 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
1033 assert_equal(new_cip, None)
1034 log_test.info('server sent NAK packet when requested other IP than that server offered')
1035
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001036 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 +00001037 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001038 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
1039 self.dhcp.return_option = 'lease'
1040 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
1041 assert_equal(lval, lease_time)
1042 log_test.info('dhcp server offered IP address with client requested lease time')
1043
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001044 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001045 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001046 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1047 cip, sip, mac, _ = self.dhcp.only_discover()
1048 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1049 (cip, sip, mac) )
1050 assert_not_equal(cip, None)
1051 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1052 log_test.info('client rebooting...')
1053 os.system('ifconfig '+iface+' down')
1054 time.sleep(5)
1055 os.system('ifconfig '+iface+' up')
1056 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
1057 assert_equal(new_cip2, cip)
1058 log_test.info('client got same IP after reboot, as expected')
1059
1060
1061 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
1062 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001063 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1064 cip, sip, mac, _ = self.dhcp.only_discover()
1065 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1066 (cip, sip, mac) )
1067 assert_not_equal(cip, None)
1068 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1069 log_test.info('server rebooting...')
1070 self.tearDownClass()
1071 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1072 assert_equal(new_cip,None)
1073 self.setUpClass()
1074 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1075 assert_equal(new_cip, cip)
1076 log_test.info('client got same IP after server rebooted, as expected')
1077
1078 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
1079 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001080 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1081 self.dhcp.return_option = 'lease'
1082 log_test.info('Sending DHCP discover with lease time of 700')
1083 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
1084 assert_equal(lval,lease_time)
1085 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
1086 assert_equal(new_cip,cip)
1087 assert_not_equal(lval, lease_time) #Negative Test Case
1088 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
1089
1090 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
1091 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 cip, sip, mac, _ = self.dhcp.only_discover()
1094 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
1095 assert_equal(new_cip,cip)
1096 assert_equal(lval, lease_time)
1097 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
1098
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001099 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001100 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001101 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1102 cip, sip, mac, _ = self.dhcp.only_discover()
1103 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1104 (cip, sip, mac) )
1105 assert_not_equal(cip,None)
1106 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
1107 log_test.info('waiting for renew time..')
1108 time.sleep(lval)
1109 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
1110 assert_equal(latest_cip, cip)
1111 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1112
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001113 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001114 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001115 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1116 cip, sip, mac, _ = self.dhcp.only_discover()
1117 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1118 (cip, sip, mac) )
1119 assert_not_equal(cip,None)
1120 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1121 log_test.info('waiting for rebind time..')
1122 time.sleep(lval)
1123 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1124 assert_equal(latest_cip, cip)
1125 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1126
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001127 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001128 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001129 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1130 expected_subnet = '255.255.255.0'
1131 self.dhcp.return_option = 'subnet'
1132
1133 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
1134 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1135 (cip, sip, mac) )
1136 assert_equal(subnet_mask,expected_subnet)
1137 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1138
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001139 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001140 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001141 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1142
1143 cip, sip, mac, _ = self.dhcp.only_discover()
1144 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1145 (cip, sip, mac) )
1146 assert_not_equal(cip,None)
1147 self.dhcp.send_different_option = 'subnet'
1148 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1149 assert_equal(new_cip, cip)
1150 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1151
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001152 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001153 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001154 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1155 expected_router_address = '20.20.20.1'
1156 self.dhcp.return_option = 'router'
1157
1158 cip, sip, mac, router_address_value = self.dhcp.only_discover()
1159 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1160 (cip, sip, mac) )
1161 assert_equal(expected_router_address, router_address_value)
1162 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1163
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001164 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001165 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001166 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1167
1168 cip, sip, mac, _ = self.dhcp.only_discover()
1169 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1170 (cip, sip, mac) )
1171 assert_not_equal(cip,None)
1172 self.dhcp.send_different_option = 'router'
1173 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1174 assert_equal(new_cip, cip)
1175 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1176
1177 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1178 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001179 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1180 expected_broadcast_address = '192.168.1.255'
1181 self.dhcp.return_option = 'broadcast_address'
1182
1183 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
1184 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1185 (cip, sip, mac) )
1186 assert_equal(expected_broadcast_address, broadcast_address_value)
1187 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1188
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001189 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001190 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001191 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1192
1193 cip, sip, mac, _ = self.dhcp.only_discover()
1194 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1195 (cip, sip, mac) )
1196 assert_not_equal(cip,None)
1197 self.dhcp.send_different_option = 'broadcast_address'
1198 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1199 assert_equal(new_cip, cip)
1200 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1201
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001202 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001203 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001204 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1205 expected_dns_address = '192.168.1.1'
1206 self.dhcp.return_option = 'dns'
1207
1208 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1209 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1210 (cip, sip, mac) )
1211 assert_equal(expected_dns_address, dns_address_value)
1212 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1213
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001214 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001215 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001216 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1217
1218 cip, sip, mac, _ = self.dhcp.only_discover()
1219 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1220 (cip, sip, mac) )
1221 assert_not_equal(cip,None)
1222 self.dhcp.send_different_option = 'dns'
1223 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1224 assert_equal(new_cip, cip)
1225 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1226
1227
1228 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1229
1230 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001231 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001232 log_test.info("Statistics for run %d",i)
1233 log_test.info("----------------------------------------------------------------------------------")
1234 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1235 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1236 log_test.info("----------------------------------------------------------------------------------")
1237 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1238
1239 log_test.info("Final Statistics for total transactions")
1240 log_test.info("----------------------------------------------------------------------------------")
1241 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1242 log_test.info(" %d %d %d %d" %(self.transactions,
1243 self.total_success, self.total_failure, self.running_time))
1244 log_test.info("----------------------------------------------------------------------------------")
1245 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1246
1247 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1248
1249 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001250 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001251 log_test.info("Statistics for run %d",i)
1252 log_test.info("----------------------------------------------------------------------------------")
1253 log_test.info("No. of consecutive successful transactions Running Time ")
1254 log_test.info(" %d %d " %(self.ip_count, self.diff))
1255 log_test.info("----------------------------------------------------------------------------------")
1256 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1257 log_test.info("----------------------------------------------------------------------------------")
1258
1259 log_test.info("Final Statistics for total successful transactions")
1260 log_test.info("----------------------------------------------------------------------------------")
1261 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1262 log_test.info(" %d %d %d " %(self.transactions,
1263 self.total_success, self.running_time))
1264 log_test.info("----------------------------------------------------------------------------------")
1265 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1266 log_test.info("----------------------------------------------------------------------------------")
1267
1268 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1269
1270 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001271 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001272 log_test.info("----------------------------------------------------------------------------------")
1273 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1274 log_test.info("----------------------------------------------------------------------------------")
1275 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1276 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1277 log_test.info("----------------------------------------------------------------------------------")
1278 log_test.info("No. of clients per second in run %d:%f "
1279 %(i, self.transaction_count))
1280 log_test.info("----------------------------------------------------------------------------------")
1281 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1282 log_test.info("----------------------------------------------------------------------------------")
1283 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1284 log_test.info(" %d %d %d %d" %(self.transactions,
1285 self.total_success, self.total_failure, self.running_time))
1286 log_test.info("----------------------------------------------------------------------------------")
1287 log_test.info("Average no. of clients per second: %d ",
1288 round(self.transactions/self.running_time,0))
1289 log_test.info("----------------------------------------------------------------------------------")
1290
1291 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1292
1293 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001294 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001295 log_test.info("----------------------------------------------------------------------------------")
1296 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1297 log_test.info("----------------------------------------------------------------------------------")
1298 log_test.info("No. of consecutive successful transactions Running Time ")
1299 log_test.info(" %d %d " %(self.ip_count, self.diff))
1300 log_test.info("----------------------------------------------------------------------------------")
1301 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1302 log_test.info("----------------------------------------------------------------------------------")
1303
1304 log_test.info("Final Statistics for total successful transactions")
1305 log_test.info("----------------------------------------------------------------------------------")
1306 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1307 log_test.info(" %d %d %d " %(self.transactions,
1308 self.total_success, self.running_time))
1309 log_test.info("----------------------------------------------------------------------------------")
1310 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1311 log_test.info("----------------------------------------------------------------------------------")
1312
1313 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001314 for key in (key for key in g_subscriber_port_map if key < 100):
1315 self.host_load(g_subscriber_port_map[key])
1316
1317 def thread_fun(i):
1318 mac = self.get_mac('veth{}'.format(i))
1319 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1320 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1321 self.lock.acquire()
1322
1323 if cip:
1324 self.ip_count += 1
1325
1326 elif cip is None:
1327 self.failure_count += 1
1328
1329 self.lock.notify_all()
1330 self.lock.release()
1331
1332 for i in range (1,4):
1333 self.ip_count = 0
1334 self.failure_count = 0
1335 self.start_time = 0
1336 self.diff = 0
1337 self.transaction_count = 0
1338 self.start_time = time.time()
1339
1340 while self.diff <= 60:
1341 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1342 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1343 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1344 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1345 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1346 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1347
1348 t.start()
1349 t1.start()
1350 t2.start()
1351 t3.start()
1352 t4.start()
1353 t5.start()
1354
1355 t.join()
1356 t1.join()
1357 t2.join()
1358 t3.join()
1359 t4.join()
1360 t5.join()
1361
1362 self.diff = round(time.time() - self.start_time, 0)
1363
1364 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1365
1366 self.transactions += (self.ip_count+self.failure_count)
1367 self.running_time += self.diff
1368 self.total_success += self.ip_count
1369 self.total_failure += self.failure_count
1370
1371
1372 log_test.info("----------------------------------------------------------------------------------")
1373 log_test.info("Statistics for run %d",i)
1374 log_test.info("----------------------------------------------------------------------------------")
1375 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1376 log_test.info(" %d %d %d %d"
1377 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1378 log_test.info("----------------------------------------------------------------------------------")
1379 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1380 log_test.info("----------------------------------------------------------------------------------")
1381
1382 log_test.info("----------------------------------------------------------------------------------")
1383 log_test.info("Final Statistics for total transactions")
1384 log_test.info("----------------------------------------------------------------------------------")
1385 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1386 log_test.info(" %d %d %d %d" %(self.transactions,
1387 self.total_success, self.total_failure, self.running_time))
1388
1389 log_test.info("----------------------------------------------------------------------------------")
1390 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1391 log_test.info("----------------------------------------------------------------------------------")
1392
1393 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001394 failure_dir = {}
1395
1396 for key in (key for key in g_subscriber_port_map if key != 100):
1397 self.host_load(g_subscriber_port_map[key])
1398
1399 def thread_fun(i, j):
1400# log_test.info("Thread Name:%s",current_thread().name)
1401# failure_dir[current_thread().name] = True
1402 while failure_dir.has_key(current_thread().name) is False:
1403 mac = RandMAC()._fix()
1404 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1405 i += 2
1406 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1407 self.lock.acquire()
1408
1409 if cip:
1410 self.ip_count += 1
1411 self.lock.notify_all()
1412 self.lock.release()
1413 elif cip is None:
1414 self.failure_count += 1
1415 failure_dir[current_thread().name] = True
1416 self.lock.notify_all()
1417 self.lock.release()
1418 break
1419# self.lock.notify_all()
1420# self.lock.release()
1421
1422 for i in range (1,4):
1423 failure_dir = {}
1424 self.ip_count = 0
1425 self.failure_count = 0
1426 self.start_time = 0
1427 self.diff = 0
1428 self.transaction_count = 0
1429 self.start_time = time.time()
1430
1431 while len(failure_dir) != 6:
1432 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1433 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1434 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1435 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1436 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1437 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1438
1439 t.start()
1440 t1.start()
1441 t2.start()
1442 t3.start()
1443 t4.start()
1444 t5.start()
1445
1446 t.join()
1447 t1.join()
1448 t2.join()
1449 t3.join()
1450 t4.join()
1451 t5.join()
1452
1453 self.diff = round(time.time() - self.start_time, 0)
1454 self.transaction_count = round((self.ip_count)/self.diff, 2)
1455
1456 self.transactions += (self.ip_count+self.failure_count)
1457 self.running_time += self.diff
1458 self.total_success += self.ip_count
1459 self.total_failure += self.failure_count
1460
1461
1462 log_test.info("Statistics for run %d",i)
1463 log_test.info("----------------------------------------------------------------------------------")
1464 log_test.info("No. of consecutive successful transactions Running Time ")
1465 log_test.info(" %d %d " %(self.ip_count, self.diff))
1466 log_test.info("----------------------------------------------------------------------------------")
1467 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1468 log_test.info("----------------------------------------------------------------------------------")
1469
1470 log_test.info("Final Statistics for total successful transactions")
1471 log_test.info("----------------------------------------------------------------------------------")
1472 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1473 log_test.info(" %d %d %d " %(self.transactions,
1474 self.total_success, self.running_time))
1475 log_test.info("----------------------------------------------------------------------------------")
1476 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1477 log_test.info("----------------------------------------------------------------------------------")
1478
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001479 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001480 for key in (key for key in g_subscriber_port_map if key < 100):
1481 self.host_load(g_subscriber_port_map[key])
1482
1483 def thread_fun(i):
1484# mac = self.get_mac('veth{}'.format(i))
1485 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1486 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1487 self.lock.acquire()
1488
1489 if cip:
1490 self.ip_count += 1
1491 elif cip is None:
1492 self.failure_count += 1
1493
1494 self.lock.notify_all()
1495 self.lock.release()
1496
1497 for i in range (1,4):
1498 self.ip_count = 0
1499 self.failure_count = 0
1500 self.start_time = 0
1501 self.diff = 0
1502 self.transaction_count = 0
1503 self.start_time = time.time()
1504
1505 while self.diff <= 60:
1506 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1507 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1508 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1509 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1510 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1511 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1512
1513 t.start()
1514 t1.start()
1515 t2.start()
1516 t3.start()
1517 t4.start()
1518 t5.start()
1519
1520 t.join()
1521 t1.join()
1522 t2.join()
1523 t3.join()
1524 t4.join()
1525 t5.join()
1526
1527 self.diff = round(time.time() - self.start_time, 0)
1528 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1529 self.transactions += (self.ip_count+self.failure_count)
1530 self.running_time += self.diff
1531 self.total_success += self.ip_count
1532 self.total_failure += self.failure_count
1533
1534 log_test.info("----------------------------------------------------------------------------------")
1535 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1536 log_test.info("----------------------------------------------------------------------------------")
1537 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1538 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1539 log_test.info("----------------------------------------------------------------------------------")
1540 log_test.info("No. of clients per second in run %d:%f "
1541 %(i, self.transaction_count))
1542 log_test.info("----------------------------------------------------------------------------------")
1543
1544 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1545 log_test.info("----------------------------------------------------------------------------------")
1546 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1547 log_test.info(" %d %d %d %d" %(self.transactions,
1548 self.total_success, self.total_failure, self.running_time))
1549 log_test.info("----------------------------------------------------------------------------------")
1550 log_test.info("Average no. of clients per second: %d ",
1551 round(self.transactions/self.running_time,0))
1552 log_test.info("----------------------------------------------------------------------------------")
1553
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001554 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001555 mac = self.get_mac(iface)
1556 self.host_load(iface)
1557 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1558 cip, sip, mac, _ = self.dhcp.only_discover()
1559 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1560 (cip, sip, mac) )
1561 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1562 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1563 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1564 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1565 (new_cip, new_sip, new_mac) )
1566 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1567 log_test.info("Now sending DHCP Request for old DHCP discover.")
1568 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1569 if new_cip is None:
1570 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1571 %(new_cip, new_sip, new_mac) )
1572 elif new_cip:
1573 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.'
1574 %(new_cip, new_sip, new_mac, new_cip) )
1575 assert_equal(new_cip, None)