blob: ce75ed491654dd7ea14c84652228489bc50f17c1 [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 Sd4d954f2017-10-12 20:05:30 +000037import os, sys, re
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
42from OltConfig import OltConfig
A R Karthickc0a008f2017-10-04 18:35:25 -070043from CordTestServer import cord_test_onos_restart, cord_test_ovs_flow_add
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070044from CordTestConfig import setup_module, teardown_module
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000045from CordLogger import CordLogger
46from portmaps import g_subscriber_port_map
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070047from CordContainer import Onos
A R Karthicke7232092017-09-07 18:01:33 -070048from VolthaCtrl import VolthaCtrl
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000049import threading, random
50from threading import current_thread
A R Karthickc0a008f2017-10-04 18:35:25 -070051import requests
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000052log_test.setLevel('INFO')
53
54class dhcpl2relay_exchange(CordLogger):
55
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070056 VOLTHA_HOST = None
A R Karthicke7232092017-09-07 18:01:33 -070057 VOLTHA_REST_PORT = VolthaCtrl.REST_PORT
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070058 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
59 VOLTHA_OLT_TYPE = 'simulated_olt'
60 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
61 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthicke2168242017-10-05 16:50:07 -070062 TAGGED_TRAFFIC = False
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000063 app = 'org.opencord.dhcpl2relay'
64 sadis_app = 'org.opencord.sadis'
65 app_dhcp = 'org.onosproject.dhcp'
Thangavelu K S905e5482017-09-12 06:48:02 -070066 app_olt = 'org.onosproject.olt'
A R Karthickc0a008f2017-10-04 18:35:25 -070067 relay_interfaces = ()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000068 relay_interfaces_last = ()
69 interface_to_mac_map = {}
A R Karthickc0a008f2017-10-04 18:35:25 -070070 relay_vlan_map = {}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +000071 host_ip_map = {}
72 test_path = os.path.dirname(os.path.realpath(__file__))
73 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070074 dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar')
A R Karthickc0a008f2017-10-04 18:35:25 -070075 olt_app_file = os.path.join(test_path, '..', 'apps/olt-app-3.0-SNAPSHOT.oar')
Thangavelu K Sa61d1da2017-09-05 05:32:21 -070076 sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar')
77 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 +000078 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
79 default_options = [ ('subnet-mask', '255.255.255.0'),
80 ('broadcast-address', '192.168.1.255'),
81 ('domain-name-servers', '192.168.1.1'),
82 ('domain-name', '"mydomain.cord-tester"'),
83 ]
84 default_subnet_config = [ ('192.168.1.2',
85'''
86subnet 192.168.1.0 netmask 255.255.255.0 {
87 range 192.168.1.10 192.168.1.100;
88}
89'''), ]
90
91 lock = threading.Condition()
92 ip_count = 0
93 failure_count = 0
94 start_time = 0
95 diff = 0
96
97 transaction_count = 0
98 transactions = 0
99 running_time = 0
100 total_success = 0
101 total_failure = 0
102 #just in case we want to reset ONOS to default network cfg after relay tests
103 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
104 configs = {}
Thangavelu K S905e5482017-09-12 06:48:02 -0700105 sadis_configs = {}
106 default_onos_netcfg = {}
A R Karthickc0a008f2017-10-04 18:35:25 -0700107 voltha_switch_map = None
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000108 remote_dhcpd_cmd = []
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000109
110 @classmethod
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700111 def update_apps_version(cls):
112 version = Onos.getVersion()
113 major = int(version.split('.')[0])
114 minor = int(version.split('.')[1])
115 dhcpl2_app_version = '1.0.0'
A R Karthickc0a008f2017-10-04 18:35:25 -0700116 sadis_app_version = '3.0-SNAPSHOT'
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700117 cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version))
118 cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version))
119
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700120 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000121 def setUpClass(cls):
122 ''' Activate the cord dhcpl2relay app'''
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700123 cls.update_apps_version()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000124 OnosCtrl(cls.app_dhcp).deactivate()
125 time.sleep(3)
126 cls.onos_ctrl = OnosCtrl(cls.app)
127 status, _ = cls.onos_ctrl.activate()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700128 #assert_equal(status, True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000129 time.sleep(3)
A R Karthickc0a008f2017-10-04 18:35:25 -0700130 status, _ = OnosCtrl(cls.sadis_app).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 cls.setup_dhcpd()
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000134 cls.default_onos_netcfg = OnosCtrl.get_config()
135
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700136
137 def setUp(self):
Thangavelu K S905e5482017-09-12 06:48:02 -0700138 self.default_onos_netcfg = OnosCtrl.get_config()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700139 super(dhcpl2relay_exchange, self).setUp()
A R Karthickc0a008f2017-10-04 18:35:25 -0700140 #self.dhcp_l2_relay_setup()
141 #self.cord_sadis_load()
142 #self.cord_l2_relay_load()
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700143
144 def tearDown(self):
145 super(dhcpl2relay_exchange, self).tearDown()
A R Karthickc0a008f2017-10-04 18:35:25 -0700146 #OnosCtrl.uninstall_app(self.dhcpl2_app_file)
147 #OnosCtrl.uninstall_app(self.sadis_app_file)
148 #OnosCtrl.uninstall_app(self.olt_app_file)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000149
150 @classmethod
151 def tearDownClass(cls):
152 '''Deactivate the cord dhcpl2relay app'''
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000153 cls.onos_load_config(cls.default_onos_netcfg)
A R Karthickc0a008f2017-10-04 18:35:25 -0700154 #cls.onos_ctrl.deactivate()
155 #OnosCtrl(cls.sadis_app).deactivate()
156 #OnosCtrl(cls.app_olt).deactivate()
157
158 @classmethod
159 def setup_dhcpd(cls, boot_delay = 5):
160 if cls.service_running("/usr/sbin/dhcpd"):
161 print('DHCPD already running in container')
162 return True
163 setup_for_relay = cls.dhcp_l2_relay_setup()
164 cls.cord_l2_relay_load()
165 cls.voltha_setup()
A R Karthick760d1382017-10-05 13:48:40 -0700166 return True
167
168 # dhcp_start_status = cls.dhcpd_start()
169 # if setup_for_relay and dhcp_start_status:
170 # return True
171 # return False
A R Karthickc0a008f2017-10-04 18:35:25 -0700172
173 @classmethod
174 def config_olt(cls, switch_map):
175 controller = get_controller()
176 auth = ('karaf', 'karaf')
177 #configure subscriber for every port on all the voltha devices
178 for device, device_map in switch_map.iteritems():
179 uni_ports = device_map['ports']
180 uplink_vlan = device_map['uplink_vlan']
181 for port in uni_ports:
182 vlan = port
183 rest_url = 'http://{}:8181/onos/olt/oltapp/{}/{}/{}'.format(controller,
184 device,
185 port,
186 vlan)
187 requests.post(rest_url, auth = auth)
188
189 @classmethod
190 def voltha_setup(cls):
191 s_tag_map = {}
192 #configure olt app to provision dhcp flows
193 cls.config_olt(cls.voltha_switch_map)
194 for switch, switch_map in cls.voltha_switch_map.iteritems():
195 s_tag_map[int(switch_map['uplink_vlan'])] = map(lambda p: int(p), switch_map['ports'])
196
197 cmd_list = []
198 relay_interface = cls.relay_interfaces[0]
199 cls.relay_vlan_map[relay_interface] = []
200 for s_tag, ports in s_tag_map.iteritems():
201 vlan_stag_intf = '{}.{}'.format(relay_interface, s_tag)
202 cmd = 'ip link add link %s name %s type vlan id %d' %(relay_interface, vlan_stag_intf, s_tag)
203 cmd_list.append(cmd)
204 cmd = 'ip link set %s up' %(vlan_stag_intf)
205 cmd_list.append(cmd)
206 for port in ports:
207 vlan_ctag_intf = '{}.{}.{}'.format(relay_interface, s_tag, port)
208 cmd = 'ip link add link %s name %s type vlan id %d' %(vlan_stag_intf, vlan_ctag_intf, port)
209 cmd_list.append(cmd)
210 cmd = 'ip link set %s up' %(vlan_ctag_intf)
211 cmd_list.append(cmd)
212 cls.relay_vlan_map[relay_interface].append(vlan_ctag_intf)
213 cls.relay_vlan_map[relay_interface].append(vlan_stag_intf)
214
215 for cmd in cmd_list:
216 log_test.info('Running command: %s' %cmd)
217 os.system(cmd)
218
219 cord_test_ovs_flow_add(cls.relay_interface_port)
220 for s_tag in s_tag_map.keys():
221 log_test.info('Configuring OVS flow for port %d, s_tag %d' %(cls.relay_interface_port, s_tag))
222 cord_test_ovs_flow_add(cls.relay_interface_port, s_tag)
223
224 @classmethod
225 def service_running(cls, pattern):
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000226 st, output = getstatusoutput('pgrep -f "{}"'.format(pattern))
A R Karthickc0a008f2017-10-04 18:35:25 -0700227 return True if st == 0 else False
228
229 @classmethod
230 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
231 subnet = default_subnet_config):
232 conf = ''
233 for k, v in config.items():
234 conf += '{} {};\n'.format(k, v)
235
236 opts = ''
237 for k, v in options:
238 opts += 'option {} {};\n'.format(k, v)
239
240 subnet_config = ''
241 for _, v in subnet:
242 subnet_config += '{}\n'.format(v)
243
244 return '{}{}{}'.format(conf, opts, subnet_config)
245
246 @classmethod
247 def dhcpd_start(cls, intf_list = None,
248 config = default_config, options = default_options,
249 subnet = default_subnet_config):
250 '''Start the dhcpd server by generating the conf file'''
251 if intf_list is None:
252 intf_list = cls.relay_interfaces
253 intf_list = list(intf_list)
254 ##stop dhcpd if already running
255 #cls.dhcpd_stop()
256 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
257 subnet = subnet)
258 ##first touch dhcpd.leases if it doesn't exist
259 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
260 if os.access(lease_file, os.F_OK) is False:
261 with open(lease_file, 'w') as fd: pass
262
A R Karthickce96dde2017-10-05 16:41:52 -0700263 lease_file_tagged = '{}/dhcpd-tagged.leases'.format(cls.dhcp_data_dir)
264 if os.access(lease_file_tagged, os.F_OK) is False:
265 with open(lease_file_tagged, 'w') as fd: pass
266
A R Karthickc0a008f2017-10-04 18:35:25 -0700267 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
268 with open(conf_file, 'w') as fd:
269 fd.write(dhcp_conf)
270
A R Karthickce96dde2017-10-05 16:41:52 -0700271 conf_file_tagged = '{}/dhcpd-tagged.conf'.format(cls.dhcp_data_dir)
272 with open(conf_file_tagged, 'w') as fd:
273 fd.write(dhcp_conf)
274
A R Karthickc0a008f2017-10-04 18:35:25 -0700275 #now configure the dhcpd interfaces for various subnets
276 index = 0
277 intf_info = []
278 vlan_intf_list = []
279 for ip,_ in subnet:
280 vlan_intf = None
281 intf = intf_list[index]
282 if intf in cls.relay_vlan_map:
283 vlan_intf = cls.relay_vlan_map[intf][0]
284 vlan_intf_list.append(vlan_intf)
285 mac = cls.get_mac(intf)
286 intf_info.append((ip, mac))
287 index += 1
288 cmd = 'ifconfig {} {}'.format(intf, ip)
289 status = os.system(cmd)
290 if vlan_intf:
291 cmd = 'ifconfig {} {}'.format(vlan_intf, ip)
292 os.system(cmd)
293
294 intf_str = ','.join(intf_list)
295 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)
296 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
297 status = os.system(dhcpd_cmd)
298 vlan_intf_str = ','.join(vlan_intf_list)
A R Karthickce96dde2017-10-05 16:41:52 -0700299 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 -0700300 print('Starting DHCPD server with command: %s' %dhcpd_cmd)
301 status = os.system(dhcpd_cmd)
302 if status > 255:
303 status = 1
304 else:
305 return False
306 time.sleep(3)
307 cls.relay_interfaces_last = cls.relay_interfaces
308 cls.relay_interfaces = intf_list
309 return True
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000310
311 @classmethod
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000312 def get_dhcpd_process(cls):
313 docker_cmd = 'docker exec cord-tester1'
314 cmd = '{} ps -eaf | grep dhcpd'.format(docker_cmd)
315 dhcpd_server_ip = get_controller()
316 server_user = 'ubuntu'
317 server_pass = 'ubuntu'
318 ssh_agent = SSHTestAgent(host = dhcpd_server_ip, user = server_user, password = server_user)
319 status, output = ssh_agent.run_cmd(cmd)
320 assert_equal(status, True)
321 if output:
322 cls.remote_dhcpd_cmd = re.findall('(?<=/)\w+.*', output)
323 log_test.info('DHCP server running on remote host and list of service commands are \n %s'%cls.remote_dhcpd_cmd)
324 assert_equal(status, True)
325 return cls.remote_dhcpd_cmd
326
327 def dhcpd_stop(self, remote_controller = False, dhcpd = None):
328 if remote_controller is not True:
329 if cls.service_running("/usr/sbin/dhcpd"):
330 cmd = 'pkill -9 dhcpd'
331 st, _ = getstatusoutput(cmd)
332 return True if st == 0 else False
333 else:
334 docker_cmd = 'docker exec cord-tester1'
335 dhcpd_server_ip = get_controller()
336 server_user = 'ubuntu'
337 server_pass = 'ubuntu'
338 service_satatus = True
339 ssh_agent = SSHTestAgent(host = dhcpd_server_ip, user = server_user, password = server_user)
340 if dhcpd == 'stop':
341 status, output = ssh_agent.run_cmd('{} pkill -9 dhcpd'.format(docker_cmd))
342 service_satatus = status and True
343 elif dhcpd == 'start':
344 for cmd in self.remote_dhcpd_cmd:
345 dhcpd_cmd = ' {0} /{1}'.format(docker_cmd,cmd)
346 status, output = ssh_agent.run_cmd(dhcpd_cmd)
347 service_satatus = status and True
348 elif dhcpd == 'restart':
349 status, output = ssh_agent.run_cmd('{} pkill -9 dhcpd'.format(docker_cmd))
350 service_satatus = status and True
351 for cmd in self.remote_dhcpd_cmd:
352 dhcpd_cmd = ' {0} /{1}'.format(docker_cmd,cmd)
353 status, output = ssh_agent.run_cmd(dhcpd_cmd)
354 service_satatus = status and True
355 return service_satatus
356
357 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000358 def dhcp_l2_relay_setup(cls):
A R Karthickc0a008f2017-10-04 18:35:25 -0700359 device_details = OnosCtrl.get_devices(mfr = 'Nicira')
Thangavelu K S905e5482017-09-12 06:48:02 -0700360 if device_details is not None:
A R Karthickc0a008f2017-10-04 18:35:25 -0700361 did_ovs = device_details[0]['id']
Thangavelu K S905e5482017-09-12 06:48:02 -0700362 else:
363 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')
364 return False
365 cls.relay_device_id = did_ovs
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000366 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
367 cls.port_map, _ = cls.olt.olt_port_map()
368 if cls.port_map:
369 ##Per subscriber, we use 1 relay port
370 try:
371 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
372 except:
373 relay_port = cls.port_map['uplink']
374 cls.relay_interface_port = relay_port
375 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
376 else:
377 cls.relay_interface_port = 100
378 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
379 cls.relay_interfaces_last = cls.relay_interfaces
380 if cls.port_map:
381 ##generate a ip/mac client virtual interface config for onos
382 interface_list = []
383 for port in cls.port_map['ports']:
384 port_num = cls.port_map[port]
385 if port_num == cls.port_map['uplink']:
386 continue
387 ip = cls.get_host_ip(port_num)
388 mac = cls.get_mac(port)
389 interface_list.append((port_num, ip, mac))
390
391 #configure dhcp server virtual interface on the same subnet as first client interface
392 relay_ip = cls.get_host_ip(interface_list[0][0])
393 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
394 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
A R Karthickc0a008f2017-10-04 18:35:25 -0700395 cls.onos_interface_load(interface_list)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000396
397 @classmethod
398 def dhcp_l2_relay_cleanup(cls):
399 ##reset the ONOS port configuration back to default
400 for config in cls.configs.items():
401 OnosCtrl.delete(config)
Thangavelu K S905e5482017-09-12 06:48:02 -0700402 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000403 # if cls.onos_restartable is True:
404 # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
405 # return cord_test_onos_restart(config = {})
406
407 @classmethod
408 def onos_load_config(cls, config):
409 status, code = OnosCtrl.config(config)
410 if status is False:
411 log_test.info('JSON request returned status %d' %code)
412 assert_equal(status, True)
413 time.sleep(3)
414
415 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700416 def onos_delete_config(cls, config):
417 status, code = OnosCtrl.delete(config)
418 if status is False:
419 log_test.info('JSON request returned status %d' %code)
420 assert_equal(status, True)
421 time.sleep(3)
422
423 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000424 def onos_interface_load(cls, interface_list):
425 interface_dict = { 'ports': {} }
426 for port_num, ip, mac in interface_list:
427 port_map = interface_dict['ports']
428 port = '{}/{}'.format(cls.relay_device_id, port_num)
429 port_map[port] = { 'interfaces': [] }
430 interface_list = port_map[port]['interfaces']
431 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
432 'mac' : mac,
433 'name': 'vir-{}'.format(port_num)
434 }
435 interface_list.append(interface_map)
436
437 cls.onos_load_config(interface_dict)
438 cls.configs['interface_config'] = interface_dict
439
440 @classmethod
A R Karthickc0a008f2017-10-04 18:35:25 -0700441 def cord_l2_relay_load(cls, dhcp_server_connectPoint = None, delete = False):
A R Karthick53735662017-10-05 12:53:35 -0700442 ##read the current config
443 current_netcfg = OnosCtrl.get_config()
444 connect_points = set([])
445 try:
446 connect_points = set(current_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints'])
447 except KeyError, e:
448 pass
449
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700450 OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
A R Karthickc0a008f2017-10-04 18:35:25 -0700451 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
Thangavelu K S905e5482017-09-12 06:48:02 -0700452 #### We have to work on later versions by removing these hard coded values
Thangavelu K S905e5482017-09-12 06:48:02 -0700453 if dhcp_server_connectPoint is None:
A R Karthick8fe89a12017-10-05 13:12:13 -0700454 relay_device_present = filter(lambda cp: cp.split('/')[0] == cls.relay_device_id, connect_points)
455 if not relay_device_present:
456 connect_points.add(relay_device_map)
A R Karthick53735662017-10-05 12:53:35 -0700457 else:
458 cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint)
459 connect_points = list(connect_points)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700460 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
A R Karthick53735662017-10-05 12:53:35 -0700461 {"dhcpServerConnectPoints": connect_points}
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000462 }
463 }
464 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700465 #OnosCtrl.uninstall_app(cls.dhcpl2_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700466 OnosCtrl.install_app(cls.dhcpl2_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700467 if delete == False:
468 cls.onos_load_config(dhcp_dict)
469 else:
470 cls.onos_delete_config(dhcp_dict)
471 cls.onos_load_config(cls.default_onos_config)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000472 cls.configs['relay_config'] = dhcp_dict
473
474 @classmethod
Thangavelu K S905e5482017-09-12 06:48:02 -0700475 def cord_sadis_load(cls, sadis_info = None):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000476 relay_device_id = '{}'.format(cls.relay_device_id)
Thangavelu K S905e5482017-09-12 06:48:02 -0700477 device_details = OnosCtrl.get_devices()
478 if device_details is not None:
479 for device in device_details:
480 ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point...
481 if device['available'] is True and device['driver'] == 'pmc-olt':
482 cls.olt_serial_id = "{}".format(device['serial'])
483 else:
484 cls.olt_serial_id = " "
485 else:
486 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')
487 return False
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700488 sadis_dict = { "apps": {
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000489 "org.opencord.sadis": {
490 "sadis": {
491 "integration": {
492 "cache": {
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700493 "enabled": "true",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000494 "maxsize": 50,
495 "ttl": "PT1m"
496 }
497 },
498 "entries": [{
499 "id": "uni-254",
500 "cTag": 202,
501 "sTag": 222,
502 "nasPortId": "uni-254"
503 },
504 {
Thangavelu K S905e5482017-09-12 06:48:02 -0700505 "id": cls.olt_serial_id,
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700506 "hardwareIdentifier": "00:0c:e2:31:05:00",
507 "ipAddress": "172.17.0.1",
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000508 "nasId": "B100-NASID"
509 }
510 ]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700511 }
512 }
513 }
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000514 }
Thangavelu K S905e5482017-09-12 06:48:02 -0700515 #OnosCtrl.uninstall_app(cls.olt_app_file)
516 OnosCtrl.install_app(cls.olt_app_file)
517 time.sleep(5)
518 #OnosCtrl.uninstall_app(cls.sadis_app_file)
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700519 OnosCtrl.install_app(cls.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700520 if sadis_info:
521 sadis_dict = sadis_info
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000522 cls.onos_load_config(sadis_dict)
Thangavelu K S905e5482017-09-12 06:48:02 -0700523 cls.sadis_configs['relay_config'] = sadis_dict
524
525 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):
526 ### Need to work on these hard coded values on later merges
527 if subscriber_port_id is None:
528 subscriber_port_id = "uni-254"
529 if c_tag is None:
530 c_tag = 202
531 if s_tag is None:
532 s_tag = 222
533 if nas_port_id is None:
534 nas_port_id = "uni-254"
535 if olt_serial_id is None:
536 olt_serial_id = self.olt_serial_id
537 if olt_mac is None:
538 olt_mac = "00:0c:e2:31:05:00"
539 if olt_ip is None:
540 olt_ip = "172.17.0.1"
541 if olt_nas_id is None:
542 olt_nas_id = "B100-NASID"
543 sadis_dict = { "apps": {
544 "org.opencord.sadis": {
545 "sadis": {
546 "integration": {
547 "cache": {
548 "enabled": "true",
549 "maxsize": 50,
550 "ttl": "PT1m"
551 }
552 },
553 "entries": [{
554 "id": subscriber_port_id,
555 "cTag": c_tag,
556 "sTag": s_tag,
557 "nasPortId": nas_port_id
558 },
559 {
560 "id": olt_serial_id,
561 "hardwareIdentifier": olt_mac,
562 "ipAddress": olt_ip,
563 "nasId": olt_nas_id
564 }
565 ]
566 }
567 }
568 }
569 }
570 return sadis_dict
571
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000572
573 @classmethod
574 def get_host_ip(cls, port):
575 if cls.host_ip_map.has_key(port):
576 return cls.host_ip_map[port]
Thangavelu K Sa61d1da2017-09-05 05:32:21 -0700577 cls.host_ip_map[port] = '192.168.100.{}'.format(port)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000578 return cls.host_ip_map[port]
579
580 @classmethod
581 def host_load(cls, iface):
582 '''Have ONOS discover the hosts for dhcp-relay responses'''
583 port = g_subscriber_port_map[iface]
584 host = '173.17.1.{}'.format(port)
585 cmds = ( 'ifconfig {} 0'.format(iface),
586 'ifconfig {0} {1}'.format(iface, host),
587 'arping -I {0} {1} -c 2'.format(iface, host),
588 'ifconfig {} 0'.format(iface), )
589 for c in cmds:
590 os.system(c)
591
592 @classmethod
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000593 def get_mac(cls, iface):
594 if cls.interface_to_mac_map.has_key(iface):
595 return cls.interface_to_mac_map[iface]
596 mac = get_mac(iface, pad = 0)
597 cls.interface_to_mac_map[iface] = mac
598 return mac
599
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000600 def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000601
602 self.ip_count = 0
603 self.failure_count = 0
604 self.start_time = 0
605 self.diff = 0
606 self.transaction_count = 0
607
608 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000609 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
610 self.start_time = time.time()
611
612 while self.diff <= 60:
613
614 if only_discover:
615 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
616 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
617 (cip, sip, mac))
618 else:
619 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
620
621 if cip:
622 self.ip_count +=1
623 elif cip == None:
624 self.failure_count += 1
625 log_test.info('Failed to get ip')
626 if success_rate and self.ip_count > 0:
627 break
628
629 self.diff = round(time.time() - self.start_time, 0)
630
631 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
632 self.transactions += (self.ip_count+self.failure_count)
633 self.running_time += self.diff
634 self.total_success += self.ip_count
635 self.total_failure += self.failure_count
636
637 def send_recv(self, mac=None, update_seed = False, validate = True):
638 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
639 if validate:
640 assert_not_equal(cip, None)
641 assert_not_equal(sip, None)
642 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
643 (cip, sip, self.dhcp.get_mac(cip)[0]))
644 return cip,sip
645
A R Karthickc0a008f2017-10-04 18:35:25 -0700646 def test_dhcpl2relay_initialize(self):
A R Karthick760d1382017-10-05 13:48:40 -0700647 '''Configure the DHCP L2 relay app and start dhcpd'''
648 self.dhcpd_start()
A R Karthickc0a008f2017-10-04 18:35:25 -0700649
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000650 def test_dhcpl2relay_with_one_request(self, iface = 'veth0'):
651 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000652 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
653 self.send_recv(mac=mac)
654
Thangavelu K S905e5482017-09-12 06:48:02 -0700655 def test_dhcpl2relay_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000656 mac = self.get_mac(iface)
657 onos_netcfg = OnosCtrl.get_config()
658 app_status = False
659 app_name = 'org.opencord.dhcpl2relay'
660 for app in onos_netcfg['apps']:
661 if app == app_name:
662 log_test.info('%s app is being installed'%app)
663 app_status = True
664 if app_status is not True:
665 log_test.info('%s app is not being installed'%app_name)
666 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000667
Thangavelu K S905e5482017-09-12 06:48:02 -0700668 def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000669 mac = self.get_mac(iface)
670 onos_netcfg = OnosCtrl.get_config()
671 app_status = False
672 app_name = 'org.opencord.sadis'
673 for app in onos_netcfg['apps']:
674 if app == app_name:
675 log_test.info('%s app is being installed'%app)
676 app_status = True
677 if app_status is not True:
678 log_test.info('%s app is not being installed'%app_name)
679 assert_equal(True, app_status)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000680
Thangavelu K S905e5482017-09-12 06:48:02 -0700681 def test_dhcpl2relay_netcfg(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000682 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700683 onos_netcfg = OnosCtrl.get_config()
684 app_status = False
685 app_name = 'org.opencord.dhcpl2relay'
686 for app in onos_netcfg['apps']:
687 if app == app_name:
688 log_test.info('%s app is being installed'%app)
689 if onos_netcfg['apps'][app_name] == {}:
690 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
691 else:
692 log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name])
693 app_status = True
694 if app_status is not True:
695 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
696 assert_equal(True, False)
697
698 def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'):
699 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000700 onos_netcfg = OnosCtrl.get_config()
701 app_status = False
702 app_name = 'org.opencord.sadis'
703 for app in onos_netcfg['apps']:
704 if app == app_name:
705 log_test.info('%s app is being installed'%app)
706 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700707 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
708 else:
709 log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]))
Thangavelu K S46063d02017-09-08 21:13:24 +0000710 app_status = True
711 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700712 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
713 assert_equal(True, False)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000714
Thangavelu K S905e5482017-09-12 06:48:02 -0700715 def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'):
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000716 connect_point = self.default_onos_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints']
717 log_test.info('Existing connect point of dhcp server is %s'%connect_point)
718 relay_device_map1 = '{}/{}'.format(self.relay_device_id, random.randrange(1,5, 1))
719 relay_device_map2 = '{}/{}'.format(self.relay_device_id, random.randrange(6,10, 1))
720 relay_device_map3 = '{}/{}'.format(self.relay_device_id, random.randrange(10,16, 1))
721 relay_device_map4 = '{}/{}'.format(self.relay_device_id, random.randrange(17,23, 1))
722 dhcp_server_array_connectPoints = [connect_point[0],relay_device_map1,relay_device_map2,relay_device_map3,relay_device_map4]
723 log_test.info('Added array of connect points of dhcp server is %s'%dhcp_server_array_connectPoints)
724
Thangavelu K S46063d02017-09-08 21:13:24 +0000725 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700726 self.onos_delete_config(self.configs['relay_config'])
727 self.onos_load_config(self.default_onos_netcfg)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000728 dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" :
729 {"dhcpServerConnectPoints": dhcp_server_array_connectPoints}
730 }
731 }
732 }
733 self.onos_load_config(dhcp_dict)
Thangavelu K S46063d02017-09-08 21:13:24 +0000734 onos_netcfg = OnosCtrl.get_config()
735 app_status = False
Thangavelu K S905e5482017-09-12 06:48:02 -0700736 app_name = 'org.opencord.dhcpl2relay'
Thangavelu K S46063d02017-09-08 21:13:24 +0000737 for app in onos_netcfg['apps']:
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000738 if app == app_name and onos_netcfg['apps'][app] != {}:
Thangavelu K S46063d02017-09-08 21:13:24 +0000739 log_test.info('%s app is being installed'%app)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000740 log_test.info('The network configuration is shown %s'%onos_netcfg['apps'][app])
741 x = set(onos_netcfg['apps'][app_name]['dhcpl2relay']['dhcpServerConnectPoints']) & set(dhcp_server_array_connectPoints)
742 if len(x) == len(dhcp_server_array_connectPoints):
743 log_test.info('The loaded onos network configuration is = %s'%dhcp_server_array_connectPoints)
Thangavelu K S46063d02017-09-08 21:13:24 +0000744 app_status = True
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000745 break
Thangavelu K S46063d02017-09-08 21:13:24 +0000746 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700747 log_test.info('%s app is not installed or network configuration is not shown'%app_name)
748 assert_equal(True, False)
Thangavelu K S46063d02017-09-08 21:13:24 +0000749 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000750 self.send_recv(mac=mac)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000751
Chetan Gaonker891302d2017-09-05 15:09:26 +0000752
Thangavelu K S905e5482017-09-12 06:48:02 -0700753 def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000754 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700755 c_tag = 600
756 invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500)
757 self.cord_sadis_load(sadis_info = invalid_sadis_info)
758 onos_netcfg = OnosCtrl.get_config()
759 app_status = False
760 app_name = 'org.opencord.sadis'
761 for app in onos_netcfg['apps']:
762 if app == app_name:
763 log_test.info('%s app is being installed'%app)
764 if onos_netcfg['apps'][app_name] == {}:
765 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
766 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
767 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']))
768 app_status = True
769 if app_status is not True:
770 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
771 assert_equal(True, False)
772 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
773 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
774 assert_equal(cip,None)
775
776 def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'):
777 iterations = 15
778 for i in range(iterations):
779 self.onos_ctrl.deactivate()
780 time.sleep(3)
781 self.onos_ctrl.activate()
782 log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations)
783 mac = self.get_mac(iface)
784 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
785 self.send_recv(mac=mac)
786
787 def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'):
788 mac = self.get_mac(iface)
789 OnosCtrl.uninstall_app(self.sadis_app_file)
790 OnosCtrl(self.sadis_app).deactivate()
791 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
792 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
793 assert_equal(cip,None)
794
795 def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'):
796 mac = self.get_mac(iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000797 log_test.info('Uninstall the sadis app from onos ,app version = %s '%self.sadis_app_file)
Thangavelu K S905e5482017-09-12 06:48:02 -0700798 OnosCtrl.uninstall_app(self.sadis_app_file)
799 OnosCtrl(self.sadis_app).deactivate()
800 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
801 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
802 assert_equal(cip,None)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000803 log_test.info('Installing the sadis app in onos again, app version = %s '%self.sadis_app_file)
804 OnosCtrl.install_app(self.sadis_app_file)
805 OnosCtrl(self.sadis_app).activate()
806 OnosCtrl(self.app).activate()
Thangavelu K S905e5482017-09-12 06:48:02 -0700807 #self.onos_load_config(self.sadis_configs['relay_config'])
808 self.send_recv(mac=mac)
809
810 def test_dhcpl2relay_with_option_82(self, iface = 'veth0'):
811 pass
812
813 def test_dhcpl2relay_without_option_82(self, iface = 'veth0'):
814 pass
815
816 def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'):
817 pass
818
819 def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'):
820 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000821 subscriber_port_id = "uni-200"
822 invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200")
823 self.cord_sadis_load(sadis_info = invalid_sadis_info)
824 onos_netcfg = OnosCtrl.get_config()
825 app_status = False
826 app_name = 'org.opencord.sadis'
827 for app in onos_netcfg['apps']:
828 if app == app_name:
829 log_test.info('%s app is being installed'%app)
830 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700831 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000832 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700833 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 +0000834 app_status = True
835 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700836 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
837
Thangavelu K S46063d02017-09-08 21:13:24 +0000838 assert_equal(True, False)
839 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
840 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
841 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000842
Thangavelu K S905e5482017-09-12 06:48:02 -0700843 def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000844 mac = self.get_mac(iface)
Thangavelu K S905e5482017-09-12 06:48:02 -0700845 c_tag = 600
Thangavelu K S46063d02017-09-08 21:13:24 +0000846 invalid_sadis_info = self.sadis_info_dict(c_tag = 600)
847 self.cord_sadis_load(sadis_info = invalid_sadis_info)
848 onos_netcfg = OnosCtrl.get_config()
849 app_status = False
850 app_name = 'org.opencord.sadis'
851 for app in onos_netcfg['apps']:
852 if app == app_name:
853 log_test.info('%s app is being installed'%app)
854 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700855 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000856 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700857 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 +0000858 app_status = True
859 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700860 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000861 assert_equal(True, False)
862 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
863 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
864 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000865
Thangavelu K S905e5482017-09-12 06:48:02 -0700866 def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000867 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000868 s_tag = 600
869 invalid_sadis_info = self.sadis_info_dict(s_tag = 600)
870 self.cord_sadis_load(sadis_info = invalid_sadis_info)
871 onos_netcfg = OnosCtrl.get_config()
872 app_status = False
873 app_name = 'org.opencord.sadis'
874 for app in onos_netcfg['apps']:
875 if app == app_name:
876 log_test.info('%s app is being installed'%app)
877 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700878 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000879 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag:
Thangavelu K S905e5482017-09-12 06:48:02 -0700880 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 +0000881 app_status = True
882 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700883 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000884 assert_equal(True, False)
885 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
886 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
887 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000888
Thangavelu K S905e5482017-09-12 06:48:02 -0700889 def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000890 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000891 invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ")
892 self.cord_sadis_load(sadis_info = invalid_sadis_info)
893 onos_netcfg = OnosCtrl.get_config()
894 app_status = False
895 app_name = 'org.opencord.sadis'
896 for app in onos_netcfg['apps']:
897 if app == app_name:
898 log_test.info('%s app is being installed'%app)
899 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700900 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000901 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700902 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 +0000903 app_status = True
904 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700905 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000906 assert_equal(True, False)
907 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
908 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
909 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000910
Thangavelu K S905e5482017-09-12 06:48:02 -0700911 def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000912 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000913 nas_port_id = "uni-509"
914 invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509")
915 self.cord_sadis_load(sadis_info = invalid_sadis_info)
916 onos_netcfg = OnosCtrl.get_config()
917 app_status = False
918 app_name = 'org.opencord.sadis'
919 for app in onos_netcfg['apps']:
920 if app == app_name:
921 log_test.info('%s app is being installed'%app)
922 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700923 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000924 elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700925 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 +0000926 app_status = True
927 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700928 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000929 assert_equal(True, False)
930 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
931 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
932 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000933
Thangavelu K S905e5482017-09-12 06:48:02 -0700934 def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000935 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000936 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ")
937 self.cord_sadis_load(sadis_info = invalid_sadis_info)
938 onos_netcfg = OnosCtrl.get_config()
939 app_status = False
940 app_name = 'org.opencord.sadis'
941 for app in onos_netcfg['apps']:
942 if app == app_name:
943 log_test.info('%s app is being installed'%app)
944 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700945 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000946 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ":
Thangavelu K S905e5482017-09-12 06:48:02 -0700947 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 +0000948 app_status = True
949 if app_status is not True:
Thangavelu K S905e5482017-09-12 06:48:02 -0700950 log_test.info('%s app is not installed or network configuration is not shown '%app_name)
Thangavelu K S46063d02017-09-08 21:13:24 +0000951 assert_equal(True, False)
952 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
953 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
954 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000955
Thangavelu K S905e5482017-09-12 06:48:02 -0700956 def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'):
Thangavelu K S46063d02017-09-08 21:13:24 +0000957 mac = self.get_mac(iface)
Thangavelu K S46063d02017-09-08 21:13:24 +0000958 olt_serial_id = "07f20d06696041febf974ccdhdhhjh37"
959 invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37")
960 self.cord_sadis_load(sadis_info = invalid_sadis_info)
961 onos_netcfg = OnosCtrl.get_config()
962 app_status = False
963 app_name = 'org.opencord.sadis'
964 for app in onos_netcfg['apps']:
965 if app == app_name:
966 log_test.info('%s app is being installed'%app)
967 if onos_netcfg['apps'][app_name] == {}:
Thangavelu K S905e5482017-09-12 06:48:02 -0700968 log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name])
Thangavelu K S46063d02017-09-08 21:13:24 +0000969 elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id:
Thangavelu K S905e5482017-09-12 06:48:02 -0700970 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 +0000971 app_status = True
972 if app_status is not True:
973 assert_equal(True, False)
974 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
975 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
976 assert_equal(cip,None)
Chetan Gaonker891302d2017-09-05 15:09:26 +0000977
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000978 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'):
979 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000980 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
981 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
982 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000983 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000984
985 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'):
986 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000987 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
988 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05')
989 assert_equal(cip,None)
Chetan Gaonkera6050ae2017-09-02 19:15:01 +0000990 log_test.info('Dhcp server rejected client discover with invalid source mac, as expected')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000991
992 def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'):
993 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +0000994 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
995 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
996 assert_equal(cip,None)
997 log_test.info('dhcp server rejected client discover with invalid source mac, as expected')
998
Thangavelu K Sd4d954f2017-10-12 20:05:30 +0000999 ### We can't test this on single uni port setup, hence its not to test
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001000 def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10):
1001 mac = self.get_mac(iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001002 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001003 ip_map = {}
1004 for i in range(requests):
1005 #mac = RandMAC()._fix()
1006 #log_test.info('mac is %s'%mac)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001007 cip, sip = self.send_recv(mac=mac, update_seed = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001008 if ip_map.has_key(cip):
1009 log_test.info('IP %s given out multiple times' %cip)
1010 assert_equal(False, ip_map.has_key(cip))
1011 ip_map[cip] = sip
1012 time.sleep(1)
1013
1014 def test_dhcpl2relay_with_one_release(self, iface = 'veth0'):
1015 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001016 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
1017 cip, sip = self.send_recv(mac=mac)
1018 log_test.info('Releasing ip %s to server %s' %(cip, sip))
1019 assert_equal(self.dhcp.release(cip), True)
1020 log_test.info('Triggering DHCP discover again after release')
1021 cip2, sip2 = self.send_recv(mac=mac)
1022 log_test.info('Verifying released IP was given back on rediscover')
1023 assert_equal(cip, cip2)
1024 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
1025 assert_equal(self.dhcp.release(cip2), True)
1026
1027 def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'):
1028 mac = None
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001029 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
1030 ip_map = {}
1031 for i in range(10):
1032 cip, sip = self.send_recv(mac=mac, update_seed = True)
1033 if ip_map.has_key(cip):
1034 log_test.info('IP %s given out multiple times' %cip)
1035 assert_equal(False, ip_map.has_key(cip))
1036 ip_map[cip] = sip
1037
1038 for ip in ip_map.keys():
1039 log_test.info('Releasing IP %s' %ip)
1040 assert_equal(self.dhcp.release(ip), True)
1041
1042 ip_map2 = {}
1043 log_test.info('Triggering DHCP discover again after release')
1044 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
1045 for i in range(len(ip_map.keys())):
1046 cip, sip = self.send_recv(mac=mac, update_seed = True)
1047 ip_map2[cip] = sip
1048
1049 log_test.info('Verifying released IPs were given back on rediscover')
1050 if ip_map != ip_map2:
1051 log_test.info('Map before release %s' %ip_map)
1052 log_test.info('Map after release %s' %ip_map2)
1053 assert_equal(ip_map, ip_map2)
1054
1055 def test_dhcpl2relay_starvation(self, iface = 'veth0'):
1056 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001057 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
1058 log_test.info('Verifying 1 ')
1059 count = 0
1060 while True:
1061 #mac = RandMAC()._fix()
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001062 cip, sip = self.send_recv(mac=mac,update_seed = True,validate = False)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001063 if cip is None:
1064 break
1065 else:
1066 count += 1
1067 assert_equal(count,91)
1068 log_test.info('Verifying 2 ')
1069 cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False)
1070 assert_equal(cip, None)
1071 assert_equal(sip, None)
1072
1073 def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'):
1074 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001075 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001076 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001077 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
1078 (cip, sip, mac) )
1079 assert_not_equal(cip, None)
1080 log_test.info('Triggering DHCP discover again.')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001081 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001082 assert_equal(new_cip, cip)
1083 log_test.info('got same ip to smae the client when sent discover again, as expected')
1084
1085 def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'):
1086 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001087 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1088 log_test.info('Sending DHCP discover and DHCP request.')
1089 cip, sip = self.send_recv(mac=mac)
1090 mac = self.dhcp.get_mac(cip)[0]
1091 log_test.info("Sending DHCP request again.")
1092 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1093 assert_equal(new_cip, cip)
1094 log_test.info('got same ip to smae the client when sent request again, as expected')
1095
1096 def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'):
1097 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001098 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001099 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001100 assert_equal(cip,self.dhcp.seed_ip)
1101 log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' %
1102 (cip, sip, mac) )
1103
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001104 def test_dhcpl2relay_with_clients_desired_address_out_of_pool(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001105 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001106 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001107 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001108 assert_not_equal(cip,None)
1109 assert_not_equal(cip,self.dhcp.seed_ip)
1110 log_test.info('server offered IP from its pool when requested out of pool IP, as expected')
1111
1112 def test_dhcpl2relay_nak_packet(self, iface = 'veth0'):
1113 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001114 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001115 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001116 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1117 (cip, sip, mac) )
1118 assert_not_equal(cip, None)
1119 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
1120 assert_equal(new_cip, None)
1121 log_test.info('server sent NAK packet when requested other IP than that server offered')
1122
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001123 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 +00001124 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001125 self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface)
1126 self.dhcp.return_option = 'lease'
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001127 cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time=True,lease_value=lease_time)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001128 assert_equal(lval, lease_time)
1129 log_test.info('dhcp server offered IP address with client requested lease time')
1130
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001131 def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001132 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001133 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001134 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001135 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1136 (cip, sip, mac) )
1137 assert_not_equal(cip, None)
1138 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1139 log_test.info('client rebooting...')
1140 os.system('ifconfig '+iface+' down')
1141 time.sleep(5)
1142 os.system('ifconfig '+iface+' up')
1143 new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
1144 assert_equal(new_cip2, cip)
1145 log_test.info('client got same IP after reboot, as expected')
1146
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001147 def test_dhcpl2relay_after_server_shutting_down(self, iface = 'veth0'):
1148 self.get_dhcpd_process()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001149 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001150 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001151 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001152 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1153 (cip, sip, mac) )
1154 assert_not_equal(cip, None)
1155 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1156 log_test.info('server rebooting...')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001157 try:
1158 if self.dhcpd_stop(remote_controller = True, dhcpd = 'stop'):
1159 time.sleep(5)
1160 log_test.info('DHCP server is stopped ')
1161 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1162 assert_equal(new_cip,None)
1163 else:
1164 log_test.info('DHCP server is not stopped' )
1165 assert_equal(new_cip,None)
1166 finally:
1167 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001168
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001169 def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'):
1170 self.get_dhcpd_process()
1171 mac = self.get_mac(iface)
1172 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1173 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1174 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1175 (cip, sip, mac) )
1176 assert_not_equal(cip, None)
1177 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1178 log_test.info('server rebooting...')
1179 try:
1180 if self.dhcpd_stop(remote_controller = True, dhcpd = 'restart'):
1181 time.sleep(5)
1182 log_test.info('DHCP server is rebooted')
1183 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1184 assert_equal(new_cip,cip)
1185 else:
1186 log_test.info('DHCP server is not stopped' )
1187 assert_equal(new_cip,None)
1188 finally:
1189 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
1190
1191 def test_dhcpl2relay_after_server_restart(self, iface = 'veth0'):
1192 self.get_dhcpd_process()
1193 mac = self.get_mac(iface)
1194 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1195 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
1196 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1197 (cip, sip, mac) )
1198 assert_not_equal(cip, None)
1199 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1200 log_test.info('server rebooting...')
1201 try:
1202 if self.dhcpd_stop(remote_controller = True, dhcpd = 'stop'):
1203 time.sleep(5)
1204 log_test.info('DHCP server is stopped ')
1205 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1206 assert_equal(new_cip,None)
1207 else:
1208 log_test.info('DHCP server is not stoppped' )
1209 assert_equal(new_cip,None)
1210 self.dhcpd_stop(remote_controller = True, dhcpd = 'start')
1211 log_test.info('DHCP server is started ')
1212 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1213 assert_equal(new_cip, cip)
1214 log_test.info('client got same IP after server rebooted, as expected')
1215 finally:
1216 self.dhcpd_stop(remote_controller = True, dhcpd = 'restart')
1217
1218 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 +00001219 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001220 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1221 self.dhcp.return_option = 'lease'
1222 log_test.info('Sending DHCP discover with lease time of 700')
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001223 cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time = True, lease_value=lease_time)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001224 assert_equal(lval,lease_time)
1225 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
1226 assert_equal(new_cip,cip)
1227 assert_not_equal(lval, lease_time) #Negative Test Case
1228 log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected')
1229
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001230 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 +00001231 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001232 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001233 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001234 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time)
1235 assert_equal(new_cip,cip)
1236 assert_equal(lval, lease_time)
1237 log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected')
1238
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001239 def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001240 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001241 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001242 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001243 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1244 (cip, sip, mac) )
1245 assert_not_equal(cip,None)
1246 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
1247 log_test.info('waiting for renew time..')
1248 time.sleep(lval)
1249 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
1250 assert_equal(latest_cip, cip)
1251 log_test.info('server renewed client IP when client sends request after renew time, as expected')
1252
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001253 def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001254 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001255 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001256 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001257 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1258 (cip, sip, mac) )
1259 assert_not_equal(cip,None)
1260 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
1261 log_test.info('waiting for rebind time..')
1262 time.sleep(lval)
1263 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
1264 assert_equal(latest_cip, cip)
1265 log_test.info('server renewed client IP when client sends request after rebind time, as expected')
1266
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001267 def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001268 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001269 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1270 expected_subnet = '255.255.255.0'
1271 self.dhcp.return_option = 'subnet'
1272
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001273 cip, sip, mac, subnet_mask = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001274 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1275 (cip, sip, mac) )
1276 assert_equal(subnet_mask,expected_subnet)
1277 log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server')
1278
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001279 def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001280 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001281 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1282
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001283 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001284 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1285 (cip, sip, mac) )
1286 assert_not_equal(cip,None)
1287 self.dhcp.send_different_option = 'subnet'
1288 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1289 assert_equal(new_cip, cip)
1290 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
1291
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001292 def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001293 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001294 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1295 expected_router_address = '20.20.20.1'
1296 self.dhcp.return_option = 'router'
1297
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001298 cip, sip, mac, router_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001299 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1300 (cip, sip, mac) )
1301 assert_equal(expected_router_address, router_address_value)
1302 log_test.info('router address in server offer packet is same as configured router address in dhcp server')
1303
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001304 def test_dhcpl2relay_by_client_sending_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001305 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001306 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1307
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001308 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001309 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1310 (cip, sip, mac) )
1311 assert_not_equal(cip,None)
1312 self.dhcp.send_different_option = 'router'
1313 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1314 assert_equal(new_cip, cip)
1315 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
1316
1317 def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'):
1318 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001319 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1320 expected_broadcast_address = '192.168.1.255'
1321 self.dhcp.return_option = 'broadcast_address'
1322
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001323 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001324 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1325 (cip, sip, mac) )
1326 assert_equal(expected_broadcast_address, broadcast_address_value)
1327 log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server')
1328
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001329 def test_dhcpl2relay_by_client_sending_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001330 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001331 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1332
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001333 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001334 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1335 (cip, sip, mac) )
1336 assert_not_equal(cip,None)
1337 self.dhcp.send_different_option = 'broadcast_address'
1338 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1339 assert_equal(new_cip, cip)
1340 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1341
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001342 def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001343 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001344 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1345 expected_dns_address = '192.168.1.1'
1346 self.dhcp.return_option = 'dns'
1347
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001348 cip, sip, mac, dns_address_value = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001349 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1350 (cip, sip, mac) )
1351 assert_equal(expected_dns_address, dns_address_value)
1352 log_test.info('dns address in server offer packet is same as configured dns address in dhcp server')
1353
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001354 def test_dhcpl2relay_by_client_sending_request_with_wrong_dns_address(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001355 mac = self.get_mac(iface)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001356 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1357
Thangavelu K Sd4d954f2017-10-12 20:05:30 +00001358 cip, sip, mac, _ = self.dhcp.only_discover(mac=mac)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001359 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
1360 (cip, sip, mac) )
1361 assert_not_equal(cip,None)
1362 self.dhcp.send_different_option = 'dns'
1363 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1364 assert_equal(new_cip, cip)
1365 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1366
1367
1368 def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'):
1369
1370 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001371 self.dhcpl2relay_stats_calc()
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001372 log_test.info("Statistics for run %d",i)
1373 log_test.info("----------------------------------------------------------------------------------")
1374 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1375 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1376 log_test.info("----------------------------------------------------------------------------------")
1377 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1378
1379 log_test.info("Final Statistics for total transactions")
1380 log_test.info("----------------------------------------------------------------------------------")
1381 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1382 log_test.info(" %d %d %d %d" %(self.transactions,
1383 self.total_success, self.total_failure, self.running_time))
1384 log_test.info("----------------------------------------------------------------------------------")
1385 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1386
1387 def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'):
1388
1389 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001390 self.dhcpl2relay_stats_calc(success_rate = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001391 log_test.info("Statistics for run %d",i)
1392 log_test.info("----------------------------------------------------------------------------------")
1393 log_test.info("No. of consecutive successful transactions Running Time ")
1394 log_test.info(" %d %d " %(self.ip_count, self.diff))
1395 log_test.info("----------------------------------------------------------------------------------")
1396 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1397 log_test.info("----------------------------------------------------------------------------------")
1398
1399 log_test.info("Final Statistics for total successful transactions")
1400 log_test.info("----------------------------------------------------------------------------------")
1401 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1402 log_test.info(" %d %d %d " %(self.transactions,
1403 self.total_success, self.running_time))
1404 log_test.info("----------------------------------------------------------------------------------")
1405 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1406 log_test.info("----------------------------------------------------------------------------------")
1407
1408 def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'):
1409
1410 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001411 self.dhcpl2relay_stats_calc(only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001412 log_test.info("----------------------------------------------------------------------------------")
1413 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1414 log_test.info("----------------------------------------------------------------------------------")
1415 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1416 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1417 log_test.info("----------------------------------------------------------------------------------")
1418 log_test.info("No. of clients per second in run %d:%f "
1419 %(i, self.transaction_count))
1420 log_test.info("----------------------------------------------------------------------------------")
1421 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1422 log_test.info("----------------------------------------------------------------------------------")
1423 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1424 log_test.info(" %d %d %d %d" %(self.transactions,
1425 self.total_success, self.total_failure, self.running_time))
1426 log_test.info("----------------------------------------------------------------------------------")
1427 log_test.info("Average no. of clients per second: %d ",
1428 round(self.transactions/self.running_time,0))
1429 log_test.info("----------------------------------------------------------------------------------")
1430
1431 def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1432
1433 for i in range(1,4):
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001434 self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True)
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001435 log_test.info("----------------------------------------------------------------------------------")
1436 log_test.info("Statistics for run %d for sending only DHCP Discover",i)
1437 log_test.info("----------------------------------------------------------------------------------")
1438 log_test.info("No. of consecutive successful transactions Running Time ")
1439 log_test.info(" %d %d " %(self.ip_count, self.diff))
1440 log_test.info("----------------------------------------------------------------------------------")
1441 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1442 log_test.info("----------------------------------------------------------------------------------")
1443
1444 log_test.info("Final Statistics for total successful transactions")
1445 log_test.info("----------------------------------------------------------------------------------")
1446 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1447 log_test.info(" %d %d %d " %(self.transactions,
1448 self.total_success, self.running_time))
1449 log_test.info("----------------------------------------------------------------------------------")
1450 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1451 log_test.info("----------------------------------------------------------------------------------")
1452
1453 def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001454 for key in (key for key in g_subscriber_port_map if key < 100):
1455 self.host_load(g_subscriber_port_map[key])
1456
1457 def thread_fun(i):
1458 mac = self.get_mac('veth{}'.format(i))
1459 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1460 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1461 self.lock.acquire()
1462
1463 if cip:
1464 self.ip_count += 1
1465
1466 elif cip is None:
1467 self.failure_count += 1
1468
1469 self.lock.notify_all()
1470 self.lock.release()
1471
1472 for i in range (1,4):
1473 self.ip_count = 0
1474 self.failure_count = 0
1475 self.start_time = 0
1476 self.diff = 0
1477 self.transaction_count = 0
1478 self.start_time = time.time()
1479
1480 while self.diff <= 60:
1481 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1482 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1483 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1484 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1485 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1486 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1487
1488 t.start()
1489 t1.start()
1490 t2.start()
1491 t3.start()
1492 t4.start()
1493 t5.start()
1494
1495 t.join()
1496 t1.join()
1497 t2.join()
1498 t3.join()
1499 t4.join()
1500 t5.join()
1501
1502 self.diff = round(time.time() - self.start_time, 0)
1503
1504 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1505
1506 self.transactions += (self.ip_count+self.failure_count)
1507 self.running_time += self.diff
1508 self.total_success += self.ip_count
1509 self.total_failure += self.failure_count
1510
1511
1512 log_test.info("----------------------------------------------------------------------------------")
1513 log_test.info("Statistics for run %d",i)
1514 log_test.info("----------------------------------------------------------------------------------")
1515 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1516 log_test.info(" %d %d %d %d"
1517 %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff))
1518 log_test.info("----------------------------------------------------------------------------------")
1519 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1520 log_test.info("----------------------------------------------------------------------------------")
1521
1522 log_test.info("----------------------------------------------------------------------------------")
1523 log_test.info("Final Statistics for total transactions")
1524 log_test.info("----------------------------------------------------------------------------------")
1525 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1526 log_test.info(" %d %d %d %d" %(self.transactions,
1527 self.total_success, self.total_failure, self.running_time))
1528
1529 log_test.info("----------------------------------------------------------------------------------")
1530 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1531 log_test.info("----------------------------------------------------------------------------------")
1532
1533 def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001534 failure_dir = {}
1535
1536 for key in (key for key in g_subscriber_port_map if key != 100):
1537 self.host_load(g_subscriber_port_map[key])
1538
1539 def thread_fun(i, j):
1540# log_test.info("Thread Name:%s",current_thread().name)
1541# failure_dir[current_thread().name] = True
1542 while failure_dir.has_key(current_thread().name) is False:
1543 mac = RandMAC()._fix()
1544 cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac)
1545 i += 2
1546 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1547 self.lock.acquire()
1548
1549 if cip:
1550 self.ip_count += 1
1551 self.lock.notify_all()
1552 self.lock.release()
1553 elif cip is None:
1554 self.failure_count += 1
1555 failure_dir[current_thread().name] = True
1556 self.lock.notify_all()
1557 self.lock.release()
1558 break
1559# self.lock.notify_all()
1560# self.lock.release()
1561
1562 for i in range (1,4):
1563 failure_dir = {}
1564 self.ip_count = 0
1565 self.failure_count = 0
1566 self.start_time = 0
1567 self.diff = 0
1568 self.transaction_count = 0
1569 self.start_time = time.time()
1570
1571 while len(failure_dir) != 6:
1572 t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1573 t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1574 t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1575 t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1576 t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1577 t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2})
1578
1579 t.start()
1580 t1.start()
1581 t2.start()
1582 t3.start()
1583 t4.start()
1584 t5.start()
1585
1586 t.join()
1587 t1.join()
1588 t2.join()
1589 t3.join()
1590 t4.join()
1591 t5.join()
1592
1593 self.diff = round(time.time() - self.start_time, 0)
1594 self.transaction_count = round((self.ip_count)/self.diff, 2)
1595
1596 self.transactions += (self.ip_count+self.failure_count)
1597 self.running_time += self.diff
1598 self.total_success += self.ip_count
1599 self.total_failure += self.failure_count
1600
1601
1602 log_test.info("Statistics for run %d",i)
1603 log_test.info("----------------------------------------------------------------------------------")
1604 log_test.info("No. of consecutive successful transactions Running Time ")
1605 log_test.info(" %d %d " %(self.ip_count, self.diff))
1606 log_test.info("----------------------------------------------------------------------------------")
1607 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1608 log_test.info("----------------------------------------------------------------------------------")
1609
1610 log_test.info("Final Statistics for total successful transactions")
1611 log_test.info("----------------------------------------------------------------------------------")
1612 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
1613 log_test.info(" %d %d %d " %(self.transactions,
1614 self.total_success, self.running_time))
1615 log_test.info("----------------------------------------------------------------------------------")
1616 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2))
1617 log_test.info("----------------------------------------------------------------------------------")
1618
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001619 def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001620 for key in (key for key in g_subscriber_port_map if key < 100):
1621 self.host_load(g_subscriber_port_map[key])
1622
1623 def thread_fun(i):
1624# mac = self.get_mac('veth{}'.format(i))
1625 cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix())
1626 log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac))
1627 self.lock.acquire()
1628
1629 if cip:
1630 self.ip_count += 1
1631 elif cip is None:
1632 self.failure_count += 1
1633
1634 self.lock.notify_all()
1635 self.lock.release()
1636
1637 for i in range (1,4):
1638 self.ip_count = 0
1639 self.failure_count = 0
1640 self.start_time = 0
1641 self.diff = 0
1642 self.transaction_count = 0
1643 self.start_time = time.time()
1644
1645 while self.diff <= 60:
1646 t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)})
1647 t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)})
1648 t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)})
1649 t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)})
1650 t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)})
1651 t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)})
1652
1653 t.start()
1654 t1.start()
1655 t2.start()
1656 t3.start()
1657 t4.start()
1658 t5.start()
1659
1660 t.join()
1661 t1.join()
1662 t2.join()
1663 t3.join()
1664 t4.join()
1665 t5.join()
1666
1667 self.diff = round(time.time() - self.start_time, 0)
1668 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1669 self.transactions += (self.ip_count+self.failure_count)
1670 self.running_time += self.diff
1671 self.total_success += self.ip_count
1672 self.total_failure += self.failure_count
1673
1674 log_test.info("----------------------------------------------------------------------------------")
1675 log_test.info("Statistics for run %d of sending only DHCP Discover",i)
1676 log_test.info("----------------------------------------------------------------------------------")
1677 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
1678 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1679 log_test.info("----------------------------------------------------------------------------------")
1680 log_test.info("No. of clients per second in run %d:%f "
1681 %(i, self.transaction_count))
1682 log_test.info("----------------------------------------------------------------------------------")
1683
1684 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
1685 log_test.info("----------------------------------------------------------------------------------")
1686 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1687 log_test.info(" %d %d %d %d" %(self.transactions,
1688 self.total_success, self.total_failure, self.running_time))
1689 log_test.info("----------------------------------------------------------------------------------")
1690 log_test.info("Average no. of clients per second: %d ",
1691 round(self.transactions/self.running_time,0))
1692 log_test.info("----------------------------------------------------------------------------------")
1693
Chetan Gaonkera6050ae2017-09-02 19:15:01 +00001694 def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'):
Chetan Gaonkerc1df33a2017-08-18 01:29:54 +00001695 mac = self.get_mac(iface)
1696 self.host_load(iface)
1697 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1698 cip, sip, mac, _ = self.dhcp.only_discover()
1699 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1700 (cip, sip, mac) )
1701 self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface)
1702 new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True)
1703 new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac)
1704 log_test.info('Got dhcp client IP %s from server %s for mac %s.' %
1705 (new_cip, new_sip, new_mac) )
1706 log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac))
1707 log_test.info("Now sending DHCP Request for old DHCP discover.")
1708 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1709 if new_cip is None:
1710 log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.'
1711 %(new_cip, new_sip, new_mac) )
1712 elif new_cip:
1713 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.'
1714 %(new_cip, new_sip, new_mac, new_cip) )
1715 assert_equal(new_cip, None)