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