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 * |
| 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 |
A R Karthick | 4a2362c | 2016-06-22 17:32:44 -0700 | [diff] [blame] | 24 | from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart, cord_test_quagga_stop |
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 | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 32 | class vrouter_exchange(unittest.TestCase): |
| 33 | |
| 34 | apps = ('org.onosproject.vrouter', 'org.onosproject.fwd') |
| 35 | device_id = 'of:' + get_mac('ovsbr0') |
| 36 | vrouter_device_dict = { "devices" : { |
| 37 | "{}".format(device_id) : { |
| 38 | "basic" : { |
| 39 | "driver" : "softrouter" |
| 40 | } |
| 41 | } |
| 42 | }, |
| 43 | } |
| 44 | zebra_conf = ''' |
| 45 | password zebra |
| 46 | log stdout |
| 47 | service advanced-vty |
| 48 | ! |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 49 | !debug zebra rib |
| 50 | !debug zebra kernel |
| 51 | !debug zebra fpm |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 52 | ! |
| 53 | !interface eth1 |
| 54 | ! ip address 10.10.0.3/16 |
| 55 | line vty |
| 56 | exec-timeout 0 0 |
| 57 | ''' |
| 58 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 59 | quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config') |
| 60 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 61 | GATEWAY = '192.168.10.50' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 62 | INGRESS_PORT = 1 |
| 63 | EGRESS_PORT = 2 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 64 | MAX_PORTS = 100 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 65 | 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] | 66 | network_list = [] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 67 | |
| 68 | @classmethod |
| 69 | def setUpClass(cls): |
| 70 | ''' Activate the vrouter apps''' |
| 71 | cls.olt = OltConfig() |
| 72 | cls.port_map = cls.olt.olt_port_map() |
| 73 | if not cls.port_map: |
| 74 | cls.port_map = g_subscriber_port_map |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 75 | #cls.vrouter_host_load(host = cls.GATEWAY) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 76 | time.sleep(3) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 77 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 78 | @classmethod |
| 79 | def tearDownClass(cls): |
| 80 | '''Deactivate the vrouter apps''' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 81 | #cls.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 82 | |
| 83 | def cliEnter(self): |
| 84 | retries = 0 |
| 85 | while retries < 3: |
| 86 | self.cli = OnosCliDriver(connect = True) |
| 87 | if self.cli.handle: |
| 88 | break |
| 89 | else: |
| 90 | retries += 1 |
| 91 | time.sleep(2) |
| 92 | |
| 93 | def cliExit(self): |
| 94 | self.cli.disconnect() |
| 95 | |
| 96 | @classmethod |
| 97 | def onos_load_config(cls, config): |
| 98 | status, code = OnosCtrl.config(config) |
| 99 | if status is False: |
| 100 | log.info('JSON request returned status %d' %code) |
| 101 | assert_equal(status, True) |
| 102 | |
| 103 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 104 | def vrouter_config_get(cls, networks = 4, peers = 1): |
| 105 | vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 106 | return vrouter_configs |
| 107 | ##ONOS router does not support dynamic reconfigurations |
| 108 | #for config in vrouter_configs: |
| 109 | # cls.onos_load_config(config) |
| 110 | # time.sleep(5) |
| 111 | |
| 112 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 113 | def vrouter_host_load(cls): |
| 114 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 115 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 116 | iface = cls.port_map[index] |
| 117 | index += 1 |
| 118 | config_cmds = ( 'ifconfig {0} {1}'.format(iface, host), |
| 119 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 120 | ) |
| 121 | for cmd in config_cmds: |
| 122 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 123 | |
| 124 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 125 | def vrouter_host_unload(cls): |
| 126 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 127 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 128 | iface = cls.port_map[index] |
| 129 | index += 1 |
| 130 | config_cmds = ('ifconfig {} 0'.format(iface), ) |
| 131 | for cmd in config_cmds: |
| 132 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 133 | |
| 134 | @classmethod |
| 135 | def start_onos(cls, network_cfg = None): |
| 136 | if type(network_cfg) is tuple: |
| 137 | res = [] |
| 138 | for v in network_cfg: |
| 139 | res += v.items() |
| 140 | config = dict(res) |
| 141 | else: |
| 142 | config = network_cfg |
| 143 | log.info('Restarting ONOS with new network configuration') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 144 | return cord_test_onos_restart(config = config) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 145 | |
| 146 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 147 | def start_quagga(cls, networks = 4): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 148 | log.info('Restarting Quagga container with configuration for %d networks' %(networks)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 149 | config = cls.generate_conf(networks = networks) |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 150 | if networks <= 10000: |
| 151 | boot_delay = 25 |
| 152 | else: |
Chetan Gaonker | 37ad23f | 2016-05-03 17:37:59 -0700 | [diff] [blame] | 153 | delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200] |
| 154 | n = min(networks/100000, len(delay_map)-1) |
| 155 | boot_delay = delay_map[n] |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 156 | cord_test_quagga_restart(config = config, boot_delay = boot_delay) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 157 | |
| 158 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 159 | def zgenerate_vrouter_conf(cls, networks = 4): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 160 | num = 0 |
| 161 | start_network = ( 11 << 24) | ( 0 << 16) | ( 0 << 8) | 0 |
| 162 | end_network = ( 200 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
| 163 | ports_dict = { 'ports' : {} } |
| 164 | interface_list = [] |
| 165 | for n in xrange(start_network, end_network): |
| 166 | if n & 255 == 0: |
| 167 | port_map = ports_dict['ports'] |
| 168 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 169 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 170 | try: |
| 171 | interfaces = port_map[device_port_key]['interfaces'] |
| 172 | except: |
| 173 | port_map[device_port_key] = { 'interfaces' : [] } |
| 174 | interfaces = port_map[device_port_key]['interfaces'] |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 175 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 176 | ips = '%d.%d.%d.2/24'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) ) |
| 177 | if num < cls.MAX_PORTS - 1: |
| 178 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : '00:00:00:00:00:01' } |
| 179 | interfaces.append(interface_dict) |
| 180 | interface_list.append(interface_dict['name']) |
| 181 | else: |
| 182 | interfaces[0]['ips'].append(ips) |
| 183 | num += 1 |
| 184 | if num == networks: |
| 185 | break |
| 186 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {} } } } |
| 187 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 188 | quagga_router_dict['ospfEnabled'] = True |
| 189 | quagga_router_dict['interfaces'] = interface_list |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 190 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 191 | networks + 1 if networks < cls.MAX_PORTS else cls.MAX_PORTS ) |
| 192 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 193 | |
| 194 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 195 | def generate_vrouter_conf(cls, networks = 4, peers = 1): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 196 | num = 0 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 197 | start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0 |
| 198 | end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 199 | local_network = end_peer + 1 |
| 200 | ports_dict = { 'ports' : {} } |
| 201 | interface_list = [] |
| 202 | peer_list = [] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 203 | for n in xrange(start_peer, end_peer, 256): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 204 | port_map = ports_dict['ports'] |
| 205 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 206 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 207 | try: |
| 208 | interfaces = port_map[device_port_key]['interfaces'] |
| 209 | except: |
| 210 | port_map[device_port_key] = { 'interfaces' : [] } |
| 211 | interfaces = port_map[device_port_key]['interfaces'] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 212 | ip = n + 2 |
| 213 | peer_ip = n + 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 214 | 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] | 215 | peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff ) |
| 216 | mac = RandMAC()._fix() |
| 217 | peer_list.append((peer, mac)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 218 | if num < cls.MAX_PORTS - 1: |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 219 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac } |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 220 | interfaces.append(interface_dict) |
| 221 | interface_list.append(interface_dict['name']) |
| 222 | else: |
| 223 | interfaces[0]['ips'].append(ips) |
| 224 | num += 1 |
| 225 | if num == peers: |
| 226 | break |
| 227 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 228 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 229 | quagga_router_dict['ospfEnabled'] = True |
| 230 | quagga_router_dict['interfaces'] = interface_list |
| 231 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 232 | |
| 233 | #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 234 | bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers'] |
| 235 | speaker_dict = {} |
| 236 | speaker_dict['name'] = 'bgp{}'.format(peers+1) |
| 237 | speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 238 | speaker_dict['peers'] = peer_list |
| 239 | bgp_speakers_list.append(speaker_dict) |
| 240 | cls.peer_list = peer_list |
| 241 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 242 | |
| 243 | @classmethod |
| 244 | def generate_conf(cls, networks = 4): |
| 245 | num = 0 |
| 246 | start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0 |
| 247 | end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 248 | net_list = [] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 249 | peer_list = cls.peer_list |
| 250 | network_list = [] |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 251 | for n in xrange(start_network, end_network, 256): |
| 252 | net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) ) |
| 253 | network_list.append(net) |
| 254 | gateway = peer_list[num % len(peer_list)][0] |
| 255 | net_route = 'ip route {0}/24 {1}'.format(net, gateway) |
| 256 | net_list.append(net_route) |
| 257 | num += 1 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 258 | if num == networks: |
| 259 | break |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 260 | cls.network_list = network_list |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 261 | zebra_routes = '\n'.join(net_list) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 262 | #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 263 | return cls.zebra_conf + zebra_routes |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 264 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 265 | @classmethod |
| 266 | def vrouter_activate(cls, deactivate = False): |
| 267 | app = 'org.onosproject.vrouter' |
| 268 | onos_ctrl = OnosCtrl(app) |
| 269 | if deactivate is True: |
| 270 | onos_ctrl.deactivate() |
| 271 | else: |
| 272 | onos_ctrl.activate() |
| 273 | time.sleep(3) |
| 274 | |
| 275 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 276 | def vrouter_configure(cls, networks = 4, peers = 1): |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 277 | ##Deactivate vrouter |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 278 | vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers) |
Chetan Gaonker | 46b62d5 | 2016-04-26 10:08:42 -0700 | [diff] [blame] | 279 | cls.start_onos(network_cfg = vrouter_configs) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 280 | cls.vrouter_host_load() |
Chetan Gaonker | 02236ba | 2016-04-26 11:24:34 -0700 | [diff] [blame] | 281 | ##Start quagga |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 282 | cls.start_quagga(networks = networks) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 283 | return vrouter_configs |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 284 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 285 | 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] | 286 | src_mac = '00:00:00:00:00:02' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 287 | src_ip = '1.1.1.1' |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 288 | self.success = False if positive_test else True |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 289 | timeout = 10 if positive_test else 1 |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 290 | count = 2 if positive_test else 1 |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 291 | self.start_sending = True |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 292 | def recv_task(): |
| 293 | def recv_cb(pkt): |
| 294 | 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] | 295 | self.success = True if positive_test else False |
| 296 | sniff(count=count, timeout=timeout, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 297 | 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] | 298 | prn = recv_cb, iface = self.port_map[ingress]) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 299 | self.start_sending = False |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 300 | |
| 301 | t = threading.Thread(target = recv_task) |
| 302 | t.start() |
| 303 | L2 = Ether(src = src_mac, dst = dst_mac) |
| 304 | L3 = IP(src = src_ip, dst = dst_ip) |
| 305 | pkt = L2/L3 |
| 306 | 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] | 307 | (dst_ip, dst_mac, self.port_map[egress])) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 308 | while self.start_sending is True: |
| 309 | sendp(pkt, count=50, iface = self.port_map[egress]) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 310 | t.join() |
| 311 | assert_equal(self.success, True) |
| 312 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 313 | def vrouter_traffic_verify(self, positive_test = True): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 314 | peers = len(self.peer_list) |
| 315 | egress = peers + 1 |
| 316 | num = 0 |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 317 | num_hosts = 5 if positive_test else 1 |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 318 | for network in self.network_list: |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 319 | num_ips = num_hosts |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 320 | octets = network.split('.') |
| 321 | for i in xrange(num_ips): |
| 322 | octets[-1] = str(int(octets[-1]) + 1) |
| 323 | dst_ip = '.'.join(octets) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 324 | dst_mac = self.peer_list[ num % peers ] [1] |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 325 | port = (num % peers) |
| 326 | ingress = port + 1 |
| 327 | #Since peers are on the same network |
| 328 | ##Verify if flows are setup by sending traffic across |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 329 | 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] | 330 | num += 1 |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 331 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 332 | def __vrouter_network_verify(self, networks, peers = 1, positive_test = True): |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 333 | _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 334 | self.cliEnter() |
| 335 | ##Now verify |
| 336 | hosts = json.loads(self.cli.hosts(jsonFormat = True)) |
| 337 | log.info('Discovered hosts: %s' %hosts) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 338 | ##We read from cli if we expect less number of routes to avoid cli timeouts |
| 339 | if networks <= 10000: |
| 340 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 341 | #log.info('Routes: %s' %routes) |
| 342 | assert_equal(len(routes['routes4']), networks) |
| 343 | flows = json.loads(self.cli.flows(jsonFormat = True)) |
| 344 | flows = filter(lambda f: f['flows'], flows) |
| 345 | #log.info('Flows: %s' %flows) |
| 346 | assert_not_equal(len(flows), 0) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 347 | self.vrouter_traffic_verify() |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 348 | if positive_test is False: |
| 349 | self.__vrouter_network_verify_negative(networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 350 | self.cliExit() |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 351 | self.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 352 | return True |
| 353 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 354 | def __vrouter_network_verify_negative(self, networks, peers = 1): |
| 355 | ##Stop quagga. Test traffic again to see if flows were removed |
| 356 | log.info('Stopping Quagga container') |
A R Karthick | 4a2362c | 2016-06-22 17:32:44 -0700 | [diff] [blame] | 357 | cord_test_quagga_stop() |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 358 | if networks <= 10000: |
| 359 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 360 | #Verify routes have been removed |
| 361 | if routes and routes.has_key('routes4'): |
| 362 | assert_equal(len(routes['routes4']), 0) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 363 | self.vrouter_traffic_verify(positive_test = False) |
| 364 | log.info('OVS flows have been removed successfully after Quagga was stopped') |
| 365 | self.start_quagga(networks = networks) |
| 366 | ##Verify the flows again after restarting quagga back |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 367 | if networks <= 10000: |
| 368 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 369 | assert_equal(len(routes['routes4']), networks) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 370 | self.vrouter_traffic_verify() |
| 371 | log.info('OVS flows have been successfully reinstalled after Quagga was restarted') |
| 372 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 373 | def test_vrouter_1(self): |
| 374 | '''Test vrouter with 5 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 375 | res = self.__vrouter_network_verify(5, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 376 | assert_equal(res, True) |
| 377 | |
| 378 | def test_vrouter_2(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 379 | '''Test vrouter with 5 routes with 2 peers''' |
| 380 | res = self.__vrouter_network_verify(5, peers = 2) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 381 | assert_equal(res, True) |
| 382 | |
| 383 | def test_vrouter_3(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 384 | '''Test vrouter with 6 routes with 3 peers''' |
| 385 | res = self.__vrouter_network_verify(6, peers = 3) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 386 | assert_equal(res, True) |
| 387 | |
| 388 | def test_vrouter_4(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 389 | '''Test vrouter with 50 routes''' |
| 390 | res = self.__vrouter_network_verify(50, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 391 | assert_equal(res, True) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 392 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 393 | def test_vrouter_5(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 394 | '''Test vrouter with 50 routes and 5 peers''' |
| 395 | res = self.__vrouter_network_verify(50, peers = 5) |
| 396 | assert_equal(res, True) |
| 397 | |
| 398 | def test_vrouter_6(self): |
| 399 | '''Test vrouter with 100 routes''' |
| 400 | res = self.__vrouter_network_verify(100, peers = 1) |
| 401 | assert_equal(res, True) |
| 402 | |
| 403 | def test_vrouter_7(self): |
| 404 | '''Test vrouter with 100 routes and 10 peers''' |
| 405 | res = self.__vrouter_network_verify(100, peers = 10) |
| 406 | assert_equal(res, True) |
| 407 | |
| 408 | def test_vrouter_8(self): |
| 409 | '''Test vrouter with 300 routes''' |
| 410 | res = self.__vrouter_network_verify(300, peers = 1) |
| 411 | assert_equal(res, True) |
| 412 | |
| 413 | def test_vrouter_9(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 414 | '''Test vrouter with 1000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 415 | res = self.__vrouter_network_verify(1000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 416 | assert_equal(res, True) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 417 | |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 418 | def test_vrouter_10(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 419 | '''Test vrouter with 10000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 420 | res = self.__vrouter_network_verify(10000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 421 | assert_equal(res, True) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 422 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 423 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 424 | def test_vrouter_11(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 425 | '''Test vrouter with 100000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 426 | res = self.__vrouter_network_verify(100000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 427 | assert_equal(res, True) |
| 428 | |
| 429 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 430 | def test_vrouter_12(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 431 | '''Test vrouter with 1000000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 432 | res = self.__vrouter_network_verify(1000000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 433 | assert_equal(res, True) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 434 | |
| 435 | def test_vrouter_13(self): |
| 436 | '''Test vrouter by installing 5 routes, removing Quagga and re-starting Quagga back''' |
| 437 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = False) |
| 438 | |
| 439 | def test_vrouter_14(self): |
| 440 | '''Test vrouter by installing 50 routes, removing Quagga and re-starting Quagga back''' |
| 441 | res = self.__vrouter_network_verify(50, peers = 1, positive_test = False) |