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