You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 1 | """ |
| 2 | Wrapper functions for CHOtest |
| 3 | Author: you@onlab.us |
| 4 | """ |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 8 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 9 | def installHostIntents(): |
| 10 | """ |
| 11 | Install one host intent for each combination of hosts in the topology |
| 12 | """ |
| 13 | import itertools |
| 14 | import time |
| 15 | |
| 16 | hostCombos = list( itertools.combinations( main.hostMACs, 2 ) ) |
| 17 | intentIdList = [] |
| 18 | for i in xrange( 0, len( hostCombos ), int( main.numCtrls ) ): |
| 19 | pool = [] |
| 20 | for cli in main.CLIs: |
| 21 | if i >= len( hostCombos ): |
| 22 | break |
| 23 | t = main.Thread( target=cli.addHostIntent, |
| 24 | threadID=main.threadID, |
| 25 | name="addHostIntent", |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 26 | args=[ hostCombos[ i ][ 0 ], |
| 27 | hostCombos[ i ][ 1 ] ] ) |
| 28 | pool.append( t ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 29 | t.start() |
| 30 | i = i + 1 |
| 31 | main.threadID = main.threadID + 1 |
| 32 | for thread in pool: |
| 33 | thread.join() |
| 34 | intentIdList.append( thread.result ) |
| 35 | |
| 36 | return intentIdList |
| 37 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 38 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 39 | def installPointIntents(): |
| 40 | """ |
| 41 | Install one point intent for each permutation of devices in the topology |
| 42 | """ |
| 43 | import itertools |
| 44 | import time |
| 45 | |
| 46 | if main.prefix == 2: |
| 47 | # Spine-leaf topology is a special case |
| 48 | for i in range( len( main.hostMACs ) ): |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 49 | main.MACsDict[ main.deviceDPIDs[ i + 10 ] ] = main.hostMACs[ i ].split( '/' )[ 0 ] |
| 50 | deviceCombos = list( itertools.permutations( main.deviceDPIDs[ 10: ], 2 ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 51 | else: |
| 52 | deviceCombos = list( itertools.permutations( main.deviceDPIDs, 2 ) ) |
| 53 | intentIdList = [] |
| 54 | time1 = time.time() |
| 55 | for i in xrange( 0, len( deviceCombos ), int( main.numCtrls ) ): |
| 56 | pool = [] |
| 57 | for cli in main.CLIs: |
| 58 | if i >= len( deviceCombos ): |
| 59 | break |
| 60 | t = main.Thread( target=cli.addPointIntent, |
| 61 | threadID=main.threadID, |
| 62 | name="addPointIntent", |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 63 | args=[ deviceCombos[ i ][ 0 ], |
| 64 | deviceCombos[ i ][ 1 ], |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 65 | 1, 1, '', |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 66 | main.MACsDict.get( deviceCombos[ i ][ 0 ] ), |
| 67 | main.MACsDict.get( deviceCombos[ i ][ 1 ] ) ] ) |
| 68 | pool.append( t ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 69 | t.start() |
| 70 | i = i + 1 |
| 71 | main.threadID = main.threadID + 1 |
| 72 | for thread in pool: |
| 73 | thread.join() |
| 74 | intentIdList.append( thread.result ) |
| 75 | time2 = time.time() |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 76 | main.log.info( "Time taken for adding point intents: %2f seconds" % ( time2 - time1 ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 77 | |
| 78 | return intentIdList |
| 79 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 80 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 81 | def checkIntents(): |
| 82 | """ |
| 83 | Check if all the intents are in INSTALLED state |
| 84 | """ |
| 85 | import time |
| 86 | |
| 87 | intentResult = main.TRUE |
| 88 | for i in range( main.intentCheck ): |
| 89 | if i != 0: |
| 90 | main.log.warn( "Verification failed. Retrying..." ) |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 91 | main.log.info( "Waiting for onos to install intents..." ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 92 | time.sleep( main.checkIntentsDelay ) |
| 93 | |
| 94 | intentResult = main.TRUE |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 95 | for e in range( int( main.numCtrls ) ): |
| 96 | main.log.info( "Checking intents on CLI %s" % ( e + 1 ) ) |
| 97 | intentResultIndividual = main.CLIs[ e ].checkIntentState( intentsId=main.intentIds ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 98 | if not intentResultIndividual: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 99 | main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 100 | intentResult = intentResult and intentResultIndividual |
| 101 | if intentResult: |
| 102 | break |
| 103 | if not intentResult: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 104 | main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 105 | |
| 106 | return intentResult |
| 107 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 108 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 109 | def checkPingall( protocol="IPv4" ): |
| 110 | """ |
| 111 | Verify ping across all hosts |
| 112 | """ |
| 113 | import time |
| 114 | |
| 115 | pingResult = main.TRUE |
| 116 | for i in range( main.numPings ): |
| 117 | if i != 0: |
| 118 | main.log.warn( "Pingall failed. Retrying..." ) |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 119 | main.log.info( "Giving ONOS some time..." ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 120 | time.sleep( main.pingSleep ) |
| 121 | |
| 122 | pingResult = main.Mininet1.pingall( protocol=protocol, timeout=main.pingTimeout ) |
| 123 | if pingResult: |
| 124 | break |
| 125 | |
| 126 | return pingResult |
| 127 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 128 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 129 | def checkLinkEvents( linkEvent, linkNum ): |
| 130 | """ |
| 131 | Verify link down/up events are correctly discovered by ONOS |
| 132 | linkNum: the correct link number after link down/up |
| 133 | """ |
| 134 | import time |
| 135 | |
| 136 | linkResult = main.TRUE |
| 137 | for i in range( main.linkCheck ): |
| 138 | if i != 0: |
| 139 | main.log.warn( "Verification failed. Retrying..." ) |
| 140 | main.log.info( "Giving ONOS some time..." ) |
| 141 | time.sleep( main.linkSleep ) |
| 142 | |
| 143 | linkResult = main.TRUE |
| 144 | for e in range( int( main.numCtrls ) ): |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 145 | main.log.info( "Checking link number on ONOS%s" % ( e + 1 ) ) |
| 146 | linkResultIndividual = main.CLIs[ e ].checkStatus( main.numMNswitches, |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 147 | str( linkNum ) ) |
| 148 | if not linkResultIndividual: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame^] | 149 | main.log.warn( "Link %s not discovered by ONOS%s" % ( linkEvent, ( e + 1 ) ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 150 | linkResult = linkResult and linkResultIndividual |
| 151 | if linkResult: |
| 152 | break |
| 153 | |
| 154 | return linkResult |