blob: 4b4a8c32c1ce44b97209c712695d56bc4c52e037 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
ChetanGaonker42d75812016-06-06 16:32:52 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
ChetanGaonker42d75812016-06-06 16:32:52 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonker42d75812016-06-06 16:32:52 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080032import unittest
33from nose.tools import *
34from nose.twistedtools import reactor, deferred
35from twisted.internet import defer
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080036import time
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080037import copy
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080038from DHCP import DHCPTest
A R Karthick10fe00e2016-07-12 16:13:16 -070039from OltConfig import *
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080040from OnosCtrl import OnosCtrl
A R Karthick10fe00e2016-07-12 16:13:16 -070041from portmaps import g_subscriber_port_map
A R Karthick9313b762016-11-07 13:14:35 -080042from CordLogger import CordLogger
A R Karthick9dc6e922017-07-12 14:40:16 -070043from CordTestConfig import setup_module, teardown_module
A R Karthick76a497a2017-04-12 10:59:39 -070044from CordTestUtils import log_test
45log_test.setLevel('INFO')
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080046
A R Karthick9313b762016-11-07 13:14:35 -080047class dhcp_exchange(CordLogger):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080048
49 dhcp_server_config = {
50 "ip": "10.1.11.50",
51 "mac": "ca:fe:ca:fe:ca:fe",
52 "subnet": "255.255.252.0",
53 "broadcast": "10.1.11.255",
54 "router": "10.1.8.1",
55 "domain": "8.8.8.8",
56 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080057 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080058 "startip": "10.1.11.51",
59 "endip": "10.1.11.100"
60 }
ChetanGaonker42d75812016-06-06 16:32:52 -070061
Chetan Gaonker2499f172017-04-05 00:30:50 +000062 STARTIP = "10.10.10.40"
63 ENDIP = "10.10.10.41"
64 IP = "10.10.10.2"
65 MAC = "ca:fe:ca:fe:ca:fe"
66 SUBNET = "255.255.255.0"
67 BROADCAST = "10.10.10.255"
68 ROUTER = "10.10.10.1"
69
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080070 app = 'org.onosproject.dhcp'
71
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070072 ip_count = 0
73 failure_count = 0
74 start_time = 0
75 diff = 0
76
77 transaction_count = 0
78 transactions = 0
79 running_time = 0
80 total_success = 0
81 total_failure = 0
82
A R Karthick10fe00e2016-07-12 16:13:16 -070083 @classmethod
84 def setUpClass(cls):
Chetan Gaonker2499f172017-04-05 00:30:50 +000085 cls.config_dhcp = {'startip': cls.STARTIP, 'endip': cls.ENDIP,
86 'ip':cls.IP, 'mac': cls.MAC, 'subnet': cls.SUBNET,
87 'broadcast':cls.BROADCAST, 'router':cls.ROUTER}
A R Karthick10fe00e2016-07-12 16:13:16 -070088 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070089 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick10fe00e2016-07-12 16:13:16 -070090 if not cls.port_map:
91 cls.port_map = g_subscriber_port_map
92 cls.iface = cls.port_map[1]
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070093
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080094 def setUp(self):
95 ''' Activate the dhcp app'''
A R Karthick9313b762016-11-07 13:14:35 -080096 super(dhcp_exchange, self).setUp()
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080097 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080098 self.onos_ctrl = OnosCtrl(self.app)
99 status, _ = self.onos_ctrl.activate()
100 assert_equal(status, True)
101 time.sleep(3)
102
A R Karthick9313b762016-11-07 13:14:35 -0800103 def tearDown(self):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800104 '''Deactivate the dhcp app'''
105 self.onos_ctrl.deactivate()
A R Karthick9313b762016-11-07 13:14:35 -0800106 super(dhcp_exchange, self).tearDown()
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800107
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800108 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -0700109 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800110 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700111 log_test.info('JSON request returned status %d' %code)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800112 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800113 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800114
115 def onos_dhcp_table_load(self, config = None):
116 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
117 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
118 if config:
119 for k in config.keys():
120 if dhcp_config.has_key(k):
121 dhcp_config[k] = config[k]
122 self.onos_load_config(dhcp_dict)
123
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700124 def send_recv(self, mac = None, update_seed = False, validate = True):
125 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
A R Karthick76a497a2017-04-12 10:59:39 -0700126 log_test.info("discover cip %s"%(cip))
127 log_test.info("discover sip %s"%(sip))
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700128 if validate:
129 assert_not_equal(cip, None)
130 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700131 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700132 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800133 return cip,sip
134
A R Karthick10fe00e2016-07-12 16:13:16 -0700135 def stats(self,success_rate = False, only_discover = False):
ChetanGaonker42d75812016-06-06 16:32:52 -0700136
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700137 self.ip_count = 0
138 self.failure_count = 0
139 self.start_time = 0
140 self.diff = 0
141 self.transaction_count = 0
ChetanGaonker42d75812016-06-06 16:32:52 -0700142 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700143 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
144 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
145 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700146 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700147 self.start_time = time.time()
148
149 while self.diff <= 60:
ChetanGaonker42d75812016-06-06 16:32:52 -0700150 if only_discover:
151 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700152 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker42d75812016-06-06 16:32:52 -0700153 (cip, sip, mac))
154 else:
155 cip, sip = self.send_recv(update_seed = True, validate = False)
156
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700157 if cip:
158 self.ip_count +=1
159 elif cip == None:
160 self.failure_count += 1
A R Karthick76a497a2017-04-12 10:59:39 -0700161 log_test.info('Failed to get ip')
ChetanGaonker42d75812016-06-06 16:32:52 -0700162 if success_rate and self.ip_count > 0:
163 break
164 self.diff = round(time.time() - self.start_time, 0)
165
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700166
167 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
168
169 self.transactions += (self.ip_count+self.failure_count)
170 self.running_time += self.diff
171 self.total_success += self.ip_count
172 self.total_failure += self.failure_count
173
A R Karthick10fe00e2016-07-12 16:13:16 -0700174 def test_dhcp_1request(self):
Chetan Gaonker2499f172017-04-05 00:30:50 +0000175 self.onos_dhcp_table_load(self.config_dhcp)
A R Karthick10fe00e2016-07-12 16:13:16 -0700176 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Anil Kumar Sanka50998902016-12-13 12:10:25 +0530177 self.send_recv()
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800178
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000179 def test_dhcp_1request_with_invalid_source_mac_broadcast(self):
180 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
181 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
182 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
183 self.onos_dhcp_table_load(config)
184 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
185 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
186 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700187 log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000188
189 def test_dhcp_1request_with_invalid_source_mac_multicast(self):
190 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
191 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
192 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
193 self.onos_dhcp_table_load(config)
194 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
195 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:91:02:e4')
196 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700197 log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000198
199 def test_dhcp_1request_with_invalid_source_mac_zero(self):
200 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
201 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
202 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
203 self.onos_dhcp_table_load(config)
204 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
205 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
206 assert_equal(cip,None)
A R Karthick76a497a2017-04-12 10:59:39 -0700207 log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000208
Chetan Gaonker2499f172017-04-05 00:30:50 +0000209 def test_dhcp_Nrequest(self, requests=10):
ChetanGaonker42d75812016-06-06 16:32:52 -0700210 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800211 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
212 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
213 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000214 self.dhcp = DHCPTest(seed_ip = '192.168.1.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800215 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000216 for i in range(requests):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800217 cip, sip = self.send_recv(update_seed = True)
218 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700219 log_test.info('IP %s given out multiple times' %cip)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800220 assert_equal(False, ip_map.has_key(cip))
221 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800222
A R Karthick10fe00e2016-07-12 16:13:16 -0700223 def test_dhcp_1release(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000224 config = {'startip':'10.10.100.20', 'endip':'10.10.100.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800225 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
226 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.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 = '10.10.100.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800229 cip, sip = self.send_recv()
A R Karthick76a497a2017-04-12 10:59:39 -0700230 log_test.info('Releasing ip %s to server %s' %(cip, sip))
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800231 assert_equal(self.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -0700232 log_test.info('Triggering DHCP discover again after release')
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800233 cip2, sip2 = self.send_recv(update_seed = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700234 log_test.info('Verifying released IP was given back on rediscover')
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800235 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -0700236 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800237 assert_equal(self.dhcp.release(cip2), True)
238
A R Karthick10fe00e2016-07-12 16:13:16 -0700239 def test_dhcp_Nrelease(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000240 config = {'startip':'192.170.1.20', 'endip':'192.170.1.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800241 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
242 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800243 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700244 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800245 ip_map = {}
246 for i in range(10):
247 cip, sip = self.send_recv(update_seed = True)
248 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700249 log_test.info('IP %s given out multiple times' %cip)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800250 assert_equal(False, ip_map.has_key(cip))
251 ip_map[cip] = sip
252
253 for ip in ip_map.keys():
A R Karthick76a497a2017-04-12 10:59:39 -0700254 log_test.info('Releasing IP %s' %ip)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800255 assert_equal(self.dhcp.release(ip), True)
256
257 ip_map2 = {}
A R Karthick76a497a2017-04-12 10:59:39 -0700258 log_test.info('Triggering DHCP discover again after release')
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800259 for i in range(len(ip_map.keys())):
260 cip, sip = self.send_recv(update_seed = True)
261 ip_map2[cip] = sip
262
A R Karthick76a497a2017-04-12 10:59:39 -0700263 log_test.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800264 if ip_map != ip_map2:
A R Karthick76a497a2017-04-12 10:59:39 -0700265 log_test.info('Map before release %s' %ip_map)
266 log_test.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800267 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700268
269
Chetan Gaonker62091182017-04-05 17:36:14 -0500270 def test_dhcp_starvation_positive_scenario(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700271 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700272 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
273 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
274 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700275 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700276 ip_map = {}
277 for i in range(10):
278 cip, sip = self.send_recv(update_seed = True)
279 if ip_map.has_key(cip):
A R Karthick76a497a2017-04-12 10:59:39 -0700280 log_test.info('IP %s given out multiple times' %cip)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700281 assert_equal(False, ip_map.has_key(cip))
282 ip_map[cip] = sip
283
284
Chetan Gaonker62091182017-04-05 17:36:14 -0500285 def test_dhcp_starvation_negative_scenario(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700286 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700287 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
288 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
289 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700290 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700291 log_test.info('Verifying passitive case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700292 for x in xrange(50):
293 mac = RandMAC()._fix()
294 self.send_recv(mac = mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700295 log_test.info('Verifying negative case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700296 cip, sip = self.send_recv(update_seed = True, validate = False)
297 assert_equal(cip, None)
298 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700299
300
A R Karthick10fe00e2016-07-12 16:13:16 -0700301 def test_dhcp_same_client_multiple_discover(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)
ChetanGaonker42d75812016-06-06 16:32:52 -0700307 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700308 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700309 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000310 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700311 log_test.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700312 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000313 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700314 log_test.info('client got same IP as expected when sent 2nd discovery')
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700315
316
A R Karthick10fe00e2016-07-12 16:13:16 -0700317 def test_dhcp_same_client_multiple_request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700318 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700319 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
320 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
321 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700322 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700323 log_test.info('Sending DHCP discover and DHCP request.')
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700324 cip, sip = self.send_recv()
325 mac = self.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -0700326 log_test.info("Sending DHCP request again.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700327 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000328 assert_equal(new_cip,cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700329 log_test.info('server offered same IP to clain for multiple requests, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700330
A R Karthick10fe00e2016-07-12 16:13:16 -0700331 def test_dhcp_client_desired_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700332 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700333 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
334 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
335 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000336 self.dhcp = DHCPTest(seed_ip = '20.20.20.50', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700337 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000338 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700339 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000340 (cip, sip, mac))
341 assert_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700342 log_test.info('ONOS dhcp server offered client requested IP %s as expected'%self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700343
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000344 #test failing, server not returns NAK when requested out of pool IP
A R Karthick10fe00e2016-07-12 16:13:16 -0700345 def test_dhcp_client_desired_address_out_of_pool(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700346 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700347 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
348 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
349 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000350 self.dhcp = DHCPTest(seed_ip = '20.20.20.75', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700351 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000352 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700353 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700354 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000355 assert_not_equal(cip,self.dhcp.seed_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700356 log_test.info('server offered IP from its pool of IPs when requested out of pool IP, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700357
358
A R Karthick10fe00e2016-07-12 16:13:16 -0700359 def test_dhcp_server_nak_packet(self):
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)
ChetanGaonker42d75812016-06-06 16:32:52 -0700365 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700366 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700367 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000368 assert_not_equal(cip, None)
369 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
370 assert_equal(new_cip, None) #Negative Test Case
A R Karthick76a497a2017-04-12 10:59:39 -0700371 log_test.info('dhcp servers sent NAK as expected when requested different IP from same client')
ChetanGaonker42d75812016-06-06 16:32:52 -0700372
373
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000374 #test_dhcp_lease_packet
375 def test_dhcp_client_requests_specific_lease_time_in_discover(self,lease_time = 700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700376 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700377 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
378 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
379 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700380 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000381 self.dhcp.return_option = 'lease'
A R Karthick76a497a2017-04-12 10:59:39 -0700382 log_test.info('Sending DHCP discover with lease time of 700')
Chetan Gaonker2499f172017-04-05 00:30:50 +0000383 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value = lease_time)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000384 assert_equal(lval, 700)
A R Karthick76a497a2017-04-12 10:59:39 -0700385 log_test.info('dhcp server offered IP address with client requested lease time')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700386
A R Karthick10fe00e2016-07-12 16:13:16 -0700387 def test_dhcp_client_request_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700388 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700389 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
390 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
391 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700392 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700393 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700394 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700395 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000396 assert_not_equal(cip,None)
397 new_cip, new_sip = self.dhcp.only_request(cip, mac)
A R Karthick76a497a2017-04-12 10:59:39 -0700398 log_test.info('verifying client IP after reboot')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000399 os.system('ifconfig '+self.iface+' down')
400 time.sleep(5)
401 os.system('ifconfig '+self.iface+' up')
402 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
403 assert_equal(new_cip,cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700404 log_test.info('client got same ip after reboot, as expected')
Chetan Gaonker2499f172017-04-05 00:30:50 +0000405
ChetanGaonker42d75812016-06-06 16:32:52 -0700406
A R Karthick10fe00e2016-07-12 16:13:16 -0700407 def test_dhcp_server_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700408 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700409 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
410 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
411 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700412 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700413 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700414 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700415 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000416 assert_not_equal(cip, None)
417 new_cip, new_sip = self.dhcp.only_request(cip, mac)
418 self.onos_ctrl.deactivate()
419 new_cip1, new_sip = self.dhcp.only_request(cip, mac)
420 assert_equal(new_cip1,None)
421 status, _ = self.onos_ctrl.activate()
422 assert_equal(status, True)
423 time.sleep(3)
424 new_cip2, new_sip = self.dhcp.only_request(cip, mac)
425 assert_equal(new_cip2,cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700426 log_test.info('client got same ip after server reboot, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700427
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000428 def test_dhcp_specific_lease_time_only_in_discover_but_not_in_request_packet(self,lease_time=700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700429 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700430 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
431 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
432 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700433 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700434 log_test.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000435 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True,lease_value=lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700436 log_test.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)
440 assert_equal(new_cip,cip)
441 assert_not_equal(lval, lease_time) #Negative Test Case
A R Karthick76a497a2017-04-12 10:59:39 -0700442 log_test.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 -0700443
444
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000445 def test_dhcp_specific_lease_time_only_in_request_but_not_in_discover_packet(self,lease_time=800):
ChetanGaonker42d75812016-06-06 16:32:52 -0700446 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700447 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
448 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
449 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700450 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700451 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700452 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700453 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000454 assert_not_equal(cip, None)
455 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True, lease_value=lease_time)
456 assert_equal(lval, lease_time)
A R Karthick76a497a2017-04-12 10:59:39 -0700457 log_test.info('client requested lease time in request packet, seen in server ACK packet as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700458
A R Karthick10fe00e2016-07-12 16:13:16 -0700459 def test_dhcp_client_renew_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700460
461 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700462 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
463 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
464 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700465 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700466 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700467 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700468 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000469 assert_not_equal(cip, None)
470 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700471 log_test.info('waiting renew time %d seconds to send next request packet'%lval)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000472 time.sleep(lval)
473 latest_cip, latest_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
474 assert_equal(latest_cip,cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700475 log_test.info('client got same IP after renew time, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700476
A R Karthick10fe00e2016-07-12 16:13:16 -0700477 def test_dhcp_client_rebind_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700478
479 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700480 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
481 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
482 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700483 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700484 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700485 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700486 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000487 assert_not_equal(cip, None)
488 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700489 log_test.info('waiting rebind time %d seconds to send next request packet'%lval)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000490 time.sleep(lval)
491 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
492 assert_equal(latest_cip,cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700493 log_test.info('client got same IP after rebind time, as expected')
Chetan Gaonker717b2942016-05-13 17:42:59 -0700494
A R Karthick10fe00e2016-07-12 16:13:16 -0700495 def test_dhcp_client_expected_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700496
497 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -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)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700502 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700503 self.dhcp.return_option = 'subnet'
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000504 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
505 assert_equal(subnet_mask, expected_subnet)
506 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700507 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700508 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -0700509 log_test.info('seen expected subnet mask %s in dhcp offer packet'%subnet_mask)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700510
A R Karthick10fe00e2016-07-12 16:13:16 -0700511 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700512
513 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700514 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
515 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
516 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700517 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700518
519 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700520 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700521 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000522 assert_not_equal(cip, None)
523 self.dhcp.send_different_option = 'subnet'
524 new_cip, new_sip = self.dhcp.only_request(cip, mac)
525 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700526 log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700527
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700528
A R Karthick10fe00e2016-07-12 16:13:16 -0700529 def test_dhcp_client_expected_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700530
531 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700532 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
533 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
534 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700535 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700536 expected_router_address = '20.20.20.1'
537 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700538
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000539 cip, sip, mac, router_address_ip = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700540 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700541 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000542 assert_not_equal(cip, None)
543 assert_equal(expected_router_address, router_address_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700544 log_test.info('seen expected rouer address %s ip in dhcp offer packet'%router_address_ip)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700545
A R Karthick10fe00e2016-07-12 16:13:16 -0700546 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700547
548 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700549 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
550 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
551 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700552 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700553
554 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700555 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700556 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000557 assert_not_equal(cip, None)
558 self.dhcp.send_different_option = 'router'
559 new_cip, new_sip = self.dhcp.only_request(cip, mac)
560 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700561 log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700562
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700563
A R Karthick10fe00e2016-07-12 16:13:16 -0700564 def test_dhcp_client_expected_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700565
566 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700567 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
568 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
569 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700570 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700571 expected_broadcast_address = '20.20.20.255'
572 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700573
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000574 cip, sip, mac, broadcast_address = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700575 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700576 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000577 assert_not_equal(cip, None)
578 assert_equal(expected_broadcast_address, broadcast_address)
A R Karthick76a497a2017-04-12 10:59:39 -0700579 log_test.info('seen expected broadcast address %s in dhcp offer packet'%broadcast_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700580
A R Karthick10fe00e2016-07-12 16:13:16 -0700581 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700582
583 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700584 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
585 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
586 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700587 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700588
589 cip, sip, mac, _ = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -0700590 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700591 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000592 assert_not_equal(cip, None)
593 self.dhcp.send_different_option = 'broadcast_address'
594 new_cip, new_sip = self.dhcp.only_request(cip, mac)
595 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700596 log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700597
A R Karthick10fe00e2016-07-12 16:13:16 -0700598 def test_dhcp_client_expected_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700599
600 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700601 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
602 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
603 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700604 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700605 expected_dns_address = '8.8.8.8'
606 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700607
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000608 cip, sip, mac, dns_address = self.dhcp.only_discover()
609 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700610 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700611 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000612 assert_equal(expected_dns_address, dns_address)
A R Karthick76a497a2017-04-12 10:59:39 -0700613 log_test.info('seen expected DNS ip address %s in dhcp offer packet'%dns_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700614
A R Karthick10fe00e2016-07-12 16:13:16 -0700615 def test_dhcp_client_sends_request_with_wrong_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700616
617 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700618 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
619 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
620 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700621 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700622
623 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000624 assert_not_equal(cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -0700625 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700626 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000627 self.dhcp.send_different_option = 'dns'
628 new_cip, new_sip = self.dhcp.only_request(cip, mac)
629 assert_equal(new_cip, cip)
A R Karthick76a497a2017-04-12 10:59:39 -0700630 log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700631
A R Karthick10fe00e2016-07-12 16:13:16 -0700632 def test_dhcp_server_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700633
634 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700635 self.stats()
A R Karthick76a497a2017-04-12 10:59:39 -0700636 log_test.info("Stats for run %d",i)
637 log_test.info("----------------------------------------------------------------------------------")
638 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
639 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
640 log_test.info("----------------------------------------------------------------------------------")
641 log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700642
A R Karthick76a497a2017-04-12 10:59:39 -0700643 log_test.info("Final Statistics for total transactions")
644 log_test.info("----------------------------------------------------------------------------------")
645 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
646 log_test.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700647 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -0700648 log_test.info("----------------------------------------------------------------------------------")
649 log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700650
A R Karthick10fe00e2016-07-12 16:13:16 -0700651 def test_dhcp_server_consecutive_successes_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700652
653 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700654 self.stats(success_rate = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700655 log_test.info("Stats for run %d",i)
656 log_test.info("----------------------------------------------------------------------------------")
657 log_test.info("No. of consecutive successful transactions Running Time ")
658 log_test.info(" %d %d " %(self.ip_count, self.diff))
659 log_test.info("----------------------------------------------------------------------------------")
660 log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
661 log_test.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700662
A R Karthick76a497a2017-04-12 10:59:39 -0700663 log_test.info("Final Statistics for total successful transactions")
664 log_test.info("----------------------------------------------------------------------------------")
665 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
666 log_test.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700667 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -0700668 log_test.info("----------------------------------------------------------------------------------")
669 log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
670 log_test.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700671
ChetanGaonker42d75812016-06-06 16:32:52 -0700672
A R Karthick10fe00e2016-07-12 16:13:16 -0700673 def test_dhcp_server_client_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700674
675 for i in range(1,4):
676 self.stats(only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700677 log_test.info("----------------------------------------------------------------------------------")
678 log_test.info("Stats for run %d of sending only DHCP Discover",i)
679 log_test.info("----------------------------------------------------------------------------------")
680 log_test.info("No. of transactions No. of successes No. of failures Running Time ")
681 log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
682 log_test.info("----------------------------------------------------------------------------------")
683 log_test.info("No. of clients per second in run %d:%f "
ChetanGaonker42d75812016-06-06 16:32:52 -0700684 %(i, self.transaction_count))
A R Karthick76a497a2017-04-12 10:59:39 -0700685 log_test.info("----------------------------------------------------------------------------------")
686 log_test.info("Final Statistics for total transactions of sending only DHCP Discover")
687 log_test.info("----------------------------------------------------------------------------------")
688 log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ")
689 log_test.info(" %d %d %d %d" %(self.transactions,
ChetanGaonker42d75812016-06-06 16:32:52 -0700690 self.total_success, self.total_failure, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -0700691 log_test.info("----------------------------------------------------------------------------------")
692 log_test.info("Average no. of clients per second: %d ",
ChetanGaonker42d75812016-06-06 16:32:52 -0700693 round(self.transactions/self.running_time,0))
A R Karthick76a497a2017-04-12 10:59:39 -0700694 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700695
A R Karthick10fe00e2016-07-12 16:13:16 -0700696 def test_dhcp_server_consecutive_successful_clients_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700697
698 for i in range(1,4):
699 self.stats(success_rate = True, only_discover = True)
A R Karthick76a497a2017-04-12 10:59:39 -0700700 log_test.info("----------------------------------------------------------------------------------")
701 log_test.info("Stats for run %d for sending only DHCP Discover",i)
702 log_test.info("----------------------------------------------------------------------------------")
703 log_test.info("No. of consecutive successful transactions Running Time ")
704 log_test.info(" %d %d " %(self.ip_count, self.diff))
705 log_test.info("----------------------------------------------------------------------------------")
706 log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
707 log_test.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700708
A R Karthick76a497a2017-04-12 10:59:39 -0700709 log_test.info("Final Statistics for total successful transactions")
710 log_test.info("----------------------------------------------------------------------------------")
711 log_test.info("Total transactions Total No. of consecutive successes Running Time ")
712 log_test.info(" %d %d %d " %(self.transactions,
ChetanGaonker42d75812016-06-06 16:32:52 -0700713 self.total_success, self.running_time))
A R Karthick76a497a2017-04-12 10:59:39 -0700714 log_test.info("----------------------------------------------------------------------------------")
715 log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
716 log_test.info("----------------------------------------------------------------------------------")