blob: 0caa1df0b125b4c570347fd774949f986992348f [file] [log] [blame]
You Wangb6586542016-02-26 09:25:56 -08001"""
2Wrapper functions for CHOtest
3Author: you@onlab.us
4"""
You Wangb6586542016-02-26 09:25:56 -08005def __init__( self ):
6 self.default = ''
7
Jon Hallef0e2a12017-05-24 16:57:53 -07008
You Wangb6586542016-02-26 09:25:56 -08009def 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 Hallef0e2a12017-05-24 16:57:53 -070026 args=[ hostCombos[ i ][ 0 ],
27 hostCombos[ i ][ 1 ] ] )
28 pool.append( t )
You Wangb6586542016-02-26 09:25:56 -080029 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 Hallef0e2a12017-05-24 16:57:53 -070038
You Wangb6586542016-02-26 09:25:56 -080039def 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 Hallef0e2a12017-05-24 16:57:53 -070049 main.MACsDict[ main.deviceDPIDs[ i + 10 ] ] = main.hostMACs[ i ].split( '/' )[ 0 ]
50 deviceCombos = list( itertools.permutations( main.deviceDPIDs[ 10: ], 2 ) )
You Wangb6586542016-02-26 09:25:56 -080051 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 Hallef0e2a12017-05-24 16:57:53 -070063 args=[ deviceCombos[ i ][ 0 ],
64 deviceCombos[ i ][ 1 ],
You Wangb6586542016-02-26 09:25:56 -080065 1, 1, '',
Jon Hallef0e2a12017-05-24 16:57:53 -070066 main.MACsDict.get( deviceCombos[ i ][ 0 ] ),
67 main.MACsDict.get( deviceCombos[ i ][ 1 ] ) ] )
68 pool.append( t )
You Wangb6586542016-02-26 09:25:56 -080069 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 Hallef0e2a12017-05-24 16:57:53 -070076 main.log.info( "Time taken for adding point intents: %2f seconds" % ( time2 - time1 ) )
You Wangb6586542016-02-26 09:25:56 -080077
78 return intentIdList
79
Jon Hallef0e2a12017-05-24 16:57:53 -070080
You Wangb6586542016-02-26 09:25:56 -080081def 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 Hallef0e2a12017-05-24 16:57:53 -070091 main.log.info( "Waiting for onos to install intents..." )
You Wangb6586542016-02-26 09:25:56 -080092 time.sleep( main.checkIntentsDelay )
93
94 intentResult = main.TRUE
Jon Hallef0e2a12017-05-24 16:57:53 -070095 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 Wangb6586542016-02-26 09:25:56 -080098 if not intentResultIndividual:
Jon Hallef0e2a12017-05-24 16:57:53 -070099 main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
You Wangb6586542016-02-26 09:25:56 -0800100 intentResult = intentResult and intentResultIndividual
101 if intentResult:
102 break
103 if not intentResult:
Jon Hallef0e2a12017-05-24 16:57:53 -0700104 main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )
You Wangb6586542016-02-26 09:25:56 -0800105
106 return intentResult
107
Jon Hallef0e2a12017-05-24 16:57:53 -0700108
You Wangb6586542016-02-26 09:25:56 -0800109def 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 Hallef0e2a12017-05-24 16:57:53 -0700119 main.log.info( "Giving ONOS some time..." )
You Wangb6586542016-02-26 09:25:56 -0800120 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 Hallef0e2a12017-05-24 16:57:53 -0700128
You Wangb6586542016-02-26 09:25:56 -0800129def 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 Hallef0e2a12017-05-24 16:57:53 -0700145 main.log.info( "Checking link number on ONOS%s" % ( e + 1 ) )
146 linkResultIndividual = main.CLIs[ e ].checkStatus( main.numMNswitches,
You Wangb6586542016-02-26 09:25:56 -0800147 str( linkNum ) )
148 if not linkResultIndividual:
Jon Hallef0e2a12017-05-24 16:57:53 -0700149 main.log.warn( "Link %s not discovered by ONOS%s" % ( linkEvent, ( e + 1 ) ) )
You Wangb6586542016-02-26 09:25:56 -0800150 linkResult = linkResult and linkResultIndividual
151 if linkResult:
152 break
153
154 return linkResult