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