Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1 | |
| 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 | # |
| 32 | import unittest |
| 33 | from nose.tools import * |
| 34 | from nose.twistedtools import reactor, deferred |
| 35 | from twisted.internet import defer |
| 36 | import time |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 37 | import os, sys, re, json |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 38 | from DHCP import DHCPTest |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 39 | from CordTestUtils import get_mac, log_test, getstatusoutput, get_controller |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 40 | from SSHTestAgent import SSHTestAgent |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 41 | from OnosCtrl import OnosCtrl |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 42 | from onosclidriver import OnosCliDriver |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 43 | from OltConfig import OltConfig |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 44 | from CordTestServer import cord_test_onos_restart, cord_test_ovs_flow_add,cord_test_onos_shutdown |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 45 | from CordTestConfig import setup_module, teardown_module |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 46 | from CordLogger import CordLogger |
| 47 | from portmaps import g_subscriber_port_map |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 48 | from CordContainer import Onos |
A R Karthick | e723209 | 2017-09-07 18:01:33 -0700 | [diff] [blame] | 49 | from VolthaCtrl import VolthaCtrl |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 50 | import threading, random |
| 51 | from threading import current_thread |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 52 | import requests |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 53 | log_test.setLevel('INFO') |
| 54 | |
| 55 | class dhcpl2relay_exchange(CordLogger): |
| 56 | |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 57 | VOLTHA_HOST = None |
A R Karthick | e723209 | 2017-09-07 18:01:33 -0700 | [diff] [blame] | 58 | VOLTHA_REST_PORT = VolthaCtrl.REST_PORT |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 59 | 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 Karthick | e216824 | 2017-10-05 16:50:07 -0700 | [diff] [blame] | 63 | TAGGED_TRAFFIC = False |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 64 | app = 'org.opencord.dhcpl2relay' |
| 65 | sadis_app = 'org.opencord.sadis' |
| 66 | app_dhcp = 'org.onosproject.dhcp' |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 67 | app_olt = 'org.onosproject.olt' |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 68 | relay_interfaces = () |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 69 | relay_interfaces_last = () |
| 70 | interface_to_mac_map = {} |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 71 | relay_vlan_map = {} |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 72 | 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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 75 | dhcpl2_app_file = os.path.join(test_path, '..', 'apps/dhcpl2relay-1.0.0.oar') |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 76 | olt_app_file = os.path.join(test_path, '..', 'apps/olt-app-3.0-SNAPSHOT.oar') |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 77 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 79 | 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 | ''' |
| 87 | subnet 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 106 | sadis_configs = {} |
| 107 | default_onos_netcfg = {} |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 108 | voltha_switch_map = None |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 109 | remote_dhcpd_cmd = [] |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 110 | ONOS_INSTANCES = 3 |
| 111 | relay_device_id = None |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 112 | |
| 113 | @classmethod |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 114 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 119 | sadis_app_version = '3.0-SNAPSHOT' |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 120 | 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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 123 | @classmethod |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 124 | def setUpClass(cls): |
| 125 | ''' Activate the cord dhcpl2relay app''' |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 126 | cls.update_apps_version() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 127 | OnosCtrl(cls.app_dhcp).deactivate() |
| 128 | time.sleep(3) |
| 129 | cls.onos_ctrl = OnosCtrl(cls.app) |
| 130 | status, _ = cls.onos_ctrl.activate() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 131 | #assert_equal(status, True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 132 | time.sleep(3) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 133 | status, _ = OnosCtrl(cls.sadis_app).activate() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 134 | #assert_equal(status, True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 135 | time.sleep(3) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 136 | cls.setup_dhcpd() |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 137 | cls.default_onos_netcfg = OnosCtrl.get_config() |
| 138 | |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 139 | |
| 140 | def setUp(self): |
| 141 | super(dhcpl2relay_exchange, self).setUp() |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 142 | #self.dhcp_l2_relay_setup() |
| 143 | #self.cord_sadis_load() |
| 144 | #self.cord_l2_relay_load() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 145 | |
| 146 | def tearDown(self): |
| 147 | super(dhcpl2relay_exchange, self).tearDown() |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 148 | #OnosCtrl.uninstall_app(self.dhcpl2_app_file) |
| 149 | #OnosCtrl.uninstall_app(self.sadis_app_file) |
| 150 | #OnosCtrl.uninstall_app(self.olt_app_file) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 151 | |
| 152 | @classmethod |
| 153 | def tearDownClass(cls): |
| 154 | '''Deactivate the cord dhcpl2relay app''' |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 155 | cls.onos_load_config(cls.default_onos_netcfg) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 156 | #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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 162 | 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 Prete | 9c0cdac | 2018-07-02 14:40:40 +0200 | [diff] [blame] | 173 | if device['available'] is True and device['driver'] == 'voltha': |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 174 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 181 | 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 Karthick | 760d138 | 2017-10-05 13:48:40 -0700 | [diff] [blame] | 187 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 193 | |
| 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 247 | st, output = getstatusoutput('pgrep -f "{}"'.format(pattern)) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 248 | 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 Karthick | ce96dde | 2017-10-05 16:41:52 -0700 | [diff] [blame] | 284 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 288 | 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 Karthick | ce96dde | 2017-10-05 16:41:52 -0700 | [diff] [blame] | 292 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 296 | #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 Karthick | ce96dde | 2017-10-05 16:41:52 -0700 | [diff] [blame] | 320 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 321 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 331 | |
| 332 | @classmethod |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 333 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 379 | def dhcp_l2_relay_setup(cls): |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 380 | device_details = OnosCtrl.get_devices(mfr = 'Nicira') |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 381 | if device_details is not None: |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 382 | did_ovs = device_details[0]['id'] |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 383 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 387 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 416 | cls.onos_interface_load(interface_list) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 417 | |
| 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 423 | cls.onos_load_config(cls.default_onos_config) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 424 | # 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 437 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 445 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 462 | def cord_l2_relay_load(cls, dhcp_server_connectPoint = None, delete = False): |
A R Karthick | 5373566 | 2017-10-05 12:53:35 -0700 | [diff] [blame] | 463 | ##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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 471 | OnosCtrl.uninstall_app(cls.dhcpl2_app_file) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 472 | relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 473 | #### We have to work on later versions by removing these hard coded values |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 474 | if dhcp_server_connectPoint is None: |
A R Karthick | 8fe89a1 | 2017-10-05 13:12:13 -0700 | [diff] [blame] | 475 | 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 Karthick | 5373566 | 2017-10-05 12:53:35 -0700 | [diff] [blame] | 478 | else: |
| 479 | cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint) |
| 480 | connect_points = list(connect_points) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 481 | dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" : |
A R Karthick | 5373566 | 2017-10-05 12:53:35 -0700 | [diff] [blame] | 482 | {"dhcpServerConnectPoints": connect_points} |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | } |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 486 | #OnosCtrl.uninstall_app(cls.dhcpl2_app_file) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 487 | OnosCtrl.install_app(cls.dhcpl2_app_file) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 488 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 493 | cls.configs['relay_config'] = dhcp_dict |
| 494 | |
| 495 | @classmethod |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 496 | def cord_sadis_load(cls, sadis_info = None): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 497 | relay_device_id = '{}'.format(cls.relay_device_id) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 498 | 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 Prete | 9c0cdac | 2018-07-02 14:40:40 +0200 | [diff] [blame] | 502 | if device['available'] is True and device['driver'] == 'voltha': |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 503 | 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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 509 | sadis_dict = { "apps": { |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 510 | "org.opencord.sadis": { |
| 511 | "sadis": { |
| 512 | "integration": { |
| 513 | "cache": { |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 514 | "enabled": "true", |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 515 | "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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 526 | "id": cls.olt_serial_id, |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 527 | "hardwareIdentifier": "00:0c:e2:31:05:00", |
| 528 | "ipAddress": "172.17.0.1", |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 529 | "nasId": "B100-NASID" |
| 530 | } |
| 531 | ] |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | } |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 535 | } |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 536 | #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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 540 | OnosCtrl.install_app(cls.sadis_app_file) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 541 | if sadis_info: |
| 542 | sadis_dict = sadis_info |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 543 | cls.onos_load_config(sadis_dict) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 544 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 593 | |
| 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 S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 598 | cls.host_ip_map[port] = '192.168.100.{}'.format(port) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 599 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 614 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 621 | def dhcpl2relay_stats_calc(self, success_rate = False, only_discover = False, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 622 | |
| 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 630 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 667 | 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 Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 949 | def test_dhcpl2relay_initialize(self): |
A R Karthick | 760d138 | 2017-10-05 13:48:40 -0700 | [diff] [blame] | 950 | '''Configure the DHCP L2 relay app and start dhcpd''' |
| 951 | self.dhcpd_start() |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 952 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 953 | def test_dhcpl2relay_with_one_request(self, iface = 'veth0'): |
| 954 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 955 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 956 | self.send_recv(mac=mac) |
| 957 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 958 | def test_dhcpl2relay_app_install(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 959 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 970 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 971 | def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 972 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 983 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 984 | def test_dhcpl2relay_netcfg(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 985 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 986 | 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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1003 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1010 | 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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1013 | app_status = True |
| 1014 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1015 | log_test.info('%s app is not installed or network configuration is not shown'%app_name) |
| 1016 | assert_equal(True, False) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1017 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1018 | def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'): |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1019 | 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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1028 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1029 | self.onos_load_config(self.default_onos_netcfg) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1030 | 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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1036 | onos_netcfg = OnosCtrl.get_config() |
| 1037 | app_status = False |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1038 | app_name = 'org.opencord.dhcpl2relay' |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1039 | for app in onos_netcfg['apps']: |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1040 | if app == app_name and onos_netcfg['apps'][app] != {}: |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1041 | log_test.info('%s app is being installed'%app) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1042 | 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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1046 | app_status = True |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1047 | break |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1048 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1049 | log_test.info('%s app is not installed or network configuration is not shown'%app_name) |
| 1050 | assert_equal(True, False) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1051 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1052 | self.send_recv(mac=mac) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1053 | |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1054 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1055 | def test_dhcpl2relay_with_subscriber_configured_with_ctag_stag_as_per_sadis(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1056 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1057 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1099 | log_test.info('Uninstall the sadis app from onos ,app version = %s '%self.sadis_app_file) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1100 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1105 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1109 | #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 S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1123 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1133 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1134 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'] == subscriber_port_id: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1135 | log_test.info('The network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['id'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1136 | app_status = True |
| 1137 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1138 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
| 1139 | |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1140 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1144 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1145 | def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1146 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1147 | c_tag = 600 |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1148 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1157 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1158 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1159 | log_test.info('The C Tag info from network configuration is = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1160 | app_status = True |
| 1161 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1162 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1163 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1167 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1168 | def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1169 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1170 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1180 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1181 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'] == s_tag: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1182 | log_test.info('The S Tag info from the network configuration is = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['sTag'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1183 | app_status = True |
| 1184 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1185 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1186 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1190 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1191 | def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1192 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1193 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1202 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1203 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ": |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1204 | log_test.info('The nasPortId info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1205 | app_status = True |
| 1206 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1207 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1208 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1212 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1213 | def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1214 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1215 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1225 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1226 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == nas_port_id: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1227 | log_test.info('The nasPortId info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1228 | app_status = True |
| 1229 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1230 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1231 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1235 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1236 | def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1237 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1238 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1247 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1248 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ": |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1249 | log_test.info('The serial Id info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1250 | app_status = True |
| 1251 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1252 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1253 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1257 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1258 | def test_dhcpl2relay_with_wrong_serial_id_of_olt(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1259 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1260 | 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 S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1270 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1271 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == olt_serial_id: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 1272 | log_test.info('The serial Id info from network configuration is shown = %s'%(onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'])) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 1273 | 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 Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 1279 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1280 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'): |
| 1281 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1282 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1285 | log_test.info('Dhcp server rejected client discover with invalid source mac, as expected') |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1286 | |
| 1287 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'): |
| 1288 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1289 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1292 | log_test.info('Dhcp server rejected client discover with invalid source mac, as expected') |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1293 | |
| 1294 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'): |
| 1295 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1296 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1301 | ### We can't test this on single uni port setup, hence its not to test |
Thangavelu K S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1302 | @nottest |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1303 | def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10): |
| 1304 | mac = self.get_mac(iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1305 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1306 | ip_map = {} |
| 1307 | for i in range(requests): |
| 1308 | #mac = RandMAC()._fix() |
| 1309 | #log_test.info('mac is %s'%mac) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1310 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1311 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1319 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1330 | @nottest |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1331 | def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'): |
| 1332 | mac = None |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1333 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1359 | @nottest |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1360 | def test_dhcpl2relay_starvation(self, iface = 'veth0'): |
| 1361 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1362 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1367 | cip, sip = self.send_recv(mac=mac,update_seed = True,validate = False) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1368 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1380 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1381 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1382 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1386 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1387 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1392 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1403 | self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1404 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1405 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1409 | def test_dhcpl2relay_with_clients_desired_address_out_of_pool(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1410 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1411 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1412 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac,desired = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1413 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1419 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1420 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1421 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1428 | def test_dhcpl2relay_client_requests_with_specific_lease_time_in_discover_message(self, iface = 'veth0',lease_time=700): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1429 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1430 | self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface) |
| 1431 | self.dhcp.return_option = 'lease' |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1432 | cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time=True,lease_value=lease_time) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1433 | assert_equal(lval, lease_time) |
| 1434 | log_test.info('dhcp server offered IP address with client requested lease time') |
| 1435 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1436 | def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1437 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1438 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1439 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1440 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1452 | def test_dhcpl2relay_after_server_shutting_down(self, iface = 'veth0'): |
| 1453 | self.get_dhcpd_process() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1454 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1455 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1456 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1457 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1462 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1473 | |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1474 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1496 | def test_dhcpl2relay_after_server_stop_start(self, iface = 'veth0'): |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1497 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1524 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1525 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1528 | cip, sip, mac, lval = self.dhcp.only_discover(mac=mac,lease_time = True, lease_value=lease_time) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1529 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1535 | def test_dhcpl2relay_with_specific_lease_time_in_request_and_without_in_discover_packet(self, iface = 'veth0',lease_time=800): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1536 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1537 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1538 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1539 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1544 | @nottest |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1545 | def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1546 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1547 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1548 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1549 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1553 | log_test.info('waiting for renew time.. a= %s b= %s c= %s'%(new_cip,new_sip,lval)) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1554 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1559 | @nottest |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1560 | def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1561 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1562 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1563 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1564 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1574 | def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1575 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1576 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1580 | cip, sip, mac, subnet_mask = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1581 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1586 | def test_dhcpl2relay_with_client_sending_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1587 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1588 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1589 | |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1590 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1591 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1599 | @nottest |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1600 | def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1601 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1602 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1606 | cip, sip, mac, router_address_value = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1607 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1612 | @nottest |
| 1613 | def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1614 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1615 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1616 | |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1617 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1618 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1628 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1632 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1633 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1638 | def test_dhcpl2relay_by_client_sending_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1639 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1640 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1641 | |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1642 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1643 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1651 | def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1652 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1653 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1657 | cip, sip, mac, dns_address_value = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1658 | 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 S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1663 | def test_dhcpl2relay_by_client_sending_request_with_wrong_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1664 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1665 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1666 | |
Thangavelu K S | d4d954f | 2017-10-12 20:05:30 +0000 | [diff] [blame] | 1667 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1668 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1680 | self.dhcpl2relay_stats_calc() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1681 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1699 | self.dhcpl2relay_stats_calc(success_rate = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1700 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1720 | self.dhcpl2relay_stats_calc(only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1721 | 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 Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1743 | self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1744 | 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 Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1763 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1842 | @nottest |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1843 | def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1844 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 1929 | @nottest |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1930 | def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1931 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 2005 | @nottest |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 2006 | def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 2007 | 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 S | aec97e6 | 2017-10-25 03:09:36 -0700 | [diff] [blame] | 2028 | |
| 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 | |