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, |
| 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 | 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: |
| 302 | cip, sip = self.send_recv(mac, update_seed = True, validate = False) |
| 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 | |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 320 | def send_recv(self, mac, update_seed = False, validate = True): |
| 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) |
| 343 | self.send_recv(mac) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 344 | |
| 345 | def test_dhcpRelay_Nrequest(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 = '192.169.1.1', iface = iface) |
| 359 | ip_map = {} |
| 360 | for i in range(10): |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 361 | mac = RandMAC()._fix() |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 362 | cip, sip = self.send_recv(mac, update_seed = True) |
| 363 | if ip_map.has_key(cip): |
| 364 | log.info('IP %s given out multiple times' %cip) |
| 365 | assert_equal(False, ip_map.has_key(cip)) |
| 366 | ip_map[cip] = sip |
| 367 | |
| 368 | def test_dhcpRelay_1release(self, iface = 'veth0'): |
| 369 | mac = self.get_mac(iface) |
| 370 | self.host_load(iface) |
| 371 | ##we use the defaults for this test that serves as an example for others |
| 372 | ##You don't need to restart dhcpd server if retaining default config |
| 373 | config = self.default_config |
| 374 | options = self.default_options |
| 375 | subnet = self.default_subnet_config |
| 376 | dhcpd_interface_list = self.relay_interfaces |
| 377 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 378 | config = config, |
| 379 | options = options, |
| 380 | subnet = subnet) |
| 381 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
| 382 | cip, sip = self.send_recv(mac) |
| 383 | log.info('Releasing ip %s to server %s' %(cip, sip)) |
| 384 | assert_equal(self.dhcp.release(cip), True) |
| 385 | log.info('Triggering DHCP discover again after release') |
| 386 | cip2, sip2 = self.send_recv(mac) |
| 387 | log.info('Verifying released IP was given back on rediscover') |
| 388 | assert_equal(cip, cip2) |
| 389 | log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 390 | assert_equal(self.dhcp.release(cip2), True) |
| 391 | |
| 392 | def test_dhcpRelay_Nrelease(self, iface = 'veth0'): |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 393 | mac = None |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 394 | self.host_load(iface) |
| 395 | ##we use the defaults for this test that serves as an example for others |
| 396 | ##You don't need to restart dhcpd server if retaining default config |
| 397 | config = self.default_config |
| 398 | options = self.default_options |
| 399 | subnet = self.default_subnet_config |
| 400 | dhcpd_interface_list = self.relay_interfaces |
| 401 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 402 | config = config, |
| 403 | options = options, |
| 404 | subnet = subnet) |
| 405 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 406 | ip_map = {} |
| 407 | for i in range(10): |
| 408 | cip, sip = self.send_recv(mac, update_seed = True) |
| 409 | if ip_map.has_key(cip): |
| 410 | log.info('IP %s given out multiple times' %cip) |
| 411 | assert_equal(False, ip_map.has_key(cip)) |
| 412 | ip_map[cip] = sip |
| 413 | |
| 414 | for ip in ip_map.keys(): |
| 415 | log.info('Releasing IP %s' %ip) |
| 416 | assert_equal(self.dhcp.release(ip), True) |
| 417 | |
| 418 | ip_map2 = {} |
| 419 | log.info('Triggering DHCP discover again after release') |
| 420 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
| 421 | for i in range(len(ip_map.keys())): |
| 422 | cip, sip = self.send_recv(mac, update_seed = True) |
| 423 | ip_map2[cip] = sip |
| 424 | |
| 425 | log.info('Verifying released IPs were given back on rediscover') |
| 426 | if ip_map != ip_map2: |
| 427 | log.info('Map before release %s' %ip_map) |
| 428 | log.info('Map after release %s' %ip_map2) |
| 429 | assert_equal(ip_map, ip_map2) |
| 430 | |
| 431 | def test_dhcpRelay_starvation(self, iface = 'veth0'): |
| 432 | mac = self.get_mac(iface) |
| 433 | self.host_load(iface) |
| 434 | ##we use the defaults for this test that serves as an example for others |
| 435 | ##You don't need to restart dhcpd server if retaining default config |
| 436 | config = self.default_config |
| 437 | options = self.default_options |
| 438 | subnet = self.default_subnet_config |
| 439 | dhcpd_interface_list = self.relay_interfaces |
| 440 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 441 | config = config, |
| 442 | options = options, |
| 443 | subnet = subnet) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 444 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 445 | log.info('Verifying 1 ') |
| 446 | while True: |
| 447 | mac = RandMAC()._fix() |
| 448 | cip, sip = self.send_recv(mac = mac, validate = False) |
| 449 | if cip is None: |
| 450 | break |
| 451 | log.info('Verifying 2 ') |
| 452 | cip, sip = self.send_recv(mac, update_seed = True, validate = False) |
| 453 | assert_equal(cip, None) |
| 454 | assert_equal(sip, None) |
| 455 | |
| 456 | def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'): |
| 457 | mac = self.get_mac(iface) |
| 458 | self.host_load(iface) |
| 459 | ##we use the defaults for this test that serves as an example for others |
| 460 | ##You don't need to restart dhcpd server if retaining default config |
| 461 | config = self.default_config |
| 462 | options = self.default_options |
| 463 | subnet = self.default_subnet_config |
| 464 | dhcpd_interface_list = self.relay_interfaces |
| 465 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 466 | config = config, |
| 467 | options = options, |
| 468 | subnet = subnet) |
| 469 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 470 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 471 | log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
| 472 | (cip, sip, mac) ) |
| 473 | log.info('Triggering DHCP discover again.') |
| 474 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
| 475 | if cip == new_cip: |
| 476 | log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. ' |
| 477 | % (new_cip, new_sip, new_mac) ) |
| 478 | elif cip != new_cip: |
| 479 | log.info('Ip after 1st discover %s' %cip) |
| 480 | log.info('Map after 2nd discover %s' %new_cip) |
| 481 | assert_equal(cip, new_cip) |
| 482 | |
| 483 | |
| 484 | def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'): |
| 485 | mac = self.get_mac(iface) |
| 486 | self.host_load(iface) |
| 487 | ##we use the defaults for this test that serves as an example for others |
| 488 | ##You don't need to restart dhcpd server if retaining default config |
| 489 | config = self.default_config |
| 490 | options = self.default_options |
| 491 | subnet = self.default_subnet_config |
| 492 | dhcpd_interface_list = self.relay_interfaces |
| 493 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 494 | config = config, |
| 495 | options = options, |
| 496 | subnet = subnet) |
| 497 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 498 | log.info('Sending DHCP discover and DHCP request.') |
| 499 | cip, sip = self.send_recv(mac) |
| 500 | mac = self.dhcp.get_mac(cip)[0] |
| 501 | log.info("Sending DHCP request again.") |
| 502 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 503 | if (new_cip,new_sip) == (cip,sip): |
| 504 | log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.' |
| 505 | % (new_cip, new_sip, mac) ) |
| 506 | elif (new_cip,new_sip): |
| 507 | log.info('No DHCP ACK') |
| 508 | assert_equal(new_cip, None) |
| 509 | assert_equal(new_sip, None) |
| 510 | else: |
| 511 | log.info('Something went wrong.') |
| 512 | |
| 513 | def test_dhcpRelay_client_desired_address(self, iface = 'veth0'): |
| 514 | mac = self.get_mac(iface) |
| 515 | self.host_load(iface) |
| 516 | ##we use the defaults for this test that serves as an example for others |
| 517 | ##You don't need to restart dhcpd server if retaining default config |
| 518 | config = self.default_config |
| 519 | options = self.default_options |
| 520 | subnet = self.default_subnet_config |
| 521 | dhcpd_interface_list = self.relay_interfaces |
| 522 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 523 | config = config, |
| 524 | options = options, |
| 525 | subnet = subnet) |
| 526 | self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface) |
| 527 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 528 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 529 | (cip, sip, mac) ) |
| 530 | if cip == self.dhcp.seed_ip: |
| 531 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 532 | (cip, sip, mac) ) |
| 533 | elif cip != self.dhcp.seed_ip: |
| 534 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 535 | (cip, sip, mac) ) |
| 536 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 537 | assert_equal(cip, self.dhcp.seed_ip) |
| 538 | |
| 539 | def test_dhcpRelay_client_desired_address_out_of_pool(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 = '20.20.20.35', iface = iface) |
| 553 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 554 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 555 | (cip, sip, mac) ) |
| 556 | if cip == self.dhcp.seed_ip: |
| 557 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 558 | (cip, sip, mac) ) |
| 559 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
| 560 | elif cip != self.dhcp.seed_ip: |
| 561 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 562 | (cip, sip, mac) ) |
| 563 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 564 | assert_not_equal(cip, self.dhcp.seed_ip) |
| 565 | elif cip == None: |
| 566 | log.info('Got DHCP NAK') |
| 567 | |
| 568 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 569 | def test_dhcpRelay_nak_packet(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 570 | mac = self.get_mac(iface) |
| 571 | self.host_load(iface) |
| 572 | ##we use the defaults for this test that serves as an example for others |
| 573 | ##You don't need to restart dhcpd server if retaining default config |
| 574 | config = self.default_config |
| 575 | options = self.default_options |
| 576 | subnet = self.default_subnet_config |
| 577 | dhcpd_interface_list = self.relay_interfaces |
| 578 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 579 | config = config, |
| 580 | options = options, |
| 581 | subnet = subnet) |
| 582 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 583 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 584 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 585 | (cip, sip, mac) ) |
| 586 | |
| 587 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 588 | if (cip == None and mac != None): |
| 589 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 590 | assert_not_equal(cip, None) |
| 591 | else: |
| 592 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 593 | if new_cip == None: |
| 594 | |
| 595 | log.info("Got DHCP server NAK.") |
| 596 | assert_equal(new_cip, None) #Negative Test Case |
| 597 | |
| 598 | |
| 599 | def test_dhcpRelay_specific_lease_packet(self, iface = 'veth0'): |
| 600 | mac = self.get_mac(iface) |
| 601 | self.host_load(iface) |
| 602 | ##we use the defaults for this test that serves as an example for others |
| 603 | ##You don't need to restart dhcpd server if retaining default config |
| 604 | config = self.default_config |
| 605 | options = self.default_options |
| 606 | subnet = self.default_subnet_config |
| 607 | dhcpd_interface_list = self.relay_interfaces |
| 608 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 609 | config = config, |
| 610 | options = options, |
| 611 | subnet = subnet) |
| 612 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 613 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 614 | |
| 615 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 616 | if (cip == None and mac != None): |
| 617 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 618 | assert_not_equal(cip, None) |
| 619 | elif cip != None: |
| 620 | self.dhcp.specific_lease = 800 |
| 621 | log.info('Sending DHCP request with specific lease time of %s', self.dhcp.specific_lease) |
| 622 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac) |
| 623 | if new_cip == None: |
| 624 | |
| 625 | log.info("Got DHCP server NAK.") |
| 626 | assert_equal(new_cip, None) #Negative Test Case |
| 627 | assert_equal(lval, self.dhcp.specific_lease) |
| 628 | |
| 629 | def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'): |
| 630 | mac = self.get_mac(iface) |
| 631 | self.host_load(iface) |
| 632 | ##we use the defaults for this test that serves as an example for others |
| 633 | ##You don't need to restart dhcpd server if retaining default config |
| 634 | config = self.default_config |
| 635 | options = self.default_options |
| 636 | subnet = self.default_subnet_config |
| 637 | dhcpd_interface_list = self.relay_interfaces |
| 638 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 639 | config = config, |
| 640 | options = options, |
| 641 | subnet = subnet) |
| 642 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 643 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 644 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 645 | (cip, sip, mac) ) |
| 646 | |
| 647 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 648 | |
| 649 | if (cip == None and mac != None): |
| 650 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 651 | assert_not_equal(cip, None) |
| 652 | |
| 653 | else: |
| 654 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 655 | if new_cip == None: |
| 656 | log.info("Got DHCP server NAK.") |
| 657 | os.system('ifconfig '+iface+' down') |
| 658 | log.info('Client goes down.') |
| 659 | log.info('Delay for 5 seconds.') |
| 660 | |
| 661 | time.sleep(5) |
| 662 | |
| 663 | os.system('ifconfig '+iface+' up') |
| 664 | log.info('Client is up now.') |
| 665 | |
| 666 | new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
| 667 | if new_cip == None: |
| 668 | log.info("Got DHCP server NAK.") |
| 669 | assert_not_equal(new_cip, None) |
| 670 | elif new_cip != None: |
| 671 | log.info("Got DHCP ACK.") |
| 672 | os.system('ifconfig '+iface+' up') |
| 673 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 674 | def test_dhcpRelay_after_reboot(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 675 | mac = self.get_mac(iface) |
| 676 | self.host_load(iface) |
| 677 | ##we use the defaults for this test that serves as an example for others |
| 678 | ##You don't need to restart dhcpd server if retaining default config |
| 679 | config = self.default_config |
| 680 | options = self.default_options |
| 681 | subnet = self.default_subnet_config |
| 682 | dhcpd_interface_list = self.relay_interfaces |
| 683 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 684 | config = config, |
| 685 | options = options, |
| 686 | subnet = subnet) |
| 687 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 688 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 689 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 690 | (cip, sip, mac) ) |
| 691 | |
| 692 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 693 | |
| 694 | if (cip == None and mac != None): |
| 695 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 696 | assert_not_equal(cip, None) |
| 697 | |
| 698 | else: |
| 699 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 700 | if new_cip == None: |
| 701 | log.info("Got DHCP server NAK.") |
| 702 | assert_not_equal(new_cip, None) |
| 703 | log.info('Getting DHCP server Down.') |
| 704 | |
| 705 | self.tearDownClass() |
| 706 | |
| 707 | for i in range(0,4): |
| 708 | log.info("Sending DHCP Request.") |
| 709 | log.info('') |
| 710 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 711 | if new_cip == None and new_sip == None: |
| 712 | log.info('') |
| 713 | log.info("DHCP Request timed out.") |
| 714 | elif new_cip and new_sip: |
| 715 | log.info("Got Reply from DHCP server.") |
| 716 | assert_equal(new_cip,None) #Neagtive Test Case |
| 717 | |
| 718 | log.info('Getting DHCP server Up.') |
| 719 | |
| 720 | self.setUpClass() |
| 721 | |
| 722 | for i in range(0,4): |
| 723 | log.info("Sending DHCP Request after DHCP server is up.") |
| 724 | log.info('') |
| 725 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 726 | if new_cip == None and new_sip == None: |
| 727 | log.info('') |
| 728 | log.info("DHCP Request timed out.") |
| 729 | elif new_cip and new_sip: |
| 730 | log.info("Got Reply from DHCP server.") |
| 731 | assert_equal(new_cip, cip) |
| 732 | |
| 733 | |
| 734 | def test_dhcpRelay_specific_lease_packet_in_dhcp_discover(self, iface = 'veth0'): |
| 735 | mac = self.get_mac(iface) |
| 736 | self.host_load(iface) |
| 737 | ##we use the defaults for this test that serves as an example for others |
| 738 | ##You don't need to restart dhcpd server if retaining default config |
| 739 | config = self.default_config |
| 740 | options = self.default_options |
| 741 | subnet = self.default_subnet_config |
| 742 | dhcpd_interface_list = self.relay_interfaces |
| 743 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 744 | config = config, |
| 745 | options = options, |
| 746 | subnet = subnet) |
| 747 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 748 | log.info('Sending DHCP discover with lease time of 700') |
| 749 | cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True) |
| 750 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 751 | (cip, sip, mac) ) |
| 752 | |
| 753 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 754 | if (cip == None and mac != None): |
| 755 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 756 | assert_not_equal(cip, None) |
| 757 | elif cip and sip and mac: |
| 758 | |
| 759 | log.info("Triggering DHCP Request.") |
| 760 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 761 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
| 762 | (new_cip, new_sip, mac, lval) ) |
| 763 | assert_not_equal(lval, 700) #Negative Test Case |
| 764 | |
| 765 | |
| 766 | |
| 767 | def test_dhcpRelay_default_lease_time(self, iface = 'veth0'): |
| 768 | mac = self.get_mac(iface) |
| 769 | self.host_load(iface) |
| 770 | ##we use the defaults for this test that serves as an example for others |
| 771 | ##You don't need to restart dhcpd server if retaining default config |
| 772 | config = self.default_config |
| 773 | options = self.default_options |
| 774 | subnet = self.default_subnet_config |
| 775 | dhcpd_interface_list = self.relay_interfaces |
| 776 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 777 | config = config, |
| 778 | options = options, |
| 779 | subnet = subnet) |
| 780 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 781 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 782 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 783 | (cip, sip, mac) ) |
| 784 | |
| 785 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 786 | if (cip == None and mac != None): |
| 787 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 788 | assert_not_equal(cip, None) |
| 789 | |
| 790 | elif cip and sip and mac: |
| 791 | |
| 792 | log.info("Triggering DHCP Request.") |
| 793 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 794 | if lval == 600: |
| 795 | log.info('Getting dhcp client IP %s from server %s for mac %s with defualt lease time %s.' % |
| 796 | (new_cip, new_sip, mac, lval) ) |
| 797 | else: |
| 798 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' % |
| 799 | (new_cip, new_sip, mac, lval) ) |
| 800 | log.info('The lease time suppossed to be 600 secs or 10 mins.') |
| 801 | assert_equal(lval, 600) |
| 802 | |
| 803 | def test_dhcpRelay_client_renew_time(self, iface = 'veth0'): |
| 804 | mac = self.get_mac(iface) |
| 805 | self.host_load(iface) |
| 806 | ##we use the defaults for this test that serves as an example for others |
| 807 | ##You don't need to restart dhcpd server if retaining default config |
| 808 | config = self.default_config |
| 809 | new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)] |
| 810 | options = self.default_options + new_options |
| 811 | subnet = self.default_subnet_config |
| 812 | dhcpd_interface_list = self.relay_interfaces |
| 813 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 814 | config = config, |
| 815 | options = options, |
| 816 | subnet = subnet) |
| 817 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 818 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 819 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 820 | (cip, sip, mac) ) |
| 821 | |
| 822 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 823 | if (cip == None and mac != None): |
| 824 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 825 | assert_not_equal(cip, None) |
| 826 | |
| 827 | elif cip and sip and mac: |
| 828 | |
| 829 | log.info("Triggering DHCP Request.") |
| 830 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 831 | |
| 832 | if new_cip and new_sip and lval: |
| 833 | |
| 834 | log.info("Clinet 's Renewal time is :%s",lval) |
| 835 | log.info("Generating delay till renewal time.") |
| 836 | time.sleep(lval) |
| 837 | |
| 838 | log.info("Client Sending Unicast DHCP request.") |
| 839 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 840 | |
| 841 | if latest_cip and latest_sip: |
| 842 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 843 | (latest_cip, mac, latest_sip) ) |
| 844 | |
| 845 | elif latest_cip == None: |
| 846 | log.info("Got DHCP NAK. Lease not renewed.") |
| 847 | |
| 848 | elif new_cip == None or new_sip == None or lval == None: |
| 849 | |
| 850 | log.info("Got DHCP NAK.") |
| 851 | |
| 852 | |
| 853 | |
| 854 | def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'): |
| 855 | mac = self.get_mac(iface) |
| 856 | self.host_load(iface) |
| 857 | ##we use the defaults for this test that serves as an example for others |
| 858 | ##You don't need to restart dhcpd server if retaining default config |
| 859 | config = self.default_config |
| 860 | new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)] |
| 861 | options = self.default_options + new_options |
| 862 | subnet = self.default_subnet_config |
| 863 | dhcpd_interface_list = self.relay_interfaces |
| 864 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 865 | config = config, |
| 866 | options = options, |
| 867 | subnet = subnet) |
| 868 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 869 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 870 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 871 | (cip, sip, mac) ) |
| 872 | |
| 873 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 874 | if (cip == None and mac != None): |
| 875 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 876 | assert_not_equal(cip, None) |
| 877 | |
| 878 | elif cip and sip and mac: |
| 879 | |
| 880 | log.info("Triggering DHCP Request.") |
| 881 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 882 | |
| 883 | if new_cip and new_sip and lval: |
| 884 | |
| 885 | log.info("Clinet 's Rebind time is :%s",lval) |
| 886 | log.info("Generating delay till rebind time.") |
| 887 | time.sleep(lval) |
| 888 | |
| 889 | log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.") |
| 890 | |
| 891 | for i in range(0,4): |
| 892 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 893 | |
| 894 | if latest_cip and latest_sip: |
| 895 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 896 | (latest_cip, mac, latest_sip) ) |
| 897 | break |
| 898 | |
| 899 | elif latest_cip == None: |
| 900 | log.info("Got DHCP NAK. Lease not renewed.") |
| 901 | assert_not_equal(latest_cip, None) |
| 902 | elif new_cip == None or new_sip == None or lval == None: |
| 903 | |
| 904 | log.info("Got DHCP NAK.Lease not Renewed.") |
| 905 | |
| 906 | |
| 907 | def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'): |
| 908 | mac = self.get_mac(iface) |
| 909 | self.host_load(iface) |
| 910 | ##we use the defaults for this test that serves as an example for others |
| 911 | ##You don't need to restart dhcpd server if retaining default config |
| 912 | config = self.default_config |
| 913 | options = self.default_options |
| 914 | subnet = self.default_subnet_config |
| 915 | dhcpd_interface_list = self.relay_interfaces |
| 916 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 917 | config = config, |
| 918 | options = options, |
| 919 | subnet = subnet) |
| 920 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 921 | expected_subnet = '255.255.255.0' |
| 922 | self.dhcp.return_option = 'subnet' |
| 923 | |
| 924 | cip, sip, mac, subnet_value = self.dhcp.only_discover() |
| 925 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 926 | (cip, sip, mac) ) |
| 927 | |
| 928 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 929 | if (cip == None and mac != None): |
| 930 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 931 | assert_not_equal(cip, None) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 932 | elif cip and sip and mac: |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 933 | if expected_subnet == subnet_value: |
| 934 | log.info("Got same subnet as passed in DHCP server configuration.") |
| 935 | elif expected_subnet != subnet_value: |
| 936 | log.info("Not getting same subnet as passed in DHCP server configuration.") |
| 937 | assert_equal(expected_subnet, subnet_value) |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 938 | |
| 939 | |
| 940 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'): |
| 941 | mac = self.get_mac(iface) |
| 942 | self.host_load(iface) |
| 943 | ##we use the defaults for this test that serves as an example for others |
| 944 | ##You don't need to restart dhcpd server if retaining default config |
| 945 | config = self.default_config |
| 946 | options = self.default_options |
| 947 | subnet = self.default_subnet_config |
| 948 | dhcpd_interface_list = self.relay_interfaces |
| 949 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 950 | config = config, |
| 951 | options = options, |
| 952 | subnet = subnet) |
| 953 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 954 | |
| 955 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 956 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 957 | (cip, sip, mac) ) |
| 958 | |
| 959 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 960 | if (cip == None and mac != None): |
| 961 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 962 | assert_not_equal(cip, None) |
| 963 | |
| 964 | elif cip and sip and mac: |
| 965 | |
| 966 | self.dhcp.send_different_option = 'subnet' |
| 967 | log.info("Sending DHCP Request with wrong subnet mask.") |
| 968 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 969 | if new_cip == None: |
| 970 | |
| 971 | log.info("Got DHCP NAK.") |
| 972 | assert_not_equal(new_cip, None) |
| 973 | |
| 974 | elif new_cip and new_sip: |
| 975 | |
| 976 | log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
| 977 | log.info("Getting subnet mask as per server 's configuration.") |
| 978 | |
| 979 | |
| 980 | def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'): |
| 981 | mac = self.get_mac(iface) |
| 982 | self.host_load(iface) |
| 983 | ##we use the defaults for this test that serves as an example for others |
| 984 | ##You don't need to restart dhcpd server if retaining default config |
| 985 | config = self.default_config |
| 986 | config = self.default_config |
| 987 | new_options = [('routers', '20.20.20.1')] |
| 988 | options = self.default_options + new_options |
| 989 | subnet = self.default_subnet_config |
| 990 | dhcpd_interface_list = self.relay_interfaces |
| 991 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 992 | config = config, |
| 993 | options = options, |
| 994 | subnet = subnet) |
| 995 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 996 | expected_router_address = '20.20.20.1' |
| 997 | self.dhcp.return_option = 'router' |
| 998 | |
| 999 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
| 1000 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1001 | (cip, sip, mac) ) |
| 1002 | |
| 1003 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1004 | if (cip == None and mac != None): |
| 1005 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1006 | assert_not_equal(cip, None) |
| 1007 | |
| 1008 | elif cip and sip and mac: |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1009 | if expected_router_address == router_address_value: |
| 1010 | log.info("Got same router address as passed in DHCP server configuration.") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1011 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1012 | elif expected_router_address != router_address_value: |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1013 | log.info("Not getting same router address as passed in DHCP server configuration.") |
| 1014 | assert_equal(expected_router_address, router_address_value) |
| 1015 | |
| 1016 | |
| 1017 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'): |
| 1018 | mac = self.get_mac(iface) |
| 1019 | self.host_load(iface) |
| 1020 | ##we use the defaults for this test that serves as an example for others |
| 1021 | ##You don't need to restart dhcpd server if retaining default config |
| 1022 | config = self.default_config |
| 1023 | options = self.default_options |
| 1024 | subnet = self.default_subnet_config |
| 1025 | dhcpd_interface_list = self.relay_interfaces |
| 1026 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1027 | config = config, |
| 1028 | options = options, |
| 1029 | subnet = subnet) |
| 1030 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1031 | |
| 1032 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1033 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1034 | (cip, sip, mac) ) |
| 1035 | |
| 1036 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1037 | if (cip == None and mac != None): |
| 1038 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1039 | assert_not_equal(cip, None) |
| 1040 | |
| 1041 | elif cip and sip and mac: |
| 1042 | |
| 1043 | self.dhcp.send_different_option = 'router' |
| 1044 | log.info("Sending DHCP Request with wrong router address.") |
| 1045 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1046 | if new_cip == None: |
| 1047 | |
| 1048 | log.info("Got DHCP NAK.") |
| 1049 | assert_not_equal(new_cip, None) |
| 1050 | |
| 1051 | elif new_cip and new_sip: |
| 1052 | |
| 1053 | log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
| 1054 | log.info("Getting Router Address as per server 's configuration.") |
| 1055 | |
| 1056 | |
| 1057 | def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'): |
| 1058 | mac = self.get_mac(iface) |
| 1059 | self.host_load(iface) |
| 1060 | ##we use the defaults for this test that serves as an example for others |
| 1061 | ##You don't need to restart dhcpd server if retaining default config |
| 1062 | config = self.default_config |
| 1063 | options = self.default_options |
| 1064 | subnet = self.default_subnet_config |
| 1065 | dhcpd_interface_list = self.relay_interfaces |
| 1066 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1067 | config = config, |
| 1068 | options = options, |
| 1069 | subnet = subnet) |
| 1070 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1071 | expected_broadcast_address = '192.168.1.255' |
| 1072 | self.dhcp.return_option = 'broadcast_address' |
| 1073 | |
| 1074 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
| 1075 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1076 | (cip, sip, mac) ) |
| 1077 | |
| 1078 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1079 | if (cip == None and mac != None): |
| 1080 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1081 | assert_not_equal(cip, None) |
| 1082 | |
| 1083 | elif cip and sip and mac: |
| 1084 | |
| 1085 | if expected_broadcast_address == broadcast_address_value: |
| 1086 | log.info("Got same router address as passed in DHCP server configuration.") |
| 1087 | |
| 1088 | elif expected_broadcast_address != broadcast_address_value: |
| 1089 | log.info("Not getting same router address as passed in DHCP server configuration.") |
| 1090 | assert_equal(expected_broadcast_address, broadcast_address_value) |
| 1091 | |
| 1092 | |
| 1093 | def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'): |
| 1094 | mac = self.get_mac(iface) |
| 1095 | self.host_load(iface) |
| 1096 | ##we use the defaults for this test that serves as an example for others |
| 1097 | ##You don't need to restart dhcpd server if retaining default config |
| 1098 | config = self.default_config |
| 1099 | options = self.default_options |
| 1100 | subnet = self.default_subnet_config |
| 1101 | dhcpd_interface_list = self.relay_interfaces |
| 1102 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1103 | config = config, |
| 1104 | options = options, |
| 1105 | subnet = subnet) |
| 1106 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1107 | |
| 1108 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1109 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1110 | (cip, sip, mac) ) |
| 1111 | |
| 1112 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1113 | if (cip == None and mac != None): |
| 1114 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1115 | assert_not_equal(cip, None) |
| 1116 | |
| 1117 | elif cip and sip and mac: |
| 1118 | |
| 1119 | self.dhcp.send_different_option = 'broadcast_address' |
| 1120 | log.info("Sending DHCP Request with wrong broadcast address.") |
| 1121 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1122 | if new_cip == None: |
| 1123 | |
| 1124 | log.info("Got DHCP NAK.") |
| 1125 | assert_not_equal(new_cip, None) |
| 1126 | |
| 1127 | elif new_cip and new_sip: |
| 1128 | |
| 1129 | log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
| 1130 | log.info("Getting Broadcast Address as per server 's configuration.") |
| 1131 | |
| 1132 | def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'): |
| 1133 | mac = self.get_mac(iface) |
| 1134 | self.host_load(iface) |
| 1135 | ##we use the defaults for this test that serves as an example for others |
| 1136 | ##You don't need to restart dhcpd server if retaining default config |
| 1137 | config = self.default_config |
| 1138 | options = self.default_options |
| 1139 | subnet = self.default_subnet_config |
| 1140 | dhcpd_interface_list = self.relay_interfaces |
| 1141 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1142 | config = config, |
| 1143 | options = options, |
| 1144 | subnet = subnet) |
| 1145 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1146 | expected_dns_address = '192.168.1.1' |
| 1147 | self.dhcp.return_option = 'dns' |
| 1148 | |
| 1149 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
| 1150 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1151 | (cip, sip, mac) ) |
| 1152 | |
| 1153 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1154 | if (cip == None and mac != None): |
| 1155 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1156 | assert_not_equal(cip, None) |
| 1157 | |
| 1158 | elif cip and sip and mac: |
| 1159 | |
| 1160 | if expected_dns_address == dns_address_value: |
| 1161 | log.info("Got same DNS address as passed in DHCP server configuration.") |
| 1162 | |
| 1163 | elif expected_dns_address != dns_address_value: |
| 1164 | log.info("Not getting same DNS address as passed in DHCP server configuration.") |
| 1165 | assert_equal(expected_dns_address, dns_address_value) |
| 1166 | |
| 1167 | |
| 1168 | def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'): |
| 1169 | mac = self.get_mac(iface) |
| 1170 | self.host_load(iface) |
| 1171 | ##we use the defaults for this test that serves as an example for others |
| 1172 | ##You don't need to restart dhcpd server if retaining default config |
| 1173 | config = self.default_config |
| 1174 | options = self.default_options |
| 1175 | subnet = self.default_subnet_config |
| 1176 | dhcpd_interface_list = self.relay_interfaces |
| 1177 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1178 | config = config, |
| 1179 | options = options, |
| 1180 | subnet = subnet) |
| 1181 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 1182 | |
| 1183 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1184 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 1185 | (cip, sip, mac) ) |
| 1186 | |
| 1187 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 1188 | if (cip == None and mac != None): |
| 1189 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 1190 | assert_not_equal(cip, None) |
| 1191 | |
| 1192 | elif cip and sip and mac: |
| 1193 | |
| 1194 | self.dhcp.send_different_option = 'dns' |
| 1195 | log.info("Sending DHCP Request with wrong DNS address.") |
| 1196 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1197 | if new_cip == None: |
| 1198 | log.info("Got DHCP NAK.") |
| 1199 | assert_not_equal(new_cip, None) |
| 1200 | elif new_cip and new_sip: |
| 1201 | log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
| 1202 | log.info("Getting DNS Address as per server 's configuration.") |
| 1203 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1204 | def test_dhcpRelay_transactions_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1205 | |
| 1206 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1207 | self.stats() |
| 1208 | log.info("Statistics for run %d",i) |
| 1209 | log.info("----------------------------------------------------------------------------------") |
| 1210 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1211 | log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1212 | log.info("----------------------------------------------------------------------------------") |
| 1213 | 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] | 1214 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1215 | log.info("Final Statistics for total transactions") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1216 | log.info("----------------------------------------------------------------------------------") |
| 1217 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1218 | log.info(" %d %d %d %d" %(self.transactions, |
| 1219 | self.total_success, self.total_failure, self.running_time)) |
| 1220 | log.info("----------------------------------------------------------------------------------") |
| 1221 | log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 1222 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1223 | def test_dhcpRelay_consecutive_successes_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1224 | |
| 1225 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1226 | self.stats(success_rate = True) |
| 1227 | log.info("Statistics for run %d",i) |
| 1228 | log.info("----------------------------------------------------------------------------------") |
| 1229 | log.info("No. of consecutive successful transactions Running Time ") |
| 1230 | log.info(" %d %d " %(self.ip_count, self.diff)) |
| 1231 | log.info("----------------------------------------------------------------------------------") |
| 1232 | log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1233 | log.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1234 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1235 | log.info("Final Statistics for total successful transactions") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1236 | log.info("----------------------------------------------------------------------------------") |
| 1237 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1238 | log.info(" %d %d %d " %(self.transactions, |
| 1239 | self.total_success, self.running_time)) |
| 1240 | log.info("----------------------------------------------------------------------------------") |
| 1241 | log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 1242 | log.info("----------------------------------------------------------------------------------") |
| 1243 | |
| 1244 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1245 | def test_dhcpRelay_clients_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1246 | |
| 1247 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1248 | self.stats(only_discover = True) |
| 1249 | log.info("----------------------------------------------------------------------------------") |
| 1250 | log.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1251 | log.info("----------------------------------------------------------------------------------") |
| 1252 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1253 | log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1254 | log.info("----------------------------------------------------------------------------------") |
| 1255 | log.info("No. of clients per second in run %d:%f " |
| 1256 | %(i, self.transaction_count)) |
| 1257 | log.info("----------------------------------------------------------------------------------") |
| 1258 | log.info("Final Statistics for total transactions of sending only DHCP Discover") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1259 | log.info("----------------------------------------------------------------------------------") |
| 1260 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1261 | log.info(" %d %d %d %d" %(self.transactions, |
| 1262 | self.total_success, self.total_failure, self.running_time)) |
| 1263 | log.info("----------------------------------------------------------------------------------") |
| 1264 | log.info("Average no. of clients per second: %d ", |
| 1265 | round(self.transactions/self.running_time,0)) |
| 1266 | log.info("----------------------------------------------------------------------------------") |
| 1267 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1268 | def test_dhcpRelay_consecutive_successful_clients_per_second(self, iface = 'veth0'): |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1269 | |
| 1270 | for i in range(1,4): |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1271 | self.stats(success_rate = True, only_discover = True) |
| 1272 | log.info("----------------------------------------------------------------------------------") |
| 1273 | log.info("Statistics for run %d for sending only DHCP Discover",i) |
| 1274 | log.info("----------------------------------------------------------------------------------") |
| 1275 | log.info("No. of consecutive successful transactions Running Time ") |
| 1276 | log.info(" %d %d " %(self.ip_count, self.diff)) |
| 1277 | log.info("----------------------------------------------------------------------------------") |
| 1278 | log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 1279 | log.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1280 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1281 | log.info("Final Statistics for total successful transactions") |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1282 | log.info("----------------------------------------------------------------------------------") |
| 1283 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1284 | log.info(" %d %d %d " %(self.transactions, |
| 1285 | self.total_success, self.running_time)) |
| 1286 | log.info("----------------------------------------------------------------------------------") |
| 1287 | log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 1288 | log.info("----------------------------------------------------------------------------------") |
| 1289 | |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1290 | def test_dhcpRelay_concurrent_transactions_per_second(self, iface = 'veth0'): |
| 1291 | |
| 1292 | config = self.default_config |
| 1293 | options = self.default_options |
| 1294 | subnet = [ ('192.168.1.2', |
| 1295 | ''' |
| 1296 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1297 | range 192.168.1.10 192.168.2.100; |
| 1298 | } |
| 1299 | '''), ] |
| 1300 | |
| 1301 | dhcpd_interface_list = self.relay_interfaces |
| 1302 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1303 | config = config, |
| 1304 | options = options, |
| 1305 | subnet = subnet) |
| 1306 | |
| 1307 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1308 | self.host_load(g_subscriber_port_map[key]) |
| 1309 | |
| 1310 | def thread_fun(i): |
| 1311 | mac = self.get_mac('veth{}'.format(i)) |
| 1312 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 1313 | log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1314 | self.lock.acquire() |
| 1315 | |
| 1316 | if cip: |
| 1317 | self.ip_count += 1 |
| 1318 | |
| 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 | |
| 1357 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1358 | |
| 1359 | self.transactions += (self.ip_count+self.failure_count) |
| 1360 | self.running_time += self.diff |
| 1361 | self.total_success += self.ip_count |
| 1362 | self.total_failure += self.failure_count |
| 1363 | |
| 1364 | |
| 1365 | log.info("----------------------------------------------------------------------------------") |
| 1366 | log.info("Statistics for run %d",i) |
| 1367 | log.info("----------------------------------------------------------------------------------") |
| 1368 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1369 | log.info(" %d %d %d %d" |
| 1370 | %(self.ip_count+self.failure_count,self.ip_count, self.failure_count, self.diff)) |
| 1371 | log.info("----------------------------------------------------------------------------------") |
| 1372 | log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1373 | log.info("----------------------------------------------------------------------------------") |
| 1374 | |
| 1375 | log.info("----------------------------------------------------------------------------------") |
| 1376 | log.info("Final Statistics for total transactions") |
| 1377 | log.info("----------------------------------------------------------------------------------") |
| 1378 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1379 | log.info(" %d %d %d %d" %(self.transactions, |
| 1380 | self.total_success, self.total_failure, self.running_time)) |
| 1381 | |
| 1382 | log.info("----------------------------------------------------------------------------------") |
| 1383 | log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 1384 | log.info("----------------------------------------------------------------------------------") |
| 1385 | |
| 1386 | def test_dhcpRelay_concurrent_consecutive_successes_per_second(self, iface = 'veth0'): |
| 1387 | |
| 1388 | config = self.default_config |
| 1389 | options = self.default_options |
| 1390 | subnet = [ ('192.168.1.2', |
| 1391 | ''' |
| 1392 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1393 | range 192.168.1.10 192.168.2.100; |
| 1394 | } |
| 1395 | '''), ] |
| 1396 | |
| 1397 | dhcpd_interface_list = self.relay_interfaces |
| 1398 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1399 | config = config, |
| 1400 | options = options, |
| 1401 | subnet = subnet) |
| 1402 | failure_dir = {} |
| 1403 | |
| 1404 | for key in (key for key in g_subscriber_port_map if key != 100): |
| 1405 | self.host_load(g_subscriber_port_map[key]) |
| 1406 | |
| 1407 | def thread_fun(i, j): |
| 1408 | # log.info("Thread Name:%s",current_thread().name) |
| 1409 | # failure_dir[current_thread().name] = True |
| 1410 | while failure_dir.has_key(current_thread().name) is False: |
| 1411 | mac = RandMAC()._fix() |
| 1412 | cip, sip = DHCPTest(iface = 'veth{}'.format(i)).discover(mac = mac) |
| 1413 | i += 2 |
| 1414 | log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1415 | self.lock.acquire() |
| 1416 | |
| 1417 | if cip: |
| 1418 | self.ip_count += 1 |
| 1419 | self.lock.notify_all() |
| 1420 | self.lock.release() |
| 1421 | elif cip is None: |
| 1422 | self.failure_count += 1 |
| 1423 | failure_dir[current_thread().name] = True |
| 1424 | self.lock.notify_all() |
| 1425 | self.lock.release() |
| 1426 | break |
| 1427 | # self.lock.notify_all() |
| 1428 | # self.lock.release() |
| 1429 | |
| 1430 | for i in range (1,4): |
| 1431 | failure_dir = {} |
| 1432 | self.ip_count = 0 |
| 1433 | self.failure_count = 0 |
| 1434 | self.start_time = 0 |
| 1435 | self.diff = 0 |
| 1436 | self.transaction_count = 0 |
| 1437 | self.start_time = time.time() |
| 1438 | |
| 1439 | while len(failure_dir) != 6: |
| 1440 | t = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1441 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1442 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1443 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1444 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1445 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': 0, 'j': 2}) |
| 1446 | |
| 1447 | t.start() |
| 1448 | t1.start() |
| 1449 | t2.start() |
| 1450 | t3.start() |
| 1451 | t4.start() |
| 1452 | t5.start() |
| 1453 | |
| 1454 | t.join() |
| 1455 | t1.join() |
| 1456 | t2.join() |
| 1457 | t3.join() |
| 1458 | t4.join() |
| 1459 | t5.join() |
| 1460 | |
| 1461 | self.diff = round(time.time() - self.start_time, 0) |
| 1462 | self.transaction_count = round((self.ip_count)/self.diff, 2) |
| 1463 | |
| 1464 | self.transactions += (self.ip_count+self.failure_count) |
| 1465 | self.running_time += self.diff |
| 1466 | self.total_success += self.ip_count |
| 1467 | self.total_failure += self.failure_count |
| 1468 | |
| 1469 | |
| 1470 | log.info("Statistics for run %d",i) |
| 1471 | log.info("----------------------------------------------------------------------------------") |
| 1472 | log.info("No. of consecutive successful transactions Running Time ") |
| 1473 | log.info(" %d %d " %(self.ip_count, self.diff)) |
| 1474 | log.info("----------------------------------------------------------------------------------") |
| 1475 | log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 1476 | log.info("----------------------------------------------------------------------------------") |
| 1477 | |
| 1478 | log.info("Final Statistics for total successful transactions") |
| 1479 | log.info("----------------------------------------------------------------------------------") |
| 1480 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
| 1481 | log.info(" %d %d %d " %(self.transactions, |
| 1482 | self.total_success, self.running_time)) |
| 1483 | log.info("----------------------------------------------------------------------------------") |
| 1484 | log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,2)) |
| 1485 | log.info("----------------------------------------------------------------------------------") |
| 1486 | |
| 1487 | def test_dhcpRelay_concurrent_clients_per_second(self, iface = 'veth0'): |
| 1488 | |
| 1489 | config = self.default_config |
| 1490 | options = self.default_options |
| 1491 | subnet = [ ('192.168.1.2', |
| 1492 | ''' |
| 1493 | subnet 192.168.0.0 netmask 255.255.0.0 { |
| 1494 | range 192.168.1.10 192.168.2.100; |
| 1495 | } |
| 1496 | '''), ] |
| 1497 | |
| 1498 | dhcpd_interface_list = self.relay_interfaces |
| 1499 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1500 | config = config, |
| 1501 | options = options, |
| 1502 | subnet = subnet) |
| 1503 | |
| 1504 | for key in (key for key in g_subscriber_port_map if key < 100): |
| 1505 | self.host_load(g_subscriber_port_map[key]) |
| 1506 | |
| 1507 | def thread_fun(i): |
| 1508 | # mac = self.get_mac('veth{}'.format(i)) |
| 1509 | cip, sip, mac, _ = DHCPTest(iface = 'veth{}'.format(i)).only_discover(mac = RandMAC()._fix()) |
| 1510 | log.info('Got dhcp client IP %s from server %s for mac %s'%(cip, sip, mac)) |
| 1511 | self.lock.acquire() |
| 1512 | |
| 1513 | if cip: |
| 1514 | self.ip_count += 1 |
| 1515 | elif cip is None: |
| 1516 | self.failure_count += 1 |
| 1517 | |
| 1518 | self.lock.notify_all() |
| 1519 | self.lock.release() |
| 1520 | |
| 1521 | for i in range (1,4): |
| 1522 | self.ip_count = 0 |
| 1523 | self.failure_count = 0 |
| 1524 | self.start_time = 0 |
| 1525 | self.diff = 0 |
| 1526 | self.transaction_count = 0 |
| 1527 | self.start_time = time.time() |
| 1528 | |
| 1529 | while self.diff <= 60: |
| 1530 | t = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(0, random.randrange(1,40,1), 1)}) |
| 1531 | t1 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(42, random.randrange(43,80,1), 1)}) |
| 1532 | t2 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(82, random.randrange(83,120,1), 1)}) |
| 1533 | t3 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(122, random.randrange(123,160,1), 1)}) |
| 1534 | t4 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(162, random.randrange(163,180,1), 1)}) |
| 1535 | t5 = threading.Thread(target = thread_fun, kwargs = {'i': random.randrange(182, random.randrange(183,196,1), 1)}) |
| 1536 | |
| 1537 | t.start() |
| 1538 | t1.start() |
| 1539 | t2.start() |
| 1540 | t3.start() |
| 1541 | t4.start() |
| 1542 | t5.start() |
| 1543 | |
| 1544 | t.join() |
| 1545 | t1.join() |
| 1546 | t2.join() |
| 1547 | t3.join() |
| 1548 | t4.join() |
| 1549 | t5.join() |
| 1550 | |
| 1551 | self.diff = round(time.time() - self.start_time, 0) |
| 1552 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1553 | self.transactions += (self.ip_count+self.failure_count) |
| 1554 | self.running_time += self.diff |
| 1555 | self.total_success += self.ip_count |
| 1556 | self.total_failure += self.failure_count |
| 1557 | |
| 1558 | log.info("----------------------------------------------------------------------------------") |
| 1559 | log.info("Statistics for run %d of sending only DHCP Discover",i) |
| 1560 | log.info("----------------------------------------------------------------------------------") |
| 1561 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 1562 | log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 1563 | log.info("----------------------------------------------------------------------------------") |
| 1564 | log.info("No. of clients per second in run %d:%f " |
| 1565 | %(i, self.transaction_count)) |
| 1566 | log.info("----------------------------------------------------------------------------------") |
| 1567 | |
| 1568 | log.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 1569 | log.info("----------------------------------------------------------------------------------") |
| 1570 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 1571 | log.info(" %d %d %d %d" %(self.transactions, |
| 1572 | self.total_success, self.total_failure, self.running_time)) |
| 1573 | log.info("----------------------------------------------------------------------------------") |
| 1574 | log.info("Average no. of clients per second: %d ", |
| 1575 | round(self.transactions/self.running_time,0)) |
| 1576 | log.info("----------------------------------------------------------------------------------") |
| 1577 | |
| 1578 | |
| 1579 | @nottest |
| 1580 | def test_dhcpRelay_inform_packet(self, iface = 'veth0'): |
| 1581 | mac = self.get_mac(iface) |
| 1582 | self.host_load(iface) |
| 1583 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1584 | self.send_recv(mac, inform_packet = True) |
| 1585 | |
| 1586 | def test_dhcpRelay_client_conflict(self, iface = 'veth0'): |
| 1587 | mac = self.get_mac(iface) |
| 1588 | self.host_load(iface) |
| 1589 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 1590 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 1591 | log.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1592 | (cip, sip, mac) ) |
| 1593 | self.dhcp1 = DHCPTest(seed_ip = cip, iface = iface) |
| 1594 | new_cip, new_sip, new_mac, _ = self.dhcp1.only_discover(desired = True) |
| 1595 | new_cip, new_sip = self.dhcp1.only_request(new_cip, new_mac) |
| 1596 | log.info('Got dhcp client IP %s from server %s for mac %s.' % |
| 1597 | (new_cip, new_sip, new_mac) ) |
| 1598 | log.info("IP %s alredy consumed by mac %s." % (new_cip, new_mac)) |
| 1599 | log.info("Now sending DHCP Request for old DHCP discover.") |
| 1600 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 1601 | if new_cip is None: |
| 1602 | log.info('Got dhcp client IP %s from server %s for mac %s.Which is expected behavior.' |
| 1603 | %(new_cip, new_sip, new_mac) ) |
| 1604 | elif new_cip: |
| 1605 | log.info('Got dhcp client IP %s from server %s for mac %s.Which is not expected behavior as IP %s is already consumed.' |
| 1606 | %(new_cip, new_sip, new_mac, new_cip) ) |
| 1607 | assert_equal(new_cip, None) |
| 1608 | |
| 1609 | |
ChetanGaonker | 5860c18 | 2016-07-05 16:33:06 -0700 | [diff] [blame] | 1610 | |