blob: 23f281b2becbddae970c4ea61308a05d1261e9ff [file] [log] [blame]
YPZhang801d46d2016-08-08 13:26:28 -07001'''
2 SCPFportLat test
3 Test latency for port status change
4 Up & Down:
5 PortStatus --- Device --- Link --- Graph
GlennRCdc7ab012015-07-23 15:40:12 -07006
YPZhang801d46d2016-08-08 13:26:28 -07007 yunpeng@onlab.us
8'''
GlennRCdc7ab012015-07-23 15:40:12 -07009class SCPFportLat:
GlennRCdc7ab012015-07-23 15:40:12 -070010 def __init__( self ):
11 self.default = ''
12
YPZhang801d46d2016-08-08 13:26:28 -070013 def CASE0( self, main ):
GlennRCdc7ab012015-07-23 15:40:12 -070014 import os
YPZhang801d46d2016-08-08 13:26:28 -070015 import imp
16 '''
17 - GIT
18 - BUILDING ONOS
19 Pull specific ONOS branch, then Build ONOS ono ONOS Bench.
20 This step is usually skipped. Because in a Jenkins driven automated
21 test env. We want Jenkins jobs to pull&build for flexibility to handle
22 different versions of ONOS.
23 - Construct tests variables
24 '''
25 gitPull = main.params['GIT']['gitPull']
26 gitBranch = main.params['GIT']['gitBranch']
GlennRCdc7ab012015-07-23 15:40:12 -070027
YPZhang801d46d2016-08-08 13:26:28 -070028 main.case( "Pull onos branch and build onos on Teststation." )
GlennRCdc7ab012015-07-23 15:40:12 -070029
YPZhang801d46d2016-08-08 13:26:28 -070030 if gitPull == 'True':
31 main.step( "Git Checkout ONOS branch: " + gitBranch )
32 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
33 utilities.assert_equals(expect=main.TRUE,
34 actual=stepResult,
35 onpass="Successfully checkout onos branch.",
36 onfail="Failed to checkout onos branch. Exiting test...")
37 if not stepResult: main.exit()
38
39 main.step( "Git Pull on ONOS branch:" + gitBranch )
40 stepResult = main.ONOSbench.gitPull()
41 utilities.assert_equals(expect=main.TRUE,
42 actual=stepResult,
43 onpass="Successfully pull onos. ",
44 onfail="Failed to pull onos. Exiting test ...")
45 if not stepResult: main.exit()
46
YPZhang801d46d2016-08-08 13:26:28 -070047
48 else:
49 main.log.warn( "Skipped pulling onos and Skipped building ONOS" )
50
51 main.testOnDirectory = os.path.dirname( os.getcwd() )
52 main.MN1Ip = main.params['MN']['ip1']
YPZhang0433bee2016-07-12 16:10:59 -070053 main.dependencyPath = main.testOnDirectory + \
54 main.params['DEPENDENCY']['path']
YPZhang801d46d2016-08-08 13:26:28 -070055 main.dependencyFunc = main.params['DEPENDENCY']['function']
56 main.topoName = main.params['DEPENDENCY']['topology']
57 main.cellName = main.params['ENV']['cellName']
58 main.Apps = main.params['ENV']['cellApps']
59 main.scale = (main.params['SCALE']).split(",")
60 main.ofportStatus = main.params['TSHARK']['ofpPortStatus']
61 main.tsharkResultPath = main.params['TSHARK']['tsharkReusltPath']
62 main.sampleSize = int( main.params['TEST']['sampleSize'] )
63 main.warmUp = int( main.params['TEST']['warmUp'] )
64 main.maxProcessTime = int( main.params['TEST']['maxProcessTime'])
65 main.dbFileName = main.params['DATABASE']['dbName']
66 main.startUpSleep = int( main.params['SLEEP']['startup'] )
67 main.measurementSleep = int( main.params['SLEEP']['measure'] )
68 main.maxScale = int( main.params['max'] )
69 main.interface = main.params['TEST']['interface']
70 main.timeout = int( main.params['TIMEOUT']['timeout'] )
71 main.MNSleep = int( main.params['SLEEP']['mininet'])
72 main.device = main.params['TEST']['device']
73 main.debug = main.params['TEST']['debug']
GlennRCdc7ab012015-07-23 15:40:12 -070074
YPZhang801d46d2016-08-08 13:26:28 -070075 if main.debug == "True":
76 main.debug = True
77 else:
78 main.debug = False
GlennRCdc7ab012015-07-23 15:40:12 -070079
YPZhang801d46d2016-08-08 13:26:28 -070080 main.log.info( "Create Database file " + main.dbFileName )
81 resultsDB = open( main.dbFileName, "w+" )
82 resultsDB.close()
GlennRCdc7ab012015-07-23 15:40:12 -070083
YPZhang801d46d2016-08-08 13:26:28 -070084 main.portFunc = imp.load_source(main.dependencyFunc,
85 main.dependencyPath +
86 main.dependencyFunc +
87 ".py")
GlennRCdc7ab012015-07-23 15:40:12 -070088
YPZhang801d46d2016-08-08 13:26:28 -070089 def CASE1( self, main ):
90 # Clean up test environment and set up
91 import time
92 main.log.info( "Get ONOS cluster IP" )
93 print( main.scale )
94 main.numCtrls = int( main.scale.pop(0) )
95 main.ONOSip = []
96 main.maxNumBatch = 0
97 main.AllONOSip = main.ONOSbench.getOnosIps()
98 for i in range( main.numCtrls ):
99 main.ONOSip.append( main.AllONOSip[i] )
100 main.log.info( main.ONOSip )
101 main.CLIs = []
102 main.log.info( "Creating list of ONOS cli handles" )
103 for i in range( main.numCtrls ):
104 main.CLIs.append( getattr(main, 'ONOS%scli' % (i + 1)) )
GlennRCdc7ab012015-07-23 15:40:12 -0700105
YPZhang801d46d2016-08-08 13:26:28 -0700106 if not main.CLIs:
107 main.log.error( "Failed to create the list of ONOS cli handles" )
108 main.cleanup()
109 main.exit()
GlennRCdc7ab012015-07-23 15:40:12 -0700110
YPZhang801d46d2016-08-08 13:26:28 -0700111 main.commit = main.ONOSbench.getVersion( report=True )
112 main.commit = main.commit.split(" ")[1]
113 main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls )
114 main.log.info("Safety check, killing all ONOS processes" +
115 " before initiating environment setup")
GlennRCdc7ab012015-07-23 15:40:12 -0700116
YPZhang801d46d2016-08-08 13:26:28 -0700117 for i in range( main.numCtrls ):
You Wangb98a9fa2017-02-15 17:27:42 -0800118 main.ONOSbench.onosStop( main.ONOSip[i] )
119 main.ONOSbench.onosKill( main.ONOSip[i] )
GlennRCdc7ab012015-07-23 15:40:12 -0700120
YPZhang801d46d2016-08-08 13:26:28 -0700121 main.log.info( "NODE COUNT = %s" % main.numCtrls )
122 main.ONOSbench.createCellFile(main.ONOSbench.ip_address,
123 main.cellName,
124 main.MN1Ip,
125 main.Apps,
Devin Lim461f0872017-06-05 16:49:33 -0700126 main.ONOSip,
127 main.ONOScli1.user_name)
YPZhang801d46d2016-08-08 13:26:28 -0700128 main.step( "Apply cell to environment" )
129 cellResult = main.ONOSbench.setCell( main.cellName )
130 verifyResult = main.ONOSbench.verifyCell()
131 stepResult = cellResult and verifyResult
132 utilities.assert_equals(expect=main.TRUE,
133 actual=stepResult,
134 onpass="Successfully applied cell to " + \
135 "environment",
136 onfail="Failed to apply cell to environment ")
GlennRCdc7ab012015-07-23 15:40:12 -0700137
138 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700139 packageResult = main.ONOSbench.buckBuild()
YPZhang801d46d2016-08-08 13:26:28 -0700140 stepResult = packageResult
141 utilities.assert_equals(expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully created ONOS package",
144 onfail="Failed to create ONOS package")
GlennRCdc7ab012015-07-23 15:40:12 -0700145
YPZhang801d46d2016-08-08 13:26:28 -0700146 main.step( "Uninstall ONOS package on all Nodes" )
147 uninstallResult = main.TRUE
148 for i in range( int( main.numCtrls ) ):
149 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
150 u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
151 utilities.assert_equals(expect=main.TRUE, actual=u_result,
152 onpass="Test step PASS",
153 onfail="Test step FAIL")
154 uninstallResult = uninstallResult and u_result
GlennRCdc7ab012015-07-23 15:40:12 -0700155
YPZhang801d46d2016-08-08 13:26:28 -0700156 main.step( "Install ONOS package on all Nodes" )
157 installResult = main.TRUE
158 for i in range( int( main.numCtrls ) ):
159 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
160 i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
161 utilities.assert_equals(expect=main.TRUE, actual=i_result,
162 onpass="Test step PASS",
163 onfail="Test step FAIL")
164 installResult = installResult and i_result
165
Chiyu Chengef109502016-11-21 15:51:38 -0800166 main.step( "Set up ONOS secure SSH" )
167 secureSshResult = main.TRUE
168 for i in range( int( main.numCtrls ) ):
169 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
170 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
171 onpass="Test step PASS",
172 onfail="Test step FAIL" )
173
You Wang0357c432017-01-09 16:13:33 -0800174 time.sleep( main.startUpSleep )
175 main.step( "Starting ONOS service" )
176 stopResult = main.TRUE
177 startResult = main.TRUE
178 onosIsUp = main.TRUE
179 for i in range( main.numCtrls ):
180 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
181 if onosIsUp == main.TRUE:
182 main.log.report( "ONOS instance is up and ready" )
183 else:
184 main.log.report( "ONOS instance may not be up, stop and " +
185 "start ONOS again " )
186 for i in range( main.numCtrls ):
187 stopResult = stopResult and \
188 main.ONOSbench.onosStop( main.ONOSip[ i ] )
189 for i in range( main.numCtrls ):
190 startResult = startResult and \
191 main.ONOSbench.onosStart( main.ONOSip[ i ] )
192 stepResult = onosIsUp and stopResult and startResult
193 utilities.assert_equals( expect=main.TRUE,
194 actual=stepResult,
195 onpass="ONOS service is ready",
196 onfail="ONOS service did not start properly" )
197
YPZhang801d46d2016-08-08 13:26:28 -0700198 main.step( "Start ONOS CLI on all nodes" )
199 cliResult = main.TRUE
200 main.step( " Start ONOS cli using thread " )
201 startCliResult = main.TRUE
202 pool = []
203 main.threadID = 0
204 for i in range( int( main.numCtrls ) ):
205 t = main.Thread(target=main.CLIs[i].startOnosCli,
206 threadID=main.threadID,
207 name="startOnosCli",
208 args=[main.ONOSip[i]],
209 kwargs={"onosStartTimeout": main.timeout})
210 pool.append(t)
211 t.start()
212 main.threadID = main.threadID + 1
213 for t in pool:
214 t.join()
215 startCliResult = startCliResult and t.result
216 time.sleep( main.startUpSleep )
217
218 main.log.info( "Configure apps" )
219 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
220 "maxEvents 1")
221 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
222 "maxBatchMs 0")
223 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
224 "maxIdleMs 0")
225 time.sleep(1)
226 main.log.info( "Copy topology file to Mininet" )
227 main.ONOSbench.copyMininetFile(main.topoName,
228 main.dependencyPath,
229 main.Mininet1.user_name,
230 main.Mininet1.ip_address)
231 main.log.info( "Stop Mininet..." )
232 main.Mininet1.stopNet()
233 time.sleep( main.MNSleep )
234 main.log.info( "Start new mininet topology" )
GlennRCdc7ab012015-07-23 15:40:12 -0700235 main.Mininet1.startNet()
YPZhang801d46d2016-08-08 13:26:28 -0700236 main.log.info( "Assign switch to controller to ONOS node 1" )
237 time.sleep(1)
238 main.Mininet1.assignSwController( sw='s1', ip=main.ONOSip[0] )
239 main.Mininet1.assignSwController( sw='s2', ip=main.ONOSip[0] )
GlennRCdc7ab012015-07-23 15:40:12 -0700240
YPZhang801d46d2016-08-08 13:26:28 -0700241 time.sleep(2)
GlennRCdc7ab012015-07-23 15:40:12 -0700242
243 def CASE2( self, main ):
GlennRCdc7ab012015-07-23 15:40:12 -0700244 import time
GlennRCdc7ab012015-07-23 15:40:12 -0700245 import numpy
YPZhang801d46d2016-08-08 13:26:28 -0700246 # dictionary for each node and each timestamps
247 resultDict = {'up' : {}, 'down' : {}}
248 for d in resultDict:
249 for i in range( 1, main.numCtrls + 1 ):
250 resultDict[d][ 'node' + str(i) ] = {}
251 resultDict[d][ 'node' + str(i) ][ 'Ave' ] = {}
252 resultDict[d][ 'node' + str(i) ][ 'Std' ] = {}
253 resultDict[d][ 'node' + str(i) ][ 'EtoE' ] = []
254 resultDict[d][ 'node' + str(i) ][ 'PtoD' ] = []
255 resultDict[d][ 'node' + str(i) ][ 'DtoL' ] = []
256 resultDict[d][ 'node' + str(i) ][ 'LtoG' ] = []
257 for i in range( 1, main.sampleSize + main.warmUp ):
258 main.log.info( "==========================================" )
259 main.log.info( "================iteration:{}==============".format(str (i) ) )
260 if i > main.warmUp:
261 # Portdown iteration
262 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "down", resultDict, False )
263 time.sleep(2)
264 # PortUp iteration
265 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "up", resultDict, False )
GlennRCdc7ab012015-07-23 15:40:12 -0700266 else:
YPZhang801d46d2016-08-08 13:26:28 -0700267 # if warm up, keep old result dictionary
268 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "down", resultDict, True)
269 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "up", resultDict, True)
GlennRCdc7ab012015-07-23 15:40:12 -0700270
YPZhang801d46d2016-08-08 13:26:28 -0700271 # Dictionary for result
272 maxDict = {}
273 maxDict['down'] = {}
274 maxDict['up'] = {}
275 maxDict['down']['max'] = 0
276 maxDict['up']['max'] = 0
277 maxDict['down']['node'] = 0
278 maxDict['up']['node'] = 0
279 EtoEtemp = 0
280 for d in resultDict:
281 for i in range( 1, main.numCtrls + 1 ):
282 # calculate average and std for result, and grep the max End to End data
283 EtoEtemp = numpy.average( resultDict[d][ 'node' + str(i) ]['EtoE'] )
284 resultDict[d][ 'node' + str(i) ][ 'Ave' ][ 'EtoE' ] = EtoEtemp
285 if maxDict[d]['max'] < EtoEtemp:
286 # get max End to End latency
287 maxDict[d]['max'] = EtoEtemp
288 maxDict[d]['node'] = i
289 resultDict[d]['node' + str(i)]['Ave']['PtoD'] = numpy.average(resultDict[d]['node' + str(i)]['PtoD'])
290 resultDict[d]['node' + str(i)]['Ave']['DtoL'] = numpy.average(resultDict[d]['node' + str(i)]['DtoL'])
291 resultDict[d]['node' + str(i)]['Ave']['LtoG'] = numpy.average(resultDict[d]['node' + str(i)]['LtoG'])
GlennRCdc7ab012015-07-23 15:40:12 -0700292
YPZhang801d46d2016-08-08 13:26:28 -0700293 resultDict[d]['node' + str(i)]['Std']['EtoE'] = numpy.std(resultDict[d]['node' + str(i)]['EtoE'])
294 resultDict[d]['node' + str(i)]['Std']['PtoD'] = numpy.std(resultDict[d]['node' + str(i)]['PtoD'])
295 resultDict[d]['node' + str(i)]['Std']['DtoL'] = numpy.std(resultDict[d]['node' + str(i)]['DtoL'])
296 resultDict[d]['node' + str(i)]['Std']['LtoG'] = numpy.std(resultDict[d]['node' + str(i)]['LtoG'])
GlennRCdc7ab012015-07-23 15:40:12 -0700297
YPZhang801d46d2016-08-08 13:26:28 -0700298 main.log.report( "=====node{} Summary:=====".format( str(i) ) )
299 main.log.report( "=============Port {}=======".format( str(d) ) )
300 main.log.report(
301 "End to End average: {}".format( str(resultDict[d][ 'node' + str(i) ][ 'Ave' ][ 'EtoE' ]) ) )
302 main.log.report(
303 "End to End Std: {}".format( str(resultDict[d][ 'node' + str(i) ][ 'Std' ][ 'EtoE' ]) ) )
304 main.log.report(
305 "Package to Device average: {}".format( str(resultDict[d]['node' + str(i)]['Ave']['PtoD']) ) )
306 main.log.report(
307 "Package to Device Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['PtoD'])))
308 main.log.report(
309 "Device to Link average: {}".format( str( resultDict[d]['node' + str(i)]['Ave']['DtoL']) ) )
310 main.log.report(
311 "Device to Link Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['DtoL'])))
312 main.log.report(
313 "Link to Grapg average: {}".format( str( resultDict[d]['node' + str(i)]['Ave']['LtoG']) ) )
314 main.log.report(
315 "Link to Grapg Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['LtoG'] ) ) )
GlennRCdc7ab012015-07-23 15:40:12 -0700316
YPZhang801d46d2016-08-08 13:26:28 -0700317 with open( main.dbFileName, "a" ) as dbFile:
318 # Scale number
319 temp = str( main.numCtrls )
320 temp += ",'baremetal1'"
321 # put result
322 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'EtoE' ] )
323 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'PtoD' ] )
324 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'DtoL' ] )
325 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'LtoG' ] )
326 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'EtoE' ] )
327 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'PtoD' ] )
328 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'DtoL' ] )
329 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'LtoG' ] )
chengchiyu074e3ef2016-08-24 16:32:32 -0700330
331 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Std' ][ 'EtoE' ] )
332 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Std' ][ 'EtoE' ] )
333
YPZhang801d46d2016-08-08 13:26:28 -0700334 temp += "\n"
335 dbFile.write( temp )
336 dbFile.close()