blob: b69bf5cd1ee04374c0b64e259ff31632918e525e [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 *
19from OnosCtrl import OnosCtrl
20from OltConfig import OltConfig
21from OnosFlowCtrl import OnosFlowCtrl, get_mac
22from 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()
85 cls.port_map = cls.olt.olt_port_map()
86 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 Karthick81acbff2016-06-17 14:45:16 -070089
Chetan Gaonker3533faa2016-04-25 17:50:14 -070090 @classmethod
91 def tearDownClass(cls):
92 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070093 #cls.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070094
95 def cliEnter(self):
96 retries = 0
97 while retries < 3:
98 self.cli = OnosCliDriver(connect = True)
99 if self.cli.handle:
100 break
101 else:
102 retries += 1
103 time.sleep(2)
104
105 def cliExit(self):
106 self.cli.disconnect()
107
108 @classmethod
109 def onos_load_config(cls, config):
110 status, code = OnosCtrl.config(config)
111 if status is False:
112 log.info('JSON request returned status %d' %code)
113 assert_equal(status, True)
114
115 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700116 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
117 route_update = None, router_address = None):
118 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
119 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700120 return vrouter_configs
121 ##ONOS router does not support dynamic reconfigurations
122 #for config in vrouter_configs:
123 # cls.onos_load_config(config)
124 # time.sleep(5)
125
126 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700127 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700128 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700129 peer_info = peer_address if peer_address is not None else cls.peer_list
130
131 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700132 iface = cls.port_map[index]
133 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700134 log.info('Assigning ip %s to interface %s' %(host, iface))
135 config_cmds = ( 'ifconfig {} 0'.format(iface),
136 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700137 'arping -I {0} {1} -c 2'.format(iface, host),
138 )
139 for cmd in config_cmds:
140 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700141
142 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700143 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700144 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700145 peer_info = peer_address if peer_address is not None else cls.peer_list
146
147 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700148 iface = cls.port_map[index]
149 index += 1
150 config_cmds = ('ifconfig {} 0'.format(iface), )
151 for cmd in config_cmds:
152 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700153
154 @classmethod
155 def start_onos(cls, network_cfg = None):
156 if type(network_cfg) is tuple:
157 res = []
158 for v in network_cfg:
159 res += v.items()
160 config = dict(res)
161 else:
162 config = network_cfg
163 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700164 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700165
166 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700167 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700168 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700169 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700170 if networks <= 10000:
171 boot_delay = 25
172 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700173 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
174 n = min(networks/100000, len(delay_map)-1)
175 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700176 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700177
178 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700179 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700180 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700181 if peer_address is None:
182 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
183 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
184 else:
185 ip = peer_address[0][0]
186 start_ip = ip.split('.')
187 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
188 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 -0700189 local_network = end_peer + 1
190 ports_dict = { 'ports' : {} }
191 interface_list = []
192 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700193 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700194 port_map = ports_dict['ports']
195 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
196 device_port_key = '{0}/{1}'.format(cls.device_id, port)
197 try:
198 interfaces = port_map[device_port_key]['interfaces']
199 except:
200 port_map[device_port_key] = { 'interfaces' : [] }
201 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700202 ip = n + 2
203 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700204 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700205 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
206 mac = RandMAC()._fix()
207 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700208 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700209 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700210 interfaces.append(interface_dict)
211 interface_list.append(interface_dict['name'])
212 else:
213 interfaces[0]['ips'].append(ips)
214 num += 1
215 if num == peers:
216 break
217 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
218 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
219 quagga_router_dict['ospfEnabled'] = True
220 quagga_router_dict['interfaces'] = interface_list
221 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
222
223 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
224 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
225 speaker_dict = {}
226 speaker_dict['name'] = 'bgp{}'.format(peers+1)
227 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
228 speaker_dict['peers'] = peer_list
229 bgp_speakers_list.append(speaker_dict)
230 cls.peer_list = peer_list
231 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
232
233 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700234 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700235 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700236 if router_address is None:
237 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
238 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
239 network_mask = 24
240 else:
241 ip = router_address
242 start_ip = ip.split('.')
243 network_mask = int(start_ip[3].split('/')[1])
244 start_ip[3] = (start_ip[3].split('/'))[0]
245 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
246 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700247 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700248 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700249 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700250 for n in xrange(start_network, end_network, 256):
251 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
252 network_list.append(net)
253 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700254 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700255 net_list.append(net_route)
256 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700257 if num == networks:
258 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700259 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700260 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700261 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700262 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700263 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700264
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700265 @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
ChetanGaonker70820bb2016-06-29 18:11:57 -0700276 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
277 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
278 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
279 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700280 cls.start_onos(network_cfg = vrouter_configs)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700281 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700282 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700283 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700284 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700285
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700286 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700287 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700288 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700289 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700290 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700291 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700292 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700293 def recv_task():
294 def recv_cb(pkt):
295 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700296 self.success = True if positive_test else False
297 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700298 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 -0700299 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700300 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700301
302 t = threading.Thread(target = recv_task)
303 t.start()
304 L2 = Ether(src = src_mac, dst = dst_mac)
305 L3 = IP(src = src_ip, dst = dst_ip)
306 pkt = L2/L3
307 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 -0700308 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700309 while self.start_sending is True:
310 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700311 t.join()
312 assert_equal(self.success, True)
313
ChetanGaonker70820bb2016-06-29 18:11:57 -0700314 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
315 if peer_address is None:
316 peers = len(self.peer_list)
317 peer_list = self.peer_list
318 else:
319 peers = len(peer_address)
320 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700321 egress = peers + 1
322 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700323 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700324 src_mac = '00:00:00:00:00:02'
325 src_ip = '1.1.1.1'
326 if self.network_mask != 24:
327 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700328 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700329 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700330 octets = network.split('.')
331 for i in xrange(num_ips):
332 octets[-1] = str(int(octets[-1]) + 1)
333 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700334 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700335 port = (num % peers)
336 ingress = port + 1
337 #Since peers are on the same network
338 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700339 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700340 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700341
ChetanGaonker70820bb2016-06-29 18:11:57 -0700342 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
343 start_network = None, start_peer_address = None, route_update = None,
344 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
345 deactivate_activate_vrouter = None, adding_new_routes = None):
346
347 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
348 peer_address = start_peer_address,
349 route_update = route_update,
350 router_address = start_network,
351 time_expire = time_expire,
352 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700353 self.cliEnter()
354 ##Now verify
355 hosts = json.loads(self.cli.hosts(jsonFormat = True))
356 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700357 ##We read from cli if we expect less number of routes to avoid cli timeouts
358 if networks <= 10000:
359 routes = json.loads(self.cli.routes(jsonFormat = True))
360 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700361 if start_network is not None:
362 if start_network.split('/')[1] is 24:
363 assert_equal(len(routes['routes4']), networks)
364 if start_network.split('/')[1] is not 24:
365 assert_equal(len(routes['routes4']), 1)
366 if start_network is None and invalid_peers is None:
367 assert_equal(len(routes['routes4']), networks)
368 if invalid_peers is not None:
369 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700370 flows = json.loads(self.cli.flows(jsonFormat = True))
371 flows = filter(lambda f: f['flows'], flows)
372 #log.info('Flows: %s' %flows)
373 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700374 if invalid_peers is None:
375 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700376 if positive_test is False:
377 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700378 if time_expire is True:
379 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
380 self.vrouter_traffic_verify()
381 if unreachable_route_traffic is True:
382 network_list_backup = self.network_list
383 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
384 self.vrouter_traffic_verify(positive_test = False)
385 self.network_list = network_list_backup
386 if deactivate_activate_vrouter is True:
387 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
388 self.vrouter_activate(deactivate = True)
389 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
390 #assert_equal(len(routes['routes4']), 'Command not found')
391 log.info('Activating vrouter app again in ONOS controller for negative scenario')
392 self.vrouter_activate(deactivate = False)
393 routes = json.loads(self.cli.routes(jsonFormat = True))
394 assert_equal(len(routes['routes4']), networks)
395 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700396 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700397 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700398 return True
399
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700400 def __vrouter_network_verify_negative(self, networks, peers = 1):
401 ##Stop quagga. Test traffic again to see if flows were removed
402 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700403 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700404 if networks <= 10000:
405 routes = json.loads(self.cli.routes(jsonFormat = True))
406 #Verify routes have been removed
407 if routes and routes.has_key('routes4'):
408 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700409 self.vrouter_traffic_verify(positive_test = False)
410 log.info('OVS flows have been removed successfully after Quagga was stopped')
411 self.start_quagga(networks = networks)
412 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700413 if networks <= 10000:
414 routes = json.loads(self.cli.routes(jsonFormat = True))
415 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700416 self.vrouter_traffic_verify()
417 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
418
ChetanGaonker70820bb2016-06-29 18:11:57 -0700419 def quagga_shell(self, cmd):
420 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
421 quagga_cmd = ' -c '.join(shell_cmds)
422 return cord_test_quagga_shell(quagga_cmd)
423
424 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700425 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700426 assert_equal(res, True)
427
ChetanGaonker70820bb2016-06-29 18:11:57 -0700428 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700429 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700430 assert_equal(res, True)
431
ChetanGaonker70820bb2016-06-29 18:11:57 -0700432 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700433 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700434 assert_equal(res, True)
435
ChetanGaonker70820bb2016-06-29 18:11:57 -0700436 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700437 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700438 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700439
ChetanGaonker70820bb2016-06-29 18:11:57 -0700440 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700441 res = self.__vrouter_network_verify(50, peers = 5)
442 assert_equal(res, True)
443
ChetanGaonker70820bb2016-06-29 18:11:57 -0700444 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700445 res = self.__vrouter_network_verify(100, peers = 1)
446 assert_equal(res, True)
447
ChetanGaonker70820bb2016-06-29 18:11:57 -0700448 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700449 res = self.__vrouter_network_verify(100, peers = 10)
450 assert_equal(res, True)
451
ChetanGaonker70820bb2016-06-29 18:11:57 -0700452 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700453 res = self.__vrouter_network_verify(300, peers = 1)
454 assert_equal(res, True)
455
ChetanGaonker70820bb2016-06-29 18:11:57 -0700456 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700457 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700458 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700459
ChetanGaonker70820bb2016-06-29 18:11:57 -0700460 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700461 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700462 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700463
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700464 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700465 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700466 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700467 assert_equal(res, True)
468
469 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700470 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700471 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700472 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700473
ChetanGaonker70820bb2016-06-29 18:11:57 -0700474 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700475 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
476
ChetanGaonker70820bb2016-06-29 18:11:57 -0700477 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700478 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700479
480 def test_vrouter_with_route_update(self):
481 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
482 assert_equal(res, True)
483 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
484 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
485 start_peer_address = peer_info, route_update = True)
486 assert_equal(res, True)
487
488 def test_vrouter_with_classA_route_update(self):
489 router_address = '11.10.10.0/8'
490 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
491 assert_equal(res, True)
492
493 def test_vrouter_with_classB_route_update(self):
494 router_address = '11.10.10.0/16'
495 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
496 assert_equal(res, True)
497
498 def test_vrouter_with_classless_route_update(self):
499 router_address = '11.10.10.0/12'
500 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
501 assert_equal(res, True)
502
503 def test_vrouter_with_classA_duplicate_route_update(self):
504 router_address = '11.10.10.0/8'
505 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
506 assert_equal(res, True)
507
508 def test_vrouter_with_classB_duplicate_route_update(self):
509 router_address = '11.10.10.0/16'
510 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
511 assert_equal(res, True)
512
513 def test_vrouter_with_classless_duplicate_route_update(self):
514 router_address = '11.10.10.0/12'
515 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
516 assert_equal(res, True)
517
518 def test_vrouter_with_invalid_peers(self):
519 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
520 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
521 start_peer_address = peer_info, invalid_peers= True)
522 assert_equal(res, True)
523
524 @nottest
525 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
526 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
527 assert_equal(res, True)
528
529 @nottest
530 def test_vrouter_with_routes_time_expire(self):
531 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
532 assert_equal(res, True)
533
534 def test_vrouter_with_unreachable_route(self):
535 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
536 assert_equal(res, True)
537
538 @nottest
539 def test_vrouter_with_enabling_disabling_vrouter_app(self):
540 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
541 assert_equal(res, True)
542
543 def test_vrouter_with_adding_new_routes_in_routing_table(self):
544 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
545 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
546 self.quagga_shell(cmd)
547 self.vrouter_traffic_verify()
548 self.network_list = [ '21.10.20.0' ]
549 self.network_mask = 24
550 self.vrouter_traffic_verify()
551 assert_equal(res, True)
552
553 def test_vrouter_with_removing_old_routes_in_routing_table(self):
554 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
555 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
556 self.quagga_shell(cmd)
557 self.vrouter_traffic_verify()
558 old_network_list = self.network_list
559 old_network_mask = self.network_mask
560 self.network_list = [ '21.10.20.0' ]
561 self.network_mask = 24
562 self.vrouter_traffic_verify()
563 assert_equal(res, True)
564 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
565 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700566 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700567 self.vrouter_traffic_verify(positive_test = False)
568 self.network_mask = old_network_mask
569 self.network_list = old_network_list
570 self.vrouter_traffic_verify(positive_test = True)
571
572 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
573 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
574 router_address = '11.10.10.0/24'
575 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
576 start_peer_address = peer_info, start_network = router_address)
577 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
578 self.quagga_shell(cmd)
579 self.vrouter_traffic_verify(positive_test = True)
580 assert_equal(res, True)
581
582
583 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
584 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
585 router_address = '11.10.10.0/24'
586 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
587 start_peer_address = peer_info, start_network = router_address)
588 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
589 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700590 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700591 self.vrouter_traffic_verify(positive_test = False)
592 assert_equal(res, True)
593
594 def test_vrouter_deleting_some_routes_in_routing_table(self):
595 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
596 router_address = '11.10.10.0/24'
597 res = self.__vrouter_network_verify(10, peers = 2, positive_test = True,
598 start_peer_address = peer_info, start_network = router_address)
599 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
600 self.quagga_shell(cmd)
601 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
602 self.quagga_shell(cmd)
603 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
604 self.quagga_shell(cmd)
605 self.vrouter_traffic_verify(positive_test = True)
606 assert_equal(res, True)
607
608
609 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
610 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
611 router_address = '11.10.10.0/24'
612 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, 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 = 'ip route 11.10.10.0/24 192.168.10.1'
616 self.quagga_shell(cmd)
617 self.vrouter_traffic_verify(positive_test = True)
618 assert_equal(res, True)
619
620 def test_vrouter_toggling_nexthop_interface(self):
621 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
622 router_address = '11.10.10.0/24'
623 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 -0700624 iface = self.port_map[1]
625 #toggle the interface to trigger host removal.
626 cmds = ('ifconfig {} down'.format(iface),
627 'sleep 2',
628 'ifconfig {} 0'.format(iface),)
629 for cmd in cmds:
630 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700631 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700632 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700633 cmd = 'ifconfig {0} {1} up'.format(iface, host)
634 os.system(cmd)
635 #wait for arp refresh
636 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700637 self.vrouter_traffic_verify(positive_test = True)
638 assert_equal(res, True)
639
640
641