Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 17 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 18 | # Copyright 2016-present Ciena Corporation |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | # you may not use this file except in compliance with the License. |
| 22 | # You may obtain a copy of the License at |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 23 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 25 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | # See the License for the specific language governing permissions and |
| 30 | # limitations under the License. |
| 31 | # |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 32 | import unittest |
| 33 | from nose.tools import * |
| 34 | from nose.twistedtools import reactor, deferred |
| 35 | from twisted.internet import defer |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 36 | import time |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 37 | import copy |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 38 | from DHCP import DHCPTest |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 39 | from OltConfig import * |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 40 | from OnosCtrl import OnosCtrl |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 41 | from portmaps import g_subscriber_port_map |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 42 | from CordLogger import CordLogger |
A R Karthick | 9dc6e92 | 2017-07-12 14:40:16 -0700 | [diff] [blame] | 43 | from CordTestConfig import setup_module, teardown_module |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 44 | from CordTestUtils import log_test |
| 45 | log_test.setLevel('INFO') |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 46 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 47 | class dhcp_exchange(CordLogger): |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 48 | |
| 49 | dhcp_server_config = { |
| 50 | "ip": "10.1.11.50", |
| 51 | "mac": "ca:fe:ca:fe:ca:fe", |
| 52 | "subnet": "255.255.252.0", |
| 53 | "broadcast": "10.1.11.255", |
| 54 | "router": "10.1.8.1", |
| 55 | "domain": "8.8.8.8", |
| 56 | "ttl": "63", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 57 | "delay": "2", |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 58 | "startip": "10.1.11.51", |
| 59 | "endip": "10.1.11.100" |
| 60 | } |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 61 | |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 62 | STARTIP = "10.10.10.40" |
| 63 | ENDIP = "10.10.10.41" |
| 64 | IP = "10.10.10.2" |
| 65 | MAC = "ca:fe:ca:fe:ca:fe" |
| 66 | SUBNET = "255.255.255.0" |
| 67 | BROADCAST = "10.10.10.255" |
| 68 | ROUTER = "10.10.10.1" |
| 69 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 70 | app = 'org.onosproject.dhcp' |
| 71 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 72 | ip_count = 0 |
| 73 | failure_count = 0 |
| 74 | start_time = 0 |
| 75 | diff = 0 |
| 76 | |
| 77 | transaction_count = 0 |
| 78 | transactions = 0 |
| 79 | running_time = 0 |
| 80 | total_success = 0 |
| 81 | total_failure = 0 |
| 82 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 83 | @classmethod |
| 84 | def setUpClass(cls): |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 85 | cls.config_dhcp = {'startip': cls.STARTIP, 'endip': cls.ENDIP, |
| 86 | 'ip':cls.IP, 'mac': cls.MAC, 'subnet': cls.SUBNET, |
| 87 | 'broadcast':cls.BROADCAST, 'router':cls.ROUTER} |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 88 | cls.olt = OltConfig() |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 89 | cls.port_map, _ = cls.olt.olt_port_map() |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 90 | if not cls.port_map: |
| 91 | cls.port_map = g_subscriber_port_map |
| 92 | cls.iface = cls.port_map[1] |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 93 | |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 94 | def setUp(self): |
| 95 | ''' Activate the dhcp app''' |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 96 | super(dhcp_exchange, self).setUp() |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 97 | self.maxDiff = None ##for assert_equal compare outputs on failure |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 98 | self.onos_ctrl = OnosCtrl(self.app) |
| 99 | status, _ = self.onos_ctrl.activate() |
| 100 | assert_equal(status, True) |
| 101 | time.sleep(3) |
| 102 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 103 | def tearDown(self): |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 104 | '''Deactivate the dhcp app''' |
| 105 | self.onos_ctrl.deactivate() |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 106 | super(dhcp_exchange, self).tearDown() |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 107 | |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 108 | def onos_load_config(self, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 109 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 110 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 111 | log_test.info('JSON request returned status %d' %code) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 112 | assert_equal(status, True) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 113 | time.sleep(3) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 114 | |
| 115 | def onos_dhcp_table_load(self, config = None): |
| 116 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 117 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 118 | if config: |
| 119 | for k in config.keys(): |
| 120 | if dhcp_config.has_key(k): |
| 121 | dhcp_config[k] = config[k] |
| 122 | self.onos_load_config(dhcp_dict) |
| 123 | |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 124 | def send_recv(self, mac = None, update_seed = False, validate = True): |
| 125 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 126 | log_test.info("discover cip %s"%(cip)) |
| 127 | log_test.info("discover sip %s"%(sip)) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 128 | if validate: |
| 129 | assert_not_equal(cip, None) |
| 130 | assert_not_equal(sip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 131 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 132 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 133 | return cip,sip |
| 134 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 135 | def stats(self,success_rate = False, only_discover = False): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 136 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 137 | self.ip_count = 0 |
| 138 | self.failure_count = 0 |
| 139 | self.start_time = 0 |
| 140 | self.diff = 0 |
| 141 | self.transaction_count = 0 |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 142 | config = {'startip':'182.17.0.3', 'endip':'182.17.0.180', |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 143 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 144 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.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 = '182.17.0.1', iface = self.iface) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 147 | self.start_time = time.time() |
| 148 | |
| 149 | while self.diff <= 60: |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 150 | if only_discover: |
| 151 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 152 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 153 | (cip, sip, mac)) |
| 154 | else: |
| 155 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 156 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 157 | if cip: |
| 158 | self.ip_count +=1 |
| 159 | elif cip == None: |
| 160 | self.failure_count += 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 161 | log_test.info('Failed to get ip') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 162 | if success_rate and self.ip_count > 0: |
| 163 | break |
| 164 | self.diff = round(time.time() - self.start_time, 0) |
| 165 | |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 166 | |
| 167 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 168 | |
| 169 | self.transactions += (self.ip_count+self.failure_count) |
| 170 | self.running_time += self.diff |
| 171 | self.total_success += self.ip_count |
| 172 | self.total_failure += self.failure_count |
| 173 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 174 | def test_dhcp_1request(self): |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 175 | self.onos_dhcp_table_load(self.config_dhcp) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 176 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
Anil Kumar Sanka | 5099890 | 2016-12-13 12:10:25 +0530 | [diff] [blame] | 177 | self.send_recv() |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 178 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 179 | def test_dhcp_1request_with_invalid_source_mac_broadcast(self): |
| 180 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 181 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 182 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 183 | self.onos_dhcp_table_load(config) |
| 184 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
| 185 | cip, sip, mac, _ = self.dhcp.only_discover(mac='ff:ff:ff:ff:ff:ff') |
| 186 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 187 | log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 188 | |
| 189 | def test_dhcp_1request_with_invalid_source_mac_multicast(self): |
| 190 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 191 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 192 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 193 | self.onos_dhcp_table_load(config) |
| 194 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
| 195 | cip, sip, mac, _ = self.dhcp.only_discover(mac='01:80:c2:91:02:e4') |
| 196 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 197 | log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 198 | |
| 199 | def test_dhcp_1request_with_invalid_source_mac_zero(self): |
| 200 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 201 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 202 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 203 | self.onos_dhcp_table_load(config) |
| 204 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
| 205 | cip, sip, mac, _ = self.dhcp.only_discover(mac='00:00:00:00:00:00') |
| 206 | assert_equal(cip,None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 207 | log_test.info('ONOS dhcp server rejected client discover with invalid source mac as expected') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 208 | |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 209 | def test_dhcp_Nrequest(self, requests=10): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 210 | config = {'startip':'192.168.1.20', 'endip':'192.168.1.69', |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 211 | 'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe", |
| 212 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 213 | self.onos_dhcp_table_load(config) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 214 | self.dhcp = DHCPTest(seed_ip = '192.168.1.1', iface = self.iface) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 215 | ip_map = {} |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 216 | for i in range(requests): |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 217 | cip, sip = self.send_recv(update_seed = True) |
| 218 | if ip_map.has_key(cip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 219 | log_test.info('IP %s given out multiple times' %cip) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 220 | assert_equal(False, ip_map.has_key(cip)) |
| 221 | ip_map[cip] = sip |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 222 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 223 | def test_dhcp_1release(self): |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 224 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.230', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 225 | 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe", |
| 226 | '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] | 227 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 228 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = self.iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 229 | cip, sip = self.send_recv() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 230 | log_test.info('Releasing ip %s to server %s' %(cip, sip)) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 231 | assert_equal(self.dhcp.release(cip), True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 232 | log_test.info('Triggering DHCP discover again after release') |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 233 | cip2, sip2 = self.send_recv(update_seed = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 234 | log_test.info('Verifying released IP was given back on rediscover') |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 235 | assert_equal(cip, cip2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 236 | log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 237 | assert_equal(self.dhcp.release(cip2), True) |
| 238 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 239 | def test_dhcp_Nrelease(self): |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 240 | config = {'startip':'192.170.1.20', 'endip':'192.170.1.230', |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 241 | 'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe", |
| 242 | '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] | 243 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 244 | self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = self.iface) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 245 | ip_map = {} |
| 246 | for i in range(10): |
| 247 | cip, sip = self.send_recv(update_seed = True) |
| 248 | if ip_map.has_key(cip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 249 | log_test.info('IP %s given out multiple times' %cip) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 250 | assert_equal(False, ip_map.has_key(cip)) |
| 251 | ip_map[cip] = sip |
| 252 | |
| 253 | for ip in ip_map.keys(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 254 | log_test.info('Releasing IP %s' %ip) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 255 | assert_equal(self.dhcp.release(ip), True) |
| 256 | |
| 257 | ip_map2 = {} |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 258 | log_test.info('Triggering DHCP discover again after release') |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 259 | for i in range(len(ip_map.keys())): |
| 260 | cip, sip = self.send_recv(update_seed = True) |
| 261 | ip_map2[cip] = sip |
| 262 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 263 | log_test.info('Verifying released IPs were given back on rediscover') |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 264 | if ip_map != ip_map2: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 265 | log_test.info('Map before release %s' %ip_map) |
| 266 | log_test.info('Map after release %s' %ip_map2) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 267 | assert_equal(ip_map, ip_map2) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 268 | |
| 269 | |
Chetan Gaonker | 6209118 | 2017-04-05 17:36:14 -0500 | [diff] [blame] | 270 | def test_dhcp_starvation_positive_scenario(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 271 | config = {'startip':'193.170.1.20', 'endip':'193.170.1.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 272 | 'ip':'193.170.1.2', 'mac': "ca:fe:c2:fe:cc:fe", |
| 273 | 'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'} |
| 274 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 275 | self.dhcp = DHCPTest(seed_ip = '192.169.1.1', iface = self.iface) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 276 | ip_map = {} |
| 277 | for i in range(10): |
| 278 | cip, sip = self.send_recv(update_seed = True) |
| 279 | if ip_map.has_key(cip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 280 | log_test.info('IP %s given out multiple times' %cip) |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 281 | assert_equal(False, ip_map.has_key(cip)) |
| 282 | ip_map[cip] = sip |
| 283 | |
| 284 | |
Chetan Gaonker | 6209118 | 2017-04-05 17:36:14 -0500 | [diff] [blame] | 285 | def test_dhcp_starvation_negative_scenario(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 286 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 287 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 288 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.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 = '182.17.0.1', iface = self.iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 291 | log_test.info('Verifying passitive case') |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 292 | for x in xrange(50): |
| 293 | mac = RandMAC()._fix() |
| 294 | self.send_recv(mac = mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 295 | log_test.info('Verifying negative case') |
Chetan Gaonker | 6c68e91 | 2016-04-15 17:22:14 -0700 | [diff] [blame] | 296 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 297 | assert_equal(cip, None) |
| 298 | assert_equal(sip, None) |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 299 | |
| 300 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 301 | def test_dhcp_same_client_multiple_discover(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 302 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 303 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 304 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 305 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 306 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 307 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 308 | log_test.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] | 309 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 310 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 311 | log_test.info('Triggering DHCP discover again.') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 312 | new_cip, new_sip, new_mac, _ = self.dhcp.only_discover() |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 313 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 314 | log_test.info('client got same IP as expected when sent 2nd discovery') |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 315 | |
| 316 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 317 | def test_dhcp_same_client_multiple_request(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 318 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 319 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 320 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 321 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 322 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = self.iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 323 | log_test.info('Sending DHCP discover and DHCP request.') |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 324 | cip, sip = self.send_recv() |
| 325 | mac = self.dhcp.get_mac(cip)[0] |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 326 | log_test.info("Sending DHCP request again.") |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 327 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 328 | assert_equal(new_cip,cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 329 | log_test.info('server offered same IP to clain for multiple requests, as expected') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 330 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 331 | def test_dhcp_client_desired_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 332 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 333 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 334 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 335 | self.onos_dhcp_table_load(config) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 336 | self.dhcp = DHCPTest(seed_ip = '20.20.20.50', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 337 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 338 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 339 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 340 | (cip, sip, mac)) |
| 341 | assert_equal(cip,self.dhcp.seed_ip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 342 | log_test.info('ONOS dhcp server offered client requested IP %s as expected'%self.dhcp.seed_ip) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 343 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 344 | #test failing, server not returns NAK when requested out of pool IP |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 345 | def test_dhcp_client_desired_address_out_of_pool(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 346 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 347 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 348 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 349 | self.onos_dhcp_table_load(config) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 350 | self.dhcp = DHCPTest(seed_ip = '20.20.20.75', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 351 | cip, sip, mac, _ = self.dhcp.only_discover(desired = True) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 352 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 353 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 354 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 355 | assert_not_equal(cip,self.dhcp.seed_ip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 356 | log_test.info('server offered IP from its pool of IPs when requested out of pool IP, as expected') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 357 | |
| 358 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 359 | def test_dhcp_server_nak_packet(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 360 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 361 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 362 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 363 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 364 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 365 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 366 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 367 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 368 | assert_not_equal(cip, None) |
| 369 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 370 | assert_equal(new_cip, None) #Negative Test Case |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 371 | log_test.info('dhcp servers sent NAK as expected when requested different IP from same client') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 372 | |
| 373 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 374 | #test_dhcp_lease_packet |
| 375 | def test_dhcp_client_requests_specific_lease_time_in_discover(self,lease_time = 700): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 376 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 377 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 378 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 379 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 380 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 381 | self.dhcp.return_option = 'lease' |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 382 | log_test.info('Sending DHCP discover with lease time of 700') |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 383 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True, lease_value = lease_time) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 384 | assert_equal(lval, 700) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 385 | log_test.info('dhcp server offered IP address with client requested lease time') |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 386 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 387 | def test_dhcp_client_request_after_reboot(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 388 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 389 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 390 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 391 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 392 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 393 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 394 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 395 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 396 | assert_not_equal(cip,None) |
| 397 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 398 | log_test.info('verifying client IP after reboot') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 399 | os.system('ifconfig '+self.iface+' down') |
| 400 | time.sleep(5) |
| 401 | os.system('ifconfig '+self.iface+' up') |
| 402 | new_cip, new_sip = self.dhcp.only_request(cip, mac, cl_reboot = True) |
| 403 | assert_equal(new_cip,cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 404 | log_test.info('client got same ip after reboot, as expected') |
Chetan Gaonker | 2499f17 | 2017-04-05 00:30:50 +0000 | [diff] [blame] | 405 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 406 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 407 | def test_dhcp_server_after_reboot(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 408 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 409 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 410 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 411 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 412 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 413 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 414 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | f148386 | 2016-05-06 14:14:31 -0700 | [diff] [blame] | 415 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 416 | assert_not_equal(cip, None) |
| 417 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 418 | self.onos_ctrl.deactivate() |
| 419 | new_cip1, new_sip = self.dhcp.only_request(cip, mac) |
| 420 | assert_equal(new_cip1,None) |
| 421 | status, _ = self.onos_ctrl.activate() |
| 422 | assert_equal(status, True) |
| 423 | time.sleep(3) |
| 424 | new_cip2, new_sip = self.dhcp.only_request(cip, mac) |
| 425 | assert_equal(new_cip2,cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 426 | log_test.info('client got same ip after server reboot, as expected') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 427 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 428 | def test_dhcp_specific_lease_time_only_in_discover_but_not_in_request_packet(self,lease_time=700): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 429 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 430 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 431 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 432 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 433 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 434 | log_test.info('Sending DHCP discover with lease time of 700') |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 435 | cip, sip, mac, _ = self.dhcp.only_discover(lease_time = True,lease_value=lease_time) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 436 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 437 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 438 | assert_not_equal(cip, None) |
| 439 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True) |
| 440 | assert_equal(new_cip,cip) |
| 441 | assert_not_equal(lval, lease_time) #Negative Test Case |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 442 | log_test.info('client requested lease time only in discover but not in request, not seen in server ACK packet as expected') |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 443 | |
| 444 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 445 | def test_dhcp_specific_lease_time_only_in_request_but_not_in_discover_packet(self,lease_time=800): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 446 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 447 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 448 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 449 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 450 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 451 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 452 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 453 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 454 | assert_not_equal(cip, None) |
| 455 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, lease_time = True, lease_value=lease_time) |
| 456 | assert_equal(lval, lease_time) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 457 | log_test.info('client requested lease time in request packet, seen in server ACK packet as expected') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 458 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 459 | def test_dhcp_client_renew_time(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 460 | |
| 461 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 462 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 463 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 464 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 465 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 466 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 467 | log_test.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) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 469 | assert_not_equal(cip, None) |
| 470 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 471 | log_test.info('waiting renew time %d seconds to send next request packet'%lval) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 472 | time.sleep(lval) |
| 473 | latest_cip, latest_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 474 | assert_equal(latest_cip,cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 475 | log_test.info('client got same IP after renew time, as expected') |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 476 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 477 | def test_dhcp_client_rebind_time(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 478 | |
| 479 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 480 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 481 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 482 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 483 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 484 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 485 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | c11d322 | 2016-05-11 17:39:36 -0700 | [diff] [blame] | 486 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 487 | assert_not_equal(cip, None) |
| 488 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 489 | log_test.info('waiting rebind time %d seconds to send next request packet'%lval) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 490 | time.sleep(lval) |
| 491 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 492 | assert_equal(latest_cip,cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 493 | log_test.info('client got same IP after rebind time, as expected') |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 494 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 495 | def test_dhcp_client_expected_subnet_mask(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 496 | |
| 497 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 498 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 499 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 500 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 501 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 502 | expected_subnet = '255.255.255.0' |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 503 | self.dhcp.return_option = 'subnet' |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 504 | cip, sip, mac, subnet_mask = self.dhcp.only_discover() |
| 505 | assert_equal(subnet_mask, expected_subnet) |
| 506 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 507 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 508 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 509 | log_test.info('seen expected subnet mask %s in dhcp offer packet'%subnet_mask) |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 510 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 511 | def test_dhcp_client_sends_dhcp_request_with_wrong_subnet_mask(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 512 | |
| 513 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 514 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 515 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 516 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 517 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 518 | |
| 519 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 520 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 521 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 522 | assert_not_equal(cip, None) |
| 523 | self.dhcp.send_different_option = 'subnet' |
| 524 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 525 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 526 | log_test.info("Got DHCP Ack despite of specifying wrong Subnet Mask in DHCP Request.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 527 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 528 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 529 | def test_dhcp_client_expected_router_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 530 | |
| 531 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 532 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 533 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 534 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 535 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 536 | expected_router_address = '20.20.20.1' |
| 537 | self.dhcp.return_option = 'router' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 538 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 539 | cip, sip, mac, router_address_ip = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 540 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 541 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 542 | assert_not_equal(cip, None) |
| 543 | assert_equal(expected_router_address, router_address_ip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 544 | log_test.info('seen expected rouer address %s ip in dhcp offer packet'%router_address_ip) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 545 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 546 | def test_dhcp_client_sends_dhcp_request_with_wrong_router_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 547 | |
| 548 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 549 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 550 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 551 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 552 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 553 | |
| 554 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 555 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 556 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 557 | assert_not_equal(cip, None) |
| 558 | self.dhcp.send_different_option = 'router' |
| 559 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 560 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 561 | log_test.info("Got DHCP Ack despite of specifying wrong Router Address in DHCP Request.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 562 | |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 563 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 564 | def test_dhcp_client_expected_broadcast_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 565 | |
| 566 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 567 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 568 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 569 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 570 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 571 | expected_broadcast_address = '20.20.20.255' |
| 572 | self.dhcp.return_option = 'broadcast_address' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 573 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 574 | cip, sip, mac, broadcast_address = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 575 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 576 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 577 | assert_not_equal(cip, None) |
| 578 | assert_equal(expected_broadcast_address, broadcast_address) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 579 | log_test.info('seen expected broadcast address %s in dhcp offer packet'%broadcast_address) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 580 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 581 | def test_dhcp_client_sends_dhcp_request_with_wrong_broadcast_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 582 | |
| 583 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 584 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 585 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 586 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 587 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 588 | |
| 589 | cip, sip, mac, _ = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 590 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 591 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 592 | assert_not_equal(cip, None) |
| 593 | self.dhcp.send_different_option = 'broadcast_address' |
| 594 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 595 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 596 | log_test.info("Got DHCP Ack despite of specifying wrong Broadcast Address in DHCP Request.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 597 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 598 | def test_dhcp_client_expected_dns_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 599 | |
| 600 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 601 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 602 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'} |
| 603 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 604 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 605 | expected_dns_address = '8.8.8.8' |
| 606 | self.dhcp.return_option = 'dns' |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 607 | |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 608 | cip, sip, mac, dns_address = self.dhcp.only_discover() |
| 609 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 610 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 611 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 612 | assert_equal(expected_dns_address, dns_address) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 613 | log_test.info('seen expected DNS ip address %s in dhcp offer packet'%dns_address) |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 614 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 615 | def test_dhcp_client_sends_request_with_wrong_dns_address(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 616 | |
| 617 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 618 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 619 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1', 'domain':'8.8.8.8'} |
| 620 | self.onos_dhcp_table_load(config) |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 621 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = self.iface) |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 622 | |
| 623 | cip, sip, mac, _ = self.dhcp.only_discover() |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 624 | assert_not_equal(cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 625 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
Chetan Gaonker | 1dabecc | 2016-05-16 14:56:01 -0700 | [diff] [blame] | 626 | (cip, sip, mac) ) |
Anil Kumar Sanka | cfa7c58 | 2016-12-09 23:17:22 +0000 | [diff] [blame] | 627 | self.dhcp.send_different_option = 'dns' |
| 628 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 629 | assert_equal(new_cip, cip) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 630 | log_test.info("Got DHCP Ack despite of specifying wrong DNS Address in DHCP Request.") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 631 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 632 | def test_dhcp_server_transactions_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 633 | |
| 634 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 635 | self.stats() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 636 | log_test.info("Stats for run %d",i) |
| 637 | log_test.info("----------------------------------------------------------------------------------") |
| 638 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 639 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 640 | log_test.info("----------------------------------------------------------------------------------") |
| 641 | log_test.info("No. of transactions per second in run %d:%f" %(i, self.transaction_count)) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 642 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 643 | log_test.info("Final Statistics for total transactions") |
| 644 | log_test.info("----------------------------------------------------------------------------------") |
| 645 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 646 | log_test.info(" %d %d %d %d" %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 647 | self.total_success, self.total_failure, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 648 | log_test.info("----------------------------------------------------------------------------------") |
| 649 | log_test.info("Average no. of transactions per second: %d", round(self.transactions/self.running_time,0)) |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 650 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 651 | def test_dhcp_server_consecutive_successes_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 652 | |
| 653 | for i in range(1,4): |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 654 | self.stats(success_rate = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 655 | log_test.info("Stats for run %d",i) |
| 656 | log_test.info("----------------------------------------------------------------------------------") |
| 657 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 658 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 659 | log_test.info("----------------------------------------------------------------------------------") |
| 660 | log_test.info("No. of successful transactions per second in run %d:%f" %(i, self.transaction_count)) |
| 661 | log_test.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 662 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 663 | log_test.info("Final Statistics for total successful transactions") |
| 664 | log_test.info("----------------------------------------------------------------------------------") |
| 665 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 666 | log_test.info(" %d %d %d " %(self.transactions, |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 667 | self.total_success, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 668 | log_test.info("----------------------------------------------------------------------------------") |
| 669 | log_test.info("Average no. of consecutive successful transactions per second: %d", round(self.total_success/self.running_time,0)) |
| 670 | log_test.info("----------------------------------------------------------------------------------") |
Chetan Gaonker | 717b294 | 2016-05-13 17:42:59 -0700 | [diff] [blame] | 671 | |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 672 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 673 | def test_dhcp_server_client_transactions_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 674 | |
| 675 | for i in range(1,4): |
| 676 | self.stats(only_discover = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 677 | log_test.info("----------------------------------------------------------------------------------") |
| 678 | log_test.info("Stats for run %d of sending only DHCP Discover",i) |
| 679 | log_test.info("----------------------------------------------------------------------------------") |
| 680 | log_test.info("No. of transactions No. of successes No. of failures Running Time ") |
| 681 | log_test.info(" %d %d %d %d" %(self.ip_count+self.failure_count, self.ip_count, self.failure_count, self.diff)) |
| 682 | log_test.info("----------------------------------------------------------------------------------") |
| 683 | log_test.info("No. of clients per second in run %d:%f " |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 684 | %(i, self.transaction_count)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 685 | log_test.info("----------------------------------------------------------------------------------") |
| 686 | log_test.info("Final Statistics for total transactions of sending only DHCP Discover") |
| 687 | log_test.info("----------------------------------------------------------------------------------") |
| 688 | log_test.info("Total transactions Total No. of successes Total No. of failures Running Time ") |
| 689 | log_test.info(" %d %d %d %d" %(self.transactions, |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 690 | self.total_success, self.total_failure, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 691 | log_test.info("----------------------------------------------------------------------------------") |
| 692 | log_test.info("Average no. of clients per second: %d ", |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 693 | round(self.transactions/self.running_time,0)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 694 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 695 | |
A R Karthick | 10fe00e | 2016-07-12 16:13:16 -0700 | [diff] [blame] | 696 | def test_dhcp_server_consecutive_successful_clients_per_second(self): |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 697 | |
| 698 | for i in range(1,4): |
| 699 | self.stats(success_rate = True, only_discover = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 700 | log_test.info("----------------------------------------------------------------------------------") |
| 701 | log_test.info("Stats for run %d for sending only DHCP Discover",i) |
| 702 | log_test.info("----------------------------------------------------------------------------------") |
| 703 | log_test.info("No. of consecutive successful transactions Running Time ") |
| 704 | log_test.info(" %d %d " %(self.ip_count, self.diff)) |
| 705 | log_test.info("----------------------------------------------------------------------------------") |
| 706 | log_test.info("No. of consecutive successful clients per second in run %d:%f" %(i, self.transaction_count)) |
| 707 | log_test.info("----------------------------------------------------------------------------------") |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 708 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 709 | log_test.info("Final Statistics for total successful transactions") |
| 710 | log_test.info("----------------------------------------------------------------------------------") |
| 711 | log_test.info("Total transactions Total No. of consecutive successes Running Time ") |
| 712 | log_test.info(" %d %d %d " %(self.transactions, |
ChetanGaonker | 42d7581 | 2016-06-06 16:32:52 -0700 | [diff] [blame] | 713 | self.total_success, self.running_time)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 714 | log_test.info("----------------------------------------------------------------------------------") |
| 715 | log_test.info("Average no. of consecutive successful clients per second: %d", round(self.total_success/self.running_time,0)) |
| 716 | log_test.info("----------------------------------------------------------------------------------") |