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