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