Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 1 | # |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 16 | import unittest |
| 17 | from nose.tools import * |
| 18 | from scapy.all import * |
| 19 | from OnosCtrl import OnosCtrl |
| 20 | from OltConfig import OltConfig |
| 21 | from OnosFlowCtrl import OnosFlowCtrl, get_mac |
| 22 | from onosclidriver import OnosCliDriver |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 23 | from CordContainer import Container, Onos, Quagga |
| 24 | from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 25 | from portmaps import g_subscriber_port_map |
| 26 | import threading |
| 27 | import time |
| 28 | import os |
| 29 | import json |
| 30 | log.setLevel('INFO') |
| 31 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 32 | class QuaggaStopWrapper(Container): |
| 33 | |
| 34 | def __init__(self, name = 'cord-quagga', image = 'cord-test/quagga', tag = 'latest'): |
| 35 | super(QuaggaStopWrapper, self).__init__(name, image, tag = tag) |
| 36 | if self.exists(): |
| 37 | self.kill() |
| 38 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 39 | class vrouter_exchange(unittest.TestCase): |
| 40 | |
| 41 | apps = ('org.onosproject.vrouter', 'org.onosproject.fwd') |
| 42 | device_id = 'of:' + get_mac('ovsbr0') |
| 43 | vrouter_device_dict = { "devices" : { |
| 44 | "{}".format(device_id) : { |
| 45 | "basic" : { |
| 46 | "driver" : "softrouter" |
| 47 | } |
| 48 | } |
| 49 | }, |
| 50 | } |
| 51 | zebra_conf = ''' |
| 52 | password zebra |
| 53 | log stdout |
| 54 | service advanced-vty |
| 55 | ! |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 56 | !debug zebra rib |
| 57 | !debug zebra kernel |
| 58 | !debug zebra fpm |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 59 | ! |
| 60 | !interface eth1 |
| 61 | ! ip address 10.10.0.3/16 |
| 62 | line vty |
| 63 | exec-timeout 0 0 |
| 64 | ''' |
| 65 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 66 | quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config') |
| 67 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 68 | GATEWAY = '192.168.10.50' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 69 | INGRESS_PORT = 1 |
| 70 | EGRESS_PORT = 2 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 71 | MAX_PORTS = 100 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 72 | 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] | 73 | network_list = [] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 74 | |
| 75 | @classmethod |
| 76 | def setUpClass(cls): |
| 77 | ''' Activate the vrouter apps''' |
| 78 | cls.olt = OltConfig() |
| 79 | cls.port_map = cls.olt.olt_port_map() |
| 80 | if not cls.port_map: |
| 81 | cls.port_map = g_subscriber_port_map |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 82 | #cls.vrouter_host_load(host = cls.GATEWAY) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 83 | time.sleep(3) |
| 84 | |
| 85 | @classmethod |
| 86 | def tearDownClass(cls): |
| 87 | '''Deactivate the vrouter apps''' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 88 | #cls.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 89 | |
| 90 | def cliEnter(self): |
| 91 | retries = 0 |
| 92 | while retries < 3: |
| 93 | self.cli = OnosCliDriver(connect = True) |
| 94 | if self.cli.handle: |
| 95 | break |
| 96 | else: |
| 97 | retries += 1 |
| 98 | time.sleep(2) |
| 99 | |
| 100 | def cliExit(self): |
| 101 | self.cli.disconnect() |
| 102 | |
| 103 | @classmethod |
| 104 | def onos_load_config(cls, config): |
| 105 | status, code = OnosCtrl.config(config) |
| 106 | if status is False: |
| 107 | log.info('JSON request returned status %d' %code) |
| 108 | assert_equal(status, True) |
| 109 | |
| 110 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 111 | def vrouter_config_get(cls, networks = 4, peers = 1): |
| 112 | vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 113 | return vrouter_configs |
| 114 | ##ONOS router does not support dynamic reconfigurations |
| 115 | #for config in vrouter_configs: |
| 116 | # cls.onos_load_config(config) |
| 117 | # time.sleep(5) |
| 118 | |
| 119 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 120 | def vrouter_host_load(cls): |
| 121 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 122 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 123 | iface = cls.port_map[index] |
| 124 | index += 1 |
| 125 | config_cmds = ( 'ifconfig {0} {1}'.format(iface, host), |
| 126 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 127 | ) |
| 128 | for cmd in config_cmds: |
| 129 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 130 | |
| 131 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 132 | def vrouter_host_unload(cls): |
| 133 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 134 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 135 | iface = cls.port_map[index] |
| 136 | index += 1 |
| 137 | config_cmds = ('ifconfig {} 0'.format(iface), ) |
| 138 | for cmd in config_cmds: |
| 139 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 140 | |
| 141 | @classmethod |
| 142 | def start_onos(cls, network_cfg = None): |
| 143 | if type(network_cfg) is tuple: |
| 144 | res = [] |
| 145 | for v in network_cfg: |
| 146 | res += v.items() |
| 147 | config = dict(res) |
| 148 | else: |
| 149 | config = network_cfg |
| 150 | log.info('Restarting ONOS with new network configuration') |
| 151 | cfg = json.dumps(config) |
| 152 | with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f: |
| 153 | f.write(cfg) |
| 154 | |
| 155 | return cord_test_onos_restart() |
| 156 | |
| 157 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 158 | def start_quagga(cls, networks = 4): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 159 | log.info('Restarting Quagga container with configuration for %d networks' %(networks)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 160 | config = cls.generate_conf(networks = networks) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 161 | host_config_file = '{}/testrib_gen.conf'.format(Quagga.host_quagga_config) |
| 162 | guest_config_file = os.path.join(Quagga.guest_quagga_config, 'testrib_gen.conf') |
| 163 | with open(host_config_file, 'w') as f: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 164 | f.write(config) |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 165 | if networks <= 10000: |
| 166 | boot_delay = 25 |
| 167 | else: |
Chetan Gaonker | 37ad23f | 2016-05-03 17:37:59 -0700 | [diff] [blame] | 168 | delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200] |
| 169 | n = min(networks/100000, len(delay_map)-1) |
| 170 | boot_delay = delay_map[n] |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 171 | cord_test_quagga_restart(config_file = guest_config_file, boot_delay = boot_delay) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 172 | |
| 173 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 174 | def zgenerate_vrouter_conf(cls, networks = 4): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 175 | num = 0 |
| 176 | start_network = ( 11 << 24) | ( 0 << 16) | ( 0 << 8) | 0 |
| 177 | end_network = ( 200 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
| 178 | ports_dict = { 'ports' : {} } |
| 179 | interface_list = [] |
| 180 | for n in xrange(start_network, end_network): |
| 181 | if n & 255 == 0: |
| 182 | port_map = ports_dict['ports'] |
| 183 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 184 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 185 | try: |
| 186 | interfaces = port_map[device_port_key]['interfaces'] |
| 187 | except: |
| 188 | port_map[device_port_key] = { 'interfaces' : [] } |
| 189 | interfaces = port_map[device_port_key]['interfaces'] |
| 190 | |
| 191 | ips = '%d.%d.%d.2/24'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) ) |
| 192 | if num < cls.MAX_PORTS - 1: |
| 193 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : '00:00:00:00:00:01' } |
| 194 | interfaces.append(interface_dict) |
| 195 | interface_list.append(interface_dict['name']) |
| 196 | else: |
| 197 | interfaces[0]['ips'].append(ips) |
| 198 | num += 1 |
| 199 | if num == networks: |
| 200 | break |
| 201 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {} } } } |
| 202 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 203 | quagga_router_dict['ospfEnabled'] = True |
| 204 | quagga_router_dict['interfaces'] = interface_list |
| 205 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, |
| 206 | networks + 1 if networks < cls.MAX_PORTS else cls.MAX_PORTS ) |
| 207 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 208 | |
| 209 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 210 | def generate_vrouter_conf(cls, networks = 4, peers = 1): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 211 | num = 0 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 212 | start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0 |
| 213 | end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 214 | local_network = end_peer + 1 |
| 215 | ports_dict = { 'ports' : {} } |
| 216 | interface_list = [] |
| 217 | peer_list = [] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 218 | for n in xrange(start_peer, end_peer, 256): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 219 | port_map = ports_dict['ports'] |
| 220 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 221 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 222 | try: |
| 223 | interfaces = port_map[device_port_key]['interfaces'] |
| 224 | except: |
| 225 | port_map[device_port_key] = { 'interfaces' : [] } |
| 226 | interfaces = port_map[device_port_key]['interfaces'] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 227 | ip = n + 2 |
| 228 | peer_ip = n + 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 229 | 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] | 230 | peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff ) |
| 231 | mac = RandMAC()._fix() |
| 232 | peer_list.append((peer, mac)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 233 | if num < cls.MAX_PORTS - 1: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 234 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac } |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 235 | interfaces.append(interface_dict) |
| 236 | interface_list.append(interface_dict['name']) |
| 237 | else: |
| 238 | interfaces[0]['ips'].append(ips) |
| 239 | num += 1 |
| 240 | if num == peers: |
| 241 | break |
| 242 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 243 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 244 | quagga_router_dict['ospfEnabled'] = True |
| 245 | quagga_router_dict['interfaces'] = interface_list |
| 246 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 247 | |
| 248 | #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 249 | bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers'] |
| 250 | speaker_dict = {} |
| 251 | speaker_dict['name'] = 'bgp{}'.format(peers+1) |
| 252 | speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 253 | speaker_dict['peers'] = peer_list |
| 254 | bgp_speakers_list.append(speaker_dict) |
| 255 | cls.peer_list = peer_list |
| 256 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 257 | |
| 258 | @classmethod |
| 259 | def generate_conf(cls, networks = 4): |
| 260 | num = 0 |
| 261 | start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0 |
| 262 | end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 263 | net_list = [] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 264 | peer_list = cls.peer_list |
| 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] |
| 270 | net_route = 'ip route {0}/24 {1}'.format(net, gateway) |
| 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 |
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 |
| 279 | |
| 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 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 291 | def vrouter_configure(cls, networks = 4, peers = 1): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 292 | ##Deactivate vrouter |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 293 | vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers) |
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 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 297 | cls.start_quagga(networks = networks) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 298 | return vrouter_configs |
| 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 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 328 | def vrouter_traffic_verify(self, positive_test = True): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 329 | peers = len(self.peer_list) |
| 330 | egress = peers + 1 |
| 331 | num = 0 |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 332 | num_hosts = 5 if positive_test else 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 333 | for network in self.network_list: |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 334 | num_ips = num_hosts |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 335 | octets = network.split('.') |
| 336 | for i in xrange(num_ips): |
| 337 | octets[-1] = str(int(octets[-1]) + 1) |
| 338 | dst_ip = '.'.join(octets) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 339 | dst_mac = self.peer_list[ num % peers ] [1] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 340 | port = (num % peers) |
| 341 | ingress = port + 1 |
| 342 | #Since peers are on the same network |
| 343 | ##Verify if flows are setup by sending traffic across |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 344 | 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] | 345 | num += 1 |
| 346 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 347 | def __vrouter_network_verify(self, networks, peers = 1, positive_test = True): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 348 | _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 349 | self.cliEnter() |
| 350 | ##Now verify |
| 351 | hosts = json.loads(self.cli.hosts(jsonFormat = True)) |
| 352 | log.info('Discovered hosts: %s' %hosts) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 353 | ##We read from cli if we expect less number of routes to avoid cli timeouts |
| 354 | if networks <= 10000: |
| 355 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 356 | #log.info('Routes: %s' %routes) |
| 357 | assert_equal(len(routes['routes4']), networks) |
| 358 | flows = json.loads(self.cli.flows(jsonFormat = True)) |
| 359 | flows = filter(lambda f: f['flows'], flows) |
| 360 | #log.info('Flows: %s' %flows) |
| 361 | assert_not_equal(len(flows), 0) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 362 | self.vrouter_traffic_verify() |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 363 | if positive_test is False: |
| 364 | self.__vrouter_network_verify_negative(networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 365 | self.cliExit() |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 366 | self.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 367 | return True |
| 368 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 369 | def __vrouter_network_verify_negative(self, networks, peers = 1): |
| 370 | ##Stop quagga. Test traffic again to see if flows were removed |
| 371 | log.info('Stopping Quagga container') |
| 372 | quaggaStop = QuaggaStopWrapper() |
| 373 | time.sleep(2) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 374 | if networks <= 10000: |
| 375 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 376 | #Verify routes have been removed |
| 377 | if routes and routes.has_key('routes4'): |
| 378 | assert_equal(len(routes['routes4']), 0) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 379 | self.vrouter_traffic_verify(positive_test = False) |
| 380 | log.info('OVS flows have been removed successfully after Quagga was stopped') |
| 381 | self.start_quagga(networks = networks) |
| 382 | ##Verify the flows again after restarting quagga back |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 383 | if networks <= 10000: |
| 384 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 385 | assert_equal(len(routes['routes4']), networks) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 386 | self.vrouter_traffic_verify() |
| 387 | log.info('OVS flows have been successfully reinstalled after Quagga was restarted') |
| 388 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 389 | def test_vrouter_1(self): |
| 390 | '''Test vrouter with 5 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 391 | res = self.__vrouter_network_verify(5, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 392 | assert_equal(res, True) |
| 393 | |
| 394 | def test_vrouter_2(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 395 | '''Test vrouter with 5 routes with 2 peers''' |
| 396 | res = self.__vrouter_network_verify(5, peers = 2) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 397 | assert_equal(res, True) |
| 398 | |
| 399 | def test_vrouter_3(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 400 | '''Test vrouter with 6 routes with 3 peers''' |
| 401 | res = self.__vrouter_network_verify(6, peers = 3) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 402 | assert_equal(res, True) |
| 403 | |
| 404 | def test_vrouter_4(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 405 | '''Test vrouter with 50 routes''' |
| 406 | res = self.__vrouter_network_verify(50, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 407 | assert_equal(res, True) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 408 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 409 | def test_vrouter_5(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 410 | '''Test vrouter with 50 routes and 5 peers''' |
| 411 | res = self.__vrouter_network_verify(50, peers = 5) |
| 412 | assert_equal(res, True) |
| 413 | |
| 414 | def test_vrouter_6(self): |
| 415 | '''Test vrouter with 100 routes''' |
| 416 | res = self.__vrouter_network_verify(100, peers = 1) |
| 417 | assert_equal(res, True) |
| 418 | |
| 419 | def test_vrouter_7(self): |
| 420 | '''Test vrouter with 100 routes and 10 peers''' |
| 421 | res = self.__vrouter_network_verify(100, peers = 10) |
| 422 | assert_equal(res, True) |
| 423 | |
| 424 | def test_vrouter_8(self): |
| 425 | '''Test vrouter with 300 routes''' |
| 426 | res = self.__vrouter_network_verify(300, peers = 1) |
| 427 | assert_equal(res, True) |
| 428 | |
| 429 | def test_vrouter_9(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 430 | '''Test vrouter with 1000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 431 | res = self.__vrouter_network_verify(1000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 432 | assert_equal(res, True) |
| 433 | |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 434 | def test_vrouter_10(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 435 | '''Test vrouter with 10000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 436 | res = self.__vrouter_network_verify(10000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 437 | assert_equal(res, True) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 438 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 439 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 440 | def test_vrouter_11(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 441 | '''Test vrouter with 100000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 442 | res = self.__vrouter_network_verify(100000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 443 | assert_equal(res, True) |
| 444 | |
| 445 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 446 | def test_vrouter_12(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 447 | '''Test vrouter with 1000000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 448 | res = self.__vrouter_network_verify(1000000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 449 | assert_equal(res, True) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 450 | |
| 451 | def test_vrouter_13(self): |
| 452 | '''Test vrouter by installing 5 routes, removing Quagga and re-starting Quagga back''' |
| 453 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = False) |
| 454 | |
| 455 | def test_vrouter_14(self): |
| 456 | '''Test vrouter by installing 50 routes, removing Quagga and re-starting Quagga back''' |
| 457 | res = self.__vrouter_network_verify(50, peers = 1, positive_test = False) |