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 |
| 37 | import os, sys |
| 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 |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 40 | from OnosCtrl import OnosCtrl |
| 41 | from OltConfig import OltConfig |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 42 | from CordTestServer import cord_test_onos_restart, cord_test_ovs_flow_add |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 43 | from CordTestConfig import setup_module, teardown_module |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 44 | from CordLogger import CordLogger |
| 45 | from portmaps import g_subscriber_port_map |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 46 | from CordContainer import Onos |
A R Karthick | e723209 | 2017-09-07 18:01:33 -0700 | [diff] [blame] | 47 | from VolthaCtrl import VolthaCtrl |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 48 | import threading, random |
| 49 | from threading import current_thread |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 50 | import requests |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 51 | log_test.setLevel('INFO') |
| 52 | |
| 53 | class dhcpl2relay_exchange(CordLogger): |
| 54 | |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 55 | VOLTHA_HOST = None |
A R Karthick | e723209 | 2017-09-07 18:01:33 -0700 | [diff] [blame] | 56 | VOLTHA_REST_PORT = VolthaCtrl.REST_PORT |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 57 | VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0))) |
| 58 | VOLTHA_OLT_TYPE = 'simulated_olt' |
| 59 | VOLTHA_OLT_MAC = '00:0c:e2:31:12:00' |
| 60 | VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' } |
| 61 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 62 | app = 'org.opencord.dhcpl2relay' |
| 63 | sadis_app = 'org.opencord.sadis' |
| 64 | app_dhcp = 'org.onosproject.dhcp' |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 65 | app_olt = 'org.onosproject.olt' |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 66 | relay_interfaces = () |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 67 | relay_interfaces_last = () |
| 68 | interface_to_mac_map = {} |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 69 | relay_vlan_map = {} |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 70 | host_ip_map = {} |
| 71 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 72 | dhcp_data_dir = os.path.join(test_path, '..', 'setup') |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 73 | 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] | 74 | 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] | 75 | sadis_app_file = os.path.join(test_path, '..', 'apps/sadis-app-1.0.0-SNAPSHOT.oar') |
| 76 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config_voltha_local.json')) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 77 | default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, } |
| 78 | default_options = [ ('subnet-mask', '255.255.255.0'), |
| 79 | ('broadcast-address', '192.168.1.255'), |
| 80 | ('domain-name-servers', '192.168.1.1'), |
| 81 | ('domain-name', '"mydomain.cord-tester"'), |
| 82 | ] |
| 83 | default_subnet_config = [ ('192.168.1.2', |
| 84 | ''' |
| 85 | subnet 192.168.1.0 netmask 255.255.255.0 { |
| 86 | range 192.168.1.10 192.168.1.100; |
| 87 | } |
| 88 | '''), ] |
| 89 | |
| 90 | lock = threading.Condition() |
| 91 | ip_count = 0 |
| 92 | failure_count = 0 |
| 93 | start_time = 0 |
| 94 | diff = 0 |
| 95 | |
| 96 | transaction_count = 0 |
| 97 | transactions = 0 |
| 98 | running_time = 0 |
| 99 | total_success = 0 |
| 100 | total_failure = 0 |
| 101 | #just in case we want to reset ONOS to default network cfg after relay tests |
| 102 | onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0))) |
| 103 | configs = {} |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 104 | sadis_configs = {} |
| 105 | default_onos_netcfg = {} |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 106 | voltha_switch_map = None |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 107 | |
| 108 | @classmethod |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 109 | def update_apps_version(cls): |
| 110 | version = Onos.getVersion() |
| 111 | major = int(version.split('.')[0]) |
| 112 | minor = int(version.split('.')[1]) |
| 113 | dhcpl2_app_version = '1.0.0' |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 114 | sadis_app_version = '3.0-SNAPSHOT' |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 115 | cls.dhcpl2_app_file = os.path.join(cls.test_path, '..', 'apps/dhcpl2relay-{}.oar'.format(dhcpl2_app_version)) |
| 116 | cls.sadis_app_file = os.path.join(cls.test_path, '..', 'apps/sadis-app-{}.oar'.format(sadis_app_version)) |
| 117 | |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 118 | @classmethod |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 119 | def setUpClass(cls): |
| 120 | ''' Activate the cord dhcpl2relay app''' |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 121 | cls.update_apps_version() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 122 | OnosCtrl(cls.app_dhcp).deactivate() |
| 123 | time.sleep(3) |
| 124 | cls.onos_ctrl = OnosCtrl(cls.app) |
| 125 | status, _ = cls.onos_ctrl.activate() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 126 | #assert_equal(status, True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 127 | time.sleep(3) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 128 | status, _ = OnosCtrl(cls.sadis_app).activate() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 129 | #assert_equal(status, True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 130 | time.sleep(3) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 131 | cls.setup_dhcpd() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 132 | |
| 133 | def setUp(self): |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 134 | self.default_onos_netcfg = OnosCtrl.get_config() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 135 | super(dhcpl2relay_exchange, self).setUp() |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 136 | #self.dhcp_l2_relay_setup() |
| 137 | #self.cord_sadis_load() |
| 138 | #self.cord_l2_relay_load() |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 139 | |
| 140 | def tearDown(self): |
| 141 | super(dhcpl2relay_exchange, self).tearDown() |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 142 | #OnosCtrl.uninstall_app(self.dhcpl2_app_file) |
| 143 | #OnosCtrl.uninstall_app(self.sadis_app_file) |
| 144 | #OnosCtrl.uninstall_app(self.olt_app_file) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 145 | |
| 146 | @classmethod |
| 147 | def tearDownClass(cls): |
| 148 | '''Deactivate the cord dhcpl2relay app''' |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 149 | #cls.onos_ctrl.deactivate() |
| 150 | #OnosCtrl(cls.sadis_app).deactivate() |
| 151 | #OnosCtrl(cls.app_olt).deactivate() |
| 152 | |
| 153 | @classmethod |
| 154 | def setup_dhcpd(cls, boot_delay = 5): |
| 155 | if cls.service_running("/usr/sbin/dhcpd"): |
| 156 | print('DHCPD already running in container') |
| 157 | return True |
| 158 | setup_for_relay = cls.dhcp_l2_relay_setup() |
| 159 | cls.cord_l2_relay_load() |
| 160 | cls.voltha_setup() |
| 161 | dhcp_start_status = cls.dhcpd_start() |
| 162 | if setup_for_relay and dhcp_start_status: |
| 163 | return True |
| 164 | return False |
| 165 | |
| 166 | @classmethod |
| 167 | def config_olt(cls, switch_map): |
| 168 | controller = get_controller() |
| 169 | auth = ('karaf', 'karaf') |
| 170 | #configure subscriber for every port on all the voltha devices |
| 171 | for device, device_map in switch_map.iteritems(): |
| 172 | uni_ports = device_map['ports'] |
| 173 | uplink_vlan = device_map['uplink_vlan'] |
| 174 | for port in uni_ports: |
| 175 | vlan = port |
| 176 | rest_url = 'http://{}:8181/onos/olt/oltapp/{}/{}/{}'.format(controller, |
| 177 | device, |
| 178 | port, |
| 179 | vlan) |
| 180 | requests.post(rest_url, auth = auth) |
| 181 | |
| 182 | @classmethod |
| 183 | def voltha_setup(cls): |
| 184 | s_tag_map = {} |
| 185 | #configure olt app to provision dhcp flows |
| 186 | cls.config_olt(cls.voltha_switch_map) |
| 187 | for switch, switch_map in cls.voltha_switch_map.iteritems(): |
| 188 | s_tag_map[int(switch_map['uplink_vlan'])] = map(lambda p: int(p), switch_map['ports']) |
| 189 | |
| 190 | cmd_list = [] |
| 191 | relay_interface = cls.relay_interfaces[0] |
| 192 | cls.relay_vlan_map[relay_interface] = [] |
| 193 | for s_tag, ports in s_tag_map.iteritems(): |
| 194 | vlan_stag_intf = '{}.{}'.format(relay_interface, s_tag) |
| 195 | cmd = 'ip link add link %s name %s type vlan id %d' %(relay_interface, vlan_stag_intf, s_tag) |
| 196 | cmd_list.append(cmd) |
| 197 | cmd = 'ip link set %s up' %(vlan_stag_intf) |
| 198 | cmd_list.append(cmd) |
| 199 | for port in ports: |
| 200 | vlan_ctag_intf = '{}.{}.{}'.format(relay_interface, s_tag, port) |
| 201 | cmd = 'ip link add link %s name %s type vlan id %d' %(vlan_stag_intf, vlan_ctag_intf, port) |
| 202 | cmd_list.append(cmd) |
| 203 | cmd = 'ip link set %s up' %(vlan_ctag_intf) |
| 204 | cmd_list.append(cmd) |
| 205 | cls.relay_vlan_map[relay_interface].append(vlan_ctag_intf) |
| 206 | cls.relay_vlan_map[relay_interface].append(vlan_stag_intf) |
| 207 | |
| 208 | for cmd in cmd_list: |
| 209 | log_test.info('Running command: %s' %cmd) |
| 210 | os.system(cmd) |
| 211 | |
| 212 | cord_test_ovs_flow_add(cls.relay_interface_port) |
| 213 | for s_tag in s_tag_map.keys(): |
| 214 | log_test.info('Configuring OVS flow for port %d, s_tag %d' %(cls.relay_interface_port, s_tag)) |
| 215 | cord_test_ovs_flow_add(cls.relay_interface_port, s_tag) |
| 216 | |
| 217 | @classmethod |
| 218 | def service_running(cls, pattern): |
| 219 | st, _ = getstatusoutput('pgrep -f "{}"'.format(pattern)) |
| 220 | return True if st == 0 else False |
| 221 | |
| 222 | @classmethod |
| 223 | def dhcpd_conf_generate(cls, config = default_config, options = default_options, |
| 224 | subnet = default_subnet_config): |
| 225 | conf = '' |
| 226 | for k, v in config.items(): |
| 227 | conf += '{} {};\n'.format(k, v) |
| 228 | |
| 229 | opts = '' |
| 230 | for k, v in options: |
| 231 | opts += 'option {} {};\n'.format(k, v) |
| 232 | |
| 233 | subnet_config = '' |
| 234 | for _, v in subnet: |
| 235 | subnet_config += '{}\n'.format(v) |
| 236 | |
| 237 | return '{}{}{}'.format(conf, opts, subnet_config) |
| 238 | |
| 239 | @classmethod |
| 240 | def dhcpd_start(cls, intf_list = None, |
| 241 | config = default_config, options = default_options, |
| 242 | subnet = default_subnet_config): |
| 243 | '''Start the dhcpd server by generating the conf file''' |
| 244 | if intf_list is None: |
| 245 | intf_list = cls.relay_interfaces |
| 246 | intf_list = list(intf_list) |
| 247 | ##stop dhcpd if already running |
| 248 | #cls.dhcpd_stop() |
| 249 | dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options, |
| 250 | subnet = subnet) |
| 251 | ##first touch dhcpd.leases if it doesn't exist |
| 252 | lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir) |
| 253 | if os.access(lease_file, os.F_OK) is False: |
| 254 | with open(lease_file, 'w') as fd: pass |
| 255 | |
| 256 | conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir) |
| 257 | with open(conf_file, 'w') as fd: |
| 258 | fd.write(dhcp_conf) |
| 259 | |
| 260 | #now configure the dhcpd interfaces for various subnets |
| 261 | index = 0 |
| 262 | intf_info = [] |
| 263 | vlan_intf_list = [] |
| 264 | for ip,_ in subnet: |
| 265 | vlan_intf = None |
| 266 | intf = intf_list[index] |
| 267 | if intf in cls.relay_vlan_map: |
| 268 | vlan_intf = cls.relay_vlan_map[intf][0] |
| 269 | vlan_intf_list.append(vlan_intf) |
| 270 | mac = cls.get_mac(intf) |
| 271 | intf_info.append((ip, mac)) |
| 272 | index += 1 |
| 273 | cmd = 'ifconfig {} {}'.format(intf, ip) |
| 274 | status = os.system(cmd) |
| 275 | if vlan_intf: |
| 276 | cmd = 'ifconfig {} {}'.format(vlan_intf, ip) |
| 277 | os.system(cmd) |
| 278 | |
| 279 | intf_str = ','.join(intf_list) |
| 280 | dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format('/root/test/src/test/setup/dhcpd.conf','/root/test/src/test/setup/dhcpd.leases', intf_str) |
| 281 | print('Starting DHCPD server with command: %s' %dhcpd_cmd) |
| 282 | status = os.system(dhcpd_cmd) |
| 283 | vlan_intf_str = ','.join(vlan_intf_list) |
| 284 | dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format('/root/test/src/test/setup/dhcpd.conf','/root/test/src/test/setup/dhcpd.leases', vlan_intf_str) |
| 285 | print('Starting DHCPD server with command: %s' %dhcpd_cmd) |
| 286 | status = os.system(dhcpd_cmd) |
| 287 | if status > 255: |
| 288 | status = 1 |
| 289 | else: |
| 290 | return False |
| 291 | time.sleep(3) |
| 292 | cls.relay_interfaces_last = cls.relay_interfaces |
| 293 | cls.relay_interfaces = intf_list |
| 294 | return True |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 295 | |
| 296 | @classmethod |
| 297 | def dhcp_l2_relay_setup(cls): |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 298 | device_details = OnosCtrl.get_devices(mfr = 'Nicira') |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 299 | if device_details is not None: |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 300 | did_ovs = device_details[0]['id'] |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 301 | else: |
| 302 | log_test.info('On this DHCPl2relay setup, onos does not have ovs device where external DHCP server is have connect point, so return with false status') |
| 303 | return False |
| 304 | cls.relay_device_id = did_ovs |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 305 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 306 | cls.port_map, _ = cls.olt.olt_port_map() |
| 307 | if cls.port_map: |
| 308 | ##Per subscriber, we use 1 relay port |
| 309 | try: |
| 310 | relay_port = cls.port_map[cls.port_map['relay_ports'][0]] |
| 311 | except: |
| 312 | relay_port = cls.port_map['uplink'] |
| 313 | cls.relay_interface_port = relay_port |
| 314 | cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],) |
| 315 | else: |
| 316 | cls.relay_interface_port = 100 |
| 317 | cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],) |
| 318 | cls.relay_interfaces_last = cls.relay_interfaces |
| 319 | if cls.port_map: |
| 320 | ##generate a ip/mac client virtual interface config for onos |
| 321 | interface_list = [] |
| 322 | for port in cls.port_map['ports']: |
| 323 | port_num = cls.port_map[port] |
| 324 | if port_num == cls.port_map['uplink']: |
| 325 | continue |
| 326 | ip = cls.get_host_ip(port_num) |
| 327 | mac = cls.get_mac(port) |
| 328 | interface_list.append((port_num, ip, mac)) |
| 329 | |
| 330 | #configure dhcp server virtual interface on the same subnet as first client interface |
| 331 | relay_ip = cls.get_host_ip(interface_list[0][0]) |
| 332 | relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port]) |
| 333 | interface_list.append((cls.relay_interface_port, relay_ip, relay_mac)) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 334 | cls.onos_interface_load(interface_list) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 335 | |
| 336 | @classmethod |
| 337 | def dhcp_l2_relay_cleanup(cls): |
| 338 | ##reset the ONOS port configuration back to default |
| 339 | for config in cls.configs.items(): |
| 340 | OnosCtrl.delete(config) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 341 | cls.onos_load_config(cls.default_onos_config) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 342 | # if cls.onos_restartable is True: |
| 343 | # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg') |
| 344 | # return cord_test_onos_restart(config = {}) |
| 345 | |
| 346 | @classmethod |
| 347 | def onos_load_config(cls, config): |
| 348 | status, code = OnosCtrl.config(config) |
| 349 | if status is False: |
| 350 | log_test.info('JSON request returned status %d' %code) |
| 351 | assert_equal(status, True) |
| 352 | time.sleep(3) |
| 353 | |
| 354 | @classmethod |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 355 | def onos_delete_config(cls, config): |
| 356 | status, code = OnosCtrl.delete(config) |
| 357 | if status is False: |
| 358 | log_test.info('JSON request returned status %d' %code) |
| 359 | assert_equal(status, True) |
| 360 | time.sleep(3) |
| 361 | |
| 362 | @classmethod |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 363 | def onos_interface_load(cls, interface_list): |
| 364 | interface_dict = { 'ports': {} } |
| 365 | for port_num, ip, mac in interface_list: |
| 366 | port_map = interface_dict['ports'] |
| 367 | port = '{}/{}'.format(cls.relay_device_id, port_num) |
| 368 | port_map[port] = { 'interfaces': [] } |
| 369 | interface_list = port_map[port]['interfaces'] |
| 370 | interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ], |
| 371 | 'mac' : mac, |
| 372 | 'name': 'vir-{}'.format(port_num) |
| 373 | } |
| 374 | interface_list.append(interface_map) |
| 375 | |
| 376 | cls.onos_load_config(interface_dict) |
| 377 | cls.configs['interface_config'] = interface_dict |
| 378 | |
| 379 | @classmethod |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 380 | 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] | 381 | ##read the current config |
| 382 | current_netcfg = OnosCtrl.get_config() |
| 383 | connect_points = set([]) |
| 384 | try: |
| 385 | connect_points = set(current_netcfg['apps']['org.opencord.dhcpl2relay']['dhcpl2relay']['dhcpServerConnectPoints']) |
| 386 | except KeyError, e: |
| 387 | pass |
| 388 | |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 389 | OnosCtrl.uninstall_app(cls.dhcpl2_app_file) |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 390 | 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] | 391 | #### 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] | 392 | if dhcp_server_connectPoint is None: |
A R Karthick | 8fe89a1 | 2017-10-05 13:12:13 -0700 | [diff] [blame^] | 393 | relay_device_present = filter(lambda cp: cp.split('/')[0] == cls.relay_device_id, connect_points) |
| 394 | if not relay_device_present: |
| 395 | connect_points.add(relay_device_map) |
A R Karthick | 5373566 | 2017-10-05 12:53:35 -0700 | [diff] [blame] | 396 | else: |
| 397 | cps_unused = map(lambda cp: connect_points.add(cp), dhcp_server_connectPoint) |
| 398 | connect_points = list(connect_points) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 399 | dhcp_dict = { "apps" : { "org.opencord.dhcpl2relay" : {"dhcpl2relay" : |
A R Karthick | 5373566 | 2017-10-05 12:53:35 -0700 | [diff] [blame] | 400 | {"dhcpServerConnectPoints": connect_points} |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | } |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 404 | #OnosCtrl.uninstall_app(cls.dhcpl2_app_file) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 405 | OnosCtrl.install_app(cls.dhcpl2_app_file) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 406 | if delete == False: |
| 407 | cls.onos_load_config(dhcp_dict) |
| 408 | else: |
| 409 | cls.onos_delete_config(dhcp_dict) |
| 410 | cls.onos_load_config(cls.default_onos_config) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 411 | cls.configs['relay_config'] = dhcp_dict |
| 412 | |
| 413 | @classmethod |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 414 | def cord_sadis_load(cls, sadis_info = None): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 415 | relay_device_id = '{}'.format(cls.relay_device_id) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 416 | device_details = OnosCtrl.get_devices() |
| 417 | if device_details is not None: |
| 418 | for device in device_details: |
| 419 | ## Assuming only one OVS is detected on ONOS and its for external DHCP server connect point... |
| 420 | if device['available'] is True and device['driver'] == 'pmc-olt': |
| 421 | cls.olt_serial_id = "{}".format(device['serial']) |
| 422 | else: |
| 423 | cls.olt_serial_id = " " |
| 424 | else: |
| 425 | 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') |
| 426 | return False |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 427 | sadis_dict = { "apps": { |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 428 | "org.opencord.sadis": { |
| 429 | "sadis": { |
| 430 | "integration": { |
| 431 | "cache": { |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 432 | "enabled": "true", |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 433 | "maxsize": 50, |
| 434 | "ttl": "PT1m" |
| 435 | } |
| 436 | }, |
| 437 | "entries": [{ |
| 438 | "id": "uni-254", |
| 439 | "cTag": 202, |
| 440 | "sTag": 222, |
| 441 | "nasPortId": "uni-254" |
| 442 | }, |
| 443 | { |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 444 | "id": cls.olt_serial_id, |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 445 | "hardwareIdentifier": "00:0c:e2:31:05:00", |
| 446 | "ipAddress": "172.17.0.1", |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 447 | "nasId": "B100-NASID" |
| 448 | } |
| 449 | ] |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | } |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 453 | } |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 454 | #OnosCtrl.uninstall_app(cls.olt_app_file) |
| 455 | OnosCtrl.install_app(cls.olt_app_file) |
| 456 | time.sleep(5) |
| 457 | #OnosCtrl.uninstall_app(cls.sadis_app_file) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 458 | OnosCtrl.install_app(cls.sadis_app_file) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 459 | if sadis_info: |
| 460 | sadis_dict = sadis_info |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 461 | cls.onos_load_config(sadis_dict) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 462 | cls.sadis_configs['relay_config'] = sadis_dict |
| 463 | |
| 464 | 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): |
| 465 | ### Need to work on these hard coded values on later merges |
| 466 | if subscriber_port_id is None: |
| 467 | subscriber_port_id = "uni-254" |
| 468 | if c_tag is None: |
| 469 | c_tag = 202 |
| 470 | if s_tag is None: |
| 471 | s_tag = 222 |
| 472 | if nas_port_id is None: |
| 473 | nas_port_id = "uni-254" |
| 474 | if olt_serial_id is None: |
| 475 | olt_serial_id = self.olt_serial_id |
| 476 | if olt_mac is None: |
| 477 | olt_mac = "00:0c:e2:31:05:00" |
| 478 | if olt_ip is None: |
| 479 | olt_ip = "172.17.0.1" |
| 480 | if olt_nas_id is None: |
| 481 | olt_nas_id = "B100-NASID" |
| 482 | sadis_dict = { "apps": { |
| 483 | "org.opencord.sadis": { |
| 484 | "sadis": { |
| 485 | "integration": { |
| 486 | "cache": { |
| 487 | "enabled": "true", |
| 488 | "maxsize": 50, |
| 489 | "ttl": "PT1m" |
| 490 | } |
| 491 | }, |
| 492 | "entries": [{ |
| 493 | "id": subscriber_port_id, |
| 494 | "cTag": c_tag, |
| 495 | "sTag": s_tag, |
| 496 | "nasPortId": nas_port_id |
| 497 | }, |
| 498 | { |
| 499 | "id": olt_serial_id, |
| 500 | "hardwareIdentifier": olt_mac, |
| 501 | "ipAddress": olt_ip, |
| 502 | "nasId": olt_nas_id |
| 503 | } |
| 504 | ] |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | return sadis_dict |
| 510 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 511 | |
| 512 | @classmethod |
| 513 | def get_host_ip(cls, port): |
| 514 | if cls.host_ip_map.has_key(port): |
| 515 | return cls.host_ip_map[port] |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 516 | cls.host_ip_map[port] = '192.168.100.{}'.format(port) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 517 | return cls.host_ip_map[port] |
| 518 | |
| 519 | @classmethod |
| 520 | def host_load(cls, iface): |
| 521 | '''Have ONOS discover the hosts for dhcp-relay responses''' |
| 522 | port = g_subscriber_port_map[iface] |
| 523 | host = '173.17.1.{}'.format(port) |
| 524 | cmds = ( 'ifconfig {} 0'.format(iface), |
| 525 | 'ifconfig {0} {1}'.format(iface, host), |
| 526 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 527 | 'ifconfig {} 0'.format(iface), ) |
| 528 | for c in cmds: |
| 529 | os.system(c) |
| 530 | |
| 531 | @classmethod |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 532 | def get_mac(cls, iface): |
| 533 | if cls.interface_to_mac_map.has_key(iface): |
| 534 | return cls.interface_to_mac_map[iface] |
| 535 | mac = get_mac(iface, pad = 0) |
| 536 | cls.interface_to_mac_map[iface] = mac |
| 537 | return mac |
| 538 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 539 | 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] | 540 | |
| 541 | self.ip_count = 0 |
| 542 | self.failure_count = 0 |
| 543 | self.start_time = 0 |
| 544 | self.diff = 0 |
| 545 | self.transaction_count = 0 |
| 546 | |
| 547 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 548 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 549 | self.start_time = time.time() |
| 550 | |
| 551 | while self.diff <= 60: |
| 552 | |
| 553 | if only_discover: |
| 554 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
| 555 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
| 556 | (cip, sip, mac)) |
| 557 | else: |
| 558 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
| 559 | |
| 560 | if cip: |
| 561 | self.ip_count +=1 |
| 562 | elif cip == None: |
| 563 | self.failure_count += 1 |
| 564 | log_test.info('Failed to get ip') |
| 565 | if success_rate and self.ip_count > 0: |
| 566 | break |
| 567 | |
| 568 | self.diff = round(time.time() - self.start_time, 0) |
| 569 | |
| 570 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 571 | self.transactions += (self.ip_count+self.failure_count) |
| 572 | self.running_time += self.diff |
| 573 | self.total_success += self.ip_count |
| 574 | self.total_failure += self.failure_count |
| 575 | |
| 576 | def send_recv(self, mac=None, update_seed = False, validate = True): |
| 577 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 578 | if validate: |
| 579 | assert_not_equal(cip, None) |
| 580 | assert_not_equal(sip, None) |
| 581 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
| 582 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
| 583 | return cip,sip |
| 584 | |
A R Karthick | c0a008f | 2017-10-04 18:35:25 -0700 | [diff] [blame] | 585 | def test_dhcpl2relay_initialize(self): |
| 586 | '''Setup and configure the DHCP L2 relay app''' |
| 587 | pass |
| 588 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 589 | def test_dhcpl2relay_with_one_request(self, iface = 'veth0'): |
| 590 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 591 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 592 | self.send_recv(mac=mac) |
| 593 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 594 | def test_dhcpl2relay_app_install(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 595 | mac = self.get_mac(iface) |
| 596 | onos_netcfg = OnosCtrl.get_config() |
| 597 | app_status = False |
| 598 | app_name = 'org.opencord.dhcpl2relay' |
| 599 | for app in onos_netcfg['apps']: |
| 600 | if app == app_name: |
| 601 | log_test.info('%s app is being installed'%app) |
| 602 | app_status = True |
| 603 | if app_status is not True: |
| 604 | log_test.info('%s app is not being installed'%app_name) |
| 605 | assert_equal(True, app_status) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 606 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 607 | def test_dhcpl2relay_sadis_app_install(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 608 | mac = self.get_mac(iface) |
| 609 | onos_netcfg = OnosCtrl.get_config() |
| 610 | app_status = False |
| 611 | app_name = 'org.opencord.sadis' |
| 612 | for app in onos_netcfg['apps']: |
| 613 | if app == app_name: |
| 614 | log_test.info('%s app is being installed'%app) |
| 615 | app_status = True |
| 616 | if app_status is not True: |
| 617 | log_test.info('%s app is not being installed'%app_name) |
| 618 | assert_equal(True, app_status) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 619 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 620 | def test_dhcpl2relay_netcfg(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 621 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 622 | onos_netcfg = OnosCtrl.get_config() |
| 623 | app_status = False |
| 624 | app_name = 'org.opencord.dhcpl2relay' |
| 625 | for app in onos_netcfg['apps']: |
| 626 | if app == app_name: |
| 627 | log_test.info('%s app is being installed'%app) |
| 628 | if onos_netcfg['apps'][app_name] == {}: |
| 629 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
| 630 | else: |
| 631 | log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]) |
| 632 | app_status = True |
| 633 | if app_status is not True: |
| 634 | log_test.info('%s app is not installed or network configuration is not shown'%app_name) |
| 635 | assert_equal(True, False) |
| 636 | |
| 637 | def test_dhcpl2relay_sadis_netcfg(self, iface = 'veth0'): |
| 638 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 639 | onos_netcfg = OnosCtrl.get_config() |
| 640 | app_status = False |
| 641 | app_name = 'org.opencord.sadis' |
| 642 | for app in onos_netcfg['apps']: |
| 643 | if app == app_name: |
| 644 | log_test.info('%s app is being installed'%app) |
| 645 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 646 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
| 647 | else: |
| 648 | 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] | 649 | app_status = True |
| 650 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 651 | log_test.info('%s app is not installed or network configuration is not shown'%app_name) |
| 652 | assert_equal(True, False) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 653 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 654 | def test_dhcpl2relay_with_array_of_connect_points_for_dhcp_server(self, iface = 'veth0'): |
| 655 | relay_device_map = '{}/{}'.format(self.relay_device_id, self.relay_interface_port) |
| 656 | relay_device_map1 = '{}/1'.format(self.relay_device_id) |
| 657 | relay_device_map2 = '{}/9'.format(self.relay_device_id) |
| 658 | relay_device_map3 = '{}/6'.format(self.relay_device_id) |
| 659 | relay_device_map4 = '{}/7'.format(self.relay_device_id) |
| 660 | dhcp_server_array_connectPoints = [relay_device_map,relay_device_map1,relay_device_map2,relay_device_map3,relay_device_map4] |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 661 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 662 | self.onos_delete_config(self.configs['relay_config']) |
| 663 | self.onos_load_config(self.default_onos_netcfg) |
| 664 | self.cord_l2_relay_load(dhcp_server_connectPoint = dhcp_server_array_connectPoints, delete = False) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 665 | onos_netcfg = OnosCtrl.get_config() |
| 666 | app_status = False |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 667 | app_name = 'org.opencord.dhcpl2relay' |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 668 | for app in onos_netcfg['apps']: |
| 669 | if app == app_name: |
| 670 | log_test.info('%s app is being installed'%app) |
| 671 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 672 | 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] | 673 | elif onos_netcfg['apps'][app_name]['dhcpServerConnectPoints'] == dhcp_server_array_connectPoints: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 674 | log_test.info('The network configuration is shown = %s'%onos_netcfg['apps'][app_name]['dhcpServerConnectPoints']) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 675 | app_status = True |
| 676 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 677 | log_test.info('%s app is not installed or network configuration is not shown'%app_name) |
| 678 | assert_equal(True, False) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 679 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 680 | self.send_recv(mac=mac) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 681 | |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 682 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 683 | 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] | 684 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 685 | c_tag = 600 |
| 686 | invalid_sadis_info = self.sadis_info_dict(c_tag = 600,s_tag = 500) |
| 687 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 688 | onos_netcfg = OnosCtrl.get_config() |
| 689 | app_status = False |
| 690 | app_name = 'org.opencord.sadis' |
| 691 | for app in onos_netcfg['apps']: |
| 692 | if app == app_name: |
| 693 | log_test.info('%s app is being installed'%app) |
| 694 | if onos_netcfg['apps'][app_name] == {}: |
| 695 | log_test.info('The network configuration is not shown'%onos_netcfg['apps'][app_name]) |
| 696 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['cTag'] == c_tag: |
| 697 | 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'])) |
| 698 | app_status = True |
| 699 | if app_status is not True: |
| 700 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
| 701 | assert_equal(True, False) |
| 702 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 703 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 704 | assert_equal(cip,None) |
| 705 | |
| 706 | def test_dhcpl2relay_app_activation_and_deactivation_multiple_times(self, iface = 'veth0'): |
| 707 | iterations = 15 |
| 708 | for i in range(iterations): |
| 709 | self.onos_ctrl.deactivate() |
| 710 | time.sleep(3) |
| 711 | self.onos_ctrl.activate() |
| 712 | log_test.info('Dhcpl2relay app is activated and deactivated multiple times around %s, now sending DHCP discover'%iterations) |
| 713 | mac = self.get_mac(iface) |
| 714 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 715 | self.send_recv(mac=mac) |
| 716 | |
| 717 | def test_dhcpl2relay_without_sadis_app(self, iface = 'veth0'): |
| 718 | mac = self.get_mac(iface) |
| 719 | OnosCtrl.uninstall_app(self.sadis_app_file) |
| 720 | OnosCtrl(self.sadis_app).deactivate() |
| 721 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 722 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 723 | assert_equal(cip,None) |
| 724 | |
| 725 | def test_dhcpl2relay_delete_and_add_sadis_app(self, iface = 'veth0'): |
| 726 | mac = self.get_mac(iface) |
| 727 | OnosCtrl.uninstall_app(self.sadis_app_file) |
| 728 | OnosCtrl(self.sadis_app).deactivate() |
| 729 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 730 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 731 | assert_equal(cip,None) |
| 732 | OnosCtrl.uninstall_app(self.sadis_app_file) |
| 733 | OnosCtrl(self.sadis_app).deactivate() |
| 734 | #self.onos_load_config(self.sadis_configs['relay_config']) |
| 735 | self.send_recv(mac=mac) |
| 736 | |
| 737 | def test_dhcpl2relay_with_option_82(self, iface = 'veth0'): |
| 738 | pass |
| 739 | |
| 740 | def test_dhcpl2relay_without_option_82(self, iface = 'veth0'): |
| 741 | pass |
| 742 | |
| 743 | def test_dhcl2relay_for_option82_without_configuring_dhcpserver_to_accept_option82(self, iface = 'veth0'): |
| 744 | pass |
| 745 | |
| 746 | def test_dhcpl2relay_with_different_uni_port_entry_sadis_config(self, iface = 'veth0'): |
| 747 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 748 | subscriber_port_id = "uni-200" |
| 749 | invalid_sadis_info = self.sadis_info_dict(subscriber_port_id = "uni-200") |
| 750 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 751 | onos_netcfg = OnosCtrl.get_config() |
| 752 | app_status = False |
| 753 | app_name = 'org.opencord.sadis' |
| 754 | for app in onos_netcfg['apps']: |
| 755 | if app == app_name: |
| 756 | log_test.info('%s app is being installed'%app) |
| 757 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 758 | 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] | 759 | 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] | 760 | 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] | 761 | app_status = True |
| 762 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 763 | log_test.info('%s app is not installed or network configuration is not shown '%app_name) |
| 764 | |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 765 | assert_equal(True, False) |
| 766 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 767 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 768 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 769 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 770 | def test_dhcpl2relay_with_different_ctag_options(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 771 | mac = self.get_mac(iface) |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 772 | c_tag = 600 |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 773 | invalid_sadis_info = self.sadis_info_dict(c_tag = 600) |
| 774 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 775 | onos_netcfg = OnosCtrl.get_config() |
| 776 | app_status = False |
| 777 | app_name = 'org.opencord.sadis' |
| 778 | for app in onos_netcfg['apps']: |
| 779 | if app == app_name: |
| 780 | log_test.info('%s app is being installed'%app) |
| 781 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 782 | 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] | 783 | 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] | 784 | 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] | 785 | app_status = True |
| 786 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 787 | 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] | 788 | assert_equal(True, False) |
| 789 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 790 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 791 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 792 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 793 | def test_dhcpl2relay_with_different_stag_options(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 794 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 795 | s_tag = 600 |
| 796 | invalid_sadis_info = self.sadis_info_dict(s_tag = 600) |
| 797 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 798 | onos_netcfg = OnosCtrl.get_config() |
| 799 | app_status = False |
| 800 | app_name = 'org.opencord.sadis' |
| 801 | for app in onos_netcfg['apps']: |
| 802 | if app == app_name: |
| 803 | log_test.info('%s app is being installed'%app) |
| 804 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 805 | 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] | 806 | 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] | 807 | 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] | 808 | app_status = True |
| 809 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 810 | 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] | 811 | assert_equal(True, False) |
| 812 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 813 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 814 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 815 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 816 | def test_dhcpl2relay_without_nasportid_option_in_sadis(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 817 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 818 | invalid_sadis_info = self.sadis_info_dict(nas_port_id = " ") |
| 819 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 820 | onos_netcfg = OnosCtrl.get_config() |
| 821 | app_status = False |
| 822 | app_name = 'org.opencord.sadis' |
| 823 | for app in onos_netcfg['apps']: |
| 824 | if app == app_name: |
| 825 | log_test.info('%s app is being installed'%app) |
| 826 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 827 | 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] | 828 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][0]['nasPortId'] == " ": |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 829 | 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] | 830 | app_status = True |
| 831 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 832 | 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] | 833 | assert_equal(True, False) |
| 834 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 835 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 836 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 837 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 838 | def test_dhcpl2relay_with_nasportid_different_from_id(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 839 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 840 | nas_port_id = "uni-509" |
| 841 | invalid_sadis_info = self.sadis_info_dict(nas_port_id = "uni-509") |
| 842 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 843 | onos_netcfg = OnosCtrl.get_config() |
| 844 | app_status = False |
| 845 | app_name = 'org.opencord.sadis' |
| 846 | for app in onos_netcfg['apps']: |
| 847 | if app == app_name: |
| 848 | log_test.info('%s app is being installed'%app) |
| 849 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 850 | 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] | 851 | 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] | 852 | 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] | 853 | app_status = True |
| 854 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 855 | 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] | 856 | assert_equal(True, False) |
| 857 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 858 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 859 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 860 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 861 | def test_dhcpl2relay_without_serial_id_of_olt(self, iface = 'veth0'): |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 862 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 863 | invalid_sadis_info = self.sadis_info_dict(olt_serial_id = " ") |
| 864 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 865 | onos_netcfg = OnosCtrl.get_config() |
| 866 | app_status = False |
| 867 | app_name = 'org.opencord.sadis' |
| 868 | for app in onos_netcfg['apps']: |
| 869 | if app == app_name: |
| 870 | log_test.info('%s app is being installed'%app) |
| 871 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 872 | 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] | 873 | elif onos_netcfg['apps'][app_name]['sadis']['entries'][1]['id'] == " ": |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 874 | 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] | 875 | app_status = True |
| 876 | if app_status is not True: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 877 | 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] | 878 | assert_equal(True, False) |
| 879 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 880 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 881 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 882 | |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 883 | 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] | 884 | mac = self.get_mac(iface) |
Thangavelu K S | 46063d0 | 2017-09-08 21:13:24 +0000 | [diff] [blame] | 885 | olt_serial_id = "07f20d06696041febf974ccdhdhhjh37" |
| 886 | invalid_sadis_info = self.sadis_info_dict(olt_serial_id = "07f20d06696041febf974ccdhdhhjh37") |
| 887 | self.cord_sadis_load(sadis_info = invalid_sadis_info) |
| 888 | onos_netcfg = OnosCtrl.get_config() |
| 889 | app_status = False |
| 890 | app_name = 'org.opencord.sadis' |
| 891 | for app in onos_netcfg['apps']: |
| 892 | if app == app_name: |
| 893 | log_test.info('%s app is being installed'%app) |
| 894 | if onos_netcfg['apps'][app_name] == {}: |
Thangavelu K S | 905e548 | 2017-09-12 06:48:02 -0700 | [diff] [blame] | 895 | 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] | 896 | 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] | 897 | 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] | 898 | app_status = True |
| 899 | if app_status is not True: |
| 900 | assert_equal(True, False) |
| 901 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 902 | cip, sip, mac, _ = self.dhcp.only_discover(mac=mac) |
| 903 | assert_equal(cip,None) |
Chetan Gaonker | 891302d | 2017-09-05 15:09:26 +0000 | [diff] [blame] | 904 | |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 905 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'): |
| 906 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 907 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 908 | cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff') |
| 909 | assert_equal(cip,None) |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 910 | 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] | 911 | |
| 912 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'): |
| 913 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 914 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 915 | cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05') |
| 916 | assert_equal(cip,None) |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 917 | 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] | 918 | |
| 919 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'): |
| 920 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 921 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 922 | cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00') |
| 923 | assert_equal(cip,None) |
| 924 | log_test.info('dhcp server rejected client discover with invalid source mac, as expected') |
| 925 | |
| 926 | def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10): |
| 927 | mac = self.get_mac(iface) |
Thangavelu K S | a61d1da | 2017-09-05 05:32:21 -0700 | [diff] [blame] | 928 | self.dhcp = DHCPTest(seed_ip = '192.169.100.1', iface = iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 929 | ip_map = {} |
| 930 | for i in range(requests): |
| 931 | #mac = RandMAC()._fix() |
| 932 | #log_test.info('mac is %s'%mac) |
| 933 | cip, sip = self.send_recv(update_seed = True) |
| 934 | if ip_map.has_key(cip): |
| 935 | log_test.info('IP %s given out multiple times' %cip) |
| 936 | assert_equal(False, ip_map.has_key(cip)) |
| 937 | ip_map[cip] = sip |
| 938 | time.sleep(1) |
| 939 | |
| 940 | def test_dhcpl2relay_with_one_release(self, iface = 'veth0'): |
| 941 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 942 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
| 943 | cip, sip = self.send_recv(mac=mac) |
| 944 | log_test.info('Releasing ip %s to server %s' %(cip, sip)) |
| 945 | assert_equal(self.dhcp.release(cip), True) |
| 946 | log_test.info('Triggering DHCP discover again after release') |
| 947 | cip2, sip2 = self.send_recv(mac=mac) |
| 948 | log_test.info('Verifying released IP was given back on rediscover') |
| 949 | assert_equal(cip, cip2) |
| 950 | log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 951 | assert_equal(self.dhcp.release(cip2), True) |
| 952 | |
| 953 | def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'): |
| 954 | mac = None |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 955 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 956 | ip_map = {} |
| 957 | for i in range(10): |
| 958 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
| 959 | if ip_map.has_key(cip): |
| 960 | log_test.info('IP %s given out multiple times' %cip) |
| 961 | assert_equal(False, ip_map.has_key(cip)) |
| 962 | ip_map[cip] = sip |
| 963 | |
| 964 | for ip in ip_map.keys(): |
| 965 | log_test.info('Releasing IP %s' %ip) |
| 966 | assert_equal(self.dhcp.release(ip), True) |
| 967 | |
| 968 | ip_map2 = {} |
| 969 | log_test.info('Triggering DHCP discover again after release') |
| 970 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 971 | for i in range(len(ip_map.keys())): |
| 972 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
| 973 | ip_map2[cip] = sip |
| 974 | |
| 975 | log_test.info('Verifying released IPs were given back on rediscover') |
| 976 | if ip_map != ip_map2: |
| 977 | log_test.info('Map before release %s' %ip_map) |
| 978 | log_test.info('Map after release %s' %ip_map2) |
| 979 | assert_equal(ip_map, ip_map2) |
| 980 | |
| 981 | def test_dhcpl2relay_starvation(self, iface = 'veth0'): |
| 982 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 983 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 984 | log_test.info('Verifying 1 ') |
| 985 | count = 0 |
| 986 | while True: |
| 987 | #mac = RandMAC()._fix() |
| 988 | cip, sip = self.send_recv(update_seed = True,validate = False) |
| 989 | if cip is None: |
| 990 | break |
| 991 | else: |
| 992 | count += 1 |
| 993 | assert_equal(count,91) |
| 994 | log_test.info('Verifying 2 ') |
| 995 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
| 996 | assert_equal(cip, None) |
| 997 | assert_equal(sip, None) |
| 998 | |
| 999 | def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'): |
| 1000 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1001 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1002 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1003 | log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
| 1004 | (cip, sip, mac) ) |
| 1005 | assert_not_equal(cip, None) |
| 1006 | log_test.info('Triggering DHCP discover again.') |
| 1007 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
| 1008 | assert_equal(new_cip, cip) |
| 1009 | log_test.info('got same ip to smae the client when sent discover again, as expected') |
| 1010 | |
| 1011 | def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'): |
| 1012 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1013 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1014 | log_test.info('Sending DHCP discover and DHCP request.') |
| 1015 | cip, sip = self.send_recv(mac=mac) |
| 1016 | mac = self.dhcp.get_mac(cip)[0] |
| 1017 | log_test.info("Sending DHCP request again.") |
| 1018 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1019 | assert_equal(new_cip, cip) |
| 1020 | log_test.info('got same ip to smae the client when sent request again, as expected') |
| 1021 | |
| 1022 | def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'): |
| 1023 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1024 | self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface) |
| 1025 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 1026 | assert_equal(cip,self.dhcp.seed_ip) |
| 1027 | log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' % |
| 1028 | (cip, sip, mac) ) |
| 1029 | |
| 1030 | def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'): |
| 1031 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1032 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 1033 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 1034 | assert_not_equal(cip,None) |
| 1035 | assert_not_equal(cip,self.dhcp.seed_ip) |
| 1036 | log_test.info('server offered IP from its pool when requested out of pool IP, as expected') |
| 1037 | |
| 1038 | def test_dhcpl2relay_nak_packet(self, iface = 'veth0'): |
| 1039 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1040 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1041 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1042 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1043 | (cip, sip, mac) ) |
| 1044 | assert_not_equal(cip, None) |
| 1045 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 1046 | assert_equal(new_cip, None) |
| 1047 | log_test.info('server sent NAK packet when requested other IP than that server offered') |
| 1048 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1049 | def test_dhcpl2relay_with_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] | 1050 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1051 | self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface) |
| 1052 | self.dhcp.return_option = 'lease' |
| 1053 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time) |
| 1054 | assert_equal(lval, lease_time) |
| 1055 | log_test.info('dhcp server offered IP address with client requested lease time') |
| 1056 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1057 | def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1058 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1059 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1060 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1061 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1062 | (cip, sip, mac) ) |
| 1063 | assert_not_equal(cip, None) |
| 1064 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1065 | log_test.info('client rebooting...') |
| 1066 | os.system('ifconfig '+iface+' down') |
| 1067 | time.sleep(5) |
| 1068 | os.system('ifconfig '+iface+' up') |
| 1069 | new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
| 1070 | assert_equal(new_cip2, cip) |
| 1071 | log_test.info('client got same IP after reboot, as expected') |
| 1072 | |
| 1073 | |
| 1074 | def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'): |
| 1075 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1076 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1077 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1078 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1079 | (cip, sip, mac) ) |
| 1080 | assert_not_equal(cip, None) |
| 1081 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1082 | log_test.info('server rebooting...') |
| 1083 | self.tearDownClass() |
| 1084 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1085 | assert_equal(new_cip,None) |
| 1086 | self.setUpClass() |
| 1087 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1088 | assert_equal(new_cip, cip) |
| 1089 | log_test.info('client got same IP after server rebooted, as expected') |
| 1090 | |
| 1091 | def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700): |
| 1092 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1093 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1094 | self.dhcp.return_option = 'lease' |
| 1095 | log_test.info('Sending DHCP discover with lease time of 700') |
| 1096 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time) |
| 1097 | assert_equal(lval,lease_time) |
| 1098 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 1099 | assert_equal(new_cip,cip) |
| 1100 | assert_not_equal(lval, lease_time) #Negative Test Case |
| 1101 | log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected') |
| 1102 | |
| 1103 | def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800): |
| 1104 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1105 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1106 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1107 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time) |
| 1108 | assert_equal(new_cip,cip) |
| 1109 | assert_equal(lval, lease_time) |
| 1110 | log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected') |
| 1111 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1112 | def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1113 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1114 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1115 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1116 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1117 | (cip, sip, mac) ) |
| 1118 | assert_not_equal(cip,None) |
| 1119 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 1120 | log_test.info('waiting for renew time..') |
| 1121 | time.sleep(lval) |
| 1122 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 1123 | assert_equal(latest_cip, cip) |
| 1124 | log_test.info('server renewed client IP when client sends request after renew time, as expected') |
| 1125 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1126 | def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1127 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1128 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1129 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1130 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1131 | (cip, sip, mac) ) |
| 1132 | assert_not_equal(cip,None) |
| 1133 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 1134 | log_test.info('waiting for rebind time..') |
| 1135 | time.sleep(lval) |
| 1136 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 1137 | assert_equal(latest_cip, cip) |
| 1138 | log_test.info('server renewed client IP when client sends request after rebind time, as expected') |
| 1139 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1140 | def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1141 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1142 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1143 | expected_subnet = '255.255.255.0' |
| 1144 | self.dhcp.return_option = 'subnet' |
| 1145 | |
| 1146 | cip, sip, mac, subnet_mask = self.dhcp.only_discover() |
| 1147 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1148 | (cip, sip, mac) ) |
| 1149 | assert_equal(subnet_mask,expected_subnet) |
| 1150 | log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server') |
| 1151 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1152 | 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] | 1153 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1154 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1155 | |
| 1156 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1157 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1158 | (cip, sip, mac) ) |
| 1159 | assert_not_equal(cip,None) |
| 1160 | self.dhcp.send_different_option = 'subnet' |
| 1161 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1162 | assert_equal(new_cip, cip) |
| 1163 | log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
| 1164 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1165 | def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1166 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1167 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1168 | expected_router_address = '20.20.20.1' |
| 1169 | self.dhcp.return_option = 'router' |
| 1170 | |
| 1171 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
| 1172 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1173 | (cip, sip, mac) ) |
| 1174 | assert_equal(expected_router_address, router_address_value) |
| 1175 | log_test.info('router address in server offer packet is same as configured router address in dhcp server') |
| 1176 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1177 | 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] | 1178 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1179 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1180 | |
| 1181 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1182 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1183 | (cip, sip, mac) ) |
| 1184 | assert_not_equal(cip,None) |
| 1185 | self.dhcp.send_different_option = 'router' |
| 1186 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1187 | assert_equal(new_cip, cip) |
| 1188 | log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
| 1189 | |
| 1190 | def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'): |
| 1191 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1192 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1193 | expected_broadcast_address = '192.168.1.255' |
| 1194 | self.dhcp.return_option = 'broadcast_address' |
| 1195 | |
| 1196 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
| 1197 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1198 | (cip, sip, mac) ) |
| 1199 | assert_equal(expected_broadcast_address, broadcast_address_value) |
| 1200 | log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server') |
| 1201 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1202 | def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1203 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1204 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1205 | |
| 1206 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1207 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1208 | (cip, sip, mac) ) |
| 1209 | assert_not_equal(cip,None) |
| 1210 | self.dhcp.send_different_option = 'broadcast_address' |
| 1211 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1212 | assert_equal(new_cip, cip) |
| 1213 | log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
| 1214 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1215 | def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1216 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1217 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1218 | expected_dns_address = '192.168.1.1' |
| 1219 | self.dhcp.return_option = 'dns' |
| 1220 | |
| 1221 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
| 1222 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1223 | (cip, sip, mac) ) |
| 1224 | assert_equal(expected_dns_address, dns_address_value) |
| 1225 | log_test.info('dns address in server offer packet is same as configured dns address in dhcp server') |
| 1226 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1227 | def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1228 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1229 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1230 | |
| 1231 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1232 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1233 | (cip, sip, mac) ) |
| 1234 | assert_not_equal(cip,None) |
| 1235 | self.dhcp.send_different_option = 'dns' |
| 1236 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1237 | assert_equal(new_cip, cip) |
| 1238 | log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
| 1239 | |
| 1240 | |
| 1241 | def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'): |
| 1242 | |
| 1243 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1244 | self.dhcpl2relay_stats_calc() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1245 | log_test.info("Statistics for run %d",i) |
| 1246 | log_test.info("----------------------------------------------------------------------------------") |
| 1247 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1248 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1249 | log_test.info("----------------------------------------------------------------------------------") |
| 1250 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1251 | |
| 1252 | log_test.info("Final Statistics for total transactions") |
| 1253 | log_test.info("----------------------------------------------------------------------------------") |
| 1254 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1255 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 1256 | self.total_success, self.total_failure, self.running_time)) |
| 1257 | log_test.info("----------------------------------------------------------------------------------") |
| 1258 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 1259 | |
| 1260 | def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'): |
| 1261 | |
| 1262 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1263 | self.dhcpl2relay_stats_calc(success_rate = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1264 | log_test.info("Statistics for run %d",i) |
| 1265 | log_test.info("----------------------------------------------------------------------------------") |
| 1266 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1267 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1268 | log_test.info("----------------------------------------------------------------------------------") |
| 1269 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1270 | log_test.info("----------------------------------------------------------------------------------") |
| 1271 | |
| 1272 | log_test.info("Final Statistics for total successful transactions") |
| 1273 | log_test.info("----------------------------------------------------------------------------------") |
| 1274 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1275 | log_test.info(" %d %d %d " %(self.transactions, |
| 1276 | self.total_success, self.running_time)) |
| 1277 | log_test.info("----------------------------------------------------------------------------------") |
| 1278 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 1279 | log_test.info("----------------------------------------------------------------------------------") |
| 1280 | |
| 1281 | def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'): |
| 1282 | |
| 1283 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1284 | self.dhcpl2relay_stats_calc(only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1285 | log_test.info("----------------------------------------------------------------------------------") |
| 1286 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1287 | log_test.info("----------------------------------------------------------------------------------") |
| 1288 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1289 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1290 | log_test.info("----------------------------------------------------------------------------------") |
| 1291 | log_test.info("No. of clients per second in run %d:%f " |
| 1292 | %(i, self.transaction_count)) |
| 1293 | log_test.info("----------------------------------------------------------------------------------") |
| 1294 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1295 | log_test.info("----------------------------------------------------------------------------------") |
| 1296 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1297 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 1298 | self.total_success, self.total_failure, self.running_time)) |
| 1299 | log_test.info("----------------------------------------------------------------------------------") |
| 1300 | log_test.info("Average no. of clients per second: %d ", |
| 1301 | round(self.transactions/self.running_time,0)) |
| 1302 | log_test.info("----------------------------------------------------------------------------------") |
| 1303 | |
| 1304 | def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'): |
| 1305 | |
| 1306 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1307 | self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1308 | log_test.info("----------------------------------------------------------------------------------") |
| 1309 | log_test.info("Statistics for run %d for sending only DHCP Discover",i) |
| 1310 | log_test.info("----------------------------------------------------------------------------------") |
| 1311 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1312 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1313 | log_test.info("----------------------------------------------------------------------------------") |
| 1314 | log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 1315 | log_test.info("----------------------------------------------------------------------------------") |
| 1316 | |
| 1317 | log_test.info("Final Statistics for total successful transactions") |
| 1318 | log_test.info("----------------------------------------------------------------------------------") |
| 1319 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1320 | log_test.info(" %d %d %d " %(self.transactions, |
| 1321 | self.total_success, self.running_time)) |
| 1322 | log_test.info("----------------------------------------------------------------------------------") |
| 1323 | log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 1324 | log_test.info("----------------------------------------------------------------------------------") |
| 1325 | |
| 1326 | def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1327 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1328 | self.host_load(g_subscriber_port_map[key]) |
| 1329 | |
| 1330 | def thread_fun(i): |
| 1331 | mac = self.get_mac('veth{}'.format(i)) |
| 1332 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 1333 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1334 | self.lock.acquire() |
| 1335 | |
| 1336 | if cip: |
| 1337 | self.ip_count += 1 |
| 1338 | |
| 1339 | elif cip is None: |
| 1340 | self.failure_count += 1 |
| 1341 | |
| 1342 | self.lock.notify_all() |
| 1343 | self.lock.release() |
| 1344 | |
| 1345 | for i in range (1,4): |
| 1346 | self.ip_count = 0 |
| 1347 | self.failure_count = 0 |
| 1348 | self.start_time = 0 |
| 1349 | self.diff = 0 |
| 1350 | self.transaction_count = 0 |
| 1351 | self.start_time = time.time() |
| 1352 | |
| 1353 | while self.diff <= 60: |
| 1354 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1355 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1356 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1357 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1358 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1359 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1360 | |
| 1361 | t.start() |
| 1362 | t1.start() |
| 1363 | t2.start() |
| 1364 | t3.start() |
| 1365 | t4.start() |
| 1366 | t5.start() |
| 1367 | |
| 1368 | t.join() |
| 1369 | t1.join() |
| 1370 | t2.join() |
| 1371 | t3.join() |
| 1372 | t4.join() |
| 1373 | t5.join() |
| 1374 | |
| 1375 | self.diff = round(time.time() - self.start_time, 0) |
| 1376 | |
| 1377 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1378 | |
| 1379 | self.transactions += (self.ip_count+self.failure_count) |
| 1380 | self.running_time += self.diff |
| 1381 | self.total_success += self.ip_count |
| 1382 | self.total_failure += self.failure_count |
| 1383 | |
| 1384 | |
| 1385 | log_test.info("----------------------------------------------------------------------------------") |
| 1386 | log_test.info("Statistics for run %d",i) |
| 1387 | log_test.info("----------------------------------------------------------------------------------") |
| 1388 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1389 | log_test.info(" %d %d %d %d" |
| 1390 | %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff)) |
| 1391 | log_test.info("----------------------------------------------------------------------------------") |
| 1392 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1393 | log_test.info("----------------------------------------------------------------------------------") |
| 1394 | |
| 1395 | log_test.info("----------------------------------------------------------------------------------") |
| 1396 | log_test.info("Final Statistics for total transactions") |
| 1397 | log_test.info("----------------------------------------------------------------------------------") |
| 1398 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1399 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 1400 | self.total_success, self.total_failure, self.running_time)) |
| 1401 | |
| 1402 | log_test.info("----------------------------------------------------------------------------------") |
| 1403 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 1404 | log_test.info("----------------------------------------------------------------------------------") |
| 1405 | |
| 1406 | def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1407 | failure_dir = {} |
| 1408 | |
| 1409 | for key in (key for key in g_subscriber_port_map if key != 100): |
| 1410 | self.host_load(g_subscriber_port_map[key]) |
| 1411 | |
| 1412 | def thread_fun(i, j): |
| 1413 | # log_test.info("Thread Name:%s",current_thread().name) |
| 1414 | # failure_dir[current_thread().name] = True |
| 1415 | while failure_dir.has_key(current_thread().name) is False: |
| 1416 | mac = RandMAC()._fix() |
| 1417 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 1418 | i += 2 |
| 1419 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1420 | self.lock.acquire() |
| 1421 | |
| 1422 | if cip: |
| 1423 | self.ip_count += 1 |
| 1424 | self.lock.notify_all() |
| 1425 | self.lock.release() |
| 1426 | elif cip is None: |
| 1427 | self.failure_count += 1 |
| 1428 | failure_dir[current_thread().name] = True |
| 1429 | self.lock.notify_all() |
| 1430 | self.lock.release() |
| 1431 | break |
| 1432 | # self.lock.notify_all() |
| 1433 | # self.lock.release() |
| 1434 | |
| 1435 | for i in range (1,4): |
| 1436 | failure_dir = {} |
| 1437 | self.ip_count = 0 |
| 1438 | self.failure_count = 0 |
| 1439 | self.start_time = 0 |
| 1440 | self.diff = 0 |
| 1441 | self.transaction_count = 0 |
| 1442 | self.start_time = time.time() |
| 1443 | |
| 1444 | while len(failure_dir) != 6: |
| 1445 | t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1446 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1447 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1448 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1449 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1450 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1451 | |
| 1452 | t.start() |
| 1453 | t1.start() |
| 1454 | t2.start() |
| 1455 | t3.start() |
| 1456 | t4.start() |
| 1457 | t5.start() |
| 1458 | |
| 1459 | t.join() |
| 1460 | t1.join() |
| 1461 | t2.join() |
| 1462 | t3.join() |
| 1463 | t4.join() |
| 1464 | t5.join() |
| 1465 | |
| 1466 | self.diff = round(time.time() - self.start_time, 0) |
| 1467 | self.transaction_count = round((self.ip_count)/self.diff, 2) |
| 1468 | |
| 1469 | self.transactions += (self.ip_count+self.failure_count) |
| 1470 | self.running_time += self.diff |
| 1471 | self.total_success += self.ip_count |
| 1472 | self.total_failure += self.failure_count |
| 1473 | |
| 1474 | |
| 1475 | log_test.info("Statistics for run %d",i) |
| 1476 | log_test.info("----------------------------------------------------------------------------------") |
| 1477 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1478 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1479 | log_test.info("----------------------------------------------------------------------------------") |
| 1480 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1481 | log_test.info("----------------------------------------------------------------------------------") |
| 1482 | |
| 1483 | log_test.info("Final Statistics for total successful transactions") |
| 1484 | log_test.info("----------------------------------------------------------------------------------") |
| 1485 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1486 | log_test.info(" %d %d %d " %(self.transactions, |
| 1487 | self.total_success, self.running_time)) |
| 1488 | log_test.info("----------------------------------------------------------------------------------") |
| 1489 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2)) |
| 1490 | log_test.info("----------------------------------------------------------------------------------") |
| 1491 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1492 | def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1493 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1494 | self.host_load(g_subscriber_port_map[key]) |
| 1495 | |
| 1496 | def thread_fun(i): |
| 1497 | # mac = self.get_mac('veth{}'.format(i)) |
| 1498 | cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix()) |
| 1499 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1500 | self.lock.acquire() |
| 1501 | |
| 1502 | if cip: |
| 1503 | self.ip_count += 1 |
| 1504 | elif cip is None: |
| 1505 | self.failure_count += 1 |
| 1506 | |
| 1507 | self.lock.notify_all() |
| 1508 | self.lock.release() |
| 1509 | |
| 1510 | for i in range (1,4): |
| 1511 | self.ip_count = 0 |
| 1512 | self.failure_count = 0 |
| 1513 | self.start_time = 0 |
| 1514 | self.diff = 0 |
| 1515 | self.transaction_count = 0 |
| 1516 | self.start_time = time.time() |
| 1517 | |
| 1518 | while self.diff <= 60: |
| 1519 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1520 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1521 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1522 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1523 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1524 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1525 | |
| 1526 | t.start() |
| 1527 | t1.start() |
| 1528 | t2.start() |
| 1529 | t3.start() |
| 1530 | t4.start() |
| 1531 | t5.start() |
| 1532 | |
| 1533 | t.join() |
| 1534 | t1.join() |
| 1535 | t2.join() |
| 1536 | t3.join() |
| 1537 | t4.join() |
| 1538 | t5.join() |
| 1539 | |
| 1540 | self.diff = round(time.time() - self.start_time, 0) |
| 1541 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1542 | self.transactions += (self.ip_count+self.failure_count) |
| 1543 | self.running_time += self.diff |
| 1544 | self.total_success += self.ip_count |
| 1545 | self.total_failure += self.failure_count |
| 1546 | |
| 1547 | log_test.info("----------------------------------------------------------------------------------") |
| 1548 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1549 | log_test.info("----------------------------------------------------------------------------------") |
| 1550 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1551 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1552 | log_test.info("----------------------------------------------------------------------------------") |
| 1553 | log_test.info("No. of clients per second in run %d:%f " |
| 1554 | %(i, self.transaction_count)) |
| 1555 | log_test.info("----------------------------------------------------------------------------------") |
| 1556 | |
| 1557 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1558 | log_test.info("----------------------------------------------------------------------------------") |
| 1559 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1560 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 1561 | self.total_success, self.total_failure, self.running_time)) |
| 1562 | log_test.info("----------------------------------------------------------------------------------") |
| 1563 | log_test.info("Average no. of clients per second: %d ", |
| 1564 | round(self.transactions/self.running_time,0)) |
| 1565 | log_test.info("----------------------------------------------------------------------------------") |
| 1566 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame] | 1567 | def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1568 | mac = self.get_mac(iface) |
| 1569 | self.host_load(iface) |
| 1570 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1571 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1572 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1573 | (cip, sip, mac) ) |
| 1574 | self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface) |
| 1575 | new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True) |
| 1576 | new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac) |
| 1577 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1578 | (new_cip, new_sip, new_mac) ) |
| 1579 | log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac)) |
| 1580 | log_test.info("Now sending DHCP Request for old DHCP discover.") |
| 1581 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1582 | if new_cip is None: |
| 1583 | log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.' |
| 1584 | %(new_cip, new_sip, new_mac) ) |
| 1585 | elif new_cip: |
| 1586 | 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.' |
| 1587 | %(new_cip, new_sip, new_mac, new_cip) ) |
| 1588 | assert_equal(new_cip, None) |