Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1 | import json |
| 2 | import time |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 3 | |
| 4 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 5 | class CheckingFlow: |
| 6 | |
| 7 | def __init__( self ): |
| 8 | self.default = '' |
| 9 | |
| 10 | def checkFlow( self ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | main.step( "Check flow is in the ADDED state" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 12 | main.log.info( "Get the flows from ONOS" ) |
| 13 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 14 | flows = json.loads( main.Cluster.active( 0 ).REST.flows() ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 15 | |
| 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 Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 27 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 28 | |
| 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" ) |