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