Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1 | import json |
| 2 | import time |
| 3 | class 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 Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 12 | flows = json.loads( main.Cluster.active( 0 ).REST.flows() ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 13 | |
| 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 Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 25 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 26 | |
| 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" ) |