blob: 0269f7e080a820a4451611044468769eac933c47 [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" )
25 main.cleanup()
26 main.exit()
27
28 utilities.assert_equals( expect=main.TRUE,
29 actual=stepResult,
30 onpass="All flows are in the ADDED state",
31 onfail="All flows are NOT in the ADDED state" )
32
33 main.step( "Check flows are in Mininet's flow table" )
34
35 # get the flow IDs that were added through rest
36 main.log.info( "Getting the flow IDs from ONOS" )
37 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
38 # convert the flowIDs to ints then hex and finally back to strings
39 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
40 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
41
42 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
43
44 utilities.assert_equals( expect=main.TRUE,
45 actual=stepResult,
46 onpass="All flows are in mininet",
47 onfail="All flows are NOT in mininet" )