blob: e3af24a47e4def8cbdf257d51c6c684a446d511b [file] [log] [blame]
YPZhanga482c202016-02-18 17:03:07 -08001"""
2 SCPFhostLat
3 This test will test the host found latency.
4 Host will arping a ip address, tshark will caputure the package time, then compare with the topology event timestamp.
5 Test will run with 1 node from start, and scale up to 7 nodes.
6 The event timestamp will only greb the latest one, then calculate average and standar dev.
7
8 yunpeng@onlab.us
9"""
10class SCPFhostLat:
11
12 def __init__( self ):
13 self.default = ''
14
15 def CASE0( self, main):
16 import sys
17 import json
18 import time
19 import os
20 import imp
21
22 main.case( "Constructing test variables and building ONOS package" )
23 main.step( "Constructing test variables" )
24 stepResult = main.FALSE
25
26 # Test variables
27 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
28 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
29 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
30 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
31 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
32 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
33 main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
34 main.measurementSleep = int( main.params['SLEEP']['measurement'])
35 main.timeout = int( main.params['SLEEP']['timeout'] )
36 main.dbFileName = main.params['DATABASE']['file']
37 main.cellData = {} # for creating cell file
38
39 # Tshark params
40 main.tsharkResultPath = main.params['TSHARK']['tsharkPath']
41 main.tsharkPacketIn = main.params['TSHARK']['tsharkPacketIn']
42
43 main.numlter = main.params['TEST']['numIter']
44 main.iterIgnore = int(main.params['TEST']['iterIgnore'])
45 main.hostTimestampKey = main.params['TEST']['hostTimestamp']
46 main.thresholdStr = main.params['TEST']['singleSwThreshold']
47 main.thresholdObj = main.thresholdStr.split(',')
48 main.thresholdMin = int(main.thresholdObj[0])
49 main.thresholdMax = int(main.thresholdObj[1])
50 main.threadID = 0
51
52 main.CLIs = []
53 main.ONOSip = []
54 main.maxNumBatch = 0
55 main.ONOSip = main.ONOSbench.getOnosIps()
56 main.log.info(main.ONOSip)
57 main.setupSkipped = False
58
59 gitBranch = main.params[ 'GIT' ][ 'branch' ]
60 gitPull = main.params[ 'GIT' ][ 'pull' ]
61 nic = main.params['DATABASE']['nic']
62 node = main.params['DATABASE']['node']
63 nic = main.params['DATABASE']['nic']
64 node = main.params['DATABASE']['node']
65 stepResult = main.TRUE
66
67 main.log.info("Cresting DB file")
68 with open(main.dbFileName, "w+") as dbFile:
69 dbFile.write("")
70
71 utilities.assert_equals( expect=main.TRUE,
72 actual=stepResult,
73 onpass="environment set up successfull",
74 onfail="environment set up Failed" )
75
76 def CASE1( self ):
77 # main.scale[ 0 ] determines the current number of ONOS controller
78 main.CLIs = []
79 main.numCtrls = int( main.scale[ 0 ] )
80 main.log.info( "Creating list of ONOS cli handles" )
81 for i in range(main.numCtrls):
82 main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) )
83
84 main.log.info(main.CLIs)
85 if not main.CLIs:
86 main.log.error( "Failed to create the list of ONOS cli handles" )
87 main.cleanup()
88 main.exit()
89
90 main.commit = main.ONOSbench.getVersion(report=True)
91 main.commit = main.commit.split(" ")[1]
92
YPZhanga482c202016-02-18 17:03:07 -080093 with open(main.dbFileName, "a") as dbFile:
94 temp = "'" + main.commit + "',"
95 temp += "'" + nic + "',"
96 dbFile.write(temp)
97 dbFile.close()
98
99 def CASE2( self, main ):
100 """
101 - Uninstall ONOS cluster
102 - Verify ONOS start up
103 - Install ONOS cluster
104 - Connect to cli
105 """
106 main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls)
107 main.log.info( "Safety check, killing all ONOS processes" +
108 " before initiating environment setup" )
109
110 for i in range( main.numCtrls ):
You Wangb98a9fa2017-02-15 17:27:42 -0800111 main.ONOSbench.onosStop( main.ONOSip[ i ] )
112 main.ONOSbench.onosKill( main.ONOSip[ i ] )
YPZhanga482c202016-02-18 17:03:07 -0800113
114 main.log.info( "NODE COUNT = %s" % main.numCtrls)
115
116 tempOnosIp = []
117 for i in range( main.numCtrls ):
118 tempOnosIp.append( main.ONOSip[i] )
119
120 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
121 "temp",
122 main.Mininet1.ip_address,
123 main.apps,
Devin Lim461f0872017-06-05 16:49:33 -0700124 tempOnosIp,
Devin Limdc78e202017-06-09 18:30:07 -0700125 main.ONOScli1.karafUser )
YPZhanga482c202016-02-18 17:03:07 -0800126
127 main.step( "Apply cell to environment" )
128 cellResult = main.ONOSbench.setCell( "temp" )
129 verifyResult = main.ONOSbench.verifyCell()
130 stepResult = cellResult and verifyResult
131 utilities.assert_equals( expect=main.TRUE,
132 actual=stepResult,
133 onpass="Successfully applied cell to " + \
134 "environment",
135 onfail="Failed to apply cell to environment " )
136
137 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700138 packageResult = main.ONOSbench.buckBuild()
YPZhanga482c202016-02-18 17:03:07 -0800139 stepResult = packageResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully created ONOS package",
143 onfail="Failed to create ONOS package" )
144
145 main.step( "Uninstall ONOS package on all Nodes" )
146 uninstallResult = main.TRUE
147 for i in range( int( main.numCtrls ) ):
148 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
149 u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
150 utilities.assert_equals( expect=main.TRUE, actual=u_result,
151 onpass="Test step PASS",
152 onfail="Test step FAIL" )
153 uninstallResult = ( uninstallResult and u_result )
154
155 main.step( "Install ONOS package on all Nodes" )
156 installResult = main.TRUE
157 for i in range( int( main.numCtrls ) ):
158 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
159 i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
160 utilities.assert_equals( expect=main.TRUE, actual=i_result,
161 onpass="Test step PASS",
162 onfail="Test step FAIL" )
163 installResult = installResult and i_result
YPZhanga482c202016-02-18 17:03:07 -0800164
Chiyu Chengef109502016-11-21 15:51:38 -0800165 main.step( "Set up ONOS secure SSH" )
166 secureSshResult = main.TRUE
167 for i in range( int( main.numCtrls ) ):
168 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
169 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
170 onpass="Test step PASS",
171 onfail="Test step FAIL" )
172
You Wang0357c432017-01-09 16:13:33 -0800173 time.sleep( main.startUpSleep )
174 main.step( "Starting ONOS service" )
175 stopResult = main.TRUE
176 startResult = main.TRUE
177 onosIsUp = main.TRUE
178
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
YPZhanga482c202016-02-18 17:03:07 -0800198 main.step( "Start ONOS CLI on all nodes" )
199 cliResult = main.TRUE
Jon Hall6509dbf2016-06-21 17:01:17 -0700200 main.step(" Start ONOS cli using thread ")
YPZhanga482c202016-02-18 17:03:07 -0800201 time.sleep( main.startUpSleep )
202 startCliResult = main.TRUE
203 pool = []
204
205 for i in range( int( main.numCtrls) ):
206 t = main.Thread( target=main.CLIs[i].startOnosCli,
207 threadID=main.threadID,
208 name="startOnosCli",
209 args=[ main.ONOSip[i] ],
210 kwargs = {"onosStartTimeout":main.timeout} )
211 pool.append(t)
212 t.start()
213 main.threadID = main.threadID + 1
214 for t in pool:
215 t.join()
216 startCliResult = startCliResult and t.result
217 time.sleep( main.startUpSleep )
218
219 def CASE11( self, main ):
220 main.log.info( "set and configure Application" )
221 import json
222 import time
223 time.sleep(main.startUpSleep)
224 main.step( "Activating org.onosproject.proxyarp" )
225 appStatus = utilities.retry( main.ONOSrest1.activateApp,
226 main.FALSE,
227 ['org.onosproject.proxyarp'],
228 sleep=3,
229 attempts=3 )
230 utilities.assert_equals( expect=main.TRUE,
231 actual=appStatus,
232 onpass="Successfully activated proxyarp",
233 onfail="Failed to activated proxyarp")
234
235 main.step( "Set up Default Topology Provider" )
236 appStatus = main.TRUE
237 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
238 configParam = 'maxEvents'
239 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' )
240 configParam = 'maxBatchMs'
241 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
242 configParam = 'maxIdleMs'
243 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
244 utilities.assert_equals( expect=main.TRUE,
245 actual=appStatus,
246 onpass="Successfully set DefaultTopologyProvider",
247 onfail="Failed to set DefaultTopologyProvider" )
248
249 time.sleep(main.startUpSleep)
250 main.step('Starting mininet topology')
251 mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
252 utilities.assert_equals( expect=main.TRUE,
253 actual=mnStatus,
254 onpass="Successfully started Mininet",
255 onfail="Failed to activate Mininet" )
256 main.step("Assinging masters to switches")
257 switches = main.Mininet1.getSwitches()
258 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
259 utilities.assert_equals( expect=main.TRUE,
260 actual=swStatus,
261 onpass="Successfully assigned switches to masters",
262 onfail="Failed assign switches to masters" )
263
264 time.sleep(main.startUpSleep)
265
266 def CASE20(self, main):
267 """
268 host1 send arping package and measure latency
269
270 There are only 1 levels of latency measurements to this test:
271 1 ) ARPING-to-device measurement: Measurement the time from host1
272 send apring package to onos processing the host event
273
274 """
275 import time
276 import subprocess
277 import json
278 import requests
279 import os
280 import numpy
281
282 # Host adding measurement
283 assertion = main.TRUE
284
285 main.log.report('Latency of adding one host to ONOS')
286 main.log.report('First ' + str(main.iterIgnore) + ' iterations ignored' + ' for jvm warmup time')
287 main.log.report('Total iterations of test: ' + str(main.numlter))
288
289 addingHostTime = []
290 metricsResultList = []
291 for i in range(0, int(main.numlter)):
292 main.log.info('Clean up data file')
293 with open(main.tsharkResultPath, "w") as dbFile:
294 dbFile.write("")
295
296 main.log.info('Starting tshark capture')
297 main.ONOSbench.tsharkGrep(main.tsharkPacketIn, main.tsharkResultPath)
298 time.sleep(main.measurementSleep)
299
300 main.log.info('host 1 arping...')
301 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
302
303 time.sleep(main.measurementSleep)
304
305 main.log.info('Stopping all Tshark processes')
306 main.ONOSbench.tsharkStop()
307
308 time.sleep(main.measurementSleep)
309
310 # Get tshark output
311 with open(main.tsharkResultPath, "r") as resultFile:
312 resultText = resultFile.readline()
313 main.log.info('Capture result:' + resultText)
314 resultText = resultText.split(' ')
315 if len(resultText) > 1:
316 tsharkResultTime = float(resultText[1]) * 1000.0
317 else:
318 main.log.error('Tshark output file for packet_in' + ' returned unexpected results')
319 hostTime = 0
320 caseResult = main.FALSE
321 resultFile.close()
322 # Compare the timestemps, and get the lowest one.
323 temp = 0;
324 # Get host event timestamps from each nodes
325 for node in range (0, main.numCtrls):
326 metricsResult = json.loads(main.CLIs[node].topologyEventsMetrics())
327 metricsResult = metricsResult.get(main.hostTimestampKey).get("value")
328 main.log.info("ONOS topology event matrics timestemp: {}".format(str(metricsResult)) )
329
330 if temp < metricsResult:
331 temp = metricsResult
332 metricsResult = temp
333
334 addingHostTime.append(float(metricsResult) - tsharkResultTime)
335 main.log.info("Result of this iteration: {}".format( str( float(metricsResult) - tsharkResultTime) ))
336 # gethost to remove
337 gethost = main.ONOSrest1.hosts()
338 HosttoRemove = []
339 HosttoRemove.append( json.loads( gethost[1:len(gethost)-1] ).get('id') )
340 main.CLIs[0].removeHost(HosttoRemove)
341
YPZhang82ca5892016-03-01 15:32:09 -0800342 main.log.info("Result List: {}".format(addingHostTime))
343
YPZhanga482c202016-02-18 17:03:07 -0800344 # calculate average latency from each nodes
345 averageResult = numpy.average(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800346 main.log.info("Average Latency: {}".format(averageResult))
YPZhanga482c202016-02-18 17:03:07 -0800347
348 # calculate std
349 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800350 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800351
352 # write to DB file
353 main.log.info("Writing results to DS file")
354 with open(main.dbFileName, "a") as dbFile:
355 # Scale number
356 temp = str(main.numCtrls)
357 temp += ",'" + "baremetal1" + "'"
358 # average latency
359 temp += "," + str( averageResult )
360 # std of latency
361 temp += "," + str(stdResult)
362 temp += "\n"
363 dbFile.write( temp )
364
365 assertion = main.TRUE
366
367 utilities.assert_equals(expect=main.TRUE, actual=assertion,
368 onpass='Host latency test successful',
369 onfail='Host latency test failed')
370
371 main.Mininet1.stopNet()
372 del main.scale[0]