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