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