Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 1 | # |
| 2 | # 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 16 | import unittest |
| 17 | from nose.tools import * |
| 18 | from nose.twistedtools import reactor, deferred |
| 19 | from twisted.internet import defer |
| 20 | from scapy.all import * |
| 21 | import time |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 22 | import copy |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 23 | from DHCP import DHCPTest |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 24 | from OnosCtrl import OnosCtrl |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 25 | log.setLevel('INFO') |
| 26 | |
| 27 | class 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 37 | "delay": "2", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 38 | "startip": "10.1.11.51", |
| 39 | "endip": "10.1.11.100" |
| 40 | } |
| 41 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 42 | app = 'org.onosproject.dhcp' |
| 43 | |
| 44 | def setUp(self): |
| 45 | ''' Activate the dhcp app''' |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 46 | self.maxDiff = None ##for assert_equal compare outputs on failure |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 47 | self.onos_ctrl = OnosCtrl(self.app) |
| 48 | status, _ = self.onos_ctrl.activate() |
| 49 | assert_equal(status, True) |
| 50 | time.sleep(3) |
| 51 | |
| 52 | def teardown(self): |
| 53 | '''Deactivate the dhcp app''' |
| 54 | self.onos_ctrl.deactivate() |
| 55 | |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 56 | def onos_load_config(self, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 57 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 58 | if status is False: |
| 59 | log.info('JSON request returned status %d' %code) |
| 60 | assert_equal(status, True) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 61 | time.sleep(3) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 62 | |
| 63 | def onos_dhcp_table_load(self, config = None): |
| 64 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 65 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 66 | if config: |
| 67 | for k in config.keys(): |
| 68 | if dhcp_config.has_key(k): |
| 69 | dhcp_config[k] = config[k] |
| 70 | self.onos_load_config(dhcp_dict) |
| 71 | |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 72 | def send_recv(self, mac = None, update_seed = False, validate = True): |
| 73 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 74 | if validate: |
| 75 | assert_not_equal(cip, None) |
| 76 | assert_not_equal(sip, None) |
| 77 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
| 78 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 79 | return cip,sip |
| 80 | |
| 81 | def test_dhcp_1request(self, iface = 'veth0'): |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 82 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 83 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 84 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 85 | self.onos_dhcp_table_load(config) |
| 86 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 87 | self.send_recv() |
| 88 | |
| 89 | def test_dhcp_Nrequest(self, iface = 'veth0'): |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 90 | config = {'startip':'192.168.1.20', 'endip':'192.168.1.69', |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 91 | 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe", |
| 92 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 93 | self.onos_dhcp_table_load(config) |
| 94 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface) |
| 95 | ip_map = {} |
| 96 | for i in range(10): |
| 97 | cip, sip = self.send_recv(update_seed = True) |
| 98 | if ip_map.has_key(cip): |
| 99 | log.info('IP %s given out multiple times' %cip) |
| 100 | assert_equal(False, ip_map.has_key(cip)) |
| 101 | ip_map[cip] = sip |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 102 | |
| 103 | def test_dhcp_1release(self, iface = 'veth0'): |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 104 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', |
| 105 | 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe", |
| 106 | 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'} |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 107 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 108 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 109 | cip, sip = self.send_recv() |
| 110 | log.info('Releasing ip %s to server %s' %(cip, sip)) |
| 111 | assert_equal(self.dhcp.release(cip), True) |
| 112 | log.info('Triggering DHCP discover again after release') |
| 113 | cip2, sip2 = self.send_recv(update_seed = True) |
| 114 | log.info('Verifying released IP was given back on rediscover') |
| 115 | assert_equal(cip, cip2) |
| 116 | log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 117 | assert_equal(self.dhcp.release(cip2), True) |
| 118 | |
| 119 | def test_dhcp_Nrelease(self, iface = 'veth0'): |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 120 | config = {'startip':'192.170.1.20', 'endip':'192.170.1.30', |
| 121 | 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe", |
| 122 | 'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'} |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 123 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 124 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 125 | ip_map = {} |
| 126 | for i in range(10): |
| 127 | cip, sip = self.send_recv(update_seed = True) |
| 128 | if ip_map.has_key(cip): |
| 129 | log.info('IP %s given out multiple times' %cip) |
| 130 | assert_equal(False, ip_map.has_key(cip)) |
| 131 | ip_map[cip] = sip |
| 132 | |
| 133 | for ip in ip_map.keys(): |
| 134 | log.info('Releasing IP %s' %ip) |
| 135 | assert_equal(self.dhcp.release(ip), True) |
| 136 | |
| 137 | ip_map2 = {} |
| 138 | log.info('Triggering DHCP discover again after release') |
| 139 | for i in range(len(ip_map.keys())): |
| 140 | cip, sip = self.send_recv(update_seed = True) |
| 141 | ip_map2[cip] = sip |
| 142 | |
| 143 | log.info('Verifying released IPs were given back on rediscover') |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 144 | if ip_map != ip_map2: |
| 145 | log.info('Map before release %s' %ip_map) |
| 146 | log.info('Map after release %s' %ip_map2) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 147 | assert_equal(ip_map, ip_map2) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 148 | |
| 149 | |
| 150 | def test_dhcp_starvation(self, iface = 'veth0'): |
| 151 | config = {'startip':'193.170.1.20', 'endip':'193.170.1.69', |
| 152 | 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe", |
| 153 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 154 | self.onos_dhcp_table_load(config) |
| 155 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = iface) |
| 156 | ip_map = {} |
| 157 | for i in range(10): |
| 158 | cip, sip = self.send_recv(update_seed = True) |
| 159 | if ip_map.has_key(cip): |
| 160 | log.info('IP %s given out multiple times' %cip) |
| 161 | assert_equal(False, ip_map.has_key(cip)) |
| 162 | ip_map[cip] = sip |
| 163 | |
| 164 | |
| 165 | def test_dhcp_starvation(self, iface = 'veth0'): |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 166 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
| 167 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 168 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'} |
| 169 | self.onos_dhcp_table_load(config) |
| 170 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 171 | log.info('Verifying 1 ') |
| 172 | for x in xrange(50): |
| 173 | mac = RandMAC()._fix() |
| 174 | self.send_recv(mac = mac) |
| 175 | log.info('Verifying 2 ') |
| 176 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 177 | assert_equal(cip, None) |
| 178 | assert_equal(sip, None) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 179 | |
| 180 | |
| 181 | def test_dhcp_same_client_multiple_discover(self, iface = 'veth0'): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 182 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 183 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 184 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 185 | self.onos_dhcp_table_load(config) |
| 186 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 187 | cip, sip, mac = self.dhcp.only_discover() |
| 188 | log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
| 189 | (cip, sip, mac) ) |
| 190 | log.info('Triggering DHCP discover again.') |
| 191 | new_cip, new_sip, new_mac = self.dhcp.only_discover() |
| 192 | if cip == new_cip: |
| 193 | log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. ' |
| 194 | % (new_cip, new_sip, new_mac) ) |
| 195 | elif cip != new_cip: |
| 196 | log.info('Ip after 1st discover %s' %cip) |
| 197 | log.info('Map after 2nd discover %s' %new_cip) |
| 198 | assert_equal(cip, new_cip) |
| 199 | |
| 200 | |
| 201 | def test_dhcp_same_client_multiple_request(self, iface = 'veth0'): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 202 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 203 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 204 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 205 | self.onos_dhcp_table_load(config) |
| 206 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 207 | log.info('Sending DHCP discover and DHCP request.') |
| 208 | cip, sip = self.send_recv() |
| 209 | mac = self.dhcp.get_mac(cip)[0] |
| 210 | log.info("Sending DHCP request again.") |
| 211 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 212 | if (new_cip,new_sip) == (cip,sip): |
| 213 | |
| 214 | log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.' |
| 215 | % (new_cip, new_sip, mac) ) |
| 216 | elif (new_cip,new_sip): |
| 217 | |
| 218 | log.info('No DHCP ACK') |
| 219 | assert_equal(new_cip, None) |
| 220 | assert_equal(new_sip, None) |
| 221 | else: |
| 222 | print "Something went wrong." |
| 223 | |
| 224 | def test_dhcp_client_desired_address(self, iface = 'veth0'): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 225 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 226 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 227 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 228 | self.onos_dhcp_table_load(config) |
| 229 | self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface) |
| 230 | cip, sip, mac = self.dhcp.only_discover(desired = True) |
| 231 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 232 | (cip, sip, mac) ) |
| 233 | if cip == self.dhcp.seed_ip: |
| 234 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 235 | (cip, sip, mac) ) |
| 236 | elif cip != self.dhcp.seed_ip: |
| 237 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 238 | (cip, sip, mac) ) |
| 239 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 240 | assert_equal(cip, self.dhcp.seed_ip) |
| 241 | |
| 242 | |
| 243 | def test_dhcp_client_desired_address_out_of_pool(self, iface = 'veth0'): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 244 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 245 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 246 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 247 | self.onos_dhcp_table_load(config) |
| 248 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 249 | cip, sip, mac = self.dhcp.only_discover(desired = True) |
| 250 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 251 | (cip, sip, mac) ) |
| 252 | if cip == self.dhcp.seed_ip: |
| 253 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 254 | (cip, sip, mac) ) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 255 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
| 256 | |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 257 | elif cip != self.dhcp.seed_ip: |
| 258 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 259 | (cip, sip, mac) ) |
| 260 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 261 | assert_not_equal(cip, self.dhcp.seed_ip) |
| 262 | |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 263 | elif cip == None: |
| 264 | log.info('Got DHCP NAK') |
| 265 | |
| 266 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 267 | def test_dhcp_server_nak_packet(self, iface = 'veth0'): |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 268 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 269 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 270 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 271 | self.onos_dhcp_table_load(config) |
| 272 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 273 | cip, sip, mac = self.dhcp.only_discover() |
| 274 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 275 | (cip, sip, mac) ) |
| 276 | |
| 277 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 278 | if (cip == None and mac != None): |
| 279 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 280 | assert_not_equal(cip, None) |
| 281 | else: |
| 282 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 283 | if new_cip == None: |
| 284 | |
| 285 | log.info("Got DHCP server NAK.") |
| 286 | assert_equal(new_cip, None) #Negative Test Case |
| 287 | |
| 288 | |
| 289 | def test_dhcp_lease_packet(self, iface = 'veth0'): |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 290 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 291 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 292 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 293 | self.onos_dhcp_table_load(config) |
| 294 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 295 | log.info('Sending DHCP discover with lease time of 700') |
| 296 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True) |
| 297 | |
| 298 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 299 | if (cip == None and mac != None): |
| 300 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 301 | assert_not_equal(cip, None) |
| 302 | elif lval != 700: |
| 303 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
| 304 | (cip, sip, mac, lval) ) |
| 305 | assert_not_equal(lval, 700) |
| 306 | |
| 307 | def test_dhcp_client_request_after_reboot(self, iface = 'veth0'): |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 308 | |
| 309 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 310 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 311 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 312 | self.onos_dhcp_table_load(config) |
| 313 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 314 | cip, sip, mac = self.dhcp.only_discover() |
| 315 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 316 | (cip, sip, mac) ) |
| 317 | |
| 318 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 319 | |
| 320 | if (cip == None and mac != None): |
| 321 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 322 | assert_not_equal(cip, None) |
| 323 | |
| 324 | else: |
| 325 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 326 | if new_cip == None: |
| 327 | log.info("Got DHCP server NAK.") |
| 328 | os.system('ifconfig '+iface+' down') |
| 329 | log.info('Client goes down.') |
| 330 | log.info('Delay for 5 seconds.') |
| 331 | |
| 332 | time.sleep(5) |
| 333 | |
| 334 | os.system('ifconfig '+iface+' up') |
| 335 | log.info('Client is up now.') |
| 336 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 337 | new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 338 | if new_cip == None: |
| 339 | log.info("Got DHCP server NAK.") |
| 340 | assert_not_equal(new_cip, None) |
| 341 | elif new_cip != None: |
| 342 | log.info("Got DHCP ACK.") |
| 343 | |
| 344 | |
| 345 | |
| 346 | def test_dhcp_server_after_reboot(self, iface = 'veth0'): |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 347 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 348 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 349 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 350 | self.onos_dhcp_table_load(config) |
| 351 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 352 | cip, sip, mac = self.dhcp.only_discover() |
| 353 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 354 | (cip, sip, mac) ) |
| 355 | |
| 356 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 357 | |
| 358 | if (cip == None and mac != None): |
| 359 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 360 | assert_not_equal(cip, None) |
| 361 | |
| 362 | else: |
| 363 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 364 | if new_cip == None: |
| 365 | log.info("Got DHCP server NAK.") |
| 366 | assert_not_equal(new_cip, None) |
| 367 | log.info('Getting DHCP server Down.') |
| 368 | |
| 369 | self.onos_ctrl.deactivate() |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 370 | |
| 371 | for i in range(0,4): |
| 372 | log.info("Sending DHCP Request.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 373 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 374 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 375 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 376 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 377 | log.info("DHCP Request timed out.") |
| 378 | elif new_cip and new_sip: |
| 379 | log.info("Got Reply from DHCP server.") |
| 380 | assert_equal(new_cip,None) #Neagtive Test Case |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 381 | |
| 382 | log.info('Getting DHCP server Up.') |
| 383 | |
| 384 | status, _ = self.onos_ctrl.activate() |
| 385 | assert_equal(status, True) |
| 386 | time.sleep(3) |
| 387 | |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 388 | for i in range(0,4): |
| 389 | log.info("Sending DHCP Request after DHCP server is up.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 390 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 391 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 392 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 393 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 394 | log.info("DHCP Request timed out.") |
| 395 | elif new_cip and new_sip: |
| 396 | log.info("Got Reply from DHCP server.") |
| 397 | assert_equal(new_cip,None) #Neagtive Test Case |
| 398 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 399 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 400 | def test_dhcp_specific_lease_packet(self, iface = 'veth0'): |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 401 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 402 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 403 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 404 | self.onos_dhcp_table_load(config) |
| 405 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 406 | log.info('Sending DHCP discover with lease time of 700') |
| 407 | cip, sip, mac = self.dhcp.only_discover(lease_time = True) |
| 408 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 409 | (cip, sip, mac) ) |
| 410 | |
| 411 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 412 | if (cip == None and mac != None): |
| 413 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 414 | assert_not_equal(cip, None) |
| 415 | elif cip and sip and mac: |
| 416 | |
| 417 | log.info("Triggering DHCP Request.") |
| 418 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 419 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
| 420 | (new_cip, new_sip, mac, lval) ) |
| 421 | assert_not_equal(lval, 700) #Negative Test Case |
| 422 | |
| 423 | |
| 424 | |
| 425 | def test_dhcp_lease_packet(self, iface = 'veth0'): |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 426 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 427 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 428 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 429 | self.onos_dhcp_table_load(config) |
| 430 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 431 | cip, sip, mac = self.dhcp.only_discover() |
| 432 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 433 | (cip, sip, mac) ) |
| 434 | |
| 435 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 436 | if (cip == None and mac != None): |
| 437 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 438 | assert_not_equal(cip, None) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 439 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 440 | elif cip and sip and mac: |
| 441 | |
| 442 | log.info("Triggering DHCP Request.") |
| 443 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 444 | if lval == 600: |
| 445 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' % |
| 446 | (new_cip, new_sip, mac, lval) ) |
| 447 | else: |
| 448 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' % |
| 449 | (new_cip, new_sip, mac, lval) ) |
| 450 | log.info('The lease time suppossed to be 600 secs or 10 mins.') |
| 451 | assert_equal(lval, 600) |
| 452 | |
| 453 | def test_dhcp_client_renew_time(self, iface = 'veth0'): |
| 454 | |
| 455 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 456 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 457 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 458 | self.onos_dhcp_table_load(config) |
| 459 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 460 | cip, sip, mac = self.dhcp.only_discover() |
| 461 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 462 | (cip, sip, mac) ) |
| 463 | |
| 464 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 465 | if (cip == None and mac != None): |
| 466 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 467 | assert_not_equal(cip, None) |
| 468 | |
| 469 | elif cip and sip and mac: |
| 470 | |
| 471 | log.info("Triggering DHCP Request.") |
| 472 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 473 | |
| 474 | if new_cip and new_sip and lval: |
| 475 | |
| 476 | log.info("Clinet 's Renewal time is :%s",lval) |
| 477 | log.info("Generating delay till renewal time.") |
| 478 | time.sleep(lval) |
| 479 | |
| 480 | log.info("Client Sending Unicast DHCP request.") |
| 481 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 482 | |
| 483 | if latest_cip and latest_sip: |
| 484 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 485 | (latest_cip, mac, latest_sip) ) |
| 486 | |
| 487 | elif latest_cip == None: |
| 488 | log.info("Got DHCP NAK. Lease not renewed.") |
| 489 | |
| 490 | elif new_cip == None or new_sip == None or lval == None: |
| 491 | |
| 492 | log.info("Got DHCP NAK.") |
| 493 | |
| 494 | |
| 495 | |
| 496 | def test_dhcp_client_rebind_time(self, iface = 'veth0'): |
| 497 | |
| 498 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 499 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 500 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 501 | self.onos_dhcp_table_load(config) |
| 502 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 503 | cip, sip, mac = self.dhcp.only_discover() |
| 504 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 505 | (cip, sip, mac) ) |
| 506 | |
| 507 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 508 | if (cip == None and mac != None): |
| 509 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 510 | assert_not_equal(cip, None) |
| 511 | |
| 512 | elif cip and sip and mac: |
| 513 | |
| 514 | log.info("Triggering DHCP Request.") |
| 515 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 516 | |
| 517 | if new_cip and new_sip and lval: |
| 518 | |
| 519 | log.info("Clinet 's Rebind time is :%s",lval) |
| 520 | log.info("Generating delay till rebind time.") |
| 521 | time.sleep(lval) |
| 522 | |
| 523 | log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.") |
| 524 | |
| 525 | for i in range(0,4): |
| 526 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 527 | |
| 528 | if latest_cip and latest_sip: |
| 529 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 530 | (latest_cip, mac, latest_sip) ) |
| 531 | |
| 532 | elif latest_cip == None: |
| 533 | log.info("Got DHCP NAK. Lease not renewed.") |
| 534 | assert_not_equal(latest_cip, None) |
| 535 | elif new_cip == None or new_sip == None or lval == None: |
| 536 | |
| 537 | log.info("Got DHCP NAK.Lease not Renewed.") |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 538 | |