Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
| 17 | # |
| 18 | # Copyright 2016-present Ciena Corporation |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | # you may not use this file except in compliance with the License. |
| 22 | # You may obtain a copy of the License at |
| 23 | # |
| 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | # |
| 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | # WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied. |
| 29 | # See the License for the specific language governing permissions and |
| 30 | # limitations under the License. |
| 31 | # |
| 32 | import unittest |
| 33 | from nose.tools import * |
| 34 | from nose.twistedtools import reactor, deferred |
| 35 | from twisted.internet import defer |
| 36 | import time |
| 37 | import os, sys |
| 38 | from DHCP import DHCPTest |
| 39 | from CordTestUtils import get_mac, log_test |
| 40 | from OnosCtrl import OnosCtrl |
| 41 | from OltConfig import OltConfig |
| 42 | from CordTestServer import cord_test_onos_restart |
| 43 | from CordLogger import CordLogger |
| 44 | from portmaps import g_subscriber_port_map |
| 45 | import threading, random |
| 46 | from threading import current_thread |
| 47 | log_test.setLevel('INFO') |
| 48 | |
| 49 | class dhcpl2relay_exchange(CordLogger): |
| 50 | |
| 51 | app = 'org.opencord.dhcpl2relay' |
| 52 | sadis_app = 'org.opencord.sadis' |
| 53 | app_dhcp = 'org.onosproject.dhcp' |
| 54 | relay_interfaces_last = () |
| 55 | interface_to_mac_map = {} |
| 56 | host_ip_map = {} |
| 57 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 58 | dhcp_data_dir = os.path.join(test_path, '..', 'setup') |
| 59 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json')) |
| 60 | default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, } |
| 61 | default_options = [ ('subnet-mask', '255.255.255.0'), |
| 62 | ('broadcast-address', '192.168.1.255'), |
| 63 | ('domain-name-servers', '192.168.1.1'), |
| 64 | ('domain-name', '"mydomain.cord-tester"'), |
| 65 | ] |
| 66 | default_subnet_config = [ ('192.168.1.2', |
| 67 | ''' |
| 68 | subnet 192.168.1.0 netmask 255.255.255.0 { |
| 69 | range 192.168.1.10 192.168.1.100; |
| 70 | } |
| 71 | '''), ] |
| 72 | |
| 73 | lock = threading.Condition() |
| 74 | ip_count = 0 |
| 75 | failure_count = 0 |
| 76 | start_time = 0 |
| 77 | diff = 0 |
| 78 | |
| 79 | transaction_count = 0 |
| 80 | transactions = 0 |
| 81 | running_time = 0 |
| 82 | total_success = 0 |
| 83 | total_failure = 0 |
| 84 | #just in case we want to reset ONOS to default network cfg after relay tests |
| 85 | onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0))) |
| 86 | configs = {} |
| 87 | |
| 88 | @classmethod |
| 89 | def setUpClass(cls): |
| 90 | ''' Activate the cord dhcpl2relay app''' |
| 91 | OnosCtrl(cls.app_dhcp).deactivate() |
| 92 | time.sleep(3) |
| 93 | cls.onos_ctrl = OnosCtrl(cls.app) |
| 94 | status, _ = cls.onos_ctrl.activate() |
| 95 | assert_equal(status, True) |
| 96 | time.sleep(3) |
| 97 | cls.onos_ctrl = OnosCtrl(cls.sadis_app) |
| 98 | status, _ = cls.onos_ctrl.activate() |
| 99 | assert_equal(status, True) |
| 100 | time.sleep(3) |
| 101 | cls.dhcp_l2_relay_setup() |
| 102 | ##start dhcpd initially with default config |
| 103 | cls.dhcpd_start() |
| 104 | |
| 105 | @classmethod |
| 106 | def tearDownClass(cls): |
| 107 | '''Deactivate the cord dhcpl2relay app''' |
| 108 | try: |
| 109 | os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir)) |
| 110 | os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir)) |
| 111 | except: pass |
| 112 | cls.onos_ctrl.deactivate() |
| 113 | cls.dhcpd_stop() |
| 114 | cls.dhcp_l2_relay_cleanup() |
| 115 | |
| 116 | @classmethod |
| 117 | def dhcp_l2_relay_setup(cls): |
| 118 | did = OnosCtrl.get_device_id() |
| 119 | cls.relay_device_id = did |
| 120 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 121 | cls.port_map, _ = cls.olt.olt_port_map() |
| 122 | if cls.port_map: |
| 123 | ##Per subscriber, we use 1 relay port |
| 124 | try: |
| 125 | relay_port = cls.port_map[cls.port_map['relay_ports'][0]] |
| 126 | except: |
| 127 | relay_port = cls.port_map['uplink'] |
| 128 | cls.relay_interface_port = relay_port |
| 129 | cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],) |
| 130 | else: |
| 131 | cls.relay_interface_port = 100 |
| 132 | cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],) |
| 133 | cls.relay_interfaces_last = cls.relay_interfaces |
| 134 | if cls.port_map: |
| 135 | ##generate a ip/mac client virtual interface config for onos |
| 136 | interface_list = [] |
| 137 | for port in cls.port_map['ports']: |
| 138 | port_num = cls.port_map[port] |
| 139 | if port_num == cls.port_map['uplink']: |
| 140 | continue |
| 141 | ip = cls.get_host_ip(port_num) |
| 142 | mac = cls.get_mac(port) |
| 143 | interface_list.append((port_num, ip, mac)) |
| 144 | |
| 145 | #configure dhcp server virtual interface on the same subnet as first client interface |
| 146 | relay_ip = cls.get_host_ip(interface_list[0][0]) |
| 147 | relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port]) |
| 148 | interface_list.append((cls.relay_interface_port, relay_ip, relay_mac)) |
| 149 | cls.onos_interface_load(interface_list) |
| 150 | |
| 151 | @classmethod |
| 152 | def dhcp_l2_relay_cleanup(cls): |
| 153 | ##reset the ONOS port configuration back to default |
| 154 | for config in cls.configs.items(): |
| 155 | OnosCtrl.delete(config) |
| 156 | # if cls.onos_restartable is True: |
| 157 | # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg') |
| 158 | # return cord_test_onos_restart(config = {}) |
| 159 | |
| 160 | @classmethod |
| 161 | def onos_load_config(cls, config): |
| 162 | status, code = OnosCtrl.config(config) |
| 163 | if status is False: |
| 164 | log_test.info('JSON request returned status %d' %code) |
| 165 | assert_equal(status, True) |
| 166 | time.sleep(3) |
| 167 | |
| 168 | @classmethod |
| 169 | def onos_interface_load(cls, interface_list): |
| 170 | interface_dict = { 'ports': {} } |
| 171 | for port_num, ip, mac in interface_list: |
| 172 | port_map = interface_dict['ports'] |
| 173 | port = '{}/{}'.format(cls.relay_device_id, port_num) |
| 174 | port_map[port] = { 'interfaces': [] } |
| 175 | interface_list = port_map[port]['interfaces'] |
| 176 | interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ], |
| 177 | 'mac' : mac, |
| 178 | 'name': 'vir-{}'.format(port_num) |
| 179 | } |
| 180 | interface_list.append(interface_map) |
| 181 | |
| 182 | cls.onos_load_config(interface_dict) |
| 183 | cls.configs['interface_config'] = interface_dict |
| 184 | |
| 185 | @classmethod |
| 186 | def cord_l2_relay_load(cls): |
| 187 | relay_device_id = '{}'.format(cls.relay_device_id) |
| 188 | dhcp_dict = {'apps':{'org.opencord.dhcpl2relay':{'dhcpl2relay': |
| 189 | {'dhcpserverConnectPoint':[relay_device_id]} |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | cls.onos_load_config(dhcp_dict) |
| 194 | cls.configs['relay_config'] = dhcp_dict |
| 195 | |
| 196 | @classmethod |
| 197 | def cord_sadis_load(cls): |
| 198 | relay_device_id = '{}'.format(cls.relay_device_id) |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 199 | sadis_dict ={ |
| 200 | "apps": { |
| 201 | "org.opencord.sadis": { |
| 202 | "sadis": { |
| 203 | "integration": { |
| 204 | "cache": { |
| 205 | "enabled": true, |
| 206 | "maxsize": 50, |
| 207 | "ttl": "PT1m" |
| 208 | } |
| 209 | }, |
| 210 | "entries": [{ |
| 211 | "id": "uni-254", |
| 212 | "cTag": 202, |
| 213 | "sTag": 222, |
| 214 | "nasPortId": "uni-254" |
| 215 | }, |
| 216 | { |
| 217 | "id": "eaf78b733390456d80fb24113f5150fd", |
| 218 | "hardwareIdentifier": "00:1b:22:00:b1:78", |
| 219 | "ipAddress": "192.168.1.252", |
| 220 | "nasId": "B100-NASID" |
| 221 | } |
| 222 | ] |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 227 | cls.onos_load_config(sadis_dict) |
| 228 | cls.configs['relay_config'] = sadis_dict |
| 229 | |
| 230 | @classmethod |
| 231 | def get_host_ip(cls, port): |
| 232 | if cls.host_ip_map.has_key(port): |
| 233 | return cls.host_ip_map[port] |
| 234 | cls.host_ip_map[port] = '192.168.1.{}'.format(port) |
| 235 | return cls.host_ip_map[port] |
| 236 | |
| 237 | @classmethod |
| 238 | def host_load(cls, iface): |
| 239 | '''Have ONOS discover the hosts for dhcp-relay responses''' |
| 240 | port = g_subscriber_port_map[iface] |
| 241 | host = '173.17.1.{}'.format(port) |
| 242 | cmds = ( 'ifconfig {} 0'.format(iface), |
| 243 | 'ifconfig {0} {1}'.format(iface, host), |
| 244 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 245 | 'ifconfig {} 0'.format(iface), ) |
| 246 | for c in cmds: |
| 247 | os.system(c) |
| 248 | |
| 249 | @classmethod |
| 250 | def dhcpd_conf_generate(cls, config = default_config, options = default_options, |
| 251 | subnet = default_subnet_config): |
| 252 | conf = '' |
| 253 | for k, v in config.items(): |
| 254 | conf += '{} {};\n'.format(k, v) |
| 255 | |
| 256 | opts = '' |
| 257 | for k, v in options: |
| 258 | opts += 'option {} {};\n'.format(k, v) |
| 259 | |
| 260 | subnet_config = '' |
| 261 | for _, v in subnet: |
| 262 | subnet_config += '{}\n'.format(v) |
| 263 | |
| 264 | return '{}{}{}'.format(conf, opts, subnet_config) |
| 265 | |
| 266 | @classmethod |
| 267 | def dhcpd_start(cls, intf_list = None, |
| 268 | config = default_config, options = default_options, |
| 269 | subnet = default_subnet_config): |
| 270 | '''Start the dhcpd server by generating the conf file''' |
| 271 | if intf_list is None: |
| 272 | intf_list = cls.relay_interfaces |
| 273 | ##stop dhcpd if already running |
| 274 | cls.dhcpd_stop() |
| 275 | dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options, |
| 276 | subnet = subnet) |
| 277 | ##first touch dhcpd.leases if it doesn't exist |
| 278 | lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir) |
| 279 | if os.access(lease_file, os.F_OK) is False: |
| 280 | with open(lease_file, 'w') as fd: pass |
| 281 | |
| 282 | conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir) |
| 283 | with open(conf_file, 'w') as fd: |
| 284 | fd.write(dhcp_conf) |
| 285 | |
| 286 | #now configure the dhcpd interfaces for various subnets |
| 287 | index = 0 |
| 288 | intf_info = [] |
| 289 | for ip,_ in subnet: |
| 290 | intf = intf_list[index] |
| 291 | mac = cls.get_mac(intf) |
| 292 | intf_info.append((ip, mac)) |
| 293 | index += 1 |
| 294 | os.system('ifconfig {} {}'.format(intf, ip)) |
| 295 | |
| 296 | intf_str = ','.join(intf_list) |
| 297 | dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str) |
| 298 | log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd) |
| 299 | ret = os.system(dhcpd_cmd) |
| 300 | assert_equal(ret, 0) |
| 301 | time.sleep(3) |
| 302 | cls.relay_interfaces_last = cls.relay_interfaces |
| 303 | cls.relay_interfaces = intf_list |
| 304 | cls.cord_l2_relay_load() |
| 305 | cls.cord_sadis_load() |
| 306 | |
| 307 | @classmethod |
| 308 | def dhcpd_stop(cls): |
| 309 | os.system('pkill -9 dhcpd') |
| 310 | for intf in cls.relay_interfaces: |
| 311 | os.system('ifconfig {} 0'.format(intf)) |
| 312 | |
| 313 | cls.relay_interfaces = cls.relay_interfaces_last |
| 314 | |
| 315 | @classmethod |
| 316 | def get_mac(cls, iface): |
| 317 | if cls.interface_to_mac_map.has_key(iface): |
| 318 | return cls.interface_to_mac_map[iface] |
| 319 | mac = get_mac(iface, pad = 0) |
| 320 | cls.interface_to_mac_map[iface] = mac |
| 321 | return mac |
| 322 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 323 | 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] | 324 | |
| 325 | self.ip_count = 0 |
| 326 | self.failure_count = 0 |
| 327 | self.start_time = 0 |
| 328 | self.diff = 0 |
| 329 | self.transaction_count = 0 |
| 330 | |
| 331 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 332 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 333 | self.start_time = time.time() |
| 334 | |
| 335 | while self.diff <= 60: |
| 336 | |
| 337 | if only_discover: |
| 338 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
| 339 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
| 340 | (cip, sip, mac)) |
| 341 | else: |
| 342 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
| 343 | |
| 344 | if cip: |
| 345 | self.ip_count +=1 |
| 346 | elif cip == None: |
| 347 | self.failure_count += 1 |
| 348 | log_test.info('Failed to get ip') |
| 349 | if success_rate and self.ip_count > 0: |
| 350 | break |
| 351 | |
| 352 | self.diff = round(time.time() - self.start_time, 0) |
| 353 | |
| 354 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 355 | self.transactions += (self.ip_count+self.failure_count) |
| 356 | self.running_time += self.diff |
| 357 | self.total_success += self.ip_count |
| 358 | self.total_failure += self.failure_count |
| 359 | |
| 360 | def send_recv(self, mac=None, update_seed = False, validate = True): |
| 361 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 362 | if validate: |
| 363 | assert_not_equal(cip, None) |
| 364 | assert_not_equal(sip, None) |
| 365 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
| 366 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
| 367 | return cip,sip |
| 368 | |
| 369 | def test_dhcpl2relay_with_one_request(self, iface = 'veth0'): |
| 370 | mac = self.get_mac(iface) |
| 371 | self.host_load(iface) |
| 372 | ##we use the defaults for this test that serves as an example for others |
| 373 | ##You don't need to restart dhcpd server if retaining default config |
| 374 | config = self.default_config |
| 375 | options = self.default_options |
| 376 | subnet = self.default_subnet_config |
| 377 | dhcpd_interface_list = self.relay_interfaces |
| 378 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 379 | config = config, |
| 380 | options = options, |
| 381 | subnet = subnet) |
| 382 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 383 | self.send_recv(mac=mac) |
| 384 | |
| 385 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_broadcast(self, iface = 'veth0'): |
| 386 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 387 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 388 | cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff') |
| 389 | assert_equal(cip,None) |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 390 | 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] | 391 | |
| 392 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_multicast(self, iface = 'veth0'): |
| 393 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 394 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 395 | cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05') |
| 396 | assert_equal(cip,None) |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 397 | 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] | 398 | |
| 399 | def test_dhcpl2relay_for_one_request_with_invalid_source_mac_zero(self, iface = 'veth0'): |
| 400 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 401 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 402 | cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00') |
| 403 | assert_equal(cip,None) |
| 404 | log_test.info('dhcp server rejected client discover with invalid source mac, as expected') |
| 405 | |
| 406 | def test_dhcpl2relay_with_N_requests(self, iface = 'veth0',requests=10): |
| 407 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 408 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface) |
| 409 | ip_map = {} |
| 410 | for i in range(requests): |
| 411 | #mac = RandMAC()._fix() |
| 412 | #log_test.info('mac is %s'%mac) |
| 413 | cip, sip = self.send_recv(update_seed = True) |
| 414 | if ip_map.has_key(cip): |
| 415 | log_test.info('IP %s given out multiple times' %cip) |
| 416 | assert_equal(False, ip_map.has_key(cip)) |
| 417 | ip_map[cip] = sip |
| 418 | time.sleep(1) |
| 419 | |
| 420 | def test_dhcpl2relay_with_one_release(self, iface = 'veth0'): |
| 421 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 422 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
| 423 | cip, sip = self.send_recv(mac=mac) |
| 424 | log_test.info('Releasing ip %s to server %s' %(cip, sip)) |
| 425 | assert_equal(self.dhcp.release(cip), True) |
| 426 | log_test.info('Triggering DHCP discover again after release') |
| 427 | cip2, sip2 = self.send_recv(mac=mac) |
| 428 | log_test.info('Verifying released IP was given back on rediscover') |
| 429 | assert_equal(cip, cip2) |
| 430 | log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 431 | assert_equal(self.dhcp.release(cip2), True) |
| 432 | |
| 433 | def test_dhcpl2relay_with_Nreleases(self, iface = 'veth0'): |
| 434 | mac = None |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 435 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 436 | ip_map = {} |
| 437 | for i in range(10): |
| 438 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
| 439 | if ip_map.has_key(cip): |
| 440 | log_test.info('IP %s given out multiple times' %cip) |
| 441 | assert_equal(False, ip_map.has_key(cip)) |
| 442 | ip_map[cip] = sip |
| 443 | |
| 444 | for ip in ip_map.keys(): |
| 445 | log_test.info('Releasing IP %s' %ip) |
| 446 | assert_equal(self.dhcp.release(ip), True) |
| 447 | |
| 448 | ip_map2 = {} |
| 449 | log_test.info('Triggering DHCP discover again after release') |
| 450 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 451 | for i in range(len(ip_map.keys())): |
| 452 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
| 453 | ip_map2[cip] = sip |
| 454 | |
| 455 | log_test.info('Verifying released IPs were given back on rediscover') |
| 456 | if ip_map != ip_map2: |
| 457 | log_test.info('Map before release %s' %ip_map) |
| 458 | log_test.info('Map after release %s' %ip_map2) |
| 459 | assert_equal(ip_map, ip_map2) |
| 460 | |
| 461 | def test_dhcpl2relay_starvation(self, iface = 'veth0'): |
| 462 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 463 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 464 | log_test.info('Verifying 1 ') |
| 465 | count = 0 |
| 466 | while True: |
| 467 | #mac = RandMAC()._fix() |
| 468 | cip, sip = self.send_recv(update_seed = True,validate = False) |
| 469 | if cip is None: |
| 470 | break |
| 471 | else: |
| 472 | count += 1 |
| 473 | assert_equal(count,91) |
| 474 | log_test.info('Verifying 2 ') |
| 475 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
| 476 | assert_equal(cip, None) |
| 477 | assert_equal(sip, None) |
| 478 | |
| 479 | def test_dhcpl2relay_with_same_client_and_multiple_discovers(self, iface = 'veth0'): |
| 480 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 481 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 482 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 483 | log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
| 484 | (cip, sip, mac) ) |
| 485 | assert_not_equal(cip, None) |
| 486 | log_test.info('Triggering DHCP discover again.') |
| 487 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
| 488 | assert_equal(new_cip, cip) |
| 489 | log_test.info('got same ip to smae the client when sent discover again, as expected') |
| 490 | |
| 491 | def test_dhcpl2relay_with_same_client_and_multiple_requests(self, iface = 'veth0'): |
| 492 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 493 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 494 | log_test.info('Sending DHCP discover and DHCP request.') |
| 495 | cip, sip = self.send_recv(mac=mac) |
| 496 | mac = self.dhcp.get_mac(cip)[0] |
| 497 | log_test.info("Sending DHCP request again.") |
| 498 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 499 | assert_equal(new_cip, cip) |
| 500 | log_test.info('got same ip to smae the client when sent request again, as expected') |
| 501 | |
| 502 | def test_dhcpl2relay_with_clients_desired_address(self, iface = 'veth0'): |
| 503 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 504 | self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface) |
| 505 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 506 | assert_equal(cip,self.dhcp.seed_ip) |
| 507 | log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' % |
| 508 | (cip, sip, mac) ) |
| 509 | |
| 510 | def test_dhcpl2relay_with_clients_desired_address_in_out_of_pool(self, iface = 'veth0'): |
| 511 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 512 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 513 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 514 | assert_not_equal(cip,None) |
| 515 | assert_not_equal(cip,self.dhcp.seed_ip) |
| 516 | log_test.info('server offered IP from its pool when requested out of pool IP, as expected') |
| 517 | |
| 518 | def test_dhcpl2relay_nak_packet(self, iface = 'veth0'): |
| 519 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 520 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 521 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 522 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 523 | (cip, sip, mac) ) |
| 524 | assert_not_equal(cip, None) |
| 525 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 526 | assert_equal(new_cip, None) |
| 527 | log_test.info('server sent NAK packet when requested other IP than that server offered') |
| 528 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 529 | def test_dhcpl2relay_with_client_requests_with_specific_lease_time_in_discover_message(self, iface = 'veth0',lease_time=700): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 530 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 531 | self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface) |
| 532 | self.dhcp.return_option = 'lease' |
| 533 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time) |
| 534 | assert_equal(lval, lease_time) |
| 535 | log_test.info('dhcp server offered IP address with client requested lease time') |
| 536 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 537 | def test_dhcpl2relay_with_client_request_after_reboot(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 538 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 539 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 540 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 541 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 542 | (cip, sip, mac) ) |
| 543 | assert_not_equal(cip, None) |
| 544 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 545 | log_test.info('client rebooting...') |
| 546 | os.system('ifconfig '+iface+' down') |
| 547 | time.sleep(5) |
| 548 | os.system('ifconfig '+iface+' up') |
| 549 | new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
| 550 | assert_equal(new_cip2, cip) |
| 551 | log_test.info('client got same IP after reboot, as expected') |
| 552 | |
| 553 | |
| 554 | def test_dhcpl2relay_after_server_reboot(self, iface = 'veth0'): |
| 555 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 556 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 557 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 558 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 559 | (cip, sip, mac) ) |
| 560 | assert_not_equal(cip, None) |
| 561 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 562 | log_test.info('server rebooting...') |
| 563 | self.tearDownClass() |
| 564 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 565 | assert_equal(new_cip,None) |
| 566 | self.setUpClass() |
| 567 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 568 | assert_equal(new_cip, cip) |
| 569 | log_test.info('client got same IP after server rebooted, as expected') |
| 570 | |
| 571 | def test_dhcpl2relay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700): |
| 572 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 573 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 574 | self.dhcp.return_option = 'lease' |
| 575 | log_test.info('Sending DHCP discover with lease time of 700') |
| 576 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time) |
| 577 | assert_equal(lval,lease_time) |
| 578 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 579 | assert_equal(new_cip,cip) |
| 580 | assert_not_equal(lval, lease_time) #Negative Test Case |
| 581 | log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected') |
| 582 | |
| 583 | def test_dhcpl2relay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800): |
| 584 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 585 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 586 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 587 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time) |
| 588 | assert_equal(new_cip,cip) |
| 589 | assert_equal(lval, lease_time) |
| 590 | log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected') |
| 591 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 592 | def test_dhcpl2relay_with_client_renew_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 593 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 594 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 595 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 596 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 597 | (cip, sip, mac) ) |
| 598 | assert_not_equal(cip,None) |
| 599 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 600 | log_test.info('waiting for renew time..') |
| 601 | time.sleep(lval) |
| 602 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 603 | assert_equal(latest_cip, cip) |
| 604 | log_test.info('server renewed client IP when client sends request after renew time, as expected') |
| 605 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 606 | def test_dhcpl2relay_with_client_rebind_time(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 607 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 608 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 609 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 610 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 611 | (cip, sip, mac) ) |
| 612 | assert_not_equal(cip,None) |
| 613 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 614 | log_test.info('waiting for rebind time..') |
| 615 | time.sleep(lval) |
| 616 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 617 | assert_equal(latest_cip, cip) |
| 618 | log_test.info('server renewed client IP when client sends request after rebind time, as expected') |
| 619 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 620 | def test_dhcpl2relay_with_client_expected_subnet_mask(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 621 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 622 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 623 | expected_subnet = '255.255.255.0' |
| 624 | self.dhcp.return_option = 'subnet' |
| 625 | |
| 626 | cip, sip, mac, subnet_mask = self.dhcp.only_discover() |
| 627 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 628 | (cip, sip, mac) ) |
| 629 | assert_equal(subnet_mask,expected_subnet) |
| 630 | log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server') |
| 631 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 632 | 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] | 633 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 634 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 635 | |
| 636 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 637 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 638 | (cip, sip, mac) ) |
| 639 | assert_not_equal(cip,None) |
| 640 | self.dhcp.send_different_option = 'subnet' |
| 641 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 642 | assert_equal(new_cip, cip) |
| 643 | log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
| 644 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 645 | def test_dhcpl2relay_with_client_expected_router_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 646 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 647 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 648 | expected_router_address = '20.20.20.1' |
| 649 | self.dhcp.return_option = 'router' |
| 650 | |
| 651 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
| 652 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 653 | (cip, sip, mac) ) |
| 654 | assert_equal(expected_router_address, router_address_value) |
| 655 | log_test.info('router address in server offer packet is same as configured router address in dhcp server') |
| 656 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 657 | def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 658 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 659 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 660 | |
| 661 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 662 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 663 | (cip, sip, mac) ) |
| 664 | assert_not_equal(cip,None) |
| 665 | self.dhcp.send_different_option = 'router' |
| 666 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 667 | assert_equal(new_cip, cip) |
| 668 | log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
| 669 | |
| 670 | def test_dhcpl2relay_with_client_expecting_broadcast_address(self, iface = 'veth0'): |
| 671 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 672 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 673 | expected_broadcast_address = '192.168.1.255' |
| 674 | self.dhcp.return_option = 'broadcast_address' |
| 675 | |
| 676 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
| 677 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 678 | (cip, sip, mac) ) |
| 679 | assert_equal(expected_broadcast_address, broadcast_address_value) |
| 680 | log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server') |
| 681 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 682 | def test_dhcpl2relay_with_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 683 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 684 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 685 | |
| 686 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 687 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 688 | (cip, sip, mac) ) |
| 689 | assert_not_equal(cip,None) |
| 690 | self.dhcp.send_different_option = 'broadcast_address' |
| 691 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 692 | assert_equal(new_cip, cip) |
| 693 | log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
| 694 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 695 | def test_dhcpl2relay_with_client_expecting_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 696 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 697 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 698 | expected_dns_address = '192.168.1.1' |
| 699 | self.dhcp.return_option = 'dns' |
| 700 | |
| 701 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
| 702 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 703 | (cip, sip, mac) ) |
| 704 | assert_equal(expected_dns_address, dns_address_value) |
| 705 | log_test.info('dns address in server offer packet is same as configured dns address in dhcp server') |
| 706 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 707 | def test_dhcpl2relay_with_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 708 | mac = self.get_mac(iface) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 709 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 710 | |
| 711 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 712 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 713 | (cip, sip, mac) ) |
| 714 | assert_not_equal(cip,None) |
| 715 | self.dhcp.send_different_option = 'dns' |
| 716 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 717 | assert_equal(new_cip, cip) |
| 718 | log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
| 719 | |
| 720 | |
| 721 | def test_dhcpl2relay_transactions_per_second(self, iface = 'veth0'): |
| 722 | |
| 723 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 724 | self.dhcpl2relay_stats_calc() |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 725 | log_test.info("Statistics for run %d",i) |
| 726 | log_test.info("----------------------------------------------------------------------------------") |
| 727 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 728 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 729 | log_test.info("----------------------------------------------------------------------------------") |
| 730 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 731 | |
| 732 | log_test.info("Final Statistics for total transactions") |
| 733 | log_test.info("----------------------------------------------------------------------------------") |
| 734 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 735 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 736 | self.total_success, self.total_failure, self.running_time)) |
| 737 | log_test.info("----------------------------------------------------------------------------------") |
| 738 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 739 | |
| 740 | def test_dhcpl2relay_consecutive_successes_per_second(self, iface = 'veth0'): |
| 741 | |
| 742 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 743 | self.dhcpl2relay_stats_calc(success_rate = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 744 | log_test.info("Statistics for run %d",i) |
| 745 | log_test.info("----------------------------------------------------------------------------------") |
| 746 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 747 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 748 | log_test.info("----------------------------------------------------------------------------------") |
| 749 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 750 | log_test.info("----------------------------------------------------------------------------------") |
| 751 | |
| 752 | log_test.info("Final Statistics for total successful transactions") |
| 753 | log_test.info("----------------------------------------------------------------------------------") |
| 754 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 755 | log_test.info(" %d %d %d " %(self.transactions, |
| 756 | self.total_success, self.running_time)) |
| 757 | log_test.info("----------------------------------------------------------------------------------") |
| 758 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 759 | log_test.info("----------------------------------------------------------------------------------") |
| 760 | |
| 761 | def test_dhcpl2relay_with_max_clients_per_second(self, iface = 'veth0'): |
| 762 | |
| 763 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 764 | self.dhcpl2relay_stats_calc(only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 765 | log_test.info("----------------------------------------------------------------------------------") |
| 766 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 767 | log_test.info("----------------------------------------------------------------------------------") |
| 768 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 769 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 770 | log_test.info("----------------------------------------------------------------------------------") |
| 771 | log_test.info("No. of clients per second in run %d:%f " |
| 772 | %(i, self.transaction_count)) |
| 773 | log_test.info("----------------------------------------------------------------------------------") |
| 774 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 775 | log_test.info("----------------------------------------------------------------------------------") |
| 776 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 777 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 778 | self.total_success, self.total_failure, self.running_time)) |
| 779 | log_test.info("----------------------------------------------------------------------------------") |
| 780 | log_test.info("Average no. of clients per second: %d ", |
| 781 | round(self.transactions/self.running_time,0)) |
| 782 | log_test.info("----------------------------------------------------------------------------------") |
| 783 | |
| 784 | def test_dhcpl2relay_consecutive_successful_clients_per_second(self, iface = 'veth0'): |
| 785 | |
| 786 | for i in range(1,4): |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 787 | self.dhcpl2relay_stats_calc(success_rate = True, only_discover = True) |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 788 | log_test.info("----------------------------------------------------------------------------------") |
| 789 | log_test.info("Statistics for run %d for sending only DHCP Discover",i) |
| 790 | log_test.info("----------------------------------------------------------------------------------") |
| 791 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 792 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 793 | log_test.info("----------------------------------------------------------------------------------") |
| 794 | log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 795 | log_test.info("----------------------------------------------------------------------------------") |
| 796 | |
| 797 | log_test.info("Final Statistics for total successful transactions") |
| 798 | log_test.info("----------------------------------------------------------------------------------") |
| 799 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 800 | log_test.info(" %d %d %d " %(self.transactions, |
| 801 | self.total_success, self.running_time)) |
| 802 | log_test.info("----------------------------------------------------------------------------------") |
| 803 | log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 804 | log_test.info("----------------------------------------------------------------------------------") |
| 805 | |
| 806 | def test_dhcpl2relay_concurrent_transactions_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 807 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 808 | self.host_load(g_subscriber_port_map[key]) |
| 809 | |
| 810 | def thread_fun(i): |
| 811 | mac = self.get_mac('veth{}'.format(i)) |
| 812 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 813 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 814 | self.lock.acquire() |
| 815 | |
| 816 | if cip: |
| 817 | self.ip_count += 1 |
| 818 | |
| 819 | elif cip is None: |
| 820 | self.failure_count += 1 |
| 821 | |
| 822 | self.lock.notify_all() |
| 823 | self.lock.release() |
| 824 | |
| 825 | for i in range (1,4): |
| 826 | self.ip_count = 0 |
| 827 | self.failure_count = 0 |
| 828 | self.start_time = 0 |
| 829 | self.diff = 0 |
| 830 | self.transaction_count = 0 |
| 831 | self.start_time = time.time() |
| 832 | |
| 833 | while self.diff <= 60: |
| 834 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 835 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 836 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 837 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 838 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 839 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 840 | |
| 841 | t.start() |
| 842 | t1.start() |
| 843 | t2.start() |
| 844 | t3.start() |
| 845 | t4.start() |
| 846 | t5.start() |
| 847 | |
| 848 | t.join() |
| 849 | t1.join() |
| 850 | t2.join() |
| 851 | t3.join() |
| 852 | t4.join() |
| 853 | t5.join() |
| 854 | |
| 855 | self.diff = round(time.time() - self.start_time, 0) |
| 856 | |
| 857 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 858 | |
| 859 | self.transactions += (self.ip_count+self.failure_count) |
| 860 | self.running_time += self.diff |
| 861 | self.total_success += self.ip_count |
| 862 | self.total_failure += self.failure_count |
| 863 | |
| 864 | |
| 865 | log_test.info("----------------------------------------------------------------------------------") |
| 866 | log_test.info("Statistics for run %d",i) |
| 867 | log_test.info("----------------------------------------------------------------------------------") |
| 868 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 869 | log_test.info(" %d %d %d %d" |
| 870 | %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff)) |
| 871 | log_test.info("----------------------------------------------------------------------------------") |
| 872 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 873 | log_test.info("----------------------------------------------------------------------------------") |
| 874 | |
| 875 | log_test.info("----------------------------------------------------------------------------------") |
| 876 | log_test.info("Final Statistics for total transactions") |
| 877 | log_test.info("----------------------------------------------------------------------------------") |
| 878 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 879 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 880 | self.total_success, self.total_failure, self.running_time)) |
| 881 | |
| 882 | log_test.info("----------------------------------------------------------------------------------") |
| 883 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 884 | log_test.info("----------------------------------------------------------------------------------") |
| 885 | |
| 886 | def test_dhcpl2relay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 887 | failure_dir = {} |
| 888 | |
| 889 | for key in (key for key in g_subscriber_port_map if key != 100): |
| 890 | self.host_load(g_subscriber_port_map[key]) |
| 891 | |
| 892 | def thread_fun(i, j): |
| 893 | # log_test.info("Thread Name:%s",current_thread().name) |
| 894 | # failure_dir[current_thread().name] = True |
| 895 | while failure_dir.has_key(current_thread().name) is False: |
| 896 | mac = RandMAC()._fix() |
| 897 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 898 | i += 2 |
| 899 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 900 | self.lock.acquire() |
| 901 | |
| 902 | if cip: |
| 903 | self.ip_count += 1 |
| 904 | self.lock.notify_all() |
| 905 | self.lock.release() |
| 906 | elif cip is None: |
| 907 | self.failure_count += 1 |
| 908 | failure_dir[current_thread().name] = True |
| 909 | self.lock.notify_all() |
| 910 | self.lock.release() |
| 911 | break |
| 912 | # self.lock.notify_all() |
| 913 | # self.lock.release() |
| 914 | |
| 915 | for i in range (1,4): |
| 916 | failure_dir = {} |
| 917 | self.ip_count = 0 |
| 918 | self.failure_count = 0 |
| 919 | self.start_time = 0 |
| 920 | self.diff = 0 |
| 921 | self.transaction_count = 0 |
| 922 | self.start_time = time.time() |
| 923 | |
| 924 | while len(failure_dir) != 6: |
| 925 | t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 926 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 927 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 928 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 929 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 930 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 931 | |
| 932 | t.start() |
| 933 | t1.start() |
| 934 | t2.start() |
| 935 | t3.start() |
| 936 | t4.start() |
| 937 | t5.start() |
| 938 | |
| 939 | t.join() |
| 940 | t1.join() |
| 941 | t2.join() |
| 942 | t3.join() |
| 943 | t4.join() |
| 944 | t5.join() |
| 945 | |
| 946 | self.diff = round(time.time() - self.start_time, 0) |
| 947 | self.transaction_count = round((self.ip_count)/self.diff, 2) |
| 948 | |
| 949 | self.transactions += (self.ip_count+self.failure_count) |
| 950 | self.running_time += self.diff |
| 951 | self.total_success += self.ip_count |
| 952 | self.total_failure += self.failure_count |
| 953 | |
| 954 | |
| 955 | log_test.info("Statistics for run %d",i) |
| 956 | log_test.info("----------------------------------------------------------------------------------") |
| 957 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 958 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 959 | log_test.info("----------------------------------------------------------------------------------") |
| 960 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 961 | log_test.info("----------------------------------------------------------------------------------") |
| 962 | |
| 963 | log_test.info("Final Statistics for total successful transactions") |
| 964 | log_test.info("----------------------------------------------------------------------------------") |
| 965 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 966 | log_test.info(" %d %d %d " %(self.transactions, |
| 967 | self.total_success, self.running_time)) |
| 968 | log_test.info("----------------------------------------------------------------------------------") |
| 969 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2)) |
| 970 | log_test.info("----------------------------------------------------------------------------------") |
| 971 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 972 | def test_dhcpl2relay_for_concurrent_clients_per_second(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 973 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 974 | self.host_load(g_subscriber_port_map[key]) |
| 975 | |
| 976 | def thread_fun(i): |
| 977 | # mac = self.get_mac('veth{}'.format(i)) |
| 978 | cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix()) |
| 979 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 980 | self.lock.acquire() |
| 981 | |
| 982 | if cip: |
| 983 | self.ip_count += 1 |
| 984 | elif cip is None: |
| 985 | self.failure_count += 1 |
| 986 | |
| 987 | self.lock.notify_all() |
| 988 | self.lock.release() |
| 989 | |
| 990 | for i in range (1,4): |
| 991 | self.ip_count = 0 |
| 992 | self.failure_count = 0 |
| 993 | self.start_time = 0 |
| 994 | self.diff = 0 |
| 995 | self.transaction_count = 0 |
| 996 | self.start_time = time.time() |
| 997 | |
| 998 | while self.diff <= 60: |
| 999 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1000 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1001 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1002 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1003 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1004 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1005 | |
| 1006 | t.start() |
| 1007 | t1.start() |
| 1008 | t2.start() |
| 1009 | t3.start() |
| 1010 | t4.start() |
| 1011 | t5.start() |
| 1012 | |
| 1013 | t.join() |
| 1014 | t1.join() |
| 1015 | t2.join() |
| 1016 | t3.join() |
| 1017 | t4.join() |
| 1018 | t5.join() |
| 1019 | |
| 1020 | self.diff = round(time.time() - self.start_time, 0) |
| 1021 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1022 | self.transactions += (self.ip_count+self.failure_count) |
| 1023 | self.running_time += self.diff |
| 1024 | self.total_success += self.ip_count |
| 1025 | self.total_failure += self.failure_count |
| 1026 | |
| 1027 | log_test.info("----------------------------------------------------------------------------------") |
| 1028 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1029 | log_test.info("----------------------------------------------------------------------------------") |
| 1030 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1031 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1032 | log_test.info("----------------------------------------------------------------------------------") |
| 1033 | log_test.info("No. of clients per second in run %d:%f " |
| 1034 | %(i, self.transaction_count)) |
| 1035 | log_test.info("----------------------------------------------------------------------------------") |
| 1036 | |
| 1037 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1038 | log_test.info("----------------------------------------------------------------------------------") |
| 1039 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1040 | log_test.info(" %d %d %d %d" %(self.transactions, |
| 1041 | self.total_success, self.total_failure, self.running_time)) |
| 1042 | log_test.info("----------------------------------------------------------------------------------") |
| 1043 | log_test.info("Average no. of clients per second: %d ", |
| 1044 | round(self.transactions/self.running_time,0)) |
| 1045 | log_test.info("----------------------------------------------------------------------------------") |
| 1046 | |
Chetan Gaonker | a6050ae | 2017-09-02 19:15:01 +0000 | [diff] [blame^] | 1047 | def test_dhcpl2relay_with_client_conflict(self, iface = 'veth0'): |
Chetan Gaonker | c1df33a | 2017-08-18 01:29:54 +0000 | [diff] [blame] | 1048 | mac = self.get_mac(iface) |
| 1049 | self.host_load(iface) |
| 1050 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1051 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1052 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1053 | (cip, sip, mac) ) |
| 1054 | self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface) |
| 1055 | new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True) |
| 1056 | new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac) |
| 1057 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1058 | (new_cip, new_sip, new_mac) ) |
| 1059 | log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac)) |
| 1060 | log_test.info("Now sending DHCP Request for old DHCP discover.") |
| 1061 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1062 | if new_cip is None: |
| 1063 | log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.' |
| 1064 | %(new_cip, new_sip, new_mac) ) |
| 1065 | elif new_cip: |
| 1066 | 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.' |
| 1067 | %(new_cip, new_sip, new_mac, new_cip) ) |
| 1068 | assert_equal(new_cip, None) |