blob: 14a9d4a67d853815e2308470c6bc9188747af77a [file] [log] [blame]
Chetan Gaonkercfcce782016-05-10 10:10:42 -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#
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080016import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from scapy.all import *
21import time
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080022import copy
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080023from DHCP import DHCPTest
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080024from OnosCtrl import OnosCtrl
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080025log.setLevel('INFO')
26
27class dhcp_exchange(unittest.TestCase):
28
29 dhcp_server_config = {
30 "ip": "10.1.11.50",
31 "mac": "ca:fe:ca:fe:ca:fe",
32 "subnet": "255.255.252.0",
33 "broadcast": "10.1.11.255",
34 "router": "10.1.8.1",
35 "domain": "8.8.8.8",
36 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080037 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080038 "startip": "10.1.11.51",
39 "endip": "10.1.11.100"
40 }
41
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080042 app = 'org.onosproject.dhcp'
43
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070044 ip_count = 0
45 failure_count = 0
46 start_time = 0
47 diff = 0
48
49 transaction_count = 0
50 transactions = 0
51 running_time = 0
52 total_success = 0
53 total_failure = 0
54
55
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080056 def setUp(self):
57 ''' Activate the dhcp app'''
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080058 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080059 self.onos_ctrl = OnosCtrl(self.app)
60 status, _ = self.onos_ctrl.activate()
61 assert_equal(status, True)
62 time.sleep(3)
63
64 def teardown(self):
65 '''Deactivate the dhcp app'''
66 self.onos_ctrl.deactivate()
67
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080068 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070069 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080070 if status is False:
71 log.info('JSON request returned status %d' %code)
72 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080073 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080074
75 def onos_dhcp_table_load(self, config = None):
76 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
77 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
78 if config:
79 for k in config.keys():
80 if dhcp_config.has_key(k):
81 dhcp_config[k] = config[k]
82 self.onos_load_config(dhcp_dict)
83
Chetan Gaonker6c68e912016-04-15 17:22:14 -070084 def send_recv(self, mac = None, update_seed = False, validate = True):
85 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
86 if validate:
87 assert_not_equal(cip, None)
88 assert_not_equal(sip, None)
89 log.info('Got dhcp client IP %s from server %s for mac %s' %
90 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080091 return cip,sip
92
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070093
94 def stats(self,success_rate = False, iface = 'veth0'):
95
96 self.ip_count = 0
97 self.failure_count = 0
98 self.start_time = 0
99 self.diff = 0
100 self.transaction_count = 0
101
102 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
103 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
104 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
105 self.onos_dhcp_table_load(config)
106 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
107 self.start_time = time.time()
108
109 while self.diff <= 60:
110
111 cip, sip = self.send_recv(update_seed = True, validate = False)
112 if cip:
113 self.ip_count +=1
114 elif cip == None:
115 self.failure_count += 1
116 log.info('Failed to get ip')
117 if success_rate:
118 break
119
120 self.diff = round(time.time() - self.start_time, 2)
121
122 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
123
124 self.transactions += (self.ip_count+self.failure_count)
125 self.running_time += self.diff
126 self.total_success += self.ip_count
127 self.total_failure += self.failure_count
128
129
130
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800131 def test_dhcp_1request(self, iface = 'veth0'):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800132 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
133 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800134 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
135 self.onos_dhcp_table_load(config)
136 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
137 self.send_recv()
138
139 def test_dhcp_Nrequest(self, iface = 'veth0'):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800140 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800141 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
142 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
143 self.onos_dhcp_table_load(config)
144 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
145 ip_map = {}
146 for i in range(10):
147 cip, sip = self.send_recv(update_seed = True)
148 if ip_map.has_key(cip):
149 log.info('IP %s given out multiple times' %cip)
150 assert_equal(False, ip_map.has_key(cip))
151 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800152
153 def test_dhcp_1release(self, iface = 'veth0'):
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800154 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
155 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
156 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800157 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800158 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800159 cip, sip = self.send_recv()
160 log.info('Releasing ip %s to server %s' %(cip, sip))
161 assert_equal(self.dhcp.release(cip), True)
162 log.info('Triggering DHCP discover again after release')
163 cip2, sip2 = self.send_recv(update_seed = True)
164 log.info('Verifying released IP was given back on rediscover')
165 assert_equal(cip, cip2)
166 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
167 assert_equal(self.dhcp.release(cip2), True)
168
169 def test_dhcp_Nrelease(self, iface = 'veth0'):
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800170 config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
171 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
172 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800173 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800174 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800175 ip_map = {}
176 for i in range(10):
177 cip, sip = self.send_recv(update_seed = True)
178 if ip_map.has_key(cip):
179 log.info('IP %s given out multiple times' %cip)
180 assert_equal(False, ip_map.has_key(cip))
181 ip_map[cip] = sip
182
183 for ip in ip_map.keys():
184 log.info('Releasing IP %s' %ip)
185 assert_equal(self.dhcp.release(ip), True)
186
187 ip_map2 = {}
188 log.info('Triggering DHCP discover again after release')
189 for i in range(len(ip_map.keys())):
190 cip, sip = self.send_recv(update_seed = True)
191 ip_map2[cip] = sip
192
193 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800194 if ip_map != ip_map2:
195 log.info('Map before release %s' %ip_map)
196 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800197 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700198
199
200 def test_dhcp_starvation(self, iface = 'veth0'):
201 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
202 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
203 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
204 self.onos_dhcp_table_load(config)
205 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
206 ip_map = {}
207 for i in range(10):
208 cip, sip = self.send_recv(update_seed = True)
209 if ip_map.has_key(cip):
210 log.info('IP %s given out multiple times' %cip)
211 assert_equal(False, ip_map.has_key(cip))
212 ip_map[cip] = sip
213
214
215 def test_dhcp_starvation(self, iface = 'veth0'):
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700216 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
217 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
218 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
219 self.onos_dhcp_table_load(config)
220 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
221 log.info('Verifying 1 ')
222 for x in xrange(50):
223 mac = RandMAC()._fix()
224 self.send_recv(mac = mac)
225 log.info('Verifying 2 ')
226 cip, sip = self.send_recv(update_seed = True, validate = False)
227 assert_equal(cip, None)
228 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700229
230
231 def test_dhcp_same_client_multiple_discover(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700232 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
233 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
234 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
235 self.onos_dhcp_table_load(config)
236 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
237 cip, sip, mac = self.dhcp.only_discover()
238 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
239 (cip, sip, mac) )
240 log.info('Triggering DHCP discover again.')
241 new_cip, new_sip, new_mac = self.dhcp.only_discover()
242 if cip == new_cip:
243 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
244 % (new_cip, new_sip, new_mac) )
245 elif cip != new_cip:
246 log.info('Ip after 1st discover %s' %cip)
247 log.info('Map after 2nd discover %s' %new_cip)
248 assert_equal(cip, new_cip)
249
250
251 def test_dhcp_same_client_multiple_request(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700252 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
253 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
254 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
255 self.onos_dhcp_table_load(config)
256 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
257 log.info('Sending DHCP discover and DHCP request.')
258 cip, sip = self.send_recv()
259 mac = self.dhcp.get_mac(cip)[0]
260 log.info("Sending DHCP request again.")
261 new_cip, new_sip = self.dhcp.only_request(cip, mac)
262 if (new_cip,new_sip) == (cip,sip):
263
264 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
265 % (new_cip, new_sip, mac) )
266 elif (new_cip,new_sip):
267
268 log.info('No DHCP ACK')
269 assert_equal(new_cip, None)
270 assert_equal(new_sip, None)
271 else:
272 print "Something went wrong."
273
274 def test_dhcp_client_desired_address(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700275 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
276 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
277 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
278 self.onos_dhcp_table_load(config)
279 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface)
280 cip, sip, mac = self.dhcp.only_discover(desired = True)
281 log.info('Got dhcp client IP %s from server %s for mac %s .' %
282 (cip, sip, mac) )
283 if cip == self.dhcp.seed_ip:
284 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
285 (cip, sip, mac) )
286 elif cip != self.dhcp.seed_ip:
287 log.info('Got dhcp client IP %s from server %s for mac %s .' %
288 (cip, sip, mac) )
289 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
290 assert_equal(cip, self.dhcp.seed_ip)
291
292
293 def test_dhcp_client_desired_address_out_of_pool(self, iface = 'veth0'):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700294 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
295 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
296 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
297 self.onos_dhcp_table_load(config)
298 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
299 cip, sip, mac = self.dhcp.only_discover(desired = True)
300 log.info('Got dhcp client IP %s from server %s for mac %s .' %
301 (cip, sip, mac) )
302 if cip == self.dhcp.seed_ip:
303 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
304 (cip, sip, mac) )
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700305 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
306
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700307 elif cip != self.dhcp.seed_ip:
308 log.info('Got dhcp client IP %s from server %s for mac %s .' %
309 (cip, sip, mac) )
310 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700311 assert_not_equal(cip, self.dhcp.seed_ip)
312
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700313 elif cip == None:
314 log.info('Got DHCP NAK')
315
316
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700317 def test_dhcp_server_nak_packet(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700318 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
319 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
320 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
321 self.onos_dhcp_table_load(config)
322 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
323 cip, sip, mac = self.dhcp.only_discover()
324 log.info('Got dhcp client IP %s from server %s for mac %s .' %
325 (cip, sip, mac) )
326
327 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
328 if (cip == None and mac != None):
329 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
330 assert_not_equal(cip, None)
331 else:
332 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
333 if new_cip == None:
334
335 log.info("Got DHCP server NAK.")
336 assert_equal(new_cip, None) #Negative Test Case
337
338
339 def test_dhcp_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700340 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
341 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
342 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
343 self.onos_dhcp_table_load(config)
344 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
345 log.info('Sending DHCP discover with lease time of 700')
346 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
347
348 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
349 if (cip == None and mac != None):
350 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
351 assert_not_equal(cip, None)
352 elif lval != 700:
353 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
354 (cip, sip, mac, lval) )
355 assert_not_equal(lval, 700)
356
357 def test_dhcp_client_request_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700358
359 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
360 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
361 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
362 self.onos_dhcp_table_load(config)
363 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
364 cip, sip, mac = self.dhcp.only_discover()
365 log.info('Got dhcp client IP %s from server %s for mac %s .' %
366 (cip, sip, mac) )
367
368 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
369
370 if (cip == None and mac != None):
371 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
372 assert_not_equal(cip, None)
373
374 else:
375 new_cip, new_sip = self.dhcp.only_request(cip, mac)
376 if new_cip == None:
377 log.info("Got DHCP server NAK.")
378 os.system('ifconfig '+iface+' down')
379 log.info('Client goes down.')
380 log.info('Delay for 5 seconds.')
381
382 time.sleep(5)
383
384 os.system('ifconfig '+iface+' up')
385 log.info('Client is up now.')
386
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700387 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700388 if new_cip == None:
389 log.info("Got DHCP server NAK.")
390 assert_not_equal(new_cip, None)
391 elif new_cip != None:
392 log.info("Got DHCP ACK.")
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700393 os.system('ifconfig '+iface+' up')
394
395
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700396
397
398 def test_dhcp_server_after_reboot(self, iface = 'veth0'):
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700399 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
400 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
401 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
402 self.onos_dhcp_table_load(config)
403 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
404 cip, sip, mac = self.dhcp.only_discover()
405 log.info('Got dhcp client IP %s from server %s for mac %s .' %
406 (cip, sip, mac) )
407
408 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
409
410 if (cip == None and mac != None):
411 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
412 assert_not_equal(cip, None)
413
414 else:
415 new_cip, new_sip = self.dhcp.only_request(cip, mac)
416 if new_cip == None:
417 log.info("Got DHCP server NAK.")
418 assert_not_equal(new_cip, None)
419 log.info('Getting DHCP server Down.')
420
421 self.onos_ctrl.deactivate()
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700422
423 for i in range(0,4):
424 log.info("Sending DHCP Request.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700425 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700426 new_cip, new_sip = self.dhcp.only_request(cip, mac)
427 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700428 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700429 log.info("DHCP Request timed out.")
430 elif new_cip and new_sip:
431 log.info("Got Reply from DHCP server.")
432 assert_equal(new_cip,None) #Neagtive Test Case
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700433
434 log.info('Getting DHCP server Up.')
435
436 status, _ = self.onos_ctrl.activate()
437 assert_equal(status, True)
438 time.sleep(3)
439
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700440 for i in range(0,4):
441 log.info("Sending DHCP Request after DHCP server is up.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700442 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700443 new_cip, new_sip = self.dhcp.only_request(cip, mac)
444 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700445 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700446 log.info("DHCP Request timed out.")
447 elif new_cip and new_sip:
448 log.info("Got Reply from DHCP server.")
449 assert_equal(new_cip,None) #Neagtive Test Case
450
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700451
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700452 def test_dhcp_specific_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700453 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
454 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
455 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
456 self.onos_dhcp_table_load(config)
457 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
458 log.info('Sending DHCP discover with lease time of 700')
459 cip, sip, mac = self.dhcp.only_discover(lease_time = True)
460 log.info('Got dhcp client IP %s from server %s for mac %s .' %
461 (cip, sip, mac) )
462
463 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
464 if (cip == None and mac != None):
465 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
466 assert_not_equal(cip, None)
467 elif cip and sip and mac:
468
469 log.info("Triggering DHCP Request.")
470 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
471 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
472 (new_cip, new_sip, mac, lval) )
473 assert_not_equal(lval, 700) #Negative Test Case
474
475
476
477 def test_dhcp_lease_packet(self, iface = 'veth0'):
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700478 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
479 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
480 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
481 self.onos_dhcp_table_load(config)
482 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
483 cip, sip, mac = self.dhcp.only_discover()
484 log.info('Got dhcp client IP %s from server %s for mac %s .' %
485 (cip, sip, mac) )
486
487 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
488 if (cip == None and mac != None):
489 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
490 assert_not_equal(cip, None)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700491
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700492 elif cip and sip and mac:
493
494 log.info("Triggering DHCP Request.")
495 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
496 if lval == 600:
497 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
498 (new_cip, new_sip, mac, lval) )
499 else:
500 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
501 (new_cip, new_sip, mac, lval) )
502 log.info('The lease time suppossed to be 600 secs or 10 mins.')
503 assert_equal(lval, 600)
504
505 def test_dhcp_client_renew_time(self, iface = 'veth0'):
506
507 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
508 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
509 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
510 self.onos_dhcp_table_load(config)
511 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
512 cip, sip, mac = self.dhcp.only_discover()
513 log.info('Got dhcp client IP %s from server %s for mac %s .' %
514 (cip, sip, mac) )
515
516 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
517 if (cip == None and mac != None):
518 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
519 assert_not_equal(cip, None)
520
521 elif cip and sip and mac:
522
523 log.info("Triggering DHCP Request.")
524 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
525
526 if new_cip and new_sip and lval:
527
528 log.info("Clinet 's Renewal time is :%s",lval)
529 log.info("Generating delay till renewal time.")
530 time.sleep(lval)
531
532 log.info("Client Sending Unicast DHCP request.")
533 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
534
535 if latest_cip and latest_sip:
536 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
537 (latest_cip, mac, latest_sip) )
538
539 elif latest_cip == None:
540 log.info("Got DHCP NAK. Lease not renewed.")
541
542 elif new_cip == None or new_sip == None or lval == None:
543
544 log.info("Got DHCP NAK.")
545
546
547
548 def test_dhcp_client_rebind_time(self, iface = 'veth0'):
549
550 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
551 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
552 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
553 self.onos_dhcp_table_load(config)
554 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
555 cip, sip, mac = self.dhcp.only_discover()
556 log.info('Got dhcp client IP %s from server %s for mac %s .' %
557 (cip, sip, mac) )
558
559 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
560 if (cip == None and mac != None):
561 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
562 assert_not_equal(cip, None)
563
564 elif cip and sip and mac:
565
566 log.info("Triggering DHCP Request.")
567 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
568
569 if new_cip and new_sip and lval:
570
571 log.info("Clinet 's Rebind time is :%s",lval)
572 log.info("Generating delay till rebind time.")
573 time.sleep(lval)
574
575 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
576
577 for i in range(0,4):
578 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
579
580 if latest_cip and latest_sip:
581 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
582 (latest_cip, mac, latest_sip) )
583
584 elif latest_cip == None:
585 log.info("Got DHCP NAK. Lease not renewed.")
586 assert_not_equal(latest_cip, None)
587 elif new_cip == None or new_sip == None or lval == None:
588
589 log.info("Got DHCP NAK.Lease not Renewed.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700590
Chetan Gaonker717b2942016-05-13 17:42:59 -0700591
592 def test_dhcp_client_expected_subnet_mask(self, iface = 'veth0'):
593
594 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
595 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
596 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
597 self.onos_dhcp_table_load(config)
598 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
599 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700600 self.dhcp.return_option = 'subnet'
Chetan Gaonker717b2942016-05-13 17:42:59 -0700601
602 cip, sip, mac, subnet_value = self.dhcp.only_discover()
603 log.info('Got dhcp client IP %s from server %s for mac %s .' %
604 (cip, sip, mac) )
605
606 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
607 if (cip == None and mac != None):
608 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
609 assert_not_equal(cip, None)
610
611 elif cip and sip and mac:
612
613 if expected_subnet == subnet_value:
614 log.info("Got same subnet as passed in DHCP server configuration.")
615
616 elif expected_subnet != subnet_value:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700617 log.info("Not getting same subnet as passed in DHCP server configuration.")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700618 assert_equal(expected_subnet, subnet_value)
619
620
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700621 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
622
623 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
624 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
625 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
626 self.onos_dhcp_table_load(config)
627 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
628
629 cip, sip, mac = self.dhcp.only_discover()
630 log.info('Got dhcp client IP %s from server %s for mac %s .' %
631 (cip, sip, mac) )
632
633 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
634 if (cip == None and mac != None):
635 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
636 assert_not_equal(cip, None)
637
638 elif cip and sip and mac:
639
640 self.dhcp.send_different_option = 'subnet'
641 log.info("Sending DHCP Request with wrong subnet mask.")
642 new_cip, new_sip = self.dhcp.only_request(cip, mac)
643 if new_cip == None:
644
645 log.info("Got DHCP NAK.")
646 assert_not_equal(new_cip, None)
647
648 elif new_cip and new_sip:
649
650 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
651 log.info("Getting subnet mask as per server 's configuration.")
652
653
654 def test_dhcp_client_expected_router_address(self, iface = 'veth0'):
655
656 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
657 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
658 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
659 self.onos_dhcp_table_load(config)
660 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
661 expected_router_address = '20.20.20.1'
662 self.dhcp.return_option = 'router'
663
664 cip, sip, mac, router_address_value = self.dhcp.only_discover()
665 log.info('Got dhcp client IP %s from server %s for mac %s .' %
666 (cip, sip, mac) )
667
668 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
669 if (cip == None and mac != None):
670 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
671 assert_not_equal(cip, None)
672
673 elif cip and sip and mac:
674
675 if expected_router_address == router_address_value:
676 log.info("Got same router address as passed in DHCP server configuration.")
677
678 elif expected_router_address != router_address_value:
679 log.info("Not getting same router address as passed in DHCP server configuration.")
680 assert_equal(expected_router_address, router_address_value)
681
682
683 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
684
685 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
686 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
687 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
688 self.onos_dhcp_table_load(config)
689 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
690
691 cip, sip, mac = self.dhcp.only_discover()
692 log.info('Got dhcp client IP %s from server %s for mac %s .' %
693 (cip, sip, mac) )
694
695 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
696 if (cip == None and mac != None):
697 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
698 assert_not_equal(cip, None)
699
700 elif cip and sip and mac:
701
702 self.dhcp.send_different_option = 'router'
703 log.info("Sending DHCP Request with wrong router address.")
704 new_cip, new_sip = self.dhcp.only_request(cip, mac)
705 if new_cip == None:
706
707 log.info("Got DHCP NAK.")
708 assert_not_equal(new_cip, None)
709
710 elif new_cip and new_sip:
711
712 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
713 log.info("Getting Router Address as per server 's configuration.")
714
715
716 def test_dhcp_client_expected_broadcast_address(self, iface = 'veth0'):
717
718 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
719 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
720 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
721 self.onos_dhcp_table_load(config)
722 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
723 expected_broadcast_address = '20.20.20.255'
724 self.dhcp.return_option = 'broadcast_address'
725
726 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
727 log.info('Got dhcp client IP %s from server %s for mac %s .' %
728 (cip, sip, mac) )
729
730 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
731 if (cip == None and mac != None):
732 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
733 assert_not_equal(cip, None)
734
735 elif cip and sip and mac:
736
737 if expected_broadcast_address == broadcast_address_value:
738 log.info("Got same router address as passed in DHCP server configuration.")
739
740 elif expected_broadcast_address != broadcast_address_value:
741 log.info("Not getting same router address as passed in DHCP server configuration.")
742 assert_equal(expected_broadcast_address, broadcast_address_value)
743
744
745 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
746
747 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
748 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
749 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
750 self.onos_dhcp_table_load(config)
751 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
752
753 cip, sip, mac = self.dhcp.only_discover()
754 log.info('Got dhcp client IP %s from server %s for mac %s .' %
755 (cip, sip, mac) )
756
757 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
758 if (cip == None and mac != None):
759 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
760 assert_not_equal(cip, None)
761
762 elif cip and sip and mac:
763
764 self.dhcp.send_different_option = 'broadcast_address'
765 log.info("Sending DHCP Request with wrong broadcast address.")
766 new_cip, new_sip = self.dhcp.only_request(cip, mac)
767 if new_cip == None:
768
769 log.info("Got DHCP NAK.")
770 assert_not_equal(new_cip, None)
771
772 elif new_cip and new_sip:
773
774 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
775 log.info("Getting Broadcast Address as per server 's configuration.")
776
777 def test_dhcp_client_expected_dns_address(self, iface = 'veth0'):
778
779 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
780 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
781 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
782 self.onos_dhcp_table_load(config)
783 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
784 expected_dns_address = '8.8.8.8'
785 self.dhcp.return_option = 'dns'
786
787 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
788 log.info('Got dhcp client IP %s from server %s for mac %s .' %
789 (cip, sip, mac) )
790
791 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
792 if (cip == None and mac != None):
793 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
794 assert_not_equal(cip, None)
795
796 elif cip and sip and mac:
797
798 if expected_dns_address == dns_address_value:
799 log.info("Got same DNS address as passed in DHCP server configuration.")
800
801 elif expected_dns_address != dns_address_value:
802 log.info("Not getting same DNS address as passed in DHCP server configuration.")
803 assert_equal(expected_dns_address, dns_address_value)
804
805
806 def test_dhcp_client_sends_dhcp_request_with_wrong_dns_address(self, iface = 'veth0'):
807
808 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
809 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
810 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
811 self.onos_dhcp_table_load(config)
812 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
813
814 cip, sip, mac = self.dhcp.only_discover()
815 log.info('Got dhcp client IP %s from server %s for mac %s .' %
816 (cip, sip, mac) )
817
818 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
819 if (cip == None and mac != None):
820 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
821 assert_not_equal(cip, None)
822
823 elif cip and sip and mac:
824
825 self.dhcp.send_different_option = 'dns'
826 log.info("Sending DHCP Request with wrong DNS address.")
827 new_cip, new_sip = self.dhcp.only_request(cip, mac)
828 if new_cip == None:
829
830 log.info("Got DHCP NAK.")
831 assert_not_equal(new_cip, None)
832
833 elif new_cip and new_sip:
834
835 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
836 log.info("Getting DNS Address as per server 's configuration.")
837
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700838 def test_dhcp_server_transactions_per_second(self, iface = 'veth0'):
839
840 for i in range(1,4):
841 self.stats()
842 log.info("Statics for run %d",i)
843 log.info("----------------------------------------------------------------------------------")
844 log.info("No. of transactions No. of successes No. of failures Running Time ")
845 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
846 log.info("----------------------------------------------------------------------------------")
847 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
848
849 log.info("Final Statatics for total transactions")
850 log.info("----------------------------------------------------------------------------------")
851 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
852 log.info(" %d %d %d %d" %(self.transactions,
853 self.total_success, self.total_failure, self.running_time))
854 log.info("----------------------------------------------------------------------------------")
855 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
856
857 def test_dhcp_server_consecutive_successes_per_second(self, iface = 'veth0'):
858
859 for i in range(1,4):
860 self.stats(success_rate = True)
861 log.info("Statics for run %d",i)
862 log.info("----------------------------------------------------------------------------------")
863 log.info("No. of consecutive successful transactions Running Time ")
864 log.info(" %d %d " %(self.ip_count, self.diff))
865 log.info("----------------------------------------------------------------------------------")
866 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
867
868 log.info("Final Statatics for total successful transactions")
869 log.info("----------------------------------------------------------------------------------")
870 log.info("Total transactions Total No. of consecutive successes Running Time ")
871 log.info(" %d %d %d " %(self.transactions,
872 self.total_success, self.running_time))
873 log.info("----------------------------------------------------------------------------------")
874 log.info("Average no. of transactions per second: %d", round((self.transactions-i)/self.running_time,0))
Chetan Gaonker717b2942016-05-13 17:42:59 -0700875