blob: e117d684ccfdfc7a9731b104fd65dd73d86ee20c [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 Gaonkerb2bd8242016-03-03 15:39:24 -080028log.setLevel('INFO')
29
A R Karthick9313b762016-11-07 13:14:35 -080030class dhcp_exchange(CordLogger):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080031
32 dhcp_server_config = {
33 "ip": "10.1.11.50",
34 "mac": "ca:fe:ca:fe:ca:fe",
35 "subnet": "255.255.252.0",
36 "broadcast": "10.1.11.255",
37 "router": "10.1.8.1",
38 "domain": "8.8.8.8",
39 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080040 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080041 "startip": "10.1.11.51",
42 "endip": "10.1.11.100"
43 }
ChetanGaonker42d75812016-06-06 16:32:52 -070044
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080045 app = 'org.onosproject.dhcp'
46
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070047 ip_count = 0
48 failure_count = 0
49 start_time = 0
50 diff = 0
51
52 transaction_count = 0
53 transactions = 0
54 running_time = 0
55 total_success = 0
56 total_failure = 0
57
A R Karthick10fe00e2016-07-12 16:13:16 -070058 @classmethod
59 def setUpClass(cls):
60 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070061 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick10fe00e2016-07-12 16:13:16 -070062 if not cls.port_map:
63 cls.port_map = g_subscriber_port_map
64 cls.iface = cls.port_map[1]
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070065
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080066 def setUp(self):
67 ''' Activate the dhcp app'''
A R Karthick9313b762016-11-07 13:14:35 -080068 super(dhcp_exchange, self).setUp()
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080069 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080070 self.onos_ctrl = OnosCtrl(self.app)
71 status, _ = self.onos_ctrl.activate()
72 assert_equal(status, True)
73 time.sleep(3)
74
A R Karthick9313b762016-11-07 13:14:35 -080075 def tearDown(self):
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080076 '''Deactivate the dhcp app'''
77 self.onos_ctrl.deactivate()
A R Karthick9313b762016-11-07 13:14:35 -080078 super(dhcp_exchange, self).tearDown()
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080079
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080080 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070081 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080082 if status is False:
83 log.info('JSON request returned status %d' %code)
84 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080085 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080086
87 def onos_dhcp_table_load(self, config = None):
88 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
89 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
90 if config:
91 for k in config.keys():
92 if dhcp_config.has_key(k):
93 dhcp_config[k] = config[k]
94 self.onos_load_config(dhcp_dict)
95
Chetan Gaonker6c68e912016-04-15 17:22:14 -070096 def send_recv(self, mac = None, update_seed = False, validate = True):
97 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
98 if validate:
99 assert_not_equal(cip, None)
100 assert_not_equal(sip, None)
101 log.info('Got dhcp client IP %s from server %s for mac %s' %
102 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800103 return cip,sip
104
A R Karthick10fe00e2016-07-12 16:13:16 -0700105 def stats(self,success_rate = False, only_discover = False):
ChetanGaonker42d75812016-06-06 16:32:52 -0700106
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700107 self.ip_count = 0
108 self.failure_count = 0
109 self.start_time = 0
110 self.diff = 0
111 self.transaction_count = 0
ChetanGaonker42d75812016-06-06 16:32:52 -0700112 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700113 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
114 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
115 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700116 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700117 self.start_time = time.time()
118
119 while self.diff <= 60:
ChetanGaonker42d75812016-06-06 16:32:52 -0700120 if only_discover:
121 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
122 log.info('Got dhcp client IP %s from server %s for mac %s' %
123 (cip, sip, mac))
124 else:
125 cip, sip = self.send_recv(update_seed = True, validate = False)
126
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700127 if cip:
128 self.ip_count +=1
129 elif cip == None:
130 self.failure_count += 1
131 log.info('Failed to get ip')
ChetanGaonker42d75812016-06-06 16:32:52 -0700132 if success_rate and self.ip_count > 0:
133 break
134 self.diff = round(time.time() - self.start_time, 0)
135
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700136
137 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
138
139 self.transactions += (self.ip_count+self.failure_count)
140 self.running_time += self.diff
141 self.total_success += self.ip_count
142 self.total_failure += self.failure_count
143
A R Karthick10fe00e2016-07-12 16:13:16 -0700144 def test_dhcp_1request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700145 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800146 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800147 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
148 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700149 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800150 self.send_recv()
151
A R Karthick10fe00e2016-07-12 16:13:16 -0700152 def test_dhcp_Nrequest(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700153 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800154 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
155 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
156 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700157 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800158 ip_map = {}
159 for i in range(10):
160 cip, sip = self.send_recv(update_seed = True)
161 if ip_map.has_key(cip):
162 log.info('IP %s given out multiple times' %cip)
163 assert_equal(False, ip_map.has_key(cip))
164 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800165
A R Karthick10fe00e2016-07-12 16:13:16 -0700166 def test_dhcp_1release(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700167 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800168 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
169 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800170 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700171 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800172 cip, sip = self.send_recv()
173 log.info('Releasing ip %s to server %s' %(cip, sip))
174 assert_equal(self.dhcp.release(cip), True)
175 log.info('Triggering DHCP discover again after release')
176 cip2, sip2 = self.send_recv(update_seed = True)
177 log.info('Verifying released IP was given back on rediscover')
178 assert_equal(cip, cip2)
179 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
180 assert_equal(self.dhcp.release(cip2), True)
181
A R Karthick10fe00e2016-07-12 16:13:16 -0700182 def test_dhcp_Nrelease(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700183 config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800184 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
185 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800186 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700187 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800188 ip_map = {}
189 for i in range(10):
190 cip, sip = self.send_recv(update_seed = True)
191 if ip_map.has_key(cip):
192 log.info('IP %s given out multiple times' %cip)
193 assert_equal(False, ip_map.has_key(cip))
194 ip_map[cip] = sip
195
196 for ip in ip_map.keys():
197 log.info('Releasing IP %s' %ip)
198 assert_equal(self.dhcp.release(ip), True)
199
200 ip_map2 = {}
201 log.info('Triggering DHCP discover again after release')
202 for i in range(len(ip_map.keys())):
203 cip, sip = self.send_recv(update_seed = True)
204 ip_map2[cip] = sip
205
206 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800207 if ip_map != ip_map2:
208 log.info('Map before release %s' %ip_map)
209 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800210 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700211
212
A R Karthick10fe00e2016-07-12 16:13:16 -0700213 def test_dhcp_starvation(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700214 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700215 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
216 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
217 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700218 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700219 ip_map = {}
220 for i in range(10):
221 cip, sip = self.send_recv(update_seed = True)
222 if ip_map.has_key(cip):
223 log.info('IP %s given out multiple times' %cip)
224 assert_equal(False, ip_map.has_key(cip))
225 ip_map[cip] = sip
226
227
A R Karthick10fe00e2016-07-12 16:13:16 -0700228 def test_dhcp_starvation(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700229 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700230 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
231 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
232 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700233 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700234 log.info('Verifying 1 ')
235 for x in xrange(50):
236 mac = RandMAC()._fix()
237 self.send_recv(mac = mac)
238 log.info('Verifying 2 ')
239 cip, sip = self.send_recv(update_seed = True, validate = False)
240 assert_equal(cip, None)
241 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700242
243
A R Karthick10fe00e2016-07-12 16:13:16 -0700244 def test_dhcp_same_client_multiple_discover(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700245 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700246 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
247 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
248 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700249 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700250 cip, sip, mac, _ = self.dhcp.only_discover()
251 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 -0700252 (cip, sip, mac) )
253 log.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700254 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700255 if cip == new_cip:
256 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
257 % (new_cip, new_sip, new_mac) )
258 elif cip != new_cip:
259 log.info('Ip after 1st discover %s' %cip)
260 log.info('Map after 2nd discover %s' %new_cip)
261 assert_equal(cip, new_cip)
262
263
A R Karthick10fe00e2016-07-12 16:13:16 -0700264 def test_dhcp_same_client_multiple_request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700265 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700266 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
267 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
268 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700269 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700270 log.info('Sending DHCP discover and DHCP request.')
271 cip, sip = self.send_recv()
272 mac = self.dhcp.get_mac(cip)[0]
273 log.info("Sending DHCP request again.")
274 new_cip, new_sip = self.dhcp.only_request(cip, mac)
275 if (new_cip,new_sip) == (cip,sip):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700276 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
277 % (new_cip, new_sip, mac) )
278 elif (new_cip,new_sip):
ChetanGaonker42d75812016-06-06 16:32:52 -0700279 log.info('No DHCP ACK')
280 assert_equal(new_cip, None)
281 assert_equal(new_sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700282 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700283 log.info('Something went wrong.')
284
A R Karthick10fe00e2016-07-12 16:13:16 -0700285 def test_dhcp_client_desired_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700286 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700287 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
288 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
289 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700290 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700291 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
292 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700293 (cip, sip, mac) )
294 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700295 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700296 (cip, sip, mac) )
297 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700298 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700299 (cip, sip, mac) )
300 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
301 assert_equal(cip, self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700302
A R Karthick10fe00e2016-07-12 16:13:16 -0700303 def test_dhcp_client_desired_address_out_of_pool(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700304 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700305 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
306 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
307 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700308 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700309 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
310 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700311 (cip, sip, mac) )
312 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700313 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700314 (cip, sip, mac) )
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700315 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700316 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700317 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700318 (cip, sip, mac) )
319 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700320 assert_not_equal(cip, self.dhcp.seed_ip)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700321 elif cip == None:
322 log.info('Got DHCP NAK')
ChetanGaonker42d75812016-06-06 16:32:52 -0700323
324
A R Karthick10fe00e2016-07-12 16:13:16 -0700325 def test_dhcp_server_nak_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700326 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700327 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
328 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
329 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700330 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700331 cip, sip, mac, _ = self.dhcp.only_discover()
332 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700333 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700334
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700335 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
336 if (cip == None and mac != None):
337 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
338 assert_not_equal(cip, None)
339 else:
340 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
341 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700342
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700343 log.info("Got DHCP server NAK.")
344 assert_equal(new_cip, None) #Negative Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700345
346
A R Karthick10fe00e2016-07-12 16:13:16 -0700347 def test_dhcp_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700348 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700349 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
350 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
351 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700352 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700353 log.info('Sending DHCP discover with lease time of 700')
354 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
355
356 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
357 if (cip == None and mac != None):
358 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
359 assert_not_equal(cip, None)
360 elif lval != 700:
ChetanGaonker42d75812016-06-06 16:32:52 -0700361 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700362 (cip, sip, mac, lval) )
363 assert_not_equal(lval, 700)
364
A R Karthick10fe00e2016-07-12 16:13:16 -0700365 def test_dhcp_client_request_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700366 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700367 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
368 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
369 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700370 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700371 cip, sip, mac, _ = self.dhcp.only_discover()
372 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700373 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700374
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700375 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700376
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700377 if (cip == None and mac != None):
378 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
379 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700380
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700381 else:
382 new_cip, new_sip = self.dhcp.only_request(cip, mac)
383 if new_cip == None:
384 log.info("Got DHCP server NAK.")
A R Karthick10fe00e2016-07-12 16:13:16 -0700385 os.system('ifconfig '+self.iface+' down')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700386 log.info('Client goes down.')
387 log.info('Delay for 5 seconds.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700388
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700389 time.sleep(5)
ChetanGaonker42d75812016-06-06 16:32:52 -0700390
A R Karthick10fe00e2016-07-12 16:13:16 -0700391 os.system('ifconfig '+self.iface+' up')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700392 log.info('Client is up now.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700393
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700394 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700395 if new_cip == None:
396 log.info("Got DHCP server NAK.")
397 assert_not_equal(new_cip, None)
398 elif new_cip != None:
399 log.info("Got DHCP ACK.")
A R Karthick10fe00e2016-07-12 16:13:16 -0700400 os.system('ifconfig '+self.iface+' up')
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700401
ChetanGaonker42d75812016-06-06 16:32:52 -0700402
403
404
A R Karthick10fe00e2016-07-12 16:13:16 -0700405 def test_dhcp_server_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700406 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700407 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
408 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
409 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700410 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700411 cip, sip, mac, _ = self.dhcp.only_discover()
412 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700413 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700414
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700415 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700416
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700417 if (cip == None and mac != None):
418 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
419 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700420
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700421 else:
422 new_cip, new_sip = self.dhcp.only_request(cip, mac)
423 if new_cip == None:
424 log.info("Got DHCP server NAK.")
425 assert_not_equal(new_cip, None)
426 log.info('Getting DHCP server Down.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700427
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700428 self.onos_ctrl.deactivate()
ChetanGaonker42d75812016-06-06 16:32:52 -0700429
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700430 for i in range(0,4):
431 log.info("Sending DHCP Request.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700432 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700433 new_cip, new_sip = self.dhcp.only_request(cip, mac)
434 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700435 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700436 log.info("DHCP Request timed out.")
437 elif new_cip and new_sip:
438 log.info("Got Reply from DHCP server.")
439 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700440
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700441 log.info('Getting DHCP server Up.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700442
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700443 status, _ = self.onos_ctrl.activate()
444 assert_equal(status, True)
445 time.sleep(3)
ChetanGaonker42d75812016-06-06 16:32:52 -0700446
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700447 for i in range(0,4):
448 log.info("Sending DHCP Request after DHCP server is up.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700449 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700450 new_cip, new_sip = self.dhcp.only_request(cip, mac)
451 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700452 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700453 log.info("DHCP Request timed out.")
454 elif new_cip and new_sip:
455 log.info("Got Reply from DHCP server.")
456 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700457
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700458
A R Karthick10fe00e2016-07-12 16:13:16 -0700459 def test_dhcp_specific_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700460 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700461 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
462 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
463 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700464 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700465 log.info('Sending DHCP discover with lease time of 700')
ChetanGaonker42d75812016-06-06 16:32:52 -0700466 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
467 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700468 (cip, sip, mac) )
469
470 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
471 if (cip == None and mac != None):
472 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700473 assert_not_equal(cip, None)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700474 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700475
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700476 log.info("Triggering DHCP Request.")
477 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700478 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700479 (new_cip, new_sip, mac, lval) )
480 assert_not_equal(lval, 700) #Negative Test Case
481
482
ChetanGaonker42d75812016-06-06 16:32:52 -0700483
A R Karthick10fe00e2016-07-12 16:13:16 -0700484 def test_dhcp_lease_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700485 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700486 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
487 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
488 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700489 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700490 cip, sip, mac, _ = self.dhcp.only_discover()
491 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700492 (cip, sip, mac) )
493
494 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
495 if (cip == None and mac != None):
496 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700497 assert_not_equal(cip, None)
498
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700499 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700500
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700501 log.info("Triggering DHCP Request.")
502 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
503 if lval == 600:
ChetanGaonker42d75812016-06-06 16:32:52 -0700504 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
505 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700506 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700507 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
508 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700509 log.info('The lease time suppossed to be 600 secs or 10 mins.')
510 assert_equal(lval, 600)
ChetanGaonker42d75812016-06-06 16:32:52 -0700511
A R Karthick10fe00e2016-07-12 16:13:16 -0700512 def test_dhcp_client_renew_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700513
514 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700515 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
516 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
517 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700518 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700519 cip, sip, mac, _ = self.dhcp.only_discover()
520 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700521 (cip, sip, mac) )
522
523 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
524 if (cip == None and mac != None):
525 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700526 assert_not_equal(cip, None)
527
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700528 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700529
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700530 log.info("Triggering DHCP Request.")
531 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700532
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700533 if new_cip and new_sip and lval:
534
535 log.info("Clinet 's Renewal time is :%s",lval)
536 log.info("Generating delay till renewal time.")
537 time.sleep(lval)
538
539 log.info("Client Sending Unicast DHCP request.")
540 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
541
542 if latest_cip and latest_sip:
543 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
544 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700545
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700546 elif latest_cip == None:
547 log.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700548
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700549 elif new_cip == None or new_sip == None or lval == None:
550
551 log.info("Got DHCP NAK.")
552
ChetanGaonker42d75812016-06-06 16:32:52 -0700553
554
A R Karthick10fe00e2016-07-12 16:13:16 -0700555 def test_dhcp_client_rebind_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700556
557 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700558 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
559 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
560 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700561 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700562 cip, sip, mac, _ = self.dhcp.only_discover()
563 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700564 (cip, sip, mac) )
565
566 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
567 if (cip == None and mac != None):
568 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700569 assert_not_equal(cip, None)
570
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700571 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700572
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700573 log.info("Triggering DHCP Request.")
574 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700575
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700576 if new_cip and new_sip and lval:
577
578 log.info("Clinet 's Rebind time is :%s",lval)
579 log.info("Generating delay till rebind time.")
580 time.sleep(lval)
581
582 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700583
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700584 for i in range(0,4):
585 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
586
587 if latest_cip and latest_sip:
588 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
589 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700590 break
591
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700592 elif latest_cip == None:
593 log.info("Got DHCP NAK. Lease not renewed.")
594 assert_not_equal(latest_cip, None)
595 elif new_cip == None or new_sip == None or lval == None:
596
597 log.info("Got DHCP NAK.Lease not Renewed.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700598
Chetan Gaonker717b2942016-05-13 17:42:59 -0700599
A R Karthick10fe00e2016-07-12 16:13:16 -0700600 def test_dhcp_client_expected_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700601
602 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -0700603 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
604 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
605 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700606 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700607 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700608 self.dhcp.return_option = 'subnet'
ChetanGaonker42d75812016-06-06 16:32:52 -0700609
Chetan Gaonker717b2942016-05-13 17:42:59 -0700610 cip, sip, mac, subnet_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700611 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700612 (cip, sip, mac) )
613
614 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
615 if (cip == None and mac != None):
616 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700617 assert_not_equal(cip, None)
618
Chetan Gaonker717b2942016-05-13 17:42:59 -0700619 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700620
Chetan Gaonker717b2942016-05-13 17:42:59 -0700621 if expected_subnet == subnet_value:
622 log.info("Got same subnet as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700623
Chetan Gaonker717b2942016-05-13 17:42:59 -0700624 elif expected_subnet != subnet_value:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700625 log.info("Not getting same subnet as passed in DHCP server configuration.")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700626 assert_equal(expected_subnet, subnet_value)
627
628
A R Karthick10fe00e2016-07-12 16:13:16 -0700629 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700630
631 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700632 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
633 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
634 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700635 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700636
637 cip, sip, mac, _ = self.dhcp.only_discover()
638 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700639 (cip, sip, mac) )
640
641 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
642 if (cip == None and mac != None):
643 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700644 assert_not_equal(cip, None)
645
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700646 elif cip and sip and mac:
647
648 self.dhcp.send_different_option = 'subnet'
649 log.info("Sending DHCP Request with wrong subnet mask.")
650 new_cip, new_sip = self.dhcp.only_request(cip, mac)
651 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700652
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700653 log.info("Got DHCP NAK.")
654 assert_not_equal(new_cip, None)
655
656 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700657
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700658 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
659 log.info("Getting subnet mask as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700660
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700661
A R Karthick10fe00e2016-07-12 16:13:16 -0700662 def test_dhcp_client_expected_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700663
664 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700665 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
666 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
667 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700668 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700669 expected_router_address = '20.20.20.1'
670 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700671
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700672 cip, sip, mac, router_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700673 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700674 (cip, sip, mac) )
675
676 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
677 if (cip == None and mac != None):
678 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700679 assert_not_equal(cip, None)
680
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700681 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700682
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700683 if expected_router_address == router_address_value:
684 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700685
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700686 elif expected_router_address != router_address_value:
687 log.info("Not getting same router address as passed in DHCP server configuration.")
688 assert_equal(expected_router_address, router_address_value)
689
690
A R Karthick10fe00e2016-07-12 16:13:16 -0700691 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700692
693 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700694 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
695 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
696 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700697 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700698
699 cip, sip, mac, _ = self.dhcp.only_discover()
700 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700701 (cip, sip, mac) )
702
703 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
704 if (cip == None and mac != None):
705 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700706 assert_not_equal(cip, None)
707
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700708 elif cip and sip and mac:
709
710 self.dhcp.send_different_option = 'router'
711 log.info("Sending DHCP Request with wrong router address.")
712 new_cip, new_sip = self.dhcp.only_request(cip, mac)
713 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700714
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700715 log.info("Got DHCP NAK.")
716 assert_not_equal(new_cip, None)
717
718 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700719
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700720 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
721 log.info("Getting Router Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700722
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700723
A R Karthick10fe00e2016-07-12 16:13:16 -0700724 def test_dhcp_client_expected_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700725
726 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700727 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
728 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
729 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700730 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700731 expected_broadcast_address = '20.20.20.255'
732 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700733
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700734 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700735 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700736 (cip, sip, mac) )
737
738 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
739 if (cip == None and mac != None):
740 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700741 assert_not_equal(cip, None)
742
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700743 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700744
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700745 if expected_broadcast_address == broadcast_address_value:
746 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700747
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700748 elif expected_broadcast_address != broadcast_address_value:
749 log.info("Not getting same router address as passed in DHCP server configuration.")
750 assert_equal(expected_broadcast_address, broadcast_address_value)
751
752
A R Karthick10fe00e2016-07-12 16:13:16 -0700753 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700754
755 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700756 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
757 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
758 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700759 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700760
761 cip, sip, mac, _ = self.dhcp.only_discover()
762 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700763 (cip, sip, mac) )
764
765 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
766 if (cip == None and mac != None):
767 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700768 assert_not_equal(cip, None)
769
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700770 elif cip and sip and mac:
771
772 self.dhcp.send_different_option = 'broadcast_address'
773 log.info("Sending DHCP Request with wrong broadcast address.")
774 new_cip, new_sip = self.dhcp.only_request(cip, mac)
775 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700776
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700777 log.info("Got DHCP NAK.")
778 assert_not_equal(new_cip, None)
779
780 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700781
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700782 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
783 log.info("Getting Broadcast Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700784
A R Karthick10fe00e2016-07-12 16:13:16 -0700785 def test_dhcp_client_expected_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700786
787 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700788 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
789 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
790 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700791 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700792 expected_dns_address = '8.8.8.8'
793 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700794
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700795 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700796 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700797 (cip, sip, mac) )
798
799 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
800 if (cip == None and mac != None):
801 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700802 assert_not_equal(cip, None)
803
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700804 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700805
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700806 if expected_dns_address == dns_address_value:
807 log.info("Got same DNS address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700808
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700809 elif expected_dns_address != dns_address_value:
810 log.info("Not getting same DNS address as passed in DHCP server configuration.")
811 assert_equal(expected_dns_address, dns_address_value)
812
813
A R Karthick10fe00e2016-07-12 16:13:16 -0700814 def test_dhcp_client_sends_request_with_wrong_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700815
816 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700817 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
818 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
819 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700820 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700821
822 cip, sip, mac, _ = self.dhcp.only_discover()
823 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700824 (cip, sip, mac) )
825
826 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
827 if (cip == None and mac != None):
828 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700829 assert_not_equal(cip, None)
830
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700831 elif cip and sip and mac:
832
833 self.dhcp.send_different_option = 'dns'
834 log.info("Sending DHCP Request with wrong DNS address.")
835 new_cip, new_sip = self.dhcp.only_request(cip, mac)
836 if new_cip == None:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700837 log.info("Got DHCP NAK.")
838 assert_not_equal(new_cip, None)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700839 elif new_cip and new_sip:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700840 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
841 log.info("Getting DNS Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700842
A R Karthick10fe00e2016-07-12 16:13:16 -0700843 def test_dhcp_server_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700844
845 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700846 self.stats()
ChetanGaonker42d75812016-06-06 16:32:52 -0700847 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700848 log.info("----------------------------------------------------------------------------------")
849 log.info("No. of transactions No. of successes No. of failures Running Time ")
850 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
851 log.info("----------------------------------------------------------------------------------")
852 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
853
ChetanGaonker42d75812016-06-06 16:32:52 -0700854 log.info("Final Statistics for total transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700855 log.info("----------------------------------------------------------------------------------")
856 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700857 log.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700858 self.total_success, self.total_failure, self.running_time))
859 log.info("----------------------------------------------------------------------------------")
860 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
861
A R Karthick10fe00e2016-07-12 16:13:16 -0700862 def test_dhcp_server_consecutive_successes_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700863
864 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700865 self.stats(success_rate = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700866 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700867 log.info("----------------------------------------------------------------------------------")
868 log.info("No. of consecutive successful transactions Running Time ")
869 log.info(" %d %d " %(self.ip_count, self.diff))
870 log.info("----------------------------------------------------------------------------------")
871 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker42d75812016-06-06 16:32:52 -0700872 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700873
ChetanGaonker42d75812016-06-06 16:32:52 -0700874 log.info("Final Statistics for total successful transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700875 log.info("----------------------------------------------------------------------------------")
876 log.info("Total transactions Total No. of consecutive successes Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700877 log.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700878 self.total_success, self.running_time))
879 log.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700880 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
881 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700882
ChetanGaonker42d75812016-06-06 16:32:52 -0700883
A R Karthick10fe00e2016-07-12 16:13:16 -0700884 def test_dhcp_server_client_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700885
886 for i in range(1,4):
887 self.stats(only_discover = True)
888 log.info("----------------------------------------------------------------------------------")
889 log.info("Stats for run %d of sending only DHCP Discover",i)
890 log.info("----------------------------------------------------------------------------------")
891 log.info("No. of transactions No. of successes No. of failures Running Time ")
892 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
893 log.info("----------------------------------------------------------------------------------")
894 log.info("No. of clients per second in run %d:%f "
895 %(i, self.transaction_count))
896 log.info("----------------------------------------------------------------------------------")
897 log.info("Final Statistics for total transactions of sending only DHCP Discover")
898 log.info("----------------------------------------------------------------------------------")
899 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
900 log.info(" %d %d %d %d" %(self.transactions,
901 self.total_success, self.total_failure, self.running_time))
902 log.info("----------------------------------------------------------------------------------")
903 log.info("Average no. of clients per second: %d ",
904 round(self.transactions/self.running_time,0))
905 log.info("----------------------------------------------------------------------------------")
906
A R Karthick10fe00e2016-07-12 16:13:16 -0700907 def test_dhcp_server_consecutive_successful_clients_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700908
909 for i in range(1,4):
910 self.stats(success_rate = True, only_discover = True)
911 log.info("----------------------------------------------------------------------------------")
912 log.info("Stats for run %d for sending only DHCP Discover",i)
913 log.info("----------------------------------------------------------------------------------")
914 log.info("No. of consecutive successful transactions Running Time ")
915 log.info(" %d %d " %(self.ip_count, self.diff))
916 log.info("----------------------------------------------------------------------------------")
917 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
918 log.info("----------------------------------------------------------------------------------")
919
920 log.info("Final Statistics for total successful transactions")
921 log.info("----------------------------------------------------------------------------------")
922 log.info("Total transactions Total No. of consecutive successes Running Time ")
923 log.info(" %d %d %d " %(self.transactions,
924 self.total_success, self.running_time))
925 log.info("----------------------------------------------------------------------------------")
926 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
927 log.info("----------------------------------------------------------------------------------")