blob: eb715189cd2819b93986eeedebd7b8bbd4db54d5 [file] [log] [blame]
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001import time
2import sys
3import os
4import re
5import time
6import json
7import itertools
8
kelvin8ec71442015-01-15 16:57:00 -08009
Hari Krishnaa43d4e92014-12-19 13:22:40 -080010class OnosCHO:
kelvin8ec71442015-01-15 16:57:00 -080011
kelvin-onlab8a832582015-01-16 17:06:11 -080012 def __init__( self ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -080013 self.default = ''
kelvin8ec71442015-01-15 16:57:00 -080014
kelvin-onlab8a832582015-01-16 17:06:11 -080015 def CASE1( self, main ):
16 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080017 Startup sequence:
18 git pull
19 mvn clean install
20 onos-package
21 cell <name>
22 onos-verify-cell
23 onos-install -f
24 onos-wait-for-start
kelvin-onlab8a832582015-01-16 17:06:11 -080025 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080026 import time
Hari Krishna22c3d412015-02-17 16:48:12 -080027
28 main.numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
29 main.ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
30 main.ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
31 main.ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
32 main.ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ]
33 main.ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ]
34 main.ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
35 main.ONOS2_port = main.params[ 'CTRL' ][ 'port2' ]
36 main.ONOS3_port = main.params[ 'CTRL' ][ 'port3' ]
37 main.ONOS4_port = main.params[ 'CTRL' ][ 'port4' ]
38 main.ONOS5_port = main.params[ 'CTRL' ][ 'port5' ]
kelvin-onlab8a832582015-01-16 17:06:11 -080039 cell_name = main.params[ 'ENV' ][ 'cellName' ]
40 git_pull = main.params[ 'GIT' ][ 'autoPull' ]
kelvin-onlab8a832582015-01-16 17:06:11 -080041 git_branch = main.params[ 'GIT' ][ 'branch' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -080042
kelvin-onlab8a832582015-01-16 17:06:11 -080043 main.case( "Set up test environment" )
44 main.log.report( "Set up test environment" )
45 main.log.report( "_______________________" )
46
47 main.step( "Git checkout and pull " + git_branch )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080048 if git_pull == 'on':
Hari Krishnad97213e2015-01-24 19:30:14 -080049 checkout_result = main.ONOSbench.gitCheckout( git_branch )
50 pull_result = main.ONOSbench.gitPull()
kelvin-onlab8a832582015-01-16 17:06:11 -080051 cp_result = ( checkout_result and pull_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080052 else:
53 checkout_result = main.TRUE
54 pull_result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -080055 main.log.info( "Skipped git checkout and pull" )
56 cp_result = ( checkout_result and pull_result )
57 utilities.assert_equals( expect=main.TRUE, actual=cp_result,
58 onpass="Test step PASS",
59 onfail="Test step FAIL" )
60
61 main.step( "mvn clean & install" )
Hari Krishna22c3d412015-02-17 16:48:12 -080062 if git_pull == 'on':
63 mvn_result = main.ONOSbench.cleanInstall()
64 utilities.assert_equals( expect=main.TRUE, actual=mvn_result,
kelvin-onlab8a832582015-01-16 17:06:11 -080065 onpass="Test step PASS",
66 onfail="Test step FAIL" )
Hari Krishna22c3d412015-02-17 16:48:12 -080067 else:
68 mvn_result = main.TRUE
69 main.log.info("Skipped mvn clean install as git pull is disabled in params file")
Hari Krishnaa43d4e92014-12-19 13:22:40 -080070
Hari Krishnad97213e2015-01-24 19:30:14 -080071 main.ONOSbench.getVersion( report=True )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080072
kelvin-onlab8a832582015-01-16 17:06:11 -080073 main.step( "Apply Cell environment for ONOS" )
Hari Krishnad97213e2015-01-24 19:30:14 -080074 cell_result = main.ONOSbench.setCell( cell_name )
kelvin-onlab8a832582015-01-16 17:06:11 -080075 utilities.assert_equals( expect=main.TRUE, actual=cell_result,
76 onpass="Test step PASS",
77 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080078
kelvin-onlab8a832582015-01-16 17:06:11 -080079 main.step( "Create ONOS package" )
Hari Krishnad97213e2015-01-24 19:30:14 -080080 packageResult = main.ONOSbench.onosPackage()
kelvin-onlab8a832582015-01-16 17:06:11 -080081 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
82 onpass="Test step PASS",
83 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080084
kelvin-onlab8a832582015-01-16 17:06:11 -080085 main.step( "Uninstall ONOS package on all Nodes" )
86 uninstallResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -080087 for i in range( 1, int( main.numCtrls ) + 1 ):
kelvin-onlab8a832582015-01-16 17:06:11 -080088 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
89 main.log.info( "Unintsalling package on ONOS Node IP: " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -080090 u_result = main.ONOSbench.onosUninstall( ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -080091 utilities.assert_equals( expect=main.TRUE, actual=u_result,
92 onpass="Test step PASS",
93 onfail="Test step FAIL" )
94 uninstallResult = ( uninstallResult and u_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080095
kelvin-onlab8a832582015-01-16 17:06:11 -080096 main.step( "Removing copy-cat logs from ONOS nodes" )
Hari Krishnad97213e2015-01-24 19:30:14 -080097 main.ONOSbench.onosRemoveRaftLogs()
Hari Krishnaa43d4e92014-12-19 13:22:40 -080098
kelvin-onlab8a832582015-01-16 17:06:11 -080099 main.step( "Install ONOS package on all Nodes" )
100 installResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800101 for i in range( 1, int( main.numCtrls ) + 1 ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800102 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
103 main.log.info( "Intsalling package on ONOS Node IP: " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -0800104 i_result = main.ONOSbench.onosInstall( node=ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -0800105 utilities.assert_equals( expect=main.TRUE, actual=i_result,
106 onpass="Test step PASS",
107 onfail="Test step FAIL" )
108 installResult = ( installResult and i_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800109
kelvin-onlab8a832582015-01-16 17:06:11 -0800110 main.step( "Verify ONOS nodes UP status" )
111 statusResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800112 for i in range( 1, int( main.numCtrls ) + 1 ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800113 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
114 main.log.info( "ONOS Node " + ONOS_ip + " status:" )
Hari Krishnad97213e2015-01-24 19:30:14 -0800115 onos_status = main.ONOSbench.onosStatus( node=ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -0800116 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
117 onpass="Test step PASS",
118 onfail="Test step FAIL" )
119 statusResult = ( statusResult and onos_status )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800120
kelvin-onlab8a832582015-01-16 17:06:11 -0800121 main.step( "Start ONOS CLI on all nodes" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800122 cliResult = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800123 karafTimeout = "3600000"
kelvin-onlab8a832582015-01-16 17:06:11 -0800124 # need to wait here for sometime. This will be removed once ONOS is
125 # stable enough
Hari Krishna22c3d412015-02-17 16:48:12 -0800126 time.sleep( 20 )
127 for i in range( 1, int( main.numCtrls ) + 1 ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800128 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
129 ONOScli = 'ONOScli' + str( i )
130 main.log.info( "ONOS Node " + ONOS_ip + " cli start:" )
131 exec "startcli=main." + ONOScli + \
Hari Krishnad97213e2015-01-24 19:30:14 -0800132 ".startOnosCli(ONOS_ip, karafTimeout=karafTimeout)"
kelvin-onlab8a832582015-01-16 17:06:11 -0800133 utilities.assert_equals( expect=main.TRUE, actual=startcli,
134 onpass="Test step PASS",
135 onfail="Test step FAIL" )
136 cliResult = ( cliResult and startcli )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800137
kelvin-onlab8a832582015-01-16 17:06:11 -0800138 case1Result = ( cp_result and cell_result
139 and packageResult and installResult and statusResult and cliResult )
140 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
141 onpass="Set up test environment PASS",
142 onfail="Set up test environment FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800143
kelvin-onlab8a832582015-01-16 17:06:11 -0800144 def CASE2( self, main ):
145 """
Hari Krishna22c3d412015-02-17 16:48:12 -0800146 This test loads a Topology (ATT) on Mininet and balances all switches.
kelvin-onlab8a832582015-01-16 17:06:11 -0800147 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800148 import re
149 import time
150 import copy
Hari Krishna22c3d412015-02-17 16:48:12 -0800151 main.numMNswitches = int ( main.params[ 'TOPO1' ][ 'numSwitches' ] )
152 main.numMNlinks = int ( main.params[ 'TOPO1' ][ 'numLinks' ] )
153 main.numMNhosts = int ( main.params[ 'TOPO1' ][ 'numHosts' ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800154
kelvin-onlab8a832582015-01-16 17:06:11 -0800155 main.log.report(
156 "Assign and Balance all Mininet switches across controllers" )
157 main.log.report(
158 "_________________________________________________________" )
159 # need to wait here for sometime. This will be removed once ONOS is
160 # stable enough
161 time.sleep( 15 )
162 main.case(
163 "Assign and Balance all Mininet switches across controllers" )
164 main.step( "Assign switches to controllers" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800165 netStatus = main.Mininet1.startNet()
166 for i in range( 1, ( main.numMNswitches + 1 ) ): # 1 to ( num of switches +1 )
Hari Krishnad97213e2015-01-24 19:30:14 -0800167 main.Mininet1.assignSwController(
kelvin-onlab8a832582015-01-16 17:06:11 -0800168 sw=str( i ),
Hari Krishna22c3d412015-02-17 16:48:12 -0800169 count=int( main.numCtrls ),
170 ip1=main.ONOS1_ip,
171 port1=main.ONOS1_port,
172 ip2=main.ONOS2_ip,
173 port2=main.ONOS2_port,
174 ip3=main.ONOS3_ip,
175 port3=main.ONOS3_port,
176 ip4=main.ONOS4_ip,
177 port4=main.ONOS4_port,
178 ip5=main.ONOS5_ip,
179 port5=main.ONOS5_port )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800180
181 switch_mastership = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800182 for i in range( 1, ( main.numMNswitches + 1 ) ):
Hari Krishnad97213e2015-01-24 19:30:14 -0800183 response = main.Mininet1.getSwController( "s" + str( i ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800184 print( "Response is " + str( response ) )
Hari Krishna22c3d412015-02-17 16:48:12 -0800185 if re.search( "tcp:" + main.ONOS1_ip, response ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800186 switch_mastership = switch_mastership and main.TRUE
187 else:
188 switch_mastership = main.FALSE
189
190 if switch_mastership == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800191 main.log.report( "Controller assignment successfull" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800192 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800193 main.log.report( "Controller assignment failed" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800194 time.sleep( 15 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800195
Hari Krishna22c3d412015-02-17 16:48:12 -0800196 #main.step( "Balance devices across controllers" )
197 #for i in range( int( main.numCtrls ) ):
198 # balanceResult = main.ONOScli1.balanceMasters()
kelvin-onlab8a832582015-01-16 17:06:11 -0800199 # giving some breathing time for ONOS to complete re-balance
Hari Krishna22c3d412015-02-17 16:48:12 -0800200 # time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800201
Hari Krishna22c3d412015-02-17 16:48:12 -0800202 #utilities.assert_equals(
203 # expect=main.TRUE,
204 # actual=balanceResult,
205 # onpass="Assign and Balance devices test PASS",
206 #onfail="Assign and Balance devices test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800207
kelvin-onlab8a832582015-01-16 17:06:11 -0800208 def CASE3( self, main ):
209 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800210 This Test case will be extended to collect and store more data related
211 ONOS state.
kelvin-onlab8a832582015-01-16 17:06:11 -0800212 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800213 import re
214 import copy
Hari Krishna22c3d412015-02-17 16:48:12 -0800215 main.deviceDPIDs = []
216 main.hostMACs = []
217 main.deviceLinks = []
218 main.deviceActiveLinksCount = []
219 main.devicePortsEnabledCount = []
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800220
kelvin-onlab8a832582015-01-16 17:06:11 -0800221 main.log.report(
222 "Collect and Store topology details from ONOS before running any Tests" )
223 main.log.report(
224 "____________________________________________________________________" )
225 main.case( "Collect and Store Topology Deatils from ONOS" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800226
kelvin-onlab8a832582015-01-16 17:06:11 -0800227 main.step( "Collect and store current number of switches and links" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800228 topology_output = main.ONOScli1.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800229 topology_result = main.ONOSbench.getTopology( topology_output )
Hari Krishna22c3d412015-02-17 16:48:12 -0800230 numOnosDevices = topology_result[ 'devices' ]
231 numOnosLinks = topology_result[ 'links' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800232
Hari Krishna22c3d412015-02-17 16:48:12 -0800233 if ( ( main.numMNswitches == int(numOnosDevices) ) and ( main.numMNlinks == int(numOnosLinks) ) ):
234 main.step( "Store Device DPIDs" )
235 for i in range( 1, (main.numMNswitches+1) ):
236 main.deviceDPIDs.append( "of:00000000000000" + format( i, '02x' ) )
237 print "Device DPIDs in Store: \n", str( main.deviceDPIDs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800238
Hari Krishna22c3d412015-02-17 16:48:12 -0800239 main.step( "Store Host MACs" )
240 for i in range( 1, ( main.numMNhosts + 1 ) ):
241 main.hostMACs.append( "00:00:00:00:00:" + format( i, '02x' ) + "/-1" )
242 print "Host MACs in Store: \n", str( main.hostMACs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800243
Hari Krishna22c3d412015-02-17 16:48:12 -0800244 main.step( "Collect and store all Devices Links" )
245 linksResult = main.ONOScli1.links( jsonFormat=False )
246 ansi_escape = re.compile( r'\x1b[^m]*m' )
247 linksResult = ansi_escape.sub( '', linksResult )
248 linksResult = linksResult.replace( " links", "" ).replace( "\r\r", "" )
249 linksResult = linksResult.splitlines()
250 linksResult = linksResult[ 1: ]
251 main.deviceLinks = copy.copy( linksResult )
252 print "Device Links Stored: \n", str( main.deviceLinks )
253 # this will be asserted to check with the params provided count of
254 # links
255 print "Length of Links Store", len( main.deviceLinks )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800256
Hari Krishna22c3d412015-02-17 16:48:12 -0800257 main.step( "Collect and store each Device ports enabled Count" )
258 for i in range( 1, ( main.numMNswitches + 1) ):
259 portResult = main.ONOScli1.getDevicePortsEnabledCount(
260 "of:00000000000000" + format( i,'02x' ) )
261 portTemp = re.split( r'\t+', portResult )
262 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
263 main.devicePortsEnabledCount.append( portCount )
264 print "Device Enabled Port Counts Stored: \n", str( main.devicePortsEnabledCount )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800265
Hari Krishna22c3d412015-02-17 16:48:12 -0800266 main.step( "Collect and store each Device active links Count" )
267 for i in range( 1, ( main.numMNswitches + 1) ):
268 linkCountResult = main.ONOScli1.getDeviceLinksActiveCount(
269 "of:00000000000000" + format( i,'02x' ) )
270 linkCountTemp = re.split( r'\t+', linkCountResult )
271 linkCount = linkCountTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
272 main.deviceActiveLinksCount.append( linkCount )
273 print "Device Active Links Count Stored: \n", str( main.deviceActiveLinksCount )
274
275 else:
276 main.log.info("Devices (expected): %s, Links (expected): %s" %
277 ( str( main.numMNswitches ), str( main.numMNlinks ) ) )
278 main.log.info("Devices (actual): %s, Links (actual): %s" %
279 ( numOnosDevices , numOnosLinks ) )
280 main.log.info("Topology does not match, exiting CHO test...")
281 time.sleep(300)
282 #main.cleanup()
283 #main.exit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800284
kelvin-onlab8a832582015-01-16 17:06:11 -0800285 # just returning TRUE for now as this one just collects data
Hari Krishna22c3d412015-02-17 16:48:12 -0800286 case3Result = main.TRUE
287 utilities.assert_equals( expect=main.TRUE, actual=case3Result,
kelvin-onlab8a832582015-01-16 17:06:11 -0800288 onpass="Saving ONOS topology data test PASS",
289 onfail="Saving ONOS topology data test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800290
kelvin-onlab8a832582015-01-16 17:06:11 -0800291 def CASE4( self, main ):
292 """
293 Enable onos-app-fwd, Verify Reactive forwarding through ping all and Disable it
294 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800295 import re
296 import copy
297 import time
Hari Krishna22c3d412015-02-17 16:48:12 -0800298
kelvin-onlab8a832582015-01-16 17:06:11 -0800299 main.log.report( "Enable Reactive forwarding and Verify ping all" )
300 main.log.report( "______________________________________________" )
301 main.case( "Enable Reactive forwarding and Verify ping all" )
302 main.step( "Enable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800303 installResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800304 for i in range( 1, int( main.numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800305 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800306 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
307 ONOScli = 'ONOScli' + str( i )
308 main.log.info( "Enabling Reactive mode on ONOS Node " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -0800309 exec "inResult=main." + ONOScli + ".featureInstall(onosFeature)"
kelvin-onlab8a832582015-01-16 17:06:11 -0800310 time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800311 installResult = inResult and installResult
312
kelvin-onlab8a832582015-01-16 17:06:11 -0800313 time.sleep( 5 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800314
kelvin-onlab8a832582015-01-16 17:06:11 -0800315 main.step( "Verify Pingall" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800316 ping_result = main.FALSE
317 time1 = time.time()
318 ping_result = main.Mininet1.pingall()
319 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800320 timeDiff = round( ( time2 - time1 ), 2 )
321 main.log.report(
322 "Time taken for Ping All: " +
323 str( timeDiff ) +
324 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800325
326 if ping_result == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800327 main.log.report( "Pingall Test in Reactive mode successful" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800328 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800329 main.log.report( "Pingall Test in Reactive mode failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800330
kelvin-onlab8a832582015-01-16 17:06:11 -0800331 main.step( "Disable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800332 uninstallResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800333 for i in range( 1, int( main.numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800334 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800335 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
336 ONOScli = 'ONOScli' + str( i )
337 main.log.info( "Disabling Reactive mode on ONOS Node " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -0800338 exec "unResult=main." + ONOScli + ".featureUninstall(onosFeature)"
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800339 uninstallResult = unResult and uninstallResult
340
kelvin-onlab8a832582015-01-16 17:06:11 -0800341 # Waiting for reative flows to be cleared.
342 time.sleep( 10 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800343
344 case3Result = installResult and ping_result and uninstallResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800345 utilities.assert_equals( expect=main.TRUE, actual=case3Result,
346 onpass="Reactive Mode Pingall test PASS",
347 onfail="Reactive Mode Pingall test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800348
kelvin-onlab8a832582015-01-16 17:06:11 -0800349 def CASE5( self, main ):
350 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800351 Compare current ONOS topology with reference data
kelvin-onlab8a832582015-01-16 17:06:11 -0800352 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800353 import re
Hari Krishna22c3d412015-02-17 16:48:12 -0800354 devicesDPIDTemp = []
355 hostMACsTemp = []
356 deviceLinksTemp = []
357 deviceActiveLinksCountTemp = []
358 devicePortsEnabledCountTemp = []
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800359
kelvin-onlab8a832582015-01-16 17:06:11 -0800360 main.log.report(
361 "Compare ONOS topology with reference data in Stores" )
362 main.log.report( "__________________________________________________" )
363 main.case( "Compare ONOS topology with reference data" )
364
365 main.step( "Compare current Device ports enabled with reference" )
366 for i in range( 1, 26 ):
367 portResult = main.ONOScli1.getDevicePortsEnabledCount(
368 "of:00000000000000" +
369 format(
370 i,
371 '02x' ) )
372 portTemp = re.split( r'\t+', portResult )
373 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800374 devicePortsEnabledCountTemp.append( portCount )
kelvin-onlab8a832582015-01-16 17:06:11 -0800375 time.sleep( 2 )
Hari Krishna22c3d412015-02-17 16:48:12 -0800376 main.log.info (
377 "Device Enabled ports EXPECTED: %s" %
378 str( main.devicePortsEnabledCount ) )
379 main.log.info (
380 "Device Enabled ports ACTUAL: %s" %
381 str( devicePortsEnabledCountTemp ) )
382 if ( cmp( main.devicePortsEnabledCount,
383 devicePortsEnabledCountTemp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800384 stepResult1 = main.TRUE
385 else:
386 stepResult1 = main.FALSE
387
kelvin-onlab8a832582015-01-16 17:06:11 -0800388 main.step( "Compare Device active links with reference" )
389 for i in range( 1, 26 ):
390 linkResult = main.ONOScli1.getDeviceLinksActiveCount(
391 "of:00000000000000" +
392 format(
393 i,
394 '02x' ) )
395 linkTemp = re.split( r'\t+', linkResult )
396 linkCount = linkTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800397 deviceActiveLinksCountTemp.append( linkCount )
kelvin-onlab8a832582015-01-16 17:06:11 -0800398 time.sleep( 3 )
Hari Krishna22c3d412015-02-17 16:48:12 -0800399 main.log.info (
400 "Device Active links EXPECTED: %s" %
401 str( main.deviceActiveLinksCount ) )
402 main.log.info (
403 "Device Active links ACTUAL: %s" % str( deviceActiveLinksCountTemp ) )
404 if ( cmp( main.deviceActiveLinksCount, deviceActiveLinksCountTemp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800405 stepResult2 = main.TRUE
406 else:
407 stepResult2 = main.FALSE
408
kelvin-onlab8a832582015-01-16 17:06:11 -0800409 """
Hari Krishna22c3d412015-02-17 16:48:12 -0800410 place holder for comparing devices, hosts, paths and intents if required.
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800411 Links and ports data would be incorrect with out devices anyways.
kelvin-onlab8a832582015-01-16 17:06:11 -0800412 """
Hari Krishna22c3d412015-02-17 16:48:12 -0800413 case5Result = ( stepResult1 and stepResult2 )
414 utilities.assert_equals( expect=main.TRUE, actual=case5Result,
kelvin-onlab8a832582015-01-16 17:06:11 -0800415 onpass="Compare Topology test PASS",
416 onfail="Compare Topology test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800417
kelvin-onlab8a832582015-01-16 17:06:11 -0800418 def CASE6( self ):
419 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800420 Install 300 host intents and verify ping all
kelvin-onlab8a832582015-01-16 17:06:11 -0800421 """
422 main.log.report( "Add 300 host intents and verify pingall" )
423 main.log.report( "_______________________________________" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800424 import itertools
Hari Krishna22c3d412015-02-17 16:48:12 -0800425
kelvin-onlab8a832582015-01-16 17:06:11 -0800426 main.case( "Install 300 host intents" )
427 main.step( "Add host Intents" )
428 intentResult = main.TRUE
Hari Krishna22c3d412015-02-17 16:48:12 -0800429 hostCombos = list( itertools.combinations( main.hostMACs, 2 ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800430 for i in range( len( hostCombos ) ):
Hari Krishnad97213e2015-01-24 19:30:14 -0800431 iResult = main.ONOScli1.addHostIntent(
kelvin-onlab8a832582015-01-16 17:06:11 -0800432 hostCombos[ i ][ 0 ],
433 hostCombos[ i ][ 1 ] )
434 intentResult = ( intentResult and iResult )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800435
kelvin-onlab8a832582015-01-16 17:06:11 -0800436 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800437 pingResult = main.FALSE
438 time1 = time.time()
439 pingResult = main.Mininet1.pingall()
440 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800441 timeDiff = round( ( time2 - time1 ), 2 )
442 main.log.report(
443 "Time taken for Ping All: " +
444 str( timeDiff ) +
445 " seconds" )
446 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
447 onpass="PING ALL PASS",
448 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800449
kelvin-onlab8a832582015-01-16 17:06:11 -0800450 case4Result = ( intentResult and pingResult )
Hari Krishna46997e02015-01-27 11:23:07 -0800451 #case4Result = pingResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800452 utilities.assert_equals(
453 expect=main.TRUE,
454 actual=case4Result,
455 onpass="Install 300 Host Intents and Ping All test PASS",
456 onfail="Install 300 Host Intents and Ping All test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800457
kelvin-onlab8a832582015-01-16 17:06:11 -0800458 def CASE70( self, main ):
459 """
460 Randomly bring some core links down and verify ping all ( Host Intents Scenario )
461 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800462 import random
Hari Krishna22c3d412015-02-17 16:48:12 -0800463 main.randomLink1 = []
464 main.randomLink2 = []
465 main.randomLink3 = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800466 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
467 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
468 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
469 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
470 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
471 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
472 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
473 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800474
Hari Krishnad97213e2015-01-24 19:30:14 -0800475 main.log.report( "Host intents - Randomly bring some core links down and verify ping all" )
476 main.log.report( "_________________________________________________________________" )
477 main.case( "Host intents - Randomly bring some core links down and verify ping all" )
478 main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800479 if ( int( switchLinksToToggle ) ==
480 0 or int( switchLinksToToggle ) > 5 ):
Hari Krishna46997e02015-01-27 11:23:07 -0800481 main.log.info( "Please check your PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800482 main.cleanup()
483 main.exit()
484 else:
Hari Krishnad97213e2015-01-24 19:30:14 -0800485 main.log.info( "User provided Core switch links range to toggle is correct, proceeding to run the test" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800486
kelvin-onlab8a832582015-01-16 17:06:11 -0800487 main.step( "Cut links on Core devices using user provided range" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800488 main.randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
489 main.randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
490 main.randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800491 for i in range( int( switchLinksToToggle ) ):
492 main.Mininet1.link(
493 END1=link1End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800494 END2=main.randomLink1[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800495 OPTION="down" )
496 main.Mininet1.link(
497 END1=link2End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800498 END2=main.randomLink2[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800499 OPTION="down" )
500 main.Mininet1.link(
501 END1=link3End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800502 END2=main.randomLink3[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800503 OPTION="down" )
504 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800505
506 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800507 linkDown = main.ONOSbench.checkStatus(
Hari Krishna22c3d412015-02-17 16:48:12 -0800508 topology_output, main.numMNswitches, str(
509 int( main.numMNlinks ) - int( switchLinksToToggle ) * 6 ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800510 utilities.assert_equals(
511 expect=main.TRUE,
512 actual=linkDown,
513 onpass="Link Down discovered properly",
514 onfail="Link down was not discovered in " +
515 str( link_sleep ) +
516 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800517
kelvin-onlab8a832582015-01-16 17:06:11 -0800518 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800519 pingResultLinkDown = main.FALSE
520 time1 = time.time()
521 pingResultLinkDown = main.Mininet1.pingall()
522 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800523 timeDiff = round( ( time2 - time1 ), 2 )
524 main.log.report(
525 "Time taken for Ping All: " +
526 str( timeDiff ) +
527 " seconds" )
528 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
529 onpass="PING ALL PASS",
530 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800531
Hari Krishna22c3d412015-02-17 16:48:12 -0800532 caseResult70 = linkDown and pingResultLinkDown
533 utilities.assert_equals( expect=main.TRUE, actual=caseResult70,
kelvin-onlab8a832582015-01-16 17:06:11 -0800534 onpass="Random Link cut Test PASS",
535 onfail="Random Link cut Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800536
kelvin-onlab8a832582015-01-16 17:06:11 -0800537 def CASE80( self, main ):
538 """
539 Bring the core links up that are down and verify ping all ( Host Intents Scenario )
540 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800541 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800542 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
543 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
544 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
545 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
546 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800547
kelvin-onlab8a832582015-01-16 17:06:11 -0800548 main.log.report(
549 "Host intents - Bring the core links up that are down and verify ping all" )
550 main.log.report(
551 "__________________________________________________________________" )
552 main.case(
553 "Host intents - Bring the core links up that are down and verify ping all" )
554 main.step( "Bring randomly cut links on Core devices up" )
555 for i in range( int( switchLinksToToggle ) ):
556 main.Mininet1.link(
557 END1=link1End1,
558 END2=randomLink1[ i ],
559 OPTION="up" )
560 main.Mininet1.link(
561 END1=link2End1,
562 END2=randomLink2[ i ],
563 OPTION="up" )
564 main.Mininet1.link(
565 END1=link3End1,
566 END2=randomLink3[ i ],
567 OPTION="up" )
568 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800569
570 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800571 linkUp = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800572 topology_output,
Hari Krishna22c3d412015-02-17 16:48:12 -0800573 main.numMNswitches,
574 str( main.numMNlinks ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800575 utilities.assert_equals(
576 expect=main.TRUE,
577 actual=linkUp,
578 onpass="Link up discovered properly",
579 onfail="Link up was not discovered in " +
580 str( link_sleep ) +
581 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800582
kelvin-onlab8a832582015-01-16 17:06:11 -0800583 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800584 pingResultLinkUp = main.FALSE
585 time1 = time.time()
586 pingResultLinkUp = main.Mininet1.pingall()
587 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800588 timeDiff = round( ( time2 - time1 ), 2 )
589 main.log.report(
590 "Time taken for Ping All: " +
591 str( timeDiff ) +
592 " seconds" )
593 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
594 onpass="PING ALL PASS",
595 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800596
Hari Krishna22c3d412015-02-17 16:48:12 -0800597 caseResult80 = linkUp and pingResultLinkUp
598 utilities.assert_equals( expect=main.TRUE, actual=caseResult80,
kelvin-onlab8a832582015-01-16 17:06:11 -0800599 onpass="Link Up Test PASS",
600 onfail="Link Up Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800601
kelvin-onlab8a832582015-01-16 17:06:11 -0800602 def CASE71( self, main ):
603 """
604 Randomly bring some core links down and verify ping all ( Point Intents Scenario )
605 """
kelvin8ec71442015-01-15 16:57:00 -0800606 import random
Hari Krishna22c3d412015-02-17 16:48:12 -0800607 main.randomLink1 = []
608 main.randomLink2 = []
609 main.randomLink3 = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800610 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
611 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
612 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
613 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
614 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
615 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
616 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
617 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
kelvin8ec71442015-01-15 16:57:00 -0800618
Hari Krishnad97213e2015-01-24 19:30:14 -0800619 main.log.report( "Point Intents - Randomly bring some core links down and verify ping all" )
620 main.log.report( "__________________________________________________________________" )
621 main.case( "Point Intents - Randomly bring some core links down and verify ping all" )
622 main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800623 if ( int( switchLinksToToggle ) ==
624 0 or int( switchLinksToToggle ) > 5 ):
625 main.log.info(
626 "Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
kelvin8ec71442015-01-15 16:57:00 -0800627 main.cleanup()
628 main.exit()
629 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800630 main.log.info(
631 "User provided Core switch links range to toggle is correct, proceeding to run the test" )
kelvin8ec71442015-01-15 16:57:00 -0800632
kelvin-onlab8a832582015-01-16 17:06:11 -0800633 main.step( "Cut links on Core devices using user provided range" )
634 randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
635 randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
636 randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
637 for i in range( int( switchLinksToToggle ) ):
638 main.Mininet1.link(
639 END1=link1End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800640 END2=main.randomLink1[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800641 OPTION="down" )
642 main.Mininet1.link(
643 END1=link2End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800644 END2=main.randomLink2[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800645 OPTION="down" )
646 main.Mininet1.link(
647 END1=link3End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800648 END2=main.randomLink3[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800649 OPTION="down" )
650 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800651
652 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800653 linkDown = main.ONOSbench.checkStatus(
Hari Krishna22c3d412015-02-17 16:48:12 -0800654 topology_output, main.numSwitches, str(
655 int( main.numLinks ) - int( switchLinksToToggle ) * 6 ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800656 utilities.assert_equals(
657 expect=main.TRUE,
658 actual=linkDown,
659 onpass="Link Down discovered properly",
660 onfail="Link down was not discovered in " +
661 str( link_sleep ) +
662 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800663
kelvin-onlab8a832582015-01-16 17:06:11 -0800664 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800665 pingResultLinkDown = main.FALSE
666 time1 = time.time()
667 pingResultLinkDown = main.Mininet1.pingall()
668 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800669 timeDiff = round( ( time2 - time1 ), 2 )
670 main.log.report(
671 "Time taken for Ping All: " +
672 str( timeDiff ) +
673 " seconds" )
674 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
675 onpass="PING ALL PASS",
676 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800677
678 caseResult7 = linkDown and pingResultLinkDown
kelvin-onlab8a832582015-01-16 17:06:11 -0800679 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
680 onpass="Random Link cut Test PASS",
681 onfail="Random Link cut Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800682
kelvin-onlab8a832582015-01-16 17:06:11 -0800683 def CASE81( self, main ):
684 """
685 Bring the core links up that are down and verify ping all ( Point Intents Scenario )
686 """
kelvin8ec71442015-01-15 16:57:00 -0800687 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800688 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
689 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
690 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
691 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
692 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
kelvin8ec71442015-01-15 16:57:00 -0800693
kelvin-onlab8a832582015-01-16 17:06:11 -0800694 main.log.report(
695 "Point intents - Bring the core links up that are down and verify ping all" )
696 main.log.report(
697 "___________________________________________________________________" )
698 main.case(
699 "Point intents - Bring the core links up that are down and verify ping all" )
700 main.step( "Bring randomly cut links on Core devices up" )
701 for i in range( int( switchLinksToToggle ) ):
702 main.Mininet1.link(
703 END1=link1End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800704 END2=main.randomLink1[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800705 OPTION="up" )
706 main.Mininet1.link(
707 END1=link2End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800708 END2=main.randomLink2[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800709 OPTION="up" )
710 main.Mininet1.link(
711 END1=link3End1,
Hari Krishna22c3d412015-02-17 16:48:12 -0800712 END2=main.randomLink3[ i ],
kelvin-onlab8a832582015-01-16 17:06:11 -0800713 OPTION="up" )
714 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800715
716 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800717 linkUp = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800718 topology_output,
Hari Krishna22c3d412015-02-17 16:48:12 -0800719 main.numMNswitches,
720 str( main.numMNlinks ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800721 utilities.assert_equals(
722 expect=main.TRUE,
723 actual=linkUp,
724 onpass="Link up discovered properly",
725 onfail="Link up was not discovered in " +
726 str( link_sleep ) +
727 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800728
kelvin-onlab8a832582015-01-16 17:06:11 -0800729 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800730 pingResultLinkUp = main.FALSE
731 time1 = time.time()
732 pingResultLinkUp = main.Mininet1.pingall()
733 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800734 timeDiff = round( ( time2 - time1 ), 2 )
735 main.log.report(
736 "Time taken for Ping All: " +
737 str( timeDiff ) +
738 " seconds" )
739 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
740 onpass="PING ALL PASS",
741 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800742
Hari Krishna22c3d412015-02-17 16:48:12 -0800743 caseResult81 = linkUp and pingResultLinkUp
744 utilities.assert_equals( expect=main.TRUE, actual=caseResult81,
kelvin-onlab8a832582015-01-16 17:06:11 -0800745 onpass="Link Up Test PASS",
746 onfail="Link Up Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800747
kelvin-onlab8a832582015-01-16 17:06:11 -0800748 def CASE9( self ):
749 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800750 Install 114 point intents and verify Ping all works
kelvin-onlab8a832582015-01-16 17:06:11 -0800751 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800752 import copy
kelvin-onlab8a832582015-01-16 17:06:11 -0800753 main.log.report( "Install 114 point intents and verify Ping all" )
754 main.log.report( "___________________________________________" )
755 main.case( "Install 114 point intents and Ping all" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800756 deviceLinksCopy = copy.copy( main.deviceLinks )
kelvin-onlab8a832582015-01-16 17:06:11 -0800757 main.step( "Install 114 point intents" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800758 for i in range( len( deviceLinksCopy ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800759 pointLink = str(
Hari Krishna22c3d412015-02-17 16:48:12 -0800760 deviceLinksCopy[ i ] ).replace(
kelvin-onlab8a832582015-01-16 17:06:11 -0800761 "src=",
762 "" ).replace(
763 "dst=",
764 "" ).split( ',' )
765 point1 = pointLink[ 0 ].split( '/' )
766 point2 = pointLink[ 1 ].split( '/' )
Hari Krishnad97213e2015-01-24 19:30:14 -0800767 installResult = main.ONOScli1.addPointIntent(
kelvin-onlab8a832582015-01-16 17:06:11 -0800768 point1[ 0 ], point2[ 0 ], int(
769 point1[ 1 ] ), int(
770 point2[ 1 ] ) )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800771 if installResult == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800772 print "Installed Point intent between :", point1[ 0 ], int( point1[ 1 ] ), point2[ 0 ], int( point2[ 1 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800773
kelvin-onlab8a832582015-01-16 17:06:11 -0800774 main.step( "Obtain the intent id's" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800775 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800776 ansi_escape = re.compile( r'\x1b[^m]*m' )
777 intentsList = ansi_escape.sub( '', intentsList )
778 intentsList = intentsList.replace(
779 " onos:intents | grep id=",
780 "" ).replace(
781 "id=",
782 "" ).replace(
783 "\r\r",
784 "" )
785 intentsList = intentsList.splitlines()
786 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800787 intentIdList = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800788 for i in range( len( intentsList ) ):
789 intentsTemp = intentsList[ i ].split( ',' )
790 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800791 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800792 print "Total Intents installed: ", len( intentIdList )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800793
kelvin-onlab8a832582015-01-16 17:06:11 -0800794 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800795 pingResult = main.FALSE
796 time1 = time.time()
797 pingResult = main.Mininet1.pingall()
798 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800799 timeDiff = round( ( time2 - time1 ), 2 )
800 main.log.report(
801 "Time taken for Ping All: " +
802 str( timeDiff ) +
803 " seconds" )
804 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
805 onpass="PING ALL PASS",
806 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800807
808 case8_result = installResult and pingResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800809 utilities.assert_equals(
810 expect=main.TRUE,
811 actual=case8_result,
812 onpass="Ping all test after Point intents addition successful",
813 onfail="Ping all test after Point intents addition failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800814
kelvin-onlab8a832582015-01-16 17:06:11 -0800815 def CASE10( self ):
816 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800817 Remove all Intents
kelvin-onlab8a832582015-01-16 17:06:11 -0800818 """
819 main.log.report( "Remove all intents that were installed previously" )
820 main.log.report( "______________________________________________" )
821 main.log.info( "Remove all intents" )
822 main.case( "Removing intents" )
823 main.step( "Obtain the intent id's first" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800824 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800825 ansi_escape = re.compile( r'\x1b[^m]*m' )
826 intentsList = ansi_escape.sub( '', intentsList )
827 intentsList = intentsList.replace(
828 " onos:intents | grep id=",
829 "" ).replace(
830 "id=",
831 "" ).replace(
832 "\r\r",
833 "" )
834 intentsList = intentsList.splitlines()
835 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800836 intentIdList = []
837 step1Result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800838 if ( len( intentsList ) > 1 ):
839 for i in range( len( intentsList ) ):
840 intentsTemp = intentsList[ i ].split( ',' )
841 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800842 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800843 for id in range( len( intentIdList ) ):
844 print "Removing intent id (round 1) :", intentIdList[ id ]
Hari Krishna46997e02015-01-27 11:23:07 -0800845 main.ONOScli1.removeIntent( intentId=intentIdList[ id ] )
Hari Krishna22c3d412015-02-17 16:48:12 -0800846 #time.sleep( 1 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800847
kelvin-onlab8a832582015-01-16 17:06:11 -0800848 main.log.info(
849 "Verify all intents are removed and if any leftovers try remove one more time" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800850 intentsList1 = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800851 ansi_escape = re.compile( r'\x1b[^m]*m' )
852 intentsList1 = ansi_escape.sub( '', intentsList1 )
853 intentsList1 = intentsList1.replace(
854 " onos:intents | grep id=",
855 "" ).replace(
856 " state=",
857 "" ).replace(
858 "\r\r",
859 "" )
860 intentsList1 = intentsList1.splitlines()
861 intentsList1 = intentsList1[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800862 print "Round 2 (leftover) intents to remove: ", intentsList1
863 intentIdList1 = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800864 if ( len( intentsList1 ) > 1 ):
865 for i in range( len( intentsList1 ) ):
866 intentsTemp1 = intentsList[ i ].split( ',' )
867 intentIdList1.append( intentsTemp1[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800868 print "Leftover Intent IDs: ", intentIdList1
kelvin-onlab8a832582015-01-16 17:06:11 -0800869 for id in range( len( intentIdList1 ) ):
870 print "Removing intent id (round 2):", intentIdList1[ id ]
Hari Krishnad97213e2015-01-24 19:30:14 -0800871 main.ONOScli1.removeIntent(
Hari Krishna46997e02015-01-27 11:23:07 -0800872 intentId=intentIdList1[ id ] )
Hari Krishna22c3d412015-02-17 16:48:12 -0800873 #time.sleep( 2 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800874 else:
875 print "There are no more intents that need to be removed"
876 step1Result = main.TRUE
877 else:
878 print "No Intent IDs found in Intents list: ", intentsList
879 step1Result = main.FALSE
880
881 caseResult7 = step1Result
kelvin-onlab8a832582015-01-16 17:06:11 -0800882 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
883 onpass="Intent removal test successful",
884 onfail="Intent removal test failed" )
Hari Krishna22c3d412015-02-17 16:48:12 -0800885
886 def CASE11( self, main ):
887 """
888 Enable onos-app-ifwd, Verify Intent based Reactive forwarding through ping all and Disable it
889 """
890 import re
891 import copy
892 import time
893
894 main.log.report( "Enable Intent based Reactive forwarding and Verify ping all" )
895 main.log.report( "_____________________________________________________" )
896 main.case( "Enable Intent based Reactive forwarding and Verify ping all" )
897 main.step( "Enable intent based Reactive forwarding" )
898 installResult = main.TRUE
899 for i in range( 1, int( main.numCtrls ) + 1 ):
900 onosFeature = 'onos-app-ifwd'
901 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
902 ONOScli = 'ONOScli' + str( i )
903 main.log.info( "Enabling Intent based Reactive forwarding on ONOS Node " + ONOS_ip )
904 exec "inResult=main." + ONOScli + ".featureInstall(onosFeature)"
905 time.sleep( 3 )
906 installResult = inResult and installResult
907
908 time.sleep( 5 )
909
910 main.step( "Verify Pingall" )
911 ping_result = main.FALSE
912 time1 = time.time()
913 ping_result = main.Mininet1.pingall()
914 time2 = time.time()
915 timeDiff = round( ( time2 - time1 ), 2 )
916 main.log.report(
917 "Time taken for Ping All: " +
918 str( timeDiff ) +
919 " seconds" )
920
921 if ping_result == main.TRUE:
922 main.log.report( "Pingall Test in Reactive mode successful" )
923 else:
924 main.log.report( "Pingall Test in Reactive mode failed" )
925
926 main.step( "Disable Intent based Reactive forwarding" )
927 uninstallResult = main.TRUE
928 for i in range( 1, int( main.numCtrls ) + 1 ):
929 onosFeature = 'onos-app-ifwd'
930 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
931 ONOScli = 'ONOScli' + str( i )
932 main.log.info( "Disabling Intent based Reactive forwarding on ONOS Node " + ONOS_ip )
933 exec "unResult=main." + ONOScli + ".featureUninstall(onosFeature)"
934 uninstallResult = unResult and uninstallResult
935
936 # Waiting for reative flows to be cleared.
937 time.sleep( 10 )
938
939 case11Result = installResult and ping_result and uninstallResult
940 utilities.assert_equals( expect=main.TRUE, actual=case11Result,
941 onpass="Intent based Reactive forwarding Pingall test PASS",
942 onfail="Intent based Reactive forwarding Pingall test FAIL" )
943
944 def CASE12( self, main ):
945 """
946 This test script Loads a new Topology (Chordal) on CHO setup and balances all switches
947 """
948 import re
949 import time
950 import copy
951
952 newTopo = main.params['TOPO2']['topo']
953 main.numMNswitches = int ( main.params[ 'TOPO2' ][ 'numSwitches' ] )
954 main.numMNlinks = int ( main.params[ 'TOPO2' ][ 'numLinks' ] )
955 main.numMNhosts = int ( main.params[ 'TOPO2' ][ 'numHosts' ] )
956
957 main.log.report(
958 "Load Chordal topology and Balance all Mininet switches across controllers" )
959 main.log.report(
960 "________________________________________________________________________" )
961 # need to wait here for sometime until ONOS bootup
962 time.sleep( 15 )
963 main.case(
964 "Assign and Balance all Mininet switches across controllers" )
965 main.step( "Stop any previous Mininet network topology" )
966 stopStatus = main.Mininet1.stopNet()
967
968 # WORK AROUND FOR ONOS-581. STOP ONOS BEFORE ASSIGNING CONTROLLERS AT MININET & START ONCE DONE
969 main.step( "Stop ONOS on all Nodes" )
970 stopResult = main.TRUE
971 for i in range( 1, int( main.numCtrls ) + 1 ):
972 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
973 main.log.info( "Stopping ONOS Node IP: " + ONOS_ip )
974 sresult = main.ONOSbench.onosStop( ONOS_ip )
975 utilities.assert_equals( expect=main.TRUE, actual=sresult,
976 onpass="Test step PASS",
977 onfail="Test step FAIL" )
978 stopResult = ( stopResult and sresult )
979
980 main.step( "Start Mininet with Chordal topology" )
981 startStatus = main.Mininet1.startNet(topoFile = newTopo)
982
983 main.step( "Assign switches to controllers" )
984 for i in range( 1, ( main.numMNswitches + 1 ) ): # 1 to ( num of switches +1 )
985 main.Mininet1.assignSwController(
986 sw=str( i ),
987 count=int( main.numCtrls ),
988 ip1=main.ONOS1_ip,
989 port1=main.ONOS1_port,
990 ip2=main.ONOS2_ip,
991 port2=main.ONOS2_port,
992 ip3=main.ONOS3_ip,
993 port3=main.ONOS3_port,
994 ip4=main.ONOS4_ip,
995 port4=main.ONOS4_port,
996 ip5=main.ONOS5_ip,
997 port5=main.ONOS5_port )
998
999 switch_mastership = main.TRUE
1000 for i in range( 1, ( main.numMNswitches + 1 ) ):
1001 response = main.Mininet1.getSwController( "s" + str( i ) )
1002 print( "Response is " + str( response ) )
1003 if re.search( "tcp:" + main.ONOS1_ip, response ):
1004 switch_mastership = switch_mastership and main.TRUE
1005 else:
1006 switch_mastership = main.FALSE
1007
1008 if switch_mastership == main.TRUE:
1009 main.log.report( "Controller assignment successfull" )
1010 else:
1011 main.log.report( "Controller assignment failed" )
1012 time.sleep( 5 )
1013
1014 main.step( "Start ONOS on all Nodes" )
1015 startResult = main.TRUE
1016 for i in range( 1, int( main.numCtrls ) + 1 ):
1017 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
1018 main.log.info( "Starting ONOS Node IP: " + ONOS_ip )
1019 sresult = main.ONOSbench.onosStart( ONOS_ip )
1020 utilities.assert_equals( expect=main.TRUE, actual=sresult,
1021 onpass="Test step PASS",
1022 onfail="Test step FAIL" )
1023 startResult = ( startResult and sresult )
1024
1025 main.step( "Start ONOS CLI on all nodes" )
1026 cliResult = main.TRUE
1027 #karafTimeout = "3600000" # This is not needed here as it is already set before.
1028 # need to wait here sometime for ONOS to bootup.
1029 time.sleep( 30 )
1030 for i in range( 1, int( main.numCtrls ) + 1 ):
1031 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
1032 ONOScli = 'ONOScli' + str( i )
1033 main.log.info( "ONOS Node " + ONOS_ip + " cli start:" )
1034 exec "startcli=main." + ONOScli + \
1035 ".startOnosCli(ONOS_ip)"
1036 utilities.assert_equals( expect=main.TRUE, actual=startcli,
1037 onpass="Test step PASS",
1038 onfail="Test step FAIL" )
1039 cliResult = ( cliResult and startcli )
1040
1041 main.step( "Balance devices across controllers" )
1042 for i in range( int( main.numCtrls ) ):
1043 balanceResult = main.ONOScli1.balanceMasters()
1044 # giving some breathing time for ONOS to complete re-balance
1045 time.sleep( 3 )
1046
1047 case12Result = ( startResult and cliResult )
1048 utilities.assert_equals(
1049 expect=main.TRUE,
1050 actual=case12Result,
1051 onpass="Starting new Chordal topology test PASS",
1052 onfail="Starting new Chordal topology test FAIL" )
1053
1054 def CASE13( self, main ):
1055 """
1056 This test script Loads a new Topology (Spine) on CHO setup and balances all switches
1057 """
1058 import re
1059 import time
1060 import copy
1061
1062 newTopo = main.params['TOPO3']['topo']
1063 main.numMNswitches = int ( main.params[ 'TOPO3' ][ 'numSwitches' ] )
1064 main.numMNlinks = int ( main.params[ 'TOPO3' ][ 'numLinks' ] )
1065 main.numMNhosts = int ( main.params[ 'TOPO3' ][ 'numHosts' ] )
1066
1067 main.log.report(
1068 "Load Spine and Leaf topology and Balance all Mininet switches across controllers" )
1069 main.log.report(
1070 "________________________________________________________________________" )
1071 # need to wait here for sometime until ONOS bootup
1072 time.sleep( 15 )
1073 main.case(
1074 "Assign and Balance all Mininet switches across controllers" )
1075 main.step( "Stop any previous Mininet network topology" )
1076 stopStatus = main.Mininet1.stopNet()
1077
1078 # WORK AROUND FOR ONOS-581. STOP ONOS BEFORE ASSIGNING CONTROLLERS AT MININET & START ONCE DONE
1079 main.step( "Stop ONOS on all Nodes" )
1080 stopResult = main.TRUE
1081 for i in range( 1, int( main.numCtrls ) + 1 ):
1082 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
1083 main.log.info( "Stopping ONOS Node IP: " + ONOS_ip )
1084 sresult = main.ONOSbench.onosStop( ONOS_ip )
1085 utilities.assert_equals( expect=main.TRUE, actual=sresult,
1086 onpass="Test step PASS",
1087 onfail="Test step FAIL" )
1088 stopResult = ( stopResult and sresult )
1089
1090 main.step( "Start Mininet with Spine topology" )
1091 startStatus = main.Mininet1.startNet(topoFile = newTopo)
1092
1093 main.step( "Assign switches to controllers" )
1094 for i in range( 1, ( main.numMNswitches + 1 ) ): # 1 to ( num of switches +1 )
1095 main.Mininet1.assignSwController(
1096 sw=str( i ),
1097 count=int( main.numCtrls ),
1098 ip1=main.ONOS1_ip,
1099 port1=main.ONOS1_port,
1100 ip2=main.ONOS2_ip,
1101 port2=main.ONOS2_port,
1102 ip3=main.ONOS3_ip,
1103 port3=main.ONOS3_port,
1104 ip4=main.ONOS4_ip,
1105 port4=main.ONOS4_port,
1106 ip5=main.ONOS5_ip,
1107 port5=main.ONOS5_port )
1108
1109 switch_mastership = main.TRUE
1110 for i in range( 1, ( main.numMNswitches + 1 ) ):
1111 response = main.Mininet1.getSwController( "s" + str( i ) )
1112 print( "Response is " + str( response ) )
1113 if re.search( "tcp:" + main.ONOS1_ip, response ):
1114 switch_mastership = switch_mastership and main.TRUE
1115 else:
1116 switch_mastership = main.FALSE
1117
1118 if switch_mastership == main.TRUE:
1119 main.log.report( "Controller assignment successfull" )
1120 else:
1121 main.log.report( "Controller assignment failed" )
1122 time.sleep( 5 )
1123
1124 main.step( "Start ONOS on all Nodes" )
1125 startResult = main.TRUE
1126 for i in range( 1, int( main.numCtrls ) + 1 ):
1127 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
1128 main.log.info( "Starting ONOS Node IP: " + ONOS_ip )
1129 sresult = main.ONOSbench.onosStart( ONOS_ip )
1130 utilities.assert_equals( expect=main.TRUE, actual=sresult,
1131 onpass="Test step PASS",
1132 onfail="Test step FAIL" )
1133 startResult = ( startResult and sresult )
1134
1135 main.step( "Start ONOS CLI on all nodes" )
1136 cliResult = main.TRUE
1137 #karafTimeout = "3600000" # This is not needed here as it is already set before.
1138 # need to wait here sometime for ONOS to bootup.
1139 time.sleep( 30 )
1140 for i in range( 1, int( main.numCtrls ) + 1 ):
1141 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
1142 ONOScli = 'ONOScli' + str( i )
1143 main.log.info( "ONOS Node " + ONOS_ip + " cli start:" )
1144 exec "startcli=main." + ONOScli + \
1145 ".startOnosCli(ONOS_ip)"
1146 utilities.assert_equals( expect=main.TRUE, actual=startcli,
1147 onpass="Test step PASS",
1148 onfail="Test step FAIL" )
1149 cliResult = ( cliResult and startcli )
1150
1151 main.step( "Balance devices across controllers" )
1152 for i in range( int( main.numCtrls ) ):
1153 balanceResult = main.ONOScli1.balanceMasters()
1154 # giving some breathing time for ONOS to complete re-balance
1155 time.sleep( 3 )
1156
1157 case13Result = ( startResult and cliResult )
1158 utilities.assert_equals(
1159 expect=main.TRUE,
1160 actual=case13Result,
1161 onpass="Starting new Spine topology test PASS",
1162 onfail="Starting new Spine topology test FAIL" )