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