blob: 8de431c8640c4cef1f15cb3559eb284e0847f9e6 [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
Thangavelu K Saec97e62017-10-25 03:09:36 -070037import os, sys, re, json
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000038from DHCP import DHCPTest
A R Karthickc0a008f2017-10-04 18:35:25 -070039from CordTestUtils import get_mac, log_test, getstatusoutput, get_controller
Thangavelu K Sd4d954f2017-10-12 20:05:30 +000040from SSHTestAgent import SSHTestAgent
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000041from OnosCtrl import OnosCtrl
Thangavelu K Saec97e62017-10-25 03:09:36 -070042from onosclidriver import OnosCliDriver
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000043from OltConfig import OltConfig
Thangavelu K Saec97e62017-10-25 03:09:36 -070044from CordTestServer import cord_test_onos_restart, cord_test_ovs_flow_add,cord_test_onos_shutdown
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070045from CordTestConfig import setup_module, teardown_module
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000046from CordLogger import CordLogger
47from portmaps import g_subscriber_port_map
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070048from CordContainer import Onos
A R Karthicke7232092017-09-07 18:01:33 -070049from VolthaCtrl import VolthaCtrl
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000050import threading, random
51from threading import current_thread
A R Karthickc0a008f2017-10-04 18:35:25 -070052import requests
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000053log_test.setLevel('INFO')
54
55class dhcpl2relay_exchange(CordLogger):
56
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070057 VOLTHA_HOST = None
A R Karthicke7232092017-09-07 18:01:33 -070058 VOLTHA_REST_PORT = VolthaCtrl.REST_PORT
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070059 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
60 VOLTHA_OLT_TYPE = 'simulated_olt'
61 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
62 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthicke2168242017-10-05 16:50:07 -070063 TAGGED_TRAFFIC = False
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000064 app = 'org.opencord.dhcpl2relay'
65 sadis_app = 'org.opencord.sadis'
66 app_dhcp = 'org.onosproject.dhcp'
Thangavelu K S905e5482017-09-12 06:48:02 -070067 app_olt = 'org.onosproject.olt'
A R Karthickc0a008f2017-10-04 18:35:25 -070068 relay_interfaces = ()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000069 relay_interfaces_last = ()
70 interface_to_mac_map = {}
A R Karthickc0a008f2017-10-04 18:35:25 -070071 relay_vlan_map = {}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000072 host_ip_map = {}
73 test_path = os.path.dirname(os.path.realpath(__file__))
74 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070075 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
A R Karthickc0a008f2017-10-04 18:35:25 -070076 olt_app_file = os.path.join(test_path, '..', 'apps/olt-app-3.0-SNAPSHOT.oar')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070077 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
78 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 +000079 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
80 default_options = [ ('subnet-mask', '255.255.255.0'),
81 ('broadcast-address', '192.168.1.255'),
82 ('domain-name-servers', '192.168.1.1'),
83 ('domain-name', '"mydomain.cord-tester"'),
84 ]
85 default_subnet_config = [ ('192.168.1.2',
86'''
87subnet 192.168.1.0 netmask 255.255.255.0 {
88 range 192.168.1.10 192.168.1.100;
89}
90'''), ]
91
92 lock = threading.Condition()
93 ip_count = 0
94 failure_count = 0
95 start_time = 0
96 diff = 0
97
98 transaction_count = 0
99 transactions = 0
100 running_time = 0
101 total_success = 0
102 total_failure = 0
103 #just in case we want to reset ONOS to default network cfg after relay tests
104 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
105 configs = {}
Thangavelu K S905e5482017-09-12 06:48:02 -0700106 sadis_configs = {}
107 default_onos_netcfg = {}
A R Karthickc0a008f2017-10-04 18:35:25 -0700108 voltha_switch_map = None
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000109 remote_dhcpd_cmd = []
Thangavelu K Saec97e62017-10-25 03:09:36 -0700110 ONOS_INSTANCES = 3
111 relay_device_id = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000112
113 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700114 def update_apps_version(cls):
115 version = Onos.getVersion()
116 major = int(version.split('.')[0])
117 minor = int(version.split('.')[1])
118 dhcpl2_app_version = '1.0.0'
A R Karthickc0a008f2017-10-04 18:35:25 -0700119 sadis_app_version = '3.0-SNAPSHOT'
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700120 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
121 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
122
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700123 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000124 def setUpClass(cls):
125 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700126 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000127 OnosCtrl(cls.app_dhcp).deactivate()
128 time.sleep(3)
129 cls.onos_ctrl = OnosCtrl(cls.app)
130 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700131 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000132 time.sleep(3)
A R Karthickc0a008f2017-10-04 18:35:25 -0700133 status, _ = OnosCtrl(cls.sadis_app).activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700134 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000135 time.sleep(3)
A R Karthickc0a008f2017-10-04 18:35:25 -0700136 cls.setup_dhcpd()
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000137 cls.default_onos_netcfg = OnosCtrl.get_config()
138
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700139
140 def setUp(self):
141 super(dhcpl2relay_exchange, self).setUp()
A R Karthickc0a008f2017-10-04 18:35:25 -0700142 #self.dhcp_l2_relay_setup()
143 #self.cord_sadis_load()
144 #self.cord_l2_relay_load()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700145
146 def tearDown(self):
147 super(dhcpl2relay_exchange, self).tearDown()
A R Karthickc0a008f2017-10-04 18:35:25 -0700148 #OnosCtrl.uninstall_app(self.dhcpl2_app_file)
149 #OnosCtrl.uninstall_app(self.sadis_app_file)
150 #OnosCtrl.uninstall_app(self.olt_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000151
152 @classmethod
153 def tearDownClass(cls):
154 '''Deactivate the cord dhcpl2relay app'''
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000155 cls.onos_load_config(cls.default_onos_netcfg)
A R Karthickc0a008f2017-10-04 18:35:25 -0700156 #cls.onos_ctrl.deactivate()
157 #OnosCtrl(cls.sadis_app).deactivate()
158 #OnosCtrl(cls.app_olt).deactivate()
159
160 @classmethod
161 def setup_dhcpd(cls, boot_delay = 5):
Thangavelu K Saec97e62017-10-25 03:09:36 -0700162 device_details = OnosCtrl.get_devices(mfr = 'Nicira')
163 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
164 if device_details is not None:
165 did_ovs = device_details[0]['id']
166 else:
167 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')
168 return False
169 cls.relay_device_id = did_ovs
170 device_details = OnosCtrl.get_devices()
171 if device_details is not None:
172 for device in device_details:
Luca Prete9c0cdac2018-07-02 14:40:40 +0200173 if device['available'] is True and device['driver'] == 'voltha':
Thangavelu K Saec97e62017-10-25 03:09:36 -0700174 cls.olt_serial_id = "{}".format(device['serial'])
175 break
176 else:
177 cls.olt_serial_id = " "
178 else:
179 log_test.info('On this DHCPl2relay setup, onos does not have ovs device where external DHCP server is have connect point, so return with false status')
180 return False
A R Karthickc0a008f2017-10-04 18:35:25 -0700181 if cls.service_running("/usr/sbin/dhcpd"):
182 print('DHCPD already running in container')
183 return True
184 setup_for_relay = cls.dhcp_l2_relay_setup()
185 cls.cord_l2_relay_load()
186 cls.voltha_setup()
A R Karthick760d1382017-10-05 13:48:40 -0700187 return True
188
189 # dhcp_start_status = cls.dhcpd_start()
190 # if setup_for_relay and dhcp_start_status:
191 # return True
192 # return False
A R Karthickc0a008f2017-10-04 18:35:25 -0700193
194 @classmethod
195 def config_olt(cls, switch_map):
196 controller = get_controller()
197 auth = ('karaf', 'karaf')
198 #configure subscriber for every port on all the voltha devices
199 for device, device_map in switch_map.iteritems():
200 uni_ports = device_map['ports']
201 uplink_vlan = device_map['uplink_vlan']
202 for port in uni_ports:
203 vlan = port
204 rest_url = 'http://{}:8181/onos/olt/oltapp/{}/{}/{}'.format(controller,
205 device,
206 port,
207 vlan)
208 requests.post(rest_url, auth = auth)
209
210 @classmethod
211 def voltha_setup(cls):
212 s_tag_map = {}
213 #configure olt app to provision dhcp flows
214 cls.config_olt(cls.voltha_switch_map)
215 for switch, switch_map in cls.voltha_switch_map.iteritems():
216 s_tag_map[int(switch_map['uplink_vlan'])] = map(lambda p: int(p), switch_map['ports'])
217
218 cmd_list = []
219 relay_interface = cls.relay_interfaces[0]
220 cls.relay_vlan_map[relay_interface] = []
221 for s_tag, ports in s_tag_map.iteritems():
222 vlan_stag_intf = '{}.{}'.format(relay_interface, s_tag)
223 cmd = 'ip link add link %s name %s type vlan id %d' %(relay_interface, vlan_stag_intf, s_tag)
224 cmd_list.append(cmd)
225 cmd = 'ip link set %s up' %(vlan_stag_intf)
226 cmd_list.append(cmd)
227 for port in ports:
228 vlan_ctag_intf = '{}.{}.{}'.format(relay_interface, s_tag, port)
229 cmd = 'ip link add link %s name %s type vlan id %d' %(vlan_stag_intf, vlan_ctag_intf, port)
230 cmd_list.append(cmd)
231 cmd = 'ip link set %s up' %(vlan_ctag_intf)
232 cmd_list.append(cmd)
233 cls.relay_vlan_map[relay_interface].append(vlan_ctag_intf)
234 cls.relay_vlan_map[relay_interface].append(vlan_stag_intf)
235
236 for cmd in cmd_list:
237 log_test.info('Running command: %s' %cmd)
238 os.system(cmd)
239
240 cord_test_ovs_flow_add(cls.relay_interface_port)
241 for s_tag in s_tag_map.keys():
242 log_test.info('Configuring OVS flow for port %d, s_tag %d' %(cls.relay_interface_port, s_tag))
243 cord_test_ovs_flow_add(cls.relay_interface_port, s_tag)
244
245 @classmethod
246 def service_running(cls, pattern):
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000247 st, output = getstatusoutput('pgrep -f "{}"'.format(pattern))
A R Karthickc0a008f2017-10-04 18:35:25 -0700248 return True if st == 0 else False
249
250 @classmethod
251 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
252 subnet = default_subnet_config):
253 conf = ''
254 for k, v in config.items():
255 conf += '{} {};\n'.format(k, v)
256
257 opts = ''
258 for k, v in options:
259 opts += 'option {} {};\n'.format(k, v)
260
261 subnet_config = ''
262 for _, v in subnet:
263 subnet_config += '{}\n'.format(v)
264
265 return '{}{}{}'.format(conf, opts, subnet_config)
266
267 @classmethod
268 def dhcpd_start(cls, intf_list = None,
269 config = default_config, options = default_options,
270 subnet = default_subnet_config):
271 '''Start the dhcpd server by generating the conf file'''
272 if intf_list is None:
273 intf_list = cls.relay_interfaces
274 intf_list = list(intf_list)
275 ##stop dhcpd if already running
276 #cls.dhcpd_stop()
277 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
278 subnet = subnet)
279 ##first touch dhcpd.leases if it doesn't exist
280 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
281 if os.access(lease_file, os.F_OK) is False:
282 with open(lease_file, 'w') as fd: pass
283
A R Karthickce96dde2017-10-05 16:41:52 -0700284 lease_file_tagged = '{}/dhcpd-tagged.leases'.format(cls.dhcp_data_dir)
285 if os.access(lease_file_tagged, os.F_OK) is False:
286 with open(lease_file_tagged, 'w') as fd: pass
287
A R Karthickc0a008f2017-10-04 18:35:25 -0700288 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
289 with open(conf_file, 'w') as fd:
290 fd.write(dhcp_conf)
291
A R Karthickce96dde2017-10-05 16:41:52 -0700292 conf_file_tagged = '{}/dhcpd-tagged.conf'.format(cls.dhcp_data_dir)
293 with open(conf_file_tagged, 'w') as fd:
294 fd.write(dhcp_conf)
295
A R Karthickc0a008f2017-10-04 18:35:25 -0700296 #now configure the dhcpd interfaces for various subnets
297 index = 0
298 intf_info = []
299 vlan_intf_list = []
300 for ip,_ in subnet:
301 vlan_intf = None
302 intf = intf_list[index]
303 if intf in cls.relay_vlan_map:
304 vlan_intf = cls.relay_vlan_map[intf][0]
305 vlan_intf_list.append(vlan_intf)
306 mac = cls.get_mac(intf)
307 intf_info.append((ip, mac))
308 index += 1
309 cmd = 'ifconfig {} {}'.format(intf, ip)
310 status = os.system(cmd)
311 if vlan_intf:
312 cmd = 'ifconfig {} {}'.format(vlan_intf, ip)
313 os.system(cmd)
314
315 intf_str = ','.join(intf_list)
316 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)
317 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
318 status = os.system(dhcpd_cmd)
319 vlan_intf_str = ','.join(vlan_intf_list)
A R Karthickce96dde2017-10-05 16:41:52 -0700320 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format('/root/test/src/test/setup/dhcpd-tagged.conf','/root/test/src/test/setup/dhcpd-tagged.leases', vlan_intf_str)
A R Karthickc0a008f2017-10-04 18:35:25 -0700321 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
322 status = os.system(dhcpd_cmd)
323 if status > 255:
324 status = 1
325 else:
326 return False
327 time.sleep(3)
328 cls.relay_interfaces_last = cls.relay_interfaces
329 cls.relay_interfaces = intf_list
330 return True
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000331
332 @classmethod
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000333 def get_dhcpd_process(cls):
334 docker_cmd = 'docker exec cord-tester1'
335 cmd = '{} ps -eaf | grep dhcpd'.format(docker_cmd)
336 dhcpd_server_ip = get_controller()
337 server_user = 'ubuntu'
338 server_pass = 'ubuntu'
339 ssh_agent = SSHTestAgent(host = dhcpd_server_ip, user = server_user, password = server_user)
340 status, output = ssh_agent.run_cmd(cmd)
341 assert_equal(status, True)
342 if output:
343 cls.remote_dhcpd_cmd = re.findall('(?<=/)\w+.*', output)
344 log_test.info('DHCP server running on remote host and list of service commands are \n %s'%cls.remote_dhcpd_cmd)
345 assert_equal(status, True)
346 return cls.remote_dhcpd_cmd
347
348 def dhcpd_stop(self, remote_controller = False, dhcpd = None):
349 if remote_controller is not True:
350 if cls.service_running("/usr/sbin/dhcpd"):
351 cmd = 'pkill -9 dhcpd'
352 st, _ = getstatusoutput(cmd)
353 return True if st == 0 else False
354 else:
355 docker_cmd = 'docker exec cord-tester1'
356 dhcpd_server_ip = get_controller()
357 server_user = 'ubuntu'
358 server_pass = 'ubuntu'
359 service_satatus = True
360 ssh_agent = SSHTestAgent(host = dhcpd_server_ip, user = server_user, password = server_user)
361 if dhcpd == 'stop':
362 status, output = ssh_agent.run_cmd('{} pkill -9 dhcpd'.format(docker_cmd))
363 service_satatus = status and True
364 elif dhcpd == 'start':
365 for cmd in self.remote_dhcpd_cmd:
366 dhcpd_cmd = ' {0} /{1}'.format(docker_cmd,cmd)
367 status, output = ssh_agent.run_cmd(dhcpd_cmd)
368 service_satatus = status and True
369 elif dhcpd == 'restart':
370 status, output = ssh_agent.run_cmd('{} pkill -9 dhcpd'.format(docker_cmd))
371 service_satatus = status and True
372 for cmd in self.remote_dhcpd_cmd:
373 dhcpd_cmd = ' {0} /{1}'.format(docker_cmd,cmd)
374 status, output = ssh_agent.run_cmd(dhcpd_cmd)
375 service_satatus = status and True
376 return service_satatus
377
378 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000379 def dhcp_l2_relay_setup(cls):
A R Karthickc0a008f2017-10-04 18:35:25 -0700380 device_details = OnosCtrl.get_devices(mfr = 'Nicira')
Thangavelu K S905e5482017-09-12 06:48:02 -0700381 if device_details is not None:
A R Karthickc0a008f2017-10-04 18:35:25 -0700382 did_ovs = device_details[0]['id']
Thangavelu K S905e5482017-09-12 06:48:02 -0700383 else:
384 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')
385 return False
386 cls.relay_device_id = did_ovs
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000387 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
388 cls.port_map, _ = cls.olt.olt_port_map()
389 if cls.port_map:
390 ##Per subscriber, we use 1 relay port
391 try:
392 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
393 except:
394 relay_port = cls.port_map['uplink']
395 cls.relay_interface_port = relay_port
396 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
397 else:
398 cls.relay_interface_port = 100
399 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
400 cls.relay_interfaces_last = cls.relay_interfaces
401 if cls.port_map:
402 ##generate a ip/mac client virtual interface config for onos
403 interface_list = []
404 for port in cls.port_map['ports']:
405 port_num = cls.port_map[port]
406 if port_num == cls.port_map['uplink']:
407 continue
408 ip = cls.get_host_ip(port_num)
409 mac = cls.get_mac(port)
410 interface_list.append((port_num, ip, mac))
411
412 #configure dhcp server virtual interface on the same subnet as first client interface
413 relay_ip = cls.get_host_ip(interface_list[0][0])
414 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
415 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthickc0a008f2017-10-04 18:35:25 -0700416 cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000417
418 @classmethod
419 def dhcp_l2_relay_cleanup(cls):
420 ##reset the ONOS port configuration back to default
421 for config in cls.configs.items():
422 OnosCtrl.delete(config)
Thangavelu K S905e5482017-09-12 06:48:02 -0700423 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000424 # if cls.onos_restartable is True:
425 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
426 # return cord_test_onos_restart(config = {})
427
428 @classmethod
429 def onos_load_config(cls, config):
430 status, code = OnosCtrl.config(config)
431 if status is False:
432 log_test.info('JSON request returned status %d' %code)
433 assert_equal(status, True)
434 time.sleep(3)
435
436 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700437 def onos_delete_config(cls, config):
438 status, code = OnosCtrl.delete(config)
439 if status is False:
440 log_test.info('JSON request returned status %d' %code)
441 assert_equal(status, True)
442 time.sleep(3)
443
444 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000445 def onos_interface_load(cls, interface_list):
446 interface_dict = { 'ports': {} }
447 for port_num, ip, mac in interface_list:
448 port_map = interface_dict['ports']
449 port = '{}/{}'.format(cls.relay_device_id, port_num)
450 port_map[port] = { 'interfaces': [] }
451 interface_list = port_map[port]['interfaces']
452 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
453 'mac' : mac,
454 'name': 'vir-{}'.format(port_num)
455 }
456 interface_list.append(interface_map)
457
458 cls.onos_load_config(interface_dict)
459 cls.configs['interface_config'] = interface_dict
460
461 @classmethod
A R Karthickc0a008f2017-10-04 18:35:25 -0700462 def cord_l2_relay_load(cls, dhcp_server_connectPoint = None, delete = False):
A R Karthick53735662017-10-05 12:53:35 -0700463 ##read the current config
464 current_netcfg = OnosCtrl.get_config()
465 connect_points = set([])
466 try:
467 connect_points = set(current_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints'])
468 except KeyError, e:
469 pass
470
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700471 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
A R Karthickc0a008f2017-10-04 18:35:25 -0700472 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700473 #### We have to work on later versions by removing these hard coded values
Thangavelu K S905e5482017-09-12 06:48:02 -0700474 if dhcp_server_connectPoint is None:
A R Karthick8fe89a12017-10-05 13:12:13 -0700475 relay_device_present = filter(lambda cp: cp.split('/')[0] == cls.relay_device_id, connect_points)
476 if not relay_device_present:
477 connect_points.add(relay_device_map)
A R Karthick53735662017-10-05 12:53:35 -0700478 else:
479 cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint)
480 connect_points = list(connect_points)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700481 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
A R Karthick53735662017-10-05 12:53:35 -0700482 {"dhcpServerConnectPoints": connect_points}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000483 }
484 }
485 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700486 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700487 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700488 if delete == False:
489 cls.onos_load_config(dhcp_dict)
490 else:
491 cls.onos_delete_config(dhcp_dict)
492 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000493 cls.configs['relay_config'] = dhcp_dict
494
495 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700496 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000497 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700498 device_details = OnosCtrl.get_devices()
499 if device_details is not None:
500 for device in device_details:
501 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
Luca Prete9c0cdac2018-07-02 14:40:40 +0200502 if device['available'] is True and device['driver'] == 'voltha':
Thangavelu K S905e5482017-09-12 06:48:02 -0700503 cls.olt_serial_id = "{}".format(device['serial'])
504 else:
505 cls.olt_serial_id = " "
506 else:
507 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')
508 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700509 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000510 "org.opencord.sadis": {
511 "sadis": {
512 "integration": {
513 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700514 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000515 "maxsize": 50,
516 "ttl": "PT1m"
517 }
518 },
519 "entries": [{
520 "id": "uni-254",
521 "cTag": 202,
522 "sTag": 222,
523 "nasPortId": "uni-254"
524 },
525 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700526 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700527 "hardwareIdentifier": "00:0c:e2:31:05:00",
528 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000529 "nasId": "B100-NASID"
530 }
531 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700532 }
533 }
534 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000535 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700536 #OnosCtrl.uninstall_app(cls.olt_app_file)
537 OnosCtrl.install_app(cls.olt_app_file)
538 time.sleep(5)
539 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700540 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700541 if sadis_info:
542 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000543 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700544 cls.sadis_configs['relay_config'] = sadis_dict
545
546 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):
547 ### Need to work on these hard coded values on later merges
548 if subscriber_port_id is None:
549 subscriber_port_id = "uni-254"
550 if c_tag is None:
551 c_tag = 202
552 if s_tag is None:
553 s_tag = 222
554 if nas_port_id is None:
555 nas_port_id = "uni-254"
556 if olt_serial_id is None:
557 olt_serial_id = self.olt_serial_id
558 if olt_mac is None:
559 olt_mac = "00:0c:e2:31:05:00"
560 if olt_ip is None:
561 olt_ip = "172.17.0.1"
562 if olt_nas_id is None:
563 olt_nas_id = "B100-NASID"
564 sadis_dict = { "apps": {
565 "org.opencord.sadis": {
566 "sadis": {
567 "integration": {
568 "cache": {
569 "enabled": "true",
570 "maxsize": 50,
571 "ttl": "PT1m"
572 }
573 },
574 "entries": [{
575 "id": subscriber_port_id,
576 "cTag": c_tag,
577 "sTag": s_tag,
578 "nasPortId": nas_port_id
579 },
580 {
581 "id": olt_serial_id,
582 "hardwareIdentifier": olt_mac,
583 "ipAddress": olt_ip,
584 "nasId": olt_nas_id
585 }
586 ]
587 }
588 }
589 }
590 }
591 return sadis_dict
592
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000593
594 @classmethod
595 def get_host_ip(cls, port):
596 if cls.host_ip_map.has_key(port):
597 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700598 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000599 return cls.host_ip_map[port]
600
601 @classmethod
602 def host_load(cls, iface):
603 '''Have ONOS discover the hosts for dhcp-relay responses'''
604 port = g_subscriber_port_map[iface]
605 host = '173.17.1.{}'.format(port)
606 cmds = ( 'ifconfig {} 0'.format(iface),
607 'ifconfig {0} {1}'.format(iface, host),
608 'arping -I {0} {1} -c 2'.format(iface, host),
609 'ifconfig {} 0'.format(iface), )
610 for c in cmds:
611 os.system(c)
612
613 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000614 def get_mac(cls, iface):
615 if cls.interface_to_mac_map.has_key(iface):
616 return cls.interface_to_mac_map[iface]
617 mac = get_mac(iface, pad = 0)
618 cls.interface_to_mac_map[iface] = mac
619 return mac
620
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000621 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000622
623 self.ip_count = 0
624 self.failure_count = 0
625 self.start_time = 0
626 self.diff = 0
627 self.transaction_count = 0
628
629 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000630 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
631 self.start_time = time.time()
632
633 while self.diff <= 60:
634
635 if only_discover:
636 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
637 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
638 (cip, sip, mac))
639 else:
640 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
641
642 if cip:
643 self.ip_count +=1
644 elif cip == None:
645 self.failure_count += 1
646 log_test.info('Failed to get ip')
647 if success_rate and self.ip_count > 0:
648 break
649
650 self.diff = round(time.time() - self.start_time, 0)
651
652 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
653 self.transactions += (self.ip_count+self.failure_count)
654 self.running_time += self.diff
655 self.total_success += self.ip_count
656 self.total_failure += self.failure_count
657
658 def send_recv(self, mac=None, update_seed = False, validate = True):
659 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
660 if validate:
661 assert_not_equal(cip, None)
662 assert_not_equal(sip, None)
663 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
664 (cip, sip, self.dhcp.get_mac(cip)[0]))
665 return cip,sip
666
Thangavelu K Saec97e62017-10-25 03:09:36 -0700667 def cliEnter(self, controller = None):
668 retries = 0
669 while retries < 30:
670 self.cli = OnosCliDriver(controller = controller, connect = True)
671 if self.cli.handle:
672 break
673 else:
674 retries += 1
675 time.sleep(2)
676
677 def cliExit(self):
678 self.cli.disconnect()
679
680
681 def verify_cluster_status(self,controller = None,onos_instances=ONOS_INSTANCES,verify=False):
682 tries = 0
683 try:
684 self.cliEnter(controller = controller)
685 while tries <= 10:
686 cluster_summary = json.loads(self.cli.summary(jsonFormat = True))
687 if cluster_summary:
688 log_test.info("cluster 'summary' command output is %s"%cluster_summary)
689 nodes = cluster_summary['nodes']
690 if verify:
691 if nodes == onos_instances:
692 self.cliExit()
693 return True
694 else:
695 tries += 1
696 time.sleep(1)
697 else:
698 if nodes >= onos_instances:
699 self.cliExit()
700 return True
701 else:
702 tries += 1
703 time.sleep(1)
704 else:
705 tries += 1
706 time.sleep(1)
707 self.cliExit()
708 return False
709 except:
710 raise Exception('Failed to get cluster members')
711 return False
712
713
714 def get_cluster_current_member_ips(self, controller = None, nodes_filter = None):
715 tries = 0
716 cluster_ips = []
717 try:
718 self.cliEnter(controller = controller)
719 while tries <= 10:
720 cluster_nodes = json.loads(self.cli.nodes(jsonFormat = True))
721 if cluster_nodes:
722 log_test.info("cluster 'nodes' output is %s"%cluster_nodes)
723 if nodes_filter:
724 cluster_nodes = nodes_filter(cluster_nodes)
725 cluster_ips = map(lambda c: c['id'], cluster_nodes)
726 self.cliExit()
727 cluster_ips.sort(lambda i1,i2: int(i1.split('.')[-1]) - int(i2.split('.')[-1]))
728 return cluster_ips
729 else:
730 tries += 1
731 self.cliExit()
732 return cluster_ips
733 except:
734 raise Exception('Failed to get cluster members')
735 return cluster_ips
736
737 def get_cluster_container_names_ips(self,controller=None):
738 onos_names_ips = {}
739 controllers = get_controllers()
740 i = 0
741 for controller in controllers:
742 if i == 0:
743 name = Onos.NAME
744 else:
745 name = '{}-{}'.format(Onos.NAME, i+1)
746 onos_names_ips[controller] = name
747 onos_names_ips[name] = controller
748 i += 1
749 return onos_names_ips
750
751 def get_cluster_current_master_standbys(self,controller=None,device_id=relay_device_id):
752 master = None
753 standbys = []
754 tries = 0
755 try:
756 cli = self.cliEnter(controller = controller)
757 while tries <= 10:
758 roles = json.loads(self.cli.roles(jsonFormat = True))
759 log_test.info("cluster 'roles' command output is %s"%roles)
760 if roles:
761 for device in roles:
762 log_test.info('Verifying device info in line %s'%device)
763 if device['id'] == device_id:
764 master = str(device['master'])
765 standbys = map(lambda d: str(d), device['standbys'])
766 log_test.info('Master and standbys for device %s are %s and %s'%(device_id, master, standbys))
767 self.cliExit()
768 return master, standbys
769 break
770 self.cliExit()
771 return master, standbys
772 else:
773 tries += 1
774 time.sleep(1)
775 self.cliExit()
776 return master,standbys
777 except:
778 raise Exception('Failed to get cluster members')
779 return master,standbys
780
781 def get_cluster_current_master_standbys_of_connected_devices(self,controller=None):
782 ''' returns master and standbys of all the connected devices to ONOS cluster instance'''
783 device_dict = {}
784 tries = 0
785 try:
786 cli = self.cliEnter(controller = controller)
787 while tries <= 10:
788 device_dict = {}
789 roles = json.loads(self.cli.roles(jsonFormat = True))
790 log_test.info("cluster 'roles' command output is %s"%roles)
791 if roles:
792 for device in roles:
793 device_dict[str(device['id'])]= {'master':str(device['master']),'standbys':device['standbys']}
794 for i in range(len(device_dict[device['id']]['standbys'])):
795 device_dict[device['id']]['standbys'][i] = str(device_dict[device['id']]['standbys'][i])
796 log_test.info('master and standbys for device %s are %s and %s'%(device['id'],device_dict[device['id']]['master'],device_dict[device['id']]['standbys']))
797 self.cliExit()
798 return device_dict
799 else:
800 tries += 1
801 time.sleep(1)
802 self.cliExit()
803 return device_dict
804 except:
805 raise Exception('Failed to get cluster members')
806 return device_dict
807
808 def get_number_of_devices_of_master(self,controller=None):
809 '''returns master-device pairs, which master having what devices'''
810 master_count = {}
811 try:
812 cli = self.cliEnter(controller = controller)
813 masters = json.loads(self.cli.masters(jsonFormat = True))
814 if masters:
815 for master in masters:
816 master_count[str(master['id'])] = {'size':int(master['size']),'devices':master['devices']}
817 return master_count
818 else:
819 return master_count
820 except:
821 raise Exception('Failed to get cluster members')
822 return master_count
823
824 def change_master_current_cluster(self,new_master=None,device_id=relay_device_id,controller=None):
825 if new_master is None: return False
826 self.cliEnter(controller=controller)
827 cmd = 'device-role' + ' ' + device_id + ' ' + new_master + ' ' + 'master'
828 command = self.cli.command(cmd = cmd, jsonFormat = False)
829 self.cliExit()
830 time.sleep(60)
831 master, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
832 assert_equal(master,new_master)
833 log_test.info('Cluster master changed to %s successfully'%new_master)
834
835 def withdraw_cluster_current_mastership(self,master_ip=None,device_id=relay_device_id,controller=None):
836 '''current master looses its mastership and hence new master will be elected'''
837 self.cliEnter(controller=controller)
838 cmd = 'device-role' + ' ' + device_id + ' ' + master_ip + ' ' + 'none'
839 command = self.cli.command(cmd = cmd, jsonFormat = False)
840 self.cliExit()
841 time.sleep(60)
842 new_master_ip, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
843 assert_not_equal(new_master_ip,master_ip)
844 log_test.info('Device-role of device %s successfully changed to none for controller %s'%(device_id,master_ip))
845 log_test.info('Cluster new master is %s'%new_master_ip)
846 return True
847 def cluster_controller_restarts(self, graceful = False):
848 controllers = get_controllers()
849 ctlr_len = len(controllers)
850 if ctlr_len <= 1:
851 log_test.info('ONOS is not running in cluster mode. This test only works for cluster mode')
852 assert_greater(ctlr_len, 1)
853
854 #this call would verify the cluster for once
855 onos_map = self.get_cluster_container_names_ips()
856
857 def check_exception(iteration, controller = None):
858 adjacent_controller = None
859 adjacent_controllers = None
860 if controller:
861 adjacent_controllers = list(set(controllers) - set([controller]))
862 adjacent_controller = adjacent_controllers[0]
863 for node in controllers:
864 onosLog = OnosLog(host = node)
865 ##check the logs for storage exception
866 _, output = onosLog.get_log(('ERROR', 'Exception',))
867 if output and output.find('StorageException$Timeout') >= 0:
868 log_test.info('\nStorage Exception Timeout found on node: %s\n' %node)
869 log_test.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
870 log_test.info('\n' + '-' * 50 + '\n')
871 log_test.info('%s' %output)
872 log_test.info('\n' + '-' * 50 + '\n')
873 failed = self.verify_leaders(controllers)
874 if failed:
875 log_test.info('Leaders command failed on nodes: %s' %failed)
876 log_test.error('Test failed on ITERATION %d' %iteration)
877 CordLogger.archive_results(self._testMethodName,
878 controllers = controllers,
879 iteration = 'FAILED',
880 archive_partition = self.ARCHIVE_PARTITION)
881 assert_equal(len(failed), 0)
882 return controller
883
884 try:
885 ips = self.get_cluster_current_member_ips(controller = adjacent_controller)
886 log_test.info('ONOS cluster formed with controllers: %s' %ips)
887 st = True
888 except:
889 st = False
890
891 failed = self.verify_leaders(controllers)
892 if failed:
893 log_test.error('Test failed on ITERATION %d' %iteration)
894 CordLogger.archive_results(self._testMethodName,
895 controllers = controllers,
896 iteration = 'FAILED',
897 archive_partition = self.ARCHIVE_PARTITION)
898 assert_equal(len(failed), 0)
899 if st is False:
900 log_test.info('No storage exception and ONOS cluster was not formed successfully')
901 else:
902 controller = None
903
904 return controller
905
906 next_controller = None
907 tries = self.ITERATIONS
908 for num in range(tries):
909 index = num % ctlr_len
910 #index = random.randrange(0, ctlr_len)
911 controller_name = onos_map[controllers[index]] if next_controller is None else onos_map[next_controller]
912 controller = onos_map[controller_name]
913 log_test.info('ITERATION: %d. Restarting Controller %s' %(num + 1, controller_name))
914 try:
915 #enable debug log for the other controllers before restarting this controller
916 adjacent_controllers = list( set(controllers) - set([controller]) )
917 self.log_set(controllers = adjacent_controllers)
918 self.log_set(app = 'io.atomix', controllers = adjacent_controllers)
919 if graceful is True:
920 log_test.info('Gracefully shutting down controller: %s' %controller)
921 self.onos_shutdown(controller)
922 cord_test_onos_restart(node = controller, timeout = 0)
923 self.log_set(controllers = controller)
924 self.log_set(app = 'io.atomix', controllers = controller)
925 time.sleep(60)
926 except:
927 time.sleep(5)
928 continue
929
930 #first archive the test case logs for this run
931 CordLogger.archive_results(self._testMethodName,
932 controllers = controllers,
933 iteration = 'iteration_{}'.format(num+1),
934 archive_partition = self.ARCHIVE_PARTITION)
935 next_controller = check_exception(num, controller = controller)
936
937 def onos_shutdown(self, controller = None):
938 status = True
939 self.cliEnter(controller = controller)
940 try:
941 self.cli.shutdown(timeout = 10)
942 except:
943 log_test.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
944 status = False
945
946 self.cliExit()
947 return status
948
A R Karthickc0a008f2017-10-04 18:35:25 -0700949 def test_dhcpl2relay_initialize(self):
A R Karthick760d1382017-10-05 13:48:40 -0700950 '''Configure the DHCP L2 relay app and start dhcpd'''
951 self.dhcpd_start()
A R Karthickc0a008f2017-10-04 18:35:25 -0700952
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000953 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
954 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000955 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
956 self.send_recv(mac=mac)
957
Thangavelu K S905e5482017-09-12 06:48:02 -0700958 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000959 mac = self.get_mac(iface)
960 onos_netcfg = OnosCtrl.get_config()
961 app_status = False
962 app_name = 'org.opencord.dhcpl2relay'
963 for app in onos_netcfg['apps']:
964 if app == app_name:
965 log_test.info('%s app is being installed'%app)
966 app_status = True
967 if app_status is not True:
968 log_test.info('%s app is not being installed'%app_name)
969 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000970
Thangavelu K S905e5482017-09-12 06:48:02 -0700971 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000972 mac = self.get_mac(iface)
973 onos_netcfg = OnosCtrl.get_config()
974 app_status = False
975 app_name = 'org.opencord.sadis'
976 for app in onos_netcfg['apps']:
977 if app == app_name:
978 log_test.info('%s app is being installed'%app)
979 app_status = True
980 if app_status is not True:
981 log_test.info('%s app is not being installed'%app_name)
982 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000983
Thangavelu K S905e5482017-09-12 06:48:02 -0700984 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000985 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700986 onos_netcfg = OnosCtrl.get_config()
987 app_status = False
988 app_name = 'org.opencord.dhcpl2relay'
989 for app in onos_netcfg['apps']:
990 if app == app_name:
991 log_test.info('%s app is being installed'%app)
992 if onos_netcfg['apps'][app_name] == {}:
993 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
994 else:
995 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
996 app_status = True
997 if app_status is not True:
998 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
999 assert_equal(True, False)
1000
1001 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
1002 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001003 onos_netcfg = OnosCtrl.get_config()
1004 app_status = False
1005 app_name = 'org.opencord.sadis'
1006 for app in onos_netcfg['apps']:
1007 if app == app_name:
1008 log_test.info('%s app is being installed'%app)
1009 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001010 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
1011 else:
1012 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
Thangavelu K S46063d02017-09-08 21:13:24 +00001013 app_status = True
1014 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001015 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
1016 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001017
Thangavelu K S905e5482017-09-12 06:48:02 -07001018 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001019 connect_point = self.default_onos_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints']
1020 log_test.info('Existing connect point of dhcp server is %s'%connect_point)
1021 relay_device_map1 = '{}/{}'.format(self.relay_device_id, random.randrange(1,5, 1))
1022 relay_device_map2 = '{}/{}'.format(self.relay_device_id, random.randrange(6,10, 1))
1023 relay_device_map3 = '{}/{}'.format(self.relay_device_id, random.randrange(10,16, 1))
1024 relay_device_map4 = '{}/{}'.format(self.relay_device_id, random.randrange(17,23, 1))
1025 dhcp_server_array_connectPoints = [connect_point[0],relay_device_map1,relay_device_map2,relay_device_map3,relay_device_map4]
1026 log_test.info('Added array of connect points of dhcp server is %s'%dhcp_server_array_connectPoints)
1027
Thangavelu K S46063d02017-09-08 21:13:24 +00001028 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -07001029 self.onos_load_config(self.default_onos_netcfg)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001030 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
1031 {"dhcpServerConnectPoints": dhcp_server_array_connectPoints}
1032 }
1033 }
1034 }
1035 self.onos_load_config(dhcp_dict)
Thangavelu K S46063d02017-09-08 21:13:24 +00001036 onos_netcfg = OnosCtrl.get_config()
1037 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -07001038 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +00001039 for app in onos_netcfg['apps']:
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001040 if app == app_name and onos_netcfg['apps'][app] != {}:
Thangavelu K S46063d02017-09-08 21:13:24 +00001041 log_test.info('%s app is being installed'%app)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001042 log_test.info('The network configuration is shown %s'%onos_netcfg['apps'][app])
1043 x = set(onos_netcfg['apps'][app_name]['dhcpl2relay']['dhcpServerConnectPoints']) & set(dhcp_server_array_connectPoints)
1044 if len(x) == len(dhcp_server_array_connectPoints):
1045 log_test.info('The loaded onos network configuration is = %s'%dhcp_server_array_connectPoints)
Thangavelu K S46063d02017-09-08 21:13:24 +00001046 app_status = True
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001047 break
Thangavelu K S46063d02017-09-08 21:13:24 +00001048 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001049 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
1050 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +00001051 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001052 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001053
Chetan Gaonker891302d2017-09-05 15:09:26 +00001054
Thangavelu K S905e5482017-09-12 06:48:02 -07001055 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001056 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -07001057 c_tag = 600
1058 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
1059 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1060 onos_netcfg = OnosCtrl.get_config()
1061 app_status = False
1062 app_name = 'org.opencord.sadis'
1063 for app in onos_netcfg['apps']:
1064 if app == app_name:
1065 log_test.info('%s app is being installed'%app)
1066 if onos_netcfg['apps'][app_name] == {}:
1067 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
1068 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
1069 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']))
1070 app_status = True
1071 if app_status is not True:
1072 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
1073 assert_equal(True, False)
1074 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1075 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1076 assert_equal(cip,None)
1077
1078 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
1079 iterations = 15
1080 for i in range(iterations):
1081 self.onos_ctrl.deactivate()
1082 time.sleep(3)
1083 self.onos_ctrl.activate()
1084 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
1085 mac = self.get_mac(iface)
1086 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1087 self.send_recv(mac=mac)
1088
1089 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
1090 mac = self.get_mac(iface)
1091 OnosCtrl.uninstall_app(self.sadis_app_file)
1092 OnosCtrl(self.sadis_app).deactivate()
1093 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1094 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1095 assert_equal(cip,None)
1096
1097 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
1098 mac = self.get_mac(iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001099 log_test.info('Uninstall the sadis app from onos ,app version = %s '%self.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -07001100 OnosCtrl.uninstall_app(self.sadis_app_file)
1101 OnosCtrl(self.sadis_app).deactivate()
1102 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1103 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1104 assert_equal(cip,None)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001105 log_test.info('Installing the sadis app in onos again, app version = %s '%self.sadis_app_file)
1106 OnosCtrl.install_app(self.sadis_app_file)
1107 OnosCtrl(self.sadis_app).activate()
1108 OnosCtrl(self.app).activate()
Thangavelu K S905e5482017-09-12 06:48:02 -07001109 #self.onos_load_config(self.sadis_configs['relay_config'])
1110 self.send_recv(mac=mac)
1111
1112 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
1113 pass
1114
1115 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
1116 pass
1117
1118 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
1119 pass
1120
1121 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
1122 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001123 subscriber_port_id = "uni-200"
1124 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
1125 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1126 onos_netcfg = OnosCtrl.get_config()
1127 app_status = False
1128 app_name = 'org.opencord.sadis'
1129 for app in onos_netcfg['apps']:
1130 if app == app_name:
1131 log_test.info('%s app is being installed'%app)
1132 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001133 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001134 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -07001135 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 +00001136 app_status = True
1137 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001138 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
1139
Thangavelu K S46063d02017-09-08 21:13:24 +00001140 assert_equal(True, False)
1141 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1142 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1143 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001144
Thangavelu K S905e5482017-09-12 06:48:02 -07001145 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001146 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -07001147 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +00001148 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
1149 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1150 onos_netcfg = OnosCtrl.get_config()
1151 app_status = False
1152 app_name = 'org.opencord.sadis'
1153 for app in onos_netcfg['apps']:
1154 if app == app_name:
1155 log_test.info('%s app is being installed'%app)
1156 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001157 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001158 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -07001159 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 +00001160 app_status = True
1161 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001162 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +00001163 assert_equal(True, False)
1164 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1165 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1166 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001167
Thangavelu K S905e5482017-09-12 06:48:02 -07001168 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001169 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001170 s_tag = 600
1171 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
1172 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1173 onos_netcfg = OnosCtrl.get_config()
1174 app_status = False
1175 app_name = 'org.opencord.sadis'
1176 for app in onos_netcfg['apps']:
1177 if app == app_name:
1178 log_test.info('%s app is being installed'%app)
1179 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001180 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001181 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -07001182 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 +00001183 app_status = True
1184 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001185 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +00001186 assert_equal(True, False)
1187 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1188 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1189 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001190
Thangavelu K S905e5482017-09-12 06:48:02 -07001191 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001192 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001193 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
1194 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1195 onos_netcfg = OnosCtrl.get_config()
1196 app_status = False
1197 app_name = 'org.opencord.sadis'
1198 for app in onos_netcfg['apps']:
1199 if app == app_name:
1200 log_test.info('%s app is being installed'%app)
1201 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001202 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001203 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -07001204 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 +00001205 app_status = True
1206 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001207 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +00001208 assert_equal(True, False)
1209 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1210 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1211 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001212
Thangavelu K S905e5482017-09-12 06:48:02 -07001213 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001214 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001215 nas_port_id = "uni-509"
1216 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
1217 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1218 onos_netcfg = OnosCtrl.get_config()
1219 app_status = False
1220 app_name = 'org.opencord.sadis'
1221 for app in onos_netcfg['apps']:
1222 if app == app_name:
1223 log_test.info('%s app is being installed'%app)
1224 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001225 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001226 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -07001227 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 +00001228 app_status = True
1229 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001230 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +00001231 assert_equal(True, False)
1232 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1233 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1234 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001235
Thangavelu K S905e5482017-09-12 06:48:02 -07001236 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001237 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001238 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
1239 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1240 onos_netcfg = OnosCtrl.get_config()
1241 app_status = False
1242 app_name = 'org.opencord.sadis'
1243 for app in onos_netcfg['apps']:
1244 if app == app_name:
1245 log_test.info('%s app is being installed'%app)
1246 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001247 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001248 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -07001249 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 +00001250 app_status = True
1251 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -07001252 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +00001253 assert_equal(True, False)
1254 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1255 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1256 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001257
Thangavelu K S905e5482017-09-12 06:48:02 -07001258 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +00001259 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +00001260 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
1261 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
1262 self.cord_sadis_load(sadis_info = invalid_sadis_info)
1263 onos_netcfg = OnosCtrl.get_config()
1264 app_status = False
1265 app_name = 'org.opencord.sadis'
1266 for app in onos_netcfg['apps']:
1267 if app == app_name:
1268 log_test.info('%s app is being installed'%app)
1269 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -07001270 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +00001271 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -07001272 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 +00001273 app_status = True
1274 if app_status is not True:
1275 assert_equal(True, False)
1276 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1277 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1278 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +00001279
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001280 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
1281 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001282 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1283 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
1284 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001285 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001286
1287 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
1288 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001289 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1290 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
1291 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001292 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001293
1294 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
1295 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001296 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1297 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
1298 assert_equal(cip,None)
1299 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
1300
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001301 ### We can't test this on single uni port setup, hence its not to test
Thangavelu K Saec97e62017-10-25 03:09:36 -07001302 @nottest
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001303 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
1304 mac = self.get_mac(iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001305 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001306 ip_map = {}
1307 for i in range(requests):
1308 #mac = RandMAC()._fix()
1309 #log_test.info('mac is %s'%mac)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001310 cip, sip = self.send_recv(mac=mac, update_seed = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001311 if ip_map.has_key(cip):
1312 log_test.info('IP %s given out multiple times' %cip)
1313 assert_equal(False, ip_map.has_key(cip))
1314 ip_map[cip] = sip
1315 time.sleep(1)
1316
1317 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
1318 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001319 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
1320 cip, sip = self.send_recv(mac=mac)
1321 log_test.info('Releasing ip %s to server %s' %(cip, sip))
1322 assert_equal(self.dhcp.release(cip), True)
1323 log_test.info('Triggering DHCP discover again after release')
1324 cip2, sip2 = self.send_recv(mac=mac)
1325 log_test.info('Verifying released IP was given back on rediscover')
1326 assert_equal(cip, cip2)
1327 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
1328 assert_equal(self.dhcp.release(cip2), True)
1329
Thangavelu K Saec97e62017-10-25 03:09:36 -07001330 @nottest
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001331 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
1332 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001333 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
1334 ip_map = {}
1335 for i in range(10):
1336 cip, sip = self.send_recv(mac=mac, update_seed = True)
1337 if ip_map.has_key(cip):
1338 log_test.info('IP %s given out multiple times' %cip)
1339 assert_equal(False, ip_map.has_key(cip))
1340 ip_map[cip] = sip
1341
1342 for ip in ip_map.keys():
1343 log_test.info('Releasing IP %s' %ip)
1344 assert_equal(self.dhcp.release(ip), True)
1345
1346 ip_map2 = {}
1347 log_test.info('Triggering DHCP discover again after release')
1348 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
1349 for i in range(len(ip_map.keys())):
1350 cip, sip = self.send_recv(mac=mac, update_seed = True)
1351 ip_map2[cip] = sip
1352
1353 log_test.info('Verifying released IPs were given back on rediscover')
1354 if ip_map != ip_map2:
1355 log_test.info('Map before release %s' %ip_map)
1356 log_test.info('Map after release %s' %ip_map2)
1357 assert_equal(ip_map, ip_map2)
1358
Thangavelu K Saec97e62017-10-25 03:09:36 -07001359 @nottest
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001360 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
1361 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001362 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
1363 log_test.info('Verifying 1 ')
1364 count = 0
1365 while True:
1366 #mac = RandMAC()._fix()
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001367 cip, sip = self.send_recv(mac=mac,update_seed = True,validate = False)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001368 if cip is None:
1369 break
1370 else:
1371 count += 1
1372 assert_equal(count,91)
1373 log_test.info('Verifying 2 ')
1374 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
1375 assert_equal(cip, None)
1376 assert_equal(sip, None)
1377
1378 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
1379 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001380 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001381 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001382 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
1383 (cip, sip, mac) )
1384 assert_not_equal(cip, None)
1385 log_test.info('Triggering DHCP discover again.')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001386 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001387 assert_equal(new_cip, cip)
1388 log_test.info('got same ip to smae the client when sent discover again, as expected')
1389
1390 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
1391 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001392 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1393 log_test.info('Sending DHCP discover and DHCP request.')
1394 cip, sip = self.send_recv(mac=mac)
1395 mac = self.dhcp.get_mac(cip)[0]
1396 log_test.info("Sending DHCP request again.")
1397 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1398 assert_equal(new_cip, cip)
1399 log_test.info('got same ip to smae the client when sent request again, as expected')
1400
1401 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
1402 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001403 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001404 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001405 assert_equal(cip,self.dhcp.seed_ip)
1406 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
1407 (cip, sip, mac) )
1408
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001409 def test_dhcpl2relay_with_clients_desired_address_out_of_pool(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001410 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001411 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001412 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001413 assert_not_equal(cip,None)
1414 assert_not_equal(cip,self.dhcp.seed_ip)
1415 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
1416
1417 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
1418 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001419 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001420 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001421 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1422 (cip, sip, mac) )
1423 assert_not_equal(cip, None)
1424 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
1425 assert_equal(new_cip, None)
1426 log_test.info('server sent NAK packet when requested other IP than that server offered')
1427
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001428 def test_dhcpl2relay_client_requests_with_specific_lease_time_in_discover_message(self, iface = 'veth0',lease_time=700):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001429 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001430 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
1431 self.dhcp.return_option = 'lease'
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001432 cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time=True,lease_value=lease_time)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001433 assert_equal(lval, lease_time)
1434 log_test.info('dhcp server offered IP address with client requested lease time')
1435
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001436 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001437 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001438 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001439 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001440 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1441 (cip, sip, mac) )
1442 assert_not_equal(cip, None)
1443 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1444 log_test.info('client rebooting...')
1445 os.system('ifconfig '+iface+' down')
1446 time.sleep(5)
1447 os.system('ifconfig '+iface+' up')
1448 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
1449 assert_equal(new_cip2, cip)
1450 log_test.info('client got same IP after reboot, as expected')
1451
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001452 def test_dhcpl2relay_after_server_shutting_down(self, iface = 'veth0'):
1453 self.get_dhcpd_process()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001454 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001455 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001456 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001457 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1458 (cip, sip, mac) )
1459 assert_not_equal(cip, None)
1460 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1461 log_test.info('server rebooting...')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001462 try:
1463 if self.dhcpd_stop(remote_controller = True, dhcpd = 'stop'):
1464 time.sleep(5)
1465 log_test.info('DHCP server is stopped ')
1466 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1467 assert_equal(new_cip,None)
1468 else:
1469 log_test.info('DHCP server is not stopped' )
1470 assert_equal(new_cip,None)
1471 finally:
1472 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001473
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001474 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
1475 self.get_dhcpd_process()
1476 mac = self.get_mac(iface)
1477 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1478 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1479 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1480 (cip, sip, mac) )
1481 assert_not_equal(cip, None)
1482 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1483 log_test.info('server rebooting...')
1484 try:
1485 if self.dhcpd_stop(remote_controller = True, dhcpd = 'restart'):
1486 time.sleep(5)
1487 log_test.info('DHCP server is rebooted')
1488 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1489 assert_equal(new_cip,cip)
1490 else:
1491 log_test.info('DHCP server is not stopped' )
1492 assert_equal(new_cip,None)
1493 finally:
1494 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
1495
Thangavelu K Saec97e62017-10-25 03:09:36 -07001496 def test_dhcpl2relay_after_server_stop_start(self, iface = 'veth0'):
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001497 self.get_dhcpd_process()
1498 mac = self.get_mac(iface)
1499 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1500 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1501 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1502 (cip, sip, mac) )
1503 assert_not_equal(cip, None)
1504 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1505 log_test.info('server rebooting...')
1506 try:
1507 if self.dhcpd_stop(remote_controller = True, dhcpd = 'stop'):
1508 time.sleep(5)
1509 log_test.info('DHCP server is stopped ')
1510 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1511 assert_equal(new_cip,None)
1512 else:
1513 log_test.info('DHCP server is not stoppped' )
1514 assert_equal(new_cip,None)
1515 self.dhcpd_stop(remote_controller = True, dhcpd = 'start')
1516 log_test.info('DHCP server is started ')
1517 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1518 assert_equal(new_cip, cip)
1519 log_test.info('client got same IP after server rebooted, as expected')
1520 finally:
1521 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
1522
1523 def test_dhcpl2relay_with_specific_lease_time_in_discover_and_without_in_request_packet(self, iface = 'veth0',lease_time=700):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001524 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001525 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1526 self.dhcp.return_option = 'lease'
1527 log_test.info('Sending DHCP discover with lease time of 700')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001528 cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time = True, lease_value=lease_time)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001529 assert_equal(lval,lease_time)
1530 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
1531 assert_equal(new_cip,cip)
1532 assert_not_equal(lval, lease_time) #Negative Test Case
1533 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
1534
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001535 def test_dhcpl2relay_with_specific_lease_time_in_request_and_without_in_discover_packet(self, iface = 'veth0',lease_time=800):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001536 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001537 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001538 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001539 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
1540 assert_equal(new_cip,cip)
1541 assert_equal(lval, lease_time)
1542 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
1543
Thangavelu K Saec97e62017-10-25 03:09:36 -07001544 @nottest
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001545 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001546 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001547 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001548 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001549 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1550 (cip, sip, mac) )
1551 assert_not_equal(cip,None)
1552 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
Thangavelu K Saec97e62017-10-25 03:09:36 -07001553 log_test.info('waiting for renew time.. a= %s b= %s c= %s'%(new_cip,new_sip,lval))
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001554 time.sleep(lval)
1555 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
1556 assert_equal(latest_cip, cip)
1557 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1558
Thangavelu K Saec97e62017-10-25 03:09:36 -07001559 @nottest
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001560 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001561 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001562 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001563 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001564 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1565 (cip, sip, mac) )
1566 assert_not_equal(cip,None)
1567 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1568 log_test.info('waiting for rebind time..')
1569 time.sleep(lval)
1570 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1571 assert_equal(latest_cip, cip)
1572 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1573
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001574 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001575 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001576 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1577 expected_subnet = '255.255.255.0'
1578 self.dhcp.return_option = 'subnet'
1579
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001580 cip, sip, mac, subnet_mask = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001581 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1582 (cip, sip, mac) )
1583 assert_equal(subnet_mask,expected_subnet)
1584 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1585
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001586 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001587 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001588 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1589
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001590 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001591 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1592 (cip, sip, mac) )
1593 assert_not_equal(cip,None)
1594 self.dhcp.send_different_option = 'subnet'
1595 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1596 assert_equal(new_cip, cip)
1597 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1598
Thangavelu K Saec97e62017-10-25 03:09:36 -07001599 @nottest
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001600 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001601 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001602 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1603 expected_router_address = '20.20.20.1'
1604 self.dhcp.return_option = 'router'
1605
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001606 cip, sip, mac, router_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001607 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1608 (cip, sip, mac) )
1609 assert_equal(expected_router_address, router_address_value)
1610 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1611
Thangavelu K Saec97e62017-10-25 03:09:36 -07001612 @nottest
1613 def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001614 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001615 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1616
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001617 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001618 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1619 (cip, sip, mac) )
1620 assert_not_equal(cip,None)
1621 self.dhcp.send_different_option = 'router'
1622 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1623 assert_equal(new_cip, cip)
1624 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1625
1626 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1627 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001628 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1629 expected_broadcast_address = '192.168.1.255'
1630 self.dhcp.return_option = 'broadcast_address'
1631
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001632 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001633 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1634 (cip, sip, mac) )
1635 assert_equal(expected_broadcast_address, broadcast_address_value)
1636 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1637
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001638 def test_dhcpl2relay_by_client_sending_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001639 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001640 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1641
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001642 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001643 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1644 (cip, sip, mac) )
1645 assert_not_equal(cip,None)
1646 self.dhcp.send_different_option = 'broadcast_address'
1647 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1648 assert_equal(new_cip, cip)
1649 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1650
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001651 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001652 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001653 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1654 expected_dns_address = '192.168.1.1'
1655 self.dhcp.return_option = 'dns'
1656
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001657 cip, sip, mac, dns_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001658 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1659 (cip, sip, mac) )
1660 assert_equal(expected_dns_address, dns_address_value)
1661 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1662
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001663 def test_dhcpl2relay_by_client_sending_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001664 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001665 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1666
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001667 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001668 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1669 (cip, sip, mac) )
1670 assert_not_equal(cip,None)
1671 self.dhcp.send_different_option = 'dns'
1672 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1673 assert_equal(new_cip, cip)
1674 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1675
1676
1677 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1678
1679 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001680 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001681 log_test.info("Statistics for run %d",i)
1682 log_test.info("----------------------------------------------------------------------------------")
1683 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1684 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1685 log_test.info("----------------------------------------------------------------------------------")
1686 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1687
1688 log_test.info("Final Statistics for total transactions")
1689 log_test.info("----------------------------------------------------------------------------------")
1690 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1691 log_test.info(" %d %d %d %d" %(self.transactions,
1692 self.total_success, self.total_failure, self.running_time))
1693 log_test.info("----------------------------------------------------------------------------------")
1694 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1695
1696 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1697
1698 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001699 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001700 log_test.info("Statistics for run %d",i)
1701 log_test.info("----------------------------------------------------------------------------------")
1702 log_test.info("No. of consecutive successful transactions Running Time ")
1703 log_test.info(" %d %d " %(self.ip_count, self.diff))
1704 log_test.info("----------------------------------------------------------------------------------")
1705 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1706 log_test.info("----------------------------------------------------------------------------------")
1707
1708 log_test.info("Final Statistics for total successful transactions")
1709 log_test.info("----------------------------------------------------------------------------------")
1710 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1711 log_test.info(" %d %d %d " %(self.transactions,
1712 self.total_success, self.running_time))
1713 log_test.info("----------------------------------------------------------------------------------")
1714 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1715 log_test.info("----------------------------------------------------------------------------------")
1716
1717 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1718
1719 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001720 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001721 log_test.info("----------------------------------------------------------------------------------")
1722 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1723 log_test.info("----------------------------------------------------------------------------------")
1724 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1725 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1726 log_test.info("----------------------------------------------------------------------------------")
1727 log_test.info("No. of clients per second in run %d:%f "
1728 %(i, self.transaction_count))
1729 log_test.info("----------------------------------------------------------------------------------")
1730 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1731 log_test.info("----------------------------------------------------------------------------------")
1732 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1733 log_test.info(" %d %d %d %d" %(self.transactions,
1734 self.total_success, self.total_failure, self.running_time))
1735 log_test.info("----------------------------------------------------------------------------------")
1736 log_test.info("Average no. of clients per second: %d ",
1737 round(self.transactions/self.running_time,0))
1738 log_test.info("----------------------------------------------------------------------------------")
1739
1740 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1741
1742 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001743 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001744 log_test.info("----------------------------------------------------------------------------------")
1745 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1746 log_test.info("----------------------------------------------------------------------------------")
1747 log_test.info("No. of consecutive successful transactions Running Time ")
1748 log_test.info(" %d %d " %(self.ip_count, self.diff))
1749 log_test.info("----------------------------------------------------------------------------------")
1750 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1751 log_test.info("----------------------------------------------------------------------------------")
1752
1753 log_test.info("Final Statistics for total successful transactions")
1754 log_test.info("----------------------------------------------------------------------------------")
1755 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1756 log_test.info(" %d %d %d " %(self.transactions,
1757 self.total_success, self.running_time))
1758 log_test.info("----------------------------------------------------------------------------------")
1759 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1760 log_test.info("----------------------------------------------------------------------------------")
1761
1762 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001763 for key in (key for key in g_subscriber_port_map if key < 100):
1764 self.host_load(g_subscriber_port_map[key])
1765
1766 def thread_fun(i):
1767 mac = self.get_mac('veth{}'.format(i))
1768 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1769 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1770 self.lock.acquire()
1771
1772 if cip:
1773 self.ip_count += 1
1774
1775 elif cip is None:
1776 self.failure_count += 1
1777
1778 self.lock.notify_all()
1779 self.lock.release()
1780
1781 for i in range (1,4):
1782 self.ip_count = 0
1783 self.failure_count = 0
1784 self.start_time = 0
1785 self.diff = 0
1786 self.transaction_count = 0
1787 self.start_time = time.time()
1788
1789 while self.diff <= 60:
1790 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1791 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1792 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1793 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1794 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1795 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1796
1797 t.start()
1798 t1.start()
1799 t2.start()
1800 t3.start()
1801 t4.start()
1802 t5.start()
1803
1804 t.join()
1805 t1.join()
1806 t2.join()
1807 t3.join()
1808 t4.join()
1809 t5.join()
1810
1811 self.diff = round(time.time() - self.start_time, 0)
1812
1813 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1814
1815 self.transactions += (self.ip_count+self.failure_count)
1816 self.running_time += self.diff
1817 self.total_success += self.ip_count
1818 self.total_failure += self.failure_count
1819
1820
1821 log_test.info("----------------------------------------------------------------------------------")
1822 log_test.info("Statistics for run %d",i)
1823 log_test.info("----------------------------------------------------------------------------------")
1824 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1825 log_test.info(" %d %d %d %d"
1826 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1827 log_test.info("----------------------------------------------------------------------------------")
1828 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1829 log_test.info("----------------------------------------------------------------------------------")
1830
1831 log_test.info("----------------------------------------------------------------------------------")
1832 log_test.info("Final Statistics for total transactions")
1833 log_test.info("----------------------------------------------------------------------------------")
1834 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1835 log_test.info(" %d %d %d %d" %(self.transactions,
1836 self.total_success, self.total_failure, self.running_time))
1837
1838 log_test.info("----------------------------------------------------------------------------------")
1839 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1840 log_test.info("----------------------------------------------------------------------------------")
1841
Thangavelu K Saec97e62017-10-25 03:09:36 -07001842 @nottest
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001843 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001844 failure_dir = {}
1845
1846 for key in (key for key in g_subscriber_port_map if key != 100):
1847 self.host_load(g_subscriber_port_map[key])
1848
1849 def thread_fun(i, j):
1850# log_test.info("Thread Name:%s",current_thread().name)
1851# failure_dir[current_thread().name] = True
1852 while failure_dir.has_key(current_thread().name) is False:
1853 mac = RandMAC()._fix()
1854 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1855 i += 2
1856 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1857 self.lock.acquire()
1858
1859 if cip:
1860 self.ip_count += 1
1861 self.lock.notify_all()
1862 self.lock.release()
1863 elif cip is None:
1864 self.failure_count += 1
1865 failure_dir[current_thread().name] = True
1866 self.lock.notify_all()
1867 self.lock.release()
1868 break
1869# self.lock.notify_all()
1870# self.lock.release()
1871
1872 for i in range (1,4):
1873 failure_dir = {}
1874 self.ip_count = 0
1875 self.failure_count = 0
1876 self.start_time = 0
1877 self.diff = 0
1878 self.transaction_count = 0
1879 self.start_time = time.time()
1880
1881 while len(failure_dir) != 6:
1882 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1883 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1884 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1885 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1886 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1887 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1888
1889 t.start()
1890 t1.start()
1891 t2.start()
1892 t3.start()
1893 t4.start()
1894 t5.start()
1895
1896 t.join()
1897 t1.join()
1898 t2.join()
1899 t3.join()
1900 t4.join()
1901 t5.join()
1902
1903 self.diff = round(time.time() - self.start_time, 0)
1904 self.transaction_count = round((self.ip_count)/self.diff, 2)
1905
1906 self.transactions += (self.ip_count+self.failure_count)
1907 self.running_time += self.diff
1908 self.total_success += self.ip_count
1909 self.total_failure += self.failure_count
1910
1911
1912 log_test.info("Statistics for run %d",i)
1913 log_test.info("----------------------------------------------------------------------------------")
1914 log_test.info("No. of consecutive successful transactions Running Time ")
1915 log_test.info(" %d %d " %(self.ip_count, self.diff))
1916 log_test.info("----------------------------------------------------------------------------------")
1917 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1918 log_test.info("----------------------------------------------------------------------------------")
1919
1920 log_test.info("Final Statistics for total successful transactions")
1921 log_test.info("----------------------------------------------------------------------------------")
1922 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1923 log_test.info(" %d %d %d " %(self.transactions,
1924 self.total_success, self.running_time))
1925 log_test.info("----------------------------------------------------------------------------------")
1926 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1927 log_test.info("----------------------------------------------------------------------------------")
1928
Thangavelu K Saec97e62017-10-25 03:09:36 -07001929 @nottest
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001930 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001931 for key in (key for key in g_subscriber_port_map if key < 100):
1932 self.host_load(g_subscriber_port_map[key])
1933
1934 def thread_fun(i):
1935# mac = self.get_mac('veth{}'.format(i))
1936 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1937 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1938 self.lock.acquire()
1939
1940 if cip:
1941 self.ip_count += 1
1942 elif cip is None:
1943 self.failure_count += 1
1944
1945 self.lock.notify_all()
1946 self.lock.release()
1947
1948 for i in range (1,4):
1949 self.ip_count = 0
1950 self.failure_count = 0
1951 self.start_time = 0
1952 self.diff = 0
1953 self.transaction_count = 0
1954 self.start_time = time.time()
1955
1956 while self.diff <= 60:
1957 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1958 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1959 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1960 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1961 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1962 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1963
1964 t.start()
1965 t1.start()
1966 t2.start()
1967 t3.start()
1968 t4.start()
1969 t5.start()
1970
1971 t.join()
1972 t1.join()
1973 t2.join()
1974 t3.join()
1975 t4.join()
1976 t5.join()
1977
1978 self.diff = round(time.time() - self.start_time, 0)
1979 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1980 self.transactions += (self.ip_count+self.failure_count)
1981 self.running_time += self.diff
1982 self.total_success += self.ip_count
1983 self.total_failure += self.failure_count
1984
1985 log_test.info("----------------------------------------------------------------------------------")
1986 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1987 log_test.info("----------------------------------------------------------------------------------")
1988 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1989 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1990 log_test.info("----------------------------------------------------------------------------------")
1991 log_test.info("No. of clients per second in run %d:%f "
1992 %(i, self.transaction_count))
1993 log_test.info("----------------------------------------------------------------------------------")
1994
1995 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1996 log_test.info("----------------------------------------------------------------------------------")
1997 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1998 log_test.info(" %d %d %d %d" %(self.transactions,
1999 self.total_success, self.total_failure, self.running_time))
2000 log_test.info("----------------------------------------------------------------------------------")
2001 log_test.info("Average no. of clients per second: %d ",
2002 round(self.transactions/self.running_time,0))
2003 log_test.info("----------------------------------------------------------------------------------")
2004
Thangavelu K Saec97e62017-10-25 03:09:36 -07002005 @nottest
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00002006 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00002007 mac = self.get_mac(iface)
2008 self.host_load(iface)
2009 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2010 cip, sip, mac, _ = self.dhcp.only_discover()
2011 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
2012 (cip, sip, mac) )
2013 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
2014 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
2015 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
2016 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
2017 (new_cip, new_sip, new_mac) )
2018 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
2019 log_test.info("Now sending DHCP Request for old DHCP discover.")
2020 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2021 if new_cip is None:
2022 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
2023 %(new_cip, new_sip, new_mac) )
2024 elif new_cip:
2025 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.'
2026 %(new_cip, new_sip, new_mac, new_cip) )
2027 assert_equal(new_cip, None)
Thangavelu K Saec97e62017-10-25 03:09:36 -07002028
2029 ##### All cluster scenarios on dhcpl2relay has to validate on voltha-setup from client server.
2030 @nottest
2031 def test_dhcpl2relay_releasing_dhcp_ip_after_cluster_master_change(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2032 status = self.verify_cluster_status(onos_instances=onos_instances)
2033 assert_equal(status, True)
2034 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2035 assert_equal(len(standbys),(onos_instances-1))
2036 mac = self.get_mac(iface)
2037 self.cord_l2_relay_load
2038 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2039 cip, sip = self.send_recv(mac=mac)
2040 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2041 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=standbys[0])
2042 self.cord_l2_relay_load
2043 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2044 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2045 try:
2046 assert_equal(self.dhcp.release(cip), True)
2047 log_test.info('Triggering DHCP discover again after release')
2048 self.cord_l2_relay_load
2049 cip2, sip2 = self.send_recv(mac=mac)
2050 log_test.info('Verifying released IP was given back on rediscover')
2051 assert_equal(cip, cip2)
2052 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2053 assert_equal(self.dhcp.release(cip2), True)
2054 finally:
2055 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2056
2057
2058 @nottest
2059 def test_dhcpl2relay_releasing_dhcp_ip_after_cluster_master_withdraw_membership(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2060 status = self.verify_cluster_status(onos_instances=onos_instances)
2061 assert_equal(status, True)
2062 master,standbys = self.get_cluster_current_member_ips(device_id=self.relay_device_id)
2063 assert_equal(len(standbys),(onos_instances-1))
2064 mac = self.get_mac(iface)
2065 self.cord_l2_relay_load
2066 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2067 cip, sip = self.send_recv(mac=mac)
2068 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2069 self.withdraw_cluster_current_mastership(device_id = self.relay_device_id,master_ip=master)
2070 self.cord_l2_relay_load
2071 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2072 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2073 try:
2074 assert_equal(self.dhcp.release(cip), True)
2075 log_test.info('Triggering DHCP discover again after release')
2076 self.cord_l2_relay_load
2077 cip2, sip2 = self.send_recv(mac=mac)
2078 log_test.info('Verifying released IP was given back on rediscover')
2079 assert_equal(cip, cip2)
2080 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2081 assert_equal(self.dhcp.release(cip2), True)
2082 finally:
2083 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2084
2085 @nottest
2086 def test_dhcpl2relay_releasing_dhcp_ip_after_restart_cluster(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2087 status = self.verify_cluster_status(onos_instances=onos_instances)
2088 assert_equal(status, True)
2089 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2090 assert_equal(len(standbys),(onos_instances-1))
2091 mac = self.get_mac(iface)
2092 self.cord_l2_relay_load
2093 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2094 cip, sip = self.send_recv(mac=mac)
2095 log_test.info('Restarting cluster whose master cluster= %s standby = %s'%(master, standbys))
2096 self.cord_test_onos_restart()
2097 self.cord_l2_relay_load
2098 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2099 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2100 try:
2101 assert_equal(self.dhcp.release(cip), True)
2102 log_test.info('Triggering DHCP discover again after release')
2103 self.cord_l2_relay_load
2104 cip2, sip2 = self.send_recv(mac=mac)
2105 log_test.info('Verifying released IP was given back on rediscover')
2106 assert_equal(cip, cip2)
2107 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2108 assert_equal(self.dhcp.release(cip2), True)
2109 finally:
2110 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2111
2112
2113 @nottest
2114 def test_dhcpl2relay_releasing_dhcp_ip_after_cluster_master_down(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2115 status = self.verify_cluster_status(onos_instances=onos_instances)
2116 assert_equal(status, True)
2117 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2118 assert_equal(len(standbys),(onos_instances-1))
2119 mac = self.get_mac(iface)
2120 self.cord_l2_relay_load
2121 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2122 cip, sip = self.send_recv(mac=mac)
2123 log_test.info('Restarting cluster whose master cluster= %s standby = %s'%(master, standbys))
2124 cord_test_onos_shutdown(node = master)
2125 self.cord_l2_relay_load
2126 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2127 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2128 try:
2129 assert_equal(self.dhcp.release(cip), True)
2130 log_test.info('Triggering DHCP discover again after release')
2131 self.cord_l2_relay_load
2132 cip2, sip2 = self.send_recv(mac=mac)
2133 log_test.info('Verifying released IP was given back on rediscover')
2134 assert_equal(cip, cip2)
2135 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2136 assert_equal(self.dhcp.release(cip2), True)
2137 finally:
2138 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2139
2140 @nottest
2141 def test_dhcpl2relay_releasing_dhcp_ip_after_cluster_standby_down(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2142 status = self.verify_cluster_status(onos_instances=onos_instances)
2143 assert_equal(status, True)
2144 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2145 assert_equal(len(standbys),(onos_instances-1))
2146 mac = self.get_mac(iface)
2147 self.cord_l2_relay_load
2148 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2149 cip, sip = self.send_recv(mac=mac)
2150 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2151 cord_test_onos_shutdown(node = standbys[0])
2152 self.cord_l2_relay_load
2153 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2154 try:
2155 assert_equal(self.dhcp.release(cip), True)
2156 log_test.info('Triggering DHCP discover again after release')
2157 self.cord_l2_relay_load
2158 cip2, sip2 = self.send_recv(mac=mac)
2159 log_test.info('Verifying released IP was given back on rediscover')
2160 assert_equal(cip, cip2)
2161 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2162 assert_equal(self.dhcp.release(cip2), True)
2163 finally:
2164 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2165
2166 @nottest
2167 def test_dhcpl2relay_releasing_dhcp_ip_after_adding_two_members_to_cluster(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2168 status = self.verify_cluster_status(onos_instances=onos_instances)
2169 assert_equal(status, True)
2170 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2171 assert_equal(len(standbys),(onos_instances-1))
2172 mac = self.get_mac(iface)
2173 self.cord_l2_relay_load
2174 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2175 cip, sip = self.send_recv(mac=mac)
2176 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2177 cord_test_onos_shutdown(node = standbys[0])
2178 self.cord_l2_relay_load
2179 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2180 try:
2181 assert_equal(self.dhcp.release(cip), True)
2182 log_test.info('Triggering DHCP discover again after release')
2183 self.cord_l2_relay_load
2184 cip2, sip2 = self.send_recv(mac=mac)
2185 log_test.info('Verifying released IP was given back on rediscover')
2186 assert_equal(cip, cip2)
2187 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2188 assert_equal(self.dhcp.release(cip2), True)
2189 finally:
2190 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2191
2192 @nottest
2193 def test_dhcpl2relay_releasing_dhcp_ip_after_restart_cluster_for_10_times(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
2194 status = self.verify_cluster_status(onos_instances=onos_instances)
2195 assert_equal(status, True)
2196 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2197 assert_equal(len(standbys),(onos_instances-1))
2198 mac = self.get_mac(iface)
2199 self.cord_l2_relay_load
2200 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2201 cip, sip = self.send_recv(mac=mac)
2202 log_test.info('Restarting cluster whose master cluster= %s standby = %s'%(master, standbys))
2203 for i in range(10):
2204 self.cord_test_onos_restart()
2205 self.cord_l2_relay_load
2206 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2207 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2208 try:
2209 assert_equal(self.dhcp.release(cip), True)
2210 log_test.info('Triggering DHCP discover again after release')
2211 self.cord_l2_relay_load
2212 cip2, sip2 = self.send_recv(mac=mac)
2213 log_test.info('Verifying released IP was given back on rediscover')
2214 assert_equal(cip, cip2)
2215 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2216 assert_equal(self.dhcp.release(cip2), True)
2217 finally:
2218 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2219
2220
2221 @nottest
2222 def test_dhcpl2relay_on_cluster_with_master_controller_only_restarts(self, iface = 'veth0'):
2223 pass
2224 status = self.verify_cluster_status(onos_instances=onos_instances)
2225 assert_equal(status, True)
2226 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2227 assert_equal(len(standbys),(onos_instances-1))
2228 mac = self.get_mac(iface)
2229 self.cord_l2_relay_load
2230 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2231 cip, sip = self.send_recv(mac=mac)
2232 log_test.info('Restarting cluster whose master cluster= %s standby = %s'%(master, standbys))
2233 self.cord_test_onos_restart(node = master)
2234 self.cord_l2_relay_load
2235 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2236 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2237 try:
2238 assert_equal(self.dhcp.release(cip), True)
2239 log_test.info('Triggering DHCP discover again after release')
2240 self.cord_l2_relay_load
2241 cip2, sip2 = self.send_recv(mac=mac)
2242 log_test.info('Verifying released IP was given back on rediscover')
2243 assert_equal(cip, cip2)
2244 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2245 assert_equal(self.dhcp.release(cip2), True)
2246 finally:
2247 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2248
2249 @nottest
2250 def test_dhcpl2relay_on_cluster_with_standby_controller_only_restarts(self, iface = 'veth0'):
2251 pass
2252 status = self.verify_cluster_status(onos_instances=onos_instances)
2253 assert_equal(status, True)
2254 master,standbys = self.get_cluster_current_master_standbys(device_id=self.relay_device_id)
2255 assert_equal(len(standbys),(onos_instances-1))
2256 mac = self.get_mac(iface)
2257 self.cord_l2_relay_load
2258 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2259 cip, sip = self.send_recv(mac=mac)
2260 log_test.info('Restarting cluster whose master cluster= %s standby = %s'%(master, standbys))
2261 self.cord_test_onos_restart(node = standbys[0])
2262 self.cord_l2_relay_load
2263 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2264 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2265 try:
2266 assert_equal(self.dhcp.release(cip), True)
2267 log_test.info('Triggering DHCP discover again after release')
2268 self.cord_l2_relay_load
2269 cip2, sip2 = self.send_recv(mac=mac)
2270 log_test.info('Verifying released IP was given back on rediscover')
2271 assert_equal(cip, cip2)
2272 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2273 assert_equal(self.dhcp.release(cip2), True)
2274 finally:
2275 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2276
2277
2278 @nottest
2279 def test_dhcpl2relay_by_removing_master_onos_instance(self, iface = 'veth0'):
2280 pass
2281 status = self.verify_cluster_status(onos_instances=onos_instances)
2282 assert_equal(status, True)
2283 master,standbys = self.get_cluster_current_member_ips(device_id=self.relay_device_id)
2284 assert_equal(len(standbys),(onos_instances-1))
2285 mac = self.get_mac(iface)
2286 self.cord_l2_relay_load
2287 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2288 cip, sip = self.send_recv(mac=mac)
2289 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2290 self.withdraw_cluster_current_mastership(device_id = self.relay_device_id,master_ip=master)
2291 self.cord_l2_relay_load
2292 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2293 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2294 try:
2295 assert_equal(self.dhcp.release(cip), True)
2296 log_test.info('Triggering DHCP discover again after release')
2297 self.cord_l2_relay_load
2298 cip2, sip2 = self.send_recv(mac=mac)
2299 log_test.info('Verifying released IP was given back on rediscover')
2300 assert_equal(cip, cip2)
2301 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2302 assert_equal(self.dhcp.release(cip2), True)
2303 finally:
2304 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2305
2306 @nottest
2307 def test_dhcpl2relay_by_removing_onos_instance_member(self, iface = 'veth0'):
2308
2309 pass
2310 status = self.verify_cluster_status(onos_instances=onos_instances)
2311 assert_equal(status, True)
2312 master,standbys = self.get_cluster_current_member_ips(device_id=self.relay_device_id)
2313 assert_equal(len(standbys),(onos_instances-1))
2314 mac = self.get_mac(iface)
2315 self.cord_l2_relay_load
2316 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2317 cip, sip = self.send_recv(mac=mac)
2318 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2319 self.withdraw_cluster_current_mastership(device_id = self.relay_device_id,master_ip=standbys[0])
2320 self.cord_l2_relay_load
2321 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2322 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2323 try:
2324 assert_equal(self.dhcp.release(cip), True)
2325 log_test.info('Triggering DHCP discover again after release')
2326 self.cord_l2_relay_load
2327 cip2, sip2 = self.send_recv(mac=mac)
2328 log_test.info('Verifying released IP was given back on rediscover')
2329 assert_equal(cip, cip2)
2330 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2331 assert_equal(self.dhcp.release(cip2), True)
2332 finally:
2333 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2334
2335 @nottest
2336 def test_dhcpl2relay_by_toggle_master_onos_instance_membership(self, iface = 'veth0'):
2337 pass
2338 status = self.verify_cluster_status(onos_instances=onos_instances)
2339 assert_equal(status, True)
2340 master,standbys = self.get_cluster_current_member_ips(device_id=self.relay_device_id)
2341 assert_equal(len(standbys),(onos_instances-1))
2342 mac = self.get_mac(iface)
2343 self.cord_l2_relay_load
2344 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2345 cip, sip = self.send_recv(mac=mac)
2346 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2347 self.withdraw_cluster_current_mastership(device_id = self.relay_device_id,master_ip=master)
2348 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2349 self.cord_l2_relay_load
2350 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2351 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2352 try:
2353 assert_equal(self.dhcp.release(cip), True)
2354 log_test.info('Triggering DHCP discover again after release')
2355 self.cord_l2_relay_load
2356 cip2, sip2 = self.send_recv(mac=mac)
2357 log_test.info('Verifying released IP was given back on rediscover')
2358 assert_equal(cip, cip2)
2359 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2360 assert_equal(self.dhcp.release(cip2), True)
2361 finally:
2362 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2363
2364
2365 @nottest
2366 def test_dhcpl2relay_by_toggle_standby_onos_instance_membership(self, iface = 'veth0'):
2367 pass
2368 status = self.verify_cluster_status(onos_instances=onos_instances)
2369 assert_equal(status, True)
2370 master,standbys = self.get_cluster_current_member_ips(device_id=self.relay_device_id)
2371 assert_equal(len(standbys),(onos_instances-1))
2372 mac = self.get_mac(iface)
2373 self.cord_l2_relay_load
2374 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2375 cip, sip = self.send_recv(mac=mac)
2376 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
2377 self.withdraw_cluster_current_mastership(device_id = self.relay_device_id,master_ip=master)
2378 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2379 self.cord_l2_relay_load
2380 log_test.info('Releasing ip %s to server %s' %(cip, sip))
2381 assert_equal(self.dhcprelay.dhcp.release(cip), True)
2382 try:
2383 assert_equal(self.dhcp.release(cip), True)
2384 log_test.info('Triggering DHCP discover again after release')
2385 self.cord_l2_relay_load
2386 cip2, sip2 = self.send_recv(mac=mac)
2387 log_test.info('Verifying released IP was given back on rediscover')
2388 assert_equal(cip, cip2)
2389 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
2390 assert_equal(self.dhcp.release(cip2), True)
2391 finally:
2392 self.change_master_current_cluster(device_id = self.relay_device_id,new_master=master)
2393
2394
2395 @nottest
2396 def test_dhcpl2relay_by_adding_onos_instance_member(self, iface = 'veth0'):
2397 pass
2398
2399
2400