blob: 42099472be797acb856a54b665d922fb8ea22cd9 [file] [log] [blame]
Devin Lim58046fa2017-07-05 16:55:00 -07001import json
2import time
3class CheckingFlow:
4
5 def __init__( self ):
6 self.default = ''
7
8 def checkFlow( self ):
9 main.step("Check flow is in the ADDED state")
10 main.log.info( "Get the flows from ONOS" )
11 try:
Devin Lim142b5342017-07-20 15:22:39 -070012 flows = json.loads( main.Cluster.active( 0 ).REST.flows() )
Devin Lim58046fa2017-07-05 16:55:00 -070013
14 stepResult = main.TRUE
15 for f in flows:
16 if "rest" in f.get( "appId" ):
17 if "ADDED" not in f.get( "state" ):
18 stepResult = main.FALSE
19 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
20 except TypeError:
21 main.log.error( "No Flows found by the REST API" )
22 stepResult = main.FALSE
23 except ValueError:
24 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -070025 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070026
27 utilities.assert_equals( expect=main.TRUE,
28 actual=stepResult,
29 onpass="All flows are in the ADDED state",
30 onfail="All flows are NOT in the ADDED state" )
31
32 main.step( "Check flows are in Mininet's flow table" )
33
34 # get the flow IDs that were added through rest
35 main.log.info( "Getting the flow IDs from ONOS" )
36 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
37 # convert the flowIDs to ints then hex and finally back to strings
38 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
39 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
40
41 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
42
43 utilities.assert_equals( expect=main.TRUE,
44 actual=stepResult,
45 onpass="All flows are in mininet",
46 onfail="All flows are NOT in mininet" )