blob: b29ca81944d602d90596f51edcdd1af713b6a57d [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
47 main.step( "Building ONOS branch: " + gitBranch )
48 stepResult = main.ONOSbench.cleanInstall( skipTest=True )
49 utilities.assert_equals(expect=main.TRUE,
50 actual=stepResult,
51 onpass="Successfully build onos.",
52 onfail="Failed to build onos. Exiting test...")
53 if not stepResult: main.exit()
54
55 else:
56 main.log.warn( "Skipped pulling onos and Skipped building ONOS" )
57
58 main.testOnDirectory = os.path.dirname( os.getcwd() )
59 main.MN1Ip = main.params['MN']['ip1']
YPZhang0433bee2016-07-12 16:10:59 -070060 main.dependencyPath = main.testOnDirectory + \
61 main.params['DEPENDENCY']['path']
YPZhang801d46d2016-08-08 13:26:28 -070062 main.dependencyFunc = main.params['DEPENDENCY']['function']
63 main.topoName = main.params['DEPENDENCY']['topology']
64 main.cellName = main.params['ENV']['cellName']
65 main.Apps = main.params['ENV']['cellApps']
66 main.scale = (main.params['SCALE']).split(",")
67 main.ofportStatus = main.params['TSHARK']['ofpPortStatus']
68 main.tsharkResultPath = main.params['TSHARK']['tsharkReusltPath']
69 main.sampleSize = int( main.params['TEST']['sampleSize'] )
70 main.warmUp = int( main.params['TEST']['warmUp'] )
71 main.maxProcessTime = int( main.params['TEST']['maxProcessTime'])
72 main.dbFileName = main.params['DATABASE']['dbName']
73 main.startUpSleep = int( main.params['SLEEP']['startup'] )
74 main.measurementSleep = int( main.params['SLEEP']['measure'] )
75 main.maxScale = int( main.params['max'] )
76 main.interface = main.params['TEST']['interface']
77 main.timeout = int( main.params['TIMEOUT']['timeout'] )
78 main.MNSleep = int( main.params['SLEEP']['mininet'])
79 main.device = main.params['TEST']['device']
80 main.debug = main.params['TEST']['debug']
GlennRCdc7ab012015-07-23 15:40:12 -070081
YPZhang801d46d2016-08-08 13:26:28 -070082 if main.debug == "True":
83 main.debug = True
84 else:
85 main.debug = False
GlennRCdc7ab012015-07-23 15:40:12 -070086
YPZhang801d46d2016-08-08 13:26:28 -070087 main.log.info( "Create Database file " + main.dbFileName )
88 resultsDB = open( main.dbFileName, "w+" )
89 resultsDB.close()
GlennRCdc7ab012015-07-23 15:40:12 -070090
YPZhang801d46d2016-08-08 13:26:28 -070091 main.portFunc = imp.load_source(main.dependencyFunc,
92 main.dependencyPath +
93 main.dependencyFunc +
94 ".py")
GlennRCdc7ab012015-07-23 15:40:12 -070095
YPZhang801d46d2016-08-08 13:26:28 -070096 def CASE1( self, main ):
97 # Clean up test environment and set up
98 import time
99 main.log.info( "Get ONOS cluster IP" )
100 print( main.scale )
101 main.numCtrls = int( main.scale.pop(0) )
102 main.ONOSip = []
103 main.maxNumBatch = 0
104 main.AllONOSip = main.ONOSbench.getOnosIps()
105 for i in range( main.numCtrls ):
106 main.ONOSip.append( main.AllONOSip[i] )
107 main.log.info( main.ONOSip )
108 main.CLIs = []
109 main.log.info( "Creating list of ONOS cli handles" )
110 for i in range( main.numCtrls ):
111 main.CLIs.append( getattr(main, 'ONOS%scli' % (i + 1)) )
GlennRCdc7ab012015-07-23 15:40:12 -0700112
YPZhang801d46d2016-08-08 13:26:28 -0700113 if not main.CLIs:
114 main.log.error( "Failed to create the list of ONOS cli handles" )
115 main.cleanup()
116 main.exit()
GlennRCdc7ab012015-07-23 15:40:12 -0700117
YPZhang801d46d2016-08-08 13:26:28 -0700118 main.commit = main.ONOSbench.getVersion( report=True )
119 main.commit = main.commit.split(" ")[1]
120 main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls )
121 main.log.info("Safety check, killing all ONOS processes" +
122 " before initiating environment setup")
GlennRCdc7ab012015-07-23 15:40:12 -0700123
YPZhang801d46d2016-08-08 13:26:28 -0700124 for i in range( main.numCtrls ):
You Wangb98a9fa2017-02-15 17:27:42 -0800125 main.ONOSbench.onosStop( main.ONOSip[i] )
126 main.ONOSbench.onosKill( main.ONOSip[i] )
GlennRCdc7ab012015-07-23 15:40:12 -0700127
YPZhang801d46d2016-08-08 13:26:28 -0700128 main.log.info( "NODE COUNT = %s" % main.numCtrls )
129 main.ONOSbench.createCellFile(main.ONOSbench.ip_address,
130 main.cellName,
131 main.MN1Ip,
132 main.Apps,
133 main.ONOSip)
134 main.step( "Apply cell to environment" )
135 cellResult = main.ONOSbench.setCell( main.cellName )
136 verifyResult = main.ONOSbench.verifyCell()
137 stepResult = cellResult and verifyResult
138 utilities.assert_equals(expect=main.TRUE,
139 actual=stepResult,
140 onpass="Successfully applied cell to " + \
141 "environment",
142 onfail="Failed to apply cell to environment ")
GlennRCdc7ab012015-07-23 15:40:12 -0700143
144 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700145 packageResult = main.ONOSbench.buckBuild()
YPZhang801d46d2016-08-08 13:26:28 -0700146 stepResult = packageResult
147 utilities.assert_equals(expect=main.TRUE,
148 actual=stepResult,
149 onpass="Successfully created ONOS package",
150 onfail="Failed to create ONOS package")
GlennRCdc7ab012015-07-23 15:40:12 -0700151
YPZhang801d46d2016-08-08 13:26:28 -0700152 main.step( "Uninstall ONOS package on all Nodes" )
153 uninstallResult = main.TRUE
154 for i in range( int( main.numCtrls ) ):
155 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
156 u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
157 utilities.assert_equals(expect=main.TRUE, actual=u_result,
158 onpass="Test step PASS",
159 onfail="Test step FAIL")
160 uninstallResult = uninstallResult and u_result
GlennRCdc7ab012015-07-23 15:40:12 -0700161
YPZhang801d46d2016-08-08 13:26:28 -0700162 main.step( "Install ONOS package on all Nodes" )
163 installResult = main.TRUE
164 for i in range( int( main.numCtrls ) ):
165 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
166 i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
167 utilities.assert_equals(expect=main.TRUE, actual=i_result,
168 onpass="Test step PASS",
169 onfail="Test step FAIL")
170 installResult = installResult and i_result
171
Chiyu Chengef109502016-11-21 15:51:38 -0800172 main.step( "Set up ONOS secure SSH" )
173 secureSshResult = main.TRUE
174 for i in range( int( main.numCtrls ) ):
175 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
176 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
177 onpass="Test step PASS",
178 onfail="Test step FAIL" )
179
You Wang0357c432017-01-09 16:13:33 -0800180 time.sleep( main.startUpSleep )
181 main.step( "Starting ONOS service" )
182 stopResult = main.TRUE
183 startResult = main.TRUE
184 onosIsUp = main.TRUE
185 for i in range( main.numCtrls ):
186 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
187 if onosIsUp == main.TRUE:
188 main.log.report( "ONOS instance is up and ready" )
189 else:
190 main.log.report( "ONOS instance may not be up, stop and " +
191 "start ONOS again " )
192 for i in range( main.numCtrls ):
193 stopResult = stopResult and \
194 main.ONOSbench.onosStop( main.ONOSip[ i ] )
195 for i in range( main.numCtrls ):
196 startResult = startResult and \
197 main.ONOSbench.onosStart( main.ONOSip[ i ] )
198 stepResult = onosIsUp and stopResult and startResult
199 utilities.assert_equals( expect=main.TRUE,
200 actual=stepResult,
201 onpass="ONOS service is ready",
202 onfail="ONOS service did not start properly" )
203
YPZhang801d46d2016-08-08 13:26:28 -0700204 main.step( "Start ONOS CLI on all nodes" )
205 cliResult = main.TRUE
206 main.step( " Start ONOS cli using thread " )
207 startCliResult = main.TRUE
208 pool = []
209 main.threadID = 0
210 for i in range( int( main.numCtrls ) ):
211 t = main.Thread(target=main.CLIs[i].startOnosCli,
212 threadID=main.threadID,
213 name="startOnosCli",
214 args=[main.ONOSip[i]],
215 kwargs={"onosStartTimeout": main.timeout})
216 pool.append(t)
217 t.start()
218 main.threadID = main.threadID + 1
219 for t in pool:
220 t.join()
221 startCliResult = startCliResult and t.result
222 time.sleep( main.startUpSleep )
223
224 main.log.info( "Configure apps" )
225 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
226 "maxEvents 1")
227 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
228 "maxBatchMs 0")
229 main.CLIs[0].setCfg("org.onosproject.net.topology.impl.DefaultTopologyProvider",
230 "maxIdleMs 0")
231 time.sleep(1)
232 main.log.info( "Copy topology file to Mininet" )
233 main.ONOSbench.copyMininetFile(main.topoName,
234 main.dependencyPath,
235 main.Mininet1.user_name,
236 main.Mininet1.ip_address)
237 main.log.info( "Stop Mininet..." )
238 main.Mininet1.stopNet()
239 time.sleep( main.MNSleep )
240 main.log.info( "Start new mininet topology" )
GlennRCdc7ab012015-07-23 15:40:12 -0700241 main.Mininet1.startNet()
YPZhang801d46d2016-08-08 13:26:28 -0700242 main.log.info( "Assign switch to controller to ONOS node 1" )
243 time.sleep(1)
244 main.Mininet1.assignSwController( sw='s1', ip=main.ONOSip[0] )
245 main.Mininet1.assignSwController( sw='s2', ip=main.ONOSip[0] )
GlennRCdc7ab012015-07-23 15:40:12 -0700246
YPZhang801d46d2016-08-08 13:26:28 -0700247 time.sleep(2)
GlennRCdc7ab012015-07-23 15:40:12 -0700248
249 def CASE2( self, main ):
GlennRCdc7ab012015-07-23 15:40:12 -0700250 import time
GlennRCdc7ab012015-07-23 15:40:12 -0700251 import numpy
YPZhang801d46d2016-08-08 13:26:28 -0700252 # dictionary for each node and each timestamps
253 resultDict = {'up' : {}, 'down' : {}}
254 for d in resultDict:
255 for i in range( 1, main.numCtrls + 1 ):
256 resultDict[d][ 'node' + str(i) ] = {}
257 resultDict[d][ 'node' + str(i) ][ 'Ave' ] = {}
258 resultDict[d][ 'node' + str(i) ][ 'Std' ] = {}
259 resultDict[d][ 'node' + str(i) ][ 'EtoE' ] = []
260 resultDict[d][ 'node' + str(i) ][ 'PtoD' ] = []
261 resultDict[d][ 'node' + str(i) ][ 'DtoL' ] = []
262 resultDict[d][ 'node' + str(i) ][ 'LtoG' ] = []
263 for i in range( 1, main.sampleSize + main.warmUp ):
264 main.log.info( "==========================================" )
265 main.log.info( "================iteration:{}==============".format(str (i) ) )
266 if i > main.warmUp:
267 # Portdown iteration
268 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "down", resultDict, False )
269 time.sleep(2)
270 # PortUp iteration
271 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "up", resultDict, False )
GlennRCdc7ab012015-07-23 15:40:12 -0700272 else:
YPZhang801d46d2016-08-08 13:26:28 -0700273 # if warm up, keep old result dictionary
274 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "down", resultDict, True)
275 main.portFunc.capturePortStatusPack( main, main.device, main.interface, "up", resultDict, True)
GlennRCdc7ab012015-07-23 15:40:12 -0700276
YPZhang801d46d2016-08-08 13:26:28 -0700277 # Dictionary for result
278 maxDict = {}
279 maxDict['down'] = {}
280 maxDict['up'] = {}
281 maxDict['down']['max'] = 0
282 maxDict['up']['max'] = 0
283 maxDict['down']['node'] = 0
284 maxDict['up']['node'] = 0
285 EtoEtemp = 0
286 for d in resultDict:
287 for i in range( 1, main.numCtrls + 1 ):
288 # calculate average and std for result, and grep the max End to End data
289 EtoEtemp = numpy.average( resultDict[d][ 'node' + str(i) ]['EtoE'] )
290 resultDict[d][ 'node' + str(i) ][ 'Ave' ][ 'EtoE' ] = EtoEtemp
291 if maxDict[d]['max'] < EtoEtemp:
292 # get max End to End latency
293 maxDict[d]['max'] = EtoEtemp
294 maxDict[d]['node'] = i
295 resultDict[d]['node' + str(i)]['Ave']['PtoD'] = numpy.average(resultDict[d]['node' + str(i)]['PtoD'])
296 resultDict[d]['node' + str(i)]['Ave']['DtoL'] = numpy.average(resultDict[d]['node' + str(i)]['DtoL'])
297 resultDict[d]['node' + str(i)]['Ave']['LtoG'] = numpy.average(resultDict[d]['node' + str(i)]['LtoG'])
GlennRCdc7ab012015-07-23 15:40:12 -0700298
YPZhang801d46d2016-08-08 13:26:28 -0700299 resultDict[d]['node' + str(i)]['Std']['EtoE'] = numpy.std(resultDict[d]['node' + str(i)]['EtoE'])
300 resultDict[d]['node' + str(i)]['Std']['PtoD'] = numpy.std(resultDict[d]['node' + str(i)]['PtoD'])
301 resultDict[d]['node' + str(i)]['Std']['DtoL'] = numpy.std(resultDict[d]['node' + str(i)]['DtoL'])
302 resultDict[d]['node' + str(i)]['Std']['LtoG'] = numpy.std(resultDict[d]['node' + str(i)]['LtoG'])
GlennRCdc7ab012015-07-23 15:40:12 -0700303
YPZhang801d46d2016-08-08 13:26:28 -0700304 main.log.report( "=====node{} Summary:=====".format( str(i) ) )
305 main.log.report( "=============Port {}=======".format( str(d) ) )
306 main.log.report(
307 "End to End average: {}".format( str(resultDict[d][ 'node' + str(i) ][ 'Ave' ][ 'EtoE' ]) ) )
308 main.log.report(
309 "End to End Std: {}".format( str(resultDict[d][ 'node' + str(i) ][ 'Std' ][ 'EtoE' ]) ) )
310 main.log.report(
311 "Package to Device average: {}".format( str(resultDict[d]['node' + str(i)]['Ave']['PtoD']) ) )
312 main.log.report(
313 "Package to Device Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['PtoD'])))
314 main.log.report(
315 "Device to Link average: {}".format( str( resultDict[d]['node' + str(i)]['Ave']['DtoL']) ) )
316 main.log.report(
317 "Device to Link Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['DtoL'])))
318 main.log.report(
319 "Link to Grapg average: {}".format( str( resultDict[d]['node' + str(i)]['Ave']['LtoG']) ) )
320 main.log.report(
321 "Link to Grapg Std: {}".format( str( resultDict[d]['node' + str(i)]['Std']['LtoG'] ) ) )
GlennRCdc7ab012015-07-23 15:40:12 -0700322
YPZhang801d46d2016-08-08 13:26:28 -0700323 with open( main.dbFileName, "a" ) as dbFile:
324 # Scale number
325 temp = str( main.numCtrls )
326 temp += ",'baremetal1'"
327 # put result
328 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'EtoE' ] )
329 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'PtoD' ] )
330 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'DtoL' ] )
331 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Ave' ][ 'LtoG' ] )
332 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'EtoE' ] )
333 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'PtoD' ] )
334 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'DtoL' ] )
335 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Ave' ][ 'LtoG' ] )
chengchiyu074e3ef2016-08-24 16:32:32 -0700336
337 temp += "," + str( resultDict['up'][ 'node' + str(maxDict['up']['node']) ][ 'Std' ][ 'EtoE' ] )
338 temp += "," + str( resultDict['down'][ 'node' + str(maxDict['down']['node']) ][ 'Std' ][ 'EtoE' ] )
339
YPZhang801d46d2016-08-08 13:26:28 -0700340 temp += "\n"
341 dbFile.write( temp )
342 dbFile.close()