blob: 50999003d6b567d54f5a16977eb7974b3960d42d [file] [log] [blame]
ChetanGaonker2099d722016-10-07 15:16:58 -07001#copyright 2016-present Ciena Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15import unittest
16from nose.tools import *
17from scapy.all import *
18from OnosCtrl import OnosCtrl, get_mac
19from OltConfig import OltConfig
20from socket import socket
21from OnosFlowCtrl import OnosFlowCtrl
22from nose.twistedtools import reactor, deferred
23from twisted.internet import defer
24from onosclidriver import OnosCliDriver
25from CordContainer import Container, Onos, Quagga
A.R Karthick2560f042016-11-30 14:38:52 -080026from CordTestServer import cord_test_onos_restart, cord_test_onos_shutdown, cord_test_onos_add_cluster, cord_test_quagga_restart, cord_test_restart_cluster
ChetanGaonker2099d722016-10-07 15:16:58 -070027from portmaps import g_subscriber_port_map
28from scapy.all import *
29import time, monotonic
30import threading
31from threading import current_thread
32from Cluster import *
33from EapTLS import TLSAuthTest
34from ACL import ACLTest
A R Karthick1f908202016-11-16 17:32:20 -080035from OnosLog import OnosLog
36from CordLogger import CordLogger
ChetanGaonker2099d722016-10-07 15:16:58 -070037import os
38import json
39import random
40import collections
41log.setLevel('INFO')
42
A R Karthick1f908202016-11-16 17:32:20 -080043class cluster_exchange(CordLogger):
ChetanGaonker2099d722016-10-07 15:16:58 -070044 test_path = os.path.dirname(os.path.realpath(__file__))
45 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
46 mac = RandMAC()._fix()
47 flows_eth = Ether(src = RandMAC()._fix(), dst = RandMAC()._fix())
48 igmp_eth = Ether(dst = '01:00:5e:00:00:16', type = ETH_P_IP)
49 igmp_ip = IP(dst = '224.0.0.22')
50 ONOS_INSTANCES = 3
51 V_INF1 = 'veth0'
52 TLS_TIMEOUT = 100
53 device_id = 'of:' + get_mac()
54 igmp = cluster_igmp()
55 igmp_groups = igmp.mcast_ip_range(start_ip = '224.1.8.10',end_ip = '224.1.10.49')
56 igmp_sources = igmp.source_ip_range(start_ip = '38.24.29.35',end_ip='38.24.35.56')
57 tls = cluster_tls()
58 flows = cluster_flows()
59 proxyarp = cluster_proxyarp()
60 vrouter = cluster_vrouter()
61 acl = cluster_acl()
62 dhcprelay = cluster_dhcprelay()
63 subscriber = cluster_subscriber()
A.R Karthick2560f042016-11-30 14:38:52 -080064 testcaseLoggers = ('test_cluster_controller_restarts', 'test_cluster_single_controller_restarts', 'test_cluster_restarts')
A R Karthick1f908202016-11-16 17:32:20 -080065
66 def setUp(self):
67 if self._testMethodName not in self.testcaseLoggers:
68 super(cluster_exchange, self).setUp()
69
70 def tearDown(self):
71 if self._testMethodName not in self.testcaseLoggers:
72 super(cluster_exchange, self).tearDown()
ChetanGaonker2099d722016-10-07 15:16:58 -070073
74 def get_controller(self):
75 controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
76 controller = controller.split(',')[0]
77 return controller
78
A R Karthick1f908202016-11-16 17:32:20 -080079 @classmethod
80 def get_controllers(cls):
81 controllers = os.getenv('ONOS_CONTROLLER_IP') or ''
82 return controllers.split(',')
83
ChetanGaonker2099d722016-10-07 15:16:58 -070084 def cliEnter(self,controller = None):
85 retries = 0
86 while retries < 3:
87 self.cli = OnosCliDriver(controller = controller,connect = True)
88 if self.cli.handle:
89 break
90 else:
91 retries += 1
92 time.sleep(2)
93
94 def cliExit(self):
95 self.cli.disconnect()
96
A R Karthick1f908202016-11-16 17:32:20 -080097 def get_leader(self, controller = None):
98 self.cliEnter(controller = controller)
A R Karthickde6b9dc2016-11-29 17:46:16 -080099 try:
100 result = json.loads(self.cli.leaders(jsonFormat = True))
101 except:
102 result = None
103
A R Karthick1f908202016-11-16 17:32:20 -0800104 if result is None:
105 log.info('Leaders command failure for controller %s' %controller)
106 else:
107 log.info('Leaders returned: %s' %result)
108 self.cliExit()
109 return result
110
A R Karthickef1232d2016-12-07 09:18:15 -0800111 def log_set(self, level = "INFO", app = "org.onosproject", controller = None):
112 self.cliEnter(controller = controller)
113 try:
114 self.cli.logSet(level = level, app = app)
115 except: pass
116 self.cliExit()
117
A R Karthick1f908202016-11-16 17:32:20 -0800118 def get_leaders(self, controller = None):
A.R Karthick45ab3e12016-11-30 11:25:51 -0800119 result_map = {}
120 if controller is None:
121 controller = self.get_controller()
A R Karthick1f908202016-11-16 17:32:20 -0800122 if type(controller) in [ list, tuple ]:
123 for c in controller:
124 leaders = self.get_leader(controller = c)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800125 result_map[c] = leaders
A R Karthick1f908202016-11-16 17:32:20 -0800126 else:
127 leaders = self.get_leader(controller = controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800128 result_map[controller] = leaders
129 return result_map
A R Karthick1f908202016-11-16 17:32:20 -0800130
A R Karthickec2db322016-11-17 15:06:01 -0800131 def verify_leaders(self, controller = None):
A.R Karthick45ab3e12016-11-30 11:25:51 -0800132 leaders_map = self.get_leaders(controller = controller)
133 failed = [ k for k,v in leaders_map.items() if v == None ]
A R Karthickec2db322016-11-17 15:06:01 -0800134 return failed
135
ChetanGaonker2099d722016-10-07 15:16:58 -0700136 def verify_cluster_status(self,controller = None,onos_instances=ONOS_INSTANCES,verify=False):
137 tries = 0
138 try:
139 self.cliEnter(controller = controller)
140 while tries <= 10:
141 cluster_summary = json.loads(self.cli.summary(jsonFormat = True))
142 if cluster_summary:
143 log.info("cluster 'summary' command output is %s"%cluster_summary)
144 nodes = cluster_summary['nodes']
145 if verify:
146 if nodes == onos_instances:
147 self.cliExit()
148 return True
149 else:
150 tries += 1
151 time.sleep(1)
152 else:
153 if nodes >= onos_instances:
154 self.cliExit()
155 return True
156 else:
157 tries += 1
158 time.sleep(1)
159 else:
160 tries += 1
161 time.sleep(1)
162 self.cliExit()
163 return False
164 except:
ChetanGaonker689b3862016-10-17 16:25:01 -0700165 raise Exception('Failed to get cluster members')
166 return False
ChetanGaonker2099d722016-10-07 15:16:58 -0700167
A.R Karthick45ab3e12016-11-30 11:25:51 -0800168 def get_cluster_current_member_ips(self, controller = None, nodes_filter = None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700169 tries = 0
170 cluster_ips = []
171 try:
172 self.cliEnter(controller = controller)
173 while tries <= 10:
174 cluster_nodes = json.loads(self.cli.nodes(jsonFormat = True))
175 if cluster_nodes:
176 log.info("cluster 'nodes' output is %s"%cluster_nodes)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800177 if nodes_filter:
178 cluster_nodes = nodes_filter(cluster_nodes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700179 cluster_ips = map(lambda c: c['id'], cluster_nodes)
180 self.cliExit()
181 cluster_ips.sort(lambda i1,i2: int(i1.split('.')[-1]) - int(i2.split('.')[-1]))
182 return cluster_ips
183 else:
184 tries += 1
185 self.cliExit()
186 return cluster_ips
187 except:
188 raise Exception('Failed to get cluster members')
189 return cluster_ips
190
ChetanGaonker689b3862016-10-17 16:25:01 -0700191 def get_cluster_container_names_ips(self,controller=None):
A R Karthick1f908202016-11-16 17:32:20 -0800192 onos_names_ips = {}
193 onos_ips = self.get_cluster_current_member_ips(controller=controller)
194 onos_names_ips[onos_ips[0]] = Onos.NAME
195 onos_names_ips[Onos.NAME] = onos_ips[0]
196 for i in range(1,len(onos_ips)):
197 name = '{0}-{1}'.format(Onos.NAME,i+1)
198 onos_names_ips[onos_ips[i]] = name
199 onos_names_ips[name] = onos_ips[i]
ChetanGaonker2099d722016-10-07 15:16:58 -0700200
201 return onos_names_ips
202
203 #identifying current master of a connected device, not tested
204 def get_cluster_current_master_standbys(self,controller=None,device_id=device_id):
205 master = None
206 standbys = []
207 tries = 0
208 try:
209 cli = self.cliEnter(controller = controller)
210 while tries <= 10:
211 roles = json.loads(self.cli.roles(jsonFormat = True))
212 log.info("cluster 'roles' command output is %s"%roles)
213 if roles:
214 for device in roles:
215 log.info('Verifying device info in line %s'%device)
216 if device['id'] == device_id:
217 master = str(device['master'])
218 standbys = map(lambda d: str(d), device['standbys'])
219 log.info('Master and standbys for device %s are %s and %s'%(device_id, master, standbys))
220 self.cliExit()
221 return master, standbys
222 self.cliExit()
223 return master, standbys
224 else:
225 tries += 1
ChetanGaonker689b3862016-10-17 16:25:01 -0700226 time.sleep(1)
227 self.cliExit()
228 return master,standbys
229 except:
230 raise Exception('Failed to get cluster members')
231 return master,standbys
232
233 def get_cluster_current_master_standbys_of_connected_devices(self,controller=None):
234 ''' returns master and standbys of all the connected devices to ONOS cluster instance'''
235 device_dict = {}
236 tries = 0
237 try:
238 cli = self.cliEnter(controller = controller)
239 while tries <= 10:
240 device_dict = {}
241 roles = json.loads(self.cli.roles(jsonFormat = True))
242 log.info("cluster 'roles' command output is %s"%roles)
243 if roles:
244 for device in roles:
245 device_dict[str(device['id'])]= {'master':str(device['master']),'standbys':device['standbys']}
246 for i in range(len(device_dict[device['id']]['standbys'])):
247 device_dict[device['id']]['standbys'][i] = str(device_dict[device['id']]['standbys'][i])
248 log.info('master and standbys for device %s are %s and %s'%(device['id'],device_dict[device['id']]['master'],device_dict[device['id']]['standbys']))
249 self.cliExit()
250 return device_dict
251 else:
252 tries += 1
ChetanGaonker2099d722016-10-07 15:16:58 -0700253 time.sleep(1)
254 self.cliExit()
ChetanGaonker689b3862016-10-17 16:25:01 -0700255 return device_dict
256 except:
257 raise Exception('Failed to get cluster members')
258 return device_dict
259
260 #identify current master of a connected device, not tested
261 def get_cluster_connected_devices(self,controller=None):
262 '''returns all the devices connected to ONOS cluster'''
263 device_list = []
264 tries = 0
265 try:
266 cli = self.cliEnter(controller = controller)
267 while tries <= 10:
268 device_list = []
269 devices = json.loads(self.cli.devices(jsonFormat = True))
270 log.info("cluster 'devices' command output is %s"%devices)
271 if devices:
272 for device in devices:
273 log.info('device id is %s'%device['id'])
274 device_list.append(str(device['id']))
275 self.cliExit()
276 return device_list
277 else:
278 tries += 1
279 time.sleep(1)
280 self.cliExit()
281 return device_list
282 except:
283 raise Exception('Failed to get cluster members')
284 return device_list
285
286 def get_number_of_devices_of_master(self,controller=None):
287 '''returns master-device pairs, which master having what devices'''
288 master_count = {}
289 try:
290 cli = self.cliEnter(controller = controller)
291 masters = json.loads(self.cli.masters(jsonFormat = True))
292 if masters:
293 for master in masters:
294 master_count[str(master['id'])] = {'size':int(master['size']),'devices':master['devices']}
295 return master_count
296 else:
297 return master_count
ChetanGaonker2099d722016-10-07 15:16:58 -0700298 except:
ChetanGaonker689b3862016-10-17 16:25:01 -0700299 raise Exception('Failed to get cluster members')
300 return master_count
ChetanGaonker2099d722016-10-07 15:16:58 -0700301
302 def change_master_current_cluster(self,new_master=None,device_id=device_id,controller=None):
303 if new_master is None: return False
ChetanGaonker689b3862016-10-17 16:25:01 -0700304 self.cliEnter(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700305 cmd = 'device-role' + ' ' + device_id + ' ' + new_master + ' ' + 'master'
306 command = self.cli.command(cmd = cmd, jsonFormat = False)
307 self.cliExit()
308 time.sleep(60)
309 master, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
310 assert_equal(master,new_master)
311 log.info('Cluster master changed to %s successfully'%new_master)
312
ChetanGaonker689b3862016-10-17 16:25:01 -0700313 def withdraw_cluster_current_mastership(self,master_ip=None,device_id=device_id,controller=None):
314 '''current master looses its mastership and hence new master will be elected'''
315 self.cliEnter(controller=controller)
316 cmd = 'device-role' + ' ' + device_id + ' ' + master_ip + ' ' + 'none'
317 command = self.cli.command(cmd = cmd, jsonFormat = False)
318 self.cliExit()
319 time.sleep(60)
320 new_master_ip, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
321 assert_not_equal(new_master_ip,master_ip)
322 log.info('Device-role of device %s successfully changed to none for controller %s'%(device_id,master_ip))
323 log.info('Cluster new master is %s'%new_master_ip)
324 return True
325
A R Karthickec2db322016-11-17 15:06:01 -0800326 def test_cluster_controller_restarts(self):
A R Karthick1f908202016-11-16 17:32:20 -0800327 '''Test the cluster by repeatedly killing the controllers'''
328 controllers = self.get_controllers()
329 ctlr_len = len(controllers)
330 if ctlr_len <= 1:
331 log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
332 assert_greater(ctlr_len, 1)
333
334 #this call would verify the cluster for once
335 onos_map = self.get_cluster_container_names_ips()
336
A R Karthickec2db322016-11-17 15:06:01 -0800337 def check_exception(controller = None):
A R Karthick1f908202016-11-16 17:32:20 -0800338 adjacent_controller = None
339 adjacent_controllers = None
340 if controller:
A.R Karthick45ab3e12016-11-30 11:25:51 -0800341 adjacent_controllers = list(set(controllers) - set([controller]))
342 adjacent_controller = adjacent_controllers[0]
A R Karthick1f908202016-11-16 17:32:20 -0800343 for node in controllers:
344 onosLog = OnosLog(host = node)
345 ##check the logs for storage exception
346 _, output = onosLog.get_log(('ERROR', 'Exception',))
A R Karthickec2db322016-11-17 15:06:01 -0800347 if output and output.find('StorageException$Timeout') >= 0:
348 log.info('\nStorage Exception Timeout found on node: %s\n' %node)
349 log.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
350 log.info('\n' + '-' * 50 + '\n')
A R Karthick1f908202016-11-16 17:32:20 -0800351 log.info('%s' %output)
A R Karthickec2db322016-11-17 15:06:01 -0800352 log.info('\n' + '-' * 50 + '\n')
353 failed = self.verify_leaders(controllers)
354 if failed:
A.R Karthick45ab3e12016-11-30 11:25:51 -0800355 log.info('Leaders command failed on nodes: %s' %failed)
A R Karthickec2db322016-11-17 15:06:01 -0800356 assert_equal(len(failed), 0)
A R Karthick1f908202016-11-16 17:32:20 -0800357 return controller
358
359 try:
A R Karthickec2db322016-11-17 15:06:01 -0800360 ips = self.get_cluster_current_member_ips(controller = adjacent_controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800361 log.info('ONOS cluster formed with controllers: %s' %ips)
A R Karthick1f908202016-11-16 17:32:20 -0800362 st = True
363 except:
364 st = False
365
A R Karthickec2db322016-11-17 15:06:01 -0800366 failed = self.verify_leaders(controllers)
A R Karthick1f908202016-11-16 17:32:20 -0800367 assert_equal(len(failed), 0)
A R Karthick1f908202016-11-16 17:32:20 -0800368 if st is False:
369 log.info('No storage exception and ONOS cluster was not formed successfully')
370 else:
371 controller = None
372
373 return controller
374
375 next_controller = None
376 tries = 10
377 for num in range(tries):
378 index = num % ctlr_len
379 #index = random.randrange(0, ctlr_len)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800380 controller_name = onos_map[controllers[index]] if next_controller is None else onos_map[next_controller]
381 controller = onos_map[controller_name]
382 log.info('ITERATION: %d. Restarting Controller %s' %(num + 1, controller_name))
A R Karthick1f908202016-11-16 17:32:20 -0800383 try:
A R Karthickef1232d2016-12-07 09:18:15 -0800384 #enable debug log for the other controllers before restarting this controller
385 for ctlr in controllers:
386 if ctlr == controller:
387 continue
388 log.info('Enabling DEBUG log for controller: %s' %ctlr)
389 self.log_set(level="DEBUG", controller = ctlr)
390 self.log_set(level="DEBUG", app = "io.atomix", controller = ctlr)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800391 cord_test_onos_restart(node = controller_name, timeout = 0)
A R Karthickef1232d2016-12-07 09:18:15 -0800392 self.log_set(level="DEBUG", controller = controller)
393 self.log_set(level="DEBUG", app = "io.atomix", controller = controller)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800394 time.sleep(60)
A R Karthick1f908202016-11-16 17:32:20 -0800395 except:
396 time.sleep(5)
397 continue
A R Karthickec2db322016-11-17 15:06:01 -0800398 next_controller = check_exception(controller = controller)
A R Karthick1f908202016-11-16 17:32:20 -0800399
A.R Karthick45ab3e12016-11-30 11:25:51 -0800400 def test_cluster_single_controller_restarts(self):
401 '''Test the cluster by repeatedly restarting the same controller'''
402 controllers = self.get_controllers()
403 ctlr_len = len(controllers)
404 if ctlr_len <= 1:
405 log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
406 assert_greater(ctlr_len, 1)
407
408 #this call would verify the cluster for once
409 onos_map = self.get_cluster_container_names_ips()
410
411 def check_exception(controller, inclusive = False):
412 adjacent_controllers = list(set(controllers) - set([controller]))
413 adjacent_controller = adjacent_controllers[0]
414 controller_list = adjacent_controllers if inclusive == False else controllers
415 storage_exceptions = []
416 for node in controller_list:
417 onosLog = OnosLog(host = node)
418 ##check the logs for storage exception
419 _, output = onosLog.get_log(('ERROR', 'Exception',))
420 if output and output.find('StorageException$Timeout') >= 0:
421 log.info('\nStorage Exception Timeout found on node: %s\n' %node)
422 log.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
423 log.info('\n' + '-' * 50 + '\n')
424 log.info('%s' %output)
425 log.info('\n' + '-' * 50 + '\n')
426 storage_exceptions.append(node)
427
428 failed = self.verify_leaders(controller_list)
429 if failed:
430 log.info('Leaders command failed on nodes: %s' %failed)
431 if storage_exceptions:
432 log.info('Storage exception seen on nodes: %s' %storage_exceptions)
433 assert_equal(len(failed), 0)
434 return controller
435
436 for ctlr in controller_list:
437 ips = self.get_cluster_current_member_ips(controller = ctlr,
438 nodes_filter = \
439 lambda nodes: [ n for n in nodes if n['state'] in [ 'ACTIVE', 'READY'] ])
440 log.info('ONOS cluster on node %s formed with controllers: %s' %(ctlr, ips))
441 if controller in ips and inclusive is False:
442 log.info('Controller %s still ACTIVE on Node %s after it was shutdown' %(controller, ctlr))
443 if controller not in ips and inclusive is True:
444 log.info('Controller %s still INACTIVE on Node %s after it was shutdown' %(controller, ctlr))
445
446 return controller
447
448 tries = 10
449 #chose a random controller for shutdown/restarts
450 controller = controllers[random.randrange(0, ctlr_len)]
451 controller_name = onos_map[controller]
452 for num in range(tries):
453 index = num % ctlr_len
454 log.info('ITERATION: %d. Shutting down Controller %s' %(num + 1, controller_name))
455 try:
456 cord_test_onos_shutdown(node = controller_name)
457 time.sleep(20)
458 except:
459 time.sleep(5)
460 continue
461 #check for exceptions on the adjacent nodes
462 check_exception(controller)
463 #Now restart the controller back
464 log.info('Restarting back the controller %s' %controller_name)
465 cord_test_onos_restart(node = controller_name)
466 time.sleep(60)
467 check_exception(controller, inclusive = True)
468
A.R Karthick2560f042016-11-30 14:38:52 -0800469 def test_cluster_restarts(self):
470 '''Test the cluster by repeatedly restarting the entire cluster'''
471 controllers = self.get_controllers()
472 ctlr_len = len(controllers)
473 if ctlr_len <= 1:
474 log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
475 assert_greater(ctlr_len, 1)
476
477 #this call would verify the cluster for once
478 onos_map = self.get_cluster_container_names_ips()
479
480 def check_exception():
481 controller_list = controllers
482 storage_exceptions = []
483 for node in controller_list:
484 onosLog = OnosLog(host = node)
485 ##check the logs for storage exception
486 _, output = onosLog.get_log(('ERROR', 'Exception',))
487 if output and output.find('StorageException$Timeout') >= 0:
488 log.info('\nStorage Exception Timeout found on node: %s\n' %node)
489 log.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
490 log.info('\n' + '-' * 50 + '\n')
491 log.info('%s' %output)
492 log.info('\n' + '-' * 50 + '\n')
493 storage_exceptions.append(node)
494
495 failed = self.verify_leaders(controller_list)
496 if failed:
497 log.info('Leaders command failed on nodes: %s' %failed)
498 if storage_exceptions:
499 log.info('Storage exception seen on nodes: %s' %storage_exceptions)
500 assert_equal(len(failed), 0)
501 return
502
503 for ctlr in controller_list:
504 ips = self.get_cluster_current_member_ips(controller = ctlr,
505 nodes_filter = \
506 lambda nodes: [ n for n in nodes if n['state'] in [ 'ACTIVE', 'READY'] ])
507 log.info('ONOS cluster on node %s formed with controllers: %s' %(ctlr, ips))
508 assert_equal(len(ips), len(controllers))
509
510 tries = 10
511 for num in range(tries):
512 log.info('ITERATION: %d. Restarting cluster with controllers at %s' %(num+1, controllers))
513 try:
514 cord_test_restart_cluster()
515 log.info('Delaying before verifying cluster status')
516 time.sleep(60)
517 except:
518 time.sleep(10)
519 continue
520 #check for exceptions on the adjacent nodes
521 check_exception()
522
ChetanGaonker2099d722016-10-07 15:16:58 -0700523 #pass
ChetanGaonker689b3862016-10-17 16:25:01 -0700524 def test_cluster_formation_and_verification(self,onos_instances = ONOS_INSTANCES):
525 status = self.verify_cluster_status(onos_instances = onos_instances)
526 assert_equal(status, True)
527 log.info('Cluster exists with %d ONOS instances'%onos_instances)
ChetanGaonker2099d722016-10-07 15:16:58 -0700528
529 #nottest cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700530 def test_cluster_adding_members(self, add = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700531 status = self.verify_cluster_status(onos_instances = onos_instances)
532 assert_equal(status, True)
533 onos_ips = self.get_cluster_current_member_ips()
534 onos_instances = len(onos_ips)+add
535 log.info('Adding %d nodes to the ONOS cluster' %add)
536 cord_test_onos_add_cluster(count = add)
537 status = self.verify_cluster_status(onos_instances=onos_instances)
538 assert_equal(status, True)
539
ChetanGaonker689b3862016-10-17 16:25:01 -0700540 def test_cluster_removing_master(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700541 status = self.verify_cluster_status(onos_instances = onos_instances)
542 assert_equal(status, True)
543 master, standbys = self.get_cluster_current_master_standbys()
544 assert_equal(len(standbys),(onos_instances-1))
545 onos_names_ips = self.get_cluster_container_names_ips()
546 master_onos_name = onos_names_ips[master]
547 log.info('Removing cluster current master %s'%(master))
548 cord_test_onos_shutdown(node = master_onos_name)
549 time.sleep(60)
550 onos_instances -= 1
551 status = self.verify_cluster_status(onos_instances = onos_instances,controller=standbys[0])
552 assert_equal(status, True)
553 new_master, standbys = self.get_cluster_current_master_standbys(controller=standbys[0])
554 assert_not_equal(master,new_master)
ChetanGaonker689b3862016-10-17 16:25:01 -0700555 log.info('Successfully removed clusters master instance')
ChetanGaonker2099d722016-10-07 15:16:58 -0700556
ChetanGaonker689b3862016-10-17 16:25:01 -0700557 def test_cluster_removing_one_member(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700558 status = self.verify_cluster_status(onos_instances = onos_instances)
559 assert_equal(status, True)
560 master, standbys = self.get_cluster_current_master_standbys()
561 assert_equal(len(standbys),(onos_instances-1))
562 onos_names_ips = self.get_cluster_container_names_ips()
563 member_onos_name = onos_names_ips[standbys[0]]
564 log.info('Removing cluster member %s'%standbys[0])
565 cord_test_onos_shutdown(node = member_onos_name)
566 time.sleep(60)
567 onos_instances -= 1
568 status = self.verify_cluster_status(onos_instances = onos_instances,controller=master)
569 assert_equal(status, True)
570
ChetanGaonker689b3862016-10-17 16:25:01 -0700571 def test_cluster_removing_two_members(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700572 status = self.verify_cluster_status(onos_instances = onos_instances)
573 assert_equal(status, True)
574 master, standbys = self.get_cluster_current_master_standbys()
575 assert_equal(len(standbys),(onos_instances-1))
576 onos_names_ips = self.get_cluster_container_names_ips()
577 member1_onos_name = onos_names_ips[standbys[0]]
578 member2_onos_name = onos_names_ips[standbys[1]]
579 log.info('Removing cluster member %s'%standbys[0])
580 cord_test_onos_shutdown(node = member1_onos_name)
581 log.info('Removing cluster member %s'%standbys[1])
582 cord_test_onos_shutdown(node = member2_onos_name)
583 time.sleep(60)
584 onos_instances = onos_instances - 2
585 status = self.verify_cluster_status(onos_instances = onos_instances,controller=master)
586 assert_equal(status, True)
587
ChetanGaonker689b3862016-10-17 16:25:01 -0700588 def test_cluster_removing_N_members(self,remove = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700589 status = self.verify_cluster_status(onos_instances = onos_instances)
590 assert_equal(status, True)
591 master, standbys = self.get_cluster_current_master_standbys()
592 assert_equal(len(standbys),(onos_instances-1))
593 onos_names_ips = self.get_cluster_container_names_ips()
594 for i in range(remove):
595 member_onos_name = onos_names_ips[standbys[i]]
596 log.info('Removing onos container with name %s'%standbys[i])
597 cord_test_onos_shutdown(node = member_onos_name)
598 time.sleep(60)
599 onos_instances = onos_instances - remove
600 status = self.verify_cluster_status(onos_instances = onos_instances, controller=master)
601 assert_equal(status, True)
602
603 #nottest test cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700604 def test_cluster_adding_and_removing_members(self,onos_instances = ONOS_INSTANCES , add = 2, remove = 2):
ChetanGaonker2099d722016-10-07 15:16:58 -0700605 status = self.verify_cluster_status(onos_instances = onos_instances)
606 assert_equal(status, True)
607 onos_ips = self.get_cluster_current_member_ips()
608 onos_instances = len(onos_ips)+add
609 log.info('Adding %d ONOS instances to the cluster'%add)
610 cord_test_onos_add_cluster(count = add)
611 status = self.verify_cluster_status(onos_instances=onos_instances)
612 assert_equal(status, True)
613 log.info('Removing %d ONOS instances from the cluster'%remove)
614 for i in range(remove):
615 name = '{}-{}'.format(Onos.NAME, onos_instances - i)
616 log.info('Removing onos container with name %s'%name)
617 cord_test_onos_shutdown(node = name)
618 time.sleep(60)
619 onos_instances = onos_instances-remove
620 status = self.verify_cluster_status(onos_instances=onos_instances)
621 assert_equal(status, True)
622
623 #nottest cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700624 def test_cluster_removing_and_adding_member(self,onos_instances = ONOS_INSTANCES,add = 1, remove = 1):
ChetanGaonker2099d722016-10-07 15:16:58 -0700625 status = self.verify_cluster_status(onos_instances = onos_instances)
626 assert_equal(status, True)
627 onos_ips = self.get_cluster_current_member_ips()
628 onos_instances = onos_instances-remove
629 log.info('Removing %d ONOS instances from the cluster'%remove)
630 for i in range(remove):
631 name = '{}-{}'.format(Onos.NAME, len(onos_ips)-i)
632 log.info('Removing onos container with name %s'%name)
633 cord_test_onos_shutdown(node = name)
634 time.sleep(60)
635 status = self.verify_cluster_status(onos_instances=onos_instances)
636 assert_equal(status, True)
637 log.info('Adding %d ONOS instances to the cluster'%add)
638 cord_test_onos_add_cluster(count = add)
639 onos_instances = onos_instances+add
640 status = self.verify_cluster_status(onos_instances=onos_instances)
641 assert_equal(status, True)
642
ChetanGaonker689b3862016-10-17 16:25:01 -0700643 def test_cluster_restart(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700644 status = self.verify_cluster_status(onos_instances = onos_instances)
645 assert_equal(status, True)
646 log.info('Restarting cluster')
647 cord_test_onos_restart()
648 status = self.verify_cluster_status(onos_instances = onos_instances)
649 assert_equal(status, True)
650
ChetanGaonker689b3862016-10-17 16:25:01 -0700651 def test_cluster_master_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700652 status = self.verify_cluster_status(onos_instances = onos_instances)
653 assert_equal(status, True)
654 master, standbys = self.get_cluster_current_master_standbys()
655 onos_names_ips = self.get_cluster_container_names_ips()
656 master_onos_name = onos_names_ips[master]
657 log.info('Restarting cluster master %s'%master)
658 cord_test_onos_restart(node = master_onos_name)
659 status = self.verify_cluster_status(onos_instances = onos_instances)
660 assert_equal(status, True)
661 log.info('Cluster came up after master restart as expected')
662
663 #test fail. master changing after restart. Need to check correct behavior.
ChetanGaonker689b3862016-10-17 16:25:01 -0700664 def test_cluster_master_ip_after_master_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700665 status = self.verify_cluster_status(onos_instances = onos_instances)
666 assert_equal(status, True)
667 master1, standbys = self.get_cluster_current_master_standbys()
668 onos_names_ips = self.get_cluster_container_names_ips()
669 master_onos_name = onos_names_ips[master1]
670 log.info('Restarting cluster master %s'%master)
671 cord_test_onos_restart(node = master_onos_name)
672 status = self.verify_cluster_status(onos_instances = onos_instances)
673 assert_equal(status, True)
674 master2, standbys = self.get_cluster_current_master_standbys()
675 assert_equal(master1,master2)
676 log.info('Cluster master is same before and after cluster master restart as expected')
677
ChetanGaonker689b3862016-10-17 16:25:01 -0700678 def test_cluster_one_member_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700679 status = self.verify_cluster_status(onos_instances = onos_instances)
680 assert_equal(status, True)
681 master, standbys = self.get_cluster_current_master_standbys()
682 assert_equal(len(standbys),(onos_instances-1))
683 onos_names_ips = self.get_cluster_container_names_ips()
684 member_onos_name = onos_names_ips[standbys[0]]
685 log.info('Restarting cluster member %s'%standbys[0])
686 cord_test_onos_restart(node = member_onos_name)
687 status = self.verify_cluster_status(onos_instances = onos_instances)
688 assert_equal(status, True)
689 log.info('Cluster came up as expected after restarting one member')
690
ChetanGaonker689b3862016-10-17 16:25:01 -0700691 def test_cluster_two_members_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700692 status = self.verify_cluster_status(onos_instances = onos_instances)
693 assert_equal(status, True)
694 master, standbys = self.get_cluster_current_master_standbys()
695 assert_equal(len(standbys),(onos_instances-1))
696 onos_names_ips = self.get_cluster_container_names_ips()
697 member1_onos_name = onos_names_ips[standbys[0]]
698 member2_onos_name = onos_names_ips[standbys[1]]
699 log.info('Restarting cluster members %s and %s'%(standbys[0],standbys[1]))
700 cord_test_onos_restart(node = member1_onos_name)
701 cord_test_onos_restart(node = member2_onos_name)
702 status = self.verify_cluster_status(onos_instances = onos_instances)
703 assert_equal(status, True)
704 log.info('Cluster came up as expected after restarting two members')
705
ChetanGaonker689b3862016-10-17 16:25:01 -0700706 def test_cluster_state_with_N_members_restart(self, members = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700707 status = self.verify_cluster_status(onos_instances = onos_instances)
708 assert_equal(status,True)
709 master, standbys = self.get_cluster_current_master_standbys()
710 assert_equal(len(standbys),(onos_instances-1))
711 onos_names_ips = self.get_cluster_container_names_ips()
712 for i in range(members):
713 member_onos_name = onos_names_ips[standbys[i]]
714 log.info('Restarting cluster member %s'%standbys[i])
715 cord_test_onos_restart(node = member_onos_name)
716
717 status = self.verify_cluster_status(onos_instances = onos_instances)
718 assert_equal(status, True)
719 log.info('Cluster came up as expected after restarting %d members'%members)
720
ChetanGaonker689b3862016-10-17 16:25:01 -0700721 def test_cluster_state_with_master_change(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700722 status = self.verify_cluster_status(onos_instances=onos_instances)
723 assert_equal(status, True)
724 master, standbys = self.get_cluster_current_master_standbys()
725 assert_equal(len(standbys),(onos_instances-1))
ChetanGaonker689b3862016-10-17 16:25:01 -0700726 log.info('Cluster current master of devices is %s'%master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700727 self.change_master_current_cluster(new_master=standbys[0])
728 log.info('Cluster master changed successfully')
729
730 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700731 def test_cluster_with_vrouter_routes_in_cluster_members(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700732 status = self.verify_cluster_status(onos_instances = onos_instances)
733 assert_equal(status, True)
734 onos_ips = self.get_cluster_current_member_ips()
735 self.vrouter.setUpClass()
736 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
737 assert_equal(res, True)
738 for onos_ip in onos_ips:
739 tries = 0
740 flag = False
741 try:
742 self.cliEnter(controller = onos_ip)
743 while tries <= 5:
744 routes = json.loads(self.cli.routes(jsonFormat = True))
745 if routes:
746 assert_equal(len(routes['routes4']), networks)
747 self.cliExit()
748 flag = True
749 break
750 else:
751 tries += 1
752 time.sleep(1)
753 assert_equal(flag, True)
754 except:
755 log.info('Exception occured while checking routes in onos instance %s'%onos_ip)
756 raise
757
758 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700759 def test_cluster_with_vrouter_and_master_down(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700760 status = self.verify_cluster_status(onos_instances = onos_instances)
761 assert_equal(status, True)
762 onos_ips = self.get_cluster_current_member_ips()
763 master, standbys = self.get_cluster_current_master_standbys()
764 onos_names_ips = self.get_cluster_container_names_ips()
765 master_onos_name = onos_names_ips[master]
766 self.vrouter.setUpClass()
767 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
768 assert_equal(res,True)
769 cord_test_onos_shutdown(node = master_onos_name)
770 time.sleep(60)
ChetanGaonker689b3862016-10-17 16:25:01 -0700771 log.info('Verifying vrouter traffic after cluster master is down')
ChetanGaonker2099d722016-10-07 15:16:58 -0700772 self.vrouter.vrouter_traffic_verify()
773
774 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700775 def test_cluster_with_vrouter_and_restarting_master(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700776 status = self.verify_cluster_status(onos_instances = onos_instances)
777 assert_equal(status, True)
778 onos_ips = self.get_cluster_current_member_ips()
779 master, standbys = self.get_cluster_current_master_standbys()
780 onos_names_ips = self.get_cluster_container_names_ips()
781 master_onos_name = onos_names_ips[master]
782 self.vrouter.setUpClass()
783 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
784 assert_equal(res, True)
785 cord_test_onos_restart()
786 self.vrouter.vrouter_traffic_verify()
787
788 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700789 def test_cluster_deactivating_vrouter_app(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700790 status = self.verify_cluster_status(onos_instances = onos_instances)
791 assert_equal(status, True)
792 self.vrouter.setUpClass()
793 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
794 assert_equal(res, True)
795 self.vrouter.vrouter_activate(deactivate=True)
796 time.sleep(15)
797 self.vrouter.vrouter_traffic_verify(positive_test=False)
798 self.vrouter.vrouter_activate(deactivate=False)
799
800 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700801 def test_cluster_deactivating_vrouter_app_and_making_master_down(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700802 status = self.verify_cluster_status(onos_instances = onos_instances)
803 assert_equal(status, True)
804 master, standbys = self.get_cluster_current_master_standbys()
805 onos_names_ips = self.get_cluster_container_names_ips()
806 master_onos_name = onos_names_ips[master]
807 self.vrouter.setUpClass()
808 log.info('Verifying vrouter before master down')
809 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
810 assert_equal(res, True)
811 self.vrouter.vrouter_activate(deactivate=True)
812 log.info('Verifying vrouter traffic after app deactivated')
813 time.sleep(15) ## Expecting vrouter should work properly if master of cluster goes down
814 self.vrouter.vrouter_traffic_verify(positive_test=False)
815 log.info('Verifying vrouter traffic after master down')
816 cord_test_onos_shutdown(node = master_onos_name)
817 time.sleep(60)
818 self.vrouter.vrouter_traffic_verify(positive_test=False)
819 self.vrouter.vrouter_activate(deactivate=False)
820
821 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700822 def test_cluster_for_vrouter_app_and_making_member_down(self, networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700823 status = self.verify_cluster_status(onos_instances = onos_instances)
824 assert_equal(status, True)
825 master, standbys = self.get_cluster_current_master_standbys()
826 onos_names_ips = self.get_cluster_container_names_ips()
827 member_onos_name = onos_names_ips[standbys[0]]
828 self.vrouter.setUpClass()
829 log.info('Verifying vrouter before cluster member down')
830 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
831 assert_equal(res, True) # Expecting vrouter should work properly
832 log.info('Verifying vrouter after cluster member down')
833 cord_test_onos_shutdown(node = member_onos_name)
834 time.sleep(60)
835 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster goes down
836
837 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700838 def test_cluster_for_vrouter_app_and_restarting_member(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700839 status = self.verify_cluster_status(onos_instances = onos_instances)
840 assert_equal(status, True)
841 master, standbys = self.get_cluster_current_master_standbys()
842 onos_names_ips = self.get_cluster_container_names_ips()
843 member_onos_name = onos_names_ips[standbys[1]]
844 self.vrouter.setUpClass()
845 log.info('Verifying vrouter traffic before cluster member restart')
846 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
847 assert_equal(res, True) # Expecting vrouter should work properly
848 cord_test_onos_restart(node = member_onos_name)
849 log.info('Verifying vrouter traffic after cluster member restart')
850 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster restarts
851
852 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700853 def test_cluster_for_vrouter_app_restarting_cluster(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700854 status = self.verify_cluster_status(onos_instances = onos_instances)
855 assert_equal(status, True)
856 self.vrouter.setUpClass()
857 log.info('Verifying vrouter traffic before cluster restart')
858 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
859 assert_equal(res, True) # Expecting vrouter should work properly
860 cord_test_onos_restart()
861 log.info('Verifying vrouter traffic after cluster restart')
862 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster restarts
863
864
865 #test fails because flow state is in pending_add in onos
ChetanGaonker689b3862016-10-17 16:25:01 -0700866 def test_cluster_for_flows_of_udp_port_and_making_master_down(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700867 status = self.verify_cluster_status(onos_instances = onos_instances)
868 assert_equal(status, True)
869 master, standbys = self.get_cluster_current_master_standbys()
870 onos_names_ips = self.get_cluster_container_names_ips()
871 master_onos_name = onos_names_ips[master]
872 self.flows.setUpClass()
873 egress = 1
874 ingress = 2
875 egress_map = { 'ip': '192.168.30.1', 'udp_port': 9500 }
876 ingress_map = { 'ip': '192.168.40.1', 'udp_port': 9000 }
877 flow = OnosFlowCtrl(deviceId = self.device_id,
878 egressPort = egress,
879 ingressPort = ingress,
880 udpSrc = ingress_map['udp_port'],
881 udpDst = egress_map['udp_port'],
882 controller=master
883 )
884 result = flow.addFlow()
885 assert_equal(result, True)
886 time.sleep(1)
887 self.success = False
888 def mac_recv_task():
889 def recv_cb(pkt):
890 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
891 self.success = True
892 sniff(timeout=2,
893 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port']
894 and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.flows.port_map[egress])
895
896 for i in [0,1]:
897 if i == 1:
898 cord_test_onos_shutdown(node = master_onos_name)
899 log.info('Verifying flows traffic after master killed')
900 time.sleep(45)
901 else:
902 log.info('Verifying flows traffic before master killed')
903 t = threading.Thread(target = mac_recv_task)
904 t.start()
905 L2 = self.flows_eth #Ether(src = ingress_map['ether'], dst = egress_map['ether'])
906 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
907 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
908 pkt = L2/L3/L4
909 log.info('Sending packets to verify if flows are correct')
910 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
911 t.join()
912 assert_equal(self.success, True)
913
ChetanGaonker689b3862016-10-17 16:25:01 -0700914 def test_cluster_state_changing_master_and_flows_of_ecn(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700915 status = self.verify_cluster_status(onos_instances=onos_instances)
916 assert_equal(status, True)
917 master, standbys = self.get_cluster_current_master_standbys()
918 self.flows.setUpClass()
919 egress = 1
920 ingress = 2
921 egress_map = { 'ip': '192.168.30.1' }
922 ingress_map = { 'ip': '192.168.40.1' }
923 flow = OnosFlowCtrl(deviceId = self.device_id,
924 egressPort = egress,
925 ingressPort = ingress,
926 ecn = 1,
927 controller=master
928 )
929 result = flow.addFlow()
930 assert_equal(result, True)
931 ##wait for flows to be added to ONOS
932 time.sleep(1)
933 self.success = False
934 def mac_recv_task():
935 def recv_cb(pkt):
936 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
937 self.success = True
938 sniff(count=2, timeout=5,
939 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
940 and int(bin(p[IP].tos).split('b')[1][-2:],2) == 1,prn = recv_cb,
941 iface = self.flows.port_map[egress])
942 for i in [0,1]:
943 if i == 1:
944 log.info('Changing cluster master to %s'%standbys[0])
945 self.change_master_current_cluster(new_master=standbys[0])
946 log.info('Verifying flow traffic after cluster master chnaged')
947 else:
948 log.info('Verifying flow traffic before cluster master changed')
949 t = threading.Thread(target = mac_recv_task)
950 t.start()
951 L2 = self.flows_eth # Ether(src = ingress_map['ether'], dst = egress_map['ether'])
952 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 1)
953 pkt = L2/L3
954 log.info('Sending a packet to verify if flows are correct')
955 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
956 t.join()
957 assert_equal(self.success, True)
958
ChetanGaonker689b3862016-10-17 16:25:01 -0700959 #pass
960 def test_cluster_flow_for_ipv6_extension_header_and_master_restart(self,onos_instances = ONOS_INSTANCES):
961 status = self.verify_cluster_status(onos_instances=onos_instances)
962 assert_equal(status, True)
963 master,standbys = self.get_cluster_current_master_standbys()
964 onos_names_ips = self.get_cluster_container_names_ips()
965 master_onos_name = onos_names_ips[master]
966 self.flows.setUpClass()
967 egress = 1
968 ingress = 2
969 egress_map = { 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
970 ingress_map = { 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
971 flow = OnosFlowCtrl(deviceId = self.device_id,
972 egressPort = egress,
973 ingressPort = ingress,
974 ipv6_extension = 0,
975 controller=master
976 )
977
978 result = flow.addFlow()
979 assert_equal(result, True)
980 ##wait for flows to be added to ONOS
981 time.sleep(1)
982 self.success = False
983 def mac_recv_task():
984 def recv_cb(pkt):
985 log.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s'%(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh))
986 self.success = True
987 sniff(timeout=2,count=5,
988 lfilter = lambda p: IPv6 in p and p[IPv6].nh == 0, prn = recv_cb, iface = self.flows.port_map[egress])
989 for i in [0,1]:
990 if i == 1:
991 log.info('Restart cluster current master %s'%master)
992 Container(master_onos_name,Onos.IMAGE).restart()
993 time.sleep(45)
994 log.info('Verifying flow traffic after master restart')
995 else:
996 log.info('Verifying flow traffic before master restart')
997 t = threading.Thread(target = mac_recv_task)
998 t.start()
999 L2 = self.flows_eth
1000 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = 0)
1001 pkt = L2/L3
1002 log.info('Sending packets to verify if flows are correct')
1003 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
1004 t.join()
1005 assert_equal(self.success, True)
1006
1007 def send_multicast_data_traffic(self, group, intf= 'veth2',source = '1.2.3.4'):
1008 dst_mac = self.igmp.iptomac(group)
1009 eth = Ether(dst= dst_mac)
1010 ip = IP(dst=group,src=source)
1011 data = repr(monotonic.monotonic())
1012 sendp(eth/ip/data,count=20, iface = intf)
1013 pkt = (eth/ip/data)
1014 log.info('multicast traffic packet %s'%pkt.show())
1015
1016 def verify_igmp_data_traffic(self, group, intf='veth0', source='1.2.3.4' ):
1017 log.info('verifying multicast traffic for group %s from source %s'%(group,source))
1018 self.success = False
1019 def recv_task():
1020 def igmp_recv_cb(pkt):
1021 log.info('multicast data received for group %s from source %s'%(group,source))
1022 self.success = True
1023 sniff(prn = igmp_recv_cb,lfilter = lambda p: IP in p and p[IP].dst == group and p[IP].src == source, count=1,timeout = 2, iface='veth0')
1024 t = threading.Thread(target = recv_task)
1025 t.start()
1026 self.send_multicast_data_traffic(group,source=source)
1027 t.join()
1028 return self.success
1029
1030 #pass
1031 def test_cluster_with_igmp_include_exclude_modes_and_restarting_master(self, onos_instances=ONOS_INSTANCES):
1032 status = self.verify_cluster_status(onos_instances=onos_instances)
1033 assert_equal(status, True)
1034 master, standbys = self.get_cluster_current_master_standbys()
1035 assert_equal(len(standbys), (onos_instances-1))
1036 onos_names_ips = self.get_cluster_container_names_ips()
1037 master_onos_name = onos_names_ips[master]
1038 self.igmp.setUp(controller=master)
1039 groups = ['224.2.3.4','230.5.6.7']
1040 src_list = ['2.2.2.2','3.3.3.3']
1041 self.igmp.onos_ssm_table_load(groups, src_list=src_list, controller=master)
1042 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1043 iface = self.V_INF1, delay = 2)
1044 self.igmp.send_igmp_join(groups = [groups[1]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_EXCLUDE,
1045 iface = self.V_INF1, delay = 2)
1046 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1047 assert_equal(status,True)
1048 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[1])
1049 assert_equal(status,False)
1050 log.info('restarting cluster master %s'%master)
1051 Container(master_onos_name,Onos.IMAGE).restart()
1052 time.sleep(60)
1053 log.info('verifying multicast data traffic after master restart')
1054 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1055 assert_equal(status,True)
1056 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[1])
1057 assert_equal(status,False)
1058
1059 #pass
1060 def test_cluster_with_igmp_include_exclude_modes_and_making_master_down(self, onos_instances=ONOS_INSTANCES):
1061 status = self.verify_cluster_status(onos_instances=onos_instances)
1062 assert_equal(status, True)
1063 master, standbys = self.get_cluster_current_master_standbys()
1064 assert_equal(len(standbys), (onos_instances-1))
1065 onos_names_ips = self.get_cluster_container_names_ips()
1066 master_onos_name = onos_names_ips[master]
1067 self.igmp.setUp(controller=master)
1068 groups = [self.igmp.random_mcast_ip(),self.igmp.random_mcast_ip()]
1069 src_list = [self.igmp.randomsourceip()]
1070 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1071 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1072 iface = self.V_INF1, delay = 2)
1073 self.igmp.send_igmp_join(groups = [groups[1]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_EXCLUDE,
1074 iface = self.V_INF1, delay = 2)
1075 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1076 assert_equal(status,True)
1077 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[0])
1078 assert_equal(status,False)
1079 log.info('Killing cluster master %s'%master)
1080 Container(master_onos_name,Onos.IMAGE).kill()
1081 time.sleep(60)
1082 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=standbys[0])
1083 assert_equal(status, True)
1084 log.info('Verifying multicast data traffic after cluster master down')
1085 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1086 assert_equal(status,True)
1087 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[0])
1088 assert_equal(status,False)
1089
1090 def test_cluster_with_igmp_include_mode_checking_traffic_recovery_time_after_master_is_down(self, onos_instances=ONOS_INSTANCES):
1091 status = self.verify_cluster_status(onos_instances=onos_instances)
1092 assert_equal(status, True)
1093 master, standbys = self.get_cluster_current_master_standbys()
1094 assert_equal(len(standbys), (onos_instances-1))
1095 onos_names_ips = self.get_cluster_container_names_ips()
1096 master_onos_name = onos_names_ips[master]
1097 self.igmp.setUp(controller=master)
1098 groups = [self.igmp.random_mcast_ip()]
1099 src_list = [self.igmp.randomsourceip()]
1100 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1101 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1102 iface = self.V_INF1, delay = 2)
1103 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1104 assert_equal(status,True)
1105 log.info('Killing clusters master %s'%master)
1106 Container(master_onos_name,Onos.IMAGE).kill()
1107 count = 0
1108 for i in range(60):
1109 log.info('Verifying multicast data traffic after cluster master down')
1110 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1111 if status:
1112 break
1113 else:
1114 count += 1
1115 time.sleep(1)
1116 assert_equal(status, True)
1117 log.info('Time taken to recover traffic after clusters master down is %d seconds'%count)
1118
1119
1120 #pass
1121 def test_cluster_state_with_igmp_leave_group_after_master_change(self, onos_instances=ONOS_INSTANCES):
1122 status = self.verify_cluster_status(onos_instances=onos_instances)
1123 assert_equal(status, True)
1124 master, standbys = self.get_cluster_current_master_standbys()
1125 assert_equal(len(standbys), (onos_instances-1))
1126 self.igmp.setUp(controller=master)
1127 groups = [self.igmp.random_mcast_ip()]
1128 src_list = [self.igmp.randomsourceip()]
1129 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1130 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1131 iface = self.V_INF1, delay = 2)
1132 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1133 assert_equal(status,True)
1134 log.info('Changing cluster master %s to %s'%(master,standbys[0]))
1135 self.change_cluster_current_master(new_master=standbys[0])
1136 log.info('Verifying multicast traffic after cluster master change')
1137 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1138 assert_equal(status,True)
1139 log.info('Sending igmp TO_EXCLUDE message to leave the group %s'%groups[0])
1140 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_CHANGE_TO_EXCLUDE,
1141 iface = self.V_INF1, delay = 1)
1142 time.sleep(10)
1143 status = self.verify_igmp_data_traffic(groups[0],intf = self.V_INF1,source= src_list[0])
1144 assert_equal(status,False)
1145
1146 #pass
1147 def test_cluster_state_with_igmp_join_before_and_after_master_change(self,onos_instances=ONOS_INSTANCES):
1148 status = self.verify_cluster_status(onos_instances=onos_instances)
1149 assert_equal(status, True)
1150 master,standbys = self.get_cluster_current_master_standbys()
1151 assert_equal(len(standbys), (onos_instances-1))
1152 self.igmp.setUp(controller=master)
1153 groups = [self.igmp.random_mcast_ip()]
1154 src_list = [self.igmp.randomsourceip()]
1155 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1156 log.info('Changing cluster master %s to %s'%(master,standbys[0]))
1157 self.change_cluster_current_master(new_master = standbys[0])
1158 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1159 iface = self.V_INF1, delay = 2)
1160 time.sleep(1)
1161 self.change_cluster_current_master(new_master = master)
1162 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1163 assert_equal(status,True)
1164
1165 #pass
ChetanGaonker2099d722016-10-07 15:16:58 -07001166 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001167 def test_cluster_with_eap_tls_traffic(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001168 status = self.verify_cluster_status(onos_instances=onos_instances)
1169 assert_equal(status, True)
1170 master, standbys = self.get_cluster_current_master_standbys()
1171 assert_equal(len(standbys), (onos_instances-1))
1172 self.tls.setUp(controller=master)
1173 df = defer.Deferred()
1174 def eap_tls_verify(df):
1175 tls = TLSAuthTest()
1176 tls.runTest()
1177 df.callback(0)
1178 reactor.callLater(0, eap_tls_verify, df)
1179 return df
1180
1181 @deferred(120)
ChetanGaonker689b3862016-10-17 16:25:01 -07001182 def test_cluster_for_eap_tls_traffic_before_and_after_master_change(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001183 master, standbys = self.get_cluster_current_master_standbys()
1184 assert_equal(len(standbys), (onos_instances-1))
1185 self.tls.setUp()
1186 df = defer.Deferred()
1187 def eap_tls_verify2(df2):
1188 tls = TLSAuthTest()
1189 tls.runTest()
1190 df.callback(0)
1191 for i in [0,1]:
1192 if i == 1:
1193 log.info('Changing cluster master %s to %s'%(master, standbys[0]))
1194 self.change_master_current_cluster(new_master=standbys[0])
1195 log.info('Verifying tls authentication after cluster master changed to %s'%standbys[0])
1196 else:
1197 log.info('Verifying tls authentication before cluster master change')
1198 reactor.callLater(0, eap_tls_verify, df)
1199 return df
1200
1201 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001202 def test_cluster_for_eap_tls_traffic_before_and_after_making_master_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001203 status = self.verify_cluster_status(onos_instances=onos_instances)
1204 assert_equal(status, True)
1205 master, standbys = self.get_cluster_current_master_standbys()
1206 assert_equal(len(standbys), (onos_instances-1))
1207 onos_names_ips = self.get_cluster_container_names_ips()
1208 master_onos_name = onos_names_ips[master]
1209 self.tls.setUp()
1210 df = defer.Deferred()
1211 def eap_tls_verify(df):
1212 tls = TLSAuthTest()
1213 tls.runTest()
1214 df.callback(0)
1215 for i in [0,1]:
1216 if i == 1:
1217 log.info('Killing cluster current master %s'%master)
1218 cord_test_onos_shutdown(node = master_onos_name)
1219 time.sleep(20)
1220 status = self.verify_cluster_status(controller=standbys[0],onos_instances=onos_instances-1,verify=True)
1221 assert_equal(status, True)
1222 log.info('Cluster came up with %d instances after killing master'%(onos_instances-1))
1223 log.info('Verifying tls authentication after killing cluster master')
1224 reactor.callLater(0, eap_tls_verify, df)
1225 return df
1226
1227 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001228 def test_cluster_for_eap_tls_with_no_cert_before_and_after_member_is_restarted(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001229 status = self.verify_cluster_status(onos_instances=onos_instances)
1230 assert_equal(status, True)
1231 master, standbys = self.get_cluster_current_master_standbys()
1232 assert_equal(len(standbys), (onos_instances-1))
1233 onos_names_ips = self.get_cluster_container_names_ips()
1234 member_onos_name = onos_names_ips[standbys[0]]
1235 self.tls.setUp()
1236 df = defer.Deferred()
1237 def eap_tls_no_cert(df):
1238 def tls_no_cert_cb():
1239 log.info('TLS authentication failed with no certificate')
1240 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
1241 tls.runTest()
1242 assert_equal(tls.failTest, True)
1243 df.callback(0)
1244 for i in [0,1]:
1245 if i == 1:
1246 log.info('Restart cluster member %s'%standbys[0])
1247 Container(member_onos_name,Onos.IMAGE).restart()
1248 time.sleep(20)
1249 status = self.verify_cluster_status(onos_instances=onos_instances)
1250 assert_equal(status, True)
1251 log.info('Cluster came up with %d instances after member restart'%(onos_instances))
1252 log.info('Verifying tls authentication after member restart')
1253 reactor.callLater(0, eap_tls_no_cert, df)
1254 return df
1255
ChetanGaonker689b3862016-10-17 16:25:01 -07001256 #pass
1257 def test_cluster_proxyarp_master_change_and_app_deactivation(self,onos_instances=ONOS_INSTANCES,hosts = 3):
1258 status = self.verify_cluster_status(onos_instances=onos_instances)
1259 assert_equal(status,True)
1260 master,standbys = self.get_cluster_current_master_standbys()
1261 assert_equal(len(standbys),(onos_instances-1))
1262 self.proxyarp.setUpClass()
1263 ports_map, egress_map,hosts_config = self.proxyarp.proxyarp_config(hosts = hosts,controller=master)
1264 ingress = hosts+1
1265 for hostip, hostmac in hosts_config:
1266 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1267 time.sleep(1)
1268 log.info('changing cluster current master from %s to %s'%(master,standbys[0]))
1269 self.change_cluster_current_master(new_master=standbys[0])
1270 log.info('verifying proxyarp after master change')
1271 for hostip, hostmac in hosts_config:
1272 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1273 time.sleep(1)
1274 log.info('Deactivating proxyarp app and expecting proxyarp functionality not to work')
1275 self.proxyarp.proxyarp_activate(deactivate = True,controller=standbys[0])
1276 time.sleep(3)
1277 for hostip, hostmac in hosts_config:
1278 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = False)
1279 time.sleep(1)
1280 log.info('activating proxyarp app and expecting to get arp reply from ONOS')
1281 self.proxyarp.proxyarp_activate(deactivate = False,controller=standbys[0])
1282 time.sleep(3)
1283 for hostip, hostmac in hosts_config:
1284 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1285 time.sleep(1)
ChetanGaonker2099d722016-10-07 15:16:58 -07001286
ChetanGaonker689b3862016-10-17 16:25:01 -07001287 #pass
1288 def test_cluster_with_proxyarp_and_one_member_down(self,hosts=3,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001289 status = self.verify_cluster_status(onos_instances=onos_instances)
1290 assert_equal(status, True)
1291 master, standbys = self.get_cluster_current_master_standbys()
ChetanGaonker689b3862016-10-17 16:25:01 -07001292 assert_equal(len(standbys), (onos_instances-1))
1293 onos_names_ips = self.get_cluster_container_names_ips()
1294 member_onos_name = onos_names_ips[standbys[1]]
1295 self.proxyarp.setUpClass()
1296 ports_map, egress_map,hosts_config = self.proxyarp.proxyarp_config(hosts = hosts,controller=master)
1297 ingress = hosts+1
1298 for hostip, hostmac in hosts_config:
1299 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1300 time.sleep(1)
1301 log.info('killing cluster member %s'%standbys[1])
1302 Container(member_onos_name,Onos.IMAGE).kill()
1303 time.sleep(20)
1304 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=master,verify=True)
1305 assert_equal(status, True)
1306 log.info('cluster came up with %d instances after member down'%(onos_instances-1))
1307 log.info('verifying proxy arp functionality after cluster member down')
1308 for hostip, hostmac in hosts_config:
1309 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1310 time.sleep(1)
1311
1312 #pass
1313 def test_cluster_with_proxyarp_and_concurrent_requests_with_multiple_host_and_different_interfaces(self,hosts=10,onos_instances=ONOS_INSTANCES):
1314 status = self.verify_cluster_status(onos_instances=onos_instances)
1315 assert_equal(status, True)
1316 self.proxyarp.setUpClass()
1317 master, standbys = self.get_cluster_current_master_standbys()
1318 assert_equal(len(standbys), (onos_instances-1))
1319 ports_map, egress_map, hosts_config = self.proxyarp.proxyarp_config(hosts = hosts, controller=master)
1320 self.success = True
1321 ingress = hosts+1
1322 ports = range(ingress,ingress+10)
1323 hostmac = []
1324 hostip = []
1325 for ip,mac in hosts_config:
1326 hostmac.append(mac)
1327 hostip.append(ip)
1328 success_dir = {}
1329 def verify_proxyarp(*r):
1330 ingress, hostmac, hostip = r[0],r[1],r[2]
1331 def mac_recv_task():
1332 def recv_cb(pkt):
1333 log.info('Arp Reply seen with source Mac is %s' %(pkt[ARP].hwsrc))
1334 success_dir[current_thread().name] = True
1335 sniff(count=1, timeout=5,lfilter = lambda p: ARP in p and p[ARP].op == 2 and p[ARP].hwsrc == hostmac,
1336 prn = recv_cb, iface = self.proxyarp.port_map[ingress])
1337 t = threading.Thread(target = mac_recv_task)
1338 t.start()
1339 pkt = (Ether(dst = 'ff:ff:ff:ff:ff:ff')/ARP(op=1,pdst= hostip))
1340 log.info('Sending arp request for dest ip %s on interface %s' %
1341 (hostip,self.proxyarp.port_map[ingress]))
1342 sendp(pkt, count = 10,iface = self.proxyarp.port_map[ingress])
1343 t.join()
1344 t = []
1345 for i in range(10):
1346 t.append(threading.Thread(target = verify_proxyarp, args = [ports[i],hostmac[i],hostip[i]]))
1347 for i in range(10):
1348 t[i].start()
1349 time.sleep(2)
1350 for i in range(10):
1351 t[i].join()
1352 if len(success_dir) != 10:
1353 self.success = False
1354 assert_equal(self.success, True)
1355
1356 #pass
1357 def test_cluster_with_acl_rule_before_master_change_and_remove_acl_rule_after_master_change(self,onos_instances=ONOS_INSTANCES):
1358 status = self.verify_cluster_status(onos_instances=onos_instances)
1359 assert_equal(status, True)
1360 master,standbys = self.get_cluster_current_master_standbys()
ChetanGaonker2099d722016-10-07 15:16:58 -07001361 assert_equal(len(standbys),(onos_instances-1))
ChetanGaonker689b3862016-10-17 16:25:01 -07001362 self.acl.setUp()
1363 acl_rule = ACLTest()
1364 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'allow',controller=master)
1365 if status is False:
1366 log.info('JSON request returned status %d' %code)
1367 assert_equal(status, True)
1368 result = acl_rule.get_acl_rules(controller=master)
1369 aclRules1 = result.json()['aclRules']
1370 log.info('Added acl rules is %s'%aclRules1)
1371 acl_Id = map(lambda d: d['id'], aclRules1)
1372 log.info('Changing cluster current master from %s to %s'%(master,standbys[0]))
1373 self.change_cluster_current_master(new_master=standbys[0])
1374 status,code = acl_rule.remove_acl_rule(acl_Id[0],controller=standbys[0])
1375 if status is False:
1376 log.info('JSON request returned status %d' %code)
1377 assert_equal(status, True)
1378
1379 #pass
1380 def test_cluster_verifying_acl_rule_in_new_master_after_current_master_is_down(self,onos_instances=ONOS_INSTANCES):
1381 status = self.verify_cluster_status(onos_instances=onos_instances)
1382 assert_equal(status, True)
1383 master,standbys = self.get_cluster_current_master_standbys()
1384 assert_equal(len(standbys),(onos_instances-1))
1385 onos_names_ips = self.get_cluster_container_names_ips()
1386 master_onos_name = onos_names_ips[master]
1387 self.acl.setUp()
1388 acl_rule = ACLTest()
1389 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'allow',controller=master)
1390 if status is False:
1391 log.info('JSON request returned status %d' %code)
1392 assert_equal(status, True)
1393 result1 = acl_rule.get_acl_rules(controller=master)
1394 aclRules1 = result1.json()['aclRules']
1395 log.info('Added acl rules is %s'%aclRules1)
1396 acl_Id1 = map(lambda d: d['id'], aclRules1)
1397 log.info('Killing cluster current master %s'%master)
1398 Container(master_onos_name,Onos.IMAGE).kill()
1399 time.sleep(45)
1400 status = self.verify_cluster_status(onos_instances=onos_instances,controller=standbys[0])
1401 assert_equal(status, True)
1402 new_master,standbys = self.get_cluster_current_master_standbys(controller=standbys[0])
1403 assert_equal(len(standbys),(onos_instances-2))
1404 assert_not_equal(new_master,master)
1405 result2 = acl_rule.get_acl_rules(controller=new_master)
1406 aclRules2 = result2.json()['aclRules']
1407 acl_Id2 = map(lambda d: d['id'], aclRules2)
1408 log.info('Acl Ids before and after master down are %s and %s'%(acl_Id1,acl_Id2))
1409 assert_equal(acl_Id2,acl_Id1)
1410
1411 #acl traffic scenario not working as acl rule is not getting added to onos
1412 def test_cluster_with_acl_traffic_before_and_after_two_members_down(self,onos_instances=ONOS_INSTANCES):
1413 status = self.verify_cluster_status(onos_instances=onos_instances)
1414 assert_equal(status, True)
1415 master,standbys = self.get_cluster_current_master_standbys()
1416 assert_equal(len(standbys),(onos_instances-1))
1417 onos_names_ips = self.get_cluster_container_names_ips()
1418 member1_onos_name = onos_names_ips[standbys[0]]
1419 member2_onos_name = onos_names_ips[standbys[1]]
1420 ingress = self.acl.ingress_iface
1421 egress = self.acl.CURRENT_PORT_NUM
1422 acl_rule = ACLTest()
1423 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.acl.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.acl.HOST_DST_IP)
1424 self.acl.CURRENT_PORT_NUM += 1
1425 time.sleep(5)
1426 if status is False:
1427 log.info('JSON request returned status %d' %code)
1428 assert_equal(status, True)
1429 srcMac = '00:00:00:00:00:11'
1430 dstMac = host_ip_mac[0][1]
1431 self.acl.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1432 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'deny',controller=master)
1433 time.sleep(10)
1434 if status is False:
1435 log.info('JSON request returned status %d' %code)
1436 assert_equal(status, True)
1437 self.acl.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.acl.ACL_SRC_IP, dstIp = self.acl.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
1438 log.info('killing cluster members %s and %s'%(standbys[0],standbys[1]))
1439 Container(member1_onos_name, Onos.IMAGE).kill()
1440 Container(member2_onos_name, Onos.IMAGE).kill()
1441 time.sleep(40)
1442 status = self.verify_cluster_status(onos_instances=onos_instances-2,verify=True,controller=master)
1443 assert_equal(status, True)
1444 self.acl.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.acl.ACL_SRC_IP, dstIp = self.acl.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
1445 self.acl.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
1446
1447 #pass
1448 def test_cluster_with_dhcpRelay_releasing_dhcp_ip_after_master_change(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1449 status = self.verify_cluster_status(onos_instances=onos_instances)
1450 assert_equal(status, True)
1451 master,standbys = self.get_cluster_current_master_standbys()
1452 assert_equal(len(standbys),(onos_instances-1))
1453 self.dhcprelay.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001454 mac = self.dhcprelay.get_mac(iface)
1455 self.dhcprelay.host_load(iface)
1456 ##we use the defaults for this test that serves as an example for others
1457 ##You don't need to restart dhcpd server if retaining default config
1458 config = self.dhcprelay.default_config
1459 options = self.dhcprelay.default_options
1460 subnet = self.dhcprelay.default_subnet_config
1461 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1462 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1463 config = config,
1464 options = options,
ChetanGaonker689b3862016-10-17 16:25:01 -07001465 subnet = subnet,
1466 controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001467 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
1468 cip, sip = self.dhcprelay.send_recv(mac)
1469 log.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
1470 self.change_master_current_cluster(new_master=standbys[0])
1471 log.info('Releasing ip %s to server %s' %(cip, sip))
1472 assert_equal(self.dhcprelay.dhcp.release(cip), True)
1473 log.info('Triggering DHCP discover again after release')
1474 cip2, sip2 = self.dhcprelay.send_recv(mac)
1475 log.info('Verifying released IP was given back on rediscover')
1476 assert_equal(cip, cip2)
1477 log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
1478 assert_equal(self.dhcprelay.dhcp.release(cip2), True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001479 self.dhcprelay.tearDownClass(controller=standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001480
ChetanGaonker689b3862016-10-17 16:25:01 -07001481
1482 def test_cluster_with_dhcpRelay_and_verify_dhcp_ip_after_master_down(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1483 status = self.verify_cluster_status(onos_instances=onos_instances)
1484 assert_equal(status, True)
1485 master,standbys = self.get_cluster_current_master_standbys()
ChetanGaonker2099d722016-10-07 15:16:58 -07001486 assert_equal(len(standbys),(onos_instances-1))
ChetanGaonker689b3862016-10-17 16:25:01 -07001487 onos_names_ips = self.get_cluster_container_names_ips()
1488 master_onos_name = onos_names_ips[master]
1489 self.dhcprelay.setUpClass(controller=master)
1490 mac = self.dhcprelay.get_mac(iface)
1491 self.dhcprelay.host_load(iface)
1492 ##we use the defaults for this test that serves as an example for others
1493 ##You don't need to restart dhcpd server if retaining default config
1494 config = self.dhcprelay.default_config
1495 options = self.dhcprelay.default_options
1496 subnet = self.dhcprelay.default_subnet_config
1497 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1498 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1499 config = config,
1500 options = options,
1501 subnet = subnet,
1502 controller=master)
1503 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1504 log.info('Initiating dhcp process from client %s'%mac)
1505 cip, sip = self.dhcprelay.send_recv(mac)
1506 log.info('Killing cluster current master %s'%master)
1507 Container(master_onos_name, Onos.IMAGE).kill()
1508 time.sleep(60)
1509 status = self.verify_cluster_status(onos_instances=onos_instances-1,verify=True,controller=standbys[0])
1510 assert_equal(status, True)
1511 mac = self.dhcprelay.dhcp.get_mac(cip)[0]
1512 log.info("Verifying dhcp clients gets same IP after cluster master restarts")
1513 new_cip, new_sip = self.dhcprelay.dhcp.only_request(cip, mac)
1514 assert_equal(new_cip, cip)
1515 self.dhcprelay.tearDownClass(controller=standbys[0])
1516
1517 #pass
1518 def test_cluster_with_dhcpRelay_and_simulate_client_by_changing_master(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1519 status = self.verify_cluster_status(onos_instances=onos_instances)
1520 assert_equal(status, True)
1521 master,standbys = self.get_cluster_current_master_standbys()
1522 assert_equal(len(standbys),(onos_instances-1))
1523 self.dhcprelay.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001524 macs = ['e4:90:5e:a3:82:c1','e4:90:5e:a3:82:c2','e4:90:5e:a3:82:c3']
1525 self.dhcprelay.host_load(iface)
1526 ##we use the defaults for this test that serves as an example for others
1527 ##You don't need to restart dhcpd server if retaining default config
1528 config = self.dhcprelay.default_config
1529 options = self.dhcprelay.default_options
1530 subnet = self.dhcprelay.default_subnet_config
1531 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1532 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1533 config = config,
1534 options = options,
ChetanGaonker689b3862016-10-17 16:25:01 -07001535 subnet = subnet,
1536 controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001537 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1538 cip1, sip1 = self.dhcprelay.send_recv(macs[0])
1539 assert_not_equal(cip1,None)
1540 log.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip1,macs[0],master))
1541 log.info('Changing cluster master from %s to %s'%(master, standbys[0]))
1542 self.change_master_current_cluster(new_master=standbys[0])
1543 cip2, sip2 = self.dhcprelay.send_recv(macs[1])
1544 assert_not_equal(cip2,None)
1545 log.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip2,macs[1],standbys[0]))
1546 self.change_master_current_cluster(new_master=master)
1547 log.info('Changing cluster master from %s to %s'%(standbys[0],master))
1548 cip3, sip3 = self.dhcprelay.send_recv(macs[2])
1549 assert_not_equal(cip3,None)
1550 log.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip2,macs[2],master))
ChetanGaonker689b3862016-10-17 16:25:01 -07001551 self.dhcprelay.tearDownClass(controller=standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001552
ChetanGaonker689b3862016-10-17 16:25:01 -07001553 def test_cluster_with_cord_subscriber_joining_next_channel_before_and_after_cluster_restart(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001554 status = self.verify_cluster_status(onos_instances=onos_instances)
1555 assert_equal(status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001556 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001557 self.subscriber.num_subscribers = 5
1558 self.subscriber.num_channels = 10
1559 for i in [0,1]:
1560 if i == 1:
1561 cord_test_onos_restart()
1562 time.sleep(45)
1563 status = self.verify_cluster_status(onos_instances=onos_instances)
1564 assert_equal(status, True)
1565 log.info('Verifying cord subscriber functionality after cluster restart')
1566 else:
1567 log.info('Verifying cord subscriber functionality before cluster restart')
1568 test_status = self.subscriber.subscriber_join_verify(num_subscribers = self.subscriber.num_subscribers,
1569 num_channels = self.subscriber.num_channels,
1570 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1571 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1572 port_list = self.subscriber.generate_port_list(self.subscriber.num_subscribers,
1573 self.subscriber.num_channels))
1574 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001575 self.subscriber.tearDownClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001576
ChetanGaonker689b3862016-10-17 16:25:01 -07001577 #not validated on cluster setup because ciena-cordigmp-multitable-2.0 app installation fails on cluster
1578 def test_cluster_with_cord_subscriber_join_next_channel_before_and_after_cluster_mastership_is_withdrawn(self,onos_instances=ONOS_INSTANCES):
1579 status = self.verify_cluster_status(onos_instances=onos_instances)
1580 assert_equal(status, True)
1581 master,standbys = self.get_cluster_current_master_standbys()
1582 assert_equal(len(standbys),(onos_instances-1))
1583 self.subscriber.setUpClass(controller=master)
1584 self.subscriber.num_subscribers = 5
1585 self.subscriber.num_channels = 10
1586 for i in [0,1]:
1587 if i == 1:
1588 status=self.withdraw_cluster_current_mastership(master_ip=master)
1589 asser_equal(status, True)
1590 master,standbys = self.get_cluster_current_master_standbys()
1591 log.info('verifying cord subscriber functionality after cluster current master withdraw mastership')
1592 else:
1593 log.info('verifying cord subscriber functionality before cluster master withdraw mastership')
1594 test_status = self.subscriber.subscriber_join_verify(num_subscribers = self.subscriber.num_subscribers,
1595 num_channels = self.subscriber.num_channels,
1596 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1597 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1598 port_list = self.subscriber.generate_port_list(self.subscriber.num_subscribers,
1599 self.subscriber.num_channels),controller=master)
1600 assert_equal(test_status, True)
1601 self.subscriber.tearDownClass(controller=master)
1602
1603 #not validated on cluster setup because ciena-cordigmp-multitable-2.0 app installation fails on cluster
1604 def test_cluster_with_cord_subscriber_join_recv_traffic_from_10channels_and_making_one_cluster_member_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001605 status = self.verify_cluster_status(onos_instances=onos_instances)
1606 assert_equal(status, True)
1607 master, standbys = self.get_cluster_current_master_standbys()
1608 assert_equal(len(standbys),(onos_instances-1))
1609 onos_names_ips = self.get_cluster_container_names_ips()
1610 member_onos_name = onos_names_ips[standbys[0]]
ChetanGaonker689b3862016-10-17 16:25:01 -07001611 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001612 num_subscribers = 1
1613 num_channels = 10
1614 for i in [0,1]:
1615 if i == 1:
1616 cord_test_onos_shutdown(node = member_onos_name)
1617 time.sleep(30)
ChetanGaonker689b3862016-10-17 16:25:01 -07001618 status = self.verify_cluster_status(onos_instances=onos_instances-1,verify=True,controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001619 assert_equal(status, True)
1620 log.info('Verifying cord subscriber functionality after cluster member %s is down'%standbys[0])
1621 else:
1622 log.info('Verifying cord subscriber functionality before cluster member %s is down'%standbys[0])
1623 test_status = self.subscriber.subscriber_join_verify(num_subscribers = num_subscribers,
1624 num_channels = num_channels,
1625 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_verify,
1626 self.subscriber.igmp_verify, self.subscriber.traffic_verify),
1627 port_list = self.subscriber.generate_port_list(num_subscribers, num_channels),
ChetanGaonker689b3862016-10-17 16:25:01 -07001628 negative_subscriber_auth = 'all',controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001629 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001630 self.subscriber.tearDownClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001631
ChetanGaonker689b3862016-10-17 16:25:01 -07001632 def test_cluster_with_cord_subscriber_joining_next_10channels_making_two_cluster_members_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001633 status = self.verify_cluster_status(onos_instances=onos_instances)
1634 assert_equal(status, True)
1635 master, standbys = self.get_cluster_current_master_standbys()
1636 assert_equal(len(standbys),(onos_instances-1))
1637 onos_names_ips = self.get_cluster_container_names_ips()
1638 member1_onos_name = onos_names_ips[standbys[0]]
1639 member2_onos_name = onos_names_ips[standbys[1]]
ChetanGaonker689b3862016-10-17 16:25:01 -07001640 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001641 num_subscribers = 1
1642 num_channels = 10
1643 for i in [0,1]:
1644 if i == 1:
1645 cord_test_onos_shutdown(node = member1_onos_name)
1646 cord_test_onos_shutdown(node = member2_onos_name)
1647 time.sleep(60)
1648 status = self.verify_cluster_status(onos_instances=onos_instances-2)
1649 assert_equal(status, True)
1650 log.info('Verifying cord subscriber funtionality after cluster two members %s and %s down'%(standbys[0],standbys[1]))
1651 else:
1652 log.info('Verifying cord subscriber funtionality before cluster two members %s and %s down'%(standbys[0],standbys[1]))
1653 test_status = self.subscriber.subscriber_join_verify(num_subscribers = num_subscribers,
1654 num_channels = num_channels,
1655 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1656 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1657 port_list = self.subscriber.generate_port_list(num_subscribers, num_channels),
1658 negative_subscriber_auth = 'all')
1659 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001660 self.subscriber.tearDownClass(controller=master)
1661
1662 #pass
1663 def test_cluster_with_multiple_ovs_switches(self,onos_instances = ONOS_INSTANCES):
1664 status = self.verify_cluster_status(onos_instances=onos_instances)
1665 assert_equal(status, True)
1666 device_dict = self.get_cluster_current_master_standbys_of_connected_devices()
1667 for device in device_dict.keys():
1668 log.info("Device is %s"%device_dict[device])
1669 assert_not_equal(device_dict[device]['master'],'none')
1670 log.info('Master and standbys for device %s are %s and %s'%(device,device_dict[device]['master'],device_dict[device]['standbys']))
1671 assert_equal(len(device_dict[device]['standbys']), onos_instances-1)
1672
1673 #pass
1674 def test_cluster_state_in_multiple_ovs_switches(self,onos_instances = ONOS_INSTANCES):
1675 status = self.verify_cluster_status(onos_instances=onos_instances)
1676 assert_equal(status, True)
1677 device_dict = self.get_cluster_current_master_standbys_of_connected_devices()
1678 cluster_ips = self.get_cluster_current_member_ips()
1679 for ip in cluster_ips:
1680 device_dict= self.get_cluster_current_master_standbys_of_connected_devices(controller = ip)
1681 assert_equal(len(device_dict.keys()),onos_instances)
1682 for device in device_dict.keys():
1683 log.info("Device is %s"%device_dict[device])
1684 assert_not_equal(device_dict[device]['master'],'none')
1685 log.info('Master and standbys for device %s are %s and %s'%(device,device_dict[device]['master'],device_dict[device]['standbys']))
1686 assert_equal(len(device_dict[device]['standbys']), onos_instances-1)
1687
1688 #pass
1689 def test_cluster_verifying_multiple_ovs_switches_after_master_is_restarted(self,onos_instances = ONOS_INSTANCES):
1690 status = self.verify_cluster_status(onos_instances=onos_instances)
1691 assert_equal(status, True)
1692 onos_names_ips = self.get_cluster_container_names_ips()
1693 master_count = self.get_number_of_devices_of_master()
1694 log.info('Master count information is %s'%master_count)
1695 total_devices = 0
1696 for master in master_count.keys():
1697 total_devices += master_count[master]['size']
1698 if master_count[master]['size'] != 0:
1699 restart_ip = master
1700 assert_equal(total_devices,onos_instances)
1701 member_onos_name = onos_names_ips[restart_ip]
1702 log.info('Restarting cluster member %s having ip %s'%(member_onos_name,restart_ip))
1703 Container(member_onos_name, Onos.IMAGE).restart()
1704 time.sleep(40)
1705 master_count = self.get_number_of_devices_of_master()
1706 log.info('Master count information after restart is %s'%master_count)
1707 total_devices = 0
1708 for master in master_count.keys():
1709 total_devices += master_count[master]['size']
1710 if master == restart_ip:
1711 assert_equal(master_count[master]['size'], 0)
1712 assert_equal(total_devices,onos_instances)
1713
1714 #pass
1715 def test_cluster_verifying_multiple_ovs_switches_with_one_master_down(self,onos_instances = ONOS_INSTANCES):
1716 status = self.verify_cluster_status(onos_instances=onos_instances)
1717 assert_equal(status, True)
1718 onos_names_ips = self.get_cluster_container_names_ips()
1719 master_count = self.get_number_of_devices_of_master()
1720 log.info('Master count information is %s'%master_count)
1721 total_devices = 0
1722 for master in master_count.keys():
1723 total_devices += master_count[master]['size']
1724 if master_count[master]['size'] != 0:
1725 restart_ip = master
1726 assert_equal(total_devices,onos_instances)
1727 master_onos_name = onos_names_ips[restart_ip]
1728 log.info('Shutting down cluster member %s having ip %s'%(master_onos_name,restart_ip))
1729 Container(master_onos_name, Onos.IMAGE).kill()
1730 time.sleep(40)
1731 for ip in onos_names_ips.keys():
1732 if ip != restart_ip:
1733 controller_ip = ip
1734 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=controller_ip)
1735 assert_equal(status, True)
1736 master_count = self.get_number_of_devices_of_master(controller=controller_ip)
1737 log.info('Master count information after restart is %s'%master_count)
1738 total_devices = 0
1739 for master in master_count.keys():
1740 total_devices += master_count[master]['size']
1741 if master == restart_ip:
1742 assert_equal(master_count[master]['size'], 0)
1743 assert_equal(total_devices,onos_instances)
1744
1745 #pass
1746 def test_cluster_verifying_multiple_ovs_switches_with_current_master_withdrawing_mastership(self,onos_instances = ONOS_INSTANCES):
1747 status = self.verify_cluster_status(onos_instances=onos_instances)
1748 assert_equal(status, True)
1749 master_count = self.get_number_of_devices_of_master()
1750 log.info('Master count information is %s'%master_count)
1751 total_devices = 0
1752 for master in master_count.keys():
1753 total_devices += int(master_count[master]['size'])
1754 if master_count[master]['size'] != 0:
1755 master_ip = master
1756 log.info('Devices of master %s are %s'%(master_count[master]['devices'],master))
1757 device_id = str(master_count[master]['devices'][0])
1758 device_count = master_count[master]['size']
1759 assert_equal(total_devices,onos_instances)
1760 log.info('Withdrawing mastership of device %s for controller %s'%(device_id,master_ip))
1761 status=self.withdraw_cluster_current_mastership(master_ip=master_ip,device_id = device_id)
1762 assert_equal(status, True)
1763 master_count = self.get_number_of_devices_of_master()
1764 log.info('Master count information after cluster mastership withdraw is %s'%master_count)
1765 total_devices = 0
1766 for master in master_count.keys():
1767 total_devices += int(master_count[master]['size'])
1768 if master == master_ip:
1769 assert_equal(master_count[master]['size'], device_count-1)
1770 assert_equal(total_devices,onos_instances)
1771
1772 #pass
1773 def test_cluster_verifying_multiple_ovs_switches_and_restarting_cluster(self,onos_instances = ONOS_INSTANCES):
1774 status = self.verify_cluster_status(onos_instances=onos_instances)
1775 assert_equal(status, True)
1776 master_count = self.get_number_of_devices_of_master()
1777 log.info('Master count information is %s'%master_count)
1778 total_devices = 0
1779 for master in master_count.keys():
1780 total_devices += master_count[master]['size']
1781 assert_equal(total_devices,onos_instances)
1782 log.info('Restarting cluster')
1783 cord_test_onos_restart()
1784 time.sleep(60)
1785 master_count = self.get_number_of_devices_of_master()
1786 log.info('Master count information after restart is %s'%master_count)
1787 total_devices = 0
1788 for master in master_count.keys():
1789 total_devices += master_count[master]['size']
1790 assert_equal(total_devices,onos_instances)