blob: dc1f28106d458b8d800e1b23ffb0ed40f873acf8 [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 Karthickbe7768c2017-03-17 11:39:41 -070019from CordTestUtils import get_mac
20from OnosCtrl import OnosCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070021from OltConfig import OltConfig
A R Karthickb03cecd2016-07-27 10:27:55 -070022from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070023from onosclidriver import OnosCliDriver
ChetanGaonker70820bb2016-06-29 18:11:57 -070024#from quaggaclidriver import QuaggaCliDriver
Chetan Gaonker6cf6e472016-04-26 14:41:51 -070025from CordContainer import Container, Onos, Quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -070026from 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 -070027from portmaps import g_subscriber_port_map
A R Karthick9313b762016-11-07 13:14:35 -080028from CordLogger import CordLogger
Chetan Gaonker3533faa2016-04-25 17:50:14 -070029import threading
30import time
31import os
32import json
ChetanGaonker70820bb2016-06-29 18:11:57 -070033import pexpect
34
35#from cli import quagga
36#from quagga import *
37#from cli import requires
38#from cli import system
39#from generic import *
40
Chetan Gaonker3533faa2016-04-25 17:50:14 -070041log.setLevel('INFO')
42
A R Karthick9313b762016-11-07 13:14:35 -080043class vrouter_exchange(CordLogger):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070044
A R Karthick52414732017-01-31 09:59:47 -080045 apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
A R Karthick078e63a2016-07-28 13:59:31 -070046 device_id = 'of:' + get_mac()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070047 vrouter_device_dict = { "devices" : {
48 "{}".format(device_id) : {
49 "basic" : {
50 "driver" : "softrouter"
51 }
52 }
53 },
54 }
55 zebra_conf = '''
56password zebra
57log stdout
58service advanced-vty
59!
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -070060!debug zebra rib
61!debug zebra kernel
62!debug zebra fpm
Chetan Gaonker3533faa2016-04-25 17:50:14 -070063!
64!interface eth1
65! ip address 10.10.0.3/16
66line vty
67 exec-timeout 0 0
68'''
69 test_path = os.path.dirname(os.path.realpath(__file__))
70 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
71 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070072 GATEWAY = '192.168.10.50'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070073 INGRESS_PORT = 1
74 EGRESS_PORT = 2
Chetan Gaonker3533faa2016-04-25 17:50:14 -070075 MAX_PORTS = 100
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070076 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 -070077 network_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -070078 network_mask = 24
79 default_routes_address = ('11.10.10.0/24',)
80 default_peer_address = peer_list
81 quagga_ip = os.getenv('QUAGGA_IP')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070082
83 @classmethod
84 def setUpClass(cls):
85 ''' Activate the vrouter apps'''
86 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070087 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070088 if not cls.port_map:
89 cls.port_map = g_subscriber_port_map
Chetan Gaonker3533faa2016-04-25 17:50:14 -070090 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070091 cls.load_device_id()
A R Karthick81acbff2016-06-17 14:45:16 -070092
Chetan Gaonker3533faa2016-04-25 17:50:14 -070093 @classmethod
94 def tearDownClass(cls):
95 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070096 #cls.vrouter_host_unload()
A R Karthick4e0c0912016-08-17 16:57:42 -070097 cls.start_onos(network_cfg = {})
Chetan Gaonker3533faa2016-04-25 17:50:14 -070098
A R Karthickb03cecd2016-07-27 10:27:55 -070099 @classmethod
100 def load_device_id(cls):
101 did = OnosCtrl.get_device_id()
102 cls.device_id = did
103 cls.vrouter_device_dict = { "devices" : {
104 "{}".format(did) : {
105 "basic" : {
106 "driver" : "softrouter"
107 }
108 }
109 },
110 }
111
A R Karthick52414732017-01-31 09:59:47 -0800112 @classmethod
113 def activate_apps(cls, deactivate = False):
114 for app in cls.apps:
115 onos_ctrl = OnosCtrl(app)
116 if deactivate is False:
117 onos_ctrl.activate()
118 else:
119 onos_ctrl.deactivate()
120 time.sleep(2)
121
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700122 def cliEnter(self):
123 retries = 0
124 while retries < 3:
125 self.cli = OnosCliDriver(connect = True)
126 if self.cli.handle:
127 break
128 else:
129 retries += 1
130 time.sleep(2)
131
132 def cliExit(self):
133 self.cli.disconnect()
134
135 @classmethod
136 def onos_load_config(cls, config):
137 status, code = OnosCtrl.config(config)
138 if status is False:
139 log.info('JSON request returned status %d' %code)
140 assert_equal(status, True)
141
142 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700143 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
144 route_update = None, router_address = None):
145 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
146 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700147 return vrouter_configs
148 ##ONOS router does not support dynamic reconfigurations
149 #for config in vrouter_configs:
150 # cls.onos_load_config(config)
151 # time.sleep(5)
152
153 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700154 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700155 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700156 peer_info = peer_address if peer_address is not None else cls.peer_list
157
158 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700159 iface = cls.port_map[index]
160 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700161 log.info('Assigning ip %s to interface %s' %(host, iface))
162 config_cmds = ( 'ifconfig {} 0'.format(iface),
163 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700164 'arping -I {0} {1} -c 2'.format(iface, host),
165 )
166 for cmd in config_cmds:
167 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700168
169 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700170 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700171 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700172 peer_info = peer_address if peer_address is not None else cls.peer_list
173
174 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700175 iface = cls.port_map[index]
176 index += 1
177 config_cmds = ('ifconfig {} 0'.format(iface), )
178 for cmd in config_cmds:
179 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700180
181 @classmethod
182 def start_onos(cls, network_cfg = None):
183 if type(network_cfg) is tuple:
184 res = []
185 for v in network_cfg:
186 res += v.items()
187 config = dict(res)
188 else:
189 config = network_cfg
190 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700191 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700192
193 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700194 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700195 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700196 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700197 if networks <= 10000:
198 boot_delay = 25
199 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700200 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
201 n = min(networks/100000, len(delay_map)-1)
202 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700203 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700204
205 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700206 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700207 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700208 if peer_address is None:
209 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
210 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
211 else:
212 ip = peer_address[0][0]
213 start_ip = ip.split('.')
214 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
215 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 -0700216 local_network = end_peer + 1
217 ports_dict = { 'ports' : {} }
218 interface_list = []
219 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700220 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700221 port_map = ports_dict['ports']
222 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
223 device_port_key = '{0}/{1}'.format(cls.device_id, port)
224 try:
225 interfaces = port_map[device_port_key]['interfaces']
226 except:
227 port_map[device_port_key] = { 'interfaces' : [] }
228 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700229 ip = n + 2
230 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700231 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700232 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
233 mac = RandMAC()._fix()
234 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700235 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700236 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700237 interfaces.append(interface_dict)
238 interface_list.append(interface_dict['name'])
239 else:
240 interfaces[0]['ips'].append(ips)
241 num += 1
242 if num == peers:
243 break
244 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
245 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
246 quagga_router_dict['ospfEnabled'] = True
247 quagga_router_dict['interfaces'] = interface_list
248 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
249
250 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
251 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
252 speaker_dict = {}
253 speaker_dict['name'] = 'bgp{}'.format(peers+1)
254 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
255 speaker_dict['peers'] = peer_list
256 bgp_speakers_list.append(speaker_dict)
257 cls.peer_list = peer_list
258 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
259
260 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700261 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700262 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700263 if router_address is None:
264 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
265 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
266 network_mask = 24
267 else:
268 ip = router_address
269 start_ip = ip.split('.')
270 network_mask = int(start_ip[3].split('/')[1])
271 start_ip[3] = (start_ip[3].split('/'))[0]
272 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
273 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700274 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700275 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700276 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700277 for n in xrange(start_network, end_network, 256):
278 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
279 network_list.append(net)
280 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700281 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700282 net_list.append(net_route)
283 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700284 if num == networks:
285 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700286 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700287 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700288 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700289 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700290 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700291
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700292 @classmethod
293 def vrouter_activate(cls, deactivate = False):
294 app = 'org.onosproject.vrouter'
295 onos_ctrl = OnosCtrl(app)
296 if deactivate is True:
297 onos_ctrl.deactivate()
298 else:
299 onos_ctrl.activate()
300 time.sleep(3)
301
302 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700303 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
304 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
305 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
306 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700307 cls.start_onos(network_cfg = vrouter_configs)
A R Karthick52414732017-01-31 09:59:47 -0800308 cls.activate_apps()
309 time.sleep(5)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700310 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700311 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700312 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700313 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700314
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700315 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700316 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700317 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700318 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700319 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700320 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700321 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700322 def recv_task():
323 def recv_cb(pkt):
324 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700325 self.success = True if positive_test else False
326 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700327 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 -0700328 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700329 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700330
331 t = threading.Thread(target = recv_task)
332 t.start()
333 L2 = Ether(src = src_mac, dst = dst_mac)
334 L3 = IP(src = src_ip, dst = dst_ip)
335 pkt = L2/L3
336 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 -0700337 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700338 while self.start_sending is True:
339 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700340 t.join()
341 assert_equal(self.success, True)
342
ChetanGaonker70820bb2016-06-29 18:11:57 -0700343 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
344 if peer_address is None:
345 peers = len(self.peer_list)
346 peer_list = self.peer_list
347 else:
348 peers = len(peer_address)
349 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700350 egress = peers + 1
351 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700352 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700353 src_mac = '00:00:00:00:00:02'
354 src_ip = '1.1.1.1'
355 if self.network_mask != 24:
356 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700357 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700358 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700359 octets = network.split('.')
360 for i in xrange(num_ips):
361 octets[-1] = str(int(octets[-1]) + 1)
362 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700363 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700364 port = (num % peers)
365 ingress = port + 1
366 #Since peers are on the same network
367 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700368 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700369 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700370
ChetanGaonker70820bb2016-06-29 18:11:57 -0700371 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
372 start_network = None, start_peer_address = None, route_update = None,
373 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
374 deactivate_activate_vrouter = None, adding_new_routes = None):
375
376 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
377 peer_address = start_peer_address,
378 route_update = route_update,
379 router_address = start_network,
380 time_expire = time_expire,
381 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700382 self.cliEnter()
383 ##Now verify
384 hosts = json.loads(self.cli.hosts(jsonFormat = True))
385 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700386 ##We read from cli if we expect less number of routes to avoid cli timeouts
387 if networks <= 10000:
388 routes = json.loads(self.cli.routes(jsonFormat = True))
389 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700390 if start_network is not None:
391 if start_network.split('/')[1] is 24:
392 assert_equal(len(routes['routes4']), networks)
393 if start_network.split('/')[1] is not 24:
394 assert_equal(len(routes['routes4']), 1)
395 if start_network is None and invalid_peers is None:
396 assert_equal(len(routes['routes4']), networks)
397 if invalid_peers is not None:
398 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700399 flows = json.loads(self.cli.flows(jsonFormat = True))
400 flows = filter(lambda f: f['flows'], flows)
401 #log.info('Flows: %s' %flows)
402 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700403 if invalid_peers is None:
404 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700405 if positive_test is False:
406 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700407 if time_expire is True:
408 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
409 self.vrouter_traffic_verify()
410 if unreachable_route_traffic is True:
411 network_list_backup = self.network_list
412 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
413 self.vrouter_traffic_verify(positive_test = False)
414 self.network_list = network_list_backup
415 if deactivate_activate_vrouter is True:
416 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
417 self.vrouter_activate(deactivate = True)
418 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
419 #assert_equal(len(routes['routes4']), 'Command not found')
420 log.info('Activating vrouter app again in ONOS controller for negative scenario')
421 self.vrouter_activate(deactivate = False)
422 routes = json.loads(self.cli.routes(jsonFormat = True))
423 assert_equal(len(routes['routes4']), networks)
424 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700425 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700426 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700427 return True
428
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700429 def __vrouter_network_verify_negative(self, networks, peers = 1):
430 ##Stop quagga. Test traffic again to see if flows were removed
431 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700432 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700433 if networks <= 10000:
434 routes = json.loads(self.cli.routes(jsonFormat = True))
435 #Verify routes have been removed
436 if routes and routes.has_key('routes4'):
437 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700438 self.vrouter_traffic_verify(positive_test = False)
439 log.info('OVS flows have been removed successfully after Quagga was stopped')
440 self.start_quagga(networks = networks)
441 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700442 if networks <= 10000:
443 routes = json.loads(self.cli.routes(jsonFormat = True))
444 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700445 self.vrouter_traffic_verify()
446 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
447
ChetanGaonker70820bb2016-06-29 18:11:57 -0700448 def quagga_shell(self, cmd):
449 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
450 quagga_cmd = ' -c '.join(shell_cmds)
451 return cord_test_quagga_shell(quagga_cmd)
452
453 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700454 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700455 assert_equal(res, True)
456
ChetanGaonker70820bb2016-06-29 18:11:57 -0700457 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700458 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700459 assert_equal(res, True)
460
ChetanGaonker70820bb2016-06-29 18:11:57 -0700461 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700462 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700463 assert_equal(res, True)
464
ChetanGaonker70820bb2016-06-29 18:11:57 -0700465 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700466 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700467 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700468
ChetanGaonker70820bb2016-06-29 18:11:57 -0700469 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700470 res = self.__vrouter_network_verify(50, peers = 5)
471 assert_equal(res, True)
472
ChetanGaonker70820bb2016-06-29 18:11:57 -0700473 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700474 res = self.__vrouter_network_verify(100, peers = 1)
475 assert_equal(res, True)
476
ChetanGaonker70820bb2016-06-29 18:11:57 -0700477 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700478 res = self.__vrouter_network_verify(100, peers = 10)
479 assert_equal(res, True)
480
ChetanGaonker70820bb2016-06-29 18:11:57 -0700481 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700482 res = self.__vrouter_network_verify(300, peers = 1)
483 assert_equal(res, True)
484
ChetanGaonker70820bb2016-06-29 18:11:57 -0700485 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700486 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700487 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700488
ChetanGaonker70820bb2016-06-29 18:11:57 -0700489 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700490 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700491 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700492
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700493 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700494 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700495 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700496 assert_equal(res, True)
497
498 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700499 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700500 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700501 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700502
ChetanGaonker70820bb2016-06-29 18:11:57 -0700503 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700504 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
505
ChetanGaonker70820bb2016-06-29 18:11:57 -0700506 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700507 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700508
509 def test_vrouter_with_route_update(self):
510 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
511 assert_equal(res, True)
512 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
513 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
514 start_peer_address = peer_info, route_update = True)
515 assert_equal(res, True)
516
517 def test_vrouter_with_classA_route_update(self):
518 router_address = '11.10.10.0/8'
519 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
520 assert_equal(res, True)
521
522 def test_vrouter_with_classB_route_update(self):
523 router_address = '11.10.10.0/16'
524 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
525 assert_equal(res, True)
526
527 def test_vrouter_with_classless_route_update(self):
528 router_address = '11.10.10.0/12'
529 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
530 assert_equal(res, True)
531
532 def test_vrouter_with_classA_duplicate_route_update(self):
533 router_address = '11.10.10.0/8'
534 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
535 assert_equal(res, True)
536
537 def test_vrouter_with_classB_duplicate_route_update(self):
538 router_address = '11.10.10.0/16'
539 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
540 assert_equal(res, True)
541
542 def test_vrouter_with_classless_duplicate_route_update(self):
543 router_address = '11.10.10.0/12'
544 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
545 assert_equal(res, True)
546
547 def test_vrouter_with_invalid_peers(self):
548 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
549 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
550 start_peer_address = peer_info, invalid_peers= True)
551 assert_equal(res, True)
552
553 @nottest
554 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
555 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
556 assert_equal(res, True)
557
558 @nottest
559 def test_vrouter_with_routes_time_expire(self):
560 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
561 assert_equal(res, True)
562
563 def test_vrouter_with_unreachable_route(self):
564 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
565 assert_equal(res, True)
566
567 @nottest
568 def test_vrouter_with_enabling_disabling_vrouter_app(self):
569 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
570 assert_equal(res, True)
571
572 def test_vrouter_with_adding_new_routes_in_routing_table(self):
573 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
574 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
575 self.quagga_shell(cmd)
576 self.vrouter_traffic_verify()
577 self.network_list = [ '21.10.20.0' ]
578 self.network_mask = 24
579 self.vrouter_traffic_verify()
580 assert_equal(res, True)
581
582 def test_vrouter_with_removing_old_routes_in_routing_table(self):
583 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
584 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
585 self.quagga_shell(cmd)
586 self.vrouter_traffic_verify()
587 old_network_list = self.network_list
588 old_network_mask = self.network_mask
589 self.network_list = [ '21.10.20.0' ]
590 self.network_mask = 24
591 self.vrouter_traffic_verify()
592 assert_equal(res, True)
593 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
594 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700595 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700596 self.vrouter_traffic_verify(positive_test = False)
597 self.network_mask = old_network_mask
598 self.network_list = old_network_list
599 self.vrouter_traffic_verify(positive_test = True)
600
601 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
602 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
603 router_address = '11.10.10.0/24'
604 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
605 start_peer_address = peer_info, start_network = router_address)
606 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
607 self.quagga_shell(cmd)
608 self.vrouter_traffic_verify(positive_test = True)
609 assert_equal(res, True)
610
611
612 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
613 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
614 router_address = '11.10.10.0/24'
615 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
616 start_peer_address = peer_info, start_network = router_address)
617 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
618 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700619 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700620 self.vrouter_traffic_verify(positive_test = False)
621 assert_equal(res, True)
622
623 def test_vrouter_deleting_some_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(10, peers = 2, positive_test = True,
627 start_peer_address = peer_info, start_network = router_address)
628 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
629 self.quagga_shell(cmd)
630 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
631 self.quagga_shell(cmd)
632 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
633 self.quagga_shell(cmd)
634 self.vrouter_traffic_verify(positive_test = True)
635 assert_equal(res, True)
636
637
638 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
639 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
640 router_address = '11.10.10.0/24'
641 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
642 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
643 self.quagga_shell(cmd)
644 cmd = 'ip route 11.10.10.0/24 192.168.10.1'
645 self.quagga_shell(cmd)
646 self.vrouter_traffic_verify(positive_test = True)
647 assert_equal(res, True)
648
649 def test_vrouter_toggling_nexthop_interface(self):
650 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
651 router_address = '11.10.10.0/24'
652 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 -0700653 iface = self.port_map[1]
654 #toggle the interface to trigger host removal.
655 cmds = ('ifconfig {} down'.format(iface),
656 'sleep 2',
657 'ifconfig {} 0'.format(iface),)
658 for cmd in cmds:
659 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700660 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700661 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700662 cmd = 'ifconfig {0} {1} up'.format(iface, host)
663 os.system(cmd)
664 #wait for arp refresh
665 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700666 self.vrouter_traffic_verify(positive_test = True)
667 assert_equal(res, True)