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