blob: 10bd78ae581e1912a63173bffe34306cb222aa84 [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):
A R Karthick53735662017-10-05 12:53:35 -0700381 ##read the current config
382 current_netcfg = OnosCtrl.get_config()
383 connect_points = set([])
384 try:
385 connect_points = set(current_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints'])
386 except KeyError, e:
387 pass
388
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700389 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
A R Karthickc0a008f2017-10-04 18:35:25 -0700390 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700391 #### We have to work on later versions by removing these hard coded values
Thangavelu K S905e5482017-09-12 06:48:02 -0700392 if dhcp_server_connectPoint is None:
A R Karthick53735662017-10-05 12:53:35 -0700393 connect_points.add(relay_device_map)
394 else:
395 cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint)
396 connect_points = list(connect_points)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700397 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
A R Karthick53735662017-10-05 12:53:35 -0700398 {"dhcpServerConnectPoints": connect_points}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000399 }
400 }
401 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700402 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700403 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700404 if delete == False:
405 cls.onos_load_config(dhcp_dict)
406 else:
407 cls.onos_delete_config(dhcp_dict)
408 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000409 cls.configs['relay_config'] = dhcp_dict
410
411 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700412 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000413 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700414 device_details = OnosCtrl.get_devices()
415 if device_details is not None:
416 for device in device_details:
417 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
418 if device['available'] is True and device['driver'] == 'pmc-olt':
419 cls.olt_serial_id = "{}".format(device['serial'])
420 else:
421 cls.olt_serial_id = " "
422 else:
423 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')
424 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700425 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000426 "org.opencord.sadis": {
427 "sadis": {
428 "integration": {
429 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700430 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000431 "maxsize": 50,
432 "ttl": "PT1m"
433 }
434 },
435 "entries": [{
436 "id": "uni-254",
437 "cTag": 202,
438 "sTag": 222,
439 "nasPortId": "uni-254"
440 },
441 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700442 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700443 "hardwareIdentifier": "00:0c:e2:31:05:00",
444 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000445 "nasId": "B100-NASID"
446 }
447 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700448 }
449 }
450 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000451 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700452 #OnosCtrl.uninstall_app(cls.olt_app_file)
453 OnosCtrl.install_app(cls.olt_app_file)
454 time.sleep(5)
455 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700456 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700457 if sadis_info:
458 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000459 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700460 cls.sadis_configs['relay_config'] = sadis_dict
461
462 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):
463 ### Need to work on these hard coded values on later merges
464 if subscriber_port_id is None:
465 subscriber_port_id = "uni-254"
466 if c_tag is None:
467 c_tag = 202
468 if s_tag is None:
469 s_tag = 222
470 if nas_port_id is None:
471 nas_port_id = "uni-254"
472 if olt_serial_id is None:
473 olt_serial_id = self.olt_serial_id
474 if olt_mac is None:
475 olt_mac = "00:0c:e2:31:05:00"
476 if olt_ip is None:
477 olt_ip = "172.17.0.1"
478 if olt_nas_id is None:
479 olt_nas_id = "B100-NASID"
480 sadis_dict = { "apps": {
481 "org.opencord.sadis": {
482 "sadis": {
483 "integration": {
484 "cache": {
485 "enabled": "true",
486 "maxsize": 50,
487 "ttl": "PT1m"
488 }
489 },
490 "entries": [{
491 "id": subscriber_port_id,
492 "cTag": c_tag,
493 "sTag": s_tag,
494 "nasPortId": nas_port_id
495 },
496 {
497 "id": olt_serial_id,
498 "hardwareIdentifier": olt_mac,
499 "ipAddress": olt_ip,
500 "nasId": olt_nas_id
501 }
502 ]
503 }
504 }
505 }
506 }
507 return sadis_dict
508
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000509
510 @classmethod
511 def get_host_ip(cls, port):
512 if cls.host_ip_map.has_key(port):
513 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700514 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000515 return cls.host_ip_map[port]
516
517 @classmethod
518 def host_load(cls, iface):
519 '''Have ONOS discover the hosts for dhcp-relay responses'''
520 port = g_subscriber_port_map[iface]
521 host = '173.17.1.{}'.format(port)
522 cmds = ( 'ifconfig {} 0'.format(iface),
523 'ifconfig {0} {1}'.format(iface, host),
524 'arping -I {0} {1} -c 2'.format(iface, host),
525 'ifconfig {} 0'.format(iface), )
526 for c in cmds:
527 os.system(c)
528
529 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000530 def get_mac(cls, iface):
531 if cls.interface_to_mac_map.has_key(iface):
532 return cls.interface_to_mac_map[iface]
533 mac = get_mac(iface, pad = 0)
534 cls.interface_to_mac_map[iface] = mac
535 return mac
536
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000537 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000538
539 self.ip_count = 0
540 self.failure_count = 0
541 self.start_time = 0
542 self.diff = 0
543 self.transaction_count = 0
544
545 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000546 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
547 self.start_time = time.time()
548
549 while self.diff <= 60:
550
551 if only_discover:
552 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
553 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
554 (cip, sip, mac))
555 else:
556 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
557
558 if cip:
559 self.ip_count +=1
560 elif cip == None:
561 self.failure_count += 1
562 log_test.info('Failed to get ip')
563 if success_rate and self.ip_count > 0:
564 break
565
566 self.diff = round(time.time() - self.start_time, 0)
567
568 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
569 self.transactions += (self.ip_count+self.failure_count)
570 self.running_time += self.diff
571 self.total_success += self.ip_count
572 self.total_failure += self.failure_count
573
574 def send_recv(self, mac=None, update_seed = False, validate = True):
575 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
576 if validate:
577 assert_not_equal(cip, None)
578 assert_not_equal(sip, None)
579 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
580 (cip, sip, self.dhcp.get_mac(cip)[0]))
581 return cip,sip
582
A R Karthickc0a008f2017-10-04 18:35:25 -0700583 def test_dhcpl2relay_initialize(self):
584 '''Setup and configure the DHCP L2 relay app'''
585 pass
586
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000587 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
588 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000589 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
590 self.send_recv(mac=mac)
591
Thangavelu K S905e5482017-09-12 06:48:02 -0700592 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000593 mac = self.get_mac(iface)
594 onos_netcfg = OnosCtrl.get_config()
595 app_status = False
596 app_name = 'org.opencord.dhcpl2relay'
597 for app in onos_netcfg['apps']:
598 if app == app_name:
599 log_test.info('%s app is being installed'%app)
600 app_status = True
601 if app_status is not True:
602 log_test.info('%s app is not being installed'%app_name)
603 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000604
Thangavelu K S905e5482017-09-12 06:48:02 -0700605 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000606 mac = self.get_mac(iface)
607 onos_netcfg = OnosCtrl.get_config()
608 app_status = False
609 app_name = 'org.opencord.sadis'
610 for app in onos_netcfg['apps']:
611 if app == app_name:
612 log_test.info('%s app is being installed'%app)
613 app_status = True
614 if app_status is not True:
615 log_test.info('%s app is not being installed'%app_name)
616 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000617
Thangavelu K S905e5482017-09-12 06:48:02 -0700618 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000619 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700620 onos_netcfg = OnosCtrl.get_config()
621 app_status = False
622 app_name = 'org.opencord.dhcpl2relay'
623 for app in onos_netcfg['apps']:
624 if app == app_name:
625 log_test.info('%s app is being installed'%app)
626 if onos_netcfg['apps'][app_name] == {}:
627 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
628 else:
629 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
630 app_status = True
631 if app_status is not True:
632 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
633 assert_equal(True, False)
634
635 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
636 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000637 onos_netcfg = OnosCtrl.get_config()
638 app_status = False
639 app_name = 'org.opencord.sadis'
640 for app in onos_netcfg['apps']:
641 if app == app_name:
642 log_test.info('%s app is being installed'%app)
643 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700644 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
645 else:
646 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
Thangavelu K S46063d02017-09-08 21:13:24 +0000647 app_status = True
648 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700649 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
650 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000651
Thangavelu K S905e5482017-09-12 06:48:02 -0700652 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
653 relay_device_map = '{}/{}'.format(self.relay_device_id, self.relay_interface_port)
654 relay_device_map1 = '{}/1'.format(self.relay_device_id)
655 relay_device_map2 = '{}/9'.format(self.relay_device_id)
656 relay_device_map3 = '{}/6'.format(self.relay_device_id)
657 relay_device_map4 = '{}/7'.format(self.relay_device_id)
658 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 +0000659 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700660 self.onos_delete_config(self.configs['relay_config'])
661 self.onos_load_config(self.default_onos_netcfg)
662 self.cord_l2_relay_load(dhcp_server_connectPoint = dhcp_server_array_connectPoints, delete = False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000663 onos_netcfg = OnosCtrl.get_config()
664 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -0700665 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +0000666 for app in onos_netcfg['apps']:
667 if app == app_name:
668 log_test.info('%s app is being installed'%app)
669 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700670 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000671 elif onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'] == dhcp_server_array_connectPoints:
Thangavelu K S905e5482017-09-12 06:48:02 -0700672 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'])
Thangavelu K S46063d02017-09-08 21:13:24 +0000673 app_status = True
674 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700675 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
676 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000677 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000678 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000679
Chetan Gaonker891302d2017-09-05 15:09:26 +0000680
Thangavelu K S905e5482017-09-12 06:48:02 -0700681 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000682 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700683 c_tag = 600
684 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
685 self.cord_sadis_load(sadis_info = invalid_sadis_info)
686 onos_netcfg = OnosCtrl.get_config()
687 app_status = False
688 app_name = 'org.opencord.sadis'
689 for app in onos_netcfg['apps']:
690 if app == app_name:
691 log_test.info('%s app is being installed'%app)
692 if onos_netcfg['apps'][app_name] == {}:
693 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
694 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
695 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']))
696 app_status = True
697 if app_status is not True:
698 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
699 assert_equal(True, False)
700 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
701 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
702 assert_equal(cip,None)
703
704 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
705 iterations = 15
706 for i in range(iterations):
707 self.onos_ctrl.deactivate()
708 time.sleep(3)
709 self.onos_ctrl.activate()
710 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
711 mac = self.get_mac(iface)
712 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
713 self.send_recv(mac=mac)
714
715 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
716 mac = self.get_mac(iface)
717 OnosCtrl.uninstall_app(self.sadis_app_file)
718 OnosCtrl(self.sadis_app).deactivate()
719 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
720 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
721 assert_equal(cip,None)
722
723 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
724 mac = self.get_mac(iface)
725 OnosCtrl.uninstall_app(self.sadis_app_file)
726 OnosCtrl(self.sadis_app).deactivate()
727 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
728 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
729 assert_equal(cip,None)
730 OnosCtrl.uninstall_app(self.sadis_app_file)
731 OnosCtrl(self.sadis_app).deactivate()
732 #self.onos_load_config(self.sadis_configs['relay_config'])
733 self.send_recv(mac=mac)
734
735 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
736 pass
737
738 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
739 pass
740
741 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
742 pass
743
744 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
745 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000746 subscriber_port_id = "uni-200"
747 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
748 self.cord_sadis_load(sadis_info = invalid_sadis_info)
749 onos_netcfg = OnosCtrl.get_config()
750 app_status = False
751 app_name = 'org.opencord.sadis'
752 for app in onos_netcfg['apps']:
753 if app == app_name:
754 log_test.info('%s app is being installed'%app)
755 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700756 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000757 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700758 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 +0000759 app_status = True
760 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700761 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
762
Thangavelu K S46063d02017-09-08 21:13:24 +0000763 assert_equal(True, False)
764 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
765 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
766 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000767
Thangavelu K S905e5482017-09-12 06:48:02 -0700768 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000769 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700770 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +0000771 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
772 self.cord_sadis_load(sadis_info = invalid_sadis_info)
773 onos_netcfg = OnosCtrl.get_config()
774 app_status = False
775 app_name = 'org.opencord.sadis'
776 for app in onos_netcfg['apps']:
777 if app == app_name:
778 log_test.info('%s app is being installed'%app)
779 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700780 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000781 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700782 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 +0000783 app_status = True
784 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700785 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000786 assert_equal(True, False)
787 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
788 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
789 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000790
Thangavelu K S905e5482017-09-12 06:48:02 -0700791 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000792 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000793 s_tag = 600
794 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
795 self.cord_sadis_load(sadis_info = invalid_sadis_info)
796 onos_netcfg = OnosCtrl.get_config()
797 app_status = False
798 app_name = 'org.opencord.sadis'
799 for app in onos_netcfg['apps']:
800 if app == app_name:
801 log_test.info('%s app is being installed'%app)
802 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700803 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000804 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700805 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 +0000806 app_status = True
807 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700808 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000809 assert_equal(True, False)
810 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
811 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
812 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000813
Thangavelu K S905e5482017-09-12 06:48:02 -0700814 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000815 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000816 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
817 self.cord_sadis_load(sadis_info = invalid_sadis_info)
818 onos_netcfg = OnosCtrl.get_config()
819 app_status = False
820 app_name = 'org.opencord.sadis'
821 for app in onos_netcfg['apps']:
822 if app == app_name:
823 log_test.info('%s app is being installed'%app)
824 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700825 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000826 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700827 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 +0000828 app_status = True
829 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700830 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000831 assert_equal(True, False)
832 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
833 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
834 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000835
Thangavelu K S905e5482017-09-12 06:48:02 -0700836 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000837 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000838 nas_port_id = "uni-509"
839 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
840 self.cord_sadis_load(sadis_info = invalid_sadis_info)
841 onos_netcfg = OnosCtrl.get_config()
842 app_status = False
843 app_name = 'org.opencord.sadis'
844 for app in onos_netcfg['apps']:
845 if app == app_name:
846 log_test.info('%s app is being installed'%app)
847 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700848 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000849 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700850 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 +0000851 app_status = True
852 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700853 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000854 assert_equal(True, False)
855 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
856 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
857 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000858
Thangavelu K S905e5482017-09-12 06:48:02 -0700859 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000860 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000861 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
862 self.cord_sadis_load(sadis_info = invalid_sadis_info)
863 onos_netcfg = OnosCtrl.get_config()
864 app_status = False
865 app_name = 'org.opencord.sadis'
866 for app in onos_netcfg['apps']:
867 if app == app_name:
868 log_test.info('%s app is being installed'%app)
869 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700870 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000871 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700872 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 +0000873 app_status = True
874 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700875 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000876 assert_equal(True, False)
877 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
878 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
879 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000880
Thangavelu K S905e5482017-09-12 06:48:02 -0700881 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000882 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000883 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
884 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
885 self.cord_sadis_load(sadis_info = invalid_sadis_info)
886 onos_netcfg = OnosCtrl.get_config()
887 app_status = False
888 app_name = 'org.opencord.sadis'
889 for app in onos_netcfg['apps']:
890 if app == app_name:
891 log_test.info('%s app is being installed'%app)
892 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700893 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000894 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700895 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 +0000896 app_status = True
897 if app_status is not True:
898 assert_equal(True, False)
899 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
900 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
901 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000902
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000903 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
904 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000905 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
906 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
907 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000908 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000909
910 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
911 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000912 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
913 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
914 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000915 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000916
917 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
918 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000919 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
920 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
921 assert_equal(cip,None)
922 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
923
924 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
925 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700926 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000927 ip_map = {}
928 for i in range(requests):
929 #mac = RandMAC()._fix()
930 #log_test.info('mac is %s'%mac)
931 cip, sip = self.send_recv(update_seed = True)
932 if ip_map.has_key(cip):
933 log_test.info('IP %s given out multiple times' %cip)
934 assert_equal(False, ip_map.has_key(cip))
935 ip_map[cip] = sip
936 time.sleep(1)
937
938 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
939 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000940 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
941 cip, sip = self.send_recv(mac=mac)
942 log_test.info('Releasing ip %s to server %s' %(cip, sip))
943 assert_equal(self.dhcp.release(cip), True)
944 log_test.info('Triggering DHCP discover again after release')
945 cip2, sip2 = self.send_recv(mac=mac)
946 log_test.info('Verifying released IP was given back on rediscover')
947 assert_equal(cip, cip2)
948 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
949 assert_equal(self.dhcp.release(cip2), True)
950
951 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
952 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000953 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
954 ip_map = {}
955 for i in range(10):
956 cip, sip = self.send_recv(mac=mac, update_seed = True)
957 if ip_map.has_key(cip):
958 log_test.info('IP %s given out multiple times' %cip)
959 assert_equal(False, ip_map.has_key(cip))
960 ip_map[cip] = sip
961
962 for ip in ip_map.keys():
963 log_test.info('Releasing IP %s' %ip)
964 assert_equal(self.dhcp.release(ip), True)
965
966 ip_map2 = {}
967 log_test.info('Triggering DHCP discover again after release')
968 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
969 for i in range(len(ip_map.keys())):
970 cip, sip = self.send_recv(mac=mac, update_seed = True)
971 ip_map2[cip] = sip
972
973 log_test.info('Verifying released IPs were given back on rediscover')
974 if ip_map != ip_map2:
975 log_test.info('Map before release %s' %ip_map)
976 log_test.info('Map after release %s' %ip_map2)
977 assert_equal(ip_map, ip_map2)
978
979 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
980 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000981 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
982 log_test.info('Verifying 1 ')
983 count = 0
984 while True:
985 #mac = RandMAC()._fix()
986 cip, sip = self.send_recv(update_seed = True,validate = False)
987 if cip is None:
988 break
989 else:
990 count += 1
991 assert_equal(count,91)
992 log_test.info('Verifying 2 ')
993 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
994 assert_equal(cip, None)
995 assert_equal(sip, None)
996
997 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
998 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000999 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1000 cip, sip, mac, _ = self.dhcp.only_discover()
1001 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
1002 (cip, sip, mac) )
1003 assert_not_equal(cip, None)
1004 log_test.info('Triggering DHCP discover again.')
1005 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
1006 assert_equal(new_cip, cip)
1007 log_test.info('got same ip to smae the client when sent discover again, as expected')
1008
1009 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
1010 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001011 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1012 log_test.info('Sending DHCP discover and DHCP request.')
1013 cip, sip = self.send_recv(mac=mac)
1014 mac = self.dhcp.get_mac(cip)[0]
1015 log_test.info("Sending DHCP request again.")
1016 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1017 assert_equal(new_cip, cip)
1018 log_test.info('got same ip to smae the client when sent request again, as expected')
1019
1020 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
1021 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001022 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
1023 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1024 assert_equal(cip,self.dhcp.seed_ip)
1025 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
1026 (cip, sip, mac) )
1027
1028 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
1029 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001030 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
1031 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1032 assert_not_equal(cip,None)
1033 assert_not_equal(cip,self.dhcp.seed_ip)
1034 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
1035
1036 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
1037 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001038 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1039 cip, sip, mac, _ = self.dhcp.only_discover()
1040 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1041 (cip, sip, mac) )
1042 assert_not_equal(cip, None)
1043 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
1044 assert_equal(new_cip, None)
1045 log_test.info('server sent NAK packet when requested other IP than that server offered')
1046
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001047 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 +00001048 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001049 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
1050 self.dhcp.return_option = 'lease'
1051 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
1052 assert_equal(lval, lease_time)
1053 log_test.info('dhcp server offered IP address with client requested lease time')
1054
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001055 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001056 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001057 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1058 cip, sip, mac, _ = self.dhcp.only_discover()
1059 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1060 (cip, sip, mac) )
1061 assert_not_equal(cip, None)
1062 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1063 log_test.info('client rebooting...')
1064 os.system('ifconfig '+iface+' down')
1065 time.sleep(5)
1066 os.system('ifconfig '+iface+' up')
1067 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
1068 assert_equal(new_cip2, cip)
1069 log_test.info('client got same IP after reboot, as expected')
1070
1071
1072 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
1073 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001074 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1075 cip, sip, mac, _ = self.dhcp.only_discover()
1076 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1077 (cip, sip, mac) )
1078 assert_not_equal(cip, None)
1079 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1080 log_test.info('server rebooting...')
1081 self.tearDownClass()
1082 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1083 assert_equal(new_cip,None)
1084 self.setUpClass()
1085 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1086 assert_equal(new_cip, cip)
1087 log_test.info('client got same IP after server rebooted, as expected')
1088
1089 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
1090 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001091 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1092 self.dhcp.return_option = 'lease'
1093 log_test.info('Sending DHCP discover with lease time of 700')
1094 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
1095 assert_equal(lval,lease_time)
1096 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
1097 assert_equal(new_cip,cip)
1098 assert_not_equal(lval, lease_time) #Negative Test Case
1099 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
1100
1101 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
1102 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001103 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1104 cip, sip, mac, _ = self.dhcp.only_discover()
1105 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
1106 assert_equal(new_cip,cip)
1107 assert_equal(lval, lease_time)
1108 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
1109
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001110 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001111 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001112 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1113 cip, sip, mac, _ = self.dhcp.only_discover()
1114 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1115 (cip, sip, mac) )
1116 assert_not_equal(cip,None)
1117 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
1118 log_test.info('waiting for renew time..')
1119 time.sleep(lval)
1120 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
1121 assert_equal(latest_cip, cip)
1122 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1123
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001124 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001125 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001126 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1127 cip, sip, mac, _ = self.dhcp.only_discover()
1128 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1129 (cip, sip, mac) )
1130 assert_not_equal(cip,None)
1131 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1132 log_test.info('waiting for rebind time..')
1133 time.sleep(lval)
1134 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1135 assert_equal(latest_cip, cip)
1136 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1137
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001138 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001139 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001140 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1141 expected_subnet = '255.255.255.0'
1142 self.dhcp.return_option = 'subnet'
1143
1144 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
1145 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1146 (cip, sip, mac) )
1147 assert_equal(subnet_mask,expected_subnet)
1148 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1149
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001150 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001151 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001152 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1153
1154 cip, sip, mac, _ = self.dhcp.only_discover()
1155 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1156 (cip, sip, mac) )
1157 assert_not_equal(cip,None)
1158 self.dhcp.send_different_option = 'subnet'
1159 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1160 assert_equal(new_cip, cip)
1161 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1162
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001163 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001164 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001165 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1166 expected_router_address = '20.20.20.1'
1167 self.dhcp.return_option = 'router'
1168
1169 cip, sip, mac, router_address_value = self.dhcp.only_discover()
1170 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1171 (cip, sip, mac) )
1172 assert_equal(expected_router_address, router_address_value)
1173 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1174
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001175 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001176 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001177 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1178
1179 cip, sip, mac, _ = self.dhcp.only_discover()
1180 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1181 (cip, sip, mac) )
1182 assert_not_equal(cip,None)
1183 self.dhcp.send_different_option = 'router'
1184 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1185 assert_equal(new_cip, cip)
1186 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1187
1188 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1189 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001190 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1191 expected_broadcast_address = '192.168.1.255'
1192 self.dhcp.return_option = 'broadcast_address'
1193
1194 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
1195 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1196 (cip, sip, mac) )
1197 assert_equal(expected_broadcast_address, broadcast_address_value)
1198 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1199
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001200 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001201 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001202 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1203
1204 cip, sip, mac, _ = self.dhcp.only_discover()
1205 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1206 (cip, sip, mac) )
1207 assert_not_equal(cip,None)
1208 self.dhcp.send_different_option = 'broadcast_address'
1209 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1210 assert_equal(new_cip, cip)
1211 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1212
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001213 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001214 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001215 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1216 expected_dns_address = '192.168.1.1'
1217 self.dhcp.return_option = 'dns'
1218
1219 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1220 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1221 (cip, sip, mac) )
1222 assert_equal(expected_dns_address, dns_address_value)
1223 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1224
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001225 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001226 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001227 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1228
1229 cip, sip, mac, _ = self.dhcp.only_discover()
1230 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1231 (cip, sip, mac) )
1232 assert_not_equal(cip,None)
1233 self.dhcp.send_different_option = 'dns'
1234 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1235 assert_equal(new_cip, cip)
1236 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1237
1238
1239 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1240
1241 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001242 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001243 log_test.info("Statistics for run %d",i)
1244 log_test.info("----------------------------------------------------------------------------------")
1245 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1246 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1247 log_test.info("----------------------------------------------------------------------------------")
1248 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1249
1250 log_test.info("Final Statistics for total transactions")
1251 log_test.info("----------------------------------------------------------------------------------")
1252 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1253 log_test.info(" %d %d %d %d" %(self.transactions,
1254 self.total_success, self.total_failure, self.running_time))
1255 log_test.info("----------------------------------------------------------------------------------")
1256 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1257
1258 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1259
1260 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001261 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001262 log_test.info("Statistics for run %d",i)
1263 log_test.info("----------------------------------------------------------------------------------")
1264 log_test.info("No. of consecutive successful transactions Running Time ")
1265 log_test.info(" %d %d " %(self.ip_count, self.diff))
1266 log_test.info("----------------------------------------------------------------------------------")
1267 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1268 log_test.info("----------------------------------------------------------------------------------")
1269
1270 log_test.info("Final Statistics for total successful transactions")
1271 log_test.info("----------------------------------------------------------------------------------")
1272 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1273 log_test.info(" %d %d %d " %(self.transactions,
1274 self.total_success, self.running_time))
1275 log_test.info("----------------------------------------------------------------------------------")
1276 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1277 log_test.info("----------------------------------------------------------------------------------")
1278
1279 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1280
1281 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001282 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001283 log_test.info("----------------------------------------------------------------------------------")
1284 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1285 log_test.info("----------------------------------------------------------------------------------")
1286 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1287 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1288 log_test.info("----------------------------------------------------------------------------------")
1289 log_test.info("No. of clients per second in run %d:%f "
1290 %(i, self.transaction_count))
1291 log_test.info("----------------------------------------------------------------------------------")
1292 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1293 log_test.info("----------------------------------------------------------------------------------")
1294 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1295 log_test.info(" %d %d %d %d" %(self.transactions,
1296 self.total_success, self.total_failure, self.running_time))
1297 log_test.info("----------------------------------------------------------------------------------")
1298 log_test.info("Average no. of clients per second: %d ",
1299 round(self.transactions/self.running_time,0))
1300 log_test.info("----------------------------------------------------------------------------------")
1301
1302 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1303
1304 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001305 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001306 log_test.info("----------------------------------------------------------------------------------")
1307 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1308 log_test.info("----------------------------------------------------------------------------------")
1309 log_test.info("No. of consecutive successful transactions Running Time ")
1310 log_test.info(" %d %d " %(self.ip_count, self.diff))
1311 log_test.info("----------------------------------------------------------------------------------")
1312 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1313 log_test.info("----------------------------------------------------------------------------------")
1314
1315 log_test.info("Final Statistics for total successful transactions")
1316 log_test.info("----------------------------------------------------------------------------------")
1317 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1318 log_test.info(" %d %d %d " %(self.transactions,
1319 self.total_success, self.running_time))
1320 log_test.info("----------------------------------------------------------------------------------")
1321 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1322 log_test.info("----------------------------------------------------------------------------------")
1323
1324 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001325 for key in (key for key in g_subscriber_port_map if key < 100):
1326 self.host_load(g_subscriber_port_map[key])
1327
1328 def thread_fun(i):
1329 mac = self.get_mac('veth{}'.format(i))
1330 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1331 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1332 self.lock.acquire()
1333
1334 if cip:
1335 self.ip_count += 1
1336
1337 elif cip is None:
1338 self.failure_count += 1
1339
1340 self.lock.notify_all()
1341 self.lock.release()
1342
1343 for i in range (1,4):
1344 self.ip_count = 0
1345 self.failure_count = 0
1346 self.start_time = 0
1347 self.diff = 0
1348 self.transaction_count = 0
1349 self.start_time = time.time()
1350
1351 while self.diff <= 60:
1352 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1353 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1354 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1355 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1356 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1357 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1358
1359 t.start()
1360 t1.start()
1361 t2.start()
1362 t3.start()
1363 t4.start()
1364 t5.start()
1365
1366 t.join()
1367 t1.join()
1368 t2.join()
1369 t3.join()
1370 t4.join()
1371 t5.join()
1372
1373 self.diff = round(time.time() - self.start_time, 0)
1374
1375 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1376
1377 self.transactions += (self.ip_count+self.failure_count)
1378 self.running_time += self.diff
1379 self.total_success += self.ip_count
1380 self.total_failure += self.failure_count
1381
1382
1383 log_test.info("----------------------------------------------------------------------------------")
1384 log_test.info("Statistics for run %d",i)
1385 log_test.info("----------------------------------------------------------------------------------")
1386 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1387 log_test.info(" %d %d %d %d"
1388 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1389 log_test.info("----------------------------------------------------------------------------------")
1390 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1391 log_test.info("----------------------------------------------------------------------------------")
1392
1393 log_test.info("----------------------------------------------------------------------------------")
1394 log_test.info("Final Statistics for total transactions")
1395 log_test.info("----------------------------------------------------------------------------------")
1396 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1397 log_test.info(" %d %d %d %d" %(self.transactions,
1398 self.total_success, self.total_failure, self.running_time))
1399
1400 log_test.info("----------------------------------------------------------------------------------")
1401 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1402 log_test.info("----------------------------------------------------------------------------------")
1403
1404 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001405 failure_dir = {}
1406
1407 for key in (key for key in g_subscriber_port_map if key != 100):
1408 self.host_load(g_subscriber_port_map[key])
1409
1410 def thread_fun(i, j):
1411# log_test.info("Thread Name:%s",current_thread().name)
1412# failure_dir[current_thread().name] = True
1413 while failure_dir.has_key(current_thread().name) is False:
1414 mac = RandMAC()._fix()
1415 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1416 i += 2
1417 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1418 self.lock.acquire()
1419
1420 if cip:
1421 self.ip_count += 1
1422 self.lock.notify_all()
1423 self.lock.release()
1424 elif cip is None:
1425 self.failure_count += 1
1426 failure_dir[current_thread().name] = True
1427 self.lock.notify_all()
1428 self.lock.release()
1429 break
1430# self.lock.notify_all()
1431# self.lock.release()
1432
1433 for i in range (1,4):
1434 failure_dir = {}
1435 self.ip_count = 0
1436 self.failure_count = 0
1437 self.start_time = 0
1438 self.diff = 0
1439 self.transaction_count = 0
1440 self.start_time = time.time()
1441
1442 while len(failure_dir) != 6:
1443 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1444 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1445 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1446 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1447 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1448 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1449
1450 t.start()
1451 t1.start()
1452 t2.start()
1453 t3.start()
1454 t4.start()
1455 t5.start()
1456
1457 t.join()
1458 t1.join()
1459 t2.join()
1460 t3.join()
1461 t4.join()
1462 t5.join()
1463
1464 self.diff = round(time.time() - self.start_time, 0)
1465 self.transaction_count = round((self.ip_count)/self.diff, 2)
1466
1467 self.transactions += (self.ip_count+self.failure_count)
1468 self.running_time += self.diff
1469 self.total_success += self.ip_count
1470 self.total_failure += self.failure_count
1471
1472
1473 log_test.info("Statistics for run %d",i)
1474 log_test.info("----------------------------------------------------------------------------------")
1475 log_test.info("No. of consecutive successful transactions Running Time ")
1476 log_test.info(" %d %d " %(self.ip_count, self.diff))
1477 log_test.info("----------------------------------------------------------------------------------")
1478 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1479 log_test.info("----------------------------------------------------------------------------------")
1480
1481 log_test.info("Final Statistics for total successful transactions")
1482 log_test.info("----------------------------------------------------------------------------------")
1483 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1484 log_test.info(" %d %d %d " %(self.transactions,
1485 self.total_success, self.running_time))
1486 log_test.info("----------------------------------------------------------------------------------")
1487 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1488 log_test.info("----------------------------------------------------------------------------------")
1489
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001490 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001491 for key in (key for key in g_subscriber_port_map if key < 100):
1492 self.host_load(g_subscriber_port_map[key])
1493
1494 def thread_fun(i):
1495# mac = self.get_mac('veth{}'.format(i))
1496 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1497 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1498 self.lock.acquire()
1499
1500 if cip:
1501 self.ip_count += 1
1502 elif cip is None:
1503 self.failure_count += 1
1504
1505 self.lock.notify_all()
1506 self.lock.release()
1507
1508 for i in range (1,4):
1509 self.ip_count = 0
1510 self.failure_count = 0
1511 self.start_time = 0
1512 self.diff = 0
1513 self.transaction_count = 0
1514 self.start_time = time.time()
1515
1516 while self.diff <= 60:
1517 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1518 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1519 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1520 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1521 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1522 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1523
1524 t.start()
1525 t1.start()
1526 t2.start()
1527 t3.start()
1528 t4.start()
1529 t5.start()
1530
1531 t.join()
1532 t1.join()
1533 t2.join()
1534 t3.join()
1535 t4.join()
1536 t5.join()
1537
1538 self.diff = round(time.time() - self.start_time, 0)
1539 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1540 self.transactions += (self.ip_count+self.failure_count)
1541 self.running_time += self.diff
1542 self.total_success += self.ip_count
1543 self.total_failure += self.failure_count
1544
1545 log_test.info("----------------------------------------------------------------------------------")
1546 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1547 log_test.info("----------------------------------------------------------------------------------")
1548 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1549 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1550 log_test.info("----------------------------------------------------------------------------------")
1551 log_test.info("No. of clients per second in run %d:%f "
1552 %(i, self.transaction_count))
1553 log_test.info("----------------------------------------------------------------------------------")
1554
1555 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1556 log_test.info("----------------------------------------------------------------------------------")
1557 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1558 log_test.info(" %d %d %d %d" %(self.transactions,
1559 self.total_success, self.total_failure, self.running_time))
1560 log_test.info("----------------------------------------------------------------------------------")
1561 log_test.info("Average no. of clients per second: %d ",
1562 round(self.transactions/self.running_time,0))
1563 log_test.info("----------------------------------------------------------------------------------")
1564
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001565 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001566 mac = self.get_mac(iface)
1567 self.host_load(iface)
1568 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1569 cip, sip, mac, _ = self.dhcp.only_discover()
1570 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1571 (cip, sip, mac) )
1572 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1573 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1574 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1575 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1576 (new_cip, new_sip, new_mac) )
1577 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1578 log_test.info("Now sending DHCP Request for old DHCP discover.")
1579 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1580 if new_cip is None:
1581 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1582 %(new_cip, new_sip, new_mac) )
1583 elif new_cip:
1584 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.'
1585 %(new_cip, new_sip, new_mac, new_cip) )
1586 assert_equal(new_cip, None)