blob: b19e675d8e858675beb801db3626a77ae683ad15 [file] [log] [blame]
A R Karthick8cf29ac2016-06-30 16:25:14 -07001#
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#
16import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from scapy.all import *
21import time
22import os
23from DHCP import DHCPTest
24from OnosCtrl import OnosCtrl
25from OnosFlowCtrl import get_mac
26from portmaps import g_subscriber_port_map
27log.setLevel('INFO')
28
29class dhcprelay_exchange(unittest.TestCase):
30
31 app = 'org.onosproject.dhcprelay'
32 app_dhcp = 'org.onosproject.dhcp'
33 relay_device_id = 'of:' + get_mac('ovsbr0')
34 relay_interface_port = 100
35 relay_interfaces = (g_subscriber_port_map[relay_interface_port],)
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'''
48subnet 192.168.1.0 netmask 255.255.255.0 {
49 range 192.168.1.10 192.168.1.100;
50}
51'''), ]
ChetanGaonker5860c182016-07-05 16:33:06 -070052 ip_count = 0
53 failure_count = 0
54 start_time = 0
55 diff = 0
56
57 transaction_count = 0
58 transactions = 0
59 running_time = 0
60 total_success = 0
61 total_failure = 0
62
A R Karthick8cf29ac2016-06-30 16:25:14 -070063
64 @classmethod
65 def setUpClass(cls):
66 ''' Activate the dhcprelay app'''
67 OnosCtrl(cls.app_dhcp).deactivate()
68 time.sleep(3)
69 cls.onos_ctrl = OnosCtrl(cls.app)
70 status, _ = cls.onos_ctrl.activate()
71 assert_equal(status, True)
72 time.sleep(3)
73 ##start dhcpd initially with default config
74 cls.dhcpd_start()
75 cls.onos_dhcp_relay_load()
76
77 @classmethod
78 def tearDownClass(cls):
79 '''Deactivate the dhcp relay app'''
80 try:
81 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
82 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
83 except: pass
84 cls.onos_ctrl.deactivate()
85 cls.dhcpd_stop()
86
87 @classmethod
88 def onos_load_config(cls, config):
89 status, code = OnosCtrl.config(config)
90 if status is False:
91 log.info('JSON request returned status %d' %code)
92 assert_equal(status, True)
93 time.sleep(3)
94
95 @classmethod
96 def onos_dhcp_relay_load(cls):
97 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
98 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
99 {'dhcpserverConnectPoint':relay_device_map}}}}
100 cls.onos_load_config(dhcp_dict)
101
102 @classmethod
103 def host_load(cls, iface):
104 '''Have ONOS discover the hosts for dhcp-relay responses'''
105 port = g_subscriber_port_map[iface]
106 host = '173.17.1.{}'.format(port)
107 cmds = ( 'ifconfig {} 0'.format(iface),
108 'ifconfig {0} {1}'.format(iface, host),
109 'arping -I {0} {1} -c 2'.format(iface, host),
110 'ifconfig {} 0'.format(iface), )
111 for c in cmds:
112 os.system(c)
113
114 @classmethod
115 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
116 subnet = default_subnet_config):
117 conf = ''
118 for k, v in config.items():
119 conf += '{} {};\n'.format(k, v)
120
121 opts = ''
122 for k, v in options:
123 opts += 'option {} {};\n'.format(k, v)
124
125 subnet_config = ''
126 for _, v in subnet:
127 subnet_config += '{}\n'.format(v)
128
129 return '{}{}{}'.format(conf, opts, subnet_config)
130
131 @classmethod
132 def dhcpd_start(cls, intf_list = relay_interfaces,
133 config = default_config, options = default_options,
134 subnet = default_subnet_config):
135 '''Start the dhcpd server by generating the conf file'''
136 ##stop dhcpd if already running
137 cls.dhcpd_stop()
138 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
139 subnet = subnet)
140 ##first touch dhcpd.leases if it doesn't exist
141 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
142 if os.access(lease_file, os.F_OK) is False:
143 with open(lease_file, 'w') as fd: pass
144
145 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
146 with open(conf_file, 'w') as fd:
147 fd.write(dhcp_conf)
148
149 #now configure the dhcpd interfaces for various subnets
150 index = 0
151 for ip,_ in subnet:
152 intf = intf_list[index]
153 index += 1
154 os.system('ifconfig {} {}'.format(intf, ip))
155
156 intf_str = ','.join(intf_list)
157 dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str)
158 log.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
159 ret = os.system(dhcpd_cmd)
160 assert_equal(ret, 0)
161 time.sleep(3)
162 cls.relay_interfaces = intf_list
163
164 @classmethod
165 def dhcpd_stop(cls):
166 os.system('pkill -9 dhcpd')
167 for intf in cls.relay_interfaces:
168 os.system('ifconfig {} 0'.format(intf))
169
170 def get_mac(self, iface):
171 if self.interface_to_mac_map.has_key(iface):
172 return self.interface_to_mac_map[iface]
173 mac = get_mac(iface, pad = 0)
174 self.interface_to_mac_map[iface] = mac
175 return mac
176
ChetanGaonker5860c182016-07-05 16:33:06 -0700177 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
178
179 self.ip_count = 0
180 self.failure_count = 0
181 self.start_time = 0
182 self.diff = 0
183 self.transaction_count = 0
184
185 mac = self.get_mac(iface)
186 self.host_load(iface)
187 ##we use the defaults for this test that serves as an example for others
188 ##You don't need to restart dhcpd server if retaining default config
189 config = self.default_config
190 options = self.default_options
191 subnet = self.default_subnet_config
192 dhcpd_interface_list = self.relay_interfaces
193 self.dhcpd_start(intf_list = dhcpd_interface_list,
194 config = config,
195 options = options,
196 subnet = subnet)
197 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
198 self.start_time = time.time()
199
200 while self.diff <= 60:
201
202 if only_discover:
203 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
204 log.info('Got dhcp client IP %s from server %s for mac %s' %
205 (cip, sip, mac))
206 else:
207 cip, sip = self.send_recv(mac, update_seed = True, validate = False)
208
209 if cip:
210 self.ip_count +=1
211 elif cip == None:
212 self.failure_count += 1
213 log.info('Failed to get ip')
214 if success_rate and self.ip_count > 0:
215 break
216
217 self.diff = round(time.time() - self.start_time, 0)
218
219
220 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
221 self.transactions += (self.ip_count+self.failure_count)
222 self.running_time += self.diff
223 self.total_success += self.ip_count
224 self.total_failure += self.failure_count
225
226
227
A R Karthick8cf29ac2016-06-30 16:25:14 -0700228 def send_recv(self, mac, update_seed = False, validate = True):
229 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
230 if validate:
231 assert_not_equal(cip, None)
232 assert_not_equal(sip, None)
ChetanGaonker5860c182016-07-05 16:33:06 -0700233 log.info('Got dhcp client IP %s from server %s for mac %s' %
234 (cip, sip, self.dhcp.get_mac(cip)[0]))
A R Karthick8cf29ac2016-06-30 16:25:14 -0700235 return cip,sip
236
ChetanGaonker5860c182016-07-05 16:33:06 -0700237 def test_dhcpRelay_1request(self, iface = 'veth0'):
A R Karthick8cf29ac2016-06-30 16:25:14 -0700238 mac = self.get_mac(iface)
239 self.host_load(iface)
240 ##we use the defaults for this test that serves as an example for others
241 ##You don't need to restart dhcpd server if retaining default config
242 config = self.default_config
243 options = self.default_options
244 subnet = self.default_subnet_config
245 dhcpd_interface_list = self.relay_interfaces
246 self.dhcpd_start(intf_list = dhcpd_interface_list,
247 config = config,
248 options = options,
249 subnet = subnet)
250 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
251 self.send_recv(mac)
ChetanGaonker5860c182016-07-05 16:33:06 -0700252
253 def test_dhcpRelay_Nrequest(self, iface = 'veth0'):
254 mac = self.get_mac(iface)
255 self.host_load(iface)
256 ##we use the defaults for this test that serves as an example for others
257 ##You don't need to restart dhcpd server if retaining default config
258 config = self.default_config
259 options = self.default_options
260 subnet = self.default_subnet_config
261 dhcpd_interface_list = self.relay_interfaces
262 self.dhcpd_start(intf_list = dhcpd_interface_list,
263 config = config,
264 options = options,
265 subnet = subnet)
266 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
267 ip_map = {}
268 for i in range(10):
269 cip, sip = self.send_recv(mac, update_seed = True)
270 if ip_map.has_key(cip):
271 log.info('IP %s given out multiple times' %cip)
272 assert_equal(False, ip_map.has_key(cip))
273 ip_map[cip] = sip
274
275 def test_dhcpRelay_1release(self, iface = 'veth0'):
276 mac = self.get_mac(iface)
277 self.host_load(iface)
278 ##we use the defaults for this test that serves as an example for others
279 ##You don't need to restart dhcpd server if retaining default config
280 config = self.default_config
281 options = self.default_options
282 subnet = self.default_subnet_config
283 dhcpd_interface_list = self.relay_interfaces
284 self.dhcpd_start(intf_list = dhcpd_interface_list,
285 config = config,
286 options = options,
287 subnet = subnet)
288 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
289 cip, sip = self.send_recv(mac)
290 log.info('Releasing ip %s to server %s' %(cip, sip))
291 assert_equal(self.dhcp.release(cip), True)
292 log.info('Triggering DHCP discover again after release')
293 cip2, sip2 = self.send_recv(mac)
294 log.info('Verifying released IP was given back on rediscover')
295 assert_equal(cip, cip2)
296 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
297 assert_equal(self.dhcp.release(cip2), True)
298
299 def test_dhcpRelay_Nrelease(self, iface = 'veth0'):
300 mac = self.get_mac(iface)
301 self.host_load(iface)
302 ##we use the defaults for this test that serves as an example for others
303 ##You don't need to restart dhcpd server if retaining default config
304 config = self.default_config
305 options = self.default_options
306 subnet = self.default_subnet_config
307 dhcpd_interface_list = self.relay_interfaces
308 self.dhcpd_start(intf_list = dhcpd_interface_list,
309 config = config,
310 options = options,
311 subnet = subnet)
312 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
313 ip_map = {}
314 for i in range(10):
315 cip, sip = self.send_recv(mac, update_seed = True)
316 if ip_map.has_key(cip):
317 log.info('IP %s given out multiple times' %cip)
318 assert_equal(False, ip_map.has_key(cip))
319 ip_map[cip] = sip
320
321 for ip in ip_map.keys():
322 log.info('Releasing IP %s' %ip)
323 assert_equal(self.dhcp.release(ip), True)
324
325 ip_map2 = {}
326 log.info('Triggering DHCP discover again after release')
327 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
328 for i in range(len(ip_map.keys())):
329 cip, sip = self.send_recv(mac, update_seed = True)
330 ip_map2[cip] = sip
331
332 log.info('Verifying released IPs were given back on rediscover')
333 if ip_map != ip_map2:
334 log.info('Map before release %s' %ip_map)
335 log.info('Map after release %s' %ip_map2)
336 assert_equal(ip_map, ip_map2)
337
338 def test_dhcpRelay_starvation(self, iface = 'veth0'):
339 mac = self.get_mac(iface)
340 self.host_load(iface)
341 ##we use the defaults for this test that serves as an example for others
342 ##You don't need to restart dhcpd server if retaining default config
343 config = self.default_config
344 options = self.default_options
345 subnet = self.default_subnet_config
346 dhcpd_interface_list = self.relay_interfaces
347 self.dhcpd_start(intf_list = dhcpd_interface_list,
348 config = config,
349 options = options,
350 subnet = subnet)
351 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
352 ip_map = {}
353 for i in range(10):
354 cip, sip = self.send_recv(mac, update_seed = True)
355 if ip_map.has_key(cip):
356 log.info('IP %s given out multiple times' %cip)
357 assert_equal(False, ip_map.has_key(cip))
358 ip_map[cip] = sip
359
360
361 def test_dhcpRelay_starvation(self, iface = 'veth0'):
362 mac = self.get_mac(iface)
363 self.host_load(iface)
364 ##we use the defaults for this test that serves as an example for others
365 ##You don't need to restart dhcpd server if retaining default config
366 config = self.default_config
367 options = self.default_options
368 subnet = self.default_subnet_config
369 dhcpd_interface_list = self.relay_interfaces
370 self.dhcpd_start(intf_list = dhcpd_interface_list,
371 config = config,
372 options = options,
373 subnet = subnet)
374 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
375 log.info('Verifying 1 ')
376 while True:
377 mac = RandMAC()._fix()
378 cip, sip = self.send_recv(mac = mac, validate = False)
379 if cip is None:
380 break
381 log.info('Verifying 2 ')
382 cip, sip = self.send_recv(mac, update_seed = True, validate = False)
383 assert_equal(cip, None)
384 assert_equal(sip, None)
385
386 def test_dhcpRelay_same_client_multiple_discover(self, iface = 'veth0'):
387 mac = self.get_mac(iface)
388 self.host_load(iface)
389 ##we use the defaults for this test that serves as an example for others
390 ##You don't need to restart dhcpd server if retaining default config
391 config = self.default_config
392 options = self.default_options
393 subnet = self.default_subnet_config
394 dhcpd_interface_list = self.relay_interfaces
395 self.dhcpd_start(intf_list = dhcpd_interface_list,
396 config = config,
397 options = options,
398 subnet = subnet)
399 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
400 cip, sip, mac, _ = self.dhcp.only_discover()
401 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
402 (cip, sip, mac) )
403 log.info('Triggering DHCP discover again.')
404 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
405 if cip == new_cip:
406 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
407 % (new_cip, new_sip, new_mac) )
408 elif cip != new_cip:
409 log.info('Ip after 1st discover %s' %cip)
410 log.info('Map after 2nd discover %s' %new_cip)
411 assert_equal(cip, new_cip)
412
413
414 def test_dhcpRelay_same_client_multiple_request(self, iface = 'veth0'):
415 mac = self.get_mac(iface)
416 self.host_load(iface)
417 ##we use the defaults for this test that serves as an example for others
418 ##You don't need to restart dhcpd server if retaining default config
419 config = self.default_config
420 options = self.default_options
421 subnet = self.default_subnet_config
422 dhcpd_interface_list = self.relay_interfaces
423 self.dhcpd_start(intf_list = dhcpd_interface_list,
424 config = config,
425 options = options,
426 subnet = subnet)
427 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
428 log.info('Sending DHCP discover and DHCP request.')
429 cip, sip = self.send_recv(mac)
430 mac = self.dhcp.get_mac(cip)[0]
431 log.info("Sending DHCP request again.")
432 new_cip, new_sip = self.dhcp.only_request(cip, mac)
433 if (new_cip,new_sip) == (cip,sip):
434 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
435 % (new_cip, new_sip, mac) )
436 elif (new_cip,new_sip):
437 log.info('No DHCP ACK')
438 assert_equal(new_cip, None)
439 assert_equal(new_sip, None)
440 else:
441 log.info('Something went wrong.')
442
443 def test_dhcpRelay_client_desired_address(self, iface = 'veth0'):
444 mac = self.get_mac(iface)
445 self.host_load(iface)
446 ##we use the defaults for this test that serves as an example for others
447 ##You don't need to restart dhcpd server if retaining default config
448 config = self.default_config
449 options = self.default_options
450 subnet = self.default_subnet_config
451 dhcpd_interface_list = self.relay_interfaces
452 self.dhcpd_start(intf_list = dhcpd_interface_list,
453 config = config,
454 options = options,
455 subnet = subnet)
456 self.dhcp = DHCPTest(seed_ip = '192.168.1.31', iface = iface)
457 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
458 log.info('Got dhcp client IP %s from server %s for mac %s .' %
459 (cip, sip, mac) )
460 if cip == self.dhcp.seed_ip:
461 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
462 (cip, sip, mac) )
463 elif cip != self.dhcp.seed_ip:
464 log.info('Got dhcp client IP %s from server %s for mac %s .' %
465 (cip, sip, mac) )
466 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
467 assert_equal(cip, self.dhcp.seed_ip)
468
469 def test_dhcpRelay_client_desired_address_out_of_pool(self, iface = 'veth0'):
470 mac = self.get_mac(iface)
471 self.host_load(iface)
472 ##we use the defaults for this test that serves as an example for others
473 ##You don't need to restart dhcpd server if retaining default config
474 config = self.default_config
475 options = self.default_options
476 subnet = self.default_subnet_config
477 dhcpd_interface_list = self.relay_interfaces
478 self.dhcpd_start(intf_list = dhcpd_interface_list,
479 config = config,
480 options = options,
481 subnet = subnet)
482 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
483 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
484 log.info('Got dhcp client IP %s from server %s for mac %s .' %
485 (cip, sip, mac) )
486 if cip == self.dhcp.seed_ip:
487 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
488 (cip, sip, mac) )
489 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
490 elif cip != self.dhcp.seed_ip:
491 log.info('Got dhcp client IP %s from server %s for mac %s .' %
492 (cip, sip, mac) )
493 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
494 assert_not_equal(cip, self.dhcp.seed_ip)
495 elif cip == None:
496 log.info('Got DHCP NAK')
497
498
499 def test_dhcpRelay_server_nak_packet(self, iface = 'veth0'):
500 mac = self.get_mac(iface)
501 self.host_load(iface)
502 ##we use the defaults for this test that serves as an example for others
503 ##You don't need to restart dhcpd server if retaining default config
504 config = self.default_config
505 options = self.default_options
506 subnet = self.default_subnet_config
507 dhcpd_interface_list = self.relay_interfaces
508 self.dhcpd_start(intf_list = dhcpd_interface_list,
509 config = config,
510 options = options,
511 subnet = subnet)
512 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
513 cip, sip, mac, _ = self.dhcp.only_discover()
514 log.info('Got dhcp client IP %s from server %s for mac %s .' %
515 (cip, sip, mac) )
516
517 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
518 if (cip == None and mac != None):
519 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
520 assert_not_equal(cip, None)
521 else:
522 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
523 if new_cip == None:
524
525 log.info("Got DHCP server NAK.")
526 assert_equal(new_cip, None) #Negative Test Case
527
528
529 def test_dhcpRelay_specific_lease_packet(self, iface = 'veth0'):
530 mac = self.get_mac(iface)
531 self.host_load(iface)
532 ##we use the defaults for this test that serves as an example for others
533 ##You don't need to restart dhcpd server if retaining default config
534 config = self.default_config
535 options = self.default_options
536 subnet = self.default_subnet_config
537 dhcpd_interface_list = self.relay_interfaces
538 self.dhcpd_start(intf_list = dhcpd_interface_list,
539 config = config,
540 options = options,
541 subnet = subnet)
542 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
543 cip, sip, mac, _ = self.dhcp.only_discover()
544
545 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
546 if (cip == None and mac != None):
547 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
548 assert_not_equal(cip, None)
549 elif cip != None:
550 self.dhcp.specific_lease = 800
551 log.info('Sending DHCP request with specific lease time of %s', self.dhcp.specific_lease)
552 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac)
553 if new_cip == None:
554
555 log.info("Got DHCP server NAK.")
556 assert_equal(new_cip, None) #Negative Test Case
557 assert_equal(lval, self.dhcp.specific_lease)
558
559 def test_dhcpRelay_client_request_after_reboot(self, iface = 'veth0'):
560 mac = self.get_mac(iface)
561 self.host_load(iface)
562 ##we use the defaults for this test that serves as an example for others
563 ##You don't need to restart dhcpd server if retaining default config
564 config = self.default_config
565 options = self.default_options
566 subnet = self.default_subnet_config
567 dhcpd_interface_list = self.relay_interfaces
568 self.dhcpd_start(intf_list = dhcpd_interface_list,
569 config = config,
570 options = options,
571 subnet = subnet)
572 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
573 cip, sip, mac, _ = self.dhcp.only_discover()
574 log.info('Got dhcp client IP %s from server %s for mac %s .' %
575 (cip, sip, mac) )
576
577 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
578
579 if (cip == None and mac != None):
580 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
581 assert_not_equal(cip, None)
582
583 else:
584 new_cip, new_sip = self.dhcp.only_request(cip, mac)
585 if new_cip == None:
586 log.info("Got DHCP server NAK.")
587 os.system('ifconfig '+iface+' down')
588 log.info('Client goes down.')
589 log.info('Delay for 5 seconds.')
590
591 time.sleep(5)
592
593 os.system('ifconfig '+iface+' up')
594 log.info('Client is up now.')
595
596 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
597 if new_cip == None:
598 log.info("Got DHCP server NAK.")
599 assert_not_equal(new_cip, None)
600 elif new_cip != None:
601 log.info("Got DHCP ACK.")
602 os.system('ifconfig '+iface+' up')
603
604 def test_dhcpRelay_server_after_reboot(self, iface = 'veth0'):
605 mac = self.get_mac(iface)
606 self.host_load(iface)
607 ##we use the defaults for this test that serves as an example for others
608 ##You don't need to restart dhcpd server if retaining default config
609 config = self.default_config
610 options = self.default_options
611 subnet = self.default_subnet_config
612 dhcpd_interface_list = self.relay_interfaces
613 self.dhcpd_start(intf_list = dhcpd_interface_list,
614 config = config,
615 options = options,
616 subnet = subnet)
617 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
618 cip, sip, mac, _ = self.dhcp.only_discover()
619 log.info('Got dhcp client IP %s from server %s for mac %s .' %
620 (cip, sip, mac) )
621
622 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
623
624 if (cip == None and mac != None):
625 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
626 assert_not_equal(cip, None)
627
628 else:
629 new_cip, new_sip = self.dhcp.only_request(cip, mac)
630 if new_cip == None:
631 log.info("Got DHCP server NAK.")
632 assert_not_equal(new_cip, None)
633 log.info('Getting DHCP server Down.')
634
635 self.tearDownClass()
636
637 for i in range(0,4):
638 log.info("Sending DHCP Request.")
639 log.info('')
640 new_cip, new_sip = self.dhcp.only_request(cip, mac)
641 if new_cip == None and new_sip == None:
642 log.info('')
643 log.info("DHCP Request timed out.")
644 elif new_cip and new_sip:
645 log.info("Got Reply from DHCP server.")
646 assert_equal(new_cip,None) #Neagtive Test Case
647
648 log.info('Getting DHCP server Up.')
649
650 self.setUpClass()
651
652 for i in range(0,4):
653 log.info("Sending DHCP Request after DHCP server is up.")
654 log.info('')
655 new_cip, new_sip = self.dhcp.only_request(cip, mac)
656 if new_cip == None and new_sip == None:
657 log.info('')
658 log.info("DHCP Request timed out.")
659 elif new_cip and new_sip:
660 log.info("Got Reply from DHCP server.")
661 assert_equal(new_cip, cip)
662
663
664 def test_dhcpRelay_specific_lease_packet_in_dhcp_discover(self, iface = 'veth0'):
665 mac = self.get_mac(iface)
666 self.host_load(iface)
667 ##we use the defaults for this test that serves as an example for others
668 ##You don't need to restart dhcpd server if retaining default config
669 config = self.default_config
670 options = self.default_options
671 subnet = self.default_subnet_config
672 dhcpd_interface_list = self.relay_interfaces
673 self.dhcpd_start(intf_list = dhcpd_interface_list,
674 config = config,
675 options = options,
676 subnet = subnet)
677 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
678 log.info('Sending DHCP discover with lease time of 700')
679 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
680 log.info('Got dhcp client IP %s from server %s for mac %s .' %
681 (cip, sip, mac) )
682
683 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
684 if (cip == None and mac != None):
685 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
686 assert_not_equal(cip, None)
687 elif cip and sip and mac:
688
689 log.info("Triggering DHCP Request.")
690 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
691 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
692 (new_cip, new_sip, mac, lval) )
693 assert_not_equal(lval, 700) #Negative Test Case
694
695
696
697 def test_dhcpRelay_default_lease_time(self, iface = 'veth0'):
698 mac = self.get_mac(iface)
699 self.host_load(iface)
700 ##we use the defaults for this test that serves as an example for others
701 ##You don't need to restart dhcpd server if retaining default config
702 config = self.default_config
703 options = self.default_options
704 subnet = self.default_subnet_config
705 dhcpd_interface_list = self.relay_interfaces
706 self.dhcpd_start(intf_list = dhcpd_interface_list,
707 config = config,
708 options = options,
709 subnet = subnet)
710 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
711 cip, sip, mac, _ = self.dhcp.only_discover()
712 log.info('Got dhcp client IP %s from server %s for mac %s .' %
713 (cip, sip, mac) )
714
715 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
716 if (cip == None and mac != None):
717 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
718 assert_not_equal(cip, None)
719
720 elif cip and sip and mac:
721
722 log.info("Triggering DHCP Request.")
723 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
724 if lval == 600:
725 log.info('Getting dhcp client IP %s from server %s for mac %s with defualt lease time %s.' %
726 (new_cip, new_sip, mac, lval) )
727 else:
728 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
729 (new_cip, new_sip, mac, lval) )
730 log.info('The lease time suppossed to be 600 secs or 10 mins.')
731 assert_equal(lval, 600)
732
733 def test_dhcpRelay_client_renew_time(self, iface = 'veth0'):
734 mac = self.get_mac(iface)
735 self.host_load(iface)
736 ##we use the defaults for this test that serves as an example for others
737 ##You don't need to restart dhcpd server if retaining default config
738 config = self.default_config
739 new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)]
740 options = self.default_options + new_options
741 subnet = self.default_subnet_config
742 dhcpd_interface_list = self.relay_interfaces
743 self.dhcpd_start(intf_list = dhcpd_interface_list,
744 config = config,
745 options = options,
746 subnet = subnet)
747 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
748 cip, sip, mac, _ = self.dhcp.only_discover()
749 log.info('Got dhcp client IP %s from server %s for mac %s .' %
750 (cip, sip, mac) )
751
752 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
753 if (cip == None and mac != None):
754 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
755 assert_not_equal(cip, None)
756
757 elif cip and sip and mac:
758
759 log.info("Triggering DHCP Request.")
760 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
761
762 if new_cip and new_sip and lval:
763
764 log.info("Clinet 's Renewal time is :%s",lval)
765 log.info("Generating delay till renewal time.")
766 time.sleep(lval)
767
768 log.info("Client Sending Unicast DHCP request.")
769 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
770
771 if latest_cip and latest_sip:
772 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
773 (latest_cip, mac, latest_sip) )
774
775 elif latest_cip == None:
776 log.info("Got DHCP NAK. Lease not renewed.")
777
778 elif new_cip == None or new_sip == None or lval == None:
779
780 log.info("Got DHCP NAK.")
781
782
783
784 def test_dhcpRelay_client_rebind_time(self, iface = 'veth0'):
785 mac = self.get_mac(iface)
786 self.host_load(iface)
787 ##we use the defaults for this test that serves as an example for others
788 ##You don't need to restart dhcpd server if retaining default config
789 config = self.default_config
790 new_options = [('dhcp-renewal-time', 300), ('dhcp-rebinding-time', 525)]
791 options = self.default_options + new_options
792 subnet = self.default_subnet_config
793 dhcpd_interface_list = self.relay_interfaces
794 self.dhcpd_start(intf_list = dhcpd_interface_list,
795 config = config,
796 options = options,
797 subnet = subnet)
798 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
799 cip, sip, mac, _ = self.dhcp.only_discover()
800 log.info('Got dhcp client IP %s from server %s for mac %s .' %
801 (cip, sip, mac) )
802
803 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
804 if (cip == None and mac != None):
805 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
806 assert_not_equal(cip, None)
807
808 elif cip and sip and mac:
809
810 log.info("Triggering DHCP Request.")
811 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
812
813 if new_cip and new_sip and lval:
814
815 log.info("Clinet 's Rebind time is :%s",lval)
816 log.info("Generating delay till rebind time.")
817 time.sleep(lval)
818
819 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
820
821 for i in range(0,4):
822 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
823
824 if latest_cip and latest_sip:
825 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
826 (latest_cip, mac, latest_sip) )
827 break
828
829 elif latest_cip == None:
830 log.info("Got DHCP NAK. Lease not renewed.")
831 assert_not_equal(latest_cip, None)
832 elif new_cip == None or new_sip == None or lval == None:
833
834 log.info("Got DHCP NAK.Lease not Renewed.")
835
836
837 def test_dhcpRelay_client_expected_subnet_mask(self, iface = 'veth0'):
838 mac = self.get_mac(iface)
839 self.host_load(iface)
840 ##we use the defaults for this test that serves as an example for others
841 ##You don't need to restart dhcpd server if retaining default config
842 config = self.default_config
843 options = self.default_options
844 subnet = self.default_subnet_config
845 dhcpd_interface_list = self.relay_interfaces
846 self.dhcpd_start(intf_list = dhcpd_interface_list,
847 config = config,
848 options = options,
849 subnet = subnet)
850 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
851 expected_subnet = '255.255.255.0'
852 self.dhcp.return_option = 'subnet'
853
854 cip, sip, mac, subnet_value = self.dhcp.only_discover()
855 log.info('Got dhcp client IP %s from server %s for mac %s .' %
856 (cip, sip, mac) )
857
858 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
859 if (cip == None and mac != None):
860 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
861 assert_not_equal(cip, None)
862
863 elif cip and sip and mac:
864
865 if expected_subnet == subnet_value:
866 log.info("Got same subnet as passed in DHCP server configuration.")
867
868 elif expected_subnet != subnet_value:
869 log.info("Not getting same subnet as passed in DHCP server configuration.")
870 assert_equal(expected_subnet, subnet_value)
871
872
873 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
874 mac = self.get_mac(iface)
875 self.host_load(iface)
876 ##we use the defaults for this test that serves as an example for others
877 ##You don't need to restart dhcpd server if retaining default config
878 config = self.default_config
879 options = self.default_options
880 subnet = self.default_subnet_config
881 dhcpd_interface_list = self.relay_interfaces
882 self.dhcpd_start(intf_list = dhcpd_interface_list,
883 config = config,
884 options = options,
885 subnet = subnet)
886 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
887
888 cip, sip, mac, _ = self.dhcp.only_discover()
889 log.info('Got dhcp client IP %s from server %s for mac %s .' %
890 (cip, sip, mac) )
891
892 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
893 if (cip == None and mac != None):
894 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
895 assert_not_equal(cip, None)
896
897 elif cip and sip and mac:
898
899 self.dhcp.send_different_option = 'subnet'
900 log.info("Sending DHCP Request with wrong subnet mask.")
901 new_cip, new_sip = self.dhcp.only_request(cip, mac)
902 if new_cip == None:
903
904 log.info("Got DHCP NAK.")
905 assert_not_equal(new_cip, None)
906
907 elif new_cip and new_sip:
908
909 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
910 log.info("Getting subnet mask as per server 's configuration.")
911
912
913 def test_dhcpRelay_client_expected_router_address(self, iface = 'veth0'):
914 mac = self.get_mac(iface)
915 self.host_load(iface)
916 ##we use the defaults for this test that serves as an example for others
917 ##You don't need to restart dhcpd server if retaining default config
918 config = self.default_config
919 config = self.default_config
920 new_options = [('routers', '20.20.20.1')]
921 options = self.default_options + new_options
922 subnet = self.default_subnet_config
923 dhcpd_interface_list = self.relay_interfaces
924 self.dhcpd_start(intf_list = dhcpd_interface_list,
925 config = config,
926 options = options,
927 subnet = subnet)
928 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
929 expected_router_address = '20.20.20.1'
930 self.dhcp.return_option = 'router'
931
932 cip, sip, mac, router_address_value = self.dhcp.only_discover()
933 log.info('Got dhcp client IP %s from server %s for mac %s .' %
934 (cip, sip, mac) )
935
936 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
937 if (cip == None and mac != None):
938 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
939 assert_not_equal(cip, None)
940
941 elif cip and sip and mac:
942
943 if expected_router_address == router_address_value:
944 log.info("Got same router address as passed in DHCP server configuration.")
945
946 elif expected_router_address != router_address_value:
947 log.info("Not getting same router address as passed in DHCP server configuration.")
948 assert_equal(expected_router_address, router_address_value)
949
950
951 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
952 mac = self.get_mac(iface)
953 self.host_load(iface)
954 ##we use the defaults for this test that serves as an example for others
955 ##You don't need to restart dhcpd server if retaining default config
956 config = self.default_config
957 options = self.default_options
958 subnet = self.default_subnet_config
959 dhcpd_interface_list = self.relay_interfaces
960 self.dhcpd_start(intf_list = dhcpd_interface_list,
961 config = config,
962 options = options,
963 subnet = subnet)
964 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
965
966 cip, sip, mac, _ = self.dhcp.only_discover()
967 log.info('Got dhcp client IP %s from server %s for mac %s .' %
968 (cip, sip, mac) )
969
970 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
971 if (cip == None and mac != None):
972 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
973 assert_not_equal(cip, None)
974
975 elif cip and sip and mac:
976
977 self.dhcp.send_different_option = 'router'
978 log.info("Sending DHCP Request with wrong router address.")
979 new_cip, new_sip = self.dhcp.only_request(cip, mac)
980 if new_cip == None:
981
982 log.info("Got DHCP NAK.")
983 assert_not_equal(new_cip, None)
984
985 elif new_cip and new_sip:
986
987 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
988 log.info("Getting Router Address as per server 's configuration.")
989
990
991 def test_dhcpRelay_client_expected_broadcast_address(self, iface = 'veth0'):
992 mac = self.get_mac(iface)
993 self.host_load(iface)
994 ##we use the defaults for this test that serves as an example for others
995 ##You don't need to restart dhcpd server if retaining default config
996 config = self.default_config
997 options = self.default_options
998 subnet = self.default_subnet_config
999 dhcpd_interface_list = self.relay_interfaces
1000 self.dhcpd_start(intf_list = dhcpd_interface_list,
1001 config = config,
1002 options = options,
1003 subnet = subnet)
1004 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1005 expected_broadcast_address = '192.168.1.255'
1006 self.dhcp.return_option = 'broadcast_address'
1007
1008 cip, sip, mac, broadcast_address_value = 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 if expected_broadcast_address == broadcast_address_value:
1020 log.info("Got same router address as passed in DHCP server configuration.")
1021
1022 elif expected_broadcast_address != broadcast_address_value:
1023 log.info("Not getting same router address as passed in DHCP server configuration.")
1024 assert_equal(expected_broadcast_address, broadcast_address_value)
1025
1026
1027 def test_dhcpRelay_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
1028 mac = self.get_mac(iface)
1029 self.host_load(iface)
1030 ##we use the defaults for this test that serves as an example for others
1031 ##You don't need to restart dhcpd server if retaining default config
1032 config = self.default_config
1033 options = self.default_options
1034 subnet = self.default_subnet_config
1035 dhcpd_interface_list = self.relay_interfaces
1036 self.dhcpd_start(intf_list = dhcpd_interface_list,
1037 config = config,
1038 options = options,
1039 subnet = subnet)
1040 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1041
1042 cip, sip, mac, _ = self.dhcp.only_discover()
1043 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1044 (cip, sip, mac) )
1045
1046 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1047 if (cip == None and mac != None):
1048 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1049 assert_not_equal(cip, None)
1050
1051 elif cip and sip and mac:
1052
1053 self.dhcp.send_different_option = 'broadcast_address'
1054 log.info("Sending DHCP Request with wrong broadcast address.")
1055 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1056 if new_cip == None:
1057
1058 log.info("Got DHCP NAK.")
1059 assert_not_equal(new_cip, None)
1060
1061 elif new_cip and new_sip:
1062
1063 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
1064 log.info("Getting Broadcast Address as per server 's configuration.")
1065
1066 def test_dhcpRelay_client_expected_dns_address(self, iface = 'veth0'):
1067 mac = self.get_mac(iface)
1068 self.host_load(iface)
1069 ##we use the defaults for this test that serves as an example for others
1070 ##You don't need to restart dhcpd server if retaining default config
1071 config = self.default_config
1072 options = self.default_options
1073 subnet = self.default_subnet_config
1074 dhcpd_interface_list = self.relay_interfaces
1075 self.dhcpd_start(intf_list = dhcpd_interface_list,
1076 config = config,
1077 options = options,
1078 subnet = subnet)
1079 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1080 expected_dns_address = '192.168.1.1'
1081 self.dhcp.return_option = 'dns'
1082
1083 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
1084 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1085 (cip, sip, mac) )
1086
1087 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1088 if (cip == None and mac != None):
1089 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1090 assert_not_equal(cip, None)
1091
1092 elif cip and sip and mac:
1093
1094 if expected_dns_address == dns_address_value:
1095 log.info("Got same DNS address as passed in DHCP server configuration.")
1096
1097 elif expected_dns_address != dns_address_value:
1098 log.info("Not getting same DNS address as passed in DHCP server configuration.")
1099 assert_equal(expected_dns_address, dns_address_value)
1100
1101
1102 def test_dhcpRelay_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
1103 mac = self.get_mac(iface)
1104 self.host_load(iface)
1105 ##we use the defaults for this test that serves as an example for others
1106 ##You don't need to restart dhcpd server if retaining default config
1107 config = self.default_config
1108 options = self.default_options
1109 subnet = self.default_subnet_config
1110 dhcpd_interface_list = self.relay_interfaces
1111 self.dhcpd_start(intf_list = dhcpd_interface_list,
1112 config = config,
1113 options = options,
1114 subnet = subnet)
1115 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
1116
1117 cip, sip, mac, _ = self.dhcp.only_discover()
1118 log.info('Got dhcp client IP %s from server %s for mac %s .' %
1119 (cip, sip, mac) )
1120
1121 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
1122 if (cip == None and mac != None):
1123 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
1124 assert_not_equal(cip, None)
1125
1126 elif cip and sip and mac:
1127
1128 self.dhcp.send_different_option = 'dns'
1129 log.info("Sending DHCP Request with wrong DNS address.")
1130 new_cip, new_sip = self.dhcp.only_request(cip, mac)
1131 if new_cip == None:
1132 log.info("Got DHCP NAK.")
1133 assert_not_equal(new_cip, None)
1134 elif new_cip and new_sip:
1135 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
1136 log.info("Getting DNS Address as per server 's configuration.")
1137
1138 def test_dhcpRelay_server_transactions_per_second(self, iface = 'veth0'):
1139
1140 for i in range(1,4):
1141 self.stats()
1142 log.info("Statics for run %d",i)
1143 log.info("----------------------------------------------------------------------------------")
1144 log.info("No. of transactions No. of successes No. of failures Running Time ")
1145 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
1146 log.info("----------------------------------------------------------------------------------")
1147 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
1148
1149 log.info("Final Statatics for total transactions")
1150 log.info("----------------------------------------------------------------------------------")
1151 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1152 log.info(" %d %d %d %d" %(self.transactions,
1153 self.total_success, self.total_failure, self.running_time))
1154 log.info("----------------------------------------------------------------------------------")
1155 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
1156
1157 def test_dhcpRelay_server_consecutive_successes_per_second(self, iface = 'veth0'):
1158
1159 for i in range(1,4):
1160 self.stats(success_rate = True)
1161 log.info("Statics for run %d",i)
1162 log.info("----------------------------------------------------------------------------------")
1163 log.info("No. of consecutive successful transactions Running Time ")
1164 log.info(" %d %d " %(self.ip_count, self.diff))
1165 log.info("----------------------------------------------------------------------------------")
1166 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
1167 log.info("----------------------------------------------------------------------------------")
1168
1169 log.info("Final Statatics for total successful transactions")
1170 log.info("----------------------------------------------------------------------------------")
1171 log.info("Total transactions Total No. of consecutive successes Running Time ")
1172 log.info(" %d %d %d " %(self.transactions,
1173 self.total_success, self.running_time))
1174 log.info("----------------------------------------------------------------------------------")
1175 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
1176 log.info("----------------------------------------------------------------------------------")
1177
1178
1179 def test_dhcpRelay_server_clients_per_second(self, iface = 'veth0'):
1180
1181 for i in range(1,4):
1182 self.stats(only_discover = True)
1183 log.info("----------------------------------------------------------------------------------")
1184 log.info("Statics for run %d of sending only DHCP Discover",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 clients per second in run %d:%f "
1190 %(i, self.transaction_count))
1191 log.info("----------------------------------------------------------------------------------")
1192 log.info("Final Statatics for total transactions of sending only DHCP Discover")
1193 log.info("----------------------------------------------------------------------------------")
1194 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
1195 log.info(" %d %d %d %d" %(self.transactions,
1196 self.total_success, self.total_failure, self.running_time))
1197 log.info("----------------------------------------------------------------------------------")
1198 log.info("Average no. of clients per second: %d ",
1199 round(self.transactions/self.running_time,0))
1200 log.info("----------------------------------------------------------------------------------")
1201
1202 def test_dhcpRelay_server_consecutive_successful_clients_per_second(self, iface = 'veth0'):
1203
1204 for i in range(1,4):
1205 self.stats(success_rate = True, only_discover = True)
1206 log.info("----------------------------------------------------------------------------------")
1207 log.info("Statics for run %d for sending only DHCP Discover",i)
1208 log.info("----------------------------------------------------------------------------------")
1209 log.info("No. of consecutive successful transactions Running Time ")
1210 log.info(" %d %d " %(self.ip_count, self.diff))
1211 log.info("----------------------------------------------------------------------------------")
1212 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
1213 log.info("----------------------------------------------------------------------------------")
1214
1215 log.info("Final Statatics for total successful transactions")
1216 log.info("----------------------------------------------------------------------------------")
1217 log.info("Total transactions Total No. of consecutive successes Running Time ")
1218 log.info(" %d %d %d " %(self.transactions,
1219 self.total_success, self.running_time))
1220 log.info("----------------------------------------------------------------------------------")
1221 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
1222 log.info("----------------------------------------------------------------------------------")
1223
1224