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