blob: 74891c062d87c75b38adf7afa3f650e9e1797196 [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
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080024from OnosCtrl import OnosCtrl
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080025log.setLevel('INFO')
26
27class dhcp_exchange(unittest.TestCase):
28
29 dhcp_server_config = {
30 "ip": "10.1.11.50",
31 "mac": "ca:fe:ca:fe:ca:fe",
32 "subnet": "255.255.252.0",
33 "broadcast": "10.1.11.255",
34 "router": "10.1.8.1",
35 "domain": "8.8.8.8",
36 "ttl": "63",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080037 "delay": "2",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080038 "startip": "10.1.11.51",
39 "endip": "10.1.11.100"
40 }
ChetanGaonker42d75812016-06-06 16:32:52 -070041
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080042 app = 'org.onosproject.dhcp'
43
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070044 ip_count = 0
45 failure_count = 0
46 start_time = 0
47 diff = 0
48
49 transaction_count = 0
50 transactions = 0
51 running_time = 0
52 total_success = 0
53 total_failure = 0
54
55
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080056 def setUp(self):
57 ''' Activate the dhcp app'''
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080058 self.maxDiff = None ##for assert_equal compare outputs on failure
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080059 self.onos_ctrl = OnosCtrl(self.app)
60 status, _ = self.onos_ctrl.activate()
61 assert_equal(status, True)
62 time.sleep(3)
63
64 def teardown(self):
65 '''Deactivate the dhcp app'''
66 self.onos_ctrl.deactivate()
67
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080068 def onos_load_config(self, config):
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070069 status, code = OnosCtrl.config(config)
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -080070 if status is False:
71 log.info('JSON request returned status %d' %code)
72 assert_equal(status, True)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080073 time.sleep(3)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080074
75 def onos_dhcp_table_load(self, config = None):
76 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
77 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
78 if config:
79 for k in config.keys():
80 if dhcp_config.has_key(k):
81 dhcp_config[k] = config[k]
82 self.onos_load_config(dhcp_dict)
83
Chetan Gaonker6c68e912016-04-15 17:22:14 -070084 def send_recv(self, mac = None, update_seed = False, validate = True):
85 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
86 if validate:
87 assert_not_equal(cip, None)
88 assert_not_equal(sip, None)
89 log.info('Got dhcp client IP %s from server %s for mac %s' %
90 (cip, sip, self.dhcp.get_mac(cip)[0]))
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080091 return cip,sip
92
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070093
ChetanGaonker42d75812016-06-06 16:32:52 -070094 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
95
Chetan Gaonker4a82bae2016-05-19 17:35:30 -070096 self.ip_count = 0
97 self.failure_count = 0
98 self.start_time = 0
99 self.diff = 0
100 self.transaction_count = 0
101
ChetanGaonker42d75812016-06-06 16:32:52 -0700102 config = {'startip':'182.17.0.3', 'endip':'182.17.0.180',
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700103 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
104 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
105 self.onos_dhcp_table_load(config)
106 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
107 self.start_time = time.time()
108
109 while self.diff <= 60:
ChetanGaonker42d75812016-06-06 16:32:52 -0700110 if only_discover:
111 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
112 log.info('Got dhcp client IP %s from server %s for mac %s' %
113 (cip, sip, mac))
114 else:
115 cip, sip = self.send_recv(update_seed = True, validate = False)
116
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700117 if cip:
118 self.ip_count +=1
119 elif cip == None:
120 self.failure_count += 1
121 log.info('Failed to get ip')
ChetanGaonker42d75812016-06-06 16:32:52 -0700122 if success_rate and self.ip_count > 0:
123 break
124 self.diff = round(time.time() - self.start_time, 0)
125
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700126
127 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
128
129 self.transactions += (self.ip_count+self.failure_count)
130 self.running_time += self.diff
131 self.total_success += self.ip_count
132 self.total_failure += self.failure_count
133
134
135
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800136 def test_dhcp_1request(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700137 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonker4a25e2b2016-03-04 14:45:15 -0800138 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800139 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
140 self.onos_dhcp_table_load(config)
141 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
142 self.send_recv()
143
144 def test_dhcp_Nrequest(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700145 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800146 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
147 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
148 self.onos_dhcp_table_load(config)
149 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
150 ip_map = {}
151 for i in range(10):
152 cip, sip = self.send_recv(update_seed = True)
153 if ip_map.has_key(cip):
154 log.info('IP %s given out multiple times' %cip)
155 assert_equal(False, ip_map.has_key(cip))
156 ip_map[cip] = sip
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800157
158 def test_dhcp_1release(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700159 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800160 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
161 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800162 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800163 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800164 cip, sip = self.send_recv()
165 log.info('Releasing ip %s to server %s' %(cip, sip))
166 assert_equal(self.dhcp.release(cip), True)
167 log.info('Triggering DHCP discover again after release')
168 cip2, sip2 = self.send_recv(update_seed = True)
169 log.info('Verifying released IP was given back on rediscover')
170 assert_equal(cip, cip2)
171 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
172 assert_equal(self.dhcp.release(cip2), True)
173
174 def test_dhcp_Nrelease(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700175 config = {'startip':'192.170.1.20', 'endip':'192.170.1.30',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800176 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
177 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800178 self.onos_dhcp_table_load(config)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800179 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800180 ip_map = {}
181 for i in range(10):
182 cip, sip = self.send_recv(update_seed = True)
183 if ip_map.has_key(cip):
184 log.info('IP %s given out multiple times' %cip)
185 assert_equal(False, ip_map.has_key(cip))
186 ip_map[cip] = sip
187
188 for ip in ip_map.keys():
189 log.info('Releasing IP %s' %ip)
190 assert_equal(self.dhcp.release(ip), True)
191
192 ip_map2 = {}
193 log.info('Triggering DHCP discover again after release')
194 for i in range(len(ip_map.keys())):
195 cip, sip = self.send_recv(update_seed = True)
196 ip_map2[cip] = sip
197
198 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800199 if ip_map != ip_map2:
200 log.info('Map before release %s' %ip_map)
201 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800202 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700203
204
205 def test_dhcp_starvation(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700206 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700207 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
208 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
209 self.onos_dhcp_table_load(config)
210 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface)
211 ip_map = {}
212 for i in range(10):
213 cip, sip = self.send_recv(update_seed = True)
214 if ip_map.has_key(cip):
215 log.info('IP %s given out multiple times' %cip)
216 assert_equal(False, ip_map.has_key(cip))
217 ip_map[cip] = sip
218
219
220 def test_dhcp_starvation(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700221 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700222 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
223 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
224 self.onos_dhcp_table_load(config)
225 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
226 log.info('Verifying 1 ')
227 for x in xrange(50):
228 mac = RandMAC()._fix()
229 self.send_recv(mac = mac)
230 log.info('Verifying 2 ')
231 cip, sip = self.send_recv(update_seed = True, validate = False)
232 assert_equal(cip, None)
233 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700234
235
236 def test_dhcp_same_client_multiple_discover(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700237 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700238 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
239 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
240 self.onos_dhcp_table_load(config)
241 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700242 cip, sip, mac, _ = self.dhcp.only_discover()
243 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 -0700244 (cip, sip, mac) )
245 log.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700246 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700247 if cip == new_cip:
248 log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
249 % (new_cip, new_sip, new_mac) )
250 elif cip != new_cip:
251 log.info('Ip after 1st discover %s' %cip)
252 log.info('Map after 2nd discover %s' %new_cip)
253 assert_equal(cip, new_cip)
254
255
256 def test_dhcp_same_client_multiple_request(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700257 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700258 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
259 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
260 self.onos_dhcp_table_load(config)
261 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
262 log.info('Sending DHCP discover and DHCP request.')
263 cip, sip = self.send_recv()
264 mac = self.dhcp.get_mac(cip)[0]
265 log.info("Sending DHCP request again.")
266 new_cip, new_sip = self.dhcp.only_request(cip, mac)
267 if (new_cip,new_sip) == (cip,sip):
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700268 log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
269 % (new_cip, new_sip, mac) )
270 elif (new_cip,new_sip):
ChetanGaonker42d75812016-06-06 16:32:52 -0700271 log.info('No DHCP ACK')
272 assert_equal(new_cip, None)
273 assert_equal(new_sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700274 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700275 log.info('Something went wrong.')
276
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700277 def test_dhcp_client_desired_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700278 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700279 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
280 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
281 self.onos_dhcp_table_load(config)
282 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700283 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
284 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700285 (cip, sip, mac) )
286 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700287 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700288 (cip, sip, mac) )
289 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700290 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700291 (cip, sip, mac) )
292 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
293 assert_equal(cip, self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700294
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700295 def test_dhcp_client_desired_address_out_of_pool(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700296 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700297 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
298 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
299 self.onos_dhcp_table_load(config)
300 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700301 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
302 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700303 (cip, sip, mac) )
304 if cip == self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700305 log.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700306 (cip, sip, mac) )
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700307 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700308 elif cip != self.dhcp.seed_ip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700309 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700310 (cip, sip, mac) )
311 log.info('The desired ip was: %s .' % self.dhcp.seed_ip)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700312 assert_not_equal(cip, self.dhcp.seed_ip)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700313 elif cip == None:
314 log.info('Got DHCP NAK')
ChetanGaonker42d75812016-06-06 16:32:52 -0700315
316
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700317 def test_dhcp_server_nak_packet(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700318 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700319 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
320 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
321 self.onos_dhcp_table_load(config)
322 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700323 cip, sip, mac, _ = self.dhcp.only_discover()
324 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700325 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700326
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700327 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
328 if (cip == None and mac != None):
329 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
330 assert_not_equal(cip, None)
331 else:
332 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
333 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700334
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700335 log.info("Got DHCP server NAK.")
336 assert_equal(new_cip, None) #Negative Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700337
338
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700339 def test_dhcp_lease_packet(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700340 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700341 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
342 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
343 self.onos_dhcp_table_load(config)
344 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
345 log.info('Sending DHCP discover with lease time of 700')
346 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
347
348 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
349 if (cip == None and mac != None):
350 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
351 assert_not_equal(cip, None)
352 elif lval != 700:
ChetanGaonker42d75812016-06-06 16:32:52 -0700353 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 -0700354 (cip, sip, mac, lval) )
355 assert_not_equal(lval, 700)
356
357 def test_dhcp_client_request_after_reboot(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700358 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700359 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
360 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
361 self.onos_dhcp_table_load(config)
362 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700363 cip, sip, mac, _ = self.dhcp.only_discover()
364 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700365 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700366
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700367 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 -0700368
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700369 if (cip == None and mac != None):
370 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
371 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700372
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700373 else:
374 new_cip, new_sip = self.dhcp.only_request(cip, mac)
375 if new_cip == None:
376 log.info("Got DHCP server NAK.")
377 os.system('ifconfig '+iface+' down')
378 log.info('Client goes down.')
379 log.info('Delay for 5 seconds.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700380
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700381 time.sleep(5)
ChetanGaonker42d75812016-06-06 16:32:52 -0700382
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700383 os.system('ifconfig '+iface+' up')
384 log.info('Client is up now.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700385
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700386 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700387 if new_cip == None:
388 log.info("Got DHCP server NAK.")
389 assert_not_equal(new_cip, None)
390 elif new_cip != None:
391 log.info("Got DHCP ACK.")
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700392 os.system('ifconfig '+iface+' up')
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700393
ChetanGaonker42d75812016-06-06 16:32:52 -0700394
395
396
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700397 def test_dhcp_server_after_reboot(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700398 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700399 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
400 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
401 self.onos_dhcp_table_load(config)
402 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700403 cip, sip, mac, _ = self.dhcp.only_discover()
404 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700405 (cip, sip, mac) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700406
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700407 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 -0700408
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700409 if (cip == None and mac != None):
410 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
411 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700412
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700413 else:
414 new_cip, new_sip = self.dhcp.only_request(cip, mac)
415 if new_cip == None:
416 log.info("Got DHCP server NAK.")
417 assert_not_equal(new_cip, None)
418 log.info('Getting DHCP server Down.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700419
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700420 self.onos_ctrl.deactivate()
ChetanGaonker42d75812016-06-06 16:32:52 -0700421
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700422 for i in range(0,4):
423 log.info("Sending DHCP Request.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700424 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700425 new_cip, new_sip = self.dhcp.only_request(cip, mac)
426 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700427 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700428 log.info("DHCP Request timed out.")
429 elif new_cip and new_sip:
430 log.info("Got Reply from DHCP server.")
431 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700432
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700433 log.info('Getting DHCP server Up.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700434
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700435 status, _ = self.onos_ctrl.activate()
436 assert_equal(status, True)
437 time.sleep(3)
ChetanGaonker42d75812016-06-06 16:32:52 -0700438
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700439 for i in range(0,4):
440 log.info("Sending DHCP Request after DHCP server is up.")
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700441 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700442 new_cip, new_sip = self.dhcp.only_request(cip, mac)
443 if new_cip == None and new_sip == None:
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700444 log.info('')
Chetan Gaonkerb926c642016-05-10 08:19:03 -0700445 log.info("DHCP Request timed out.")
446 elif new_cip and new_sip:
447 log.info("Got Reply from DHCP server.")
448 assert_equal(new_cip,None) #Neagtive Test Case
ChetanGaonker42d75812016-06-06 16:32:52 -0700449
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700450
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700451 def test_dhcp_specific_lease_packet(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700452 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700453 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
454 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
455 self.onos_dhcp_table_load(config)
456 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
457 log.info('Sending DHCP discover with lease time of 700')
ChetanGaonker42d75812016-06-06 16:32:52 -0700458 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True)
459 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700460 (cip, sip, mac) )
461
462 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
463 if (cip == None and mac != None):
464 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 -0700465 assert_not_equal(cip, None)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700466 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700467
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700468 log.info("Triggering DHCP Request.")
469 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700470 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 -0700471 (new_cip, new_sip, mac, lval) )
472 assert_not_equal(lval, 700) #Negative Test Case
473
474
ChetanGaonker42d75812016-06-06 16:32:52 -0700475
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700476 def test_dhcp_lease_packet(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700477 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700478 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
479 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
480 self.onos_dhcp_table_load(config)
481 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700482 cip, sip, mac, _ = self.dhcp.only_discover()
483 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700484 (cip, sip, mac) )
485
486 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
487 if (cip == None and mac != None):
488 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 -0700489 assert_not_equal(cip, None)
490
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700491 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700492
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700493 log.info("Triggering DHCP Request.")
494 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
495 if lval == 600:
ChetanGaonker42d75812016-06-06 16:32:52 -0700496 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
497 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700498 else:
ChetanGaonker42d75812016-06-06 16:32:52 -0700499 log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' %
500 (new_cip, new_sip, mac, lval) )
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700501 log.info('The lease time suppossed to be 600 secs or 10 mins.')
502 assert_equal(lval, 600)
ChetanGaonker42d75812016-06-06 16:32:52 -0700503
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700504 def test_dhcp_client_renew_time(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700505
506 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700507 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
508 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
509 self.onos_dhcp_table_load(config)
510 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700511 cip, sip, mac, _ = self.dhcp.only_discover()
512 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700513 (cip, sip, mac) )
514
515 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
516 if (cip == None and mac != None):
517 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 -0700518 assert_not_equal(cip, None)
519
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700520 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700521
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700522 log.info("Triggering DHCP Request.")
523 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700524
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700525 if new_cip and new_sip and lval:
526
527 log.info("Clinet 's Renewal time is :%s",lval)
528 log.info("Generating delay till renewal time.")
529 time.sleep(lval)
530
531 log.info("Client Sending Unicast DHCP request.")
532 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
533
534 if latest_cip and latest_sip:
535 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
536 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700537
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700538 elif latest_cip == None:
539 log.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700540
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700541 elif new_cip == None or new_sip == None or lval == None:
542
543 log.info("Got DHCP NAK.")
544
ChetanGaonker42d75812016-06-06 16:32:52 -0700545
546
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700547 def test_dhcp_client_rebind_time(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700548
549 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700550 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
551 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
552 self.onos_dhcp_table_load(config)
553 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700554 cip, sip, mac, _ = self.dhcp.only_discover()
555 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700556 (cip, sip, mac) )
557
558 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
559 if (cip == None and mac != None):
560 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 -0700561 assert_not_equal(cip, None)
562
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700563 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700564
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700565 log.info("Triggering DHCP Request.")
566 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700567
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700568 if new_cip and new_sip and lval:
569
570 log.info("Clinet 's Rebind time is :%s",lval)
571 log.info("Generating delay till rebind time.")
572 time.sleep(lval)
573
574 log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700575
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700576 for i in range(0,4):
577 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
578
579 if latest_cip and latest_sip:
580 log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
581 (latest_cip, mac, latest_sip) )
ChetanGaonker42d75812016-06-06 16:32:52 -0700582 break
583
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700584 elif latest_cip == None:
585 log.info("Got DHCP NAK. Lease not renewed.")
586 assert_not_equal(latest_cip, None)
587 elif new_cip == None or new_sip == None or lval == None:
588
589 log.info("Got DHCP NAK.Lease not Renewed.")
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700590
Chetan Gaonker717b2942016-05-13 17:42:59 -0700591
592 def test_dhcp_client_expected_subnet_mask(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700593
594 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -0700595 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
596 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
597 self.onos_dhcp_table_load(config)
598 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
599 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700600 self.dhcp.return_option = 'subnet'
ChetanGaonker42d75812016-06-06 16:32:52 -0700601
Chetan Gaonker717b2942016-05-13 17:42:59 -0700602 cip, sip, mac, subnet_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700603 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700604 (cip, sip, mac) )
605
606 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
607 if (cip == None and mac != None):
608 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700609 assert_not_equal(cip, None)
610
Chetan Gaonker717b2942016-05-13 17:42:59 -0700611 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700612
Chetan Gaonker717b2942016-05-13 17:42:59 -0700613 if expected_subnet == subnet_value:
614 log.info("Got same subnet as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700615
Chetan Gaonker717b2942016-05-13 17:42:59 -0700616 elif expected_subnet != subnet_value:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700617 log.info("Not getting same subnet as passed in DHCP server configuration.")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700618 assert_equal(expected_subnet, subnet_value)
619
620
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700621 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700622
623 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700624 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
625 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
626 self.onos_dhcp_table_load(config)
627 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700628
629 cip, sip, mac, _ = self.dhcp.only_discover()
630 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700631 (cip, sip, mac) )
632
633 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
634 if (cip == None and mac != None):
635 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700636 assert_not_equal(cip, None)
637
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700638 elif cip and sip and mac:
639
640 self.dhcp.send_different_option = 'subnet'
641 log.info("Sending DHCP Request with wrong subnet mask.")
642 new_cip, new_sip = self.dhcp.only_request(cip, mac)
643 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700644
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700645 log.info("Got DHCP NAK.")
646 assert_not_equal(new_cip, None)
647
648 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700649
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700650 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
651 log.info("Getting subnet mask as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700652
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700653
654 def test_dhcp_client_expected_router_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700655
656 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700657 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
658 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
659 self.onos_dhcp_table_load(config)
660 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
661 expected_router_address = '20.20.20.1'
662 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700663
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700664 cip, sip, mac, router_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700665 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700666 (cip, sip, mac) )
667
668 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
669 if (cip == None and mac != None):
670 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700671 assert_not_equal(cip, None)
672
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700673 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700674
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700675 if expected_router_address == router_address_value:
676 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700677
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700678 elif expected_router_address != router_address_value:
679 log.info("Not getting same router address as passed in DHCP server configuration.")
680 assert_equal(expected_router_address, router_address_value)
681
682
683 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700684
685 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700686 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
687 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
688 self.onos_dhcp_table_load(config)
689 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700690
691 cip, sip, mac, _ = self.dhcp.only_discover()
692 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700693 (cip, sip, mac) )
694
695 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
696 if (cip == None and mac != None):
697 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700698 assert_not_equal(cip, None)
699
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700700 elif cip and sip and mac:
701
702 self.dhcp.send_different_option = 'router'
703 log.info("Sending DHCP Request with wrong router address.")
704 new_cip, new_sip = self.dhcp.only_request(cip, mac)
705 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700706
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700707 log.info("Got DHCP NAK.")
708 assert_not_equal(new_cip, None)
709
710 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700711
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700712 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
713 log.info("Getting Router Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700714
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700715
716 def test_dhcp_client_expected_broadcast_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700717
718 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700719 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
720 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
721 self.onos_dhcp_table_load(config)
722 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
723 expected_broadcast_address = '20.20.20.255'
724 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700725
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700726 cip, sip, mac, broadcast_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700727 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700728 (cip, sip, mac) )
729
730 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
731 if (cip == None and mac != None):
732 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700733 assert_not_equal(cip, None)
734
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700735 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700736
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700737 if expected_broadcast_address == broadcast_address_value:
738 log.info("Got same router address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700739
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700740 elif expected_broadcast_address != broadcast_address_value:
741 log.info("Not getting same router address as passed in DHCP server configuration.")
742 assert_equal(expected_broadcast_address, broadcast_address_value)
743
744
745 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700746
747 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700748 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
749 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
750 self.onos_dhcp_table_load(config)
751 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700752
753 cip, sip, mac, _ = self.dhcp.only_discover()
754 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700755 (cip, sip, mac) )
756
757 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
758 if (cip == None and mac != None):
759 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700760 assert_not_equal(cip, None)
761
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700762 elif cip and sip and mac:
763
764 self.dhcp.send_different_option = 'broadcast_address'
765 log.info("Sending DHCP Request with wrong broadcast address.")
766 new_cip, new_sip = self.dhcp.only_request(cip, mac)
767 if new_cip == None:
ChetanGaonker42d75812016-06-06 16:32:52 -0700768
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700769 log.info("Got DHCP NAK.")
770 assert_not_equal(new_cip, None)
771
772 elif new_cip and new_sip:
ChetanGaonker42d75812016-06-06 16:32:52 -0700773
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700774 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
775 log.info("Getting Broadcast Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700776
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700777 def test_dhcp_client_expected_dns_address(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700778
779 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700780 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
781 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
782 self.onos_dhcp_table_load(config)
783 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
784 expected_dns_address = '8.8.8.8'
785 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700786
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700787 cip, sip, mac, dns_address_value = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700788 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700789 (cip, sip, mac) )
790
791 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
792 if (cip == None and mac != None):
793 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700794 assert_not_equal(cip, None)
795
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700796 elif cip and sip and mac:
ChetanGaonker42d75812016-06-06 16:32:52 -0700797
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700798 if expected_dns_address == dns_address_value:
799 log.info("Got same DNS address as passed in DHCP server configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700800
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700801 elif expected_dns_address != dns_address_value:
802 log.info("Not getting same DNS address as passed in DHCP server configuration.")
803 assert_equal(expected_dns_address, dns_address_value)
804
805
ChetanGaonker42d75812016-06-06 16:32:52 -0700806 def test_dhcp_client_sends_request_with_wrong_dns_address(self, iface = 'veth0'):
807
808 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700809 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
810 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
811 self.onos_dhcp_table_load(config)
812 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700813
814 cip, sip, mac, _ = self.dhcp.only_discover()
815 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700816 (cip, sip, mac) )
817
818 log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
819 if (cip == None and mac != None):
820 log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700821 assert_not_equal(cip, None)
822
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700823 elif cip and sip and mac:
824
825 self.dhcp.send_different_option = 'dns'
826 log.info("Sending DHCP Request with wrong DNS address.")
827 new_cip, new_sip = self.dhcp.only_request(cip, mac)
828 if new_cip == None:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700829 log.info("Got DHCP NAK.")
830 assert_not_equal(new_cip, None)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700831 elif new_cip and new_sip:
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700832 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
833 log.info("Getting DNS Address as per server 's configuration.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700834
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700835 def test_dhcp_server_transactions_per_second(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700836
837 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700838 self.stats()
ChetanGaonker42d75812016-06-06 16:32:52 -0700839 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700840 log.info("----------------------------------------------------------------------------------")
841 log.info("No. of transactions No. of successes No. of failures Running Time ")
842 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
843 log.info("----------------------------------------------------------------------------------")
844 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
845
ChetanGaonker42d75812016-06-06 16:32:52 -0700846 log.info("Final Statistics for total transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700847 log.info("----------------------------------------------------------------------------------")
848 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700849 log.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700850 self.total_success, self.total_failure, self.running_time))
851 log.info("----------------------------------------------------------------------------------")
852 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
853
854 def test_dhcp_server_consecutive_successes_per_second(self, iface = 'veth0'):
ChetanGaonker42d75812016-06-06 16:32:52 -0700855
856 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700857 self.stats(success_rate = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700858 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700859 log.info("----------------------------------------------------------------------------------")
860 log.info("No. of consecutive successful transactions Running Time ")
861 log.info(" %d %d " %(self.ip_count, self.diff))
862 log.info("----------------------------------------------------------------------------------")
863 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker42d75812016-06-06 16:32:52 -0700864 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700865
ChetanGaonker42d75812016-06-06 16:32:52 -0700866 log.info("Final Statistics for total successful transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700867 log.info("----------------------------------------------------------------------------------")
868 log.info("Total transactions Total No. of consecutive successes Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700869 log.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700870 self.total_success, self.running_time))
871 log.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700872 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
873 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700874
ChetanGaonker42d75812016-06-06 16:32:52 -0700875
876 def test_dhcp_server_client_transactions_per_second(self, iface = 'veth0'):
877
878 for i in range(1,4):
879 self.stats(only_discover = True)
880 log.info("----------------------------------------------------------------------------------")
881 log.info("Stats for run %d of sending only DHCP Discover",i)
882 log.info("----------------------------------------------------------------------------------")
883 log.info("No. of transactions No. of successes No. of failures Running Time ")
884 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
885 log.info("----------------------------------------------------------------------------------")
886 log.info("No. of clients per second in run %d:%f "
887 %(i, self.transaction_count))
888 log.info("----------------------------------------------------------------------------------")
889 log.info("Final Statistics for total transactions of sending only DHCP Discover")
890 log.info("----------------------------------------------------------------------------------")
891 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
892 log.info(" %d %d %d %d" %(self.transactions,
893 self.total_success, self.total_failure, self.running_time))
894 log.info("----------------------------------------------------------------------------------")
895 log.info("Average no. of clients per second: %d ",
896 round(self.transactions/self.running_time,0))
897 log.info("----------------------------------------------------------------------------------")
898
899 def test_dhcp_server_consecutive_successful_clients_per_second(self, iface = 'veth0'):
900
901 for i in range(1,4):
902 self.stats(success_rate = True, only_discover = True)
903 log.info("----------------------------------------------------------------------------------")
904 log.info("Stats for run %d for sending only DHCP Discover",i)
905 log.info("----------------------------------------------------------------------------------")
906 log.info("No. of consecutive successful transactions Running Time ")
907 log.info(" %d %d " %(self.ip_count, self.diff))
908 log.info("----------------------------------------------------------------------------------")
909 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
910 log.info("----------------------------------------------------------------------------------")
911
912 log.info("Final Statistics for total successful transactions")
913 log.info("----------------------------------------------------------------------------------")
914 log.info("Total transactions Total No. of consecutive successes Running Time ")
915 log.info(" %d %d %d " %(self.transactions,
916 self.total_success, self.running_time))
917 log.info("----------------------------------------------------------------------------------")
918 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
919 log.info("----------------------------------------------------------------------------------")