blob: 4722c27a01aba5a6bba278ceb66571feb0cae8ee [file] [log] [blame]
You Wangb6586542016-02-26 09:25:56 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Wangb6586542016-02-26 09:25:56 -080023Wrapper functions for CHOtest
24Author: you@onlab.us
25"""
You Wangb6586542016-02-26 09:25:56 -080026def __init__( self ):
27 self.default = ''
28
Jon Hallef0e2a12017-05-24 16:57:53 -070029
You Wangb6586542016-02-26 09:25:56 -080030def 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 Hallef0e2a12017-05-24 16:57:53 -070047 args=[ hostCombos[ i ][ 0 ],
48 hostCombos[ i ][ 1 ] ] )
49 pool.append( t )
You Wangb6586542016-02-26 09:25:56 -080050 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 Hallef0e2a12017-05-24 16:57:53 -070059
You Wangb6586542016-02-26 09:25:56 -080060def 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 Hallef0e2a12017-05-24 16:57:53 -070070 main.MACsDict[ main.deviceDPIDs[ i + 10 ] ] = main.hostMACs[ i ].split( '/' )[ 0 ]
71 deviceCombos = list( itertools.permutations( main.deviceDPIDs[ 10: ], 2 ) )
You Wangb6586542016-02-26 09:25:56 -080072 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 Hallef0e2a12017-05-24 16:57:53 -070084 args=[ deviceCombos[ i ][ 0 ],
85 deviceCombos[ i ][ 1 ],
You Wangb6586542016-02-26 09:25:56 -080086 1, 1, '',
Jon Hallef0e2a12017-05-24 16:57:53 -070087 main.MACsDict.get( deviceCombos[ i ][ 0 ] ),
88 main.MACsDict.get( deviceCombos[ i ][ 1 ] ) ] )
89 pool.append( t )
You Wangb6586542016-02-26 09:25:56 -080090 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 Hallef0e2a12017-05-24 16:57:53 -070097 main.log.info( "Time taken for adding point intents: %2f seconds" % ( time2 - time1 ) )
You Wangb6586542016-02-26 09:25:56 -080098
99 return intentIdList
100
Jon Hallef0e2a12017-05-24 16:57:53 -0700101
You Wangb6586542016-02-26 09:25:56 -0800102def 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 Hallef0e2a12017-05-24 16:57:53 -0700112 main.log.info( "Waiting for onos to install intents..." )
You Wangb6586542016-02-26 09:25:56 -0800113 time.sleep( main.checkIntentsDelay )
114
115 intentResult = main.TRUE
Jon Hallef0e2a12017-05-24 16:57:53 -0700116 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 Wangb6586542016-02-26 09:25:56 -0800119 if not intentResultIndividual:
Jon Hallef0e2a12017-05-24 16:57:53 -0700120 main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
You Wangb6586542016-02-26 09:25:56 -0800121 intentResult = intentResult and intentResultIndividual
122 if intentResult:
123 break
124 if not intentResult:
Jon Hallef0e2a12017-05-24 16:57:53 -0700125 main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )
You Wangb6586542016-02-26 09:25:56 -0800126
127 return intentResult
128
Jon Hallef0e2a12017-05-24 16:57:53 -0700129
You Wangb6586542016-02-26 09:25:56 -0800130def 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 Hallef0e2a12017-05-24 16:57:53 -0700140 main.log.info( "Giving ONOS some time..." )
You Wangb6586542016-02-26 09:25:56 -0800141 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 Hallef0e2a12017-05-24 16:57:53 -0700149
You Wangb6586542016-02-26 09:25:56 -0800150def 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 Hallef0e2a12017-05-24 16:57:53 -0700166 main.log.info( "Checking link number on ONOS%s" % ( e + 1 ) )
167 linkResultIndividual = main.CLIs[ e ].checkStatus( main.numMNswitches,
You Wangb6586542016-02-26 09:25:56 -0800168 str( linkNum ) )
169 if not linkResultIndividual:
Jon Hallef0e2a12017-05-24 16:57:53 -0700170 main.log.warn( "Link %s not discovered by ONOS%s" % ( linkEvent, ( e + 1 ) ) )
You Wangb6586542016-02-26 09:25:56 -0800171 linkResult = linkResult and linkResultIndividual
172 if linkResult:
173 break
174
175 return linkResult