blob: 97df637dc576bc68d3f09dbf8448ef3b68d8d310 [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
A R Karthick9313b762016-11-07 13:14:35 -080027from CordLogger import CordLogger
Chetan Gaonker3533faa2016-04-25 17:50:14 -070028import threading
29import time
30import os
31import json
ChetanGaonker70820bb2016-06-29 18:11:57 -070032import pexpect
33
34#from cli import quagga
35#from quagga import *
36#from cli import requires
37#from cli import system
38#from generic import *
39
Chetan Gaonker3533faa2016-04-25 17:50:14 -070040log.setLevel('INFO')
41
A R Karthick9313b762016-11-07 13:14:35 -080042class vrouter_exchange(CordLogger):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070043
A R Karthick52414732017-01-31 09:59:47 -080044 apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
A R Karthick078e63a2016-07-28 13:59:31 -070045 device_id = 'of:' + get_mac()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070046 vrouter_device_dict = { "devices" : {
47 "{}".format(device_id) : {
48 "basic" : {
49 "driver" : "softrouter"
50 }
51 }
52 },
53 }
54 zebra_conf = '''
55password zebra
56log stdout
57service advanced-vty
58!
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -070059!debug zebra rib
60!debug zebra kernel
61!debug zebra fpm
Chetan Gaonker3533faa2016-04-25 17:50:14 -070062!
63!interface eth1
64! ip address 10.10.0.3/16
65line vty
66 exec-timeout 0 0
67'''
68 test_path = os.path.dirname(os.path.realpath(__file__))
69 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
70 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070071 GATEWAY = '192.168.10.50'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070072 INGRESS_PORT = 1
73 EGRESS_PORT = 2
Chetan Gaonker3533faa2016-04-25 17:50:14 -070074 MAX_PORTS = 100
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070075 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 -070076 network_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -070077 network_mask = 24
78 default_routes_address = ('11.10.10.0/24',)
79 default_peer_address = peer_list
80 quagga_ip = os.getenv('QUAGGA_IP')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070081
82 @classmethod
83 def setUpClass(cls):
84 ''' Activate the vrouter apps'''
85 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070086 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070087 if not cls.port_map:
88 cls.port_map = g_subscriber_port_map
Chetan Gaonker3533faa2016-04-25 17:50:14 -070089 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070090 cls.load_device_id()
A R Karthick81acbff2016-06-17 14:45:16 -070091
Chetan Gaonker3533faa2016-04-25 17:50:14 -070092 @classmethod
93 def tearDownClass(cls):
94 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070095 #cls.vrouter_host_unload()
A R Karthick4e0c0912016-08-17 16:57:42 -070096 cls.start_onos(network_cfg = {})
Chetan Gaonker3533faa2016-04-25 17:50:14 -070097
A R Karthickb03cecd2016-07-27 10:27:55 -070098 @classmethod
99 def load_device_id(cls):
100 did = OnosCtrl.get_device_id()
101 cls.device_id = did
102 cls.vrouter_device_dict = { "devices" : {
103 "{}".format(did) : {
104 "basic" : {
105 "driver" : "softrouter"
106 }
107 }
108 },
109 }
110
A R Karthick52414732017-01-31 09:59:47 -0800111 @classmethod
112 def activate_apps(cls, deactivate = False):
113 for app in cls.apps:
114 onos_ctrl = OnosCtrl(app)
115 if deactivate is False:
116 onos_ctrl.activate()
117 else:
118 onos_ctrl.deactivate()
119 time.sleep(2)
120
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700121 def cliEnter(self):
122 retries = 0
123 while retries < 3:
124 self.cli = OnosCliDriver(connect = True)
125 if self.cli.handle:
126 break
127 else:
128 retries += 1
129 time.sleep(2)
130
131 def cliExit(self):
132 self.cli.disconnect()
133
134 @classmethod
135 def onos_load_config(cls, config):
136 status, code = OnosCtrl.config(config)
137 if status is False:
138 log.info('JSON request returned status %d' %code)
139 assert_equal(status, True)
140
141 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700142 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
143 route_update = None, router_address = None):
144 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
145 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700146 return vrouter_configs
147 ##ONOS router does not support dynamic reconfigurations
148 #for config in vrouter_configs:
149 # cls.onos_load_config(config)
150 # time.sleep(5)
151
152 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700153 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700154 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700155 peer_info = peer_address if peer_address is not None else cls.peer_list
156
157 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700158 iface = cls.port_map[index]
159 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700160 log.info('Assigning ip %s to interface %s' %(host, iface))
161 config_cmds = ( 'ifconfig {} 0'.format(iface),
162 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700163 'arping -I {0} {1} -c 2'.format(iface, host),
164 )
165 for cmd in config_cmds:
166 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700167
168 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700169 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700170 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700171 peer_info = peer_address if peer_address is not None else cls.peer_list
172
173 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700174 iface = cls.port_map[index]
175 index += 1
176 config_cmds = ('ifconfig {} 0'.format(iface), )
177 for cmd in config_cmds:
178 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700179
180 @classmethod
181 def start_onos(cls, network_cfg = None):
182 if type(network_cfg) is tuple:
183 res = []
184 for v in network_cfg:
185 res += v.items()
186 config = dict(res)
187 else:
188 config = network_cfg
189 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700190 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700191
192 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700193 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700194 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700195 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700196 if networks <= 10000:
197 boot_delay = 25
198 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700199 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
200 n = min(networks/100000, len(delay_map)-1)
201 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700202 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700203
204 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700205 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700206 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700207 if peer_address is None:
208 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
209 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
210 else:
211 ip = peer_address[0][0]
212 start_ip = ip.split('.')
213 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
214 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 -0700215 local_network = end_peer + 1
216 ports_dict = { 'ports' : {} }
217 interface_list = []
218 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700219 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700220 port_map = ports_dict['ports']
221 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
222 device_port_key = '{0}/{1}'.format(cls.device_id, port)
223 try:
224 interfaces = port_map[device_port_key]['interfaces']
225 except:
226 port_map[device_port_key] = { 'interfaces' : [] }
227 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700228 ip = n + 2
229 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700230 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700231 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
232 mac = RandMAC()._fix()
233 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700234 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700235 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700236 interfaces.append(interface_dict)
237 interface_list.append(interface_dict['name'])
238 else:
239 interfaces[0]['ips'].append(ips)
240 num += 1
241 if num == peers:
242 break
243 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
244 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
245 quagga_router_dict['ospfEnabled'] = True
246 quagga_router_dict['interfaces'] = interface_list
247 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
248
249 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
250 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
251 speaker_dict = {}
252 speaker_dict['name'] = 'bgp{}'.format(peers+1)
253 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
254 speaker_dict['peers'] = peer_list
255 bgp_speakers_list.append(speaker_dict)
256 cls.peer_list = peer_list
257 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
258
259 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700260 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700261 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700262 if router_address is None:
263 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
264 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
265 network_mask = 24
266 else:
267 ip = router_address
268 start_ip = ip.split('.')
269 network_mask = int(start_ip[3].split('/')[1])
270 start_ip[3] = (start_ip[3].split('/'))[0]
271 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
272 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700273 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700274 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700275 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700276 for n in xrange(start_network, end_network, 256):
277 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
278 network_list.append(net)
279 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700280 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700281 net_list.append(net_route)
282 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700283 if num == networks:
284 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700285 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700286 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700287 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700288 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700289 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700290
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700291 @classmethod
292 def vrouter_activate(cls, deactivate = False):
293 app = 'org.onosproject.vrouter'
294 onos_ctrl = OnosCtrl(app)
295 if deactivate is True:
296 onos_ctrl.deactivate()
297 else:
298 onos_ctrl.activate()
299 time.sleep(3)
300
301 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700302 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
303 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
304 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
305 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700306 cls.start_onos(network_cfg = vrouter_configs)
A R Karthick52414732017-01-31 09:59:47 -0800307 cls.activate_apps()
308 time.sleep(5)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700309 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700310 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700311 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700312 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700313
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700314 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700315 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700316 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700317 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700318 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700319 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700320 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700321 def recv_task():
322 def recv_cb(pkt):
323 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700324 self.success = True if positive_test else False
325 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700326 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 -0700327 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700328 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700329
330 t = threading.Thread(target = recv_task)
331 t.start()
332 L2 = Ether(src = src_mac, dst = dst_mac)
333 L3 = IP(src = src_ip, dst = dst_ip)
334 pkt = L2/L3
335 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 -0700336 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700337 while self.start_sending is True:
338 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700339 t.join()
340 assert_equal(self.success, True)
341
ChetanGaonker70820bb2016-06-29 18:11:57 -0700342 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
343 if peer_address is None:
344 peers = len(self.peer_list)
345 peer_list = self.peer_list
346 else:
347 peers = len(peer_address)
348 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700349 egress = peers + 1
350 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700351 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700352 src_mac = '00:00:00:00:00:02'
353 src_ip = '1.1.1.1'
354 if self.network_mask != 24:
355 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700356 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700357 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700358 octets = network.split('.')
359 for i in xrange(num_ips):
360 octets[-1] = str(int(octets[-1]) + 1)
361 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700362 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700363 port = (num % peers)
364 ingress = port + 1
365 #Since peers are on the same network
366 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700367 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700368 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700369
ChetanGaonker70820bb2016-06-29 18:11:57 -0700370 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
371 start_network = None, start_peer_address = None, route_update = None,
372 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
373 deactivate_activate_vrouter = None, adding_new_routes = None):
374
375 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
376 peer_address = start_peer_address,
377 route_update = route_update,
378 router_address = start_network,
379 time_expire = time_expire,
380 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700381 self.cliEnter()
382 ##Now verify
383 hosts = json.loads(self.cli.hosts(jsonFormat = True))
384 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700385 ##We read from cli if we expect less number of routes to avoid cli timeouts
386 if networks <= 10000:
387 routes = json.loads(self.cli.routes(jsonFormat = True))
388 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700389 if start_network is not None:
390 if start_network.split('/')[1] is 24:
391 assert_equal(len(routes['routes4']), networks)
392 if start_network.split('/')[1] is not 24:
393 assert_equal(len(routes['routes4']), 1)
394 if start_network is None and invalid_peers is None:
395 assert_equal(len(routes['routes4']), networks)
396 if invalid_peers is not None:
397 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700398 flows = json.loads(self.cli.flows(jsonFormat = True))
399 flows = filter(lambda f: f['flows'], flows)
400 #log.info('Flows: %s' %flows)
401 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700402 if invalid_peers is None:
403 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700404 if positive_test is False:
405 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700406 if time_expire is True:
407 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
408 self.vrouter_traffic_verify()
409 if unreachable_route_traffic is True:
410 network_list_backup = self.network_list
411 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
412 self.vrouter_traffic_verify(positive_test = False)
413 self.network_list = network_list_backup
414 if deactivate_activate_vrouter is True:
415 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
416 self.vrouter_activate(deactivate = True)
417 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
418 #assert_equal(len(routes['routes4']), 'Command not found')
419 log.info('Activating vrouter app again in ONOS controller for negative scenario')
420 self.vrouter_activate(deactivate = False)
421 routes = json.loads(self.cli.routes(jsonFormat = True))
422 assert_equal(len(routes['routes4']), networks)
423 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700424 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700425 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700426 return True
427
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700428 def __vrouter_network_verify_negative(self, networks, peers = 1):
429 ##Stop quagga. Test traffic again to see if flows were removed
430 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700431 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700432 if networks <= 10000:
433 routes = json.loads(self.cli.routes(jsonFormat = True))
434 #Verify routes have been removed
435 if routes and routes.has_key('routes4'):
436 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700437 self.vrouter_traffic_verify(positive_test = False)
438 log.info('OVS flows have been removed successfully after Quagga was stopped')
439 self.start_quagga(networks = networks)
440 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700441 if networks <= 10000:
442 routes = json.loads(self.cli.routes(jsonFormat = True))
443 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700444 self.vrouter_traffic_verify()
445 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
446
ChetanGaonker70820bb2016-06-29 18:11:57 -0700447 def quagga_shell(self, cmd):
448 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
449 quagga_cmd = ' -c '.join(shell_cmds)
450 return cord_test_quagga_shell(quagga_cmd)
451
452 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700453 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700454 assert_equal(res, True)
455
ChetanGaonker70820bb2016-06-29 18:11:57 -0700456 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700457 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700458 assert_equal(res, True)
459
ChetanGaonker70820bb2016-06-29 18:11:57 -0700460 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700461 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700462 assert_equal(res, True)
463
ChetanGaonker70820bb2016-06-29 18:11:57 -0700464 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700465 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700466 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700467
ChetanGaonker70820bb2016-06-29 18:11:57 -0700468 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700469 res = self.__vrouter_network_verify(50, peers = 5)
470 assert_equal(res, True)
471
ChetanGaonker70820bb2016-06-29 18:11:57 -0700472 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700473 res = self.__vrouter_network_verify(100, peers = 1)
474 assert_equal(res, True)
475
ChetanGaonker70820bb2016-06-29 18:11:57 -0700476 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700477 res = self.__vrouter_network_verify(100, peers = 10)
478 assert_equal(res, True)
479
ChetanGaonker70820bb2016-06-29 18:11:57 -0700480 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700481 res = self.__vrouter_network_verify(300, peers = 1)
482 assert_equal(res, True)
483
ChetanGaonker70820bb2016-06-29 18:11:57 -0700484 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700485 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700486 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700487
ChetanGaonker70820bb2016-06-29 18:11:57 -0700488 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700489 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700490 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700491
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700492 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700493 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700494 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700495 assert_equal(res, True)
496
497 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700498 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700499 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700500 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700501
ChetanGaonker70820bb2016-06-29 18:11:57 -0700502 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700503 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
504
ChetanGaonker70820bb2016-06-29 18:11:57 -0700505 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700506 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700507
508 def test_vrouter_with_route_update(self):
509 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
510 assert_equal(res, True)
511 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
512 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
513 start_peer_address = peer_info, route_update = True)
514 assert_equal(res, True)
515
516 def test_vrouter_with_classA_route_update(self):
517 router_address = '11.10.10.0/8'
518 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
519 assert_equal(res, True)
520
521 def test_vrouter_with_classB_route_update(self):
522 router_address = '11.10.10.0/16'
523 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
524 assert_equal(res, True)
525
526 def test_vrouter_with_classless_route_update(self):
527 router_address = '11.10.10.0/12'
528 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
529 assert_equal(res, True)
530
531 def test_vrouter_with_classA_duplicate_route_update(self):
532 router_address = '11.10.10.0/8'
533 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
534 assert_equal(res, True)
535
536 def test_vrouter_with_classB_duplicate_route_update(self):
537 router_address = '11.10.10.0/16'
538 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
539 assert_equal(res, True)
540
541 def test_vrouter_with_classless_duplicate_route_update(self):
542 router_address = '11.10.10.0/12'
543 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
544 assert_equal(res, True)
545
546 def test_vrouter_with_invalid_peers(self):
547 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
548 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
549 start_peer_address = peer_info, invalid_peers= True)
550 assert_equal(res, True)
551
552 @nottest
553 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
554 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
555 assert_equal(res, True)
556
557 @nottest
558 def test_vrouter_with_routes_time_expire(self):
559 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
560 assert_equal(res, True)
561
562 def test_vrouter_with_unreachable_route(self):
563 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
564 assert_equal(res, True)
565
566 @nottest
567 def test_vrouter_with_enabling_disabling_vrouter_app(self):
568 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
569 assert_equal(res, True)
570
571 def test_vrouter_with_adding_new_routes_in_routing_table(self):
572 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
573 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
574 self.quagga_shell(cmd)
575 self.vrouter_traffic_verify()
576 self.network_list = [ '21.10.20.0' ]
577 self.network_mask = 24
578 self.vrouter_traffic_verify()
579 assert_equal(res, True)
580
581 def test_vrouter_with_removing_old_routes_in_routing_table(self):
582 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
583 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
584 self.quagga_shell(cmd)
585 self.vrouter_traffic_verify()
586 old_network_list = self.network_list
587 old_network_mask = self.network_mask
588 self.network_list = [ '21.10.20.0' ]
589 self.network_mask = 24
590 self.vrouter_traffic_verify()
591 assert_equal(res, True)
592 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
593 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700594 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700595 self.vrouter_traffic_verify(positive_test = False)
596 self.network_mask = old_network_mask
597 self.network_list = old_network_list
598 self.vrouter_traffic_verify(positive_test = True)
599
600 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
601 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
602 router_address = '11.10.10.0/24'
603 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
604 start_peer_address = peer_info, start_network = router_address)
605 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
606 self.quagga_shell(cmd)
607 self.vrouter_traffic_verify(positive_test = True)
608 assert_equal(res, True)
609
610
611 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
612 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
613 router_address = '11.10.10.0/24'
614 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
615 start_peer_address = peer_info, start_network = router_address)
616 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
617 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700618 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700619 self.vrouter_traffic_verify(positive_test = False)
620 assert_equal(res, True)
621
622 def test_vrouter_deleting_some_routes_in_routing_table(self):
623 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
624 router_address = '11.10.10.0/24'
625 res = self.__vrouter_network_verify(10, peers = 2, positive_test = True,
626 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 = 'no ip route 11.10.13.0/24 192.168.11.1'
630 self.quagga_shell(cmd)
631 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
632 self.quagga_shell(cmd)
633 self.vrouter_traffic_verify(positive_test = True)
634 assert_equal(res, True)
635
636
637 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
638 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
639 router_address = '11.10.10.0/24'
640 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
641 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
642 self.quagga_shell(cmd)
643 cmd = 'ip route 11.10.10.0/24 192.168.10.1'
644 self.quagga_shell(cmd)
645 self.vrouter_traffic_verify(positive_test = True)
646 assert_equal(res, True)
647
648 def test_vrouter_toggling_nexthop_interface(self):
649 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
650 router_address = '11.10.10.0/24'
651 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 -0700652 iface = self.port_map[1]
653 #toggle the interface to trigger host removal.
654 cmds = ('ifconfig {} down'.format(iface),
655 'sleep 2',
656 'ifconfig {} 0'.format(iface),)
657 for cmd in cmds:
658 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700659 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700660 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700661 cmd = 'ifconfig {0} {1} up'.format(iface, host)
662 os.system(cmd)
663 #wait for arp refresh
664 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700665 self.vrouter_traffic_verify(positive_test = True)
666 assert_equal(res, True)