blob: 8e602ee92136ce114c9f80054b5000f5201874e8 [file] [log] [blame]
A R Karthick81acbff2016-06-17 14:45:16 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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 Karthick81acbff2016-06-17 14:45:16 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick81acbff2016-06-17 14:45:16 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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 Gaonker3533faa2016-04-25 17:50:14 -070016import unittest
17from nose.tools import *
18from scapy.all import *
A R Karthickb03cecd2016-07-27 10:27:55 -070019from OnosCtrl import OnosCtrl, get_mac
Chetan Gaonker3533faa2016-04-25 17:50:14 -070020from OltConfig import OltConfig
A R Karthickb03cecd2016-07-27 10:27:55 -070021from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070022from onosclidriver import OnosCliDriver
ChetanGaonker70820bb2016-06-29 18:11:57 -070023#from quaggaclidriver import QuaggaCliDriver
Chetan Gaonker6cf6e472016-04-26 14:41:51 -070024from CordContainer import Container, Onos, Quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -070025from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart, cord_test_quagga_stop, cord_test_quagga_shell
Chetan Gaonker3533faa2016-04-25 17:50:14 -070026from portmaps import g_subscriber_port_map
27import threading
28import time
29import os
30import json
ChetanGaonker70820bb2016-06-29 18:11:57 -070031import pexpect
32
33#from cli import quagga
34#from quagga import *
35#from cli import requires
36#from cli import system
37#from generic import *
38
Chetan Gaonker3533faa2016-04-25 17:50:14 -070039log.setLevel('INFO')
40
Chetan Gaonker3533faa2016-04-25 17:50:14 -070041class vrouter_exchange(unittest.TestCase):
42
43 apps = ('org.onosproject.vrouter', 'org.onosproject.fwd')
44 device_id = 'of:' + get_mac('ovsbr0')
45 vrouter_device_dict = { "devices" : {
46 "{}".format(device_id) : {
47 "basic" : {
48 "driver" : "softrouter"
49 }
50 }
51 },
52 }
53 zebra_conf = '''
54password zebra
55log stdout
56service advanced-vty
57!
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -070058!debug zebra rib
59!debug zebra kernel
60!debug zebra fpm
Chetan Gaonker3533faa2016-04-25 17:50:14 -070061!
62!interface eth1
63! ip address 10.10.0.3/16
64line vty
65 exec-timeout 0 0
66'''
67 test_path = os.path.dirname(os.path.realpath(__file__))
68 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
69 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070070 GATEWAY = '192.168.10.50'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070071 INGRESS_PORT = 1
72 EGRESS_PORT = 2
Chetan Gaonker3533faa2016-04-25 17:50:14 -070073 MAX_PORTS = 100
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070074 peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070075 network_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -070076 network_mask = 24
77 default_routes_address = ('11.10.10.0/24',)
78 default_peer_address = peer_list
79 quagga_ip = os.getenv('QUAGGA_IP')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070080
81 @classmethod
82 def setUpClass(cls):
83 ''' Activate the vrouter apps'''
84 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070085 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070086 if not cls.port_map:
87 cls.port_map = g_subscriber_port_map
Chetan Gaonker3533faa2016-04-25 17:50:14 -070088 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070089 cls.load_device_id()
A R Karthick81acbff2016-06-17 14:45:16 -070090
Chetan Gaonker3533faa2016-04-25 17:50:14 -070091 @classmethod
92 def tearDownClass(cls):
93 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070094 #cls.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070095
A R Karthickb03cecd2016-07-27 10:27:55 -070096 @classmethod
97 def load_device_id(cls):
98 did = OnosCtrl.get_device_id()
99 cls.device_id = did
100 cls.vrouter_device_dict = { "devices" : {
101 "{}".format(did) : {
102 "basic" : {
103 "driver" : "softrouter"
104 }
105 }
106 },
107 }
108
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700109 def cliEnter(self):
110 retries = 0
111 while retries < 3:
112 self.cli = OnosCliDriver(connect = True)
113 if self.cli.handle:
114 break
115 else:
116 retries += 1
117 time.sleep(2)
118
119 def cliExit(self):
120 self.cli.disconnect()
121
122 @classmethod
123 def onos_load_config(cls, config):
124 status, code = OnosCtrl.config(config)
125 if status is False:
126 log.info('JSON request returned status %d' %code)
127 assert_equal(status, True)
128
129 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700130 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
131 route_update = None, router_address = None):
132 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
133 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700134 return vrouter_configs
135 ##ONOS router does not support dynamic reconfigurations
136 #for config in vrouter_configs:
137 # cls.onos_load_config(config)
138 # time.sleep(5)
139
140 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700141 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700142 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700143 peer_info = peer_address if peer_address is not None else cls.peer_list
144
145 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700146 iface = cls.port_map[index]
147 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700148 log.info('Assigning ip %s to interface %s' %(host, iface))
149 config_cmds = ( 'ifconfig {} 0'.format(iface),
150 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700151 'arping -I {0} {1} -c 2'.format(iface, host),
152 )
153 for cmd in config_cmds:
154 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700155
156 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700157 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700158 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700159 peer_info = peer_address if peer_address is not None else cls.peer_list
160
161 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700162 iface = cls.port_map[index]
163 index += 1
164 config_cmds = ('ifconfig {} 0'.format(iface), )
165 for cmd in config_cmds:
166 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700167
168 @classmethod
169 def start_onos(cls, network_cfg = None):
170 if type(network_cfg) is tuple:
171 res = []
172 for v in network_cfg:
173 res += v.items()
174 config = dict(res)
175 else:
176 config = network_cfg
177 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700178 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700179
180 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700181 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700182 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700183 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700184 if networks <= 10000:
185 boot_delay = 25
186 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700187 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
188 n = min(networks/100000, len(delay_map)-1)
189 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700190 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700191
192 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700193 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700194 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700195 if peer_address is None:
196 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
197 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
198 else:
199 ip = peer_address[0][0]
200 start_ip = ip.split('.')
201 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
202 end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700203 local_network = end_peer + 1
204 ports_dict = { 'ports' : {} }
205 interface_list = []
206 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700207 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700208 port_map = ports_dict['ports']
209 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
210 device_port_key = '{0}/{1}'.format(cls.device_id, port)
211 try:
212 interfaces = port_map[device_port_key]['interfaces']
213 except:
214 port_map[device_port_key] = { 'interfaces' : [] }
215 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700216 ip = n + 2
217 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700218 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700219 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
220 mac = RandMAC()._fix()
221 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700222 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700223 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700224 interfaces.append(interface_dict)
225 interface_list.append(interface_dict['name'])
226 else:
227 interfaces[0]['ips'].append(ips)
228 num += 1
229 if num == peers:
230 break
231 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
232 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
233 quagga_router_dict['ospfEnabled'] = True
234 quagga_router_dict['interfaces'] = interface_list
235 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
236
237 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
238 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
239 speaker_dict = {}
240 speaker_dict['name'] = 'bgp{}'.format(peers+1)
241 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
242 speaker_dict['peers'] = peer_list
243 bgp_speakers_list.append(speaker_dict)
244 cls.peer_list = peer_list
245 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
246
247 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700248 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700249 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700250 if router_address is None:
251 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
252 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
253 network_mask = 24
254 else:
255 ip = router_address
256 start_ip = ip.split('.')
257 network_mask = int(start_ip[3].split('/')[1])
258 start_ip[3] = (start_ip[3].split('/'))[0]
259 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
260 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700261 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700262 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700263 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700264 for n in xrange(start_network, end_network, 256):
265 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
266 network_list.append(net)
267 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700268 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700269 net_list.append(net_route)
270 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700271 if num == networks:
272 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700273 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700274 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700275 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700276 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700277 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700278
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700279 @classmethod
280 def vrouter_activate(cls, deactivate = False):
281 app = 'org.onosproject.vrouter'
282 onos_ctrl = OnosCtrl(app)
283 if deactivate is True:
284 onos_ctrl.deactivate()
285 else:
286 onos_ctrl.activate()
287 time.sleep(3)
288
289 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700290 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
291 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
292 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
293 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700294 cls.start_onos(network_cfg = vrouter_configs)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700295 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700296 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700297 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700298 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700299
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700300 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700301 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700302 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700303 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700304 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700305 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700306 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700307 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 Gaonkerb6064fa2016-05-02 16:29:57 -0700310 self.success = True if positive_test else False
311 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700312 lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip,
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700313 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700314 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700315
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 Gaonkerfe551a22016-04-29 17:34:57 -0700322 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700323 while self.start_sending is True:
324 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700325 t.join()
326 assert_equal(self.success, True)
327
ChetanGaonker70820bb2016-06-29 18:11:57 -0700328 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
329 if peer_address is None:
330 peers = len(self.peer_list)
331 peer_list = self.peer_list
332 else:
333 peers = len(peer_address)
334 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700335 egress = peers + 1
336 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700337 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700338 src_mac = '00:00:00:00:00:02'
339 src_ip = '1.1.1.1'
340 if self.network_mask != 24:
341 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700342 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700343 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700344 octets = network.split('.')
345 for i in xrange(num_ips):
346 octets[-1] = str(int(octets[-1]) + 1)
347 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700348 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700349 port = (num % peers)
350 ingress = port + 1
351 #Since peers are on the same network
352 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700353 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700354 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700355
ChetanGaonker70820bb2016-06-29 18:11:57 -0700356 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
357 start_network = None, start_peer_address = None, route_update = None,
358 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
359 deactivate_activate_vrouter = None, adding_new_routes = None):
360
361 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
362 peer_address = start_peer_address,
363 route_update = route_update,
364 router_address = start_network,
365 time_expire = time_expire,
366 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700367 self.cliEnter()
368 ##Now verify
369 hosts = json.loads(self.cli.hosts(jsonFormat = True))
370 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700371 ##We read from cli if we expect less number of routes to avoid cli timeouts
372 if networks <= 10000:
373 routes = json.loads(self.cli.routes(jsonFormat = True))
374 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700375 if start_network is not None:
376 if start_network.split('/')[1] is 24:
377 assert_equal(len(routes['routes4']), networks)
378 if start_network.split('/')[1] is not 24:
379 assert_equal(len(routes['routes4']), 1)
380 if start_network is None and invalid_peers is None:
381 assert_equal(len(routes['routes4']), networks)
382 if invalid_peers is not None:
383 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700384 flows = json.loads(self.cli.flows(jsonFormat = True))
385 flows = filter(lambda f: f['flows'], flows)
386 #log.info('Flows: %s' %flows)
387 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700388 if invalid_peers is None:
389 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700390 if positive_test is False:
391 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700392 if time_expire is True:
393 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
394 self.vrouter_traffic_verify()
395 if unreachable_route_traffic is True:
396 network_list_backup = self.network_list
397 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
398 self.vrouter_traffic_verify(positive_test = False)
399 self.network_list = network_list_backup
400 if deactivate_activate_vrouter is True:
401 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
402 self.vrouter_activate(deactivate = True)
403 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
404 #assert_equal(len(routes['routes4']), 'Command not found')
405 log.info('Activating vrouter app again in ONOS controller for negative scenario')
406 self.vrouter_activate(deactivate = False)
407 routes = json.loads(self.cli.routes(jsonFormat = True))
408 assert_equal(len(routes['routes4']), networks)
409 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700410 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700411 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700412 return True
413
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700414 def __vrouter_network_verify_negative(self, networks, peers = 1):
415 ##Stop quagga. Test traffic again to see if flows were removed
416 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700417 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700418 if networks <= 10000:
419 routes = json.loads(self.cli.routes(jsonFormat = True))
420 #Verify routes have been removed
421 if routes and routes.has_key('routes4'):
422 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700423 self.vrouter_traffic_verify(positive_test = False)
424 log.info('OVS flows have been removed successfully after Quagga was stopped')
425 self.start_quagga(networks = networks)
426 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700427 if networks <= 10000:
428 routes = json.loads(self.cli.routes(jsonFormat = True))
429 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700430 self.vrouter_traffic_verify()
431 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
432
ChetanGaonker70820bb2016-06-29 18:11:57 -0700433 def quagga_shell(self, cmd):
434 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
435 quagga_cmd = ' -c '.join(shell_cmds)
436 return cord_test_quagga_shell(quagga_cmd)
437
438 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700439 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700440 assert_equal(res, True)
441
ChetanGaonker70820bb2016-06-29 18:11:57 -0700442 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700443 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700444 assert_equal(res, True)
445
ChetanGaonker70820bb2016-06-29 18:11:57 -0700446 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700447 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700448 assert_equal(res, True)
449
ChetanGaonker70820bb2016-06-29 18:11:57 -0700450 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700451 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700452 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700453
ChetanGaonker70820bb2016-06-29 18:11:57 -0700454 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700455 res = self.__vrouter_network_verify(50, peers = 5)
456 assert_equal(res, True)
457
ChetanGaonker70820bb2016-06-29 18:11:57 -0700458 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700459 res = self.__vrouter_network_verify(100, peers = 1)
460 assert_equal(res, True)
461
ChetanGaonker70820bb2016-06-29 18:11:57 -0700462 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700463 res = self.__vrouter_network_verify(100, peers = 10)
464 assert_equal(res, True)
465
ChetanGaonker70820bb2016-06-29 18:11:57 -0700466 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700467 res = self.__vrouter_network_verify(300, peers = 1)
468 assert_equal(res, True)
469
ChetanGaonker70820bb2016-06-29 18:11:57 -0700470 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700471 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700472 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700473
ChetanGaonker70820bb2016-06-29 18:11:57 -0700474 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700475 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700476 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700477
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700478 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700479 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700480 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700481 assert_equal(res, True)
482
483 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700484 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700485 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700486 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700487
ChetanGaonker70820bb2016-06-29 18:11:57 -0700488 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700489 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
490
ChetanGaonker70820bb2016-06-29 18:11:57 -0700491 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700492 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700493
494 def test_vrouter_with_route_update(self):
495 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
496 assert_equal(res, True)
497 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
498 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
499 start_peer_address = peer_info, route_update = True)
500 assert_equal(res, True)
501
502 def test_vrouter_with_classA_route_update(self):
503 router_address = '11.10.10.0/8'
504 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
505 assert_equal(res, True)
506
507 def test_vrouter_with_classB_route_update(self):
508 router_address = '11.10.10.0/16'
509 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
510 assert_equal(res, True)
511
512 def test_vrouter_with_classless_route_update(self):
513 router_address = '11.10.10.0/12'
514 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
515 assert_equal(res, True)
516
517 def test_vrouter_with_classA_duplicate_route_update(self):
518 router_address = '11.10.10.0/8'
519 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
520 assert_equal(res, True)
521
522 def test_vrouter_with_classB_duplicate_route_update(self):
523 router_address = '11.10.10.0/16'
524 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
525 assert_equal(res, True)
526
527 def test_vrouter_with_classless_duplicate_route_update(self):
528 router_address = '11.10.10.0/12'
529 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
530 assert_equal(res, True)
531
532 def test_vrouter_with_invalid_peers(self):
533 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
534 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
535 start_peer_address = peer_info, invalid_peers= True)
536 assert_equal(res, True)
537
538 @nottest
539 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
540 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
541 assert_equal(res, True)
542
543 @nottest
544 def test_vrouter_with_routes_time_expire(self):
545 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
546 assert_equal(res, True)
547
548 def test_vrouter_with_unreachable_route(self):
549 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
550 assert_equal(res, True)
551
552 @nottest
553 def test_vrouter_with_enabling_disabling_vrouter_app(self):
554 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
555 assert_equal(res, True)
556
557 def test_vrouter_with_adding_new_routes_in_routing_table(self):
558 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
559 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
560 self.quagga_shell(cmd)
561 self.vrouter_traffic_verify()
562 self.network_list = [ '21.10.20.0' ]
563 self.network_mask = 24
564 self.vrouter_traffic_verify()
565 assert_equal(res, True)
566
567 def test_vrouter_with_removing_old_routes_in_routing_table(self):
568 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
569 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
570 self.quagga_shell(cmd)
571 self.vrouter_traffic_verify()
572 old_network_list = self.network_list
573 old_network_mask = self.network_mask
574 self.network_list = [ '21.10.20.0' ]
575 self.network_mask = 24
576 self.vrouter_traffic_verify()
577 assert_equal(res, True)
578 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
579 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700580 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700581 self.vrouter_traffic_verify(positive_test = False)
582 self.network_mask = old_network_mask
583 self.network_list = old_network_list
584 self.vrouter_traffic_verify(positive_test = True)
585
586 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
587 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
588 router_address = '11.10.10.0/24'
589 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
590 start_peer_address = peer_info, start_network = router_address)
591 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
592 self.quagga_shell(cmd)
593 self.vrouter_traffic_verify(positive_test = True)
594 assert_equal(res, True)
595
596
597 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
598 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
599 router_address = '11.10.10.0/24'
600 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
601 start_peer_address = peer_info, start_network = router_address)
602 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
603 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700604 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700605 self.vrouter_traffic_verify(positive_test = False)
606 assert_equal(res, True)
607
608 def test_vrouter_deleting_some_routes_in_routing_table(self):
609 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
610 router_address = '11.10.10.0/24'
611 res = self.__vrouter_network_verify(10, peers = 2, positive_test = True,
612 start_peer_address = peer_info, start_network = router_address)
613 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
614 self.quagga_shell(cmd)
615 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
616 self.quagga_shell(cmd)
617 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
618 self.quagga_shell(cmd)
619 self.vrouter_traffic_verify(positive_test = True)
620 assert_equal(res, True)
621
622
623 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
624 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
625 router_address = '11.10.10.0/24'
626 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
627 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
628 self.quagga_shell(cmd)
629 cmd = 'ip route 11.10.10.0/24 192.168.10.1'
630 self.quagga_shell(cmd)
631 self.vrouter_traffic_verify(positive_test = True)
632 assert_equal(res, True)
633
634 def test_vrouter_toggling_nexthop_interface(self):
635 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
636 router_address = '11.10.10.0/24'
637 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
A R Karthicka93829a2016-07-01 10:08:23 -0700638 iface = self.port_map[1]
639 #toggle the interface to trigger host removal.
640 cmds = ('ifconfig {} down'.format(iface),
641 'sleep 2',
642 'ifconfig {} 0'.format(iface),)
643 for cmd in cmds:
644 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700645 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700646 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700647 cmd = 'ifconfig {0} {1} up'.format(iface, host)
648 os.system(cmd)
649 #wait for arp refresh
650 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700651 self.vrouter_traffic_verify(positive_test = True)
652 assert_equal(res, True)
653
654
655