blob: 7b416a6198985d6ed556275282d293c11da08748 [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
44 apps = ('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
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700111 def cliEnter(self):
112 retries = 0
113 while retries < 3:
114 self.cli = OnosCliDriver(connect = True)
115 if self.cli.handle:
116 break
117 else:
118 retries += 1
119 time.sleep(2)
120
121 def cliExit(self):
122 self.cli.disconnect()
123
124 @classmethod
125 def onos_load_config(cls, config):
126 status, code = OnosCtrl.config(config)
127 if status is False:
128 log.info('JSON request returned status %d' %code)
129 assert_equal(status, True)
130
131 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700132 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
133 route_update = None, router_address = None):
134 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
135 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700136 return vrouter_configs
137 ##ONOS router does not support dynamic reconfigurations
138 #for config in vrouter_configs:
139 # cls.onos_load_config(config)
140 # time.sleep(5)
141
142 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700143 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700144 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700145 peer_info = peer_address if peer_address is not None else cls.peer_list
146
147 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700148 iface = cls.port_map[index]
149 index += 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700150 log.info('Assigning ip %s to interface %s' %(host, iface))
151 config_cmds = ( 'ifconfig {} 0'.format(iface),
152 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700153 'arping -I {0} {1} -c 2'.format(iface, host),
154 )
155 for cmd in config_cmds:
156 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700157
158 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700159 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700160 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700161 peer_info = peer_address if peer_address is not None else cls.peer_list
162
163 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700164 iface = cls.port_map[index]
165 index += 1
166 config_cmds = ('ifconfig {} 0'.format(iface), )
167 for cmd in config_cmds:
168 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700169
170 @classmethod
171 def start_onos(cls, network_cfg = None):
172 if type(network_cfg) is tuple:
173 res = []
174 for v in network_cfg:
175 res += v.items()
176 config = dict(res)
177 else:
178 config = network_cfg
179 log.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700180 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700181
182 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700183 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700184 log.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700185 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700186 if networks <= 10000:
187 boot_delay = 25
188 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700189 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
190 n = min(networks/100000, len(delay_map)-1)
191 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700192 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700193
194 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700195 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700196 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700197 if peer_address is None:
198 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
199 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
200 else:
201 ip = peer_address[0][0]
202 start_ip = ip.split('.')
203 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
204 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 -0700205 local_network = end_peer + 1
206 ports_dict = { 'ports' : {} }
207 interface_list = []
208 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700209 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700210 port_map = ports_dict['ports']
211 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
212 device_port_key = '{0}/{1}'.format(cls.device_id, port)
213 try:
214 interfaces = port_map[device_port_key]['interfaces']
215 except:
216 port_map[device_port_key] = { 'interfaces' : [] }
217 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700218 ip = n + 2
219 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700220 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700221 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
222 mac = RandMAC()._fix()
223 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700224 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700225 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700226 interfaces.append(interface_dict)
227 interface_list.append(interface_dict['name'])
228 else:
229 interfaces[0]['ips'].append(ips)
230 num += 1
231 if num == peers:
232 break
233 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
234 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
235 quagga_router_dict['ospfEnabled'] = True
236 quagga_router_dict['interfaces'] = interface_list
237 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
238
239 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
240 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
241 speaker_dict = {}
242 speaker_dict['name'] = 'bgp{}'.format(peers+1)
243 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
244 speaker_dict['peers'] = peer_list
245 bgp_speakers_list.append(speaker_dict)
246 cls.peer_list = peer_list
247 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
248
249 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700250 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700251 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700252 if router_address is None:
253 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
254 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
255 network_mask = 24
256 else:
257 ip = router_address
258 start_ip = ip.split('.')
259 network_mask = int(start_ip[3].split('/')[1])
260 start_ip[3] = (start_ip[3].split('/'))[0]
261 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
262 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700263 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700264 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700265 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700266 for n in xrange(start_network, end_network, 256):
267 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
268 network_list.append(net)
269 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700270 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700271 net_list.append(net_route)
272 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700273 if num == networks:
274 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700275 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700276 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700277 zebra_routes = '\n'.join(net_list)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700278 #log.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700279 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700280
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700281 @classmethod
282 def vrouter_activate(cls, deactivate = False):
283 app = 'org.onosproject.vrouter'
284 onos_ctrl = OnosCtrl(app)
285 if deactivate is True:
286 onos_ctrl.deactivate()
287 else:
288 onos_ctrl.activate()
289 time.sleep(3)
290
291 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700292 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
293 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
294 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
295 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700296 cls.start_onos(network_cfg = vrouter_configs)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700297 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700298 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700299 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700300 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700301
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700302 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700303 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700304 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700305 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700306 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700307 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700308 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700309 def recv_task():
310 def recv_cb(pkt):
311 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700312 self.success = True if positive_test else False
313 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700314 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 -0700315 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700316 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700317
318 t = threading.Thread(target = recv_task)
319 t.start()
320 L2 = Ether(src = src_mac, dst = dst_mac)
321 L3 = IP(src = src_ip, dst = dst_ip)
322 pkt = L2/L3
323 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 -0700324 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700325 while self.start_sending is True:
326 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700327 t.join()
328 assert_equal(self.success, True)
329
ChetanGaonker70820bb2016-06-29 18:11:57 -0700330 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
331 if peer_address is None:
332 peers = len(self.peer_list)
333 peer_list = self.peer_list
334 else:
335 peers = len(peer_address)
336 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700337 egress = peers + 1
338 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700339 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700340 src_mac = '00:00:00:00:00:02'
341 src_ip = '1.1.1.1'
342 if self.network_mask != 24:
343 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700344 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700345 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700346 octets = network.split('.')
347 for i in xrange(num_ips):
348 octets[-1] = str(int(octets[-1]) + 1)
349 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700350 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700351 port = (num % peers)
352 ingress = port + 1
353 #Since peers are on the same network
354 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700355 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700356 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700357
ChetanGaonker70820bb2016-06-29 18:11:57 -0700358 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
359 start_network = None, start_peer_address = None, route_update = None,
360 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
361 deactivate_activate_vrouter = None, adding_new_routes = None):
362
363 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
364 peer_address = start_peer_address,
365 route_update = route_update,
366 router_address = start_network,
367 time_expire = time_expire,
368 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700369 self.cliEnter()
370 ##Now verify
371 hosts = json.loads(self.cli.hosts(jsonFormat = True))
372 log.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700373 ##We read from cli if we expect less number of routes to avoid cli timeouts
374 if networks <= 10000:
375 routes = json.loads(self.cli.routes(jsonFormat = True))
376 #log.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700377 if start_network is not None:
378 if start_network.split('/')[1] is 24:
379 assert_equal(len(routes['routes4']), networks)
380 if start_network.split('/')[1] is not 24:
381 assert_equal(len(routes['routes4']), 1)
382 if start_network is None and invalid_peers is None:
383 assert_equal(len(routes['routes4']), networks)
384 if invalid_peers is not None:
385 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700386 flows = json.loads(self.cli.flows(jsonFormat = True))
387 flows = filter(lambda f: f['flows'], flows)
388 #log.info('Flows: %s' %flows)
389 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700390 if invalid_peers is None:
391 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700392 if positive_test is False:
393 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700394 if time_expire is True:
395 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
396 self.vrouter_traffic_verify()
397 if unreachable_route_traffic is True:
398 network_list_backup = self.network_list
399 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
400 self.vrouter_traffic_verify(positive_test = False)
401 self.network_list = network_list_backup
402 if deactivate_activate_vrouter is True:
403 log.info('Deactivating vrouter app in ONOS controller for negative scenario')
404 self.vrouter_activate(deactivate = True)
405 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
406 #assert_equal(len(routes['routes4']), 'Command not found')
407 log.info('Activating vrouter app again in ONOS controller for negative scenario')
408 self.vrouter_activate(deactivate = False)
409 routes = json.loads(self.cli.routes(jsonFormat = True))
410 assert_equal(len(routes['routes4']), networks)
411 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700412 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700413 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700414 return True
415
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700416 def __vrouter_network_verify_negative(self, networks, peers = 1):
417 ##Stop quagga. Test traffic again to see if flows were removed
418 log.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700419 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700420 if networks <= 10000:
421 routes = json.loads(self.cli.routes(jsonFormat = True))
422 #Verify routes have been removed
423 if routes and routes.has_key('routes4'):
424 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700425 self.vrouter_traffic_verify(positive_test = False)
426 log.info('OVS flows have been removed successfully after Quagga was stopped')
427 self.start_quagga(networks = networks)
428 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700429 if networks <= 10000:
430 routes = json.loads(self.cli.routes(jsonFormat = True))
431 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700432 self.vrouter_traffic_verify()
433 log.info('OVS flows have been successfully reinstalled after Quagga was restarted')
434
ChetanGaonker70820bb2016-06-29 18:11:57 -0700435 def quagga_shell(self, cmd):
436 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
437 quagga_cmd = ' -c '.join(shell_cmds)
438 return cord_test_quagga_shell(quagga_cmd)
439
440 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700441 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700442 assert_equal(res, True)
443
ChetanGaonker70820bb2016-06-29 18:11:57 -0700444 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700445 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700446 assert_equal(res, True)
447
ChetanGaonker70820bb2016-06-29 18:11:57 -0700448 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700449 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700450 assert_equal(res, True)
451
ChetanGaonker70820bb2016-06-29 18:11:57 -0700452 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700453 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700454 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700455
ChetanGaonker70820bb2016-06-29 18:11:57 -0700456 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700457 res = self.__vrouter_network_verify(50, peers = 5)
458 assert_equal(res, True)
459
ChetanGaonker70820bb2016-06-29 18:11:57 -0700460 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700461 res = self.__vrouter_network_verify(100, peers = 1)
462 assert_equal(res, True)
463
ChetanGaonker70820bb2016-06-29 18:11:57 -0700464 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700465 res = self.__vrouter_network_verify(100, peers = 10)
466 assert_equal(res, True)
467
ChetanGaonker70820bb2016-06-29 18:11:57 -0700468 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700469 res = self.__vrouter_network_verify(300, peers = 1)
470 assert_equal(res, True)
471
ChetanGaonker70820bb2016-06-29 18:11:57 -0700472 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700473 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700474 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700475
ChetanGaonker70820bb2016-06-29 18:11:57 -0700476 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700477 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700478 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700479
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700480 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700481 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700482 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700483 assert_equal(res, True)
484
485 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700486 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700487 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700488 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700489
ChetanGaonker70820bb2016-06-29 18:11:57 -0700490 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700491 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
492
ChetanGaonker70820bb2016-06-29 18:11:57 -0700493 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700494 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700495
496 def test_vrouter_with_route_update(self):
497 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
498 assert_equal(res, True)
499 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
500 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
501 start_peer_address = peer_info, route_update = True)
502 assert_equal(res, True)
503
504 def test_vrouter_with_classA_route_update(self):
505 router_address = '11.10.10.0/8'
506 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
507 assert_equal(res, True)
508
509 def test_vrouter_with_classB_route_update(self):
510 router_address = '11.10.10.0/16'
511 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
512 assert_equal(res, True)
513
514 def test_vrouter_with_classless_route_update(self):
515 router_address = '11.10.10.0/12'
516 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
517 assert_equal(res, True)
518
519 def test_vrouter_with_classA_duplicate_route_update(self):
520 router_address = '11.10.10.0/8'
521 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
522 assert_equal(res, True)
523
524 def test_vrouter_with_classB_duplicate_route_update(self):
525 router_address = '11.10.10.0/16'
526 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
527 assert_equal(res, True)
528
529 def test_vrouter_with_classless_duplicate_route_update(self):
530 router_address = '11.10.10.0/12'
531 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
532 assert_equal(res, True)
533
534 def test_vrouter_with_invalid_peers(self):
535 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
536 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
537 start_peer_address = peer_info, invalid_peers= True)
538 assert_equal(res, True)
539
540 @nottest
541 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
542 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
543 assert_equal(res, True)
544
545 @nottest
546 def test_vrouter_with_routes_time_expire(self):
547 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
548 assert_equal(res, True)
549
550 def test_vrouter_with_unreachable_route(self):
551 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
552 assert_equal(res, True)
553
554 @nottest
555 def test_vrouter_with_enabling_disabling_vrouter_app(self):
556 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
557 assert_equal(res, True)
558
559 def test_vrouter_with_adding_new_routes_in_routing_table(self):
560 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
561 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
562 self.quagga_shell(cmd)
563 self.vrouter_traffic_verify()
564 self.network_list = [ '21.10.20.0' ]
565 self.network_mask = 24
566 self.vrouter_traffic_verify()
567 assert_equal(res, True)
568
569 def test_vrouter_with_removing_old_routes_in_routing_table(self):
570 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
571 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
572 self.quagga_shell(cmd)
573 self.vrouter_traffic_verify()
574 old_network_list = self.network_list
575 old_network_mask = self.network_mask
576 self.network_list = [ '21.10.20.0' ]
577 self.network_mask = 24
578 self.vrouter_traffic_verify()
579 assert_equal(res, True)
580 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
581 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700582 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700583 self.vrouter_traffic_verify(positive_test = False)
584 self.network_mask = old_network_mask
585 self.network_list = old_network_list
586 self.vrouter_traffic_verify(positive_test = True)
587
588 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
589 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
590 router_address = '11.10.10.0/24'
591 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
592 start_peer_address = peer_info, start_network = router_address)
593 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
594 self.quagga_shell(cmd)
595 self.vrouter_traffic_verify(positive_test = True)
596 assert_equal(res, True)
597
598
599 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
600 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
601 router_address = '11.10.10.0/24'
602 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
603 start_peer_address = peer_info, start_network = router_address)
604 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
605 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700606 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700607 self.vrouter_traffic_verify(positive_test = False)
608 assert_equal(res, True)
609
610 def test_vrouter_deleting_some_routes_in_routing_table(self):
611 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
612 router_address = '11.10.10.0/24'
613 res = self.__vrouter_network_verify(10, peers = 2, positive_test = True,
614 start_peer_address = peer_info, start_network = router_address)
615 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
616 self.quagga_shell(cmd)
617 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
618 self.quagga_shell(cmd)
619 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
620 self.quagga_shell(cmd)
621 self.vrouter_traffic_verify(positive_test = True)
622 assert_equal(res, True)
623
624
625 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
626 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
627 router_address = '11.10.10.0/24'
628 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
629 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
630 self.quagga_shell(cmd)
631 cmd = 'ip route 11.10.10.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 def test_vrouter_toggling_nexthop_interface(self):
637 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
638 router_address = '11.10.10.0/24'
639 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 -0700640 iface = self.port_map[1]
641 #toggle the interface to trigger host removal.
642 cmds = ('ifconfig {} down'.format(iface),
643 'sleep 2',
644 'ifconfig {} 0'.format(iface),)
645 for cmd in cmds:
646 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700647 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700648 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700649 cmd = 'ifconfig {0} {1} up'.format(iface, host)
650 os.system(cmd)
651 #wait for arp refresh
652 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700653 self.vrouter_traffic_verify(positive_test = True)
654 assert_equal(res, True)
655
656
657