ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 1 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 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 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 7 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 9 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 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 | } |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 41 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 42 | app = 'org.onosproject.dhcp' |
| 43 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 44 | 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 Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 56 | def setUp(self): |
| 57 | ''' Activate the dhcp app''' |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 58 | self.maxDiff = None ##for assert_equal compare outputs on failure |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 59 | 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 68 | def onos_load_config(self, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 69 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 70 | if status is False: |
| 71 | log.info('JSON request returned status %d' %code) |
| 72 | assert_equal(status, True) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 73 | time.sleep(3) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 74 | |
| 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 Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 84 | 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 91 | return cip,sip |
| 92 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 93 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 94 | def stats(self,success_rate = False, only_discover = False, iface = 'veth0'): |
| 95 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 96 | self.ip_count = 0 |
| 97 | self.failure_count = 0 |
| 98 | self.start_time = 0 |
| 99 | self.diff = 0 |
| 100 | self.transaction_count = 0 |
| 101 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 102 | config = {'startip':'182.17.0.3', 'endip':'182.17.0.180', |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 103 | '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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 110 | 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 Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 117 | if cip: |
| 118 | self.ip_count +=1 |
| 119 | elif cip == None: |
| 120 | self.failure_count += 1 |
| 121 | log.info('Failed to get ip') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 122 | if success_rate and self.ip_count > 0: |
| 123 | break |
| 124 | self.diff = round(time.time() - self.start_time, 0) |
| 125 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 126 | |
| 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 136 | def test_dhcp_1request(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 137 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 138 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 139 | '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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 145 | config = {'startip':'192.168.1.20', 'endip':'192.168.1.69', |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 146 | '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 Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 157 | |
| 158 | def test_dhcp_1release(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 159 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 160 | '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 Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 162 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 163 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 164 | 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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 175 | config = {'startip':'192.170.1.20', 'endip':'192.170.1.30', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 176 | '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 Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 178 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 179 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 180 | 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 Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 199 | if ip_map != ip_map2: |
| 200 | log.info('Map before release %s' %ip_map) |
| 201 | log.info('Map after release %s' %ip_map2) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 202 | assert_equal(ip_map, ip_map2) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 203 | |
| 204 | |
| 205 | def test_dhcp_starvation(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 206 | config = {'startip':'193.170.1.20', 'endip':'193.170.1.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 207 | '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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 221 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 222 | '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 Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 234 | |
| 235 | |
| 236 | def test_dhcp_same_client_multiple_discover(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 237 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 238 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 242 | 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 Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 244 | (cip, sip, mac) ) |
| 245 | log.info('Triggering DHCP discover again.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 246 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 247 | 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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 257 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 258 | '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 Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 268 | 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): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 271 | log.info('No DHCP ACK') |
| 272 | assert_equal(new_cip, None) |
| 273 | assert_equal(new_sip, None) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 274 | else: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 275 | log.info('Something went wrong.') |
| 276 | |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 277 | def test_dhcp_client_desired_address(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 278 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 279 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 283 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 284 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 285 | (cip, sip, mac) ) |
| 286 | if cip == self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 287 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 288 | (cip, sip, mac) ) |
| 289 | elif cip != self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 290 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 291 | (cip, sip, mac) ) |
| 292 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 293 | assert_equal(cip, self.dhcp.seed_ip) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 294 | |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 295 | def test_dhcp_client_desired_address_out_of_pool(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 296 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 297 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 301 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 302 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 303 | (cip, sip, mac) ) |
| 304 | if cip == self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 305 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 306 | (cip, sip, mac) ) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 307 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 308 | elif cip != self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 309 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 310 | (cip, sip, mac) ) |
| 311 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 312 | assert_not_equal(cip, self.dhcp.seed_ip) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 313 | elif cip == None: |
| 314 | log.info('Got DHCP NAK') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 315 | |
| 316 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 317 | def test_dhcp_server_nak_packet(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 318 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 319 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 323 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 324 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 325 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 326 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 327 | 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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 334 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 335 | log.info("Got DHCP server NAK.") |
| 336 | assert_equal(new_cip, None) #Negative Test Case |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 337 | |
| 338 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 339 | def test_dhcp_lease_packet(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 340 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 341 | '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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 353 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 354 | (cip, sip, mac, lval) ) |
| 355 | assert_not_equal(lval, 700) |
| 356 | |
| 357 | def test_dhcp_client_request_after_reboot(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 358 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 359 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 363 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 364 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 365 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 366 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 367 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 368 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 369 | 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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 372 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 373 | 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.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 380 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 381 | time.sleep(5) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 382 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 383 | os.system('ifconfig '+iface+' up') |
| 384 | log.info('Client is up now.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 385 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 386 | 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] | 387 | 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 Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 392 | os.system('ifconfig '+iface+' up') |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 393 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 394 | |
| 395 | |
| 396 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 397 | def test_dhcp_server_after_reboot(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 398 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 399 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 403 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 404 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 405 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 406 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 407 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 408 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 409 | 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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 412 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 413 | 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.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 419 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 420 | self.onos_ctrl.deactivate() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 421 | |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 422 | for i in range(0,4): |
| 423 | log.info("Sending DHCP Request.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 424 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 425 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 426 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 427 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 428 | 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 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 432 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 433 | log.info('Getting DHCP server Up.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 434 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 435 | status, _ = self.onos_ctrl.activate() |
| 436 | assert_equal(status, True) |
| 437 | time.sleep(3) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 438 | |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 439 | for i in range(0,4): |
| 440 | log.info("Sending DHCP Request after DHCP server is up.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 441 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 442 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 443 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 444 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 445 | 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 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 449 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 450 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 451 | def test_dhcp_specific_lease_packet(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 452 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 453 | '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') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 458 | 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 Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 460 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 465 | assert_not_equal(cip, None) |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 466 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 467 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 468 | log.info("Triggering DHCP Request.") |
| 469 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 470 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 471 | (new_cip, new_sip, mac, lval) ) |
| 472 | assert_not_equal(lval, 700) #Negative Test Case |
| 473 | |
| 474 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 475 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 476 | def test_dhcp_lease_packet(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 477 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 478 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 482 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 483 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 484 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 489 | assert_not_equal(cip, None) |
| 490 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 491 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 492 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 493 | log.info("Triggering DHCP Request.") |
| 494 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 495 | if lval == 600: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 496 | 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 Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 498 | else: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 499 | 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 Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 501 | log.info('The lease time suppossed to be 600 secs or 10 mins.') |
| 502 | assert_equal(lval, 600) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 503 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 504 | def test_dhcp_client_renew_time(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 505 | |
| 506 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 507 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 511 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 512 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 513 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 518 | assert_not_equal(cip, None) |
| 519 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 520 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 521 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 522 | log.info("Triggering DHCP Request.") |
| 523 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 524 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 525 | 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) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 537 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 538 | elif latest_cip == None: |
| 539 | log.info("Got DHCP NAK. Lease not renewed.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 540 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 541 | elif new_cip == None or new_sip == None or lval == None: |
| 542 | |
| 543 | log.info("Got DHCP NAK.") |
| 544 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 545 | |
| 546 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 547 | def test_dhcp_client_rebind_time(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 548 | |
| 549 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 550 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 554 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 555 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 556 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 561 | assert_not_equal(cip, None) |
| 562 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 563 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 564 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 565 | log.info("Triggering DHCP Request.") |
| 566 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 567 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 568 | 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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 575 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 576 | 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) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 582 | break |
| 583 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 584 | 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 Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 590 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 591 | |
| 592 | def test_dhcp_client_expected_subnet_mask(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 593 | |
| 594 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 595 | '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 Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 600 | self.dhcp.return_option = 'subnet' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 601 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 602 | cip, sip, mac, subnet_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 603 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 604 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 609 | assert_not_equal(cip, None) |
| 610 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 611 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 612 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 613 | if expected_subnet == subnet_value: |
| 614 | log.info("Got same subnet as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 615 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 616 | elif expected_subnet != subnet_value: |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 617 | log.info("Not getting same subnet as passed in DHCP server configuration.") |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 618 | assert_equal(expected_subnet, subnet_value) |
| 619 | |
| 620 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 621 | def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 622 | |
| 623 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 624 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 628 | |
| 629 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 630 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 631 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 636 | assert_not_equal(cip, None) |
| 637 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 638 | 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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 644 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 645 | log.info("Got DHCP NAK.") |
| 646 | assert_not_equal(new_cip, None) |
| 647 | |
| 648 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 649 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 650 | 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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 652 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 653 | |
| 654 | def test_dhcp_client_expected_router_address(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 655 | |
| 656 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 657 | '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' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 663 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 664 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 665 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 666 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 671 | assert_not_equal(cip, None) |
| 672 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 673 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 674 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 675 | if expected_router_address == router_address_value: |
| 676 | log.info("Got same router address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 677 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 678 | 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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 684 | |
| 685 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 686 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 690 | |
| 691 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 692 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 693 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 698 | assert_not_equal(cip, None) |
| 699 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 700 | 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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 706 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 707 | log.info("Got DHCP NAK.") |
| 708 | assert_not_equal(new_cip, None) |
| 709 | |
| 710 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 711 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 712 | 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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 714 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 715 | |
| 716 | def test_dhcp_client_expected_broadcast_address(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 717 | |
| 718 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 719 | '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' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 725 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 726 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 727 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 728 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 733 | assert_not_equal(cip, None) |
| 734 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 735 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 736 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 737 | if expected_broadcast_address == broadcast_address_value: |
| 738 | log.info("Got same router address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 739 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 740 | 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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 746 | |
| 747 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 748 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 752 | |
| 753 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 754 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 755 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 760 | assert_not_equal(cip, None) |
| 761 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 762 | 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: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 768 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 769 | log.info("Got DHCP NAK.") |
| 770 | assert_not_equal(new_cip, None) |
| 771 | |
| 772 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 773 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 774 | 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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 776 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 777 | def test_dhcp_client_expected_dns_address(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 778 | |
| 779 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 780 | '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' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 786 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 787 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 788 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 789 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 794 | assert_not_equal(cip, None) |
| 795 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 796 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 797 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 798 | if expected_dns_address == dns_address_value: |
| 799 | log.info("Got same DNS address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 800 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 801 | 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 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 806 | 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 Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 809 | '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) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 813 | |
| 814 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 815 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 816 | (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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 821 | assert_not_equal(cip, None) |
| 822 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 823 | 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 Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 829 | log.info("Got DHCP NAK.") |
| 830 | assert_not_equal(new_cip, None) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 831 | elif new_cip and new_sip: |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 832 | 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.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 834 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 835 | def test_dhcp_server_transactions_per_second(self, iface = 'veth0'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 836 | |
| 837 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 838 | self.stats() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 839 | log.info("Stats for run %d",i) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 840 | 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 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 846 | log.info("Final Statistics for total transactions") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 847 | log.info("----------------------------------------------------------------------------------") |
| 848 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 849 | log.info(" %d %d %d %d" %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 850 | 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'): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 855 | |
| 856 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 857 | self.stats(success_rate = True) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 858 | log.info("Stats for run %d",i) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 859 | 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)) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 864 | log.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 865 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 866 | log.info("Final Statistics for total successful transactions") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 867 | log.info("----------------------------------------------------------------------------------") |
| 868 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 869 | log.info(" %d %d %d " %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 870 | self.total_success, self.running_time)) |
| 871 | log.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 872 | log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 873 | log.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 874 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame^] | 875 | |
| 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("----------------------------------------------------------------------------------") |