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