blob: c24b6a7b8311002b59be5aec3f1fa17d7b5a571c [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 ):
119 main.ONOSbench.onosDie( main.ONOSip[ i ] )
120
121 main.log.info( "NODE COUNT = %s" % main.numCtrls)
122
123 tempOnosIp = []
124 for i in range( main.numCtrls ):
125 tempOnosIp.append( main.ONOSip[i] )
126
127 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
128 "temp",
129 main.Mininet1.ip_address,
130 main.apps,
131 tempOnosIp )
132
133 main.step( "Apply cell to environment" )
134 cellResult = main.ONOSbench.setCell( "temp" )
135 verifyResult = main.ONOSbench.verifyCell()
136 stepResult = cellResult and verifyResult
137 utilities.assert_equals( expect=main.TRUE,
138 actual=stepResult,
139 onpass="Successfully applied cell to " + \
140 "environment",
141 onfail="Failed to apply cell to environment " )
142
143 main.step( "Creating ONOS package" )
144 packageResult = main.ONOSbench.onosPackage()
145 stepResult = packageResult
146 utilities.assert_equals( expect=main.TRUE,
147 actual=stepResult,
148 onpass="Successfully created ONOS package",
149 onfail="Failed to create ONOS package" )
150
151 main.step( "Uninstall ONOS package on all Nodes" )
152 uninstallResult = main.TRUE
153 for i in range( int( main.numCtrls ) ):
154 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
155 u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
156 utilities.assert_equals( expect=main.TRUE, actual=u_result,
157 onpass="Test step PASS",
158 onfail="Test step FAIL" )
159 uninstallResult = ( uninstallResult and u_result )
160
161 main.step( "Install ONOS package on all Nodes" )
162 installResult = main.TRUE
163 for i in range( int( main.numCtrls ) ):
164 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
165 i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
166 utilities.assert_equals( expect=main.TRUE, actual=i_result,
167 onpass="Test step PASS",
168 onfail="Test step FAIL" )
169 installResult = installResult and i_result
170 time.sleep( main.startUpSleep )
171 main.step( "Verify ONOS nodes UP status" )
172 statusResult = main.TRUE
173 for i in range( int( main.numCtrls ) ):
174 main.log.info( "ONOS Node " + main.ONOSip[i] + " status:" )
175 onos_status = main.ONOSbench.onosStatus( node=main.ONOSip[i] )
176 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
177 onpass="Test step PASS",
178 onfail="Test step FAIL" )
179 statusResult = ( statusResult and onos_status )
180
181 main.step( "Start ONOS CLI on all nodes" )
182 cliResult = main.TRUE
183 main.log.step(" Start ONOS cli using thread ")
184 time.sleep( main.startUpSleep )
185 startCliResult = main.TRUE
186 pool = []
187
188 for i in range( int( main.numCtrls) ):
189 t = main.Thread( target=main.CLIs[i].startOnosCli,
190 threadID=main.threadID,
191 name="startOnosCli",
192 args=[ main.ONOSip[i] ],
193 kwargs = {"onosStartTimeout":main.timeout} )
194 pool.append(t)
195 t.start()
196 main.threadID = main.threadID + 1
197 for t in pool:
198 t.join()
199 startCliResult = startCliResult and t.result
200 time.sleep( main.startUpSleep )
201
202 def CASE11( self, main ):
203 main.log.info( "set and configure Application" )
204 import json
205 import time
206 time.sleep(main.startUpSleep)
207 main.step( "Activating org.onosproject.proxyarp" )
208 appStatus = utilities.retry( main.ONOSrest1.activateApp,
209 main.FALSE,
210 ['org.onosproject.proxyarp'],
211 sleep=3,
212 attempts=3 )
213 utilities.assert_equals( expect=main.TRUE,
214 actual=appStatus,
215 onpass="Successfully activated proxyarp",
216 onfail="Failed to activated proxyarp")
217
218 main.step( "Set up Default Topology Provider" )
219 appStatus = main.TRUE
220 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
221 configParam = 'maxEvents'
222 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' )
223 configParam = 'maxBatchMs'
224 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
225 configParam = 'maxIdleMs'
226 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
227 utilities.assert_equals( expect=main.TRUE,
228 actual=appStatus,
229 onpass="Successfully set DefaultTopologyProvider",
230 onfail="Failed to set DefaultTopologyProvider" )
231
232 time.sleep(main.startUpSleep)
233 main.step('Starting mininet topology')
234 mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
235 utilities.assert_equals( expect=main.TRUE,
236 actual=mnStatus,
237 onpass="Successfully started Mininet",
238 onfail="Failed to activate Mininet" )
239 main.step("Assinging masters to switches")
240 switches = main.Mininet1.getSwitches()
241 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
242 utilities.assert_equals( expect=main.TRUE,
243 actual=swStatus,
244 onpass="Successfully assigned switches to masters",
245 onfail="Failed assign switches to masters" )
246
247 time.sleep(main.startUpSleep)
248
249 def CASE20(self, main):
250 """
251 host1 send arping package and measure latency
252
253 There are only 1 levels of latency measurements to this test:
254 1 ) ARPING-to-device measurement: Measurement the time from host1
255 send apring package to onos processing the host event
256
257 """
258 import time
259 import subprocess
260 import json
261 import requests
262 import os
263 import numpy
264
265 # Host adding measurement
266 assertion = main.TRUE
267
268 main.log.report('Latency of adding one host to ONOS')
269 main.log.report('First ' + str(main.iterIgnore) + ' iterations ignored' + ' for jvm warmup time')
270 main.log.report('Total iterations of test: ' + str(main.numlter))
271
272 addingHostTime = []
273 metricsResultList = []
274 for i in range(0, int(main.numlter)):
275 main.log.info('Clean up data file')
276 with open(main.tsharkResultPath, "w") as dbFile:
277 dbFile.write("")
278
279 main.log.info('Starting tshark capture')
280 main.ONOSbench.tsharkGrep(main.tsharkPacketIn, main.tsharkResultPath)
281 time.sleep(main.measurementSleep)
282
283 main.log.info('host 1 arping...')
284 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
285
286 time.sleep(main.measurementSleep)
287
288 main.log.info('Stopping all Tshark processes')
289 main.ONOSbench.tsharkStop()
290
291 time.sleep(main.measurementSleep)
292
293 # Get tshark output
294 with open(main.tsharkResultPath, "r") as resultFile:
295 resultText = resultFile.readline()
296 main.log.info('Capture result:' + resultText)
297 resultText = resultText.split(' ')
298 if len(resultText) > 1:
299 tsharkResultTime = float(resultText[1]) * 1000.0
300 else:
301 main.log.error('Tshark output file for packet_in' + ' returned unexpected results')
302 hostTime = 0
303 caseResult = main.FALSE
304 resultFile.close()
305 # Compare the timestemps, and get the lowest one.
306 temp = 0;
307 # Get host event timestamps from each nodes
308 for node in range (0, main.numCtrls):
309 metricsResult = json.loads(main.CLIs[node].topologyEventsMetrics())
310 metricsResult = metricsResult.get(main.hostTimestampKey).get("value")
311 main.log.info("ONOS topology event matrics timestemp: {}".format(str(metricsResult)) )
312
313 if temp < metricsResult:
314 temp = metricsResult
315 metricsResult = temp
316
317 addingHostTime.append(float(metricsResult) - tsharkResultTime)
318 main.log.info("Result of this iteration: {}".format( str( float(metricsResult) - tsharkResultTime) ))
319 # gethost to remove
320 gethost = main.ONOSrest1.hosts()
321 HosttoRemove = []
322 HosttoRemove.append( json.loads( gethost[1:len(gethost)-1] ).get('id') )
323 main.CLIs[0].removeHost(HosttoRemove)
324
YPZhang82ca5892016-03-01 15:32:09 -0800325 main.log.info("Result List: {}".format(addingHostTime))
326
YPZhanga482c202016-02-18 17:03:07 -0800327 # calculate average latency from each nodes
328 averageResult = numpy.average(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800329 main.log.info("Average Latency: {}".format(averageResult))
YPZhanga482c202016-02-18 17:03:07 -0800330
331 # calculate std
332 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800333 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800334
335 # write to DB file
336 main.log.info("Writing results to DS file")
337 with open(main.dbFileName, "a") as dbFile:
338 # Scale number
339 temp = str(main.numCtrls)
340 temp += ",'" + "baremetal1" + "'"
341 # average latency
342 temp += "," + str( averageResult )
343 # std of latency
344 temp += "," + str(stdResult)
345 temp += "\n"
346 dbFile.write( temp )
347
348 assertion = main.TRUE
349
350 utilities.assert_equals(expect=main.TRUE, actual=assertion,
351 onpass='Host latency test successful',
352 onfail='Host latency test failed')
353
354 main.Mininet1.stopNet()
355 del main.scale[0]