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 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -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 |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -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 |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -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 | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 32 | import unittest |
| 33 | from nose.tools import * |
| 34 | from scapy.all import * |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 35 | from CordTestUtils import get_mac, log_test |
A.R Karthick | be7768c | 2017-03-17 11:39:41 -0700 | [diff] [blame] | 36 | from OnosCtrl import OnosCtrl |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 37 | from OltConfig import OltConfig |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 38 | from OnosFlowCtrl import OnosFlowCtrl |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 39 | from onosclidriver import OnosCliDriver |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 40 | #from quaggaclidriver import QuaggaCliDriver |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 41 | from CordContainer import Container, Onos, Quagga |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 42 | from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart, cord_test_quagga_stop, cord_test_quagga_shell |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 43 | from portmaps import g_subscriber_port_map |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 44 | from CordLogger import CordLogger |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 45 | import threading |
| 46 | import time |
| 47 | import os |
| 48 | import json |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 49 | import pexpect |
| 50 | |
| 51 | #from cli import quagga |
| 52 | #from quagga import * |
| 53 | #from cli import requires |
| 54 | #from cli import system |
| 55 | #from generic import * |
| 56 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 57 | log_test.setLevel('INFO') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 58 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 59 | class vrouter_exchange(CordLogger): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 60 | |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 61 | apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd') |
A R Karthick | 078e63a | 2016-07-28 13:59:31 -0700 | [diff] [blame] | 62 | device_id = 'of:' + get_mac() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 63 | vrouter_device_dict = { "devices" : { |
| 64 | "{}".format(device_id) : { |
| 65 | "basic" : { |
| 66 | "driver" : "softrouter" |
| 67 | } |
| 68 | } |
| 69 | }, |
| 70 | } |
| 71 | zebra_conf = ''' |
| 72 | password zebra |
| 73 | log stdout |
| 74 | service advanced-vty |
| 75 | ! |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 76 | !debug zebra rib |
| 77 | !debug zebra kernel |
| 78 | !debug zebra fpm |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 79 | ! |
| 80 | !interface eth1 |
| 81 | ! ip address 10.10.0.3/16 |
| 82 | line vty |
| 83 | exec-timeout 0 0 |
| 84 | ''' |
| 85 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 86 | quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config') |
| 87 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 88 | GATEWAY = '192.168.10.50' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 89 | INGRESS_PORT = 1 |
| 90 | EGRESS_PORT = 2 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 91 | MAX_PORTS = 100 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 92 | peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 93 | network_list = [] |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 94 | network_mask = 24 |
| 95 | default_routes_address = ('11.10.10.0/24',) |
| 96 | default_peer_address = peer_list |
| 97 | quagga_ip = os.getenv('QUAGGA_IP') |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 98 | |
| 99 | @classmethod |
| 100 | def setUpClass(cls): |
| 101 | ''' Activate the vrouter apps''' |
| 102 | cls.olt = OltConfig() |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 103 | cls.port_map, _ = cls.olt.olt_port_map() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 104 | if not cls.port_map: |
| 105 | cls.port_map = g_subscriber_port_map |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 106 | time.sleep(3) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 107 | cls.load_device_id() |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 108 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 109 | @classmethod |
| 110 | def tearDownClass(cls): |
| 111 | '''Deactivate the vrouter apps''' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 112 | #cls.vrouter_host_unload() |
A R Karthick | 4e0c091 | 2016-08-17 16:57:42 -0700 | [diff] [blame] | 113 | cls.start_onos(network_cfg = {}) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 114 | |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 115 | @classmethod |
| 116 | def load_device_id(cls): |
| 117 | did = OnosCtrl.get_device_id() |
| 118 | cls.device_id = did |
| 119 | cls.vrouter_device_dict = { "devices" : { |
| 120 | "{}".format(did) : { |
| 121 | "basic" : { |
| 122 | "driver" : "softrouter" |
| 123 | } |
| 124 | } |
| 125 | }, |
| 126 | } |
| 127 | |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 128 | @classmethod |
| 129 | def activate_apps(cls, deactivate = False): |
| 130 | for app in cls.apps: |
| 131 | onos_ctrl = OnosCtrl(app) |
| 132 | if deactivate is False: |
| 133 | onos_ctrl.activate() |
| 134 | else: |
| 135 | onos_ctrl.deactivate() |
| 136 | time.sleep(2) |
| 137 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 138 | def cliEnter(self): |
| 139 | retries = 0 |
| 140 | while retries < 3: |
| 141 | self.cli = OnosCliDriver(connect = True) |
| 142 | if self.cli.handle: |
| 143 | break |
| 144 | else: |
| 145 | retries += 1 |
| 146 | time.sleep(2) |
| 147 | |
| 148 | def cliExit(self): |
| 149 | self.cli.disconnect() |
| 150 | |
| 151 | @classmethod |
| 152 | def onos_load_config(cls, config): |
| 153 | status, code = OnosCtrl.config(config) |
| 154 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 155 | log_test.info('JSON request returned status %d' %code) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 156 | assert_equal(status, True) |
| 157 | |
| 158 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 159 | def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None, |
| 160 | route_update = None, router_address = None): |
| 161 | vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers, |
| 162 | peer_address = peer_address, router_address = router_address) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 163 | return vrouter_configs |
| 164 | ##ONOS router does not support dynamic reconfigurations |
| 165 | #for config in vrouter_configs: |
| 166 | # cls.onos_load_config(config) |
| 167 | # time.sleep(5) |
| 168 | |
| 169 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 170 | def vrouter_host_load(cls, peer_address = None): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 171 | index = 1 |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 172 | peer_info = peer_address if peer_address is not None else cls.peer_list |
| 173 | |
| 174 | for host,_ in peer_info: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 175 | iface = cls.port_map[index] |
| 176 | index += 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 177 | log_test.info('Assigning ip %s to interface %s' %(host, iface)) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 178 | config_cmds = ( 'ifconfig {} 0'.format(iface), |
| 179 | 'ifconfig {0} {1}'.format(iface, host), |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 180 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 181 | ) |
| 182 | for cmd in config_cmds: |
| 183 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 184 | |
| 185 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 186 | def vrouter_host_unload(cls, peer_address = None): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 187 | index = 1 |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 188 | peer_info = peer_address if peer_address is not None else cls.peer_list |
| 189 | |
| 190 | for host,_ in peer_info: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 191 | iface = cls.port_map[index] |
| 192 | index += 1 |
| 193 | config_cmds = ('ifconfig {} 0'.format(iface), ) |
| 194 | for cmd in config_cmds: |
| 195 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 196 | |
| 197 | @classmethod |
| 198 | def start_onos(cls, network_cfg = None): |
| 199 | if type(network_cfg) is tuple: |
| 200 | res = [] |
| 201 | for v in network_cfg: |
| 202 | res += v.items() |
| 203 | config = dict(res) |
| 204 | else: |
| 205 | config = network_cfg |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 206 | log_test.info('Restarting ONOS with new network configuration') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 207 | return cord_test_onos_restart(config = config) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 208 | |
| 209 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 210 | def start_quagga(cls, networks = 4, peer_address = None, router_address = None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 211 | log_test.info('Restarting Quagga container with configuration for %d networks' %(networks)) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 212 | config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address) |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 213 | if networks <= 10000: |
| 214 | boot_delay = 25 |
| 215 | else: |
Chetan Gaonker | 37ad23f | 2016-05-03 17:37:59 -0700 | [diff] [blame] | 216 | delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200] |
| 217 | n = min(networks/100000, len(delay_map)-1) |
| 218 | boot_delay = delay_map[n] |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 219 | cord_test_quagga_restart(config = config, boot_delay = boot_delay) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 220 | |
| 221 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 222 | def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 223 | num = 0 |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 224 | if peer_address is None: |
| 225 | start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0 |
| 226 | end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0 |
| 227 | else: |
| 228 | ip = peer_address[0][0] |
| 229 | start_ip = ip.split('.') |
| 230 | start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0 |
| 231 | end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 232 | local_network = end_peer + 1 |
| 233 | ports_dict = { 'ports' : {} } |
| 234 | interface_list = [] |
| 235 | peer_list = [] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 236 | for n in xrange(start_peer, end_peer, 256): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 237 | port_map = ports_dict['ports'] |
| 238 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 239 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 240 | try: |
| 241 | interfaces = port_map[device_port_key]['interfaces'] |
| 242 | except: |
| 243 | port_map[device_port_key] = { 'interfaces' : [] } |
| 244 | interfaces = port_map[device_port_key]['interfaces'] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 245 | ip = n + 2 |
| 246 | peer_ip = n + 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 247 | ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 248 | peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff ) |
| 249 | mac = RandMAC()._fix() |
| 250 | peer_list.append((peer, mac)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 251 | if num < cls.MAX_PORTS - 1: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 252 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac } |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 253 | interfaces.append(interface_dict) |
| 254 | interface_list.append(interface_dict['name']) |
| 255 | else: |
| 256 | interfaces[0]['ips'].append(ips) |
| 257 | num += 1 |
| 258 | if num == peers: |
| 259 | break |
| 260 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 261 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 262 | quagga_router_dict['ospfEnabled'] = True |
| 263 | quagga_router_dict['interfaces'] = interface_list |
| 264 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 265 | |
| 266 | #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 267 | bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers'] |
| 268 | speaker_dict = {} |
| 269 | speaker_dict['name'] = 'bgp{}'.format(peers+1) |
| 270 | speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 271 | speaker_dict['peers'] = peer_list |
| 272 | bgp_speakers_list.append(speaker_dict) |
| 273 | cls.peer_list = peer_list |
| 274 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 275 | |
| 276 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 277 | def generate_conf(cls, networks = 4, peer_address = None, router_address = None): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 278 | num = 0 |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 279 | if router_address is None: |
| 280 | start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0 |
| 281 | end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
| 282 | network_mask = 24 |
| 283 | else: |
| 284 | ip = router_address |
| 285 | start_ip = ip.split('.') |
| 286 | network_mask = int(start_ip[3].split('/')[1]) |
| 287 | start_ip[3] = (start_ip[3].split('/'))[0] |
| 288 | start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0 |
| 289 | end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 290 | net_list = [] |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 291 | peer_list = peer_address if peer_address is not None else cls.peer_list |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 292 | network_list = [] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 293 | for n in xrange(start_network, end_network, 256): |
| 294 | net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) ) |
| 295 | network_list.append(net) |
| 296 | gateway = peer_list[num % len(peer_list)][0] |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 297 | net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway) |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 298 | net_list.append(net_route) |
| 299 | num += 1 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 300 | if num == networks: |
| 301 | break |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 302 | cls.network_list = network_list |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 303 | cls.network_mask = network_mask |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 304 | zebra_routes = '\n'.join(net_list) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 305 | #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 306 | return cls.zebra_conf + zebra_routes |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 307 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 308 | @classmethod |
| 309 | def vrouter_activate(cls, deactivate = False): |
| 310 | app = 'org.onosproject.vrouter' |
| 311 | onos_ctrl = OnosCtrl(app) |
| 312 | if deactivate is True: |
| 313 | onos_ctrl.deactivate() |
| 314 | else: |
| 315 | onos_ctrl.activate() |
| 316 | time.sleep(3) |
| 317 | |
| 318 | @classmethod |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 319 | def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None, |
| 320 | route_update = None, router_address = None, time_expire = None, adding_new_routes = None): |
| 321 | vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers, |
| 322 | peer_address = peer_address, route_update = route_update) |
Chetan Gaonker | 46b62d5 | 2016-04-26 10:08:42 -0700 | [diff] [blame] | 323 | cls.start_onos(network_cfg = vrouter_configs) |
A R Karthick | 5241473 | 2017-01-31 09:59:47 -0800 | [diff] [blame] | 324 | cls.activate_apps() |
| 325 | time.sleep(5) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 326 | cls.vrouter_host_load() |
Chetan Gaonker | 02236ba | 2016-04-26 11:24:34 -0700 | [diff] [blame] | 327 | ##Start quagga |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 328 | cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 329 | return vrouter_configs |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 330 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 331 | def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 332 | src_mac = '00:00:00:00:00:02' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 333 | src_ip = '1.1.1.1' |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 334 | self.success = False if positive_test else True |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 335 | timeout = 10 if positive_test else 1 |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 336 | count = 2 if positive_test else 1 |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 337 | self.start_sending = True |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 338 | def recv_task(): |
| 339 | def recv_cb(pkt): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 340 | log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 341 | self.success = True if positive_test else False |
| 342 | sniff(count=count, timeout=timeout, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 343 | lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip, |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 344 | prn = recv_cb, iface = self.port_map[ingress]) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 345 | self.start_sending = False |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 346 | |
| 347 | t = threading.Thread(target = recv_task) |
| 348 | t.start() |
| 349 | L2 = Ether(src = src_mac, dst = dst_mac) |
| 350 | L3 = IP(src = src_ip, dst = dst_ip) |
| 351 | pkt = L2/L3 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 352 | log_test.info('Sending a packet with dst ip %s, dst mac %s on port %s to verify if flows are correct' % |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 353 | (dst_ip, dst_mac, self.port_map[egress])) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 354 | while self.start_sending is True: |
| 355 | sendp(pkt, count=50, iface = self.port_map[egress]) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 356 | t.join() |
| 357 | assert_equal(self.success, True) |
| 358 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 359 | def vrouter_traffic_verify(self, positive_test = True, peer_address = None): |
| 360 | if peer_address is None: |
| 361 | peers = len(self.peer_list) |
| 362 | peer_list = self.peer_list |
| 363 | else: |
| 364 | peers = len(peer_address) |
| 365 | peer_list = peer_address |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 366 | egress = peers + 1 |
| 367 | num = 0 |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 368 | num_hosts = 5 if positive_test else 1 |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 369 | src_mac = '00:00:00:00:00:02' |
| 370 | src_ip = '1.1.1.1' |
| 371 | if self.network_mask != 24: |
| 372 | peers = 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 373 | for network in self.network_list: |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 374 | num_ips = num_hosts |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 375 | octets = network.split('.') |
| 376 | for i in xrange(num_ips): |
| 377 | octets[-1] = str(int(octets[-1]) + 1) |
| 378 | dst_ip = '.'.join(octets) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 379 | dst_mac = peer_list[ num % peers ] [1] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 380 | port = (num % peers) |
| 381 | ingress = port + 1 |
| 382 | #Since peers are on the same network |
| 383 | ##Verify if flows are setup by sending traffic across |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 384 | self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 385 | num += 1 |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 386 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 387 | def __vrouter_network_verify(self, networks, peers = 1, positive_test = True, |
| 388 | start_network = None, start_peer_address = None, route_update = None, |
| 389 | invalid_peers = None, time_expire = None, unreachable_route_traffic = None, |
| 390 | deactivate_activate_vrouter = None, adding_new_routes = None): |
| 391 | |
| 392 | _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers, |
| 393 | peer_address = start_peer_address, |
| 394 | route_update = route_update, |
| 395 | router_address = start_network, |
| 396 | time_expire = time_expire, |
| 397 | adding_new_routes = adding_new_routes) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 398 | self.cliEnter() |
| 399 | ##Now verify |
| 400 | hosts = json.loads(self.cli.hosts(jsonFormat = True)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 401 | log_test.info('Discovered hosts: %s' %hosts) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 402 | ##We read from cli if we expect less number of routes to avoid cli timeouts |
| 403 | if networks <= 10000: |
| 404 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 405 | #log_test.info('Routes: %s' %routes) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 406 | if start_network is not None: |
| 407 | if start_network.split('/')[1] is 24: |
| 408 | assert_equal(len(routes['routes4']), networks) |
| 409 | if start_network.split('/')[1] is not 24: |
| 410 | assert_equal(len(routes['routes4']), 1) |
| 411 | if start_network is None and invalid_peers is None: |
| 412 | assert_equal(len(routes['routes4']), networks) |
| 413 | if invalid_peers is not None: |
| 414 | assert_equal(len(routes['routes4']), 0) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 415 | flows = json.loads(self.cli.flows(jsonFormat = True)) |
| 416 | flows = filter(lambda f: f['flows'], flows) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 417 | #log_test.info('Flows: %s' %flows) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 418 | assert_not_equal(len(flows), 0) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 419 | if invalid_peers is None: |
| 420 | self.vrouter_traffic_verify() |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 421 | if positive_test is False: |
| 422 | self.__vrouter_network_verify_negative(networks, peers = peers) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 423 | if time_expire is True: |
| 424 | self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24') |
| 425 | self.vrouter_traffic_verify() |
| 426 | if unreachable_route_traffic is True: |
| 427 | network_list_backup = self.network_list |
| 428 | self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5'] |
| 429 | self.vrouter_traffic_verify(positive_test = False) |
| 430 | self.network_list = network_list_backup |
| 431 | if deactivate_activate_vrouter is True: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 432 | log_test.info('Deactivating vrouter app in ONOS controller for negative scenario') |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 433 | self.vrouter_activate(deactivate = True) |
| 434 | #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False)) |
| 435 | #assert_equal(len(routes['routes4']), 'Command not found') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 436 | log_test.info('Activating vrouter app again in ONOS controller for negative scenario') |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 437 | self.vrouter_activate(deactivate = False) |
| 438 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 439 | assert_equal(len(routes['routes4']), networks) |
| 440 | self.vrouter_traffic_verify() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 441 | self.cliExit() |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 442 | self.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 443 | return True |
| 444 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 445 | def __vrouter_network_verify_negative(self, networks, peers = 1): |
| 446 | ##Stop quagga. Test traffic again to see if flows were removed |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 447 | log_test.info('Stopping Quagga container') |
A R Karthick | 4a2362c | 2016-06-22 17:32:44 -0700 | [diff] [blame] | 448 | cord_test_quagga_stop() |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 449 | if networks <= 10000: |
| 450 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 451 | #Verify routes have been removed |
| 452 | if routes and routes.has_key('routes4'): |
| 453 | assert_equal(len(routes['routes4']), 0) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 454 | self.vrouter_traffic_verify(positive_test = False) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 455 | log_test.info('OVS flows have been removed successfully after Quagga was stopped') |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 456 | self.start_quagga(networks = networks) |
| 457 | ##Verify the flows again after restarting quagga back |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 458 | if networks <= 10000: |
| 459 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 460 | assert_equal(len(routes['routes4']), networks) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 461 | self.vrouter_traffic_verify() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 462 | log_test.info('OVS flows have been successfully reinstalled after Quagga was restarted') |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 463 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 464 | def quagga_shell(self, cmd): |
| 465 | shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd)) |
| 466 | quagga_cmd = ' -c '.join(shell_cmds) |
| 467 | return cord_test_quagga_shell(quagga_cmd) |
| 468 | |
| 469 | def test_vrouter_with_5_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 470 | res = self.__vrouter_network_verify(5, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 471 | assert_equal(res, True) |
| 472 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 473 | def test_vrouter_with_5_routes_2_peers(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 474 | res = self.__vrouter_network_verify(5, peers = 2) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 475 | assert_equal(res, True) |
| 476 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 477 | def test_vrouter_with_6_routes_3_peers(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 478 | res = self.__vrouter_network_verify(6, peers = 3) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 479 | assert_equal(res, True) |
| 480 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 481 | def test_vrouter_with_50_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 482 | res = self.__vrouter_network_verify(50, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 483 | assert_equal(res, True) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 484 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 485 | def test_vrouter_with_50_routes_5_peers(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 486 | res = self.__vrouter_network_verify(50, peers = 5) |
| 487 | assert_equal(res, True) |
| 488 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 489 | def test_vrouter_with_100_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 490 | res = self.__vrouter_network_verify(100, peers = 1) |
| 491 | assert_equal(res, True) |
| 492 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 493 | def test_vrouter_with_100_routes_10_peers(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 494 | res = self.__vrouter_network_verify(100, peers = 10) |
| 495 | assert_equal(res, True) |
| 496 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 497 | def test_vrouter_with_300_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 498 | res = self.__vrouter_network_verify(300, peers = 1) |
| 499 | assert_equal(res, True) |
| 500 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 501 | def test_vrouter_with_1000_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 502 | res = self.__vrouter_network_verify(1000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 503 | assert_equal(res, True) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 504 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 505 | def test_vrouter_with_10000_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 506 | res = self.__vrouter_network_verify(10000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 507 | assert_equal(res, True) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 508 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 509 | @nottest |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 510 | def test_vrouter_with_100000_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 511 | res = self.__vrouter_network_verify(100000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 512 | assert_equal(res, True) |
| 513 | |
| 514 | @nottest |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 515 | def test_vrouter_with_1000000_routes(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 516 | res = self.__vrouter_network_verify(1000000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 517 | assert_equal(res, True) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 518 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 519 | def test_vrouter_with_5_routes_stopping_quagga(self): |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 520 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = False) |
| 521 | |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 522 | def test_vrouter_with_50_routes_stopping_quagga(self): |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 523 | res = self.__vrouter_network_verify(50, peers = 1, positive_test = False) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 524 | |
| 525 | def test_vrouter_with_route_update(self): |
| 526 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True) |
| 527 | assert_equal(res, True) |
| 528 | peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')] |
| 529 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, |
| 530 | start_peer_address = peer_info, route_update = True) |
| 531 | assert_equal(res, True) |
| 532 | |
| 533 | def test_vrouter_with_classA_route_update(self): |
| 534 | router_address = '11.10.10.0/8' |
| 535 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address) |
| 536 | assert_equal(res, True) |
| 537 | |
| 538 | def test_vrouter_with_classB_route_update(self): |
| 539 | router_address = '11.10.10.0/16' |
| 540 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address) |
| 541 | assert_equal(res, True) |
| 542 | |
| 543 | def test_vrouter_with_classless_route_update(self): |
| 544 | router_address = '11.10.10.0/12' |
| 545 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address) |
| 546 | assert_equal(res, True) |
| 547 | |
| 548 | def test_vrouter_with_classA_duplicate_route_update(self): |
| 549 | router_address = '11.10.10.0/8' |
| 550 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address) |
| 551 | assert_equal(res, True) |
| 552 | |
| 553 | def test_vrouter_with_classB_duplicate_route_update(self): |
| 554 | router_address = '11.10.10.0/16' |
| 555 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address) |
| 556 | assert_equal(res, True) |
| 557 | |
| 558 | def test_vrouter_with_classless_duplicate_route_update(self): |
| 559 | router_address = '11.10.10.0/12' |
| 560 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address) |
| 561 | assert_equal(res, True) |
| 562 | |
| 563 | def test_vrouter_with_invalid_peers(self): |
| 564 | peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')] |
| 565 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, |
| 566 | start_peer_address = peer_info, invalid_peers= True) |
| 567 | assert_equal(res, True) |
| 568 | |
| 569 | @nottest |
| 570 | def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self): |
| 571 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True) |
| 572 | assert_equal(res, True) |
| 573 | |
| 574 | @nottest |
| 575 | def test_vrouter_with_routes_time_expire(self): |
| 576 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True) |
| 577 | assert_equal(res, True) |
| 578 | |
| 579 | def test_vrouter_with_unreachable_route(self): |
| 580 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True) |
| 581 | assert_equal(res, True) |
| 582 | |
| 583 | @nottest |
| 584 | def test_vrouter_with_enabling_disabling_vrouter_app(self): |
| 585 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True) |
| 586 | assert_equal(res, True) |
| 587 | |
| 588 | def test_vrouter_with_adding_new_routes_in_routing_table(self): |
| 589 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True) |
| 590 | cmd = 'ip route 21.10.20.0/24 192.168.10.1' |
| 591 | self.quagga_shell(cmd) |
| 592 | self.vrouter_traffic_verify() |
| 593 | self.network_list = [ '21.10.20.0' ] |
| 594 | self.network_mask = 24 |
| 595 | self.vrouter_traffic_verify() |
| 596 | assert_equal(res, True) |
| 597 | |
| 598 | def test_vrouter_with_removing_old_routes_in_routing_table(self): |
| 599 | res = self.__vrouter_network_verify(5, peers = 2, positive_test = True) |
| 600 | cmd = 'ip route 21.10.20.0/24 192.168.10.1' |
| 601 | self.quagga_shell(cmd) |
| 602 | self.vrouter_traffic_verify() |
| 603 | old_network_list = self.network_list |
| 604 | old_network_mask = self.network_mask |
| 605 | self.network_list = [ '21.10.20.0' ] |
| 606 | self.network_mask = 24 |
| 607 | self.vrouter_traffic_verify() |
| 608 | assert_equal(res, True) |
| 609 | cmd = 'no ip route 21.10.20.0/24 192.168.10.1' |
| 610 | self.quagga_shell(cmd) |
A R Karthick | a93829a | 2016-07-01 10:08:23 -0700 | [diff] [blame] | 611 | time.sleep(5) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 612 | self.vrouter_traffic_verify(positive_test = False) |
| 613 | self.network_mask = old_network_mask |
| 614 | self.network_list = old_network_list |
| 615 | self.vrouter_traffic_verify(positive_test = True) |
| 616 | |
| 617 | def test_vrouter_modifying_nexthop_route_in_routing_table(self): |
| 618 | peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')] |
| 619 | router_address = '11.10.10.0/24' |
| 620 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, |
| 621 | start_peer_address = peer_info, start_network = router_address) |
| 622 | cmd = 'ip route 11.10.10.0/24 192.168.20.1' |
| 623 | self.quagga_shell(cmd) |
| 624 | self.vrouter_traffic_verify(positive_test = True) |
| 625 | assert_equal(res, True) |
| 626 | |
| 627 | |
| 628 | def test_vrouter_deleting_alternative_nexthop_in_routing_table(self): |
| 629 | peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')] |
| 630 | router_address = '11.10.10.0/24' |
| 631 | res = self.__vrouter_network_verify(1, peers = 2, positive_test = True, |
| 632 | start_peer_address = peer_info, start_network = router_address) |
| 633 | cmd = 'no ip route 11.10.10.0/24 192.168.10.1' |
| 634 | self.quagga_shell(cmd) |
A R Karthick | a93829a | 2016-07-01 10:08:23 -0700 | [diff] [blame] | 635 | time.sleep(5) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 636 | self.vrouter_traffic_verify(positive_test = False) |
| 637 | assert_equal(res, True) |
| 638 | |
| 639 | def test_vrouter_deleting_some_routes_in_routing_table(self): |
| 640 | peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')] |
| 641 | router_address = '11.10.10.0/24' |
| 642 | res = self.__vrouter_network_verify(10, peers = 2, positive_test = True, |
| 643 | start_peer_address = peer_info, start_network = router_address) |
| 644 | cmd = 'no ip route 11.10.10.0/24 192.168.10.1' |
| 645 | self.quagga_shell(cmd) |
| 646 | cmd = 'no ip route 11.10.13.0/24 192.168.11.1' |
| 647 | self.quagga_shell(cmd) |
| 648 | cmd = 'no ip route 11.10.14.0/24 192.168.10.1' |
| 649 | self.quagga_shell(cmd) |
| 650 | self.vrouter_traffic_verify(positive_test = True) |
| 651 | assert_equal(res, True) |
| 652 | |
| 653 | |
| 654 | def test_vrouter_deleting_and_adding_routes_in_routing_table(self): |
| 655 | peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')] |
| 656 | router_address = '11.10.10.0/24' |
| 657 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address) |
| 658 | cmd = 'no ip route 11.10.10.0/24 192.168.10.1' |
| 659 | self.quagga_shell(cmd) |
| 660 | cmd = 'ip route 11.10.10.0/24 192.168.10.1' |
| 661 | self.quagga_shell(cmd) |
| 662 | self.vrouter_traffic_verify(positive_test = True) |
| 663 | assert_equal(res, True) |
| 664 | |
| 665 | def test_vrouter_toggling_nexthop_interface(self): |
| 666 | peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')] |
| 667 | router_address = '11.10.10.0/24' |
| 668 | res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address) |
A R Karthick | a93829a | 2016-07-01 10:08:23 -0700 | [diff] [blame] | 669 | iface = self.port_map[1] |
| 670 | #toggle the interface to trigger host removal. |
| 671 | cmds = ('ifconfig {} down'.format(iface), |
| 672 | 'sleep 2', |
| 673 | 'ifconfig {} 0'.format(iface),) |
| 674 | for cmd in cmds: |
| 675 | os.system(cmd) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 676 | self.vrouter_traffic_verify(positive_test = False) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 677 | host = "192.168.10.1" |
A R Karthick | a93829a | 2016-07-01 10:08:23 -0700 | [diff] [blame] | 678 | cmd = 'ifconfig {0} {1} up'.format(iface, host) |
| 679 | os.system(cmd) |
| 680 | #wait for arp refresh |
| 681 | time.sleep(60) |
ChetanGaonker | 70820bb | 2016-06-29 18:11:57 -0700 | [diff] [blame] | 682 | self.vrouter_traffic_verify(positive_test = True) |
| 683 | assert_equal(res, True) |
A R Karthick | 8f93029 | 2017-07-07 12:36:22 -0700 | [diff] [blame] | 684 | |
| 685 | def vrouter_scale(self, num_routes, peers = 1): |
| 686 | '''Called from scale test''' |
| 687 | return self.__vrouter_network_verify(num_routes, peers = peers) |