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 |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 24 | from OltConfig import * |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 25 | from OnosCtrl import OnosCtrl |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 26 | from portmaps import g_subscriber_port_map |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 27 | log.setLevel('INFO') |
| 28 | |
| 29 | class dhcp_exchange(unittest.TestCase): |
| 30 | |
| 31 | dhcp_server_config = { |
| 32 | "ip": "10.1.11.50", |
| 33 | "mac": "ca:fe:ca:fe:ca:fe", |
| 34 | "subnet": "255.255.252.0", |
| 35 | "broadcast": "10.1.11.255", |
| 36 | "router": "10.1.8.1", |
| 37 | "domain": "8.8.8.8", |
| 38 | "ttl": "63", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 39 | "delay": "2", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 40 | "startip": "10.1.11.51", |
| 41 | "endip": "10.1.11.100" |
| 42 | } |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 43 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 44 | app = 'org.onosproject.dhcp' |
| 45 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 46 | ip_count = 0 |
| 47 | failure_count = 0 |
| 48 | start_time = 0 |
| 49 | diff = 0 |
| 50 | |
| 51 | transaction_count = 0 |
| 52 | transactions = 0 |
| 53 | running_time = 0 |
| 54 | total_success = 0 |
| 55 | total_failure = 0 |
| 56 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 57 | @classmethod |
| 58 | def setUpClass(cls): |
| 59 | cls.olt = OltConfig() |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 60 | cls.port_map, _ = cls.olt.olt_port_map() |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 61 | if not cls.port_map: |
| 62 | cls.port_map = g_subscriber_port_map |
| 63 | cls.iface = cls.port_map[1] |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 64 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 65 | def setUp(self): |
| 66 | ''' Activate the dhcp app''' |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 67 | self.maxDiff = None ##for assert_equal compare outputs on failure |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 68 | self.onos_ctrl = OnosCtrl(self.app) |
| 69 | status, _ = self.onos_ctrl.activate() |
| 70 | assert_equal(status, True) |
| 71 | time.sleep(3) |
| 72 | |
| 73 | def teardown(self): |
| 74 | '''Deactivate the dhcp app''' |
| 75 | self.onos_ctrl.deactivate() |
| 76 | |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 77 | def onos_load_config(self, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 78 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 79 | if status is False: |
| 80 | log.info('JSON request returned status %d' %code) |
| 81 | assert_equal(status, True) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 82 | time.sleep(3) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 83 | |
| 84 | def onos_dhcp_table_load(self, config = None): |
| 85 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 86 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 87 | if config: |
| 88 | for k in config.keys(): |
| 89 | if dhcp_config.has_key(k): |
| 90 | dhcp_config[k] = config[k] |
| 91 | self.onos_load_config(dhcp_dict) |
| 92 | |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 93 | def send_recv(self, mac = None, update_seed = False, validate = True): |
| 94 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 95 | if validate: |
| 96 | assert_not_equal(cip, None) |
| 97 | assert_not_equal(sip, None) |
| 98 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
| 99 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 100 | return cip,sip |
| 101 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 102 | def stats(self,success_rate = False, only_discover = False): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 103 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 104 | self.ip_count = 0 |
| 105 | self.failure_count = 0 |
| 106 | self.start_time = 0 |
| 107 | self.diff = 0 |
| 108 | self.transaction_count = 0 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 109 | config = {'startip':'182.17.0.3', 'endip':'182.17.0.180', |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 110 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 111 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'} |
| 112 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 113 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 114 | self.start_time = time.time() |
| 115 | |
| 116 | while self.diff <= 60: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 117 | if only_discover: |
| 118 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
| 119 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
| 120 | (cip, sip, mac)) |
| 121 | else: |
| 122 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 123 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 124 | if cip: |
| 125 | self.ip_count +=1 |
| 126 | elif cip == None: |
| 127 | self.failure_count += 1 |
| 128 | log.info('Failed to get ip') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 129 | if success_rate and self.ip_count > 0: |
| 130 | break |
| 131 | self.diff = round(time.time() - self.start_time, 0) |
| 132 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 133 | |
| 134 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 135 | |
| 136 | self.transactions += (self.ip_count+self.failure_count) |
| 137 | self.running_time += self.diff |
| 138 | self.total_success += self.ip_count |
| 139 | self.total_failure += self.failure_count |
| 140 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 141 | def test_dhcp_1request(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 142 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 143 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 144 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 145 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 146 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 147 | self.send_recv() |
| 148 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 149 | def test_dhcp_Nrequest(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 150 | config = {'startip':'192.168.1.20', 'endip':'192.168.1.69', |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 151 | 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe", |
| 152 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 153 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 154 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 155 | ip_map = {} |
| 156 | for i in range(10): |
| 157 | cip, sip = self.send_recv(update_seed = True) |
| 158 | if ip_map.has_key(cip): |
| 159 | log.info('IP %s given out multiple times' %cip) |
| 160 | assert_equal(False, ip_map.has_key(cip)) |
| 161 | ip_map[cip] = sip |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 162 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 163 | def test_dhcp_1release(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 164 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 165 | 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe", |
| 166 | '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] | 167 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 168 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 169 | cip, sip = self.send_recv() |
| 170 | log.info('Releasing ip %s to server %s' %(cip, sip)) |
| 171 | assert_equal(self.dhcp.release(cip), True) |
| 172 | log.info('Triggering DHCP discover again after release') |
| 173 | cip2, sip2 = self.send_recv(update_seed = True) |
| 174 | log.info('Verifying released IP was given back on rediscover') |
| 175 | assert_equal(cip, cip2) |
| 176 | log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 177 | assert_equal(self.dhcp.release(cip2), True) |
| 178 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 179 | def test_dhcp_Nrelease(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 180 | config = {'startip':'192.170.1.20', 'endip':'192.170.1.30', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 181 | 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe", |
| 182 | '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] | 183 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 184 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 185 | ip_map = {} |
| 186 | for i in range(10): |
| 187 | cip, sip = self.send_recv(update_seed = True) |
| 188 | if ip_map.has_key(cip): |
| 189 | log.info('IP %s given out multiple times' %cip) |
| 190 | assert_equal(False, ip_map.has_key(cip)) |
| 191 | ip_map[cip] = sip |
| 192 | |
| 193 | for ip in ip_map.keys(): |
| 194 | log.info('Releasing IP %s' %ip) |
| 195 | assert_equal(self.dhcp.release(ip), True) |
| 196 | |
| 197 | ip_map2 = {} |
| 198 | log.info('Triggering DHCP discover again after release') |
| 199 | for i in range(len(ip_map.keys())): |
| 200 | cip, sip = self.send_recv(update_seed = True) |
| 201 | ip_map2[cip] = sip |
| 202 | |
| 203 | log.info('Verifying released IPs were given back on rediscover') |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 204 | if ip_map != ip_map2: |
| 205 | log.info('Map before release %s' %ip_map) |
| 206 | log.info('Map after release %s' %ip_map2) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 207 | assert_equal(ip_map, ip_map2) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 208 | |
| 209 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 210 | def test_dhcp_starvation(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 211 | config = {'startip':'193.170.1.20', 'endip':'193.170.1.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 212 | 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe", |
| 213 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 214 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 215 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 216 | ip_map = {} |
| 217 | for i in range(10): |
| 218 | cip, sip = self.send_recv(update_seed = True) |
| 219 | if ip_map.has_key(cip): |
| 220 | log.info('IP %s given out multiple times' %cip) |
| 221 | assert_equal(False, ip_map.has_key(cip)) |
| 222 | ip_map[cip] = sip |
| 223 | |
| 224 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 225 | def test_dhcp_starvation(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 226 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 227 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 228 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'} |
| 229 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 230 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = self.iface) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 231 | log.info('Verifying 1 ') |
| 232 | for x in xrange(50): |
| 233 | mac = RandMAC()._fix() |
| 234 | self.send_recv(mac = mac) |
| 235 | log.info('Verifying 2 ') |
| 236 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 237 | assert_equal(cip, None) |
| 238 | assert_equal(sip, None) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 239 | |
| 240 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 241 | def test_dhcp_same_client_multiple_discover(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 242 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 243 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 244 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 245 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 246 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 247 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 248 | 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] | 249 | (cip, sip, mac) ) |
| 250 | log.info('Triggering DHCP discover again.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 251 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 252 | if cip == new_cip: |
| 253 | log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. ' |
| 254 | % (new_cip, new_sip, new_mac) ) |
| 255 | elif cip != new_cip: |
| 256 | log.info('Ip after 1st discover %s' %cip) |
| 257 | log.info('Map after 2nd discover %s' %new_cip) |
| 258 | assert_equal(cip, new_cip) |
| 259 | |
| 260 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 261 | def test_dhcp_same_client_multiple_request(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 262 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 263 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 264 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 265 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 266 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 267 | log.info('Sending DHCP discover and DHCP request.') |
| 268 | cip, sip = self.send_recv() |
| 269 | mac = self.dhcp.get_mac(cip)[0] |
| 270 | log.info("Sending DHCP request again.") |
| 271 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 272 | if (new_cip,new_sip) == (cip,sip): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 273 | log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.' |
| 274 | % (new_cip, new_sip, mac) ) |
| 275 | elif (new_cip,new_sip): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 276 | log.info('No DHCP ACK') |
| 277 | assert_equal(new_cip, None) |
| 278 | assert_equal(new_sip, None) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 279 | else: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 280 | log.info('Something went wrong.') |
| 281 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 282 | def test_dhcp_client_desired_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 283 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 284 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 285 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 286 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 287 | self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 288 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 289 | 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] | 290 | (cip, sip, mac) ) |
| 291 | if cip == self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 292 | 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] | 293 | (cip, sip, mac) ) |
| 294 | elif cip != self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 295 | 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] | 296 | (cip, sip, mac) ) |
| 297 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 298 | assert_equal(cip, self.dhcp.seed_ip) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 299 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 300 | def test_dhcp_client_desired_address_out_of_pool(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 301 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 302 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 303 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 304 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 305 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 306 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
| 307 | 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] | 308 | (cip, sip, mac) ) |
| 309 | if cip == self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 310 | 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] | 311 | (cip, sip, mac) ) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 312 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 313 | elif cip != self.dhcp.seed_ip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 314 | 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] | 315 | (cip, sip, mac) ) |
| 316 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 317 | assert_not_equal(cip, self.dhcp.seed_ip) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 318 | elif cip == None: |
| 319 | log.info('Got DHCP NAK') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 320 | |
| 321 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 322 | def test_dhcp_server_nak_packet(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 323 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 324 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 325 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 326 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 327 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 328 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 329 | 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] | 330 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 331 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 332 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 333 | if (cip == None and mac != None): |
| 334 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 335 | assert_not_equal(cip, None) |
| 336 | else: |
| 337 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 338 | if new_cip == None: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 339 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 340 | log.info("Got DHCP server NAK.") |
| 341 | assert_equal(new_cip, None) #Negative Test Case |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 342 | |
| 343 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 344 | def test_dhcp_lease_packet(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 345 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 346 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 347 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 348 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 349 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 350 | log.info('Sending DHCP discover with lease time of 700') |
| 351 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True) |
| 352 | |
| 353 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 354 | if (cip == None and mac != None): |
| 355 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 356 | assert_not_equal(cip, None) |
| 357 | elif lval != 700: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 358 | 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] | 359 | (cip, sip, mac, lval) ) |
| 360 | assert_not_equal(lval, 700) |
| 361 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 362 | def test_dhcp_client_request_after_reboot(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 363 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 364 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 365 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 366 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 367 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 368 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 369 | 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] | 370 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 371 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 372 | 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] | 373 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 374 | if (cip == None and mac != None): |
| 375 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 376 | assert_not_equal(cip, None) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 377 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 378 | else: |
| 379 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 380 | if new_cip == None: |
| 381 | log.info("Got DHCP server NAK.") |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 382 | os.system('ifconfig '+self.iface+' down') |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 383 | log.info('Client goes down.') |
| 384 | log.info('Delay for 5 seconds.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 385 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 386 | time.sleep(5) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 387 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 388 | os.system('ifconfig '+self.iface+' up') |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 389 | log.info('Client is up now.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 390 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 391 | 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] | 392 | if new_cip == None: |
| 393 | log.info("Got DHCP server NAK.") |
| 394 | assert_not_equal(new_cip, None) |
| 395 | elif new_cip != None: |
| 396 | log.info("Got DHCP ACK.") |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 397 | os.system('ifconfig '+self.iface+' up') |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 398 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 399 | |
| 400 | |
| 401 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 402 | def test_dhcp_server_after_reboot(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 403 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 404 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 405 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 406 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 407 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 408 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 409 | 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] | 410 | (cip, sip, mac) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 411 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 412 | 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] | 413 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 414 | if (cip == None and mac != None): |
| 415 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 416 | assert_not_equal(cip, None) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 417 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 418 | else: |
| 419 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 420 | if new_cip == None: |
| 421 | log.info("Got DHCP server NAK.") |
| 422 | assert_not_equal(new_cip, None) |
| 423 | log.info('Getting DHCP server Down.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 424 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 425 | self.onos_ctrl.deactivate() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 426 | |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 427 | for i in range(0,4): |
| 428 | log.info("Sending DHCP Request.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 429 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 430 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 431 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 432 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 433 | log.info("DHCP Request timed out.") |
| 434 | elif new_cip and new_sip: |
| 435 | log.info("Got Reply from DHCP server.") |
| 436 | assert_equal(new_cip,None) #Neagtive Test Case |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 437 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 438 | log.info('Getting DHCP server Up.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 439 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 440 | status, _ = self.onos_ctrl.activate() |
| 441 | assert_equal(status, True) |
| 442 | time.sleep(3) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 443 | |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 444 | for i in range(0,4): |
| 445 | log.info("Sending DHCP Request after DHCP server is up.") |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 446 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 447 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 448 | if new_cip == None and new_sip == None: |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 449 | log.info('') |
Chetan Gaonker | b926c64 | 2016-05-10 08:19:03 -0700 | [diff] [blame] | 450 | log.info("DHCP Request timed out.") |
| 451 | elif new_cip and new_sip: |
| 452 | log.info("Got Reply from DHCP server.") |
| 453 | assert_equal(new_cip,None) #Neagtive Test Case |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 454 | |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 455 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 456 | def test_dhcp_specific_lease_packet(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 457 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 458 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 459 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 460 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 461 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 462 | log.info('Sending DHCP discover with lease time of 700') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 463 | cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True) |
| 464 | 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] | 465 | (cip, sip, mac) ) |
| 466 | |
| 467 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 468 | if (cip == None and mac != None): |
| 469 | 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] | 470 | assert_not_equal(cip, None) |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 471 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 472 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 473 | log.info("Triggering DHCP Request.") |
| 474 | 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] | 475 | 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] | 476 | (new_cip, new_sip, mac, lval) ) |
| 477 | assert_not_equal(lval, 700) #Negative Test Case |
| 478 | |
| 479 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 480 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 481 | def test_dhcp_lease_packet(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 482 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 483 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 484 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 485 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 486 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 487 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 488 | 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] | 489 | (cip, sip, mac) ) |
| 490 | |
| 491 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 492 | if (cip == None and mac != None): |
| 493 | 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] | 494 | assert_not_equal(cip, None) |
| 495 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 496 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 497 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 498 | log.info("Triggering DHCP Request.") |
| 499 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 500 | if lval == 600: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 501 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' % |
| 502 | (new_cip, new_sip, mac, lval) ) |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 503 | else: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 504 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s.' % |
| 505 | (new_cip, new_sip, mac, lval) ) |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 506 | log.info('The lease time suppossed to be 600 secs or 10 mins.') |
| 507 | assert_equal(lval, 600) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 508 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 509 | def test_dhcp_client_renew_time(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 510 | |
| 511 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 512 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 513 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 514 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 515 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 516 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 517 | 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] | 518 | (cip, sip, mac) ) |
| 519 | |
| 520 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 521 | if (cip == None and mac != None): |
| 522 | 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] | 523 | assert_not_equal(cip, None) |
| 524 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 525 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 526 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 527 | log.info("Triggering DHCP Request.") |
| 528 | 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] | 529 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 530 | if new_cip and new_sip and lval: |
| 531 | |
| 532 | log.info("Clinet 's Renewal time is :%s",lval) |
| 533 | log.info("Generating delay till renewal time.") |
| 534 | time.sleep(lval) |
| 535 | |
| 536 | log.info("Client Sending Unicast DHCP request.") |
| 537 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 538 | |
| 539 | if latest_cip and latest_sip: |
| 540 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 541 | (latest_cip, mac, latest_sip) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 542 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 543 | elif latest_cip == None: |
| 544 | log.info("Got DHCP NAK. Lease not renewed.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 545 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 546 | elif new_cip == None or new_sip == None or lval == None: |
| 547 | |
| 548 | log.info("Got DHCP NAK.") |
| 549 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 550 | |
| 551 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 552 | def test_dhcp_client_rebind_time(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 553 | |
| 554 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 555 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 556 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 557 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 558 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 559 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 560 | 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] | 561 | (cip, sip, mac) ) |
| 562 | |
| 563 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 564 | if (cip == None and mac != None): |
| 565 | 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] | 566 | assert_not_equal(cip, None) |
| 567 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 568 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 569 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 570 | log.info("Triggering DHCP Request.") |
| 571 | 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] | 572 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 573 | if new_cip and new_sip and lval: |
| 574 | |
| 575 | log.info("Clinet 's Rebind time is :%s",lval) |
| 576 | log.info("Generating delay till rebind time.") |
| 577 | time.sleep(lval) |
| 578 | |
| 579 | 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] | 580 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 581 | for i in range(0,4): |
| 582 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 583 | |
| 584 | if latest_cip and latest_sip: |
| 585 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 586 | (latest_cip, mac, latest_sip) ) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 587 | break |
| 588 | |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 589 | elif latest_cip == None: |
| 590 | log.info("Got DHCP NAK. Lease not renewed.") |
| 591 | assert_not_equal(latest_cip, None) |
| 592 | elif new_cip == None or new_sip == None or lval == None: |
| 593 | |
| 594 | log.info("Got DHCP NAK.Lease not Renewed.") |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 595 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 596 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 597 | def test_dhcp_client_expected_subnet_mask(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 598 | |
| 599 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 600 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 601 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 602 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 603 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 604 | expected_subnet = '255.255.255.0' |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 605 | self.dhcp.return_option = 'subnet' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 606 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 607 | cip, sip, mac, subnet_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 608 | 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] | 609 | (cip, sip, mac) ) |
| 610 | |
| 611 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 612 | if (cip == None and mac != None): |
| 613 | 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] | 614 | assert_not_equal(cip, None) |
| 615 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 616 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 617 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 618 | if expected_subnet == subnet_value: |
| 619 | log.info("Got same subnet as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 620 | |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 621 | elif expected_subnet != subnet_value: |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 622 | log.info("Not getting same subnet as passed in DHCP server configuration.") |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 623 | assert_equal(expected_subnet, subnet_value) |
| 624 | |
| 625 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 626 | def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 627 | |
| 628 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 629 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 630 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 631 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 632 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 633 | |
| 634 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 635 | 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] | 636 | (cip, sip, mac) ) |
| 637 | |
| 638 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 639 | if (cip == None and mac != None): |
| 640 | 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] | 641 | assert_not_equal(cip, None) |
| 642 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 643 | elif cip and sip and mac: |
| 644 | |
| 645 | self.dhcp.send_different_option = 'subnet' |
| 646 | log.info("Sending DHCP Request with wrong subnet mask.") |
| 647 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 648 | if new_cip == None: |
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 NAK.") |
| 651 | assert_not_equal(new_cip, None) |
| 652 | |
| 653 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 654 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 655 | log.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
| 656 | log.info("Getting subnet mask as per server 's configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 657 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 658 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 659 | def test_dhcp_client_expected_router_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 660 | |
| 661 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 662 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 663 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 664 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 665 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 666 | expected_router_address = '20.20.20.1' |
| 667 | self.dhcp.return_option = 'router' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 668 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 669 | cip, sip, mac, router_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 670 | 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] | 671 | (cip, sip, mac) ) |
| 672 | |
| 673 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 674 | if (cip == None and mac != None): |
| 675 | 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] | 676 | assert_not_equal(cip, None) |
| 677 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 678 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 679 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 680 | if expected_router_address == router_address_value: |
| 681 | log.info("Got same router address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 682 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 683 | elif expected_router_address != router_address_value: |
| 684 | log.info("Not getting same router address as passed in DHCP server configuration.") |
| 685 | assert_equal(expected_router_address, router_address_value) |
| 686 | |
| 687 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 688 | def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 689 | |
| 690 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 691 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 692 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 693 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 694 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 695 | |
| 696 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 697 | 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] | 698 | (cip, sip, mac) ) |
| 699 | |
| 700 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 701 | if (cip == None and mac != None): |
| 702 | 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] | 703 | assert_not_equal(cip, None) |
| 704 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 705 | elif cip and sip and mac: |
| 706 | |
| 707 | self.dhcp.send_different_option = 'router' |
| 708 | log.info("Sending DHCP Request with wrong router address.") |
| 709 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 710 | if new_cip == None: |
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 NAK.") |
| 713 | assert_not_equal(new_cip, None) |
| 714 | |
| 715 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 716 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 717 | log.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
| 718 | log.info("Getting Router Address as per server 's configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 719 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 720 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 721 | def test_dhcp_client_expected_broadcast_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 722 | |
| 723 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 724 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 725 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 726 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 727 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 728 | expected_broadcast_address = '20.20.20.255' |
| 729 | self.dhcp.return_option = 'broadcast_address' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 730 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 731 | cip, sip, mac, broadcast_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 732 | 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] | 733 | (cip, sip, mac) ) |
| 734 | |
| 735 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 736 | if (cip == None and mac != None): |
| 737 | 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] | 738 | assert_not_equal(cip, None) |
| 739 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 740 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 741 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 742 | if expected_broadcast_address == broadcast_address_value: |
| 743 | log.info("Got same router address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 744 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 745 | elif expected_broadcast_address != broadcast_address_value: |
| 746 | log.info("Not getting same router address as passed in DHCP server configuration.") |
| 747 | assert_equal(expected_broadcast_address, broadcast_address_value) |
| 748 | |
| 749 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 750 | def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 751 | |
| 752 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 753 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 754 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 755 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 756 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 757 | |
| 758 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 759 | 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] | 760 | (cip, sip, mac) ) |
| 761 | |
| 762 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 763 | if (cip == None and mac != None): |
| 764 | 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] | 765 | assert_not_equal(cip, None) |
| 766 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 767 | elif cip and sip and mac: |
| 768 | |
| 769 | self.dhcp.send_different_option = 'broadcast_address' |
| 770 | log.info("Sending DHCP Request with wrong broadcast address.") |
| 771 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 772 | if new_cip == None: |
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 NAK.") |
| 775 | assert_not_equal(new_cip, None) |
| 776 | |
| 777 | elif new_cip and new_sip: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 778 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 779 | log.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
| 780 | log.info("Getting Broadcast Address as per server 's configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 781 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 782 | def test_dhcp_client_expected_dns_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 783 | |
| 784 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 785 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 786 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'} |
| 787 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 788 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 789 | expected_dns_address = '8.8.8.8' |
| 790 | self.dhcp.return_option = 'dns' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 791 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 792 | cip, sip, mac, dns_address_value = self.dhcp.only_discover() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 793 | 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] | 794 | (cip, sip, mac) ) |
| 795 | |
| 796 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 797 | if (cip == None and mac != None): |
| 798 | 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] | 799 | assert_not_equal(cip, None) |
| 800 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 801 | elif cip and sip and mac: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 802 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 803 | if expected_dns_address == dns_address_value: |
| 804 | log.info("Got same DNS address as passed in DHCP server configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 805 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 806 | elif expected_dns_address != dns_address_value: |
| 807 | log.info("Not getting same DNS address as passed in DHCP server configuration.") |
| 808 | assert_equal(expected_dns_address, dns_address_value) |
| 809 | |
| 810 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 811 | def test_dhcp_client_sends_request_with_wrong_dns_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 812 | |
| 813 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 814 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 815 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'} |
| 816 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 817 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 818 | |
| 819 | cip, sip, mac, _ = self.dhcp.only_discover() |
| 820 | 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] | 821 | (cip, sip, mac) ) |
| 822 | |
| 823 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 824 | if (cip == None and mac != None): |
| 825 | 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] | 826 | assert_not_equal(cip, None) |
| 827 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 828 | elif cip and sip and mac: |
| 829 | |
| 830 | self.dhcp.send_different_option = 'dns' |
| 831 | log.info("Sending DHCP Request with wrong DNS address.") |
| 832 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 833 | if new_cip == None: |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 834 | log.info("Got DHCP NAK.") |
| 835 | assert_not_equal(new_cip, None) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 836 | elif new_cip and new_sip: |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 837 | log.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
| 838 | log.info("Getting DNS Address as per server 's configuration.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 839 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 840 | def test_dhcp_server_transactions_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 841 | |
| 842 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 843 | self.stats() |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 844 | log.info("Stats for run %d",i) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 845 | log.info("----------------------------------------------------------------------------------") |
| 846 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 847 | log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 848 | log.info("----------------------------------------------------------------------------------") |
| 849 | log.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 850 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 851 | log.info("Final Statistics for total transactions") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 852 | log.info("----------------------------------------------------------------------------------") |
| 853 | 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] | 854 | log.info(" %d %d %d %d" %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 855 | self.total_success, self.total_failure, self.running_time)) |
| 856 | log.info("----------------------------------------------------------------------------------") |
| 857 | log.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
| 858 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 859 | def test_dhcp_server_consecutive_successes_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 860 | |
| 861 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 862 | self.stats(success_rate = True) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 863 | log.info("Stats for run %d",i) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 864 | log.info("----------------------------------------------------------------------------------") |
| 865 | log.info("No. of consecutive successful transactions Running Time ") |
| 866 | log.info(" %d %d " %(self.ip_count, self.diff)) |
| 867 | log.info("----------------------------------------------------------------------------------") |
| 868 | 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] | 869 | log.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 870 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 871 | log.info("Final Statistics for total successful transactions") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 872 | log.info("----------------------------------------------------------------------------------") |
| 873 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 874 | log.info(" %d %d %d " %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 875 | self.total_success, self.running_time)) |
| 876 | log.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 877 | log.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 878 | log.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 879 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 880 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 881 | def test_dhcp_server_client_transactions_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 882 | |
| 883 | for i in range(1,4): |
| 884 | self.stats(only_discover = True) |
| 885 | log.info("----------------------------------------------------------------------------------") |
| 886 | log.info("Stats for run %d of sending only DHCP Discover",i) |
| 887 | log.info("----------------------------------------------------------------------------------") |
| 888 | log.info("No. of transactions No. of successes No. of failures Running Time ") |
| 889 | log.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 890 | log.info("----------------------------------------------------------------------------------") |
| 891 | log.info("No. of clients per second in run %d:%f " |
| 892 | %(i, self.transaction_count)) |
| 893 | log.info("----------------------------------------------------------------------------------") |
| 894 | log.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 895 | log.info("----------------------------------------------------------------------------------") |
| 896 | log.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 897 | log.info(" %d %d %d %d" %(self.transactions, |
| 898 | self.total_success, self.total_failure, self.running_time)) |
| 899 | log.info("----------------------------------------------------------------------------------") |
| 900 | log.info("Average no. of clients per second: %d ", |
| 901 | round(self.transactions/self.running_time,0)) |
| 902 | log.info("----------------------------------------------------------------------------------") |
| 903 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 904 | def test_dhcp_server_consecutive_successful_clients_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 905 | |
| 906 | for i in range(1,4): |
| 907 | self.stats(success_rate = True, only_discover = True) |
| 908 | log.info("----------------------------------------------------------------------------------") |
| 909 | log.info("Stats for run %d for sending only DHCP Discover",i) |
| 910 | log.info("----------------------------------------------------------------------------------") |
| 911 | log.info("No. of consecutive successful transactions Running Time ") |
| 912 | log.info(" %d %d " %(self.ip_count, self.diff)) |
| 913 | log.info("----------------------------------------------------------------------------------") |
| 914 | log.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 915 | log.info("----------------------------------------------------------------------------------") |
| 916 | |
| 917 | log.info("Final Statistics for total successful transactions") |
| 918 | log.info("----------------------------------------------------------------------------------") |
| 919 | log.info("Total transactions Total No. of consecutive successes Running Time ") |
| 920 | log.info(" %d %d %d " %(self.transactions, |
| 921 | self.total_success, self.running_time)) |
| 922 | log.info("----------------------------------------------------------------------------------") |
| 923 | log.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 924 | log.info("----------------------------------------------------------------------------------") |