blob: fc24724ac54be96435cd4a1ecee8ffc0aa286f94 [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 = ''
14 global deviceDPIDs
15 global hostMACs
16 global deviceLinks
17 global deviceActiveLinksCount
18 global devicePortsEnabledCount
19 global installedIntents
20 global randomLink1, randomLink2, randomLink3, numSwitches, numLinks
kelvin8ec71442015-01-15 16:57:00 -080021
kelvin-onlab8a832582015-01-16 17:06:11 -080022 def CASE1( self, main ):
23 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080024 Startup sequence:
25 git pull
26 mvn clean install
27 onos-package
28 cell <name>
29 onos-verify-cell
30 onos-install -f
31 onos-wait-for-start
kelvin-onlab8a832582015-01-16 17:06:11 -080032 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -080033 import time
kelvin-onlab8a832582015-01-16 17:06:11 -080034 cell_name = main.params[ 'ENV' ][ 'cellName' ]
35 git_pull = main.params[ 'GIT' ][ 'autoPull' ]
36 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
37 git_branch = main.params[ 'GIT' ][ 'branch' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -080038
kelvin-onlab8a832582015-01-16 17:06:11 -080039 main.case( "Set up test environment" )
40 main.log.report( "Set up test environment" )
41 main.log.report( "_______________________" )
42
43 main.step( "Git checkout and pull " + git_branch )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080044 if git_pull == 'on':
Hari Krishnad97213e2015-01-24 19:30:14 -080045 checkout_result = main.ONOSbench.gitCheckout( git_branch )
46 pull_result = main.ONOSbench.gitPull()
kelvin-onlab8a832582015-01-16 17:06:11 -080047 cp_result = ( checkout_result and pull_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080048 else:
49 checkout_result = main.TRUE
50 pull_result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -080051 main.log.info( "Skipped git checkout and pull" )
52 cp_result = ( checkout_result and pull_result )
53 utilities.assert_equals( expect=main.TRUE, actual=cp_result,
54 onpass="Test step PASS",
55 onfail="Test step FAIL" )
56
57 main.step( "mvn clean & install" )
Hari Krishnad97213e2015-01-24 19:30:14 -080058 mvn_result = main.ONOSbench.cleanInstall()
kelvin-onlab8a832582015-01-16 17:06:11 -080059 utilities.assert_equals( expect=main.TRUE, actual=mvn_result,
60 onpass="Test step PASS",
61 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080062
Hari Krishnad97213e2015-01-24 19:30:14 -080063 main.ONOSbench.getVersion( report=True )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080064
kelvin-onlab8a832582015-01-16 17:06:11 -080065 main.step( "Apply Cell environment for ONOS" )
Hari Krishnad97213e2015-01-24 19:30:14 -080066 cell_result = main.ONOSbench.setCell( cell_name )
kelvin-onlab8a832582015-01-16 17:06:11 -080067 utilities.assert_equals( expect=main.TRUE, actual=cell_result,
68 onpass="Test step PASS",
69 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080070
kelvin-onlab8a832582015-01-16 17:06:11 -080071 main.step( "Create ONOS package" )
Hari Krishnad97213e2015-01-24 19:30:14 -080072 packageResult = main.ONOSbench.onosPackage()
kelvin-onlab8a832582015-01-16 17:06:11 -080073 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
74 onpass="Test step PASS",
75 onfail="Test step FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080076
kelvin-onlab8a832582015-01-16 17:06:11 -080077 main.step( "Uninstall ONOS package on all Nodes" )
78 uninstallResult = main.TRUE
79 for i in range( 1, int( numCtrls ) + 1 ):
80 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
81 main.log.info( "Unintsalling package on ONOS Node IP: " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -080082 u_result = main.ONOSbench.onosUninstall( ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -080083 utilities.assert_equals( expect=main.TRUE, actual=u_result,
84 onpass="Test step PASS",
85 onfail="Test step FAIL" )
86 uninstallResult = ( uninstallResult and u_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -080087
kelvin-onlab8a832582015-01-16 17:06:11 -080088 main.step( "Removing copy-cat logs from ONOS nodes" )
Hari Krishnad97213e2015-01-24 19:30:14 -080089 main.ONOSbench.onosRemoveRaftLogs()
Hari Krishnaa43d4e92014-12-19 13:22:40 -080090
kelvin-onlab8a832582015-01-16 17:06:11 -080091 main.step( "Install ONOS package on all Nodes" )
92 installResult = main.TRUE
93 for i in range( 1, int( numCtrls ) + 1 ):
94 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
95 main.log.info( "Intsalling package on ONOS Node IP: " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -080096 i_result = main.ONOSbench.onosInstall( node=ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -080097 utilities.assert_equals( expect=main.TRUE, actual=i_result,
98 onpass="Test step PASS",
99 onfail="Test step FAIL" )
100 installResult = ( installResult and i_result )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800101
kelvin-onlab8a832582015-01-16 17:06:11 -0800102 main.step( "Verify ONOS nodes UP status" )
103 statusResult = main.TRUE
104 for i in range( 1, int( numCtrls ) + 1 ):
105 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
106 main.log.info( "ONOS Node " + ONOS_ip + " status:" )
Hari Krishnad97213e2015-01-24 19:30:14 -0800107 onos_status = main.ONOSbench.onosStatus( node=ONOS_ip )
kelvin-onlab8a832582015-01-16 17:06:11 -0800108 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
109 onpass="Test step PASS",
110 onfail="Test step FAIL" )
111 statusResult = ( statusResult and onos_status )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800112
kelvin-onlab8a832582015-01-16 17:06:11 -0800113 main.step( "Start ONOS CLI on all nodes" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800114 cliResult = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800115 karafTimeout = "3600000"
kelvin-onlab8a832582015-01-16 17:06:11 -0800116 # need to wait here for sometime. This will be removed once ONOS is
117 # stable enough
118 time.sleep( 15 )
119 for i in range( 1, int( numCtrls ) + 1 ):
120 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
121 ONOScli = 'ONOScli' + str( i )
122 main.log.info( "ONOS Node " + ONOS_ip + " cli start:" )
123 exec "startcli=main." + ONOScli + \
Hari Krishnad97213e2015-01-24 19:30:14 -0800124 ".startOnosCli(ONOS_ip, karafTimeout=karafTimeout)"
kelvin-onlab8a832582015-01-16 17:06:11 -0800125 utilities.assert_equals( expect=main.TRUE, actual=startcli,
126 onpass="Test step PASS",
127 onfail="Test step FAIL" )
128 cliResult = ( cliResult and startcli )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800129
kelvin-onlab8a832582015-01-16 17:06:11 -0800130 case1Result = ( cp_result and cell_result
131 and packageResult and installResult and statusResult and cliResult )
132 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
133 onpass="Set up test environment PASS",
134 onfail="Set up test environment FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800135
kelvin-onlab8a832582015-01-16 17:06:11 -0800136 def CASE2( self, main ):
137 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800138 This test script still needs more refactoring
kelvin-onlab8a832582015-01-16 17:06:11 -0800139 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800140 import re
141 import time
142 import copy
kelvin-onlab8a832582015-01-16 17:06:11 -0800143 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
144 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
145 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
146 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
147 ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ]
148 ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ]
149 ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
150 ONOS2_port = main.params[ 'CTRL' ][ 'port2' ]
151 ONOS3_port = main.params[ 'CTRL' ][ 'port3' ]
152 ONOS4_port = main.params[ 'CTRL' ][ 'port4' ]
153 ONOS5_port = main.params[ 'CTRL' ][ 'port5' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800154
kelvin-onlab8a832582015-01-16 17:06:11 -0800155 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
156 main.log.report(
157 "Assign and Balance all Mininet switches across controllers" )
158 main.log.report(
159 "_________________________________________________________" )
160 # need to wait here for sometime. This will be removed once ONOS is
161 # stable enough
162 time.sleep( 15 )
163 main.case(
164 "Assign and Balance all Mininet switches across controllers" )
165 main.step( "Assign switches to controllers" )
166 for i in range( 1, 26 ): # 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 ),
169 count=int( numCtrls ),
170 ip1=ONOS1_ip,
171 port1=ONOS1_port,
172 ip2=ONOS2_ip,
173 port2=ONOS2_port,
174 ip3=ONOS3_ip,
175 port3=ONOS3_port,
176 ip4=ONOS4_ip,
177 port4=ONOS4_port,
178 ip5=ONOS5_ip,
179 port5=ONOS5_port )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800180
181 switch_mastership = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800182 for i in range( 1, 26 ):
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 ) )
185 if re.search( "tcp:" + 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" )
194 time.sleep( 5 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800195
kelvin-onlab8a832582015-01-16 17:06:11 -0800196 main.step( "Balance devices across controllers" )
197 for i in range( int( numCtrls ) ):
Hari Krishnad97213e2015-01-24 19:30:14 -0800198 balanceResult = main.ONOScli1.balanceMasters()
kelvin-onlab8a832582015-01-16 17:06:11 -0800199 # giving some breathing time for ONOS to complete re-balance
200 time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800201
kelvin-onlab8a832582015-01-16 17:06:11 -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
215 deviceDPIDs = []
216 hostMACs = []
217 deviceLinks = []
218 deviceActiveLinksCount = []
219 devicePortsEnabledCount = []
220
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 )
kelvin-onlab8a832582015-01-16 17:06:11 -0800230 numSwitches = topology_result[ 'devices' ]
231 numLinks = topology_result[ 'links' ]
232 main.log.info(
233 "Currently there are %s switches and %s links" %
234 ( str( numSwitches ), str( numLinks ) ) )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800235
kelvin-onlab8a832582015-01-16 17:06:11 -0800236 main.step( "Store Device DPIDs" )
237 for i in range( 1, 26 ):
238 deviceDPIDs.append( "of:00000000000000" + format( i, '02x' ) )
239 print "Device DPIDs in Store: \n", str( deviceDPIDs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800240
kelvin-onlab8a832582015-01-16 17:06:11 -0800241 main.step( "Store Host MACs" )
242 for i in range( 1, 26 ):
243 hostMACs.append( "00:00:00:00:00:" + format( i, '02x' ) + "/-1" )
244 print "Host MACs in Store: \n", str( hostMACs )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800245
kelvin-onlab8a832582015-01-16 17:06:11 -0800246 main.step( "Collect and store all Devices Links" )
Hari Krishnad97213e2015-01-24 19:30:14 -0800247 linksResult = main.ONOScli1.links( jsonFormat=False )
kelvin-onlab8a832582015-01-16 17:06:11 -0800248 ansi_escape = re.compile( r'\x1b[^m]*m' )
249 linksResult = ansi_escape.sub( '', linksResult )
250 linksResult = linksResult.replace( " links", "" ).replace( "\r\r", "" )
251 linksResult = linksResult.splitlines()
252 linksResult = linksResult[ 1: ]
253 deviceLinks = copy.copy( linksResult )
254 print "Device Links Stored: \n", str( deviceLinks )
255 # this will be asserted to check with the params provided count of
256 # links
257 print "Length of Links Store", len( deviceLinks )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800258
kelvin-onlab8a832582015-01-16 17:06:11 -0800259 main.step( "Collect and store each Device ports enabled Count" )
260 for i in range( 1, 26 ):
261 portResult = main.ONOScli1.getDevicePortsEnabledCount(
Hari Krishnad97213e2015-01-24 19:30:14 -0800262 "of:00000000000000" + format( i,'02x' ) )
263 print portResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800264 portTemp = re.split( r'\t+', portResult )
265 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
266 devicePortsEnabledCount.append( portCount )
267 print "Device Enabled Port Counts Stored: \n", str( devicePortsEnabledCount )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800268
kelvin-onlab8a832582015-01-16 17:06:11 -0800269 main.step( "Collect and store each Device active links Count" )
270 for i in range( 1, 26 ):
271 linkCountResult = main.ONOScli1.getDeviceLinksActiveCount(
Hari Krishnad97213e2015-01-24 19:30:14 -0800272 "of:00000000000000" + format( i,'02x' ) )
kelvin-onlab8a832582015-01-16 17:06:11 -0800273 linkCountTemp = re.split( r'\t+', linkCountResult )
274 linkCount = linkCountTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
275 deviceActiveLinksCount.append( linkCount )
276 print "Device Active Links Count Stored: \n", str( deviceActiveLinksCount )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800277
kelvin-onlab8a832582015-01-16 17:06:11 -0800278 # just returning TRUE for now as this one just collects data
279 caseResult = main.TRUE
280 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
281 onpass="Saving ONOS topology data test PASS",
282 onfail="Saving ONOS topology data test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800283
kelvin-onlab8a832582015-01-16 17:06:11 -0800284 def CASE4( self, main ):
285 """
286 Enable onos-app-fwd, Verify Reactive forwarding through ping all and Disable it
287 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800288 import re
289 import copy
290 import time
kelvin-onlab8a832582015-01-16 17:06:11 -0800291 numCtrls = main.params[ 'CTRL' ][ 'numCtrl' ]
292 main.log.report( "Enable Reactive forwarding and Verify ping all" )
293 main.log.report( "______________________________________________" )
294 main.case( "Enable Reactive forwarding and Verify ping all" )
295 main.step( "Enable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800296 installResult = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800297 for i in range( 1, int( numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800298 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800299 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
300 ONOScli = 'ONOScli' + str( i )
301 main.log.info( "Enabling Reactive mode on ONOS Node " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -0800302 exec "inResult=main." + ONOScli + ".featureInstall(onosFeature)"
kelvin-onlab8a832582015-01-16 17:06:11 -0800303 time.sleep( 3 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800304 installResult = inResult and installResult
305
kelvin-onlab8a832582015-01-16 17:06:11 -0800306 time.sleep( 5 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800307
kelvin-onlab8a832582015-01-16 17:06:11 -0800308 main.step( "Verify Pingall" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800309 ping_result = main.FALSE
310 time1 = time.time()
311 ping_result = main.Mininet1.pingall()
312 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800313 timeDiff = round( ( time2 - time1 ), 2 )
314 main.log.report(
315 "Time taken for Ping All: " +
316 str( timeDiff ) +
317 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800318
319 if ping_result == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800320 main.log.report( "Pingall Test in Reactive mode successful" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800321 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800322 main.log.report( "Pingall Test in Reactive mode failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800323
kelvin-onlab8a832582015-01-16 17:06:11 -0800324 main.step( "Disable Reactive forwarding" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800325 uninstallResult = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800326 for i in range( 1, int( numCtrls ) + 1 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800327 onosFeature = 'onos-app-fwd'
kelvin-onlab8a832582015-01-16 17:06:11 -0800328 ONOS_ip = main.params[ 'CTRL' ][ 'ip' + str( i ) ]
329 ONOScli = 'ONOScli' + str( i )
330 main.log.info( "Disabling Reactive mode on ONOS Node " + ONOS_ip )
Hari Krishnad97213e2015-01-24 19:30:14 -0800331 exec "unResult=main." + ONOScli + ".featureUninstall(onosFeature)"
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800332 uninstallResult = unResult and uninstallResult
333
kelvin-onlab8a832582015-01-16 17:06:11 -0800334 # Waiting for reative flows to be cleared.
335 time.sleep( 10 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800336
337 case3Result = installResult and ping_result and uninstallResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800338 utilities.assert_equals( expect=main.TRUE, actual=case3Result,
339 onpass="Reactive Mode Pingall test PASS",
340 onfail="Reactive Mode Pingall test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800341
kelvin-onlab8a832582015-01-16 17:06:11 -0800342 def CASE5( self, main ):
343 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800344 Compare current ONOS topology with reference data
kelvin-onlab8a832582015-01-16 17:06:11 -0800345 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800346 import re
347 devicesDPID_tmp = []
348 hostMACs_tmp = []
349 deviceLinks_tmp = []
350 deviceActiveLinksCount_tmp = []
351 devicePortsEnabledCount_tmp = []
352
kelvin-onlab8a832582015-01-16 17:06:11 -0800353 main.log.report(
354 "Compare ONOS topology with reference data in Stores" )
355 main.log.report( "__________________________________________________" )
356 main.case( "Compare ONOS topology with reference data" )
357
358 main.step( "Compare current Device ports enabled with reference" )
359 for i in range( 1, 26 ):
360 portResult = main.ONOScli1.getDevicePortsEnabledCount(
361 "of:00000000000000" +
362 format(
363 i,
364 '02x' ) )
365 portTemp = re.split( r'\t+', portResult )
366 portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
367 devicePortsEnabledCount_tmp.append( portCount )
368 time.sleep( 2 )
369 print (
370 "Device Enabled ports EXPECTED: \n" +
371 str( devicePortsEnabledCount ) )
372 print (
373 "Device Enabled ports ACTUAL: \n" +
374 str( devicePortsEnabledCount_tmp ) )
375 if ( cmp( devicePortsEnabledCount,
376 devicePortsEnabledCount_tmp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800377 stepResult1 = main.TRUE
378 else:
379 stepResult1 = main.FALSE
380
kelvin-onlab8a832582015-01-16 17:06:11 -0800381 main.step( "Compare Device active links with reference" )
382 for i in range( 1, 26 ):
383 linkResult = main.ONOScli1.getDeviceLinksActiveCount(
384 "of:00000000000000" +
385 format(
386 i,
387 '02x' ) )
388 linkTemp = re.split( r'\t+', linkResult )
389 linkCount = linkTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
390 deviceActiveLinksCount_tmp.append( linkCount )
391 time.sleep( 3 )
392 print (
393 "Device Active links EXPECTED: \n" +
394 str( deviceActiveLinksCount ) )
395 print (
396 "Device Active links ACTUAL: \n" +
397 str( deviceActiveLinksCount_tmp ) )
398 if ( cmp( deviceActiveLinksCount, deviceActiveLinksCount_tmp ) == 0 ):
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800399 stepResult2 = main.TRUE
400 else:
401 stepResult2 = main.FALSE
402
kelvin-onlab8a832582015-01-16 17:06:11 -0800403 """
404 place holder for comparing devices, hosts and paths if required.
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800405 Links and ports data would be incorrect with out devices anyways.
kelvin-onlab8a832582015-01-16 17:06:11 -0800406 """
407 caseResult = ( stepResult1 and stepResult2 )
408 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
409 onpass="Compare Topology test PASS",
410 onfail="Compare Topology test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800411 if caseResult == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800412 main.log.report( "Compare Topology test Pass" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800413
kelvin-onlab8a832582015-01-16 17:06:11 -0800414 def CASE6( self ):
415 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800416 Install 300 host intents and verify ping all
kelvin-onlab8a832582015-01-16 17:06:11 -0800417 """
418 main.log.report( "Add 300 host intents and verify pingall" )
419 main.log.report( "_______________________________________" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800420 import itertools
kelvin-onlab8a832582015-01-16 17:06:11 -0800421 main.case( "Install 300 host intents" )
422 main.step( "Add host Intents" )
423 intentResult = main.TRUE
424 hostCombos = list( itertools.combinations( hostMACs, 2 ) )
425 for i in range( len( hostCombos ) ):
Hari Krishnad97213e2015-01-24 19:30:14 -0800426 iResult = main.ONOScli1.addHostIntent(
kelvin-onlab8a832582015-01-16 17:06:11 -0800427 hostCombos[ i ][ 0 ],
428 hostCombos[ i ][ 1 ] )
429 intentResult = ( intentResult and iResult )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800430
kelvin-onlab8a832582015-01-16 17:06:11 -0800431 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800432 pingResult = main.FALSE
433 time1 = time.time()
434 pingResult = main.Mininet1.pingall()
435 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800436 timeDiff = round( ( time2 - time1 ), 2 )
437 main.log.report(
438 "Time taken for Ping All: " +
439 str( timeDiff ) +
440 " seconds" )
441 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
442 onpass="PING ALL PASS",
443 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800444
kelvin-onlab8a832582015-01-16 17:06:11 -0800445 case4Result = ( intentResult and pingResult )
446 utilities.assert_equals(
447 expect=main.TRUE,
448 actual=case4Result,
449 onpass="Install 300 Host Intents and Ping All test PASS",
450 onfail="Install 300 Host Intents and Ping All test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800451
kelvin-onlab8a832582015-01-16 17:06:11 -0800452 def CASE70( self, main ):
453 """
454 Randomly bring some core links down and verify ping all ( Host Intents Scenario )
455 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800456 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800457 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
458 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
459 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
460 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
461 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
462 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
463 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
464 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
465 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800466
Hari Krishnad97213e2015-01-24 19:30:14 -0800467 main.log.report( "Host intents - Randomly bring some core links down and verify ping all" )
468 main.log.report( "_________________________________________________________________" )
469 main.case( "Host intents - Randomly bring some core links down and verify ping all" )
470 main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800471 if ( int( switchLinksToToggle ) ==
472 0 or int( switchLinksToToggle ) > 5 ):
Hari Krishnad97213e2015-01-24 19:30:14 -0800473 main.log.info( "Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800474 main.cleanup()
475 main.exit()
476 else:
Hari Krishnad97213e2015-01-24 19:30:14 -0800477 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 -0800478
kelvin-onlab8a832582015-01-16 17:06:11 -0800479 main.step( "Cut links on Core devices using user provided range" )
480 randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
481 randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
482 randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
483 for i in range( int( switchLinksToToggle ) ):
484 main.Mininet1.link(
485 END1=link1End1,
486 END2=randomLink1[ i ],
487 OPTION="down" )
488 main.Mininet1.link(
489 END1=link2End1,
490 END2=randomLink2[ i ],
491 OPTION="down" )
492 main.Mininet1.link(
493 END1=link3End1,
494 END2=randomLink3[ i ],
495 OPTION="down" )
496 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800497
498 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800499 linkDown = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800500 topology_output, numSwitches, str(
501 int( numLinks ) - int( switchLinksToToggle ) * 6 ) )
502 utilities.assert_equals(
503 expect=main.TRUE,
504 actual=linkDown,
505 onpass="Link Down discovered properly",
506 onfail="Link down was not discovered in " +
507 str( link_sleep ) +
508 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800509
kelvin-onlab8a832582015-01-16 17:06:11 -0800510 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800511 pingResultLinkDown = main.FALSE
512 time1 = time.time()
513 pingResultLinkDown = main.Mininet1.pingall()
514 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800515 timeDiff = round( ( time2 - time1 ), 2 )
516 main.log.report(
517 "Time taken for Ping All: " +
518 str( timeDiff ) +
519 " seconds" )
520 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
521 onpass="PING ALL PASS",
522 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800523
524 caseResult7 = linkDown and pingResultLinkDown
kelvin-onlab8a832582015-01-16 17:06:11 -0800525 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
526 onpass="Random Link cut Test PASS",
527 onfail="Random Link cut Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800528
kelvin-onlab8a832582015-01-16 17:06:11 -0800529 def CASE80( self, main ):
530 """
531 Bring the core links up that are down and verify ping all ( Host Intents Scenario )
532 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800533 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800534 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
535 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
536 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
537 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
538 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
539 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800540
kelvin-onlab8a832582015-01-16 17:06:11 -0800541 main.log.report(
542 "Host intents - Bring the core links up that are down and verify ping all" )
543 main.log.report(
544 "__________________________________________________________________" )
545 main.case(
546 "Host intents - Bring the core links up that are down and verify ping all" )
547 main.step( "Bring randomly cut links on Core devices up" )
548 for i in range( int( switchLinksToToggle ) ):
549 main.Mininet1.link(
550 END1=link1End1,
551 END2=randomLink1[ i ],
552 OPTION="up" )
553 main.Mininet1.link(
554 END1=link2End1,
555 END2=randomLink2[ i ],
556 OPTION="up" )
557 main.Mininet1.link(
558 END1=link3End1,
559 END2=randomLink3[ i ],
560 OPTION="up" )
561 time.sleep( link_sleep )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800562
563 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800564 linkUp = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800565 topology_output,
566 numSwitches,
567 str( numLinks ) )
568 utilities.assert_equals(
569 expect=main.TRUE,
570 actual=linkUp,
571 onpass="Link up discovered properly",
572 onfail="Link up was not discovered in " +
573 str( link_sleep ) +
574 " seconds" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800575
kelvin-onlab8a832582015-01-16 17:06:11 -0800576 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800577 pingResultLinkUp = main.FALSE
578 time1 = time.time()
579 pingResultLinkUp = main.Mininet1.pingall()
580 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800581 timeDiff = round( ( time2 - time1 ), 2 )
582 main.log.report(
583 "Time taken for Ping All: " +
584 str( timeDiff ) +
585 " seconds" )
586 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
587 onpass="PING ALL PASS",
588 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800589
590 caseResult8 = linkUp and pingResultLinkUp
kelvin-onlab8a832582015-01-16 17:06:11 -0800591 utilities.assert_equals( expect=main.TRUE, actual=caseResult8,
592 onpass="Link Up Test PASS",
593 onfail="Link Up Test FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800594
kelvin-onlab8a832582015-01-16 17:06:11 -0800595 def CASE71( self, main ):
596 """
597 Randomly bring some core links down and verify ping all ( Point Intents Scenario )
598 """
kelvin8ec71442015-01-15 16:57:00 -0800599 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800600 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
601 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
602 link1End2 = main.params[ 'CORELINKS' ][ 'linkS3b' ].split( ',' )
603 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
604 link2End2 = main.params[ 'CORELINKS' ][ 'linkS14b' ].split( ',' )
605 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
606 link3End2 = main.params[ 'CORELINKS' ][ 'linkS18b' ].split( ',' )
607 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
608 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
kelvin8ec71442015-01-15 16:57:00 -0800609
Hari Krishnad97213e2015-01-24 19:30:14 -0800610 main.log.report( "Point Intents - Randomly bring some core links down and verify ping all" )
611 main.log.report( "__________________________________________________________________" )
612 main.case( "Point Intents - Randomly bring some core links down and verify ping all" )
613 main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800614 if ( int( switchLinksToToggle ) ==
615 0 or int( switchLinksToToggle ) > 5 ):
616 main.log.info(
617 "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 -0800618 main.cleanup()
619 main.exit()
620 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800621 main.log.info(
622 "User provided Core switch links range to toggle is correct, proceeding to run the test" )
kelvin8ec71442015-01-15 16:57:00 -0800623
kelvin-onlab8a832582015-01-16 17:06:11 -0800624 main.step( "Cut links on Core devices using user provided range" )
625 randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
626 randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
627 randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
628 for i in range( int( switchLinksToToggle ) ):
629 main.Mininet1.link(
630 END1=link1End1,
631 END2=randomLink1[ i ],
632 OPTION="down" )
633 main.Mininet1.link(
634 END1=link2End1,
635 END2=randomLink2[ i ],
636 OPTION="down" )
637 main.Mininet1.link(
638 END1=link3End1,
639 END2=randomLink3[ i ],
640 OPTION="down" )
641 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800642
643 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800644 linkDown = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800645 topology_output, numSwitches, str(
646 int( numLinks ) - int( switchLinksToToggle ) * 6 ) )
647 utilities.assert_equals(
648 expect=main.TRUE,
649 actual=linkDown,
650 onpass="Link Down discovered properly",
651 onfail="Link down was not discovered in " +
652 str( link_sleep ) +
653 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800654
kelvin-onlab8a832582015-01-16 17:06:11 -0800655 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800656 pingResultLinkDown = main.FALSE
657 time1 = time.time()
658 pingResultLinkDown = main.Mininet1.pingall()
659 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800660 timeDiff = round( ( time2 - time1 ), 2 )
661 main.log.report(
662 "Time taken for Ping All: " +
663 str( timeDiff ) +
664 " seconds" )
665 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkDown,
666 onpass="PING ALL PASS",
667 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800668
669 caseResult7 = linkDown and pingResultLinkDown
kelvin-onlab8a832582015-01-16 17:06:11 -0800670 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
671 onpass="Random Link cut Test PASS",
672 onfail="Random Link cut Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800673
kelvin-onlab8a832582015-01-16 17:06:11 -0800674 def CASE81( self, main ):
675 """
676 Bring the core links up that are down and verify ping all ( Point Intents Scenario )
677 """
kelvin8ec71442015-01-15 16:57:00 -0800678 import random
kelvin-onlab8a832582015-01-16 17:06:11 -0800679 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
680 link1End1 = main.params[ 'CORELINKS' ][ 'linkS3a' ]
681 link2End1 = main.params[ 'CORELINKS' ][ 'linkS14a' ]
682 link3End1 = main.params[ 'CORELINKS' ][ 'linkS18a' ]
683 link_sleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
684 switchLinksToToggle = main.params[ 'CORELINKS' ][ 'toggleLinks' ]
kelvin8ec71442015-01-15 16:57:00 -0800685
kelvin-onlab8a832582015-01-16 17:06:11 -0800686 main.log.report(
687 "Point intents - Bring the core links up that are down and verify ping all" )
688 main.log.report(
689 "___________________________________________________________________" )
690 main.case(
691 "Point intents - Bring the core links up that are down and verify ping all" )
692 main.step( "Bring randomly cut links on Core devices up" )
693 for i in range( int( switchLinksToToggle ) ):
694 main.Mininet1.link(
695 END1=link1End1,
696 END2=randomLink1[ i ],
697 OPTION="up" )
698 main.Mininet1.link(
699 END1=link2End1,
700 END2=randomLink2[ i ],
701 OPTION="up" )
702 main.Mininet1.link(
703 END1=link3End1,
704 END2=randomLink3[ i ],
705 OPTION="up" )
706 time.sleep( link_sleep )
kelvin8ec71442015-01-15 16:57:00 -0800707
708 topology_output = main.ONOScli2.topology()
Hari Krishnad97213e2015-01-24 19:30:14 -0800709 linkUp = main.ONOSbench.checkStatus(
kelvin-onlab8a832582015-01-16 17:06:11 -0800710 topology_output,
711 numSwitches,
712 str( numLinks ) )
713 utilities.assert_equals(
714 expect=main.TRUE,
715 actual=linkUp,
716 onpass="Link up discovered properly",
717 onfail="Link up was not discovered in " +
718 str( link_sleep ) +
719 " seconds" )
kelvin8ec71442015-01-15 16:57:00 -0800720
kelvin-onlab8a832582015-01-16 17:06:11 -0800721 main.step( "Verify Ping across all hosts" )
kelvin8ec71442015-01-15 16:57:00 -0800722 pingResultLinkUp = main.FALSE
723 time1 = time.time()
724 pingResultLinkUp = main.Mininet1.pingall()
725 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800726 timeDiff = round( ( time2 - time1 ), 2 )
727 main.log.report(
728 "Time taken for Ping All: " +
729 str( timeDiff ) +
730 " seconds" )
731 utilities.assert_equals( expect=main.TRUE, actual=pingResultLinkUp,
732 onpass="PING ALL PASS",
733 onfail="PING ALL FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800734
735 caseResult8 = linkUp and pingResultLinkUp
kelvin-onlab8a832582015-01-16 17:06:11 -0800736 utilities.assert_equals( expect=main.TRUE, actual=caseResult8,
737 onpass="Link Up Test PASS",
738 onfail="Link Up Test FAIL" )
kelvin8ec71442015-01-15 16:57:00 -0800739
kelvin-onlab8a832582015-01-16 17:06:11 -0800740 def CASE9( self ):
741 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800742 Install 114 point intents and verify Ping all works
kelvin-onlab8a832582015-01-16 17:06:11 -0800743 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800744 import copy
kelvin-onlab8a832582015-01-16 17:06:11 -0800745 main.log.report( "Install 114 point intents and verify Ping all" )
746 main.log.report( "___________________________________________" )
747 main.case( "Install 114 point intents and Ping all" )
748 deviceLinks_copy = copy.copy( deviceLinks )
749 main.step( "Install 114 point intents" )
750 for i in range( len( deviceLinks_copy ) ):
751 pointLink = str(
752 deviceLinks_copy[ i ] ).replace(
753 "src=",
754 "" ).replace(
755 "dst=",
756 "" ).split( ',' )
757 point1 = pointLink[ 0 ].split( '/' )
758 point2 = pointLink[ 1 ].split( '/' )
Hari Krishnad97213e2015-01-24 19:30:14 -0800759 installResult = main.ONOScli1.addPointIntent(
kelvin-onlab8a832582015-01-16 17:06:11 -0800760 point1[ 0 ], point2[ 0 ], int(
761 point1[ 1 ] ), int(
762 point2[ 1 ] ) )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800763 if installResult == main.TRUE:
kelvin-onlab8a832582015-01-16 17:06:11 -0800764 print "Installed Point intent between :", point1[ 0 ], int( point1[ 1 ] ), point2[ 0 ], int( point2[ 1 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800765
kelvin-onlab8a832582015-01-16 17:06:11 -0800766 main.step( "Obtain the intent id's" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800767 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800768 ansi_escape = re.compile( r'\x1b[^m]*m' )
769 intentsList = ansi_escape.sub( '', intentsList )
770 intentsList = intentsList.replace(
771 " onos:intents | grep id=",
772 "" ).replace(
773 "id=",
774 "" ).replace(
775 "\r\r",
776 "" )
777 intentsList = intentsList.splitlines()
778 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800779 intentIdList = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800780 for i in range( len( intentsList ) ):
781 intentsTemp = intentsList[ i ].split( ',' )
782 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800783 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800784 print "Total Intents installed: ", len( intentIdList )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800785
kelvin-onlab8a832582015-01-16 17:06:11 -0800786 main.step( "Verify Ping across all hosts" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800787 pingResult = main.FALSE
788 time1 = time.time()
789 pingResult = main.Mininet1.pingall()
790 time2 = time.time()
kelvin-onlab8a832582015-01-16 17:06:11 -0800791 timeDiff = round( ( time2 - time1 ), 2 )
792 main.log.report(
793 "Time taken for Ping All: " +
794 str( timeDiff ) +
795 " seconds" )
796 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
797 onpass="PING ALL PASS",
798 onfail="PING ALL FAIL" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800799
800 case8_result = installResult and pingResult
kelvin-onlab8a832582015-01-16 17:06:11 -0800801 utilities.assert_equals(
802 expect=main.TRUE,
803 actual=case8_result,
804 onpass="Ping all test after Point intents addition successful",
805 onfail="Ping all test after Point intents addition failed" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800806
kelvin-onlab8a832582015-01-16 17:06:11 -0800807 def CASE10( self ):
808 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800809 Remove all Intents
kelvin-onlab8a832582015-01-16 17:06:11 -0800810 """
811 main.log.report( "Remove all intents that were installed previously" )
812 main.log.report( "______________________________________________" )
813 main.log.info( "Remove all intents" )
814 main.case( "Removing intents" )
815 main.step( "Obtain the intent id's first" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800816 intentsList = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800817 ansi_escape = re.compile( r'\x1b[^m]*m' )
818 intentsList = ansi_escape.sub( '', intentsList )
819 intentsList = intentsList.replace(
820 " onos:intents | grep id=",
821 "" ).replace(
822 "id=",
823 "" ).replace(
824 "\r\r",
825 "" )
826 intentsList = intentsList.splitlines()
827 intentsList = intentsList[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800828 intentIdList = []
829 step1Result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800830 if ( len( intentsList ) > 1 ):
831 for i in range( len( intentsList ) ):
832 intentsTemp = intentsList[ i ].split( ',' )
833 intentIdList.append( intentsTemp[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800834 print "Intent IDs: ", intentIdList
kelvin-onlab8a832582015-01-16 17:06:11 -0800835 for id in range( len( intentIdList ) ):
836 print "Removing intent id (round 1) :", intentIdList[ id ]
Hari Krishnad97213e2015-01-24 19:30:14 -0800837 main.ONOScli1.removeIntent( intent_id=intentIdList[ id ] )
kelvin-onlab8a832582015-01-16 17:06:11 -0800838 time.sleep( 1 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800839
kelvin-onlab8a832582015-01-16 17:06:11 -0800840 main.log.info(
841 "Verify all intents are removed and if any leftovers try remove one more time" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800842 intentsList1 = main.ONOScli1.getAllIntentIds()
kelvin-onlab8a832582015-01-16 17:06:11 -0800843 ansi_escape = re.compile( r'\x1b[^m]*m' )
844 intentsList1 = ansi_escape.sub( '', intentsList1 )
845 intentsList1 = intentsList1.replace(
846 " onos:intents | grep id=",
847 "" ).replace(
848 " state=",
849 "" ).replace(
850 "\r\r",
851 "" )
852 intentsList1 = intentsList1.splitlines()
853 intentsList1 = intentsList1[ 1: ]
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800854 print "Round 2 (leftover) intents to remove: ", intentsList1
855 intentIdList1 = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800856 if ( len( intentsList1 ) > 1 ):
857 for i in range( len( intentsList1 ) ):
858 intentsTemp1 = intentsList[ i ].split( ',' )
859 intentIdList1.append( intentsTemp1[ 0 ] )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800860 print "Leftover Intent IDs: ", intentIdList1
kelvin-onlab8a832582015-01-16 17:06:11 -0800861 for id in range( len( intentIdList1 ) ):
862 print "Removing intent id (round 2):", intentIdList1[ id ]
Hari Krishnad97213e2015-01-24 19:30:14 -0800863 main.ONOScli1.removeIntent(
kelvin-onlab8a832582015-01-16 17:06:11 -0800864 intent_id=intentIdList1[ id ] )
865 time.sleep( 2 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800866 else:
867 print "There are no more intents that need to be removed"
868 step1Result = main.TRUE
869 else:
870 print "No Intent IDs found in Intents list: ", intentsList
871 step1Result = main.FALSE
872
873 caseResult7 = step1Result
kelvin-onlab8a832582015-01-16 17:06:11 -0800874 utilities.assert_equals( expect=main.TRUE, actual=caseResult7,
875 onpass="Intent removal test successful",
876 onfail="Intent removal test failed" )