blob: b81e3cf12701ff16312a3d35329ff89b20f66b8f [file] [log] [blame]
ChetanGaonker42d75812016-06-06 16:32:52 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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
ChetanGaonker42d75812016-06-06 16:32:52 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonker42d75812016-06-06 16:32:52 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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
A R Karthick10fe00e2016-07-12 16:13:16 -070024from OltConfig import *
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080025from OnosCtrl import OnosCtrl
A R Karthick10fe00e2016-07-12 16:13:16 -070026from portmaps import g_subscriber_port_map
A R Karthick9313b762016-11-07 13:14:35 -080027from CordLogger import CordLogger
Chetan Gaonker2499f172017-04-05 00:30:50 +000028from CordTestConfig import setup_module
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080029log.setLevel('INFO')
30
A R Karthick9313b762016-11-07 13:14:35 -080031class dhcp_exchange(CordLogger):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080032
33 dhcp_server_config = {
34 "ip": "10.1.11.50",
35 "mac": "ca:fe:ca:fe:ca:fe",
36 "subnet": "255.255.252.0",
37 "broadcast": "10.1.11.255",
38 "router": "10.1.8.1",
39 "domain": "8.8.8.8",
40 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080041 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080042 "startip": "10.1.11.51",
43 "endip": "10.1.11.100"
44 }
ChetanGaonker42d75812016-06-06 16:32:52 -070045
Chetan Gaonker2499f172017-04-05 00:30:50 +000046 STARTIP = "10.10.10.40"
47 ENDIP = "10.10.10.41"
48 IP = "10.10.10.2"
49 MAC = "ca:fe:ca:fe:ca:fe"
50 SUBNET = "255.255.255.0"
51 BROADCAST = "10.10.10.255"
52 ROUTER = "10.10.10.1"
53
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080054 app = 'org.onosproject.dhcp'
55
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070056 ip_count = 0
57 failure_count = 0
58 start_time = 0
59 diff = 0
60
61 transaction_count = 0
62 transactions = 0
63 running_time = 0
64 total_success = 0
65 total_failure = 0
66
A R Karthick10fe00e2016-07-12 16:13:16 -070067 @classmethod
68 def setUpClass(cls):
Chetan Gaonker2499f172017-04-05 00:30:50 +000069 cls.config_dhcp = {'startip': cls.STARTIP, 'endip': cls.ENDIP,
70 'ip':cls.IP, 'mac': cls.MAC, 'subnet': cls.SUBNET,
71 'broadcast':cls.BROADCAST, 'router':cls.ROUTER}
A R Karthick10fe00e2016-07-12 16:13:16 -070072 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070073 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick10fe00e2016-07-12 16:13:16 -070074 if not cls.port_map:
75 cls.port_map = g_subscriber_port_map
76 cls.iface = cls.port_map[1]
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070077
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080078 def setUp(self):
79 ''' Activate the dhcp app'''
A R Karthick9313b762016-11-07 13:14:35 -080080 super(dhcp_exchange, self).setUp()
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080081 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080082 self.onos_ctrl = OnosCtrl(self.app)
83 status, _ = self.onos_ctrl.activate()
84 assert_equal(status, True)
85 time.sleep(3)
86
A R Karthick9313b762016-11-07 13:14:35 -080087 def tearDown(self):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080088 '''Deactivate the dhcp app'''
89 self.onos_ctrl.deactivate()
A R Karthick9313b762016-11-07 13:14:35 -080090 super(dhcp_exchange, self).tearDown()
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080091
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080092 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070093 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080094 if status is False:
95 log.info('JSON request returned status %d' %code)
96 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080097 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080098
99 def onos_dhcp_table_load(self, config = None):
100 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
101 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
102 if config:
103 for k in config.keys():
104 if dhcp_config.has_key(k):
105 dhcp_config[k] = config[k]
106 self.onos_load_config(dhcp_dict)
107
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700108 def send_recv(self, mac = None, update_seed = False, validate = True):
109 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
Chetan Gaonker2499f172017-04-05 00:30:50 +0000110 log.info("discover cip %s"%(cip))
111 log.info("discover sip %s"%(sip))
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700112 if validate:
113 assert_not_equal(cip, None)
114 assert_not_equal(sip, None)
115 log.info('Got dhcp client IP %s from server %s for mac %s' %
116 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800117 return cip,sip
118
A R Karthick10fe00e2016-07-12 16:13:16 -0700119 def stats(self,success_rate = False, only_discover = False):
ChetanGaonker42d75812016-06-06 16:32:52 -0700120
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700121 self.ip_count = 0
122 self.failure_count = 0
123 self.start_time = 0
124 self.diff = 0
125 self.transaction_count = 0
ChetanGaonker42d75812016-06-06 16:32:52 -0700126 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700127 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
128 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
129 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700130 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700131 self.start_time = time.time()
132
133 while self.diff <= 60:
ChetanGaonker42d75812016-06-06 16:32:52 -0700134 if only_discover:
135 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
136 log.info('Got dhcp client IP %s from server %s for mac %s' %
137 (cip, sip, mac))
138 else:
139 cip, sip = self.send_recv(update_seed = True, validate = False)
140
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700141 if cip:
142 self.ip_count +=1
143 elif cip == None:
144 self.failure_count += 1
145 log.info('Failed to get ip')
ChetanGaonker42d75812016-06-06 16:32:52 -0700146 if success_rate and self.ip_count > 0:
147 break
148 self.diff = round(time.time() - self.start_time, 0)
149
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700150
151 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
152
153 self.transactions += (self.ip_count+self.failure_count)
154 self.running_time += self.diff
155 self.total_success += self.ip_count
156 self.total_failure += self.failure_count
157
A R Karthick10fe00e2016-07-12 16:13:16 -0700158 def test_dhcp_1request(self):
Chetan Gaonker2499f172017-04-05 00:30:50 +0000159 self.onos_dhcp_table_load(self.config_dhcp)
A R Karthick10fe00e2016-07-12 16:13:16 -0700160 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Anil Kumar Sanka50998902016-12-13 12:10:25 +0530161 self.send_recv()
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800162
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000163 def test_dhcp_1request_with_invalid_source_mac_broadcast(self):
164 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
165 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
166 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
167 self.onos_dhcp_table_load(config)
168 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
169 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
170 assert_equal(cip,None)
171 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
172
173 def test_dhcp_1request_with_invalid_source_mac_multicast(self):
174 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
175 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
176 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
177 self.onos_dhcp_table_load(config)
178 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
179 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:91:02:e4')
180 assert_equal(cip,None)
181 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
182
183 def test_dhcp_1request_with_invalid_source_mac_zero(self):
184 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
185 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
186 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
187 self.onos_dhcp_table_load(config)
188 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
189 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
190 assert_equal(cip,None)
191 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
192
Chetan Gaonker2499f172017-04-05 00:30:50 +0000193 def test_dhcp_Nrequest(self, requests=10):
ChetanGaonker42d75812016-06-06 16:32:52 -0700194 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800195 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
196 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
197 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000198 self.dhcp = DHCPTest(seed_ip = '192.168.1.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800199 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000200 for i in range(requests):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800201 cip, sip = self.send_recv(update_seed = True)
202 if ip_map.has_key(cip):
203 log.info('IP %s given out multiple times' %cip)
204 assert_equal(False, ip_map.has_key(cip))
205 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800206
A R Karthick10fe00e2016-07-12 16:13:16 -0700207 def test_dhcp_1release(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000208 config = {'startip':'10.10.100.20', 'endip':'10.10.100.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800209 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
210 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800211 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700212 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800213 cip, sip = self.send_recv()
214 log.info('Releasing ip %s to server %s' %(cip, sip))
215 assert_equal(self.dhcp.release(cip), True)
216 log.info('Triggering DHCP discover again after release')
217 cip2, sip2 = self.send_recv(update_seed = True)
218 log.info('Verifying released IP was given back on rediscover')
219 assert_equal(cip, cip2)
220 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
221 assert_equal(self.dhcp.release(cip2), True)
222
A R Karthick10fe00e2016-07-12 16:13:16 -0700223 def test_dhcp_Nrelease(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000224 config = {'startip':'192.170.1.20', 'endip':'192.170.1.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800225 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
226 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800227 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700228 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800229 ip_map = {}
230 for i in range(10):
231 cip, sip = self.send_recv(update_seed = True)
232 if ip_map.has_key(cip):
233 log.info('IP %s given out multiple times' %cip)
234 assert_equal(False, ip_map.has_key(cip))
235 ip_map[cip] = sip
236
237 for ip in ip_map.keys():
238 log.info('Releasing IP %s' %ip)
239 assert_equal(self.dhcp.release(ip), True)
240
241 ip_map2 = {}
242 log.info('Triggering DHCP discover again after release')
243 for i in range(len(ip_map.keys())):
244 cip, sip = self.send_recv(update_seed = True)
245 ip_map2[cip] = sip
246
247 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800248 if ip_map != ip_map2:
249 log.info('Map before release %s' %ip_map)
250 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800251 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700252
253
Chetan Gaonker62091182017-04-05 17:36:14 -0500254 def test_dhcp_starvation_positive_scenario(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700255 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700256 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
257 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
258 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700259 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700260 ip_map = {}
261 for i in range(10):
262 cip, sip = self.send_recv(update_seed = True)
263 if ip_map.has_key(cip):
264 log.info('IP %s given out multiple times' %cip)
265 assert_equal(False, ip_map.has_key(cip))
266 ip_map[cip] = sip
267
268
Chetan Gaonker62091182017-04-05 17:36:14 -0500269 def test_dhcp_starvation_negative_scenario(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700270 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700271 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
272 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
273 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700274 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000275 log.info('Verifying passitive case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700276 for x in xrange(50):
277 mac = RandMAC()._fix()
278 self.send_recv(mac = mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000279 log.info('Verifying negative case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700280 cip, sip = self.send_recv(update_seed = True, validate = False)
281 assert_equal(cip, None)
282 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700283
284
A R Karthick10fe00e2016-07-12 16:13:16 -0700285 def test_dhcp_same_client_multiple_discover(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700286 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700287 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
288 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
289 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700290 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700291 cip, sip, mac, _ = self.dhcp.only_discover()
292 log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700293 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000294 assert_not_equal(cip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700295 log.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700296 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000297 assert_equal(new_cip, cip)
298 log.info('client got same IP as expected when sent 2nd discovery')
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700299
300
A R Karthick10fe00e2016-07-12 16:13:16 -0700301 def test_dhcp_same_client_multiple_request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700302 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700303 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
304 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
305 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700306 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700307 log.info('Sending DHCP discover and DHCP request.')
308 cip, sip = self.send_recv()
309 mac = self.dhcp.get_mac(cip)[0]
310 log.info("Sending DHCP request again.")
311 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000312 assert_equal(new_cip,cip)
313 log.info('server offered same IP to clain for multiple requests, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700314
A R Karthick10fe00e2016-07-12 16:13:16 -0700315 def test_dhcp_client_desired_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700316 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700317 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
318 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
319 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000320 self.dhcp = DHCPTest(seed_ip = '20.20.20.50', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700321 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000322 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700323 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000324 (cip, sip, mac))
325 assert_equal(cip,self.dhcp.seed_ip)
326 log.info('ONOS dhcp server offered client requested IP %s as expected'%self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700327
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000328 #test failing, server not returns NAK when requested out of pool IP
A R Karthick10fe00e2016-07-12 16:13:16 -0700329 def test_dhcp_client_desired_address_out_of_pool(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700330 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700331 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
332 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
333 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000334 self.dhcp = DHCPTest(seed_ip = '20.20.20.75', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700335 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000336 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700337 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700338 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000339 assert_not_equal(cip,self.dhcp.seed_ip)
340 log.info('server offered IP from its pool of IPs when requested out of pool IP, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700341
342
A R Karthick10fe00e2016-07-12 16:13:16 -0700343 def test_dhcp_server_nak_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700344 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700345 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
346 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
347 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700348 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700349 cip, sip, mac, _ = self.dhcp.only_discover()
350 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700351 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000352 assert_not_equal(cip, None)
353 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
354 assert_equal(new_cip, None) #Negative Test Case
355 log.info('dhcp servers sent NAK as expected when requested different IP from same client')
ChetanGaonker42d75812016-06-06 16:32:52 -0700356
357
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000358 #test_dhcp_lease_packet
359 def test_dhcp_client_requests_specific_lease_time_in_discover(self,lease_time = 700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700360 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700361 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
362 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
363 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700364 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000365 self.dhcp.return_option = 'lease'
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700366 log.info('Sending DHCP discover with lease time of 700')
Chetan Gaonker2499f172017-04-05 00:30:50 +0000367 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value = lease_time)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000368 assert_equal(lval, 700)
369 log.info('dhcp server offered IP address with client requested lease time')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700370
A R Karthick10fe00e2016-07-12 16:13:16 -0700371 def test_dhcp_client_request_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700372 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700373 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
374 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
375 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700376 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700377 cip, sip, mac, _ = self.dhcp.only_discover()
378 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700379 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000380 assert_not_equal(cip,None)
381 new_cip, new_sip = self.dhcp.only_request(cip, mac)
382 log.info('verifying client IP after reboot')
383 os.system('ifconfig '+self.iface+' down')
384 time.sleep(5)
385 os.system('ifconfig '+self.iface+' up')
386 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
387 assert_equal(new_cip,cip)
388 log.info('client got same ip after reboot, as expected')
Chetan Gaonker2499f172017-04-05 00:30:50 +0000389
ChetanGaonker42d75812016-06-06 16:32:52 -0700390
A R Karthick10fe00e2016-07-12 16:13:16 -0700391 def test_dhcp_server_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700392 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700393 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
394 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
395 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700396 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700397 cip, sip, mac, _ = self.dhcp.only_discover()
398 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700399 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000400 assert_not_equal(cip, None)
401 new_cip, new_sip = self.dhcp.only_request(cip, mac)
402 self.onos_ctrl.deactivate()
403 new_cip1, new_sip = self.dhcp.only_request(cip, mac)
404 assert_equal(new_cip1,None)
405 status, _ = self.onos_ctrl.activate()
406 assert_equal(status, True)
407 time.sleep(3)
408 new_cip2, new_sip = self.dhcp.only_request(cip, mac)
409 assert_equal(new_cip2,cip)
410 log.info('client got same ip after server reboot, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700411
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000412 def test_dhcp_specific_lease_time_only_in_discover_but_not_in_request_packet(self,lease_time=700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700413 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700414 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
415 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
416 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700417 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700418 log.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000419 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True,lease_value=lease_time)
ChetanGaonker42d75812016-06-06 16:32:52 -0700420 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700421 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000422 assert_not_equal(cip, None)
423 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
424 assert_equal(new_cip,cip)
425 assert_not_equal(lval, lease_time) #Negative Test Case
426 log.info('client requested lease time only in discover but not in request, not seen in server ACK packet as expected')
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700427
428
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000429 def test_dhcp_specific_lease_time_only_in_request_but_not_in_discover_packet(self,lease_time=800):
ChetanGaonker42d75812016-06-06 16:32:52 -0700430 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700431 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
432 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
433 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700434 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700435 cip, sip, mac, _ = self.dhcp.only_discover()
436 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700437 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000438 assert_not_equal(cip, None)
439 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True, lease_value=lease_time)
440 assert_equal(lval, lease_time)
441 log.info('client requested lease time in request packet, seen in server ACK packet as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700442
A R Karthick10fe00e2016-07-12 16:13:16 -0700443 def test_dhcp_client_renew_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700444
445 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700446 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
447 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
448 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700449 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700450 cip, sip, mac, _ = self.dhcp.only_discover()
451 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700452 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000453 assert_not_equal(cip, None)
454 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
Chetan Gaonker2499f172017-04-05 00:30:50 +0000455 log.info('waiting renew time %d seconds to send next request packet'%lval)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000456 time.sleep(lval)
457 latest_cip, latest_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
458 assert_equal(latest_cip,cip)
459 log.info('client got same IP after renew time, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700460
A R Karthick10fe00e2016-07-12 16:13:16 -0700461 def test_dhcp_client_rebind_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700462
463 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700464 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
465 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
466 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700467 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700468 cip, sip, mac, _ = self.dhcp.only_discover()
469 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700470 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000471 assert_not_equal(cip, None)
472 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
473 log.info('waiting rebind time %d seconds to send next request packet'%lval)
474 time.sleep(lval)
475 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
476 assert_equal(latest_cip,cip)
477 log.info('client got same IP after rebind time, as expected')
Chetan Gaonker717b2942016-05-13 17:42:59 -0700478
A R Karthick10fe00e2016-07-12 16:13:16 -0700479 def test_dhcp_client_expected_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700480
481 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -0700482 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
483 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
484 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700485 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700486 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700487 self.dhcp.return_option = 'subnet'
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000488 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
489 assert_equal(subnet_mask, expected_subnet)
490 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700491 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700492 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000493 log.info('seen expected subnet mask %s in dhcp offer packet'%subnet_mask)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700494
A R Karthick10fe00e2016-07-12 16:13:16 -0700495 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700496
497 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700498 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
499 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
500 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700501 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700502
503 cip, sip, mac, _ = self.dhcp.only_discover()
504 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700505 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000506 assert_not_equal(cip, None)
507 self.dhcp.send_different_option = 'subnet'
508 new_cip, new_sip = self.dhcp.only_request(cip, mac)
509 assert_equal(new_cip, cip)
510 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700511
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700512
A R Karthick10fe00e2016-07-12 16:13:16 -0700513 def test_dhcp_client_expected_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700514
515 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700516 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
517 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
518 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700519 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700520 expected_router_address = '20.20.20.1'
521 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700522
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000523 cip, sip, mac, router_address_ip = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700524 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700525 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000526 assert_not_equal(cip, None)
527 assert_equal(expected_router_address, router_address_ip)
528 log.info('seen expected rouer address %s ip in dhcp offer packet'%router_address_ip)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700529
A R Karthick10fe00e2016-07-12 16:13:16 -0700530 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700531
532 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700533 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
534 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
535 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700536 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700537
538 cip, sip, mac, _ = self.dhcp.only_discover()
539 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700540 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000541 assert_not_equal(cip, None)
542 self.dhcp.send_different_option = 'router'
543 new_cip, new_sip = self.dhcp.only_request(cip, mac)
544 assert_equal(new_cip, cip)
545 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700546
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700547
A R Karthick10fe00e2016-07-12 16:13:16 -0700548 def test_dhcp_client_expected_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700549
550 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700551 '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)
A R Karthick10fe00e2016-07-12 16:13:16 -0700554 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700555 expected_broadcast_address = '20.20.20.255'
556 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700557
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000558 cip, sip, mac, broadcast_address = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700559 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700560 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000561 assert_not_equal(cip, None)
562 assert_equal(expected_broadcast_address, broadcast_address)
563 log.info('seen expected broadcast address %s in dhcp offer packet'%broadcast_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700564
A R Karthick10fe00e2016-07-12 16:13:16 -0700565 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700566
567 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700568 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
569 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
570 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700571 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700572
573 cip, sip, mac, _ = self.dhcp.only_discover()
574 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700575 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000576 assert_not_equal(cip, None)
577 self.dhcp.send_different_option = 'broadcast_address'
578 new_cip, new_sip = self.dhcp.only_request(cip, mac)
579 assert_equal(new_cip, cip)
580 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700581
A R Karthick10fe00e2016-07-12 16:13:16 -0700582 def test_dhcp_client_expected_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700583
584 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700585 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
586 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
587 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700588 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700589 expected_dns_address = '8.8.8.8'
590 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700591
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000592 cip, sip, mac, dns_address = self.dhcp.only_discover()
593 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700594 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700595 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000596 assert_equal(expected_dns_address, dns_address)
597 log.info('seen expected DNS ip address %s in dhcp offer packet'%dns_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700598
A R Karthick10fe00e2016-07-12 16:13:16 -0700599 def test_dhcp_client_sends_request_with_wrong_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700600
601 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700602 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
603 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
604 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700605 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700606
607 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000608 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700609 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700610 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000611 self.dhcp.send_different_option = 'dns'
612 new_cip, new_sip = self.dhcp.only_request(cip, mac)
613 assert_equal(new_cip, cip)
614 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700615
A R Karthick10fe00e2016-07-12 16:13:16 -0700616 def test_dhcp_server_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700617
618 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700619 self.stats()
ChetanGaonker42d75812016-06-06 16:32:52 -0700620 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700621 log.info("----------------------------------------------------------------------------------")
622 log.info("No. of transactions No. of successes No. of failures Running Time ")
623 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
624 log.info("----------------------------------------------------------------------------------")
625 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
626
ChetanGaonker42d75812016-06-06 16:32:52 -0700627 log.info("Final Statistics for total transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700628 log.info("----------------------------------------------------------------------------------")
629 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700630 log.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700631 self.total_success, self.total_failure, self.running_time))
632 log.info("----------------------------------------------------------------------------------")
633 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
634
A R Karthick10fe00e2016-07-12 16:13:16 -0700635 def test_dhcp_server_consecutive_successes_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700636
637 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700638 self.stats(success_rate = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700639 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700640 log.info("----------------------------------------------------------------------------------")
641 log.info("No. of consecutive successful transactions Running Time ")
642 log.info(" %d %d " %(self.ip_count, self.diff))
643 log.info("----------------------------------------------------------------------------------")
644 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker42d75812016-06-06 16:32:52 -0700645 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700646
ChetanGaonker42d75812016-06-06 16:32:52 -0700647 log.info("Final Statistics for total successful transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700648 log.info("----------------------------------------------------------------------------------")
649 log.info("Total transactions Total No. of consecutive successes Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700650 log.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700651 self.total_success, self.running_time))
652 log.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700653 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
654 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700655
ChetanGaonker42d75812016-06-06 16:32:52 -0700656
A R Karthick10fe00e2016-07-12 16:13:16 -0700657 def test_dhcp_server_client_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700658
659 for i in range(1,4):
660 self.stats(only_discover = True)
661 log.info("----------------------------------------------------------------------------------")
662 log.info("Stats for run %d of sending only DHCP Discover",i)
663 log.info("----------------------------------------------------------------------------------")
664 log.info("No. of transactions No. of successes No. of failures Running Time ")
665 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
666 log.info("----------------------------------------------------------------------------------")
667 log.info("No. of clients per second in run %d:%f "
668 %(i, self.transaction_count))
669 log.info("----------------------------------------------------------------------------------")
670 log.info("Final Statistics for total transactions of sending only DHCP Discover")
671 log.info("----------------------------------------------------------------------------------")
672 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
673 log.info(" %d %d %d %d" %(self.transactions,
674 self.total_success, self.total_failure, self.running_time))
675 log.info("----------------------------------------------------------------------------------")
676 log.info("Average no. of clients per second: %d ",
677 round(self.transactions/self.running_time,0))
678 log.info("----------------------------------------------------------------------------------")
679
A R Karthick10fe00e2016-07-12 16:13:16 -0700680 def test_dhcp_server_consecutive_successful_clients_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700681
682 for i in range(1,4):
683 self.stats(success_rate = True, only_discover = True)
684 log.info("----------------------------------------------------------------------------------")
685 log.info("Stats for run %d for sending only DHCP Discover",i)
686 log.info("----------------------------------------------------------------------------------")
687 log.info("No. of consecutive successful transactions Running Time ")
688 log.info(" %d %d " %(self.ip_count, self.diff))
689 log.info("----------------------------------------------------------------------------------")
690 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
691 log.info("----------------------------------------------------------------------------------")
692
693 log.info("Final Statistics for total successful transactions")
694 log.info("----------------------------------------------------------------------------------")
695 log.info("Total transactions Total No. of consecutive successes Running Time ")
696 log.info(" %d %d %d " %(self.transactions,
697 self.total_success, self.running_time))
698 log.info("----------------------------------------------------------------------------------")
699 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
700 log.info("----------------------------------------------------------------------------------")
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000701