blob: cbaeea83f3e1f0b57a7b97cc3a0fec42d42c3fb3 [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()
A R Karthick760d1382017-10-05 13:48:40 -0700161 return True
162
163 # dhcp_start_status = cls.dhcpd_start()
164 # if setup_for_relay and dhcp_start_status:
165 # return True
166 # return False
A R Karthickc0a008f2017-10-04 18:35:25 -0700167
168 @classmethod
169 def config_olt(cls, switch_map):
170 controller = get_controller()
171 auth = ('karaf', 'karaf')
172 #configure subscriber for every port on all the voltha devices
173 for device, device_map in switch_map.iteritems():
174 uni_ports = device_map['ports']
175 uplink_vlan = device_map['uplink_vlan']
176 for port in uni_ports:
177 vlan = port
178 rest_url = 'http://{}:8181/onos/olt/oltapp/{}/{}/{}'.format(controller,
179 device,
180 port,
181 vlan)
182 requests.post(rest_url, auth = auth)
183
184 @classmethod
185 def voltha_setup(cls):
186 s_tag_map = {}
187 #configure olt app to provision dhcp flows
188 cls.config_olt(cls.voltha_switch_map)
189 for switch, switch_map in cls.voltha_switch_map.iteritems():
190 s_tag_map[int(switch_map['uplink_vlan'])] = map(lambda p: int(p), switch_map['ports'])
191
192 cmd_list = []
193 relay_interface = cls.relay_interfaces[0]
194 cls.relay_vlan_map[relay_interface] = []
195 for s_tag, ports in s_tag_map.iteritems():
196 vlan_stag_intf = '{}.{}'.format(relay_interface, s_tag)
197 cmd = 'ip link add link %s name %s type vlan id %d' %(relay_interface, vlan_stag_intf, s_tag)
198 cmd_list.append(cmd)
199 cmd = 'ip link set %s up' %(vlan_stag_intf)
200 cmd_list.append(cmd)
201 for port in ports:
202 vlan_ctag_intf = '{}.{}.{}'.format(relay_interface, s_tag, port)
203 cmd = 'ip link add link %s name %s type vlan id %d' %(vlan_stag_intf, vlan_ctag_intf, port)
204 cmd_list.append(cmd)
205 cmd = 'ip link set %s up' %(vlan_ctag_intf)
206 cmd_list.append(cmd)
207 cls.relay_vlan_map[relay_interface].append(vlan_ctag_intf)
208 cls.relay_vlan_map[relay_interface].append(vlan_stag_intf)
209
210 for cmd in cmd_list:
211 log_test.info('Running command: %s' %cmd)
212 os.system(cmd)
213
214 cord_test_ovs_flow_add(cls.relay_interface_port)
215 for s_tag in s_tag_map.keys():
216 log_test.info('Configuring OVS flow for port %d, s_tag %d' %(cls.relay_interface_port, s_tag))
217 cord_test_ovs_flow_add(cls.relay_interface_port, s_tag)
218
219 @classmethod
220 def service_running(cls, pattern):
221 st, _ = getstatusoutput('pgrep -f "{}"'.format(pattern))
222 return True if st == 0 else False
223
224 @classmethod
225 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
226 subnet = default_subnet_config):
227 conf = ''
228 for k, v in config.items():
229 conf += '{} {};\n'.format(k, v)
230
231 opts = ''
232 for k, v in options:
233 opts += 'option {} {};\n'.format(k, v)
234
235 subnet_config = ''
236 for _, v in subnet:
237 subnet_config += '{}\n'.format(v)
238
239 return '{}{}{}'.format(conf, opts, subnet_config)
240
241 @classmethod
242 def dhcpd_start(cls, intf_list = None,
243 config = default_config, options = default_options,
244 subnet = default_subnet_config):
245 '''Start the dhcpd server by generating the conf file'''
246 if intf_list is None:
247 intf_list = cls.relay_interfaces
248 intf_list = list(intf_list)
249 ##stop dhcpd if already running
250 #cls.dhcpd_stop()
251 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
252 subnet = subnet)
253 ##first touch dhcpd.leases if it doesn't exist
254 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
255 if os.access(lease_file, os.F_OK) is False:
256 with open(lease_file, 'w') as fd: pass
257
258 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
259 with open(conf_file, 'w') as fd:
260 fd.write(dhcp_conf)
261
262 #now configure the dhcpd interfaces for various subnets
263 index = 0
264 intf_info = []
265 vlan_intf_list = []
266 for ip,_ in subnet:
267 vlan_intf = None
268 intf = intf_list[index]
269 if intf in cls.relay_vlan_map:
270 vlan_intf = cls.relay_vlan_map[intf][0]
271 vlan_intf_list.append(vlan_intf)
272 mac = cls.get_mac(intf)
273 intf_info.append((ip, mac))
274 index += 1
275 cmd = 'ifconfig {} {}'.format(intf, ip)
276 status = os.system(cmd)
277 if vlan_intf:
278 cmd = 'ifconfig {} {}'.format(vlan_intf, ip)
279 os.system(cmd)
280
281 intf_str = ','.join(intf_list)
282 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)
283 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
284 status = os.system(dhcpd_cmd)
285 vlan_intf_str = ','.join(vlan_intf_list)
286 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)
287 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
288 status = os.system(dhcpd_cmd)
289 if status > 255:
290 status = 1
291 else:
292 return False
293 time.sleep(3)
294 cls.relay_interfaces_last = cls.relay_interfaces
295 cls.relay_interfaces = intf_list
296 return True
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000297
298 @classmethod
299 def dhcp_l2_relay_setup(cls):
A R Karthickc0a008f2017-10-04 18:35:25 -0700300 device_details = OnosCtrl.get_devices(mfr = 'Nicira')
Thangavelu K S905e5482017-09-12 06:48:02 -0700301 if device_details is not None:
A R Karthickc0a008f2017-10-04 18:35:25 -0700302 did_ovs = device_details[0]['id']
Thangavelu K S905e5482017-09-12 06:48:02 -0700303 else:
304 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')
305 return False
306 cls.relay_device_id = did_ovs
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000307 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
308 cls.port_map, _ = cls.olt.olt_port_map()
309 if cls.port_map:
310 ##Per subscriber, we use 1 relay port
311 try:
312 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
313 except:
314 relay_port = cls.port_map['uplink']
315 cls.relay_interface_port = relay_port
316 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
317 else:
318 cls.relay_interface_port = 100
319 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
320 cls.relay_interfaces_last = cls.relay_interfaces
321 if cls.port_map:
322 ##generate a ip/mac client virtual interface config for onos
323 interface_list = []
324 for port in cls.port_map['ports']:
325 port_num = cls.port_map[port]
326 if port_num == cls.port_map['uplink']:
327 continue
328 ip = cls.get_host_ip(port_num)
329 mac = cls.get_mac(port)
330 interface_list.append((port_num, ip, mac))
331
332 #configure dhcp server virtual interface on the same subnet as first client interface
333 relay_ip = cls.get_host_ip(interface_list[0][0])
334 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
335 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthickc0a008f2017-10-04 18:35:25 -0700336 cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000337
338 @classmethod
339 def dhcp_l2_relay_cleanup(cls):
340 ##reset the ONOS port configuration back to default
341 for config in cls.configs.items():
342 OnosCtrl.delete(config)
Thangavelu K S905e5482017-09-12 06:48:02 -0700343 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000344 # if cls.onos_restartable is True:
345 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
346 # return cord_test_onos_restart(config = {})
347
348 @classmethod
349 def onos_load_config(cls, config):
350 status, code = OnosCtrl.config(config)
351 if status is False:
352 log_test.info('JSON request returned status %d' %code)
353 assert_equal(status, True)
354 time.sleep(3)
355
356 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700357 def onos_delete_config(cls, config):
358 status, code = OnosCtrl.delete(config)
359 if status is False:
360 log_test.info('JSON request returned status %d' %code)
361 assert_equal(status, True)
362 time.sleep(3)
363
364 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000365 def onos_interface_load(cls, interface_list):
366 interface_dict = { 'ports': {} }
367 for port_num, ip, mac in interface_list:
368 port_map = interface_dict['ports']
369 port = '{}/{}'.format(cls.relay_device_id, port_num)
370 port_map[port] = { 'interfaces': [] }
371 interface_list = port_map[port]['interfaces']
372 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
373 'mac' : mac,
374 'name': 'vir-{}'.format(port_num)
375 }
376 interface_list.append(interface_map)
377
378 cls.onos_load_config(interface_dict)
379 cls.configs['interface_config'] = interface_dict
380
381 @classmethod
A R Karthickc0a008f2017-10-04 18:35:25 -0700382 def cord_l2_relay_load(cls, dhcp_server_connectPoint = None, delete = False):
A R Karthick53735662017-10-05 12:53:35 -0700383 ##read the current config
384 current_netcfg = OnosCtrl.get_config()
385 connect_points = set([])
386 try:
387 connect_points = set(current_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints'])
388 except KeyError, e:
389 pass
390
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700391 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
A R Karthickc0a008f2017-10-04 18:35:25 -0700392 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700393 #### We have to work on later versions by removing these hard coded values
Thangavelu K S905e5482017-09-12 06:48:02 -0700394 if dhcp_server_connectPoint is None:
A R Karthick8fe89a12017-10-05 13:12:13 -0700395 relay_device_present = filter(lambda cp: cp.split('/')[0] == cls.relay_device_id, connect_points)
396 if not relay_device_present:
397 connect_points.add(relay_device_map)
A R Karthick53735662017-10-05 12:53:35 -0700398 else:
399 cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint)
400 connect_points = list(connect_points)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700401 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
A R Karthick53735662017-10-05 12:53:35 -0700402 {"dhcpServerConnectPoints": connect_points}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000403 }
404 }
405 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700406 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700407 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700408 if delete == False:
409 cls.onos_load_config(dhcp_dict)
410 else:
411 cls.onos_delete_config(dhcp_dict)
412 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000413 cls.configs['relay_config'] = dhcp_dict
414
415 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700416 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000417 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700418 device_details = OnosCtrl.get_devices()
419 if device_details is not None:
420 for device in device_details:
421 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
422 if device['available'] is True and device['driver'] == 'pmc-olt':
423 cls.olt_serial_id = "{}".format(device['serial'])
424 else:
425 cls.olt_serial_id = " "
426 else:
427 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')
428 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700429 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000430 "org.opencord.sadis": {
431 "sadis": {
432 "integration": {
433 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700434 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000435 "maxsize": 50,
436 "ttl": "PT1m"
437 }
438 },
439 "entries": [{
440 "id": "uni-254",
441 "cTag": 202,
442 "sTag": 222,
443 "nasPortId": "uni-254"
444 },
445 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700446 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700447 "hardwareIdentifier": "00:0c:e2:31:05:00",
448 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000449 "nasId": "B100-NASID"
450 }
451 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700452 }
453 }
454 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000455 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700456 #OnosCtrl.uninstall_app(cls.olt_app_file)
457 OnosCtrl.install_app(cls.olt_app_file)
458 time.sleep(5)
459 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700460 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700461 if sadis_info:
462 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000463 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700464 cls.sadis_configs['relay_config'] = sadis_dict
465
466 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):
467 ### Need to work on these hard coded values on later merges
468 if subscriber_port_id is None:
469 subscriber_port_id = "uni-254"
470 if c_tag is None:
471 c_tag = 202
472 if s_tag is None:
473 s_tag = 222
474 if nas_port_id is None:
475 nas_port_id = "uni-254"
476 if olt_serial_id is None:
477 olt_serial_id = self.olt_serial_id
478 if olt_mac is None:
479 olt_mac = "00:0c:e2:31:05:00"
480 if olt_ip is None:
481 olt_ip = "172.17.0.1"
482 if olt_nas_id is None:
483 olt_nas_id = "B100-NASID"
484 sadis_dict = { "apps": {
485 "org.opencord.sadis": {
486 "sadis": {
487 "integration": {
488 "cache": {
489 "enabled": "true",
490 "maxsize": 50,
491 "ttl": "PT1m"
492 }
493 },
494 "entries": [{
495 "id": subscriber_port_id,
496 "cTag": c_tag,
497 "sTag": s_tag,
498 "nasPortId": nas_port_id
499 },
500 {
501 "id": olt_serial_id,
502 "hardwareIdentifier": olt_mac,
503 "ipAddress": olt_ip,
504 "nasId": olt_nas_id
505 }
506 ]
507 }
508 }
509 }
510 }
511 return sadis_dict
512
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000513
514 @classmethod
515 def get_host_ip(cls, port):
516 if cls.host_ip_map.has_key(port):
517 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700518 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000519 return cls.host_ip_map[port]
520
521 @classmethod
522 def host_load(cls, iface):
523 '''Have ONOS discover the hosts for dhcp-relay responses'''
524 port = g_subscriber_port_map[iface]
525 host = '173.17.1.{}'.format(port)
526 cmds = ( 'ifconfig {} 0'.format(iface),
527 'ifconfig {0} {1}'.format(iface, host),
528 'arping -I {0} {1} -c 2'.format(iface, host),
529 'ifconfig {} 0'.format(iface), )
530 for c in cmds:
531 os.system(c)
532
533 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000534 def get_mac(cls, iface):
535 if cls.interface_to_mac_map.has_key(iface):
536 return cls.interface_to_mac_map[iface]
537 mac = get_mac(iface, pad = 0)
538 cls.interface_to_mac_map[iface] = mac
539 return mac
540
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000541 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000542
543 self.ip_count = 0
544 self.failure_count = 0
545 self.start_time = 0
546 self.diff = 0
547 self.transaction_count = 0
548
549 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000550 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
551 self.start_time = time.time()
552
553 while self.diff <= 60:
554
555 if only_discover:
556 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
557 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
558 (cip, sip, mac))
559 else:
560 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
561
562 if cip:
563 self.ip_count +=1
564 elif cip == None:
565 self.failure_count += 1
566 log_test.info('Failed to get ip')
567 if success_rate and self.ip_count > 0:
568 break
569
570 self.diff = round(time.time() - self.start_time, 0)
571
572 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
573 self.transactions += (self.ip_count+self.failure_count)
574 self.running_time += self.diff
575 self.total_success += self.ip_count
576 self.total_failure += self.failure_count
577
578 def send_recv(self, mac=None, update_seed = False, validate = True):
579 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
580 if validate:
581 assert_not_equal(cip, None)
582 assert_not_equal(sip, None)
583 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
584 (cip, sip, self.dhcp.get_mac(cip)[0]))
585 return cip,sip
586
A R Karthickc0a008f2017-10-04 18:35:25 -0700587 def test_dhcpl2relay_initialize(self):
A R Karthick760d1382017-10-05 13:48:40 -0700588 '''Configure the DHCP L2 relay app and start dhcpd'''
589 self.dhcpd_start()
A R Karthickc0a008f2017-10-04 18:35:25 -0700590
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000591 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
592 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000593 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
594 self.send_recv(mac=mac)
595
Thangavelu K S905e5482017-09-12 06:48:02 -0700596 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000597 mac = self.get_mac(iface)
598 onos_netcfg = OnosCtrl.get_config()
599 app_status = False
600 app_name = 'org.opencord.dhcpl2relay'
601 for app in onos_netcfg['apps']:
602 if app == app_name:
603 log_test.info('%s app is being installed'%app)
604 app_status = True
605 if app_status is not True:
606 log_test.info('%s app is not being installed'%app_name)
607 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000608
Thangavelu K S905e5482017-09-12 06:48:02 -0700609 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000610 mac = self.get_mac(iface)
611 onos_netcfg = OnosCtrl.get_config()
612 app_status = False
613 app_name = 'org.opencord.sadis'
614 for app in onos_netcfg['apps']:
615 if app == app_name:
616 log_test.info('%s app is being installed'%app)
617 app_status = True
618 if app_status is not True:
619 log_test.info('%s app is not being installed'%app_name)
620 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000621
Thangavelu K S905e5482017-09-12 06:48:02 -0700622 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000623 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700624 onos_netcfg = OnosCtrl.get_config()
625 app_status = False
626 app_name = 'org.opencord.dhcpl2relay'
627 for app in onos_netcfg['apps']:
628 if app == app_name:
629 log_test.info('%s app is being installed'%app)
630 if onos_netcfg['apps'][app_name] == {}:
631 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
632 else:
633 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
634 app_status = True
635 if app_status is not True:
636 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
637 assert_equal(True, False)
638
639 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
640 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000641 onos_netcfg = OnosCtrl.get_config()
642 app_status = False
643 app_name = 'org.opencord.sadis'
644 for app in onos_netcfg['apps']:
645 if app == app_name:
646 log_test.info('%s app is being installed'%app)
647 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700648 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
649 else:
650 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
Thangavelu K S46063d02017-09-08 21:13:24 +0000651 app_status = True
652 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700653 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
654 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000655
Thangavelu K S905e5482017-09-12 06:48:02 -0700656 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
657 relay_device_map = '{}/{}'.format(self.relay_device_id, self.relay_interface_port)
658 relay_device_map1 = '{}/1'.format(self.relay_device_id)
659 relay_device_map2 = '{}/9'.format(self.relay_device_id)
660 relay_device_map3 = '{}/6'.format(self.relay_device_id)
661 relay_device_map4 = '{}/7'.format(self.relay_device_id)
662 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 +0000663 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700664 self.onos_delete_config(self.configs['relay_config'])
665 self.onos_load_config(self.default_onos_netcfg)
666 self.cord_l2_relay_load(dhcp_server_connectPoint = dhcp_server_array_connectPoints, delete = False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000667 onos_netcfg = OnosCtrl.get_config()
668 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -0700669 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +0000670 for app in onos_netcfg['apps']:
671 if app == app_name:
672 log_test.info('%s app is being installed'%app)
673 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700674 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000675 elif onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'] == dhcp_server_array_connectPoints:
Thangavelu K S905e5482017-09-12 06:48:02 -0700676 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'])
Thangavelu K S46063d02017-09-08 21:13:24 +0000677 app_status = True
678 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700679 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
680 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000681 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000682 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000683
Chetan Gaonker891302d2017-09-05 15:09:26 +0000684
Thangavelu K S905e5482017-09-12 06:48:02 -0700685 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000686 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700687 c_tag = 600
688 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
689 self.cord_sadis_load(sadis_info = invalid_sadis_info)
690 onos_netcfg = OnosCtrl.get_config()
691 app_status = False
692 app_name = 'org.opencord.sadis'
693 for app in onos_netcfg['apps']:
694 if app == app_name:
695 log_test.info('%s app is being installed'%app)
696 if onos_netcfg['apps'][app_name] == {}:
697 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
698 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
699 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']))
700 app_status = True
701 if app_status is not True:
702 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
703 assert_equal(True, False)
704 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
705 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
706 assert_equal(cip,None)
707
708 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
709 iterations = 15
710 for i in range(iterations):
711 self.onos_ctrl.deactivate()
712 time.sleep(3)
713 self.onos_ctrl.activate()
714 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
715 mac = self.get_mac(iface)
716 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
717 self.send_recv(mac=mac)
718
719 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
720 mac = self.get_mac(iface)
721 OnosCtrl.uninstall_app(self.sadis_app_file)
722 OnosCtrl(self.sadis_app).deactivate()
723 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
724 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
725 assert_equal(cip,None)
726
727 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
728 mac = self.get_mac(iface)
729 OnosCtrl.uninstall_app(self.sadis_app_file)
730 OnosCtrl(self.sadis_app).deactivate()
731 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
732 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
733 assert_equal(cip,None)
734 OnosCtrl.uninstall_app(self.sadis_app_file)
735 OnosCtrl(self.sadis_app).deactivate()
736 #self.onos_load_config(self.sadis_configs['relay_config'])
737 self.send_recv(mac=mac)
738
739 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
740 pass
741
742 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
743 pass
744
745 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
746 pass
747
748 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
749 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000750 subscriber_port_id = "uni-200"
751 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
752 self.cord_sadis_load(sadis_info = invalid_sadis_info)
753 onos_netcfg = OnosCtrl.get_config()
754 app_status = False
755 app_name = 'org.opencord.sadis'
756 for app in onos_netcfg['apps']:
757 if app == app_name:
758 log_test.info('%s app is being installed'%app)
759 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700760 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000761 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700762 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 +0000763 app_status = True
764 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700765 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
766
Thangavelu K S46063d02017-09-08 21:13:24 +0000767 assert_equal(True, False)
768 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
769 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
770 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000771
Thangavelu K S905e5482017-09-12 06:48:02 -0700772 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000773 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700774 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +0000775 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
776 self.cord_sadis_load(sadis_info = invalid_sadis_info)
777 onos_netcfg = OnosCtrl.get_config()
778 app_status = False
779 app_name = 'org.opencord.sadis'
780 for app in onos_netcfg['apps']:
781 if app == app_name:
782 log_test.info('%s app is being installed'%app)
783 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700784 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000785 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700786 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 +0000787 app_status = True
788 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700789 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000790 assert_equal(True, False)
791 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
792 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
793 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000794
Thangavelu K S905e5482017-09-12 06:48:02 -0700795 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000796 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000797 s_tag = 600
798 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
799 self.cord_sadis_load(sadis_info = invalid_sadis_info)
800 onos_netcfg = OnosCtrl.get_config()
801 app_status = False
802 app_name = 'org.opencord.sadis'
803 for app in onos_netcfg['apps']:
804 if app == app_name:
805 log_test.info('%s app is being installed'%app)
806 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700807 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000808 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700809 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 +0000810 app_status = True
811 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700812 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000813 assert_equal(True, False)
814 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
815 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
816 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000817
Thangavelu K S905e5482017-09-12 06:48:02 -0700818 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000819 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000820 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
821 self.cord_sadis_load(sadis_info = invalid_sadis_info)
822 onos_netcfg = OnosCtrl.get_config()
823 app_status = False
824 app_name = 'org.opencord.sadis'
825 for app in onos_netcfg['apps']:
826 if app == app_name:
827 log_test.info('%s app is being installed'%app)
828 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700829 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000830 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700831 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 +0000832 app_status = True
833 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700834 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000835 assert_equal(True, False)
836 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
837 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
838 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000839
Thangavelu K S905e5482017-09-12 06:48:02 -0700840 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000841 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000842 nas_port_id = "uni-509"
843 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
844 self.cord_sadis_load(sadis_info = invalid_sadis_info)
845 onos_netcfg = OnosCtrl.get_config()
846 app_status = False
847 app_name = 'org.opencord.sadis'
848 for app in onos_netcfg['apps']:
849 if app == app_name:
850 log_test.info('%s app is being installed'%app)
851 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700852 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000853 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700854 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 +0000855 app_status = True
856 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700857 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000858 assert_equal(True, False)
859 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
860 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
861 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000862
Thangavelu K S905e5482017-09-12 06:48:02 -0700863 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000864 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000865 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
866 self.cord_sadis_load(sadis_info = invalid_sadis_info)
867 onos_netcfg = OnosCtrl.get_config()
868 app_status = False
869 app_name = 'org.opencord.sadis'
870 for app in onos_netcfg['apps']:
871 if app == app_name:
872 log_test.info('%s app is being installed'%app)
873 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700874 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000875 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700876 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 +0000877 app_status = True
878 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700879 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000880 assert_equal(True, False)
881 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
882 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
883 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000884
Thangavelu K S905e5482017-09-12 06:48:02 -0700885 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000886 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000887 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
888 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
889 self.cord_sadis_load(sadis_info = invalid_sadis_info)
890 onos_netcfg = OnosCtrl.get_config()
891 app_status = False
892 app_name = 'org.opencord.sadis'
893 for app in onos_netcfg['apps']:
894 if app == app_name:
895 log_test.info('%s app is being installed'%app)
896 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700897 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000898 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700899 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 +0000900 app_status = True
901 if app_status is not True:
902 assert_equal(True, False)
903 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
904 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
905 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000906
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000907 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
908 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000909 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
910 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
911 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000912 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000913
914 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
915 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000916 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
917 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
918 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000919 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000920
921 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
922 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000923 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
924 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
925 assert_equal(cip,None)
926 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
927
928 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
929 mac = self.get_mac(iface)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700930 self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000931 ip_map = {}
932 for i in range(requests):
933 #mac = RandMAC()._fix()
934 #log_test.info('mac is %s'%mac)
935 cip, sip = self.send_recv(update_seed = True)
936 if ip_map.has_key(cip):
937 log_test.info('IP %s given out multiple times' %cip)
938 assert_equal(False, ip_map.has_key(cip))
939 ip_map[cip] = sip
940 time.sleep(1)
941
942 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
943 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000944 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
945 cip, sip = self.send_recv(mac=mac)
946 log_test.info('Releasing ip %s to server %s' %(cip, sip))
947 assert_equal(self.dhcp.release(cip), True)
948 log_test.info('Triggering DHCP discover again after release')
949 cip2, sip2 = self.send_recv(mac=mac)
950 log_test.info('Verifying released IP was given back on rediscover')
951 assert_equal(cip, cip2)
952 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
953 assert_equal(self.dhcp.release(cip2), True)
954
955 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
956 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000957 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
958 ip_map = {}
959 for i in range(10):
960 cip, sip = self.send_recv(mac=mac, update_seed = True)
961 if ip_map.has_key(cip):
962 log_test.info('IP %s given out multiple times' %cip)
963 assert_equal(False, ip_map.has_key(cip))
964 ip_map[cip] = sip
965
966 for ip in ip_map.keys():
967 log_test.info('Releasing IP %s' %ip)
968 assert_equal(self.dhcp.release(ip), True)
969
970 ip_map2 = {}
971 log_test.info('Triggering DHCP discover again after release')
972 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
973 for i in range(len(ip_map.keys())):
974 cip, sip = self.send_recv(mac=mac, update_seed = True)
975 ip_map2[cip] = sip
976
977 log_test.info('Verifying released IPs were given back on rediscover')
978 if ip_map != ip_map2:
979 log_test.info('Map before release %s' %ip_map)
980 log_test.info('Map after release %s' %ip_map2)
981 assert_equal(ip_map, ip_map2)
982
983 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
984 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000985 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
986 log_test.info('Verifying 1 ')
987 count = 0
988 while True:
989 #mac = RandMAC()._fix()
990 cip, sip = self.send_recv(update_seed = True,validate = False)
991 if cip is None:
992 break
993 else:
994 count += 1
995 assert_equal(count,91)
996 log_test.info('Verifying 2 ')
997 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
998 assert_equal(cip, None)
999 assert_equal(sip, None)
1000
1001 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
1002 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001003 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1004 cip, sip, mac, _ = self.dhcp.only_discover()
1005 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
1006 (cip, sip, mac) )
1007 assert_not_equal(cip, None)
1008 log_test.info('Triggering DHCP discover again.')
1009 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
1010 assert_equal(new_cip, cip)
1011 log_test.info('got same ip to smae the client when sent discover again, as expected')
1012
1013 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
1014 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001015 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1016 log_test.info('Sending DHCP discover and DHCP request.')
1017 cip, sip = self.send_recv(mac=mac)
1018 mac = self.dhcp.get_mac(cip)[0]
1019 log_test.info("Sending DHCP request again.")
1020 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1021 assert_equal(new_cip, cip)
1022 log_test.info('got same ip to smae the client when sent request again, as expected')
1023
1024 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
1025 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001026 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
1027 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1028 assert_equal(cip,self.dhcp.seed_ip)
1029 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
1030 (cip, sip, mac) )
1031
1032 def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'):
1033 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001034 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
1035 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
1036 assert_not_equal(cip,None)
1037 assert_not_equal(cip,self.dhcp.seed_ip)
1038 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
1039
1040 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
1041 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001042 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1043 cip, sip, mac, _ = self.dhcp.only_discover()
1044 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1045 (cip, sip, mac) )
1046 assert_not_equal(cip, None)
1047 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
1048 assert_equal(new_cip, None)
1049 log_test.info('server sent NAK packet when requested other IP than that server offered')
1050
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001051 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 +00001052 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001053 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
1054 self.dhcp.return_option = 'lease'
1055 cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time)
1056 assert_equal(lval, lease_time)
1057 log_test.info('dhcp server offered IP address with client requested lease time')
1058
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001059 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001060 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001061 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1062 cip, sip, mac, _ = self.dhcp.only_discover()
1063 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1064 (cip, sip, mac) )
1065 assert_not_equal(cip, None)
1066 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1067 log_test.info('client rebooting...')
1068 os.system('ifconfig '+iface+' down')
1069 time.sleep(5)
1070 os.system('ifconfig '+iface+' up')
1071 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
1072 assert_equal(new_cip2, cip)
1073 log_test.info('client got same IP after reboot, as expected')
1074
1075
1076 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
1077 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001078 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1079 cip, sip, mac, _ = self.dhcp.only_discover()
1080 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1081 (cip, sip, mac) )
1082 assert_not_equal(cip, None)
1083 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1084 log_test.info('server rebooting...')
1085 self.tearDownClass()
1086 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1087 assert_equal(new_cip,None)
1088 self.setUpClass()
1089 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1090 assert_equal(new_cip, cip)
1091 log_test.info('client got same IP after server rebooted, as expected')
1092
1093 def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700):
1094 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001095 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1096 self.dhcp.return_option = 'lease'
1097 log_test.info('Sending DHCP discover with lease time of 700')
1098 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time)
1099 assert_equal(lval,lease_time)
1100 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
1101 assert_equal(new_cip,cip)
1102 assert_not_equal(lval, lease_time) #Negative Test Case
1103 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
1104
1105 def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800):
1106 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001107 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1108 cip, sip, mac, _ = self.dhcp.only_discover()
1109 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
1110 assert_equal(new_cip,cip)
1111 assert_equal(lval, lease_time)
1112 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
1113
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001114 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001115 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001116 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1117 cip, sip, mac, _ = self.dhcp.only_discover()
1118 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1119 (cip, sip, mac) )
1120 assert_not_equal(cip,None)
1121 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
1122 log_test.info('waiting for renew time..')
1123 time.sleep(lval)
1124 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
1125 assert_equal(latest_cip, cip)
1126 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1127
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001128 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001129 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001130 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1131 cip, sip, mac, _ = self.dhcp.only_discover()
1132 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1133 (cip, sip, mac) )
1134 assert_not_equal(cip,None)
1135 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1136 log_test.info('waiting for rebind time..')
1137 time.sleep(lval)
1138 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1139 assert_equal(latest_cip, cip)
1140 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1141
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001142 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001143 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001144 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1145 expected_subnet = '255.255.255.0'
1146 self.dhcp.return_option = 'subnet'
1147
1148 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
1149 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1150 (cip, sip, mac) )
1151 assert_equal(subnet_mask,expected_subnet)
1152 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1153
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001154 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001155 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001156 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1157
1158 cip, sip, mac, _ = 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_not_equal(cip,None)
1162 self.dhcp.send_different_option = 'subnet'
1163 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1164 assert_equal(new_cip, cip)
1165 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1166
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001167 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001168 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001169 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1170 expected_router_address = '20.20.20.1'
1171 self.dhcp.return_option = 'router'
1172
1173 cip, sip, mac, router_address_value = self.dhcp.only_discover()
1174 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1175 (cip, sip, mac) )
1176 assert_equal(expected_router_address, router_address_value)
1177 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1178
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001179 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001180 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001181 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1182
1183 cip, sip, mac, _ = 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_not_equal(cip,None)
1187 self.dhcp.send_different_option = 'router'
1188 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1189 assert_equal(new_cip, cip)
1190 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1191
1192 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1193 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001194 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1195 expected_broadcast_address = '192.168.1.255'
1196 self.dhcp.return_option = 'broadcast_address'
1197
1198 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
1199 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1200 (cip, sip, mac) )
1201 assert_equal(expected_broadcast_address, broadcast_address_value)
1202 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1203
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001204 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001205 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001206 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1207
1208 cip, sip, mac, _ = 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_not_equal(cip,None)
1212 self.dhcp.send_different_option = 'broadcast_address'
1213 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1214 assert_equal(new_cip, cip)
1215 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1216
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001217 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001218 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001219 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1220 expected_dns_address = '192.168.1.1'
1221 self.dhcp.return_option = 'dns'
1222
1223 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1224 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1225 (cip, sip, mac) )
1226 assert_equal(expected_dns_address, dns_address_value)
1227 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1228
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001229 def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001230 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001231 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1232
1233 cip, sip, mac, _ = self.dhcp.only_discover()
1234 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1235 (cip, sip, mac) )
1236 assert_not_equal(cip,None)
1237 self.dhcp.send_different_option = 'dns'
1238 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1239 assert_equal(new_cip, cip)
1240 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1241
1242
1243 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1244
1245 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001246 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001247 log_test.info("Statistics for run %d",i)
1248 log_test.info("----------------------------------------------------------------------------------")
1249 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1250 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1251 log_test.info("----------------------------------------------------------------------------------")
1252 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1253
1254 log_test.info("Final Statistics for total transactions")
1255 log_test.info("----------------------------------------------------------------------------------")
1256 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1257 log_test.info(" %d %d %d %d" %(self.transactions,
1258 self.total_success, self.total_failure, self.running_time))
1259 log_test.info("----------------------------------------------------------------------------------")
1260 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1261
1262 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1263
1264 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001265 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001266 log_test.info("Statistics for run %d",i)
1267 log_test.info("----------------------------------------------------------------------------------")
1268 log_test.info("No. of consecutive successful transactions Running Time ")
1269 log_test.info(" %d %d " %(self.ip_count, self.diff))
1270 log_test.info("----------------------------------------------------------------------------------")
1271 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1272 log_test.info("----------------------------------------------------------------------------------")
1273
1274 log_test.info("Final Statistics for total successful transactions")
1275 log_test.info("----------------------------------------------------------------------------------")
1276 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1277 log_test.info(" %d %d %d " %(self.transactions,
1278 self.total_success, self.running_time))
1279 log_test.info("----------------------------------------------------------------------------------")
1280 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1281 log_test.info("----------------------------------------------------------------------------------")
1282
1283 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1284
1285 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001286 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001287 log_test.info("----------------------------------------------------------------------------------")
1288 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1289 log_test.info("----------------------------------------------------------------------------------")
1290 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1291 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1292 log_test.info("----------------------------------------------------------------------------------")
1293 log_test.info("No. of clients per second in run %d:%f "
1294 %(i, self.transaction_count))
1295 log_test.info("----------------------------------------------------------------------------------")
1296 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1297 log_test.info("----------------------------------------------------------------------------------")
1298 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1299 log_test.info(" %d %d %d %d" %(self.transactions,
1300 self.total_success, self.total_failure, self.running_time))
1301 log_test.info("----------------------------------------------------------------------------------")
1302 log_test.info("Average no. of clients per second: %d ",
1303 round(self.transactions/self.running_time,0))
1304 log_test.info("----------------------------------------------------------------------------------")
1305
1306 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1307
1308 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001309 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001310 log_test.info("----------------------------------------------------------------------------------")
1311 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1312 log_test.info("----------------------------------------------------------------------------------")
1313 log_test.info("No. of consecutive successful transactions Running Time ")
1314 log_test.info(" %d %d " %(self.ip_count, self.diff))
1315 log_test.info("----------------------------------------------------------------------------------")
1316 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1317 log_test.info("----------------------------------------------------------------------------------")
1318
1319 log_test.info("Final Statistics for total successful transactions")
1320 log_test.info("----------------------------------------------------------------------------------")
1321 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1322 log_test.info(" %d %d %d " %(self.transactions,
1323 self.total_success, self.running_time))
1324 log_test.info("----------------------------------------------------------------------------------")
1325 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1326 log_test.info("----------------------------------------------------------------------------------")
1327
1328 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001329 for key in (key for key in g_subscriber_port_map if key < 100):
1330 self.host_load(g_subscriber_port_map[key])
1331
1332 def thread_fun(i):
1333 mac = self.get_mac('veth{}'.format(i))
1334 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1335 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1336 self.lock.acquire()
1337
1338 if cip:
1339 self.ip_count += 1
1340
1341 elif cip is None:
1342 self.failure_count += 1
1343
1344 self.lock.notify_all()
1345 self.lock.release()
1346
1347 for i in range (1,4):
1348 self.ip_count = 0
1349 self.failure_count = 0
1350 self.start_time = 0
1351 self.diff = 0
1352 self.transaction_count = 0
1353 self.start_time = time.time()
1354
1355 while self.diff <= 60:
1356 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1357 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1358 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1359 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1360 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1361 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1362
1363 t.start()
1364 t1.start()
1365 t2.start()
1366 t3.start()
1367 t4.start()
1368 t5.start()
1369
1370 t.join()
1371 t1.join()
1372 t2.join()
1373 t3.join()
1374 t4.join()
1375 t5.join()
1376
1377 self.diff = round(time.time() - self.start_time, 0)
1378
1379 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1380
1381 self.transactions += (self.ip_count+self.failure_count)
1382 self.running_time += self.diff
1383 self.total_success += self.ip_count
1384 self.total_failure += self.failure_count
1385
1386
1387 log_test.info("----------------------------------------------------------------------------------")
1388 log_test.info("Statistics for run %d",i)
1389 log_test.info("----------------------------------------------------------------------------------")
1390 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1391 log_test.info(" %d %d %d %d"
1392 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1393 log_test.info("----------------------------------------------------------------------------------")
1394 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1395 log_test.info("----------------------------------------------------------------------------------")
1396
1397 log_test.info("----------------------------------------------------------------------------------")
1398 log_test.info("Final Statistics for total transactions")
1399 log_test.info("----------------------------------------------------------------------------------")
1400 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1401 log_test.info(" %d %d %d %d" %(self.transactions,
1402 self.total_success, self.total_failure, self.running_time))
1403
1404 log_test.info("----------------------------------------------------------------------------------")
1405 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1406 log_test.info("----------------------------------------------------------------------------------")
1407
1408 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001409 failure_dir = {}
1410
1411 for key in (key for key in g_subscriber_port_map if key != 100):
1412 self.host_load(g_subscriber_port_map[key])
1413
1414 def thread_fun(i, j):
1415# log_test.info("Thread Name:%s",current_thread().name)
1416# failure_dir[current_thread().name] = True
1417 while failure_dir.has_key(current_thread().name) is False:
1418 mac = RandMAC()._fix()
1419 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1420 i += 2
1421 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1422 self.lock.acquire()
1423
1424 if cip:
1425 self.ip_count += 1
1426 self.lock.notify_all()
1427 self.lock.release()
1428 elif cip is None:
1429 self.failure_count += 1
1430 failure_dir[current_thread().name] = True
1431 self.lock.notify_all()
1432 self.lock.release()
1433 break
1434# self.lock.notify_all()
1435# self.lock.release()
1436
1437 for i in range (1,4):
1438 failure_dir = {}
1439 self.ip_count = 0
1440 self.failure_count = 0
1441 self.start_time = 0
1442 self.diff = 0
1443 self.transaction_count = 0
1444 self.start_time = time.time()
1445
1446 while len(failure_dir) != 6:
1447 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1448 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1449 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1450 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1451 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1452 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1453
1454 t.start()
1455 t1.start()
1456 t2.start()
1457 t3.start()
1458 t4.start()
1459 t5.start()
1460
1461 t.join()
1462 t1.join()
1463 t2.join()
1464 t3.join()
1465 t4.join()
1466 t5.join()
1467
1468 self.diff = round(time.time() - self.start_time, 0)
1469 self.transaction_count = round((self.ip_count)/self.diff, 2)
1470
1471 self.transactions += (self.ip_count+self.failure_count)
1472 self.running_time += self.diff
1473 self.total_success += self.ip_count
1474 self.total_failure += self.failure_count
1475
1476
1477 log_test.info("Statistics for run %d",i)
1478 log_test.info("----------------------------------------------------------------------------------")
1479 log_test.info("No. of consecutive successful transactions Running Time ")
1480 log_test.info(" %d %d " %(self.ip_count, self.diff))
1481 log_test.info("----------------------------------------------------------------------------------")
1482 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1483 log_test.info("----------------------------------------------------------------------------------")
1484
1485 log_test.info("Final Statistics for total successful transactions")
1486 log_test.info("----------------------------------------------------------------------------------")
1487 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1488 log_test.info(" %d %d %d " %(self.transactions,
1489 self.total_success, self.running_time))
1490 log_test.info("----------------------------------------------------------------------------------")
1491 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1492 log_test.info("----------------------------------------------------------------------------------")
1493
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001494 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001495 for key in (key for key in g_subscriber_port_map if key < 100):
1496 self.host_load(g_subscriber_port_map[key])
1497
1498 def thread_fun(i):
1499# mac = self.get_mac('veth{}'.format(i))
1500 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1501 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1502 self.lock.acquire()
1503
1504 if cip:
1505 self.ip_count += 1
1506 elif cip is None:
1507 self.failure_count += 1
1508
1509 self.lock.notify_all()
1510 self.lock.release()
1511
1512 for i in range (1,4):
1513 self.ip_count = 0
1514 self.failure_count = 0
1515 self.start_time = 0
1516 self.diff = 0
1517 self.transaction_count = 0
1518 self.start_time = time.time()
1519
1520 while self.diff <= 60:
1521 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1522 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1523 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1524 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1525 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1526 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1527
1528 t.start()
1529 t1.start()
1530 t2.start()
1531 t3.start()
1532 t4.start()
1533 t5.start()
1534
1535 t.join()
1536 t1.join()
1537 t2.join()
1538 t3.join()
1539 t4.join()
1540 t5.join()
1541
1542 self.diff = round(time.time() - self.start_time, 0)
1543 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1544 self.transactions += (self.ip_count+self.failure_count)
1545 self.running_time += self.diff
1546 self.total_success += self.ip_count
1547 self.total_failure += self.failure_count
1548
1549 log_test.info("----------------------------------------------------------------------------------")
1550 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1551 log_test.info("----------------------------------------------------------------------------------")
1552 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1553 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1554 log_test.info("----------------------------------------------------------------------------------")
1555 log_test.info("No. of clients per second in run %d:%f "
1556 %(i, self.transaction_count))
1557 log_test.info("----------------------------------------------------------------------------------")
1558
1559 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1560 log_test.info("----------------------------------------------------------------------------------")
1561 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1562 log_test.info(" %d %d %d %d" %(self.transactions,
1563 self.total_success, self.total_failure, self.running_time))
1564 log_test.info("----------------------------------------------------------------------------------")
1565 log_test.info("Average no. of clients per second: %d ",
1566 round(self.transactions/self.running_time,0))
1567 log_test.info("----------------------------------------------------------------------------------")
1568
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001569 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001570 mac = self.get_mac(iface)
1571 self.host_load(iface)
1572 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1573 cip, sip, mac, _ = self.dhcp.only_discover()
1574 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1575 (cip, sip, mac) )
1576 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1577 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1578 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1579 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1580 (new_cip, new_sip, new_mac) )
1581 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1582 log_test.info("Now sending DHCP Request for old DHCP discover.")
1583 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1584 if new_cip is None:
1585 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1586 %(new_cip, new_sip, new_mac) )
1587 elif new_cip:
1588 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.'
1589 %(new_cip, new_sip, new_mac, new_cip) )
1590 assert_equal(new_cip, None)