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