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