blob: 7554ddb80564af291b743a129504c0770d97e88a [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# 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
16
A R Karthick81acbff2016-06-17 14:45:16 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
A R Karthick81acbff2016-06-17 14:45:16 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick81acbff2016-06-17 14:45:16 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
Chetan Gaonker3533faa2016-04-25 17:50:14 -070032import unittest
33from nose.tools import *
34from scapy.all import *
A R Karthick76a497a2017-04-12 10:59:39 -070035from CordTestUtils import get_mac, log_test
A.R Karthickbe7768c2017-03-17 11:39:41 -070036from OnosCtrl import OnosCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070037from OltConfig import OltConfig
A R Karthickb03cecd2016-07-27 10:27:55 -070038from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070039from onosclidriver import OnosCliDriver
ChetanGaonker70820bb2016-06-29 18:11:57 -070040#from quaggaclidriver import QuaggaCliDriver
Chetan Gaonker6cf6e472016-04-26 14:41:51 -070041from CordContainer import Container, Onos, Quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -070042from 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 -070043from portmaps import g_subscriber_port_map
A R Karthick9313b762016-11-07 13:14:35 -080044from CordLogger import CordLogger
Chetan Gaonker3533faa2016-04-25 17:50:14 -070045import threading
46import time
47import os
48import json
ChetanGaonker70820bb2016-06-29 18:11:57 -070049import pexpect
50
51#from cli import quagga
52#from quagga import *
53#from cli import requires
54#from cli import system
55#from generic import *
56
A R Karthick76a497a2017-04-12 10:59:39 -070057log_test.setLevel('INFO')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070058
A R Karthick9313b762016-11-07 13:14:35 -080059class vrouter_exchange(CordLogger):
Chetan Gaonker3533faa2016-04-25 17:50:14 -070060
A R Karthick52414732017-01-31 09:59:47 -080061 apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
A R Karthick078e63a2016-07-28 13:59:31 -070062 device_id = 'of:' + get_mac()
Chetan Gaonker3533faa2016-04-25 17:50:14 -070063 vrouter_device_dict = { "devices" : {
64 "{}".format(device_id) : {
65 "basic" : {
66 "driver" : "softrouter"
67 }
68 }
69 },
70 }
71 zebra_conf = '''
72password zebra
73log stdout
74service advanced-vty
75!
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -070076!debug zebra rib
77!debug zebra kernel
78!debug zebra fpm
Chetan Gaonker3533faa2016-04-25 17:50:14 -070079!
80!interface eth1
81! ip address 10.10.0.3/16
82line vty
83 exec-timeout 0 0
84'''
85 test_path = os.path.dirname(os.path.realpath(__file__))
86 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
87 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070088 GATEWAY = '192.168.10.50'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -070089 INGRESS_PORT = 1
90 EGRESS_PORT = 2
Chetan Gaonker3533faa2016-04-25 17:50:14 -070091 MAX_PORTS = 100
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -070092 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 -070093 network_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -070094 network_mask = 24
95 default_routes_address = ('11.10.10.0/24',)
96 default_peer_address = peer_list
97 quagga_ip = os.getenv('QUAGGA_IP')
Chetan Gaonker3533faa2016-04-25 17:50:14 -070098
99 @classmethod
100 def setUpClass(cls):
101 ''' Activate the vrouter apps'''
102 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -0700103 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700104 if not cls.port_map:
105 cls.port_map = g_subscriber_port_map
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700106 time.sleep(3)
A R Karthickb03cecd2016-07-27 10:27:55 -0700107 cls.load_device_id()
A R Karthick81acbff2016-06-17 14:45:16 -0700108
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700109 @classmethod
110 def tearDownClass(cls):
111 '''Deactivate the vrouter apps'''
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700112 #cls.vrouter_host_unload()
A R Karthick4e0c0912016-08-17 16:57:42 -0700113 cls.start_onos(network_cfg = {})
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700114
A R Karthickb03cecd2016-07-27 10:27:55 -0700115 @classmethod
116 def load_device_id(cls):
117 did = OnosCtrl.get_device_id()
118 cls.device_id = did
119 cls.vrouter_device_dict = { "devices" : {
120 "{}".format(did) : {
121 "basic" : {
122 "driver" : "softrouter"
123 }
124 }
125 },
126 }
127
A R Karthick52414732017-01-31 09:59:47 -0800128 @classmethod
129 def activate_apps(cls, deactivate = False):
130 for app in cls.apps:
131 onos_ctrl = OnosCtrl(app)
132 if deactivate is False:
133 onos_ctrl.activate()
134 else:
135 onos_ctrl.deactivate()
136 time.sleep(2)
137
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700138 def cliEnter(self):
139 retries = 0
140 while retries < 3:
141 self.cli = OnosCliDriver(connect = True)
142 if self.cli.handle:
143 break
144 else:
145 retries += 1
146 time.sleep(2)
147
148 def cliExit(self):
149 self.cli.disconnect()
150
151 @classmethod
152 def onos_load_config(cls, config):
153 status, code = OnosCtrl.config(config)
154 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700155 log_test.info('JSON request returned status %d' %code)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156 assert_equal(status, True)
157
158 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700159 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
160 route_update = None, router_address = None):
161 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
162 peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700163 return vrouter_configs
164 ##ONOS router does not support dynamic reconfigurations
165 #for config in vrouter_configs:
166 # cls.onos_load_config(config)
167 # time.sleep(5)
168
169 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700170 def vrouter_host_load(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700171 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700172 peer_info = peer_address if peer_address is not None else cls.peer_list
173
174 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700175 iface = cls.port_map[index]
176 index += 1
A R Karthick76a497a2017-04-12 10:59:39 -0700177 log_test.info('Assigning ip %s to interface %s' %(host, iface))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700178 config_cmds = ( 'ifconfig {} 0'.format(iface),
179 'ifconfig {0} {1}'.format(iface, host),
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700180 'arping -I {0} {1} -c 2'.format(iface, host),
181 )
182 for cmd in config_cmds:
183 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700184
185 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700186 def vrouter_host_unload(cls, peer_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700187 index = 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700188 peer_info = peer_address if peer_address is not None else cls.peer_list
189
190 for host,_ in peer_info:
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700191 iface = cls.port_map[index]
192 index += 1
193 config_cmds = ('ifconfig {} 0'.format(iface), )
194 for cmd in config_cmds:
195 os.system(cmd)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700196
197 @classmethod
198 def start_onos(cls, network_cfg = None):
199 if type(network_cfg) is tuple:
200 res = []
201 for v in network_cfg:
202 res += v.items()
203 config = dict(res)
204 else:
205 config = network_cfg
A R Karthick76a497a2017-04-12 10:59:39 -0700206 log_test.info('Restarting ONOS with new network configuration')
A R Karthick81acbff2016-06-17 14:45:16 -0700207 return cord_test_onos_restart(config = config)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700208
209 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700210 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
A R Karthick76a497a2017-04-12 10:59:39 -0700211 log_test.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker70820bb2016-06-29 18:11:57 -0700212 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonkerfd3d6502016-05-03 13:23:07 -0700213 if networks <= 10000:
214 boot_delay = 25
215 else:
Chetan Gaonker37ad23f2016-05-03 17:37:59 -0700216 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
217 n = min(networks/100000, len(delay_map)-1)
218 boot_delay = delay_map[n]
A R Karthick81acbff2016-06-17 14:45:16 -0700219 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700220
221 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700222 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700223 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700224 if peer_address is None:
225 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
226 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
227 else:
228 ip = peer_address[0][0]
229 start_ip = ip.split('.')
230 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
231 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 -0700232 local_network = end_peer + 1
233 ports_dict = { 'ports' : {} }
234 interface_list = []
235 peer_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700236 for n in xrange(start_peer, end_peer, 256):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700237 port_map = ports_dict['ports']
238 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
239 device_port_key = '{0}/{1}'.format(cls.device_id, port)
240 try:
241 interfaces = port_map[device_port_key]['interfaces']
242 except:
243 port_map[device_port_key] = { 'interfaces' : [] }
244 interfaces = port_map[device_port_key]['interfaces']
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700245 ip = n + 2
246 peer_ip = n + 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700247 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700248 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
249 mac = RandMAC()._fix()
250 peer_list.append((peer, mac))
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700251 if num < cls.MAX_PORTS - 1:
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700252 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700253 interfaces.append(interface_dict)
254 interface_list.append(interface_dict['name'])
255 else:
256 interfaces[0]['ips'].append(ips)
257 num += 1
258 if num == peers:
259 break
260 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
261 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
262 quagga_router_dict['ospfEnabled'] = True
263 quagga_router_dict['interfaces'] = interface_list
264 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
265
266 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
267 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
268 speaker_dict = {}
269 speaker_dict['name'] = 'bgp{}'.format(peers+1)
270 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
271 speaker_dict['peers'] = peer_list
272 bgp_speakers_list.append(speaker_dict)
273 cls.peer_list = peer_list
274 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
275
276 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700277 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700278 num = 0
ChetanGaonker70820bb2016-06-29 18:11:57 -0700279 if router_address is None:
280 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
281 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
282 network_mask = 24
283 else:
284 ip = router_address
285 start_ip = ip.split('.')
286 network_mask = int(start_ip[3].split('/')[1])
287 start_ip[3] = (start_ip[3].split('/'))[0]
288 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
289 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700290 net_list = []
ChetanGaonker70820bb2016-06-29 18:11:57 -0700291 peer_list = peer_address if peer_address is not None else cls.peer_list
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700292 network_list = []
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700293 for n in xrange(start_network, end_network, 256):
294 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
295 network_list.append(net)
296 gateway = peer_list[num % len(peer_list)][0]
ChetanGaonker70820bb2016-06-29 18:11:57 -0700297 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700298 net_list.append(net_route)
299 num += 1
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700300 if num == networks:
301 break
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700302 cls.network_list = network_list
ChetanGaonker70820bb2016-06-29 18:11:57 -0700303 cls.network_mask = network_mask
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700304 zebra_routes = '\n'.join(net_list)
A R Karthick76a497a2017-04-12 10:59:39 -0700305 #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700306 return cls.zebra_conf + zebra_routes
A R Karthick81acbff2016-06-17 14:45:16 -0700307
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700308 @classmethod
309 def vrouter_activate(cls, deactivate = False):
310 app = 'org.onosproject.vrouter'
311 onos_ctrl = OnosCtrl(app)
312 if deactivate is True:
313 onos_ctrl.deactivate()
314 else:
315 onos_ctrl.activate()
316 time.sleep(3)
317
318 @classmethod
ChetanGaonker70820bb2016-06-29 18:11:57 -0700319 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
320 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
321 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
322 peer_address = peer_address, route_update = route_update)
Chetan Gaonker46b62d52016-04-26 10:08:42 -0700323 cls.start_onos(network_cfg = vrouter_configs)
A R Karthick52414732017-01-31 09:59:47 -0800324 cls.activate_apps()
325 time.sleep(5)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700326 cls.vrouter_host_load()
Chetan Gaonker02236ba2016-04-26 11:24:34 -0700327 ##Start quagga
ChetanGaonker70820bb2016-06-29 18:11:57 -0700328 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700329 return vrouter_configs
A R Karthick81acbff2016-06-17 14:45:16 -0700330
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700331 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700332 src_mac = '00:00:00:00:00:02'
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700333 src_ip = '1.1.1.1'
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700334 self.success = False if positive_test else True
Chetan Gaonker68d95172016-05-03 11:16:59 -0700335 timeout = 10 if positive_test else 1
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700336 count = 2 if positive_test else 1
Chetan Gaonker68d95172016-05-03 11:16:59 -0700337 self.start_sending = True
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700338 def recv_task():
339 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700340 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700341 self.success = True if positive_test else False
342 sniff(count=count, timeout=timeout,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700343 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 -0700344 prn = recv_cb, iface = self.port_map[ingress])
Chetan Gaonker68d95172016-05-03 11:16:59 -0700345 self.start_sending = False
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700346
347 t = threading.Thread(target = recv_task)
348 t.start()
349 L2 = Ether(src = src_mac, dst = dst_mac)
350 L3 = IP(src = src_ip, dst = dst_ip)
351 pkt = L2/L3
A R Karthick76a497a2017-04-12 10:59:39 -0700352 log_test.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 -0700353 (dst_ip, dst_mac, self.port_map[egress]))
Chetan Gaonker68d95172016-05-03 11:16:59 -0700354 while self.start_sending is True:
355 sendp(pkt, count=50, iface = self.port_map[egress])
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700356 t.join()
357 assert_equal(self.success, True)
358
ChetanGaonker70820bb2016-06-29 18:11:57 -0700359 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
360 if peer_address is None:
361 peers = len(self.peer_list)
362 peer_list = self.peer_list
363 else:
364 peers = len(peer_address)
365 peer_list = peer_address
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700366 egress = peers + 1
367 num = 0
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700368 num_hosts = 5 if positive_test else 1
ChetanGaonker70820bb2016-06-29 18:11:57 -0700369 src_mac = '00:00:00:00:00:02'
370 src_ip = '1.1.1.1'
371 if self.network_mask != 24:
372 peers = 1
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700373 for network in self.network_list:
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700374 num_ips = num_hosts
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700375 octets = network.split('.')
376 for i in xrange(num_ips):
377 octets[-1] = str(int(octets[-1]) + 1)
378 dst_ip = '.'.join(octets)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700379 dst_mac = peer_list[ num % peers ] [1]
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700380 port = (num % peers)
381 ingress = port + 1
382 #Since peers are on the same network
383 ##Verify if flows are setup by sending traffic across
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700384 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700385 num += 1
A R Karthick81acbff2016-06-17 14:45:16 -0700386
ChetanGaonker70820bb2016-06-29 18:11:57 -0700387 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
388 start_network = None, start_peer_address = None, route_update = None,
389 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
390 deactivate_activate_vrouter = None, adding_new_routes = None):
391
392 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
393 peer_address = start_peer_address,
394 route_update = route_update,
395 router_address = start_network,
396 time_expire = time_expire,
397 adding_new_routes = adding_new_routes)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700398 self.cliEnter()
399 ##Now verify
400 hosts = json.loads(self.cli.hosts(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700401 log_test.info('Discovered hosts: %s' %hosts)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700402 ##We read from cli if we expect less number of routes to avoid cli timeouts
403 if networks <= 10000:
404 routes = json.loads(self.cli.routes(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700405 #log_test.info('Routes: %s' %routes)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700406 if start_network is not None:
407 if start_network.split('/')[1] is 24:
408 assert_equal(len(routes['routes4']), networks)
409 if start_network.split('/')[1] is not 24:
410 assert_equal(len(routes['routes4']), 1)
411 if start_network is None and invalid_peers is None:
412 assert_equal(len(routes['routes4']), networks)
413 if invalid_peers is not None:
414 assert_equal(len(routes['routes4']), 0)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700415 flows = json.loads(self.cli.flows(jsonFormat = True))
416 flows = filter(lambda f: f['flows'], flows)
A R Karthick76a497a2017-04-12 10:59:39 -0700417 #log_test.info('Flows: %s' %flows)
Chetan Gaonker68d95172016-05-03 11:16:59 -0700418 assert_not_equal(len(flows), 0)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700419 if invalid_peers is None:
420 self.vrouter_traffic_verify()
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700421 if positive_test is False:
422 self.__vrouter_network_verify_negative(networks, peers = peers)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700423 if time_expire is True:
424 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
425 self.vrouter_traffic_verify()
426 if unreachable_route_traffic is True:
427 network_list_backup = self.network_list
428 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
429 self.vrouter_traffic_verify(positive_test = False)
430 self.network_list = network_list_backup
431 if deactivate_activate_vrouter is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700432 log_test.info('Deactivating vrouter app in ONOS controller for negative scenario')
ChetanGaonker70820bb2016-06-29 18:11:57 -0700433 self.vrouter_activate(deactivate = True)
434 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
435 #assert_equal(len(routes['routes4']), 'Command not found')
A R Karthick76a497a2017-04-12 10:59:39 -0700436 log_test.info('Activating vrouter app again in ONOS controller for negative scenario')
ChetanGaonker70820bb2016-06-29 18:11:57 -0700437 self.vrouter_activate(deactivate = False)
438 routes = json.loads(self.cli.routes(jsonFormat = True))
439 assert_equal(len(routes['routes4']), networks)
440 self.vrouter_traffic_verify()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700441 self.cliExit()
Chetan Gaonkerfe551a22016-04-29 17:34:57 -0700442 self.vrouter_host_unload()
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700443 return True
444
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700445 def __vrouter_network_verify_negative(self, networks, peers = 1):
446 ##Stop quagga. Test traffic again to see if flows were removed
A R Karthick76a497a2017-04-12 10:59:39 -0700447 log_test.info('Stopping Quagga container')
A R Karthick4a2362c2016-06-22 17:32:44 -0700448 cord_test_quagga_stop()
Chetan Gaonker68d95172016-05-03 11:16:59 -0700449 if networks <= 10000:
450 routes = json.loads(self.cli.routes(jsonFormat = True))
451 #Verify routes have been removed
452 if routes and routes.has_key('routes4'):
453 assert_equal(len(routes['routes4']), 0)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700454 self.vrouter_traffic_verify(positive_test = False)
A R Karthick76a497a2017-04-12 10:59:39 -0700455 log_test.info('OVS flows have been removed successfully after Quagga was stopped')
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700456 self.start_quagga(networks = networks)
457 ##Verify the flows again after restarting quagga back
Chetan Gaonker68d95172016-05-03 11:16:59 -0700458 if networks <= 10000:
459 routes = json.loads(self.cli.routes(jsonFormat = True))
460 assert_equal(len(routes['routes4']), networks)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700461 self.vrouter_traffic_verify()
A R Karthick76a497a2017-04-12 10:59:39 -0700462 log_test.info('OVS flows have been successfully reinstalled after Quagga was restarted')
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700463
ChetanGaonker70820bb2016-06-29 18:11:57 -0700464 def quagga_shell(self, cmd):
465 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
466 quagga_cmd = ' -c '.join(shell_cmds)
467 return cord_test_quagga_shell(quagga_cmd)
468
469 def test_vrouter_with_5_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700470 res = self.__vrouter_network_verify(5, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700471 assert_equal(res, True)
472
ChetanGaonker70820bb2016-06-29 18:11:57 -0700473 def test_vrouter_with_5_routes_2_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700474 res = self.__vrouter_network_verify(5, peers = 2)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700475 assert_equal(res, True)
476
ChetanGaonker70820bb2016-06-29 18:11:57 -0700477 def test_vrouter_with_6_routes_3_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700478 res = self.__vrouter_network_verify(6, peers = 3)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700479 assert_equal(res, True)
480
ChetanGaonker70820bb2016-06-29 18:11:57 -0700481 def test_vrouter_with_50_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700482 res = self.__vrouter_network_verify(50, peers = 1)
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700483 assert_equal(res, True)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700484
ChetanGaonker70820bb2016-06-29 18:11:57 -0700485 def test_vrouter_with_50_routes_5_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700486 res = self.__vrouter_network_verify(50, peers = 5)
487 assert_equal(res, True)
488
ChetanGaonker70820bb2016-06-29 18:11:57 -0700489 def test_vrouter_with_100_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700490 res = self.__vrouter_network_verify(100, peers = 1)
491 assert_equal(res, True)
492
ChetanGaonker70820bb2016-06-29 18:11:57 -0700493 def test_vrouter_with_100_routes_10_peers(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700494 res = self.__vrouter_network_verify(100, peers = 10)
495 assert_equal(res, True)
496
ChetanGaonker70820bb2016-06-29 18:11:57 -0700497 def test_vrouter_with_300_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700498 res = self.__vrouter_network_verify(300, peers = 1)
499 assert_equal(res, True)
500
ChetanGaonker70820bb2016-06-29 18:11:57 -0700501 def test_vrouter_with_1000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700502 res = self.__vrouter_network_verify(1000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700503 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700504
ChetanGaonker70820bb2016-06-29 18:11:57 -0700505 def test_vrouter_with_10000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700506 res = self.__vrouter_network_verify(10000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700507 assert_equal(res, True)
A R Karthick81acbff2016-06-17 14:45:16 -0700508
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700509 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700510 def test_vrouter_with_100000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700511 res = self.__vrouter_network_verify(100000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700512 assert_equal(res, True)
513
514 @nottest
ChetanGaonker70820bb2016-06-29 18:11:57 -0700515 def test_vrouter_with_1000000_routes(self):
Chetan Gaonker8e25e1b2016-05-02 13:42:21 -0700516 res = self.__vrouter_network_verify(1000000, peers = 1)
Chetan Gaonker6cf6e472016-04-26 14:41:51 -0700517 assert_equal(res, True)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700518
ChetanGaonker70820bb2016-06-29 18:11:57 -0700519 def test_vrouter_with_5_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700520 res = self.__vrouter_network_verify(5, peers = 1, positive_test = False)
521
ChetanGaonker70820bb2016-06-29 18:11:57 -0700522 def test_vrouter_with_50_routes_stopping_quagga(self):
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700523 res = self.__vrouter_network_verify(50, peers = 1, positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700524
525 def test_vrouter_with_route_update(self):
526 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
527 assert_equal(res, True)
528 peer_info = [('192.168.20.1', '00:00:00:00:01:01'), ('192.168.21.1', '00:00:00:00:02:01')]
529 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
530 start_peer_address = peer_info, route_update = True)
531 assert_equal(res, True)
532
533 def test_vrouter_with_classA_route_update(self):
534 router_address = '11.10.10.0/8'
535 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
536 assert_equal(res, True)
537
538 def test_vrouter_with_classB_route_update(self):
539 router_address = '11.10.10.0/16'
540 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
541 assert_equal(res, True)
542
543 def test_vrouter_with_classless_route_update(self):
544 router_address = '11.10.10.0/12'
545 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_network = router_address)
546 assert_equal(res, True)
547
548 def test_vrouter_with_classA_duplicate_route_update(self):
549 router_address = '11.10.10.0/8'
550 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
551 assert_equal(res, True)
552
553 def test_vrouter_with_classB_duplicate_route_update(self):
554 router_address = '11.10.10.0/16'
555 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
556 assert_equal(res, True)
557
558 def test_vrouter_with_classless_duplicate_route_update(self):
559 router_address = '11.10.10.0/12'
560 res = self.__vrouter_network_verify(5, peers = 1, positive_test = True, start_network = router_address)
561 assert_equal(res, True)
562
563 def test_vrouter_with_invalid_peers(self):
564 peer_info = [('239.255.255.250', '00:00:00:00:01:01'), ('239.255.255.240', '00:00:00:00:02:01')]
565 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True,
566 start_peer_address = peer_info, invalid_peers= True)
567 assert_equal(res, True)
568
569 @nottest
570 def test_vrouter_with_traffic_sent_between_peers_connected_to_onos(self):
571 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, traffic_running_between_peers = True)
572 assert_equal(res, True)
573
574 @nottest
575 def test_vrouter_with_routes_time_expire(self):
576 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, time_expire = True)
577 assert_equal(res, True)
578
579 def test_vrouter_with_unreachable_route(self):
580 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, unreachable_route_traffic = True)
581 assert_equal(res, True)
582
583 @nottest
584 def test_vrouter_with_enabling_disabling_vrouter_app(self):
585 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True, deactivate_activate_vrouter = True)
586 assert_equal(res, True)
587
588 def test_vrouter_with_adding_new_routes_in_routing_table(self):
589 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
590 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
591 self.quagga_shell(cmd)
592 self.vrouter_traffic_verify()
593 self.network_list = [ '21.10.20.0' ]
594 self.network_mask = 24
595 self.vrouter_traffic_verify()
596 assert_equal(res, True)
597
598 def test_vrouter_with_removing_old_routes_in_routing_table(self):
599 res = self.__vrouter_network_verify(5, peers = 2, positive_test = True)
600 cmd = 'ip route 21.10.20.0/24 192.168.10.1'
601 self.quagga_shell(cmd)
602 self.vrouter_traffic_verify()
603 old_network_list = self.network_list
604 old_network_mask = self.network_mask
605 self.network_list = [ '21.10.20.0' ]
606 self.network_mask = 24
607 self.vrouter_traffic_verify()
608 assert_equal(res, True)
609 cmd = 'no ip route 21.10.20.0/24 192.168.10.1'
610 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700611 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700612 self.vrouter_traffic_verify(positive_test = False)
613 self.network_mask = old_network_mask
614 self.network_list = old_network_list
615 self.vrouter_traffic_verify(positive_test = True)
616
617 def test_vrouter_modifying_nexthop_route_in_routing_table(self):
618 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
619 router_address = '11.10.10.0/24'
620 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True,
621 start_peer_address = peer_info, start_network = router_address)
622 cmd = 'ip route 11.10.10.0/24 192.168.20.1'
623 self.quagga_shell(cmd)
624 self.vrouter_traffic_verify(positive_test = True)
625 assert_equal(res, True)
626
627
628 def test_vrouter_deleting_alternative_nexthop_in_routing_table(self):
629 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
630 router_address = '11.10.10.0/24'
631 res = self.__vrouter_network_verify(1, peers = 2, positive_test = True,
632 start_peer_address = peer_info, start_network = router_address)
633 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
634 self.quagga_shell(cmd)
A R Karthicka93829a2016-07-01 10:08:23 -0700635 time.sleep(5)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700636 self.vrouter_traffic_verify(positive_test = False)
637 assert_equal(res, True)
638
639 def test_vrouter_deleting_some_routes_in_routing_table(self):
640 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
641 router_address = '11.10.10.0/24'
642 res = self.__vrouter_network_verify(10, peers = 2, positive_test = True,
643 start_peer_address = peer_info, start_network = router_address)
644 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
645 self.quagga_shell(cmd)
646 cmd = 'no ip route 11.10.13.0/24 192.168.11.1'
647 self.quagga_shell(cmd)
648 cmd = 'no ip route 11.10.14.0/24 192.168.10.1'
649 self.quagga_shell(cmd)
650 self.vrouter_traffic_verify(positive_test = True)
651 assert_equal(res, True)
652
653
654 def test_vrouter_deleting_and_adding_routes_in_routing_table(self):
655 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
656 router_address = '11.10.10.0/24'
657 res = self.__vrouter_network_verify(1, peers = 1, positive_test = True, start_peer_address = peer_info, start_network = router_address)
658 cmd = 'no ip route 11.10.10.0/24 192.168.10.1'
659 self.quagga_shell(cmd)
660 cmd = 'ip route 11.10.10.0/24 192.168.10.1'
661 self.quagga_shell(cmd)
662 self.vrouter_traffic_verify(positive_test = True)
663 assert_equal(res, True)
664
665 def test_vrouter_toggling_nexthop_interface(self):
666 peer_info = [('192.168.10.1', '00:00:00:00:01:01'), ('192.168.11.1', '00:00:00:00:02:01')]
667 router_address = '11.10.10.0/24'
668 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 -0700669 iface = self.port_map[1]
670 #toggle the interface to trigger host removal.
671 cmds = ('ifconfig {} down'.format(iface),
672 'sleep 2',
673 'ifconfig {} 0'.format(iface),)
674 for cmd in cmds:
675 os.system(cmd)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700676 self.vrouter_traffic_verify(positive_test = False)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700677 host = "192.168.10.1"
A R Karthicka93829a2016-07-01 10:08:23 -0700678 cmd = 'ifconfig {0} {1} up'.format(iface, host)
679 os.system(cmd)
680 #wait for arp refresh
681 time.sleep(60)
ChetanGaonker70820bb2016-06-29 18:11:57 -0700682 self.vrouter_traffic_verify(positive_test = True)
683 assert_equal(res, True)
A R Karthick8f930292017-07-07 12:36:22 -0700684
685 def vrouter_scale(self, num_routes, peers = 1):
686 '''Called from scale test'''
687 return self.__vrouter_network_verify(num_routes, peers = peers)