You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame^] | 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
| 22 | """ |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 23 | Wrapper functions for CHOtest |
| 24 | Author: you@onlab.us |
| 25 | """ |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 26 | def __init__( self ): |
| 27 | self.default = '' |
| 28 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 29 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 30 | def installHostIntents(): |
| 31 | """ |
| 32 | Install one host intent for each combination of hosts in the topology |
| 33 | """ |
| 34 | import itertools |
| 35 | import time |
| 36 | |
| 37 | hostCombos = list( itertools.combinations( main.hostMACs, 2 ) ) |
| 38 | intentIdList = [] |
| 39 | for i in xrange( 0, len( hostCombos ), int( main.numCtrls ) ): |
| 40 | pool = [] |
| 41 | for cli in main.CLIs: |
| 42 | if i >= len( hostCombos ): |
| 43 | break |
| 44 | t = main.Thread( target=cli.addHostIntent, |
| 45 | threadID=main.threadID, |
| 46 | name="addHostIntent", |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 47 | args=[ hostCombos[ i ][ 0 ], |
| 48 | hostCombos[ i ][ 1 ] ] ) |
| 49 | pool.append( t ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 50 | t.start() |
| 51 | i = i + 1 |
| 52 | main.threadID = main.threadID + 1 |
| 53 | for thread in pool: |
| 54 | thread.join() |
| 55 | intentIdList.append( thread.result ) |
| 56 | |
| 57 | return intentIdList |
| 58 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 59 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 60 | def installPointIntents(): |
| 61 | """ |
| 62 | Install one point intent for each permutation of devices in the topology |
| 63 | """ |
| 64 | import itertools |
| 65 | import time |
| 66 | |
| 67 | if main.prefix == 2: |
| 68 | # Spine-leaf topology is a special case |
| 69 | for i in range( len( main.hostMACs ) ): |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 70 | main.MACsDict[ main.deviceDPIDs[ i + 10 ] ] = main.hostMACs[ i ].split( '/' )[ 0 ] |
| 71 | deviceCombos = list( itertools.permutations( main.deviceDPIDs[ 10: ], 2 ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 72 | else: |
| 73 | deviceCombos = list( itertools.permutations( main.deviceDPIDs, 2 ) ) |
| 74 | intentIdList = [] |
| 75 | time1 = time.time() |
| 76 | for i in xrange( 0, len( deviceCombos ), int( main.numCtrls ) ): |
| 77 | pool = [] |
| 78 | for cli in main.CLIs: |
| 79 | if i >= len( deviceCombos ): |
| 80 | break |
| 81 | t = main.Thread( target=cli.addPointIntent, |
| 82 | threadID=main.threadID, |
| 83 | name="addPointIntent", |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 84 | args=[ deviceCombos[ i ][ 0 ], |
| 85 | deviceCombos[ i ][ 1 ], |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 86 | 1, 1, '', |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 87 | main.MACsDict.get( deviceCombos[ i ][ 0 ] ), |
| 88 | main.MACsDict.get( deviceCombos[ i ][ 1 ] ) ] ) |
| 89 | pool.append( t ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 90 | t.start() |
| 91 | i = i + 1 |
| 92 | main.threadID = main.threadID + 1 |
| 93 | for thread in pool: |
| 94 | thread.join() |
| 95 | intentIdList.append( thread.result ) |
| 96 | time2 = time.time() |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 97 | 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] | 98 | |
| 99 | return intentIdList |
| 100 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 101 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 102 | def checkIntents(): |
| 103 | """ |
| 104 | Check if all the intents are in INSTALLED state |
| 105 | """ |
| 106 | import time |
| 107 | |
| 108 | intentResult = main.TRUE |
| 109 | for i in range( main.intentCheck ): |
| 110 | if i != 0: |
| 111 | main.log.warn( "Verification failed. Retrying..." ) |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 112 | main.log.info( "Waiting for onos to install intents..." ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 113 | time.sleep( main.checkIntentsDelay ) |
| 114 | |
| 115 | intentResult = main.TRUE |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 116 | for e in range( int( main.numCtrls ) ): |
| 117 | main.log.info( "Checking intents on CLI %s" % ( e + 1 ) ) |
| 118 | intentResultIndividual = main.CLIs[ e ].checkIntentState( intentsId=main.intentIds ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 119 | if not intentResultIndividual: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 120 | main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 121 | intentResult = intentResult and intentResultIndividual |
| 122 | if intentResult: |
| 123 | break |
| 124 | if not intentResult: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 125 | 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] | 126 | |
| 127 | return intentResult |
| 128 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 129 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 130 | def checkPingall( protocol="IPv4" ): |
| 131 | """ |
| 132 | Verify ping across all hosts |
| 133 | """ |
| 134 | import time |
| 135 | |
| 136 | pingResult = main.TRUE |
| 137 | for i in range( main.numPings ): |
| 138 | if i != 0: |
| 139 | main.log.warn( "Pingall failed. Retrying..." ) |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 140 | main.log.info( "Giving ONOS some time..." ) |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 141 | time.sleep( main.pingSleep ) |
| 142 | |
| 143 | pingResult = main.Mininet1.pingall( protocol=protocol, timeout=main.pingTimeout ) |
| 144 | if pingResult: |
| 145 | break |
| 146 | |
| 147 | return pingResult |
| 148 | |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 149 | |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 150 | def checkLinkEvents( linkEvent, linkNum ): |
| 151 | """ |
| 152 | Verify link down/up events are correctly discovered by ONOS |
| 153 | linkNum: the correct link number after link down/up |
| 154 | """ |
| 155 | import time |
| 156 | |
| 157 | linkResult = main.TRUE |
| 158 | for i in range( main.linkCheck ): |
| 159 | if i != 0: |
| 160 | main.log.warn( "Verification failed. Retrying..." ) |
| 161 | main.log.info( "Giving ONOS some time..." ) |
| 162 | time.sleep( main.linkSleep ) |
| 163 | |
| 164 | linkResult = main.TRUE |
| 165 | for e in range( int( main.numCtrls ) ): |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 166 | main.log.info( "Checking link number on ONOS%s" % ( e + 1 ) ) |
| 167 | linkResultIndividual = main.CLIs[ e ].checkStatus( main.numMNswitches, |
You Wang | b658654 | 2016-02-26 09:25:56 -0800 | [diff] [blame] | 168 | str( linkNum ) ) |
| 169 | if not linkResultIndividual: |
Jon Hall | ef0e2a1 | 2017-05-24 16:57:53 -0700 | [diff] [blame] | 170 | 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] | 171 | linkResult = linkResult and linkResultIndividual |
| 172 | if linkResult: |
| 173 | break |
| 174 | |
| 175 | return linkResult |