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