Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [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 | |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 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, |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 28 | # WITHOUT WARRANTIES OR CONDITIONS OF AeY KIND, either express or implied. |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 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 |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 36 | import time |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 37 | import os, sys |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 38 | from DHCP import DHCPTest |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 39 | from CordTestUtils import get_mac, log_test |
A.R Karthick | be7768c | 2017-03-17 11:39:41 -0700 | [diff] [blame] | 40 | from OnosCtrl import OnosCtrl |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 41 | from OltConfig import OltConfig |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 42 | from CordTestServer import cord_test_onos_restart |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 43 | from CordLogger import CordLogger |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 44 | from portmaps import g_subscriber_port_map |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 45 | import threading, random |
| 46 | from threading import current_thread |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 47 | log_test.setLevel('INFO') |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 48 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 49 | class dhcprelay_exchange(CordLogger): |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 50 | |
| 51 | app = 'org.onosproject.dhcprelay' |
| 52 | app_dhcp = 'org.onosproject.dhcp' |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 53 | relay_interfaces_last = () |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 54 | interface_to_mac_map = {} |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 55 | host_ip_map = {} |
| 56 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 57 | dhcp_data_dir = os.path.join(test_path, '..', 'setup') |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 58 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json')) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 59 | default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, } |
| 60 | default_options = [ ('subnet-mask', '255.255.255.0'), |
| 61 | ('broadcast-address', '192.168.1.255'), |
| 62 | ('domain-name-servers', '192.168.1.1'), |
| 63 | ('domain-name', '"mydomain.cord-tester"'), |
| 64 | ] |
| 65 | ##specify the IP for the dhcp interface matching the subnet and subnet config |
| 66 | ##this is done for each interface dhcpd server would be listening on |
| 67 | default_subnet_config = [ ('192.168.1.2', |
| 68 | ''' |
| 69 | subnet 192.168.1.0 netmask 255.255.255.0 { |
| 70 | range 192.168.1.10 192.168.1.100; |
| 71 | } |
| 72 | '''), ] |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 73 | |
| 74 | lock = threading.Condition() |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 75 | ip_count = 0 |
| 76 | failure_count = 0 |
| 77 | start_time = 0 |
| 78 | diff = 0 |
| 79 | |
| 80 | transaction_count = 0 |
| 81 | transactions = 0 |
| 82 | running_time = 0 |
| 83 | total_success = 0 |
| 84 | total_failure = 0 |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 85 | #just in case we want to reset ONOS to default network cfg after relay tests |
| 86 | onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0))) |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 87 | configs = {} |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 88 | |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 89 | @classmethod |
| 90 | def setUpClass(cls): |
| 91 | ''' Activate the dhcprelay app''' |
| 92 | OnosCtrl(cls.app_dhcp).deactivate() |
| 93 | time.sleep(3) |
| 94 | cls.onos_ctrl = OnosCtrl(cls.app) |
| 95 | status, _ = cls.onos_ctrl.activate() |
| 96 | assert_equal(status, True) |
| 97 | time.sleep(3) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 98 | cls.dhcp_relay_setup() |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 99 | ##start dhcpd initially with default config |
| 100 | cls.dhcpd_start() |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 101 | |
| 102 | @classmethod |
| 103 | def tearDownClass(cls): |
| 104 | '''Deactivate the dhcp relay app''' |
| 105 | try: |
| 106 | os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir)) |
| 107 | os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir)) |
| 108 | except: pass |
| 109 | cls.onos_ctrl.deactivate() |
| 110 | cls.dhcpd_stop() |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 111 | cls.dhcp_relay_cleanup() |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 112 | |
| 113 | @classmethod |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 114 | def dhcp_relay_setup(cls): |
| 115 | did = OnosCtrl.get_device_id() |
| 116 | cls.relay_device_id = did |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 117 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 118 | cls.port_map, _ = cls.olt.olt_port_map() |
| 119 | if cls.port_map: |
A R Karthick | 36cfcef | 2016-08-18 15:20:07 -0700 | [diff] [blame] | 120 | ##Per subscriber, we use 1 relay port |
| 121 | try: |
| 122 | relay_port = cls.port_map[cls.port_map['relay_ports'][0]] |
| 123 | except: |
| 124 | relay_port = cls.port_map['uplink'] |
| 125 | cls.relay_interface_port = relay_port |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 126 | cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],) |
| 127 | else: |
| 128 | cls.relay_interface_port = 100 |
| 129 | cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],) |
| 130 | cls.relay_interfaces_last = cls.relay_interfaces |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 131 | if cls.port_map: |
| 132 | ##generate a ip/mac client virtual interface config for onos |
| 133 | interface_list = [] |
| 134 | for port in cls.port_map['ports']: |
| 135 | port_num = cls.port_map[port] |
| 136 | if port_num == cls.port_map['uplink']: |
A R Karthick | 36cfcef | 2016-08-18 15:20:07 -0700 | [diff] [blame] | 137 | continue |
| 138 | ip = cls.get_host_ip(port_num) |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 139 | mac = cls.get_mac(port) |
| 140 | interface_list.append((port_num, ip, mac)) |
| 141 | |
A R Karthick | 36cfcef | 2016-08-18 15:20:07 -0700 | [diff] [blame] | 142 | #configure dhcp server virtual interface on the same subnet as first client interface |
| 143 | relay_ip = cls.get_host_ip(interface_list[0][0]) |
| 144 | relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port]) |
| 145 | interface_list.append((cls.relay_interface_port, relay_ip, relay_mac)) |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 146 | cls.onos_interface_load(interface_list) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 147 | |
| 148 | @classmethod |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 149 | def dhcp_relay_cleanup(cls): |
| 150 | ##reset the ONOS port configuration back to default |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 151 | for config in cls.configs.items(): |
| 152 | OnosCtrl.delete(config) |
| 153 | # if cls.onos_restartable is True: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 154 | # log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg') |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 155 | # return cord_test_onos_restart(config = {}) |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 156 | |
| 157 | @classmethod |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 158 | def onos_load_config(cls, config): |
| 159 | status, code = OnosCtrl.config(config) |
| 160 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 161 | log_test.info('JSON request returned status %d' %code) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 162 | assert_equal(status, True) |
| 163 | time.sleep(3) |
| 164 | |
| 165 | @classmethod |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 166 | def onos_interface_load(cls, interface_list): |
| 167 | interface_dict = { 'ports': {} } |
| 168 | for port_num, ip, mac in interface_list: |
| 169 | port_map = interface_dict['ports'] |
| 170 | port = '{}/{}'.format(cls.relay_device_id, port_num) |
| 171 | port_map[port] = { 'interfaces': [] } |
| 172 | interface_list = port_map[port]['interfaces'] |
| 173 | interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ], |
| 174 | 'mac' : mac, |
| 175 | 'name': 'vir-{}'.format(port_num) |
| 176 | } |
| 177 | interface_list.append(interface_map) |
| 178 | |
| 179 | cls.onos_load_config(interface_dict) |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 180 | cls.configs['interface_config'] = interface_dict |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 181 | |
| 182 | @classmethod |
| 183 | def onos_dhcp_relay_load(cls, server_ip, server_mac): |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 184 | relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port) |
| 185 | dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay': |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 186 | {'dhcpserverConnectPoint':relay_device_map, |
| 187 | 'serverip':server_ip, |
| 188 | 'servermac':server_mac |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 193 | cls.onos_load_config(dhcp_dict) |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 194 | cls.configs['relay_config'] = dhcp_dict |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 195 | |
| 196 | @classmethod |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 197 | def get_host_ip(cls, port): |
| 198 | if cls.host_ip_map.has_key(port): |
| 199 | return cls.host_ip_map[port] |
| 200 | cls.host_ip_map[port] = '192.168.1.{}'.format(port) |
| 201 | return cls.host_ip_map[port] |
| 202 | |
| 203 | @classmethod |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 204 | def host_load(cls, iface): |
| 205 | '''Have ONOS discover the hosts for dhcp-relay responses''' |
| 206 | port = g_subscriber_port_map[iface] |
| 207 | host = '173.17.1.{}'.format(port) |
| 208 | cmds = ( 'ifconfig {} 0'.format(iface), |
| 209 | 'ifconfig {0} {1}'.format(iface, host), |
| 210 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 211 | 'ifconfig {} 0'.format(iface), ) |
| 212 | for c in cmds: |
| 213 | os.system(c) |
| 214 | |
| 215 | @classmethod |
| 216 | def dhcpd_conf_generate(cls, config = default_config, options = default_options, |
| 217 | subnet = default_subnet_config): |
| 218 | conf = '' |
| 219 | for k, v in config.items(): |
| 220 | conf += '{} {};\n'.format(k, v) |
| 221 | |
| 222 | opts = '' |
| 223 | for k, v in options: |
| 224 | opts += 'option {} {};\n'.format(k, v) |
| 225 | |
| 226 | subnet_config = '' |
| 227 | for _, v in subnet: |
| 228 | subnet_config += '{}\n'.format(v) |
| 229 | |
| 230 | return '{}{}{}'.format(conf, opts, subnet_config) |
| 231 | |
| 232 | @classmethod |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 233 | def dhcpd_start(cls, intf_list = None, |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 234 | config = default_config, options = default_options, |
| 235 | subnet = default_subnet_config): |
| 236 | '''Start the dhcpd server by generating the conf file''' |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 237 | if intf_list is None: |
| 238 | intf_list = cls.relay_interfaces |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 239 | ##stop dhcpd if already running |
| 240 | cls.dhcpd_stop() |
| 241 | dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options, |
| 242 | subnet = subnet) |
| 243 | ##first touch dhcpd.leases if it doesn't exist |
| 244 | lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir) |
| 245 | if os.access(lease_file, os.F_OK) is False: |
| 246 | with open(lease_file, 'w') as fd: pass |
| 247 | |
| 248 | conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir) |
| 249 | with open(conf_file, 'w') as fd: |
| 250 | fd.write(dhcp_conf) |
| 251 | |
| 252 | #now configure the dhcpd interfaces for various subnets |
| 253 | index = 0 |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 254 | intf_info = [] |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 255 | for ip,_ in subnet: |
| 256 | intf = intf_list[index] |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 257 | mac = cls.get_mac(intf) |
| 258 | intf_info.append((ip, mac)) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 259 | index += 1 |
| 260 | os.system('ifconfig {} {}'.format(intf, ip)) |
| 261 | |
| 262 | intf_str = ','.join(intf_list) |
| 263 | dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 264 | log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 265 | ret = os.system(dhcpd_cmd) |
| 266 | assert_equal(ret, 0) |
| 267 | time.sleep(3) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 268 | cls.relay_interfaces_last = cls.relay_interfaces |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 269 | cls.relay_interfaces = intf_list |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 270 | cls.onos_dhcp_relay_load(*intf_info[0]) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 271 | |
| 272 | @classmethod |
| 273 | def dhcpd_stop(cls): |
| 274 | os.system('pkill -9 dhcpd') |
| 275 | for intf in cls.relay_interfaces: |
| 276 | os.system('ifconfig {} 0'.format(intf)) |
| 277 | |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 278 | cls.relay_interfaces = cls.relay_interfaces_last |
| 279 | |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 280 | @classmethod |
| 281 | def get_mac(cls, iface): |
| 282 | if cls.interface_to_mac_map.has_key(iface): |
| 283 | return cls.interface_to_mac_map[iface] |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 284 | mac = get_mac(iface, pad = 0) |
A R Karthick | 3026e48 | 2016-08-12 16:02:40 -0700 | [diff] [blame] | 285 | cls.interface_to_mac_map[iface] = mac |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 286 | return mac |
| 287 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 288 | def stats(self,success_rate = False, only_discover = False, iface = 'veth0'): |
| 289 | |
| 290 | self.ip_count = 0 |
| 291 | self.failure_count = 0 |
| 292 | self.start_time = 0 |
| 293 | self.diff = 0 |
| 294 | self.transaction_count = 0 |
| 295 | |
| 296 | mac = self.get_mac(iface) |
| 297 | self.host_load(iface) |
| 298 | ##we use the defaults for this test that serves as an example for others |
| 299 | ##You don't need to restart dhcpd server if retaining default config |
| 300 | config = self.default_config |
| 301 | options = self.default_options |
| 302 | subnet = self.default_subnet_config |
| 303 | dhcpd_interface_list = self.relay_interfaces |
| 304 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 305 | config = config, |
| 306 | options = options, |
| 307 | subnet = subnet) |
| 308 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 309 | self.start_time = time.time() |
| 310 | |
| 311 | while self.diff <= 60: |
| 312 | |
| 313 | if only_discover: |
| 314 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 315 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 316 | (cip, sip, mac)) |
| 317 | else: |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 318 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 319 | |
| 320 | if cip: |
| 321 | self.ip_count +=1 |
| 322 | elif cip == None: |
| 323 | self.failure_count += 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 324 | log_test.info('Failed to get ip') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 325 | if success_rate and self.ip_count > 0: |
| 326 | break |
| 327 | |
| 328 | self.diff = round(time.time() - self.start_time, 0) |
| 329 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 330 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 331 | self.transactions += (self.ip_count+self.failure_count) |
| 332 | self.running_time += self.diff |
| 333 | self.total_success += self.ip_count |
| 334 | self.total_failure += self.failure_count |
| 335 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 336 | def send_recv(self, mac=None, update_seed = False, validate = True): |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 337 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 338 | if validate: |
| 339 | assert_not_equal(cip, None) |
| 340 | assert_not_equal(sip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 341 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 342 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 343 | return cip,sip |
| 344 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 345 | def test_dhcpRelay_1request(self, iface = 'veth0'): |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 346 | mac = self.get_mac(iface) |
| 347 | self.host_load(iface) |
| 348 | ##we use the defaults for this test that serves as an example for others |
| 349 | ##You don't need to restart dhcpd server if retaining default config |
| 350 | config = self.default_config |
| 351 | options = self.default_options |
| 352 | subnet = self.default_subnet_config |
| 353 | dhcpd_interface_list = self.relay_interfaces |
| 354 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 355 | config = config, |
| 356 | options = options, |
| 357 | subnet = subnet) |
| 358 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 359 | self.send_recv(mac=mac) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 360 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 361 | def test_dhcpRelay_1request_with_invalid_source_mac_broadcast(self, iface = 'veth0'): |
| 362 | mac = self.get_mac(iface) |
| 363 | self.host_load(iface) |
| 364 | ##we use the defaults for this test that serves as an example for others |
| 365 | ##You don't need to restart dhcpd server if retaining default config |
| 366 | config = self.default_config |
| 367 | options = self.default_options |
| 368 | subnet = self.default_subnet_config |
| 369 | dhcpd_interface_list = self.relay_interfaces |
| 370 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 371 | config = config, |
| 372 | options = options, |
| 373 | subnet = subnet) |
| 374 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 375 | cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff') |
| 376 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 377 | log_test.info('dhcp server rejected client discover with invalid source mac, as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 378 | |
| 379 | def test_dhcpRelay_1request_with_invalid_source_mac_multicast(self, iface = 'veth0'): |
| 380 | mac = self.get_mac(iface) |
| 381 | self.host_load(iface) |
| 382 | ##we use the defaults for this test that serves as an example for others |
| 383 | ##You don't need to restart dhcpd server if retaining default config |
| 384 | config = self.default_config |
| 385 | options = self.default_options |
| 386 | subnet = self.default_subnet_config |
| 387 | dhcpd_interface_list = self.relay_interfaces |
| 388 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 389 | config = config, |
| 390 | options = options, |
| 391 | subnet = subnet) |
| 392 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 393 | cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:01:98:05') |
| 394 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 395 | log_test.info('dhcp server rejected client discover with invalid source mac, as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 396 | |
| 397 | def test_dhcpRelay_1request_with_invalid_source_mac_zero(self, iface = 'veth0'): |
| 398 | mac = self.get_mac(iface) |
| 399 | self.host_load(iface) |
| 400 | ##we use the defaults for this test that serves as an example for others |
| 401 | ##You don't need to restart dhcpd server if retaining default config |
| 402 | config = self.default_config |
| 403 | options = self.default_options |
| 404 | subnet = self.default_subnet_config |
| 405 | dhcpd_interface_list = self.relay_interfaces |
| 406 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 407 | config = config, |
| 408 | options = options, |
| 409 | subnet = subnet) |
| 410 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 411 | cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00') |
| 412 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 413 | log_test.info('dhcp server rejected client discover with invalid source mac, as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 414 | |
| 415 | def test_dhcpRelay_Nrequest(self, iface = 'veth0',requests=10): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 416 | mac = self.get_mac(iface) |
| 417 | self.host_load(iface) |
| 418 | ##we use the defaults for this test that serves as an example for others |
| 419 | ##You don't need to restart dhcpd server if retaining default config |
| 420 | config = self.default_config |
| 421 | options = self.default_options |
| 422 | subnet = self.default_subnet_config |
| 423 | dhcpd_interface_list = self.relay_interfaces |
| 424 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 425 | config = config, |
| 426 | options = options, |
| 427 | subnet = subnet) |
| 428 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface) |
| 429 | ip_map = {} |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 430 | for i in range(requests): |
| 431 | #mac = RandMAC()._fix() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 432 | #log_test.info('mac is %s'%mac) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 433 | cip, sip = self.send_recv(update_seed = True) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 434 | if ip_map.has_key(cip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 435 | log_test.info('IP %s given out multiple times' %cip) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 436 | assert_equal(False, ip_map.has_key(cip)) |
| 437 | ip_map[cip] = sip |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 438 | time.sleep(1) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 439 | |
| 440 | def test_dhcpRelay_1release(self, iface = 'veth0'): |
| 441 | mac = self.get_mac(iface) |
| 442 | self.host_load(iface) |
| 443 | ##we use the defaults for this test that serves as an example for others |
| 444 | ##You don't need to restart dhcpd server if retaining default config |
| 445 | config = self.default_config |
| 446 | options = self.default_options |
| 447 | subnet = self.default_subnet_config |
| 448 | dhcpd_interface_list = self.relay_interfaces |
| 449 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 450 | config = config, |
| 451 | options = options, |
| 452 | subnet = subnet) |
| 453 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 454 | cip, sip = self.send_recv(mac=mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 455 | log_test.info('Releasing ip %s to server %s' %(cip, sip)) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 456 | assert_equal(self.dhcp.release(cip), True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 457 | log_test.info('Triggering DHCP discover again after release') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 458 | cip2, sip2 = self.send_recv(mac=mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 459 | log_test.info('Verifying released IP was given back on rediscover') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 460 | assert_equal(cip, cip2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 461 | log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 462 | assert_equal(self.dhcp.release(cip2), True) |
| 463 | |
| 464 | def test_dhcpRelay_Nrelease(self, iface = 'veth0'): |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 465 | mac = None |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 466 | self.host_load(iface) |
| 467 | ##we use the defaults for this test that serves as an example for others |
| 468 | ##You don't need to restart dhcpd server if retaining default config |
| 469 | config = self.default_config |
| 470 | options = self.default_options |
| 471 | subnet = self.default_subnet_config |
| 472 | dhcpd_interface_list = self.relay_interfaces |
| 473 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 474 | config = config, |
| 475 | options = options, |
| 476 | subnet = subnet) |
| 477 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 478 | ip_map = {} |
| 479 | for i in range(10): |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 480 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 481 | if ip_map.has_key(cip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 482 | log_test.info('IP %s given out multiple times' %cip) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 483 | assert_equal(False, ip_map.has_key(cip)) |
| 484 | ip_map[cip] = sip |
| 485 | |
| 486 | for ip in ip_map.keys(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 487 | log_test.info('Releasing IP %s' %ip) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 488 | assert_equal(self.dhcp.release(ip), True) |
| 489 | |
| 490 | ip_map2 = {} |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 491 | log_test.info('Triggering DHCP discover again after release') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 492 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 493 | for i in range(len(ip_map.keys())): |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 494 | cip, sip = self.send_recv(mac=mac, update_seed = True) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 495 | ip_map2[cip] = sip |
| 496 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 497 | log_test.info('Verifying released IPs were given back on rediscover') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 498 | if ip_map != ip_map2: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 499 | log_test.info('Map before release %s' %ip_map) |
| 500 | log_test.info('Map after release %s' %ip_map2) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 501 | assert_equal(ip_map, ip_map2) |
| 502 | |
| 503 | def test_dhcpRelay_starvation(self, iface = 'veth0'): |
| 504 | mac = self.get_mac(iface) |
| 505 | self.host_load(iface) |
| 506 | ##we use the defaults for this test that serves as an example for others |
| 507 | ##You don't need to restart dhcpd server if retaining default config |
| 508 | config = self.default_config |
| 509 | options = self.default_options |
| 510 | subnet = self.default_subnet_config |
| 511 | dhcpd_interface_list = self.relay_interfaces |
| 512 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 513 | config = config, |
| 514 | options = options, |
| 515 | subnet = subnet) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 516 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 517 | log_test.info('Verifying 1 ') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 518 | count = 0 |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 519 | while True: |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 520 | #mac = RandMAC()._fix() |
| 521 | cip, sip = self.send_recv(update_seed = True,validate = False) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 522 | if cip is None: |
| 523 | break |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 524 | else: |
| 525 | count += 1 |
| 526 | assert_equal(count,91) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 527 | log_test.info('Verifying 2 ') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 528 | cip, sip = self.send_recv(mac=mac, update_seed = True, validate = False) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 529 | assert_equal(cip, None) |
| 530 | assert_equal(sip, None) |
| 531 | |
| 532 | def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'): |
| 533 | mac = self.get_mac(iface) |
| 534 | self.host_load(iface) |
| 535 | ##we use the defaults for this test that serves as an example for others |
| 536 | ##You don't need to restart dhcpd server if retaining default config |
| 537 | config = self.default_config |
| 538 | options = self.default_options |
| 539 | subnet = self.default_subnet_config |
| 540 | dhcpd_interface_list = self.relay_interfaces |
| 541 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 542 | config = config, |
| 543 | options = options, |
| 544 | subnet = subnet) |
| 545 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 546 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 547 | log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 548 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 549 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 550 | log_test.info('Triggering DHCP discover again.') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 551 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 552 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 553 | log_test.info('got same ip to smae the client when sent discover again, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 554 | |
| 555 | def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'): |
| 556 | mac = self.get_mac(iface) |
| 557 | self.host_load(iface) |
| 558 | ##we use the defaults for this test that serves as an example for others |
| 559 | ##You don't need to restart dhcpd server if retaining default config |
| 560 | config = self.default_config |
| 561 | options = self.default_options |
| 562 | subnet = self.default_subnet_config |
| 563 | dhcpd_interface_list = self.relay_interfaces |
| 564 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 565 | config = config, |
| 566 | options = options, |
| 567 | subnet = subnet) |
| 568 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 569 | log_test.info('Sending DHCP discover and DHCP request.') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 570 | cip, sip = self.send_recv(mac=mac) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 571 | mac = self.dhcp.get_mac(cip)[0] |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 572 | log_test.info("Sending DHCP request again.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 573 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 574 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 575 | log_test.info('got same ip to smae the client when sent request again, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 576 | |
| 577 | def test_dhcpRelay_client_desired_address(self, iface = 'veth0'): |
| 578 | mac = self.get_mac(iface) |
| 579 | self.host_load(iface) |
| 580 | ##we use the defaults for this test that serves as an example for others |
| 581 | ##You don't need to restart dhcpd server if retaining default config |
| 582 | config = self.default_config |
| 583 | options = self.default_options |
| 584 | subnet = self.default_subnet_config |
| 585 | dhcpd_interface_list = self.relay_interfaces |
| 586 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 587 | config = config, |
| 588 | options = options, |
| 589 | subnet = subnet) |
| 590 | self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface) |
| 591 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 592 | assert_equal(cip,self.dhcp.seed_ip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 593 | log_test.info('Got dhcp client desired IP %s from server %s for mac %s as expected' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 594 | (cip, sip, mac) ) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 595 | |
| 596 | def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'): |
| 597 | mac = self.get_mac(iface) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 598 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 599 | self.host_load(iface) |
| 600 | ##we use the defaults for this test that serves as an example for others |
| 601 | ##You don't need to restart dhcpd server if retaining default config |
| 602 | config = self.default_config |
| 603 | options = self.default_options |
| 604 | subnet = self.default_subnet_config |
| 605 | dhcpd_interface_list = self.relay_interfaces |
| 606 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 607 | config = config, |
| 608 | options = options, |
| 609 | subnet = subnet) |
| 610 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 611 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 612 | assert_not_equal(cip,None) |
| 613 | assert_not_equal(cip,self.dhcp.seed_ip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 614 | log_test.info('server offered IP from its pool when requested out of pool IP, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 615 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 616 | def test_dhcpRelay_nak_packet(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 617 | mac = self.get_mac(iface) |
| 618 | self.host_load(iface) |
| 619 | ##we use the defaults for this test that serves as an example for others |
| 620 | ##You don't need to restart dhcpd server if retaining default config |
| 621 | config = self.default_config |
| 622 | options = self.default_options |
| 623 | subnet = self.default_subnet_config |
| 624 | dhcpd_interface_list = self.relay_interfaces |
| 625 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 626 | config = config, |
| 627 | options = options, |
| 628 | subnet = subnet) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 629 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 630 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 631 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 632 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 633 | assert_not_equal(cip, None) |
| 634 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 635 | assert_equal(new_cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 636 | log_test.info('server sent NAK packet when requested other IP than that server offered') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 637 | |
| 638 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 639 | def test_dhcpRelay_client_requests_specific_lease_time_in_discover(self, iface = 'veth0',lease_time=700): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 640 | mac = self.get_mac(iface) |
| 641 | self.host_load(iface) |
| 642 | ##we use the defaults for this test that serves as an example for others |
| 643 | ##You don't need to restart dhcpd server if retaining default config |
| 644 | config = self.default_config |
| 645 | options = self.default_options |
| 646 | subnet = self.default_subnet_config |
| 647 | dhcpd_interface_list = self.relay_interfaces |
| 648 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 649 | config = config, |
| 650 | options = options, |
| 651 | subnet = subnet) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 652 | self.dhcp = DHCPTest(seed_ip = '10.10.10.70', iface = iface) |
| 653 | self.dhcp.return_option = 'lease' |
| 654 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time=True,lease_value=lease_time) |
| 655 | assert_equal(lval, lease_time) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 656 | log_test.info('dhcp server offered IP address with client requested lease time') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 657 | |
| 658 | def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'): |
| 659 | mac = self.get_mac(iface) |
| 660 | self.host_load(iface) |
| 661 | ##we use the defaults for this test that serves as an example for others |
| 662 | ##You don't need to restart dhcpd server if retaining default config |
| 663 | config = self.default_config |
| 664 | options = self.default_options |
| 665 | subnet = self.default_subnet_config |
| 666 | dhcpd_interface_list = self.relay_interfaces |
| 667 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 668 | config = config, |
| 669 | options = options, |
| 670 | subnet = subnet) |
| 671 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 672 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 673 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 674 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 675 | assert_not_equal(cip, None) |
| 676 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 677 | log_test.info('client rebooting...') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 678 | os.system('ifconfig '+iface+' down') |
| 679 | time.sleep(5) |
| 680 | os.system('ifconfig '+iface+' up') |
| 681 | new_cip2, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
| 682 | assert_equal(new_cip2, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 683 | log_test.info('client got same IP after reboot, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 684 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 685 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 686 | def test_dhcpRelay_after_server_reboot(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 687 | mac = self.get_mac(iface) |
| 688 | self.host_load(iface) |
| 689 | ##we use the defaults for this test that serves as an example for others |
| 690 | ##You don't need to restart dhcpd server if retaining default config |
| 691 | config = self.default_config |
| 692 | options = self.default_options |
| 693 | subnet = self.default_subnet_config |
| 694 | dhcpd_interface_list = self.relay_interfaces |
| 695 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 696 | config = config, |
| 697 | options = options, |
| 698 | subnet = subnet) |
| 699 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 700 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 701 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 702 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 703 | assert_not_equal(cip, None) |
| 704 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 705 | log_test.info('server rebooting...') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 706 | self.tearDownClass() |
| 707 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 708 | assert_equal(new_cip,None) |
| 709 | self.setUpClass() |
| 710 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 711 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 712 | log_test.info('client got same IP after server rebooted, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 713 | |
| 714 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 715 | def test_dhcpRelay_specific_lease_time_only_in_discover_but_not_in_request_packet(self, iface = 'veth0',lease_time=700): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 716 | mac = self.get_mac(iface) |
| 717 | self.host_load(iface) |
| 718 | ##we use the defaults for this test that serves as an example for others |
| 719 | ##You don't need to restart dhcpd server if retaining default config |
| 720 | config = self.default_config |
| 721 | options = self.default_options |
| 722 | subnet = self.default_subnet_config |
| 723 | dhcpd_interface_list = self.relay_interfaces |
| 724 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 725 | config = config, |
| 726 | options = options, |
| 727 | subnet = subnet) |
| 728 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 729 | self.dhcp.return_option = 'lease' |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 730 | log_test.info('Sending DHCP discover with lease time of 700') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 731 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value=lease_time) |
| 732 | assert_equal(lval,lease_time) |
| 733 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 734 | assert_equal(new_cip,cip) |
| 735 | assert_not_equal(lval, lease_time) #Negative Test Case |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 736 | log_test.info('client requested lease time in discover packer is not seen in server ACK packet as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 737 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 738 | def test_dhcpRelay_specific_lease_time_only_in_request_but_not_in_discover_packet(self, iface = 'veth0',lease_time=800): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 739 | mac = self.get_mac(iface) |
| 740 | self.host_load(iface) |
| 741 | ##we use the defaults for this test that serves as an example for others |
| 742 | ##You don't need to restart dhcpd server if retaining default config |
| 743 | config = self.default_config |
| 744 | options = self.default_options |
| 745 | subnet = self.default_subnet_config |
| 746 | dhcpd_interface_list = self.relay_interfaces |
| 747 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 748 | config = config, |
| 749 | options = options, |
| 750 | subnet = subnet) |
| 751 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 752 | cip, sip, mac, _ = self.dhcp.only_discover() |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 753 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True,lease_value=lease_time) |
| 754 | assert_equal(new_cip,cip) |
| 755 | assert_equal(lval, lease_time) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 756 | log_test.info('client requested lease time in request packet seen in servre replied ACK packet as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 757 | |
| 758 | def test_dhcpRelay_client_renew_time(self, iface = 'veth0'): |
| 759 | mac = self.get_mac(iface) |
| 760 | self.host_load(iface) |
| 761 | ##we use the defaults for this test that serves as an example for others |
| 762 | ##You don't need to restart dhcpd server if retaining default config |
| 763 | config = self.default_config |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 764 | new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)] |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 765 | options = self.default_options + new_options |
| 766 | subnet = self.default_subnet_config |
| 767 | dhcpd_interface_list = self.relay_interfaces |
| 768 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 769 | config = config, |
| 770 | options = options, |
| 771 | subnet = subnet) |
| 772 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 773 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 774 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 775 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 776 | assert_not_equal(cip,None) |
| 777 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 778 | log_test.info('waiting for renew time..') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 779 | time.sleep(lval) |
| 780 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 781 | assert_equal(latest_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 782 | log_test.info('server renewed client IP when client sends request after renew time, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 783 | |
| 784 | |
| 785 | def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'): |
| 786 | mac = self.get_mac(iface) |
| 787 | self.host_load(iface) |
| 788 | ##we use the defaults for this test that serves as an example for others |
| 789 | ##You don't need to restart dhcpd server if retaining default config |
| 790 | config = self.default_config |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 791 | new_options = [('dhcp-renewal-time', 100), ('dhcp-rebinding-time', 125)] |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 792 | options = self.default_options + new_options |
| 793 | subnet = self.default_subnet_config |
| 794 | dhcpd_interface_list = self.relay_interfaces |
| 795 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 796 | config = config, |
| 797 | options = options, |
| 798 | subnet = subnet) |
| 799 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 800 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 801 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 802 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 803 | assert_not_equal(cip,None) |
| 804 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 805 | log_test.info('waiting for rebind time..') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 806 | time.sleep(lval) |
| 807 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 808 | assert_equal(latest_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 809 | log_test.info('server renewed client IP when client sends request after rebind time, as expected') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 810 | |
| 811 | |
| 812 | def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'): |
| 813 | mac = self.get_mac(iface) |
| 814 | self.host_load(iface) |
| 815 | ##we use the defaults for this test that serves as an example for others |
| 816 | ##You don't need to restart dhcpd server if retaining default config |
| 817 | config = self.default_config |
| 818 | options = self.default_options |
| 819 | subnet = self.default_subnet_config |
| 820 | dhcpd_interface_list = self.relay_interfaces |
| 821 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 822 | config = config, |
| 823 | options = options, |
| 824 | subnet = subnet) |
| 825 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 826 | expected_subnet = '255.255.255.0' |
| 827 | self.dhcp.return_option = 'subnet' |
| 828 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 829 | cip, sip, mac, subnet_mask = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 830 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 831 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 832 | assert_equal(subnet_mask,expected_subnet) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 833 | log_test.info('subnet mask in server offer packet is same as configured subnet mask in dhcp server') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 834 | |
| 835 | |
| 836 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'): |
| 837 | mac = self.get_mac(iface) |
| 838 | self.host_load(iface) |
| 839 | ##we use the defaults for this test that serves as an example for others |
| 840 | ##You don't need to restart dhcpd server if retaining default config |
| 841 | config = self.default_config |
| 842 | options = self.default_options |
| 843 | subnet = self.default_subnet_config |
| 844 | dhcpd_interface_list = self.relay_interfaces |
| 845 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 846 | config = config, |
| 847 | options = options, |
| 848 | subnet = subnet) |
| 849 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 850 | |
| 851 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 852 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 853 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 854 | assert_not_equal(cip,None) |
| 855 | self.dhcp.send_different_option = 'subnet' |
| 856 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 857 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 858 | log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 859 | |
| 860 | |
| 861 | def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'): |
| 862 | mac = self.get_mac(iface) |
| 863 | self.host_load(iface) |
| 864 | ##we use the defaults for this test that serves as an example for others |
| 865 | ##You don't need to restart dhcpd server if retaining default config |
| 866 | config = self.default_config |
| 867 | config = self.default_config |
| 868 | new_options = [('routers', '20.20.20.1')] |
| 869 | options = self.default_options + new_options |
| 870 | subnet = self.default_subnet_config |
| 871 | dhcpd_interface_list = self.relay_interfaces |
| 872 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 873 | config = config, |
| 874 | options = options, |
| 875 | subnet = subnet) |
| 876 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 877 | expected_router_address = '20.20.20.1' |
| 878 | self.dhcp.return_option = 'router' |
| 879 | |
| 880 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 881 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 882 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 883 | assert_equal(expected_router_address, router_address_value) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 884 | log_test.info('router address in server offer packet is same as configured router address in dhcp server') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 885 | |
| 886 | |
| 887 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'): |
| 888 | mac = self.get_mac(iface) |
| 889 | self.host_load(iface) |
| 890 | ##we use the defaults for this test that serves as an example for others |
| 891 | ##You don't need to restart dhcpd server if retaining default config |
| 892 | config = self.default_config |
| 893 | options = self.default_options |
| 894 | subnet = self.default_subnet_config |
| 895 | dhcpd_interface_list = self.relay_interfaces |
| 896 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 897 | config = config, |
| 898 | options = options, |
| 899 | subnet = subnet) |
| 900 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 901 | |
| 902 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 903 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 904 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 905 | assert_not_equal(cip,None) |
| 906 | self.dhcp.send_different_option = 'router' |
| 907 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 908 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 909 | log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 910 | |
| 911 | |
| 912 | def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'): |
| 913 | mac = self.get_mac(iface) |
| 914 | self.host_load(iface) |
| 915 | ##we use the defaults for this test that serves as an example for others |
| 916 | ##You don't need to restart dhcpd server if retaining default config |
| 917 | config = self.default_config |
| 918 | options = self.default_options |
| 919 | subnet = self.default_subnet_config |
| 920 | dhcpd_interface_list = self.relay_interfaces |
| 921 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 922 | config = config, |
| 923 | options = options, |
| 924 | subnet = subnet) |
| 925 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 926 | expected_broadcast_address = '192.168.1.255' |
| 927 | self.dhcp.return_option = 'broadcast_address' |
| 928 | |
| 929 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 930 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 931 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 932 | assert_equal(expected_broadcast_address, broadcast_address_value) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 933 | log_test.info('broadcast address in server offer packet is same as configured broadcast address in dhcp server') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 934 | |
| 935 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'): |
| 936 | mac = self.get_mac(iface) |
| 937 | self.host_load(iface) |
| 938 | ##we use the defaults for this test that serves as an example for others |
| 939 | ##You don't need to restart dhcpd server if retaining default config |
| 940 | config = self.default_config |
| 941 | options = self.default_options |
| 942 | subnet = self.default_subnet_config |
| 943 | dhcpd_interface_list = self.relay_interfaces |
| 944 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 945 | config = config, |
| 946 | options = options, |
| 947 | subnet = subnet) |
| 948 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 949 | |
| 950 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 951 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 952 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 953 | assert_not_equal(cip,None) |
| 954 | self.dhcp.send_different_option = 'broadcast_address' |
| 955 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 956 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 957 | log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 958 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 959 | |
| 960 | def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'): |
| 961 | mac = self.get_mac(iface) |
| 962 | self.host_load(iface) |
| 963 | ##we use the defaults for this test that serves as an example for others |
| 964 | ##You don't need to restart dhcpd server if retaining default config |
| 965 | config = self.default_config |
| 966 | options = self.default_options |
| 967 | subnet = self.default_subnet_config |
| 968 | dhcpd_interface_list = self.relay_interfaces |
| 969 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 970 | config = config, |
| 971 | options = options, |
| 972 | subnet = subnet) |
| 973 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 974 | expected_dns_address = '192.168.1.1' |
| 975 | self.dhcp.return_option = 'dns' |
| 976 | |
| 977 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 978 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 979 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 980 | assert_equal(expected_dns_address, dns_address_value) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 981 | log_test.info('dns address in server offer packet is same as configured dns address in dhcp server') |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 982 | |
| 983 | def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'): |
| 984 | mac = self.get_mac(iface) |
| 985 | self.host_load(iface) |
| 986 | ##we use the defaults for this test that serves as an example for others |
| 987 | ##You don't need to restart dhcpd server if retaining default config |
| 988 | config = self.default_config |
| 989 | options = self.default_options |
| 990 | subnet = self.default_subnet_config |
| 991 | dhcpd_interface_list = self.relay_interfaces |
| 992 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 993 | config = config, |
| 994 | options = options, |
| 995 | subnet = subnet) |
| 996 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 997 | |
| 998 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 999 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1000 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 1001 | assert_not_equal(cip,None) |
| 1002 | self.dhcp.send_different_option = 'dns' |
| 1003 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1004 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1005 | log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1006 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1007 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1008 | def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1009 | |
| 1010 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1011 | self.stats() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1012 | log_test.info("Statistics for run %d",i) |
| 1013 | log_test.info("----------------------------------------------------------------------------------") |
| 1014 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1015 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1016 | log_test.info("----------------------------------------------------------------------------------") |
| 1017 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1018 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1019 | log_test.info("Final Statistics for total transactions") |
| 1020 | log_test.info("----------------------------------------------------------------------------------") |
| 1021 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1022 | log_test.info(" %d %d %d %d" %(self.transactions, |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1023 | self.total_success, self.total_failure, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1024 | log_test.info("----------------------------------------------------------------------------------") |
| 1025 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1026 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1027 | def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1028 | |
| 1029 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1030 | self.stats(success_rate = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1031 | log_test.info("Statistics for run %d",i) |
| 1032 | log_test.info("----------------------------------------------------------------------------------") |
| 1033 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1034 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1035 | log_test.info("----------------------------------------------------------------------------------") |
| 1036 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1037 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1038 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1039 | log_test.info("Final Statistics for total successful transactions") |
| 1040 | log_test.info("----------------------------------------------------------------------------------") |
| 1041 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1042 | log_test.info(" %d %d %d " %(self.transactions, |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1043 | self.total_success, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1044 | log_test.info("----------------------------------------------------------------------------------") |
| 1045 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 1046 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1047 | |
| 1048 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1049 | def test_dhcpRelay_clients_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1050 | |
| 1051 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1052 | self.stats(only_discover = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1053 | log_test.info("----------------------------------------------------------------------------------") |
| 1054 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1055 | log_test.info("----------------------------------------------------------------------------------") |
| 1056 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1057 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1058 | log_test.info("----------------------------------------------------------------------------------") |
| 1059 | log_test.info("No. of clients per second in run %d:%f " |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1060 | %(i, self.transaction_count)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1061 | log_test.info("----------------------------------------------------------------------------------") |
| 1062 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1063 | log_test.info("----------------------------------------------------------------------------------") |
| 1064 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1065 | log_test.info(" %d %d %d %d" %(self.transactions, |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1066 | self.total_success, self.total_failure, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1067 | log_test.info("----------------------------------------------------------------------------------") |
| 1068 | log_test.info("Average no. of clients per second: %d ", |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1069 | round(self.transactions/self.running_time,0)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1070 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1071 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1072 | def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1073 | |
| 1074 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1075 | self.stats(success_rate = True, only_discover = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1076 | log_test.info("----------------------------------------------------------------------------------") |
| 1077 | log_test.info("Statistics for run %d for sending only DHCP Discover",i) |
| 1078 | log_test.info("----------------------------------------------------------------------------------") |
| 1079 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1080 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1081 | log_test.info("----------------------------------------------------------------------------------") |
| 1082 | log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 1083 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1084 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1085 | log_test.info("Final Statistics for total successful transactions") |
| 1086 | log_test.info("----------------------------------------------------------------------------------") |
| 1087 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1088 | log_test.info(" %d %d %d " %(self.transactions, |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1089 | self.total_success, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1090 | log_test.info("----------------------------------------------------------------------------------") |
| 1091 | log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 1092 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1093 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1094 | def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'): |
| 1095 | |
| 1096 | config = self.default_config |
| 1097 | options = self.default_options |
| 1098 | subnet = [ ('192.168.1.2', |
| 1099 | ''' |
| 1100 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1101 | range 192.168.1.10 192.168.2.100; |
| 1102 | } |
| 1103 | '''), ] |
| 1104 | |
| 1105 | dhcpd_interface_list = self.relay_interfaces |
| 1106 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1107 | config = config, |
| 1108 | options = options, |
| 1109 | subnet = subnet) |
| 1110 | |
| 1111 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1112 | self.host_load(g_subscriber_port_map[key]) |
| 1113 | |
| 1114 | def thread_fun(i): |
| 1115 | mac = self.get_mac('veth{}'.format(i)) |
| 1116 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1117 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1118 | self.lock.acquire() |
| 1119 | |
| 1120 | if cip: |
| 1121 | self.ip_count += 1 |
| 1122 | |
| 1123 | elif cip is None: |
| 1124 | self.failure_count += 1 |
| 1125 | |
| 1126 | self.lock.notify_all() |
| 1127 | self.lock.release() |
| 1128 | |
| 1129 | for i in range (1,4): |
| 1130 | self.ip_count = 0 |
| 1131 | self.failure_count = 0 |
| 1132 | self.start_time = 0 |
| 1133 | self.diff = 0 |
| 1134 | self.transaction_count = 0 |
| 1135 | self.start_time = time.time() |
| 1136 | |
| 1137 | while self.diff <= 60: |
| 1138 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1139 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1140 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1141 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1142 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1143 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1144 | |
| 1145 | t.start() |
| 1146 | t1.start() |
| 1147 | t2.start() |
| 1148 | t3.start() |
| 1149 | t4.start() |
| 1150 | t5.start() |
| 1151 | |
| 1152 | t.join() |
| 1153 | t1.join() |
| 1154 | t2.join() |
| 1155 | t3.join() |
| 1156 | t4.join() |
| 1157 | t5.join() |
| 1158 | |
| 1159 | self.diff = round(time.time() - self.start_time, 0) |
| 1160 | |
| 1161 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1162 | |
| 1163 | self.transactions += (self.ip_count+self.failure_count) |
| 1164 | self.running_time += self.diff |
| 1165 | self.total_success += self.ip_count |
| 1166 | self.total_failure += self.failure_count |
| 1167 | |
| 1168 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1169 | log_test.info("----------------------------------------------------------------------------------") |
| 1170 | log_test.info("Statistics for run %d",i) |
| 1171 | log_test.info("----------------------------------------------------------------------------------") |
| 1172 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1173 | log_test.info(" %d %d %d %d" |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1174 | %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1175 | log_test.info("----------------------------------------------------------------------------------") |
| 1176 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1177 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1178 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1179 | log_test.info("----------------------------------------------------------------------------------") |
| 1180 | log_test.info("Final Statistics for total transactions") |
| 1181 | log_test.info("----------------------------------------------------------------------------------") |
| 1182 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1183 | log_test.info(" %d %d %d %d" %(self.transactions, |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1184 | self.total_success, self.total_failure, self.running_time)) |
| 1185 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1186 | log_test.info("----------------------------------------------------------------------------------") |
| 1187 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 1188 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1189 | |
| 1190 | def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'): |
| 1191 | |
| 1192 | config = self.default_config |
| 1193 | options = self.default_options |
| 1194 | subnet = [ ('192.168.1.2', |
| 1195 | ''' |
| 1196 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1197 | range 192.168.1.10 192.168.2.100; |
| 1198 | } |
| 1199 | '''), ] |
| 1200 | |
| 1201 | dhcpd_interface_list = self.relay_interfaces |
| 1202 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1203 | config = config, |
| 1204 | options = options, |
| 1205 | subnet = subnet) |
| 1206 | failure_dir = {} |
| 1207 | |
| 1208 | for key in (key for key in g_subscriber_port_map if key != 100): |
| 1209 | self.host_load(g_subscriber_port_map[key]) |
| 1210 | |
| 1211 | def thread_fun(i, j): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1212 | # log_test.info("Thread Name:%s",current_thread().name) |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1213 | # failure_dir[current_thread().name] = True |
| 1214 | while failure_dir.has_key(current_thread().name) is False: |
| 1215 | mac = RandMAC()._fix() |
| 1216 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 1217 | i += 2 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1218 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1219 | self.lock.acquire() |
| 1220 | |
| 1221 | if cip: |
| 1222 | self.ip_count += 1 |
| 1223 | self.lock.notify_all() |
| 1224 | self.lock.release() |
| 1225 | elif cip is None: |
| 1226 | self.failure_count += 1 |
| 1227 | failure_dir[current_thread().name] = True |
| 1228 | self.lock.notify_all() |
| 1229 | self.lock.release() |
| 1230 | break |
| 1231 | # self.lock.notify_all() |
| 1232 | # self.lock.release() |
| 1233 | |
| 1234 | for i in range (1,4): |
| 1235 | failure_dir = {} |
| 1236 | self.ip_count = 0 |
| 1237 | self.failure_count = 0 |
| 1238 | self.start_time = 0 |
| 1239 | self.diff = 0 |
| 1240 | self.transaction_count = 0 |
| 1241 | self.start_time = time.time() |
| 1242 | |
| 1243 | while len(failure_dir) != 6: |
| 1244 | t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1245 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1246 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1247 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1248 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1249 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1250 | |
| 1251 | t.start() |
| 1252 | t1.start() |
| 1253 | t2.start() |
| 1254 | t3.start() |
| 1255 | t4.start() |
| 1256 | t5.start() |
| 1257 | |
| 1258 | t.join() |
| 1259 | t1.join() |
| 1260 | t2.join() |
| 1261 | t3.join() |
| 1262 | t4.join() |
| 1263 | t5.join() |
| 1264 | |
| 1265 | self.diff = round(time.time() - self.start_time, 0) |
| 1266 | self.transaction_count = round((self.ip_count)/self.diff, 2) |
| 1267 | |
| 1268 | self.transactions += (self.ip_count+self.failure_count) |
| 1269 | self.running_time += self.diff |
| 1270 | self.total_success += self.ip_count |
| 1271 | self.total_failure += self.failure_count |
| 1272 | |
| 1273 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1274 | log_test.info("Statistics for run %d",i) |
| 1275 | log_test.info("----------------------------------------------------------------------------------") |
| 1276 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 1277 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 1278 | log_test.info("----------------------------------------------------------------------------------") |
| 1279 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1280 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1281 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1282 | log_test.info("Final Statistics for total successful transactions") |
| 1283 | log_test.info("----------------------------------------------------------------------------------") |
| 1284 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1285 | log_test.info(" %d %d %d " %(self.transactions, |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1286 | self.total_success, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1287 | log_test.info("----------------------------------------------------------------------------------") |
| 1288 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2)) |
| 1289 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1290 | |
| 1291 | def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'): |
| 1292 | |
| 1293 | config = self.default_config |
| 1294 | options = self.default_options |
| 1295 | subnet = [ ('192.168.1.2', |
| 1296 | ''' |
| 1297 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1298 | range 192.168.1.10 192.168.2.100; |
| 1299 | } |
| 1300 | '''), ] |
| 1301 | |
| 1302 | dhcpd_interface_list = self.relay_interfaces |
| 1303 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1304 | config = config, |
| 1305 | options = options, |
| 1306 | subnet = subnet) |
| 1307 | |
| 1308 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1309 | self.host_load(g_subscriber_port_map[key]) |
| 1310 | |
| 1311 | def thread_fun(i): |
| 1312 | # mac = self.get_mac('veth{}'.format(i)) |
| 1313 | cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix()) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1314 | log_test.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1315 | self.lock.acquire() |
| 1316 | |
| 1317 | if cip: |
| 1318 | self.ip_count += 1 |
| 1319 | elif cip is None: |
| 1320 | self.failure_count += 1 |
| 1321 | |
| 1322 | self.lock.notify_all() |
| 1323 | self.lock.release() |
| 1324 | |
| 1325 | for i in range (1,4): |
| 1326 | self.ip_count = 0 |
| 1327 | self.failure_count = 0 |
| 1328 | self.start_time = 0 |
| 1329 | self.diff = 0 |
| 1330 | self.transaction_count = 0 |
| 1331 | self.start_time = time.time() |
| 1332 | |
| 1333 | while self.diff <= 60: |
| 1334 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1335 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1336 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1337 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1338 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1339 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1340 | |
| 1341 | t.start() |
| 1342 | t1.start() |
| 1343 | t2.start() |
| 1344 | t3.start() |
| 1345 | t4.start() |
| 1346 | t5.start() |
| 1347 | |
| 1348 | t.join() |
| 1349 | t1.join() |
| 1350 | t2.join() |
| 1351 | t3.join() |
| 1352 | t4.join() |
| 1353 | t5.join() |
| 1354 | |
| 1355 | self.diff = round(time.time() - self.start_time, 0) |
| 1356 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1357 | self.transactions += (self.ip_count+self.failure_count) |
| 1358 | self.running_time += self.diff |
| 1359 | self.total_success += self.ip_count |
| 1360 | self.total_failure += self.failure_count |
| 1361 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1362 | log_test.info("----------------------------------------------------------------------------------") |
| 1363 | log_test.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1364 | log_test.info("----------------------------------------------------------------------------------") |
| 1365 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1366 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1367 | log_test.info("----------------------------------------------------------------------------------") |
| 1368 | log_test.info("No. of clients per second in run %d:%f " |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1369 | %(i, self.transaction_count)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1370 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1371 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1372 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1373 | log_test.info("----------------------------------------------------------------------------------") |
| 1374 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1375 | log_test.info(" %d %d %d %d" %(self.transactions, |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1376 | self.total_success, self.total_failure, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1377 | log_test.info("----------------------------------------------------------------------------------") |
| 1378 | log_test.info("Average no. of clients per second: %d ", |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1379 | round(self.transactions/self.running_time,0)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1380 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1381 | |
| 1382 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1383 | def test_dhcpRelay_client_conflict(self, iface = 'veth0'): |
| 1384 | mac = self.get_mac(iface) |
| 1385 | self.host_load(iface) |
| 1386 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1387 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1388 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1389 | (cip, sip, mac) ) |
| 1390 | self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface) |
| 1391 | new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True) |
| 1392 | new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1393 | log_test.info('Got dhcp client IP %s from server %s for mac %s.' % |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1394 | (new_cip, new_sip, new_mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1395 | log_test.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac)) |
| 1396 | log_test.info("Now sending DHCP Request for old DHCP discover.") |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1397 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1398 | if new_cip is None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1399 | log_test.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.' |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1400 | %(new_cip, new_sip, new_mac) ) |
| 1401 | elif new_cip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1402 | 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.' |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1403 | %(new_cip, new_sip, new_mac, new_cip) ) |
| 1404 | assert_equal(new_cip, None) |