blob: 9ca696ae4bfcf17edddef595cfc3cbe17d65694b [file] [log] [blame]
A R Karthick81acbff2016-06-17 14:45:16 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
A R Karthick81acbff2016-06-17 14:45:16 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick81acbff2016-06-17 14:45:16 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Chetan Gaonker3533faa2016-04-25 17:50:14 -070016import unittest
17from nose.tools import *
18from scapy.all import *
A R Karthickb03cecd2016-07-27 10:27:55 -070019from OnosCtrl import OnosCtrl, get_mac
Chetan Gaonker3533faa2016-04-25 17:50:14 -070020from OltConfig import OltConfig
A R Karthickb03cecd2016-07-27 10:27:55 -070021from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070022from onosclidriver import OnosCliDriver
ChetanGaonker70820bb2016-06-29 18:11:57 -070023#from quaggaclidriver import QuaggaCliDriver
Chetan Gaonker6cf6e472016-04-26 14:41:51 -070024from CordContainer import Container, Onos, Quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -070025from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart, cord_test_quagga_stop, cord_test_quagga_shell
Chetan Gaonker3533faa2016-04-25 17:50:14 -070026from portmaps import g_subscriber_port_map
27import threading
28import time
29import os
30import json
ChetanGaonker70820bb2016-06-29 18:11:57 -070031import pexpect
32
33#from cli import quagga
34#from quagga import *
35#from cli import requires
36#from cli import system
37#from generic import *
38
Chetan Gaonker3533faa2016-04-25 17:50:14 -070039log.setLevel('INFO')
40
Chetan Gaonker3533faa2016-04-25 17:50:14 -070041class vrouter_exchange(unittest.TestCase):
42
43 apps = ('org.onosproject.vrouter', 'org.onosproject.fwd')
A R Karthick078e63a2016-07-28 13:59:31 -070044 device_id = 'of:' + get_mac()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070045 vrouter_device_dict = { "devices" : {
46 "{}".format(device_id) : {
47 "basic" : {
48 "driver" : "softrouter"
49 }
50 }
51 },
52 }
53 zebra_conf = '''
54password zebra
55log stdout
56service advanced-vty
57!
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -070058!debug zebra rib
59!debug zebra kernel
60!debug zebra fpm
Chetan Gaonker3533faa2016-04-25 17:50:14 -070061!
62!interface eth1
63! ip address 10.10.0.3/16
64line vty
65 exec-timeout 0 0
66'''
67 test_path = os.path.dirname(os.path.realpath(__file__))
68 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
69 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070070 GATEWAY = '192.168.10.50'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070071 INGRESS_PORT = 1
72 EGRESS_PORT = 2
Chetan Gaonker3533faa2016-04-25 17:50:14 -070073 MAX_PORTS = 100
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070074 peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070075 network_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -070076 network_mask = 24
77 default_routes_address = ('11.10.10.0/24',)
78 default_peer_address = peer_list
79 quagga_ip = os.getenv('QUAGGA_IP')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070080
81 @classmethod
82 def setUpClass(cls):
83 ''' Activate the vrouter apps'''
84 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -070085 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070086 if not cls.port_map:
87 cls.port_map = g_subscriber_port_map
Chetan Gaonker3533faa2016-04-25 17:50:14 -070088 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -070089 cls.load_device_id()
A R Karthick81acbff2016-06-17 14:45:16 -070090
Chetan Gaonker3533faa2016-04-25 17:50:14 -070091 @classmethod
92 def tearDownClass(cls):
93 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070094 #cls.vrouter_host_unload()
A R Karthick4e0c0912016-08-17 16:57:42 -070095 cls.start_onos(network_cfg = {})
Chetan Gaonker3533faa2016-04-25 17:50:14 -070096
A R Karthickb03cecd2016-07-27 10:27:55 -070097 @classmethod
98 def load_device_id(cls):
99 did = OnosCtrl.get_device_id()
100 cls.device_id = did
101 cls.vrouter_device_dict = { "devices" : {
102 "{}".format(did) : {
103 "basic" : {
104 "driver" : "softrouter"
105 }
106 }
107 },
108 }
109
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700110 def cliEnter(self):
111 retries = 0
112 while retries < 3:
113 self.cli = OnosCliDriver(connect = True)
114 if self.cli.handle:
115 break
116 else:
117 retries += 1
118 time.sleep(2)
119
120 def cliExit(self):
121 self.cli.disconnect()
122
123 @classmethod
124 def onos_load_config(cls, config):
125 status, code = OnosCtrl.config(config)
126 if status is False:
127 log.info('JSON request returned status %d' %code)
128 assert_equal(status, True)
129
130 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700131 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
132 route_update = None, router_address = None):
133 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
134 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700135 return vrouter_configs
136 ##ONOS router does not support dynamic reconfigurations
137 #for config in vrouter_configs:
138 # cls.onos_load_config(config)
139 # time.sleep(5)
140
141 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700142 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700143 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700144 peer_info = peer_address if peer_address is not None else cls.peer_list
145
146 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700147 iface = cls.port_map[index]
148 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700149 log.info('Assigning ip %s to interface %s' %(host, iface))
150 config_cmds = ( 'ifconfig {} 0'.format(iface),
151 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700152 'arping -I {0} {1} -c 2'.format(iface, host),
153 )
154 for cmd in config_cmds:
155 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156
157 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700158 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700159 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700160 peer_info = peer_address if peer_address is not None else cls.peer_list
161
162 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700163 iface = cls.port_map[index]
164 index += 1
165 config_cmds = ('ifconfig {} 0'.format(iface), )
166 for cmd in config_cmds:
167 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700168
169 @classmethod
170 def start_onos(cls, network_cfg = None):
171 if type(network_cfg) is tuple:
172 res = []
173 for v in network_cfg:
174 res += v.items()
175 config = dict(res)
176 else:
177 config = network_cfg
178 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700179 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700180
181 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700182 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700183 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700184 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700185 if networks <= 10000:
186 boot_delay = 25
187 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700188 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
189 n = min(networks/100000, len(delay_map)-1)
190 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700191 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700192
193 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700194 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700195 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700196 if peer_address is None:
197 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
198 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
199 else:
200 ip = peer_address[0][0]
201 start_ip = ip.split('.')
202 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
203 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 -0700204 local_network = end_peer + 1
205 ports_dict = { 'ports' : {} }
206 interface_list = []
207 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700208 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700209 port_map = ports_dict['ports']
210 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
211 device_port_key = '{0}/{1}'.format(cls.device_id, port)
212 try:
213 interfaces = port_map[device_port_key]['interfaces']
214 except:
215 port_map[device_port_key] = { 'interfaces' : [] }
216 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700217 ip = n + 2
218 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700219 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700220 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
221 mac = RandMAC()._fix()
222 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700223 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700224 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700225 interfaces.append(interface_dict)
226 interface_list.append(interface_dict['name'])
227 else:
228 interfaces[0]['ips'].append(ips)
229 num += 1
230 if num == peers:
231 break
232 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
233 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
234 quagga_router_dict['ospfEnabled'] = True
235 quagga_router_dict['interfaces'] = interface_list
236 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
237
238 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
239 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
240 speaker_dict = {}
241 speaker_dict['name'] = 'bgp{}'.format(peers+1)
242 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
243 speaker_dict['peers'] = peer_list
244 bgp_speakers_list.append(speaker_dict)
245 cls.peer_list = peer_list
246 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
247
248 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700249 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700250 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700251 if router_address is None:
252 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
253 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
254 network_mask = 24
255 else:
256 ip = router_address
257 start_ip = ip.split('.')
258 network_mask = int(start_ip[3].split('/')[1])
259 start_ip[3] = (start_ip[3].split('/'))[0]
260 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
261 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700262 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700263 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700264 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700265 for n in xrange(start_network, end_network, 256):
266 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
267 network_list.append(net)
268 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700269 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700270 net_list.append(net_route)
271 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700272 if num == networks:
273 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700274 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700275 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700276 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700277 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700278 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700279
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700280 @classmethod
281 def vrouter_activate(cls, deactivate = False):
282 app = 'org.onosproject.vrouter'
283 onos_ctrl = OnosCtrl(app)
284 if deactivate is True:
285 onos_ctrl.deactivate()
286 else:
287 onos_ctrl.activate()
288 time.sleep(3)
289
290 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700291 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
292 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
293 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
294 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700295 cls.start_onos(network_cfg = vrouter_configs)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700296 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700297 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700298 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700299 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700300
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700301 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700302 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700303 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700304 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700305 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700306 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700307 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700308 def recv_task():
309 def recv_cb(pkt):
310 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700311 self.success = True if positive_test else False
312 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700313 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 -0700314 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700315 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700316
317 t = threading.Thread(target = recv_task)
318 t.start()
319 L2 = Ether(src = src_mac, dst = dst_mac)
320 L3 = IP(src = src_ip, dst = dst_ip)
321 pkt = L2/L3
322 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 -0700323 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700324 while self.start_sending is True:
325 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700326 t.join()
327 assert_equal(self.success, True)
328
ChetanGaonker70820bb2016-06-29 18:11:57 -0700329 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
330 if peer_address is None:
331 peers = len(self.peer_list)
332 peer_list = self.peer_list
333 else:
334 peers = len(peer_address)
335 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700336 egress = peers + 1
337 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700338 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700339 src_mac = '00:00:00:00:00:02'
340 src_ip = '1.1.1.1'
341 if self.network_mask != 24:
342 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700343 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700344 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700345 octets = network.split('.')
346 for i in xrange(num_ips):
347 octets[-1] = str(int(octets[-1]) + 1)
348 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700349 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700350 port = (num % peers)
351 ingress = port + 1
352 #Since peers are on the same network
353 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700354 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700355 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700356
ChetanGaonker70820bb2016-06-29 18:11:57 -0700357 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
358 start_network = None, start_peer_address = None, route_update = None,
359 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
360 deactivate_activate_vrouter = None, adding_new_routes = None):
361
362 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
363 peer_address = start_peer_address,
364 route_update = route_update,
365 router_address = start_network,
366 time_expire = time_expire,
367 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700368 self.cliEnter()
369 ##Now verify
370 hosts = json.loads(self.cli.hosts(jsonFormat = True))
371 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700372 ##We read from cli if we expect less number of routes to avoid cli timeouts
373 if networks <= 10000:
374 routes = json.loads(self.cli.routes(jsonFormat = True))
375 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700376 if start_network is not None:
377 if start_network.split('/')[1] is 24:
378 assert_equal(len(routes['routes4']), networks)
379 if start_network.split('/')[1] is not 24:
380 assert_equal(len(routes['routes4']), 1)
381 if start_network is None and invalid_peers is None:
382 assert_equal(len(routes['routes4']), networks)
383 if invalid_peers is not None:
384 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700385 flows = json.loads(self.cli.flows(jsonFormat = True))
386 flows = filter(lambda f: f['flows'], flows)
387 #log.info('Flows: %s' %flows)
388 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700389 if invalid_peers is None:
390 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700391 if positive_test is False:
392 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700393 if time_expire is True:
394 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
395 self.vrouter_traffic_verify()
396 if unreachable_route_traffic is True:
397 network_list_backup = self.network_list
398 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
399 self.vrouter_traffic_verify(positive_test = False)
400 self.network_list = network_list_backup
401 if deactivate_activate_vrouter is True:
402 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
403 self.vrouter_activate(deactivate = True)
404 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
405 #assert_equal(len(routes['routes4']), 'Command not found')
406 log.info('Activating vrouter app again in ONOS controller for negative scenario')
407 self.vrouter_activate(deactivate = False)
408 routes = json.loads(self.cli.routes(jsonFormat = True))
409 assert_equal(len(routes['routes4']), networks)
410 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700411 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700412 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700413 return True
414
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700415 def __vrouter_network_verify_negative(self, networks, peers = 1):
416 ##Stop quagga. Test traffic again to see if flows were removed
417 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700418 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700419 if networks <= 10000:
420 routes = json.loads(self.cli.routes(jsonFormat = True))
421 #Verify routes have been removed
422 if routes and routes.has_key('routes4'):
423 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700424 self.vrouter_traffic_verify(positive_test = False)
425 log.info('OVS flows have been removed successfully after Quagga was stopped')
426 self.start_quagga(networks = networks)
427 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700428 if networks <= 10000:
429 routes = json.loads(self.cli.routes(jsonFormat = True))
430 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700431 self.vrouter_traffic_verify()
432 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
433
ChetanGaonker70820bb2016-06-29 18:11:57 -0700434 def quagga_shell(self, cmd):
435 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
436 quagga_cmd = ' -c '.join(shell_cmds)
437 return cord_test_quagga_shell(quagga_cmd)
438
439 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700440 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700441 assert_equal(res, True)
442
ChetanGaonker70820bb2016-06-29 18:11:57 -0700443 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700444 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700445 assert_equal(res, True)
446
ChetanGaonker70820bb2016-06-29 18:11:57 -0700447 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700448 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700449 assert_equal(res, True)
450
ChetanGaonker70820bb2016-06-29 18:11:57 -0700451 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700452 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700453 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700454
ChetanGaonker70820bb2016-06-29 18:11:57 -0700455 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700456 res = self.__vrouter_network_verify(50, peers = 5)
457 assert_equal(res, True)
458
ChetanGaonker70820bb2016-06-29 18:11:57 -0700459 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700460 res = self.__vrouter_network_verify(100, peers = 1)
461 assert_equal(res, True)
462
ChetanGaonker70820bb2016-06-29 18:11:57 -0700463 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700464 res = self.__vrouter_network_verify(100, peers = 10)
465 assert_equal(res, True)
466
ChetanGaonker70820bb2016-06-29 18:11:57 -0700467 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700468 res = self.__vrouter_network_verify(300, peers = 1)
469 assert_equal(res, True)
470
ChetanGaonker70820bb2016-06-29 18:11:57 -0700471 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700472 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700473 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700474
ChetanGaonker70820bb2016-06-29 18:11:57 -0700475 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700476 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700477 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700478
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700479 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700480 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700481 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700482 assert_equal(res, True)
483
484 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700485 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700486 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700487 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700488
ChetanGaonker70820bb2016-06-29 18:11:57 -0700489 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700490 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
491
ChetanGaonker70820bb2016-06-29 18:11:57 -0700492 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700493 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700494
495 def test_vrouter_with_route_update(self):
496 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
497 assert_equal(res, True)
498 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
499 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
500 start_peer_address = peer_info, route_update = True)
501 assert_equal(res, True)
502
503 def test_vrouter_with_classA_route_update(self):
504 router_address = '11.10.10.0/8'
505 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
506 assert_equal(res, True)
507
508 def test_vrouter_with_classB_route_update(self):
509 router_address = '11.10.10.0/16'
510 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
511 assert_equal(res, True)
512
513 def test_vrouter_with_classless_route_update(self):
514 router_address = '11.10.10.0/12'
515 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
516 assert_equal(res, True)
517
518 def test_vrouter_with_classA_duplicate_route_update(self):
519 router_address = '11.10.10.0/8'
520 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
521 assert_equal(res, True)
522
523 def test_vrouter_with_classB_duplicate_route_update(self):
524 router_address = '11.10.10.0/16'
525 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
526 assert_equal(res, True)
527
528 def test_vrouter_with_classless_duplicate_route_update(self):
529 router_address = '11.10.10.0/12'
530 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
531 assert_equal(res, True)
532
533 def test_vrouter_with_invalid_peers(self):
534 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
535 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
536 start_peer_address = peer_info, invalid_peers= True)
537 assert_equal(res, True)
538
539 @nottest
540 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
541 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
542 assert_equal(res, True)
543
544 @nottest
545 def test_vrouter_with_routes_time_expire(self):
546 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
547 assert_equal(res, True)
548
549 def test_vrouter_with_unreachable_route(self):
550 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
551 assert_equal(res, True)
552
553 @nottest
554 def test_vrouter_with_enabling_disabling_vrouter_app(self):
555 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
556 assert_equal(res, True)
557
558 def test_vrouter_with_adding_new_routes_in_routing_table(self):
559 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
560 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
561 self.quagga_shell(cmd)
562 self.vrouter_traffic_verify()
563 self.network_list = [ '21.10.20.0' ]
564 self.network_mask = 24
565 self.vrouter_traffic_verify()
566 assert_equal(res, True)
567
568 def test_vrouter_with_removing_old_routes_in_routing_table(self):
569 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
570 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
571 self.quagga_shell(cmd)
572 self.vrouter_traffic_verify()
573 old_network_list = self.network_list
574 old_network_mask = self.network_mask
575 self.network_list = [ '21.10.20.0' ]
576 self.network_mask = 24
577 self.vrouter_traffic_verify()
578 assert_equal(res, True)
579 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
580 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700581 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700582 self.vrouter_traffic_verify(positive_test = False)
583 self.network_mask = old_network_mask
584 self.network_list = old_network_list
585 self.vrouter_traffic_verify(positive_test = True)
586
587 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
588 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
589 router_address = '11.10.10.0/24'
590 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
591 start_peer_address = peer_info, start_network = router_address)
592 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
593 self.quagga_shell(cmd)
594 self.vrouter_traffic_verify(positive_test = True)
595 assert_equal(res, True)
596
597
598 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
599 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
600 router_address = '11.10.10.0/24'
601 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
602 start_peer_address = peer_info, start_network = router_address)
603 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
604 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700605 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700606 self.vrouter_traffic_verify(positive_test = False)
607 assert_equal(res, True)
608
609 def test_vrouter_deleting_some_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(10, peers = 2, positive_test = True,
613 start_peer_address = peer_info, start_network = router_address)
614 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
615 self.quagga_shell(cmd)
616 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
617 self.quagga_shell(cmd)
618 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
619 self.quagga_shell(cmd)
620 self.vrouter_traffic_verify(positive_test = True)
621 assert_equal(res, True)
622
623
624 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
625 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
626 router_address = '11.10.10.0/24'
627 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, 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 = 'ip route 11.10.10.0/24 192.168.10.1'
631 self.quagga_shell(cmd)
632 self.vrouter_traffic_verify(positive_test = True)
633 assert_equal(res, True)
634
635 def test_vrouter_toggling_nexthop_interface(self):
636 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
637 router_address = '11.10.10.0/24'
638 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 -0700639 iface = self.port_map[1]
640 #toggle the interface to trigger host removal.
641 cmds = ('ifconfig {} down'.format(iface),
642 'sleep 2',
643 'ifconfig {} 0'.format(iface),)
644 for cmd in cmds:
645 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700646 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700647 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700648 cmd = 'ifconfig {0} {1} up'.format(iface, host)
649 os.system(cmd)
650 #wait for arp refresh
651 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700652 self.vrouter_traffic_verify(positive_test = True)
653 assert_equal(res, True)
654
655
656