blob: a35bedc35af3c22ead0dd16e1b8531d19eeb69f6 [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)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000150 self.send_recv(mac=mac)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800151
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000152 def test_dhcp_1request_with_invalid_source_mac_broadcast(self):
153 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
154 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
155 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
156 self.onos_dhcp_table_load(config)
157 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
158 cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff')
159 assert_equal(cip,None)
160 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
161
162 def test_dhcp_1request_with_invalid_source_mac_multicast(self):
163 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
164 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
165 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
166 self.onos_dhcp_table_load(config)
167 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
168 cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:91:02:e4')
169 assert_equal(cip,None)
170 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
171
172 def test_dhcp_1request_with_invalid_source_mac_zero(self):
173 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
174 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
175 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
176 self.onos_dhcp_table_load(config)
177 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
178 cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00')
179 assert_equal(cip,None)
180 log.info('ONOS dhcp server rejected client discover with invalid source mac as expected')
181
182 def test_dhcp_Nrequest(self,requests=10):
ChetanGaonker42d75812016-06-06 16:32:52 -0700183 config = {'startip':'192.168.1.20', 'endip':'192.168.1.69',
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800184 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
185 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
186 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000187 self.dhcp = DHCPTest(seed_ip = '192.168.1.1', iface = self.iface)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800188 ip_map = {}
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000189 for i in range(requests):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -0800190 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
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800195
A R Karthick10fe00e2016-07-12 16:13:16 -0700196 def test_dhcp_1release(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000197 config = {'startip':'10.10.100.20', 'endip':'10.10.100.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800198 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
199 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800200 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700201 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800202 cip, sip = self.send_recv()
203 log.info('Releasing ip %s to server %s' %(cip, sip))
204 assert_equal(self.dhcp.release(cip), True)
205 log.info('Triggering DHCP discover again after release')
206 cip2, sip2 = self.send_recv(update_seed = True)
207 log.info('Verifying released IP was given back on rediscover')
208 assert_equal(cip, cip2)
209 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
210 assert_equal(self.dhcp.release(cip2), True)
211
A R Karthick10fe00e2016-07-12 16:13:16 -0700212 def test_dhcp_Nrelease(self):
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000213 config = {'startip':'192.170.1.20', 'endip':'192.170.1.230',
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800214 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
215 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800216 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700217 self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800218 ip_map = {}
219 for i in range(10):
220 cip, sip = self.send_recv(update_seed = True)
221 if ip_map.has_key(cip):
222 log.info('IP %s given out multiple times' %cip)
223 assert_equal(False, ip_map.has_key(cip))
224 ip_map[cip] = sip
225
226 for ip in ip_map.keys():
227 log.info('Releasing IP %s' %ip)
228 assert_equal(self.dhcp.release(ip), True)
229
230 ip_map2 = {}
231 log.info('Triggering DHCP discover again after release')
232 for i in range(len(ip_map.keys())):
233 cip, sip = self.send_recv(update_seed = True)
234 ip_map2[cip] = sip
235
236 log.info('Verifying released IPs were given back on rediscover')
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800237 if ip_map != ip_map2:
238 log.info('Map before release %s' %ip_map)
239 log.info('Map after release %s' %ip_map2)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800240 assert_equal(ip_map, ip_map2)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700241
242
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000243 def test_dhcp_starvation_positive(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700244 config = {'startip':'193.170.1.20', 'endip':'193.170.1.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700245 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe",
246 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
247 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700248 self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface)
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700249 ip_map = {}
250 for i in range(10):
251 cip, sip = self.send_recv(update_seed = True)
252 if ip_map.has_key(cip):
253 log.info('IP %s given out multiple times' %cip)
254 assert_equal(False, ip_map.has_key(cip))
255 ip_map[cip] = sip
256
257
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000258 def test_dhcp_starvation_negative(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700259 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700260 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
261 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
262 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700263 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000264 log.info('Verifying passitive case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700265 for x in xrange(50):
266 mac = RandMAC()._fix()
267 self.send_recv(mac = mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000268 log.info('Verifying negative case')
Chetan Gaonker6c68e912016-04-15 17:22:14 -0700269 cip, sip = self.send_recv(update_seed = True, validate = False)
270 assert_equal(cip, None)
271 assert_equal(sip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700272
273
A R Karthick10fe00e2016-07-12 16:13:16 -0700274 def test_dhcp_same_client_multiple_discover(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700275 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700276 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
277 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
278 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700279 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700280 cip, sip, mac, _ = self.dhcp.only_discover()
281 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 -0700282 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000283 assert_not_equal(cip, None)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700284 log.info('Triggering DHCP discover again.')
ChetanGaonker42d75812016-06-06 16:32:52 -0700285 new_cip, new_sip, new_mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000286 assert_equal(new_cip, cip)
287 log.info('client got same IP as expected when sent 2nd discovery')
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700288
289
A R Karthick10fe00e2016-07-12 16:13:16 -0700290 def test_dhcp_same_client_multiple_request(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700291 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700292 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
293 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
294 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700295 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface)
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700296 log.info('Sending DHCP discover and DHCP request.')
297 cip, sip = self.send_recv()
298 mac = self.dhcp.get_mac(cip)[0]
299 log.info("Sending DHCP request again.")
300 new_cip, new_sip = self.dhcp.only_request(cip, mac)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000301 assert_equal(new_cip,cip)
302 log.info('server offered same IP to clain for multiple requests, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700303
A R Karthick10fe00e2016-07-12 16:13:16 -0700304 def test_dhcp_client_desired_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700305 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700306 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
307 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
308 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000309 self.dhcp = DHCPTest(seed_ip = '20.20.20.50', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700310 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000311 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700312 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000313 (cip, sip, mac))
314 assert_equal(cip,self.dhcp.seed_ip)
315 log.info('ONOS dhcp server offered client requested IP %s as expected'%self.dhcp.seed_ip)
ChetanGaonker42d75812016-06-06 16:32:52 -0700316
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000317 #test failing, server not returns NAK when requested out of pool IP
A R Karthick10fe00e2016-07-12 16:13:16 -0700318 def test_dhcp_client_desired_address_out_of_pool(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700319 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700320 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
321 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
322 self.onos_dhcp_table_load(config)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000323 self.dhcp = DHCPTest(seed_ip = '20.20.20.75', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700324 cip, sip, mac, _ = self.dhcp.only_discover(desired = True)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000325 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700326 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf72ca402016-05-02 16:29:32 -0700327 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000328 assert_not_equal(cip,self.dhcp.seed_ip)
329 log.info('server offered IP from its pool of IPs when requested out of pool IP, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700330
331
A R Karthick10fe00e2016-07-12 16:13:16 -0700332 def test_dhcp_server_nak_packet(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700333 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700334 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
335 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
336 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700337 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700338 cip, sip, mac, _ = self.dhcp.only_discover()
339 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700340 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000341 assert_not_equal(cip, None)
342 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
343 assert_equal(new_cip, None) #Negative Test Case
344 log.info('dhcp servers sent NAK as expected when requested different IP from same client')
ChetanGaonker42d75812016-06-06 16:32:52 -0700345
346
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000347 #test_dhcp_lease_packet
348 def test_dhcp_client_requests_specific_lease_time_in_discover(self,lease_time = 700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700349 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700350 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
351 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
352 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700353 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000354 self.dhcp.return_option = 'lease'
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700355 log.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000356 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value = lease_time)
357 assert_equal(lval, 700)
358 log.info('dhcp server offered IP address with client requested lease time')
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700359
A R Karthick10fe00e2016-07-12 16:13:16 -0700360 def test_dhcp_client_request_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700361 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700362 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
363 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
364 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700365 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700366 cip, sip, mac, _ = self.dhcp.only_discover()
367 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700368 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000369 assert_not_equal(cip,None)
370 new_cip, new_sip = self.dhcp.only_request(cip, mac)
371 log.info('verifying client IP after reboot')
372 os.system('ifconfig '+self.iface+' down')
373 time.sleep(5)
374 os.system('ifconfig '+self.iface+' up')
375 new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True)
376 assert_equal(new_cip,cip)
377 log.info('client got same ip after reboot, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700378
379
A R Karthick10fe00e2016-07-12 16:13:16 -0700380 def test_dhcp_server_after_reboot(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700381 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700382 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
383 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
384 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700385 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700386 cip, sip, mac, _ = self.dhcp.only_discover()
387 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerf1483862016-05-06 14:14:31 -0700388 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000389 assert_not_equal(cip, None)
390 new_cip, new_sip = self.dhcp.only_request(cip, mac)
391 self.onos_ctrl.deactivate()
392 new_cip1, new_sip = self.dhcp.only_request(cip, mac)
393 assert_equal(new_cip1,None)
394 status, _ = self.onos_ctrl.activate()
395 assert_equal(status, True)
396 time.sleep(3)
397 new_cip2, new_sip = self.dhcp.only_request(cip, mac)
398 assert_equal(new_cip2,cip)
399 log.info('client got same ip after server reboot, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700400
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000401 def test_dhcp_specific_lease_time_only_in_discover_but_not_in_request_packet(self,lease_time=700):
ChetanGaonker42d75812016-06-06 16:32:52 -0700402 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700403 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
404 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
405 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700406 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700407 log.info('Sending DHCP discover with lease time of 700')
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000408 cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True,lease_value=lease_time)
ChetanGaonker42d75812016-06-06 16:32:52 -0700409 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700410 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000411 assert_not_equal(cip, None)
412 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True)
413 assert_equal(new_cip,cip)
414 assert_not_equal(lval, lease_time) #Negative Test Case
415 log.info('client requested lease time only in discover but not in request, not seen in server ACK packet as expected')
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700416
417
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000418 def test_dhcp_specific_lease_time_only_in_request_but_not_in_discover_packet(self,lease_time=800):
ChetanGaonker42d75812016-06-06 16:32:52 -0700419 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700420 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
421 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
422 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700423 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700424 cip, sip, mac, _ = self.dhcp.only_discover()
425 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700426 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000427 assert_not_equal(cip, None)
428 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True, lease_value=lease_time)
429 assert_equal(lval, lease_time)
430 log.info('client requested lease time in request packet, seen in server ACK packet as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700431
A R Karthick10fe00e2016-07-12 16:13:16 -0700432 def test_dhcp_client_renew_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700433
434 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700435 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
436 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
437 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700438 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700439 cip, sip, mac, _ = self.dhcp.only_discover()
440 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700441 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000442 assert_not_equal(cip, None)
443 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
444 log.info('waiting renew time %d seconds to send next request packet'%lval)
445 time.sleep(lval)
446 latest_cip, latest_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
447 assert_equal(latest_cip,cip)
448 log.info('client got same IP after renew time, as expected')
ChetanGaonker42d75812016-06-06 16:32:52 -0700449
A R Karthick10fe00e2016-07-12 16:13:16 -0700450 def test_dhcp_client_rebind_time(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700451
452 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)
A R Karthick10fe00e2016-07-12 16:13:16 -0700456 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700457 cip, sip, mac, _ = self.dhcp.only_discover()
458 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonkerc11d3222016-05-11 17:39:36 -0700459 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000460 assert_not_equal(cip, None)
461 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
462 log.info('waiting rebind time %d seconds to send next request packet'%lval)
463 time.sleep(lval)
464 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
465 assert_equal(latest_cip,cip)
466 log.info('client got same IP after rebind time, as expected')
Chetan Gaonker717b2942016-05-13 17:42:59 -0700467
A R Karthick10fe00e2016-07-12 16:13:16 -0700468 def test_dhcp_client_expected_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700469
470 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker717b2942016-05-13 17:42:59 -0700471 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
472 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
473 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700474 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700475 expected_subnet = '255.255.255.0'
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700476 self.dhcp.return_option = 'subnet'
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000477 cip, sip, mac, subnet_mask = self.dhcp.only_discover()
478 assert_equal(subnet_mask, expected_subnet)
479 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700480 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker717b2942016-05-13 17:42:59 -0700481 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000482 log.info('seen expected subnet mask %s in dhcp offer packet'%subnet_mask)
Chetan Gaonker717b2942016-05-13 17:42:59 -0700483
A R Karthick10fe00e2016-07-12 16:13:16 -0700484 def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700485
486 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700487 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
488 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
489 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700490 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700491
492 cip, sip, mac, _ = self.dhcp.only_discover()
493 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700494 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000495 assert_not_equal(cip, None)
496 self.dhcp.send_different_option = 'subnet'
497 new_cip, new_sip = self.dhcp.only_request(cip, mac)
498 assert_equal(new_cip, cip)
499 log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700500
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700501
A R Karthick10fe00e2016-07-12 16:13:16 -0700502 def test_dhcp_client_expected_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700503
504 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700505 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
506 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
507 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700508 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700509 expected_router_address = '20.20.20.1'
510 self.dhcp.return_option = 'router'
ChetanGaonker42d75812016-06-06 16:32:52 -0700511
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000512 cip, sip, mac, router_address_ip = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700513 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700514 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000515 assert_not_equal(cip, None)
516 assert_equal(expected_router_address, router_address_ip)
517 log.info('seen expected rouer address %s ip in dhcp offer packet'%router_address_ip)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700518
A R Karthick10fe00e2016-07-12 16:13:16 -0700519 def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700520
521 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700522 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
523 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
524 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700525 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700526
527 cip, sip, mac, _ = self.dhcp.only_discover()
528 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700529 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000530 assert_not_equal(cip, None)
531 self.dhcp.send_different_option = 'router'
532 new_cip, new_sip = self.dhcp.only_request(cip, mac)
533 assert_equal(new_cip, cip)
534 log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700535
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700536
A R Karthick10fe00e2016-07-12 16:13:16 -0700537 def test_dhcp_client_expected_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700538
539 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700540 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
541 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
542 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700543 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700544 expected_broadcast_address = '20.20.20.255'
545 self.dhcp.return_option = 'broadcast_address'
ChetanGaonker42d75812016-06-06 16:32:52 -0700546
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000547 cip, sip, mac, broadcast_address = self.dhcp.only_discover()
ChetanGaonker42d75812016-06-06 16:32:52 -0700548 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700549 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000550 assert_not_equal(cip, None)
551 assert_equal(expected_broadcast_address, broadcast_address)
552 log.info('seen expected broadcast address %s in dhcp offer packet'%broadcast_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700553
A R Karthick10fe00e2016-07-12 16:13:16 -0700554 def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700555
556 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700557 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
558 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
559 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700560 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700561
562 cip, sip, mac, _ = self.dhcp.only_discover()
563 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700564 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000565 assert_not_equal(cip, None)
566 self.dhcp.send_different_option = 'broadcast_address'
567 new_cip, new_sip = self.dhcp.only_request(cip, mac)
568 assert_equal(new_cip, cip)
569 log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700570
A R Karthick10fe00e2016-07-12 16:13:16 -0700571 def test_dhcp_client_expected_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700572
573 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700574 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
575 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
576 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700577 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700578 expected_dns_address = '8.8.8.8'
579 self.dhcp.return_option = 'dns'
ChetanGaonker42d75812016-06-06 16:32:52 -0700580
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000581 cip, sip, mac, dns_address = self.dhcp.only_discover()
582 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700583 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700584 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000585 assert_equal(expected_dns_address, dns_address)
586 log.info('seen expected DNS ip address %s in dhcp offer packet'%dns_address)
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700587
A R Karthick10fe00e2016-07-12 16:13:16 -0700588 def test_dhcp_client_sends_request_with_wrong_dns_address(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700589
590 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700591 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
592 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'}
593 self.onos_dhcp_table_load(config)
A R Karthick10fe00e2016-07-12 16:13:16 -0700594 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface)
ChetanGaonker42d75812016-06-06 16:32:52 -0700595
596 cip, sip, mac, _ = self.dhcp.only_discover()
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000597 assert_not_equal(cip, None)
ChetanGaonker42d75812016-06-06 16:32:52 -0700598 log.info('Got dhcp client IP %s from server %s for mac %s .' %
Chetan Gaonker1dabecc2016-05-16 14:56:01 -0700599 (cip, sip, mac) )
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000600 self.dhcp.send_different_option = 'dns'
601 new_cip, new_sip = self.dhcp.only_request(cip, mac)
602 assert_equal(new_cip, cip)
603 log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.")
ChetanGaonker42d75812016-06-06 16:32:52 -0700604
A R Karthick10fe00e2016-07-12 16:13:16 -0700605 def test_dhcp_server_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700606
607 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700608 self.stats()
ChetanGaonker42d75812016-06-06 16:32:52 -0700609 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700610 log.info("----------------------------------------------------------------------------------")
611 log.info("No. of transactions No. of successes No. of failures Running Time ")
612 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
613 log.info("----------------------------------------------------------------------------------")
614 log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count))
615
ChetanGaonker42d75812016-06-06 16:32:52 -0700616 log.info("Final Statistics for total transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700617 log.info("----------------------------------------------------------------------------------")
618 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700619 log.info(" %d %d %d %d" %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700620 self.total_success, self.total_failure, self.running_time))
621 log.info("----------------------------------------------------------------------------------")
622 log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0))
623
A R Karthick10fe00e2016-07-12 16:13:16 -0700624 def test_dhcp_server_consecutive_successes_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700625
626 for i in range(1,4):
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700627 self.stats(success_rate = True)
ChetanGaonker42d75812016-06-06 16:32:52 -0700628 log.info("Stats for run %d",i)
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700629 log.info("----------------------------------------------------------------------------------")
630 log.info("No. of consecutive successful transactions Running Time ")
631 log.info(" %d %d " %(self.ip_count, self.diff))
632 log.info("----------------------------------------------------------------------------------")
633 log.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count))
ChetanGaonker42d75812016-06-06 16:32:52 -0700634 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700635
ChetanGaonker42d75812016-06-06 16:32:52 -0700636 log.info("Final Statistics for total successful transactions")
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700637 log.info("----------------------------------------------------------------------------------")
638 log.info("Total transactions Total No. of consecutive successes Running Time ")
ChetanGaonker42d75812016-06-06 16:32:52 -0700639 log.info(" %d %d %d " %(self.transactions,
Chetan Gaonker4a82bae2016-05-19 17:35:30 -0700640 self.total_success, self.running_time))
641 log.info("----------------------------------------------------------------------------------")
ChetanGaonker42d75812016-06-06 16:32:52 -0700642 log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0))
643 log.info("----------------------------------------------------------------------------------")
Chetan Gaonker717b2942016-05-13 17:42:59 -0700644
ChetanGaonker42d75812016-06-06 16:32:52 -0700645
A R Karthick10fe00e2016-07-12 16:13:16 -0700646 def test_dhcp_server_client_transactions_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700647
648 for i in range(1,4):
649 self.stats(only_discover = True)
650 log.info("----------------------------------------------------------------------------------")
651 log.info("Stats for run %d of sending only DHCP Discover",i)
652 log.info("----------------------------------------------------------------------------------")
653 log.info("No. of transactions No. of successes No. of failures Running Time ")
654 log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff))
655 log.info("----------------------------------------------------------------------------------")
656 log.info("No. of clients per second in run %d:%f "
657 %(i, self.transaction_count))
658 log.info("----------------------------------------------------------------------------------")
659 log.info("Final Statistics for total transactions of sending only DHCP Discover")
660 log.info("----------------------------------------------------------------------------------")
661 log.info("Total transactions Total No. of successes Total No. of failures Running Time ")
662 log.info(" %d %d %d %d" %(self.transactions,
663 self.total_success, self.total_failure, self.running_time))
664 log.info("----------------------------------------------------------------------------------")
665 log.info("Average no. of clients per second: %d ",
666 round(self.transactions/self.running_time,0))
667 log.info("----------------------------------------------------------------------------------")
668
A R Karthick10fe00e2016-07-12 16:13:16 -0700669 def test_dhcp_server_consecutive_successful_clients_per_second(self):
ChetanGaonker42d75812016-06-06 16:32:52 -0700670
671 for i in range(1,4):
672 self.stats(success_rate = True, only_discover = True)
673 log.info("----------------------------------------------------------------------------------")
674 log.info("Stats for run %d for sending only DHCP Discover",i)
675 log.info("----------------------------------------------------------------------------------")
676 log.info("No. of consecutive successful transactions Running Time ")
677 log.info(" %d %d " %(self.ip_count, self.diff))
678 log.info("----------------------------------------------------------------------------------")
679 log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count))
680 log.info("----------------------------------------------------------------------------------")
681
682 log.info("Final Statistics for total successful transactions")
683 log.info("----------------------------------------------------------------------------------")
684 log.info("Total transactions Total No. of consecutive successes Running Time ")
685 log.info(" %d %d %d " %(self.transactions,
686 self.total_success, self.running_time))
687 log.info("----------------------------------------------------------------------------------")
688 log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0))
689 log.info("----------------------------------------------------------------------------------")
Anil Kumar Sankacfa7c582016-12-09 23:17:22 +0000690