Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 1 | import unittest |
| 2 | from nose.tools import * |
| 3 | from scapy.all import * |
| 4 | from OnosCtrl import OnosCtrl |
| 5 | from OltConfig import OltConfig |
| 6 | from OnosFlowCtrl import OnosFlowCtrl, get_mac |
| 7 | from onosclidriver import OnosCliDriver |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 8 | from CordContainer import Container, Onos, Quagga |
| 9 | from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 10 | from portmaps import g_subscriber_port_map |
| 11 | import threading |
| 12 | import time |
| 13 | import os |
| 14 | import json |
| 15 | log.setLevel('INFO') |
| 16 | |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 17 | class QuaggaStopWrapper(Container): |
| 18 | |
| 19 | def __init__(self, name = 'cord-quagga', image = 'cord-test/quagga', tag = 'latest'): |
| 20 | super(QuaggaStopWrapper, self).__init__(name, image, tag = tag) |
| 21 | if self.exists(): |
| 22 | self.kill() |
| 23 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 24 | class vrouter_exchange(unittest.TestCase): |
| 25 | |
| 26 | apps = ('org.onosproject.vrouter', 'org.onosproject.fwd') |
| 27 | device_id = 'of:' + get_mac('ovsbr0') |
| 28 | vrouter_device_dict = { "devices" : { |
| 29 | "{}".format(device_id) : { |
| 30 | "basic" : { |
| 31 | "driver" : "softrouter" |
| 32 | } |
| 33 | } |
| 34 | }, |
| 35 | } |
| 36 | zebra_conf = ''' |
| 37 | password zebra |
| 38 | log stdout |
| 39 | service advanced-vty |
| 40 | ! |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 41 | !debug zebra rib |
| 42 | !debug zebra kernel |
| 43 | !debug zebra fpm |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 44 | ! |
| 45 | !interface eth1 |
| 46 | ! ip address 10.10.0.3/16 |
| 47 | line vty |
| 48 | exec-timeout 0 0 |
| 49 | ''' |
| 50 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 51 | quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config') |
| 52 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 53 | GATEWAY = '192.168.10.50' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 54 | INGRESS_PORT = 1 |
| 55 | EGRESS_PORT = 2 |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 56 | MAX_PORTS = 100 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 57 | 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] | 58 | network_list = [] |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 59 | |
| 60 | @classmethod |
| 61 | def setUpClass(cls): |
| 62 | ''' Activate the vrouter apps''' |
| 63 | cls.olt = OltConfig() |
| 64 | cls.port_map = cls.olt.olt_port_map() |
| 65 | if not cls.port_map: |
| 66 | cls.port_map = g_subscriber_port_map |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 67 | #cls.vrouter_host_load(host = cls.GATEWAY) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 68 | time.sleep(3) |
| 69 | |
| 70 | @classmethod |
| 71 | def tearDownClass(cls): |
| 72 | '''Deactivate the vrouter apps''' |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 73 | #cls.vrouter_host_unload() |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 74 | |
| 75 | def cliEnter(self): |
| 76 | retries = 0 |
| 77 | while retries < 3: |
| 78 | self.cli = OnosCliDriver(connect = True) |
| 79 | if self.cli.handle: |
| 80 | break |
| 81 | else: |
| 82 | retries += 1 |
| 83 | time.sleep(2) |
| 84 | |
| 85 | def cliExit(self): |
| 86 | self.cli.disconnect() |
| 87 | |
| 88 | @classmethod |
| 89 | def onos_load_config(cls, config): |
| 90 | status, code = OnosCtrl.config(config) |
| 91 | if status is False: |
| 92 | log.info('JSON request returned status %d' %code) |
| 93 | assert_equal(status, True) |
| 94 | |
| 95 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 96 | def vrouter_config_get(cls, networks = 4, peers = 1): |
| 97 | vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 98 | return vrouter_configs |
| 99 | ##ONOS router does not support dynamic reconfigurations |
| 100 | #for config in vrouter_configs: |
| 101 | # cls.onos_load_config(config) |
| 102 | # time.sleep(5) |
| 103 | |
| 104 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 105 | def vrouter_host_load(cls): |
| 106 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 107 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 108 | iface = cls.port_map[index] |
| 109 | index += 1 |
| 110 | config_cmds = ( 'ifconfig {0} {1}'.format(iface, host), |
| 111 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 112 | ) |
| 113 | for cmd in config_cmds: |
| 114 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 115 | |
| 116 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 117 | def vrouter_host_unload(cls): |
| 118 | index = 1 |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 119 | for host,_ in cls.peer_list: |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 120 | iface = cls.port_map[index] |
| 121 | index += 1 |
| 122 | config_cmds = ('ifconfig {} 0'.format(iface), ) |
| 123 | for cmd in config_cmds: |
| 124 | os.system(cmd) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 125 | |
| 126 | @classmethod |
| 127 | def start_onos(cls, network_cfg = None): |
| 128 | if type(network_cfg) is tuple: |
| 129 | res = [] |
| 130 | for v in network_cfg: |
| 131 | res += v.items() |
| 132 | config = dict(res) |
| 133 | else: |
| 134 | config = network_cfg |
| 135 | log.info('Restarting ONOS with new network configuration') |
| 136 | cfg = json.dumps(config) |
| 137 | with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f: |
| 138 | f.write(cfg) |
| 139 | |
| 140 | return cord_test_onos_restart() |
| 141 | |
| 142 | @classmethod |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 143 | def start_quagga(cls, networks = 4): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 144 | log.info('Restarting Quagga container with configuration for %d networks' %(networks)) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 145 | config = cls.generate_conf(networks = networks) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 146 | host_config_file = '{}/testrib_gen.conf'.format(Quagga.host_quagga_config) |
| 147 | guest_config_file = os.path.join(Quagga.guest_quagga_config, 'testrib_gen.conf') |
| 148 | with open(host_config_file, 'w') as f: |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 149 | f.write(config) |
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] |
Chetan Gaonker | fd3d650 | 2016-05-03 13:23:07 -0700 | [diff] [blame] | 156 | 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] | 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'] |
| 175 | |
| 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 |
| 190 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, |
| 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 |
| 264 | |
| 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 |
| 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 |
| 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') |
| 357 | quaggaStop = QuaggaStopWrapper() |
| 358 | time.sleep(2) |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 359 | if networks <= 10000: |
| 360 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 361 | #Verify routes have been removed |
| 362 | if routes and routes.has_key('routes4'): |
| 363 | assert_equal(len(routes['routes4']), 0) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 364 | self.vrouter_traffic_verify(positive_test = False) |
| 365 | log.info('OVS flows have been removed successfully after Quagga was stopped') |
| 366 | self.start_quagga(networks = networks) |
| 367 | ##Verify the flows again after restarting quagga back |
Chetan Gaonker | 68d9517 | 2016-05-03 11:16:59 -0700 | [diff] [blame] | 368 | if networks <= 10000: |
| 369 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 370 | assert_equal(len(routes['routes4']), networks) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 371 | self.vrouter_traffic_verify() |
| 372 | log.info('OVS flows have been successfully reinstalled after Quagga was restarted') |
| 373 | |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 374 | def test_vrouter_1(self): |
| 375 | '''Test vrouter with 5 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 376 | res = self.__vrouter_network_verify(5, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 377 | assert_equal(res, True) |
| 378 | |
| 379 | def test_vrouter_2(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 380 | '''Test vrouter with 5 routes with 2 peers''' |
| 381 | res = self.__vrouter_network_verify(5, peers = 2) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 382 | assert_equal(res, True) |
| 383 | |
| 384 | def test_vrouter_3(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 385 | '''Test vrouter with 6 routes with 3 peers''' |
| 386 | res = self.__vrouter_network_verify(6, peers = 3) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 387 | assert_equal(res, True) |
| 388 | |
| 389 | def test_vrouter_4(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 390 | '''Test vrouter with 50 routes''' |
| 391 | res = self.__vrouter_network_verify(50, peers = 1) |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 392 | assert_equal(res, True) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 393 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 394 | def test_vrouter_5(self): |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 395 | '''Test vrouter with 50 routes and 5 peers''' |
| 396 | res = self.__vrouter_network_verify(50, peers = 5) |
| 397 | assert_equal(res, True) |
| 398 | |
| 399 | def test_vrouter_6(self): |
| 400 | '''Test vrouter with 100 routes''' |
| 401 | res = self.__vrouter_network_verify(100, peers = 1) |
| 402 | assert_equal(res, True) |
| 403 | |
| 404 | def test_vrouter_7(self): |
| 405 | '''Test vrouter with 100 routes and 10 peers''' |
| 406 | res = self.__vrouter_network_verify(100, peers = 10) |
| 407 | assert_equal(res, True) |
| 408 | |
| 409 | def test_vrouter_8(self): |
| 410 | '''Test vrouter with 300 routes''' |
| 411 | res = self.__vrouter_network_verify(300, peers = 1) |
| 412 | assert_equal(res, True) |
| 413 | |
| 414 | def test_vrouter_9(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 415 | '''Test vrouter with 1000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 416 | res = self.__vrouter_network_verify(1000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 417 | assert_equal(res, True) |
| 418 | |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 419 | def test_vrouter_10(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 420 | '''Test vrouter with 10000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 421 | res = self.__vrouter_network_verify(10000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 422 | assert_equal(res, True) |
Chetan Gaonker | fe551a2 | 2016-04-29 17:34:57 -0700 | [diff] [blame] | 423 | |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 424 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 425 | def test_vrouter_11(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 426 | '''Test vrouter with 100000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 427 | res = self.__vrouter_network_verify(100000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 428 | assert_equal(res, True) |
| 429 | |
| 430 | @nottest |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 431 | def test_vrouter_12(self): |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 432 | '''Test vrouter with 1000000 routes''' |
Chetan Gaonker | 8e25e1b | 2016-05-02 13:42:21 -0700 | [diff] [blame] | 433 | res = self.__vrouter_network_verify(1000000, peers = 1) |
Chetan Gaonker | 6cf6e47 | 2016-04-26 14:41:51 -0700 | [diff] [blame] | 434 | assert_equal(res, True) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 435 | |
| 436 | def test_vrouter_13(self): |
| 437 | '''Test vrouter by installing 5 routes, removing Quagga and re-starting Quagga back''' |
| 438 | res = self.__vrouter_network_verify(5, peers = 1, positive_test = False) |
| 439 | |
| 440 | def test_vrouter_14(self): |
| 441 | '''Test vrouter by installing 50 routes, removing Quagga and re-starting Quagga back''' |
| 442 | res = self.__vrouter_network_verify(50, peers = 1, positive_test = False) |