blob: 8344cc48e08f7e256afebb3ce7dde625f8a5b123 [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
93 if gitPull == 'True':
94 if not main.startUp.onosBuild( main, gitBranch ):
95 main.log.error( "Failed to build ONOS" )
96 main.cleanup()
97 main.exit()
98 else:
99 main.log.warn( "Did not pull new code so skipping mvn " +
100 "clean install" )
101 with open(main.dbFileName, "a") as dbFile:
102 temp = "'" + main.commit + "',"
103 temp += "'" + nic + "',"
104 dbFile.write(temp)
105 dbFile.close()
106
107 def CASE2( self, main ):
108 """
109 - Uninstall ONOS cluster
110 - Verify ONOS start up
111 - Install ONOS cluster
112 - Connect to cli
113 """
114 main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls)
115 main.log.info( "Safety check, killing all ONOS processes" +
116 " before initiating environment setup" )
117
118 for i in range( main.numCtrls ):
You Wangc7e5cd02017-02-15 17:27:42 -0800119 main.ONOSbench.onosStop( main.ONOSip[ i ] )
120 main.ONOSbench.onosKill( main.ONOSip[ i ] )
YPZhanga482c202016-02-18 17:03:07 -0800121
122 main.log.info( "NODE COUNT = %s" % main.numCtrls)
123
124 tempOnosIp = []
125 for i in range( main.numCtrls ):
126 tempOnosIp.append( main.ONOSip[i] )
127
128 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
129 "temp",
130 main.Mininet1.ip_address,
131 main.apps,
132 tempOnosIp )
133
134 main.step( "Apply cell to environment" )
135 cellResult = main.ONOSbench.setCell( "temp" )
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 " )
143
144 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700145 packageResult = main.ONOSbench.buckBuild()
YPZhanga482c202016-02-18 17:03:07 -0800146 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" )
151
152 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 )
161
162 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 time.sleep( main.startUpSleep )
172 main.step( "Verify ONOS nodes UP status" )
173 statusResult = main.TRUE
174 for i in range( int( main.numCtrls ) ):
175 main.log.info( "ONOS Node " + main.ONOSip[i] + " status:" )
176 onos_status = main.ONOSbench.onosStatus( node=main.ONOSip[i] )
177 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
178 onpass="Test step PASS",
179 onfail="Test step FAIL" )
180 statusResult = ( statusResult and onos_status )
181
Chiyu Chengef109502016-11-21 15:51:38 -0800182 main.step( "Set up ONOS secure SSH" )
183 secureSshResult = main.TRUE
184 for i in range( int( main.numCtrls ) ):
185 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
186 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
187 onpass="Test step PASS",
188 onfail="Test step FAIL" )
189
YPZhanga482c202016-02-18 17:03:07 -0800190 main.step( "Start ONOS CLI on all nodes" )
191 cliResult = main.TRUE
Jon Hall6509dbf2016-06-21 17:01:17 -0700192 main.step(" Start ONOS cli using thread ")
YPZhanga482c202016-02-18 17:03:07 -0800193 time.sleep( main.startUpSleep )
194 startCliResult = main.TRUE
195 pool = []
196
197 for i in range( int( main.numCtrls) ):
198 t = main.Thread( target=main.CLIs[i].startOnosCli,
199 threadID=main.threadID,
200 name="startOnosCli",
201 args=[ main.ONOSip[i] ],
202 kwargs = {"onosStartTimeout":main.timeout} )
203 pool.append(t)
204 t.start()
205 main.threadID = main.threadID + 1
206 for t in pool:
207 t.join()
208 startCliResult = startCliResult and t.result
209 time.sleep( main.startUpSleep )
210
211 def CASE11( self, main ):
212 main.log.info( "set and configure Application" )
213 import json
214 import time
215 time.sleep(main.startUpSleep)
216 main.step( "Activating org.onosproject.proxyarp" )
217 appStatus = utilities.retry( main.ONOSrest1.activateApp,
218 main.FALSE,
219 ['org.onosproject.proxyarp'],
220 sleep=3,
221 attempts=3 )
222 utilities.assert_equals( expect=main.TRUE,
223 actual=appStatus,
224 onpass="Successfully activated proxyarp",
225 onfail="Failed to activated proxyarp")
226
227 main.step( "Set up Default Topology Provider" )
228 appStatus = main.TRUE
229 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
230 configParam = 'maxEvents'
231 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' )
232 configParam = 'maxBatchMs'
233 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
234 configParam = 'maxIdleMs'
235 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
236 utilities.assert_equals( expect=main.TRUE,
237 actual=appStatus,
238 onpass="Successfully set DefaultTopologyProvider",
239 onfail="Failed to set DefaultTopologyProvider" )
240
241 time.sleep(main.startUpSleep)
242 main.step('Starting mininet topology')
243 mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
244 utilities.assert_equals( expect=main.TRUE,
245 actual=mnStatus,
246 onpass="Successfully started Mininet",
247 onfail="Failed to activate Mininet" )
248 main.step("Assinging masters to switches")
249 switches = main.Mininet1.getSwitches()
250 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
251 utilities.assert_equals( expect=main.TRUE,
252 actual=swStatus,
253 onpass="Successfully assigned switches to masters",
254 onfail="Failed assign switches to masters" )
255
256 time.sleep(main.startUpSleep)
257
258 def CASE20(self, main):
259 """
260 host1 send arping package and measure latency
261
262 There are only 1 levels of latency measurements to this test:
263 1 ) ARPING-to-device measurement: Measurement the time from host1
264 send apring package to onos processing the host event
265
266 """
267 import time
268 import subprocess
269 import json
270 import requests
271 import os
272 import numpy
273
274 # Host adding measurement
275 assertion = main.TRUE
276
277 main.log.report('Latency of adding one host to ONOS')
278 main.log.report('First ' + str(main.iterIgnore) + ' iterations ignored' + ' for jvm warmup time')
279 main.log.report('Total iterations of test: ' + str(main.numlter))
280
281 addingHostTime = []
282 metricsResultList = []
283 for i in range(0, int(main.numlter)):
284 main.log.info('Clean up data file')
285 with open(main.tsharkResultPath, "w") as dbFile:
286 dbFile.write("")
287
288 main.log.info('Starting tshark capture')
289 main.ONOSbench.tsharkGrep(main.tsharkPacketIn, main.tsharkResultPath)
290 time.sleep(main.measurementSleep)
291
292 main.log.info('host 1 arping...')
293 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
294
295 time.sleep(main.measurementSleep)
296
297 main.log.info('Stopping all Tshark processes')
298 main.ONOSbench.tsharkStop()
299
300 time.sleep(main.measurementSleep)
301
302 # Get tshark output
303 with open(main.tsharkResultPath, "r") as resultFile:
304 resultText = resultFile.readline()
305 main.log.info('Capture result:' + resultText)
306 resultText = resultText.split(' ')
307 if len(resultText) > 1:
308 tsharkResultTime = float(resultText[1]) * 1000.0
309 else:
310 main.log.error('Tshark output file for packet_in' + ' returned unexpected results')
311 hostTime = 0
312 caseResult = main.FALSE
313 resultFile.close()
314 # Compare the timestemps, and get the lowest one.
315 temp = 0;
316 # Get host event timestamps from each nodes
317 for node in range (0, main.numCtrls):
318 metricsResult = json.loads(main.CLIs[node].topologyEventsMetrics())
319 metricsResult = metricsResult.get(main.hostTimestampKey).get("value")
320 main.log.info("ONOS topology event matrics timestemp: {}".format(str(metricsResult)) )
321
322 if temp < metricsResult:
323 temp = metricsResult
324 metricsResult = temp
325
326 addingHostTime.append(float(metricsResult) - tsharkResultTime)
327 main.log.info("Result of this iteration: {}".format( str( float(metricsResult) - tsharkResultTime) ))
328 # gethost to remove
329 gethost = main.ONOSrest1.hosts()
330 HosttoRemove = []
331 HosttoRemove.append( json.loads( gethost[1:len(gethost)-1] ).get('id') )
332 main.CLIs[0].removeHost(HosttoRemove)
333
YPZhang82ca5892016-03-01 15:32:09 -0800334 main.log.info("Result List: {}".format(addingHostTime))
335
YPZhanga482c202016-02-18 17:03:07 -0800336 # calculate average latency from each nodes
337 averageResult = numpy.average(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800338 main.log.info("Average Latency: {}".format(averageResult))
YPZhanga482c202016-02-18 17:03:07 -0800339
340 # calculate std
341 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800342 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800343
344 # write to DB file
345 main.log.info("Writing results to DS file")
346 with open(main.dbFileName, "a") as dbFile:
347 # Scale number
348 temp = str(main.numCtrls)
349 temp += ",'" + "baremetal1" + "'"
350 # average latency
351 temp += "," + str( averageResult )
352 # std of latency
353 temp += "," + str(stdResult)
354 temp += "\n"
355 dbFile.write( temp )
356
357 assertion = main.TRUE
358
359 utilities.assert_equals(expect=main.TRUE, actual=assertion,
360 onpass='Host latency test successful',
361 onfail='Host latency test failed')
362
363 main.Mininet1.stopNet()
364 del main.scale[0]