blob: ff09766b25863873f23a062bb12a52df30ee2480 [file] [log] [blame]
shahshreya3140b1a2015-04-28 14:22:15 -07001
2# Testing the basic functionality of ONOS Next
3# For sanity and driver functionality excercises only.
4
5import time
6import sys
7import os
8import re
9import time
10import json
11
12time.sleep( 1 )
13
14class IpOpticalMulti:
15
16 def __init__( self ):
17 self.default = ''
18
19 def CASE1( self, main ):
20 """
21 Startup sequence:
22 cell <name>
23 onos-verify-cell
24 onos-remove-raft-logs
25 git pull
26 mvn clean install
27 onos-package
28 onos-install -f
29 onos-wait-for-start
30 """
31 cellName = main.params[ 'ENV' ][ 'cellName' ]
32 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
33 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
34 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
35 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
36 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
37 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
38
39 main.case( "Setting up test environment" )
40 main.log.report(
41 "This testcase is testing setting up test environment" )
42 main.log.report( "__________________________________" )
43
44 main.step( "Applying cell variable to environment" )
45 cellResult1 = main.ONOSbench.setCell( cellName )
46 # cellResult2 = main.ONOScli1.setCell( cellName )
47 # cellResult3 = main.ONOScli2.setCell( cellName )
48 # cellResult4 = main.ONOScli3.setCell( cellName )
49 verifyResult = main.ONOSbench.verifyCell()
50 cellResult = cellResult1
51
52 main.step( "Removing raft logs before a clen installation of ONOS" )
53 removeLogResult = main.ONOSbench.onosRemoveRaftLogs()
54
55 main.step( "Git checkout, pull and get version" )
56 #main.ONOSbench.gitCheckout( "master" )
57 gitPullResult = main.ONOSbench.gitPull()
58 main.log.info( "git_pull_result = " + str( gitPullResult ))
59 versionResult = main.ONOSbench.getVersion( report=True )
60
shahshreyaa47ebf42015-05-20 13:29:18 -070061 if gitPullResult == 100:
shahshreya3140b1a2015-04-28 14:22:15 -070062 main.step( "Using mvn clean & install" )
63 cleanInstallResult = main.ONOSbench.cleanInstall()
64 # cleanInstallResult = main.TRUE
65
66 main.step( "Creating ONOS package" )
67 packageResult = main.ONOSbench.onosPackage()
68
69 # main.step( "Creating a cell" )
70 # cellCreateResult = main.ONOSbench.createCellFile( **************
71 # )
72
73 main.step( "Installing ONOS package" )
74 onos1InstallResult = main.ONOSbench.onosInstall(
75 options="-f",
76 node=ONOS1Ip )
77 onos2InstallResult = main.ONOSbench.onosInstall(
78 options="-f",
79 node=ONOS2Ip )
80 onos3InstallResult = main.ONOSbench.onosInstall(
81 options="-f",
82 node=ONOS3Ip )
83 onosInstallResult = onos1InstallResult and onos2InstallResult and\
84 onos3InstallResult
85 if onosInstallResult == main.TRUE:
86 main.log.report( "Installing ONOS package successful" )
87 else:
88 main.log.report( "Installing ONOS package failed" )
89
90 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
91 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
92 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
93 onosIsup = onos1Isup and onos2Isup and onos3Isup
94 if onosIsup == main.TRUE:
95 main.log.report( "ONOS instances are up and ready" )
96 else:
97 main.log.report( "ONOS instances may not be up" )
98
99 main.step( "Starting ONOS service" )
100 startResult = main.TRUE
101 # startResult = main.ONOSbench.onosStart( ONOS1Ip )
102 startcli1 = main.ONOScli1.startOnosCli( ONOSIp=ONOS1Ip )
103 startcli2 = main.ONOScli2.startOnosCli( ONOSIp=ONOS2Ip )
104 startcli3 = main.ONOScli3.startOnosCli( ONOSIp=ONOS3Ip )
105 print startcli1
106 print startcli2
107 print startcli3
108
109 case1Result = ( packageResult and
110 cellResult and verifyResult and onosInstallResult and
111 onosIsup and startResult )
112 utilities.assertEquals( expect=main.TRUE, actual=case1Result,
113 onpass="Test startup successful",
114 onfail="Test startup NOT successful" )
115
shahshreya3140b1a2015-04-28 14:22:15 -0700116 def CASE20( self ):
117 """
118 Exit from mininet cli
119 reinstall ONOS
120 """
shahshreya7bf64442015-04-28 16:28:54 -0700121 import time
shahshreya3140b1a2015-04-28 14:22:15 -0700122 cellName = main.params[ 'ENV' ][ 'cellName' ]
123 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
124 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
125 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
126 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
127 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
128 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
129
shahshreya7bf64442015-04-28 16:28:54 -0700130
shahshreya3140b1a2015-04-28 14:22:15 -0700131 main.log.report( "This testcase exits the mininet cli and reinstalls" +
132 "ONOS to switch over to Packet Optical topology" )
133 main.log.report( "_____________________________________________" )
134 main.case( "Disconnecting mininet and restarting ONOS" )
shahshreya7bf64442015-04-28 16:28:54 -0700135
shahshreya3140b1a2015-04-28 14:22:15 -0700136 main.step( "Disconnecting mininet and restarting ONOS" )
shahshreya7bf64442015-04-28 16:28:54 -0700137 step1Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700138 mininetDisconnect = main.Mininet1.disconnect()
139 print "mininetDisconnect = ", mininetDisconnect
shahshreya7bf64442015-04-28 16:28:54 -0700140 step1Result = mininetDisconnect
141 utilities.assert_equals(
142 expect=main.TRUE,
143 actual=step1Result,
144 onpass="Mininet disconnect successfully",
145 onfail="Mininet failed to disconnect")
146 """
147 main.step( "Removing raft logs before a clean installation of ONOS" )
148 step2Result = main.TRUE
149 removeRaftLogsResult = main.ONOSbench.onosRemoveRaftLogs()
150 step2Result = removeRaftLogsResult
151 utilities.assert_equals(
152 expect=main.TRUE,
153 actual=step2Result,
154 onpass="Raft logs removed successfully",
155 onfail="Failed to remove raft logs")
156 """
shahshreya3140b1a2015-04-28 14:22:15 -0700157 main.step( "Applying cell variable to environment" )
shahshreya7bf64442015-04-28 16:28:54 -0700158 step3Result = main.TRUE
159 setCellResult = main.ONOSbench.setCell( cellName )
160 verifyCellResult = main.ONOSbench.verifyCell()
161 step3Result = setCellResult and verifyCellResult
162 utilities.assert_equals(
163 expect=main.TRUE,
164 actual=step3Result,
165 onpass="Cell applied successfully",
166 onfail="Failed to apply cell")
shahshreya3140b1a2015-04-28 14:22:15 -0700167
shahshreya7bf64442015-04-28 16:28:54 -0700168 main.step( "Uninstalling ONOS package" )
169 step4Result = main.TRUE
170 onos1UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS1Ip)
171 onos2UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS2Ip)
172 onos3UninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOS3Ip)
173 onosUninstallResult = onos1UninstallResult and onos2UninstallResult \
174 and onos3UninstallResult
175 step4Result = onosUninstallResult
176 utilities.assert_equals(
177 expect=main.TRUE,
178 actual=step4Result,
179 onpass="Successfully uninstalled ONOS",
180 onfail="Failed to uninstall ONOS")
shahshreya3140b1a2015-04-28 14:22:15 -0700181
shahshreya7bf64442015-04-28 16:28:54 -0700182 time.sleep( 5 )
shahshreya3140b1a2015-04-28 14:22:15 -0700183 main.step( "Installing ONOS package" )
shahshreya7bf64442015-04-28 16:28:54 -0700184 step5Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700185 onos1InstallResult = main.ONOSbench.onosInstall(
186 options="-f",
187 node=ONOS1Ip )
188 onos2InstallResult = main.ONOSbench.onosInstall(
189 options="-f",
190 node=ONOS2Ip )
191 onos3InstallResult = main.ONOSbench.onosInstall(
192 options="-f",
193 node=ONOS3Ip )
194 onosInstallResult = onos1InstallResult and onos2InstallResult and\
195 onos3InstallResult
shahshreya3140b1a2015-04-28 14:22:15 -0700196
197 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
198 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
199 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
shahshreya7bf64442015-04-28 16:28:54 -0700200 onosIsUp = onos1Isup and onos2Isup and onos3Isup
201 if onosIsUp == main.TRUE:
shahshreya3140b1a2015-04-28 14:22:15 -0700202 main.log.report( "ONOS instances are up and ready" )
203 else:
204 main.log.report( "ONOS instances may not be up" )
shahshreya7bf64442015-04-28 16:28:54 -0700205 step5Result = onosInstallResult and onosIsUp
206 utilities.assert_equals(
207 expect=main.TRUE,
208 actual=step5Result,
209 onpass="Successfully installed ONOS",
210 onfail="Failed to install ONOS")
shahshreya3140b1a2015-04-28 14:22:15 -0700211
212 main.step( "Starting ONOS service" )
shahshreya7bf64442015-04-28 16:28:54 -0700213 step6Result = main.TRUE
214 startResult = main.ONOSbench.onosStart( ONOS1Ip )
215 step6Result = startResult
216 utilities.assert_equals(
217 expect=main.TRUE,
218 actual=step6Result,
219 onpass="Successfully started ONOS",
220 onfail="Failed to start ONOS")
221
222 main.step( "Starting ONOS cli" )
223 step7Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700224 startcli1 = main.ONOScli1.startOnosCli( ONOSIp=ONOS1Ip )
225 startcli2 = main.ONOScli2.startOnosCli( ONOSIp=ONOS2Ip )
226 startcli3 = main.ONOScli3.startOnosCli( ONOSIp=ONOS3Ip )
227 startResult = startcli1 and startcli2 and startcli3
shahshreya7bf64442015-04-28 16:28:54 -0700228 step7Result = startResult
229 utilities.assert_equals(
230 expect=main.TRUE,
231 actual=step7Result,
232 onpass="Successfully started ONOS cli",
233 onfail="Failed to start ONOS cli")
shahshreya3140b1a2015-04-28 14:22:15 -0700234
shahshreya7bf64442015-04-28 16:28:54 -0700235 case20Result = step1Result and step3Result and\
236 step4Result and step5Result and step6Result and\
237 step7Result
shahshreya3140b1a2015-04-28 14:22:15 -0700238 utilities.assert_equals(
239 expect=main.TRUE,
240 actual=case20Result,
241 onpass= "Exiting functionality mininet topology and reinstalling" +
242 " ONOS successful",
243 onfail= "Exiting functionality mininet topology and reinstalling" +
244 " ONOS failed" )
245
246 def CASE21( self, main ):
247 """
248 On ONOS bench, run this command:
shahshreya7bf64442015-04-28 16:28:54 -0700249 sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1
shahshreya3140b1a2015-04-28 14:22:15 -0700250 which spawns packet optical topology and copies the links
251 json file to the onos instance.
252 Note that in case of Packet Optical, the links are not learnt
253 from the topology, instead the links are learnt
254 from the json config file
255 """
shahshreya7bf64442015-04-28 16:28:54 -0700256 import time
shahshreya3140b1a2015-04-28 14:22:15 -0700257 main.log.report(
258 "This testcase starts the packet layer topology and REST" )
259 main.log.report( "_____________________________________________" )
260 main.case( "Starting LINC-OE and other components" )
shahshreya3140b1a2015-04-28 14:22:15 -0700261
shahshreya7bf64442015-04-28 16:28:54 -0700262 main.step( "Activate optical app" )
263 step1Result = main.TRUE
264 activateOpticalResult = main.ONOScli2.activateApp( "org.onosproject.optical" )
265 step1Result = activateOpticalResult
266 utilities.assert_equals(
267 expect=main.TRUE,
268 actual=step1Result,
269 onpass="Successfully activated optical app",
270 onfail="Failed to activate optical app")
271
272 appCheck = main.ONOScli2.appToIDCheck()
273 if appCheck != main.TRUE:
274 main.log.warn( main.ONOScli2.apps() )
275 main.log.warn( main.ONOScli2.appIDs() )
276
277 main.step( "Starting mininet and LINC-OE" )
278 step2Result = main.TRUE
279 time.sleep( 10 )
280 opticalMnScript = main.LincOE2.runOpticalMnScript(ctrllerIP = main.params[ 'CTRL' ][ 'ip1' ])
281 step2Result = opticalMnScript
282 utilities.assert_equals(
283 expect=main.TRUE,
284 actual=step2Result,
285 onpass="Started the topology successfully ",
286 onfail="Failed to start the topology")
287
288 case21Result = step1Result and step2Result
shahshreya3140b1a2015-04-28 14:22:15 -0700289 utilities.assert_equals(
290 expect=main.TRUE,
291 actual=case21Result,
292 onpass="Packet optical topology spawned successsfully",
293 onfail="Packet optical topology spawning failed" )
294
295 def CASE22( self, main ):
296 """
297 Curretly we use, 10 optical switches(ROADM's) and
298 6 packet layer mininet switches each with one host.
299 Therefore, the roadmCount variable = 10,
300 packetLayerSWCount variable = 6, hostCount=6 and
shahshreyaa47ebf42015-05-20 13:29:18 -0700301 links=46.
shahshreya3140b1a2015-04-28 14:22:15 -0700302 All this is hardcoded in the testcase. If the topology changes,
303 these hardcoded values need to be changed
304 """
shahshreya7bf64442015-04-28 16:28:54 -0700305 import time
shahshreya3140b1a2015-04-28 14:22:15 -0700306 main.log.report(
307 "This testcase compares the optical+packet topology against what" +
308 " is expected" )
309 main.case( "Topology comparision" )
shahshreya3140b1a2015-04-28 14:22:15 -0700310
shahshreya7bf64442015-04-28 16:28:54 -0700311 main.step( "Starts new ONOS cli" )
312 step1Result = main.TRUE
313 cliResult = main.ONOScli1.startOnosCli( ONOSIp=main.params[ 'CTRL' ]\
314 [ 'ip1' ] )
315 step1Result = cliResult
316 utilities.assert_equals(
317 expect=main.TRUE,
318 actual=step1Result,
319 onpass="Successfully starts a new cli",
320 onfail="Failed to start new cli" )
321
322 main.step( "Compare topology" )
323 step2Result = main.TRUE
324 devicesResult = main.ONOScli1.devices( jsonFormat=False )
325 print "devices_result :\n", devicesResult
shahshreya3140b1a2015-04-28 14:22:15 -0700326 devicesLinewise = devicesResult.split( "\n" )
327 roadmCount = 0
328 packetLayerSWCount = 0
329 for line in devicesLinewise:
330 components = line.split( "," )
331 availability = components[ 1 ].split( "=" )[ 1 ]
332 type = components[ 3 ].split( "=" )[ 1 ]
333 if availability == 'true' and type == 'ROADM':
334 roadmCount += 1
335 elif availability == 'true' and type == 'SWITCH':
336 packetLayerSWCount += 1
337 if roadmCount == 10:
338 print "Number of Optical Switches = %d and is" % roadmCount +\
339 " correctly detected"
340 main.log.info(
341 "Number of Optical Switches = " +
342 str( roadmCount ) +
343 " and is correctly detected" )
344 opticalSWResult = main.TRUE
345 else:
346 print "Number of Optical Switches = %d and is wrong" % roadmCount
347 main.log.info(
348 "Number of Optical Switches = " +
349 str( roadmCount ) +
350 " and is wrong" )
351 opticalSWResult = main.FALSE
shahshreya3140b1a2015-04-28 14:22:15 -0700352 if packetLayerSWCount == 6:
353 print "Number of Packet layer or mininet Switches = %d "\
354 % packetLayerSWCount + "and is correctly detected"
355 main.log.info(
356 "Number of Packet layer or mininet Switches = " +
357 str( packetLayerSWCount ) +
358 " and is correctly detected" )
359 packetSWResult = main.TRUE
360 else:
361 print "Number of Packet layer or mininet Switches = %d and"\
362 % packetLayerSWCount + " is wrong"
363 main.log.info(
364 "Number of Packet layer or mininet Switches = " +
365 str( packetLayerSWCount ) +
366 " and is wrong" )
367 packetSWResult = main.FALSE
shahshreya7bf64442015-04-28 16:28:54 -0700368 # sleeps for sometime so the state of the switches will be active
369 time.sleep( 30 )
shahshreya3140b1a2015-04-28 14:22:15 -0700370 print "_________________________________"
shahshreya7bf64442015-04-28 16:28:54 -0700371 linksResult = main.ONOScli1.links( jsonFormat=False )
shahshreya3140b1a2015-04-28 14:22:15 -0700372 print "links_result = ", linksResult
373 print "_________________________________"
shahshreya7bf64442015-04-28 16:28:54 -0700374 linkActiveCount = linksResult.count("state=ACTIVE")
shahshreya3140b1a2015-04-28 14:22:15 -0700375 main.log.info( "linkActiveCount = " + str( linkActiveCount ))
shahshreyaa47ebf42015-05-20 13:29:18 -0700376 if linkActiveCount == 46:
shahshreya3140b1a2015-04-28 14:22:15 -0700377 linkActiveResult = main.TRUE
378 main.log.info(
379 "Number of links in ACTIVE state are correct")
380 else:
381 linkActiveResult = main.FALSE
382 main.log.info(
383 "Number of links in ACTIVE state are wrong")
shahshreya7bf64442015-04-28 16:28:54 -0700384 step2Result = opticalSWResult and packetSWResult and \
shahshreya3140b1a2015-04-28 14:22:15 -0700385 linkActiveResult
386 utilities.assert_equals(
387 expect=main.TRUE,
shahshreya7bf64442015-04-28 16:28:54 -0700388 actual=step2Result,
389 onpass="Successfully loaded packet optical topology",
390 onfail="Failed to load packet optical topology" )
391
392 case22Result = step1Result and step2Result
393
394 utilities.assert_equals(
395 expect=main.TRUE,
shahshreya3140b1a2015-04-28 14:22:15 -0700396 actual=case22Result,
397 onpass="Packet optical topology discovery successful",
398 onfail="Packet optical topology discovery failed" )
399
400 def CASE23( self, main ):
401 import time
402 """
403 Add bidirectional point intents between 2 packet layer( mininet )
404 devices and
405 ping mininet hosts
406 """
407 main.log.report(
408 "This testcase adds bidirectional point intents between 2 " +
409 "packet layer( mininet ) devices and ping mininet hosts" )
shahshreya7bf64442015-04-28 16:28:54 -0700410 main.case( "Install point intents between 2 packet layer device and " +
411 "ping the hosts" )
412
shahshreya3140b1a2015-04-28 14:22:15 -0700413 main.step( "Adding point intents" )
shahshreya7bf64442015-04-28 16:28:54 -0700414 step1Result = main.TRUE
415 intentsId = []
416 pIntent1 = main.ONOScli1.addPointIntent(
shahshreya3140b1a2015-04-28 14:22:15 -0700417 "of:0000ffffffff0001/1",
418 "of:0000ffffffff0005/1" )
shahshreya7bf64442015-04-28 16:28:54 -0700419 pIntent2 = main.ONOScli1.addPointIntent(
shahshreya3140b1a2015-04-28 14:22:15 -0700420 "of:0000ffffffff0005/1",
421 "of:0000ffffffff0001/1" )
shahshreya7bf64442015-04-28 16:28:54 -0700422 intentsId.append( pIntent1 )
423 intentsId.append( pIntent2 )
424 main.log.info( "Checking intents state")
425 checkStateResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
shahshreya3140b1a2015-04-28 14:22:15 -0700426 time.sleep( 30 )
shahshreya7bf64442015-04-28 16:28:54 -0700427 main.log.info( "Checking flows state")
428 checkFlowResult = main.ONOScli1.checkFlowsState()
shahshreya3140b1a2015-04-28 14:22:15 -0700429 # Sleep for 30 seconds to provide time for the intent state to change
shahshreya7bf64442015-04-28 16:28:54 -0700430 time.sleep( 30 )
431 main.log.info( "Checking intents state one more time")
432 checkStateResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
433 step1Result = checkStateResult and checkFlowResult
434 utilities.assert_equals(
435 expect=main.TRUE,
436 actual=step1Result,
437 onpass="Successfully added point intents",
438 onfail="Failed to add point intents")
shahshreya3140b1a2015-04-28 14:22:15 -0700439
shahshreya7bf64442015-04-28 16:28:54 -0700440 main.step( "Ping h1 and h5" )
441 step2Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700442 main.log.info( "\n\nh1 is Pinging h5" )
shahshreya7bf64442015-04-28 16:28:54 -0700443 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
444 step2Result = pingResult
445 utilities.assert_equals(
446 expect=main.TRUE,
447 actual=step2Result,
448 onpass="Successfully pinged h1 and h5",
449 onfail="Failed to ping between h1 and h5")
shahshreya3140b1a2015-04-28 14:22:15 -0700450
shahshreya7bf64442015-04-28 16:28:54 -0700451 case23Result = step1Result and step2Result
shahshreya3140b1a2015-04-28 14:22:15 -0700452 utilities.assert_equals(
453 expect=main.TRUE,
454 actual=case23Result,
shahshreya7bf64442015-04-28 16:28:54 -0700455 onpass="Point intents are installed properly",
456 onfail="Failed to install point intents" )
shahshreya3140b1a2015-04-28 14:22:15 -0700457
458 def CASE24( self, main ):
459 import time
460 import json
461 """
462 LINC uses its own switch IDs. You can use the following
shahshreya7bf64442015-04-28 16:28:54 -0700463 command on the LINC console to find the mapping between
shahshreya3140b1a2015-04-28 14:22:15 -0700464 DPIDs and LINC IDs.
465 rp(application:get_all_key(linc)).
shahshreya7bf64442015-04-28 16:28:54 -0700466
shahshreya3140b1a2015-04-28 14:22:15 -0700467 Test Rerouting of Packet Optical by bringing a port down
shahshreya7bf64442015-04-28 16:28:54 -0700468 ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
shahshreya3140b1a2015-04-28 14:22:15 -0700469 so that link
470 ( between switch1 port20 - switch5 port50 ) is inactive
471 and do a ping test. If rerouting is successful,
472 ping should pass. also check the flows
473 """
474 main.log.report(
475 "This testcase tests rerouting and pings mininet hosts" )
476 main.case( "Test rerouting and pings mininet hosts" )
shahshreya7bf64442015-04-28 16:28:54 -0700477
shahshreya3140b1a2015-04-28 14:22:15 -0700478 main.step( "Attach to the Linc-OE session" )
shahshreya7bf64442015-04-28 16:28:54 -0700479 step1Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700480 attachConsole = main.LincOE1.attachLincOESession()
shahshreya7bf64442015-04-28 16:28:54 -0700481 step1Result = attachConsole
482 utilities.assert_equals(
483 expect=main.TRUE,
484 actual=step1Result,
485 onpass="Successfully attached Linc-OE session",
486 onfail="Failed to attached Linc-OE session")
shahshreya3140b1a2015-04-28 14:22:15 -0700487
488 main.step( "Bring a port down and verify the link state" )
shahshreya7bf64442015-04-28 16:28:54 -0700489 step2Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700490 main.LincOE1.portDown( swId="9", ptId="20" )
shahshreya7bf64442015-04-28 16:28:54 -0700491 linksNonjson = main.ONOScli1.links( jsonFormat=False )
shahshreya3140b1a2015-04-28 14:22:15 -0700492 main.log.info( "links = " + linksNonjson )
shahshreya7bf64442015-04-28 16:28:54 -0700493 linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
shahshreya3140b1a2015-04-28 14:22:15 -0700494 main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
495 if linkInactiveCount == 2:
496 main.log.info(
497 "Number of links in INACTIVE state are correct")
498 else:
499 main.log.info(
500 "Number of links in INACTIVE state are wrong")
shahshreya7bf64442015-04-28 16:28:54 -0700501 links = main.ONOScli1.links()
shahshreya3140b1a2015-04-28 14:22:15 -0700502 main.log.info( "links = " + links )
shahshreya3140b1a2015-04-28 14:22:15 -0700503 linksResult = json.loads( links )
504 linksStateResult = main.FALSE
505 for item in linksResult:
506 if item[ 'src' ][ 'device' ] == "of:0000ffffffffff01" and item[
507 'src' ][ 'port' ] == "20":
508 if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff05" and item[
509 'dst' ][ 'port' ] == "50":
510 linksState = item[ 'state' ]
511 if linksState == "INACTIVE":
512 main.log.info(
513 "Links state is inactive as expected due to one" +
514 " of the ports being down" )
515 main.log.report(
516 "Links state is inactive as expected due to one" +
517 " of the ports being down" )
518 linksStateResult = main.TRUE
519 break
520 else:
521 main.log.info(
522 "Links state is not inactive as expected" )
523 main.log.report(
524 "Links state is not inactive as expected" )
525 linksStateResult = main.FALSE
shahshreya3140b1a2015-04-28 14:22:15 -0700526 time.sleep( 10 )
shahshreya7bf64442015-04-28 16:28:54 -0700527 checkFlowsState = main.ONOScli1.checkFlowsState()
528 step2Result = linksStateResult
529 utilities.assert_equals(
530 expect=main.TRUE,
531 actual=step2Result,
532 onpass="Successfuly brought down a link",
533 onfail="Failed to bring down a link")
shahshreya3140b1a2015-04-28 14:22:15 -0700534
535 main.step( "Verify Rerouting by a ping test" )
shahshreya7bf64442015-04-28 16:28:54 -0700536 step3Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700537 main.log.info( "\n\nh1 is Pinging h5" )
shahshreya7bf64442015-04-28 16:28:54 -0700538 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
539 step3Result = pingResult
540 utilities.assert_equals(
541 expect=main.TRUE,
542 actual=step3Result,
543 onpass="Successfully pinged h1 and h5",
544 onfail="Failed to ping between h1 and h5")
545
546 main.step( "Bring the downed port up and verify the link state" )
547 step4Result = main.TRUE
548 main.LincOE1.portUp( swId="9", ptId="20" )
549 linksNonjson = main.ONOScli1.links( jsonFormat=False )
550 main.log.info( "links = " + linksNonjson )
551 linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
552 main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
553 if linkInactiveCount == 0:
shahshreya3140b1a2015-04-28 14:22:15 -0700554 main.log.info(
shahshreya7bf64442015-04-28 16:28:54 -0700555 "Number of links in INACTIVE state are correct")
shahshreya3140b1a2015-04-28 14:22:15 -0700556 else:
shahshreya7bf64442015-04-28 16:28:54 -0700557 main.log.info(
558 "Number of links in INACTIVE state are wrong")
559 step4Result = main.FALSE
560 utilities.assert_equals(
561 expect=main.TRUE,
562 actual=step4Result,
563 onpass="Successfully brought the port up",
564 onfail="Failed to bring the port up")
shahshreya3140b1a2015-04-28 14:22:15 -0700565
shahshreya7bf64442015-04-28 16:28:54 -0700566 case24Result = step1Result and step2Result and step3Result \
567 and step4Result
568 utilities.assert_equals( expect=main.TRUE,
569 actual=case24Result,
shahshreya3140b1a2015-04-28 14:22:15 -0700570 onpass="Packet optical rerouting successful",
571 onfail="Packet optical rerouting failed" )
572
shahshreya7bf64442015-04-28 16:28:54 -0700573 def CASE10( self ):
574 main.log.report(
575 "This testcase uninstalls the reactive forwarding app" )
576 main.log.report( "__________________________________" )
577 main.case( "Uninstalling reactive forwarding app" )
578 main.step( "Uninstalling reactive forwarding app" )
579 step1Result = main.TRUE
580 # Unistall onos-app-fwd app to disable reactive forwarding
581 main.log.info( "deactivate reactive forwarding app" )
582 appUninstallResult = main.ONOScli2.deactivateApp( "org.onosproject.fwd" )
583 appCheck = main.ONOScli2.appToIDCheck()
584 if appCheck != main.TRUE:
585 main.log.warn( main.ONOScli2.apps() )
586 main.log.warn( main.ONOScli2.appIDs() )
587 step1Result = appUninstallResult
588 utilities.assert_equals(
589 expect=main.TRUE,
590 actual=step1Result,
591 onpass="Successfully deactivate reactive forwarding app",
592 onfail="Failed to deactivate reactive forwarding app")
593 # After reactive forwarding is disabled, the reactive flows on
594 # switches timeout in 10-15s
595 # So sleep for 15s
596 time.sleep( 15 )
597 flows = main.ONOScli2.flows()
598 main.log.info( flows )
599
600 case10Result = step1Result
601 utilities.assert_equals(
602 expect=main.TRUE,
603 actual=case10Result,
604 onpass="Reactive forwarding app uninstallation successful",
605 onfail="Reactive forwarding app uninstallation failed" )
606
shahshreya3140b1a2015-04-28 14:22:15 -0700607 def CASE25( self ):
608 """
609 Add host intents between 2 packet layer host
610 """
611 import time
612 import json
shahshreya7bf64442015-04-28 16:28:54 -0700613 main.log.report( "Adding host intents between 2 optical layer host" )
614 main.case( "Test add host intents between optical layer host" )
615
616 main.step( "Discover host using arping" )
617 step1Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700618 main.hostMACs = []
619 main.hostId = []
620 #Listing host MAC addresses
621 for i in range( 1 , 7 ):
622 main.hostMACs.append( "00:00:00:00:00:" +
623 str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
624 for macs in main.hostMACs:
625 main.hostId.append( macs + "/-1" )
shahshreya3140b1a2015-04-28 14:22:15 -0700626 host1 = main.hostId[ 0 ]
627 host2 = main.hostId[ 1 ]
shahshreya3140b1a2015-04-28 14:22:15 -0700628 # Use arping to discover the hosts
629 main.LincOE2.arping( host = "h1" )
630 main.LincOE2.arping( host = "h2" )
shahshreya7bf64442015-04-28 16:28:54 -0700631 time.sleep( 5 )
632 hostsDict = main.ONOScli1.hosts()
633 if not len( hostsDict ):
634 step1Result = main.FALSE
shahshreya3140b1a2015-04-28 14:22:15 -0700635 # Adding host intent
shahshreya7bf64442015-04-28 16:28:54 -0700636 utilities.assert_equals(
637 expect=main.TRUE,
638 actual=step1Result,
639 onpass="Hosts discovered",
640 onfail="Failed to discover hosts")
641
642 main.step( "Adding host intents to h1 and h2" )
643 step2Result = main.TRUE
644 intentsId = []
shahshreya3140b1a2015-04-28 14:22:15 -0700645 intent1 = main.ONOScli1.addHostIntent( hostIdOne = host1,
646 hostIdTwo = host2 )
647 intentsId.append( intent1 )
648 time.sleep( 5 )
649 intent2 = main.ONOScli1.addHostIntent( hostIdOne = host2,
650 hostIdTwo = host1 )
651 intentsId.append( intent2 )
652 # Checking intents state before pinging
shahshreya7bf64442015-04-28 16:28:54 -0700653 main.log.info( "Checking intents state" )
654 time.sleep( 30 )
shahshreya3140b1a2015-04-28 14:22:15 -0700655 intentResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
shahshreya7bf64442015-04-28 16:28:54 -0700656 #check intent state again if intents are not in installed state
657 if not intentResult:
658 intentResult = main.ONOScli1.checkIntentState( intentsId = intentsId )
659 step2Result = intentResult
660 utilities.assert_equals( expect=main.TRUE,
661 actual=step2Result,
shahshreya3140b1a2015-04-28 14:22:15 -0700662 onpass="All intents are in INSTALLED state ",
663 onfail="Some of the intents are not in " +
664 "INSTALLED state " )
665
666 # pinging h1 to h2 and then ping h2 to h1
shahshreya7bf64442015-04-28 16:28:54 -0700667 main.step( "Pinging h1 and h2" )
668 step3Result = main.TRUE
shahshreya3140b1a2015-04-28 14:22:15 -0700669 pingResult = main.TRUE
670 pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
671 pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
672 target="h1" )
shahshreya7bf64442015-04-28 16:28:54 -0700673 step3Result = pingResult
674 utilities.assert_equals( expect=main.TRUE,
675 actual=step3Result,
shahshreya3140b1a2015-04-28 14:22:15 -0700676 onpass="Pinged successfully between h1 and h2",
677 onfail="Pinged failed between h1 and h2" )
shahshreya7bf64442015-04-28 16:28:54 -0700678 # Removed all added host intents
679 main.step( "Removing host intents" )
680 step4Result = main.TRUE
681 removeResult = main.TRUE
682 # Check remaining intents
683 intentsJson = json.loads( main.ONOScli1.intents() )
684 main.ONOScli1.removeIntent( intentId=intent1, purge=True )
685 main.ONOScli1.removeIntent( intentId=intent2, purge=True )
686 for intents in intentsJson:
687 main.ONOScli1.removeIntent( intentId=intents.get( 'id' ),
688 app='org.onosproject.optical',
689 purge=True )
690 print json.loads( main.ONOScli1.intents() )
691 if len( json.loads( main.ONOScli1.intents() ) ):
692 removeResult = main.FALSE
693 step4Result = removeResult
694 utilities.assert_equals( expect=main.TRUE,
695 actual=step4Result,
696 onpass="Successfully removed host intents",
697 onfail="Failed to remove host intents" )
698 case25Result = step1Result and step2Result and step3Result and \
699 step4Result
700 utilities.assert_equals( expect=main.TRUE,
701 actual=case25Result,
shahshreya3140b1a2015-04-28 14:22:15 -0700702 onpass="Add host intent successful",
703 onfail="Add host intent failed" )