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