blob: 6a819eb1e047e5b398eac26087016ff92d8818f1 [file] [log] [blame]
YPZhanga482c202016-02-18 17:03:07 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
22"""
YPZhanga482c202016-02-18 17:03:07 -080023 SCPFhostLat
24 This test will test the host found latency.
25 Host will arping a ip address, tshark will caputure the package time, then compare with the topology event timestamp.
26 Test will run with 1 node from start, and scale up to 7 nodes.
27 The event timestamp will only greb the latest one, then calculate average and standar dev.
28
29 yunpeng@onlab.us
30"""
31class SCPFhostLat:
32
33 def __init__( self ):
34 self.default = ''
35
36 def CASE0( self, main):
37 import sys
38 import json
39 import time
40 import os
41 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070042 try:
43 from tests.dependencies.ONOSSetup import ONOSSetup
44 main.testSetUp = ONOSSetup()
45 except ImportError:
46 main.log.error( "ONOSSetup not found. exiting the test" )
YPZhanga482c202016-02-18 17:03:07 -080047 main.exit()
Devin Lim58046fa2017-07-05 16:55:00 -070048 main.testSetUp.envSetupDescription()
49 stepResult = main.FALSE
50 try:
YPZhanga482c202016-02-18 17:03:07 -080051
Devin Lim58046fa2017-07-05 16:55:00 -070052 # Test variables
53 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
54 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
55 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
56 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
57 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
58 main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
59 main.measurementSleep = int( main.params[ 'SLEEP' ][ 'measurement' ] )
60 main.timeout = int( main.params[ 'SLEEP' ][ 'timeout' ] )
61 main.dbFileName = main.params[ 'DATABASE' ][ 'file' ]
YPZhanga482c202016-02-18 17:03:07 -080062
Devin Lim58046fa2017-07-05 16:55:00 -070063 # Tshark params
64 main.tsharkResultPath = main.params[ 'TSHARK' ][ 'tsharkPath' ]
65 main.tsharkPacketIn = main.params[ 'TSHARK' ][ 'tsharkPacketIn' ]
66
67 main.numlter = main.params[ 'TEST' ][ 'numIter' ]
68 main.iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
69 main.hostTimestampKey = main.params[ 'TEST' ][ 'hostTimestamp' ]
70 main.thresholdStr = main.params[ 'TEST' ][ 'singleSwThreshold' ]
71 main.thresholdObj = main.thresholdStr.split( ',' )
72 main.thresholdMin = int( main.thresholdObj[ 0 ] )
73 main.thresholdMax = int( main.thresholdObj[ 1 ] )
74 main.threadID = 0
75
76 main.maxNumBatch = 0
77 main.setupSkipped = False
78
79 nic = main.params[ 'DATABASE' ][ 'nic' ]
80 node = main.params[ 'DATABASE' ][ 'node' ]
81 nic = main.params[ 'DATABASE' ][ 'nic' ]
82 node = main.params[ 'DATABASE' ][ 'node' ]
83 stepResult = main.TRUE
84
85 main.log.info( "Cresting DB file" )
86 with open( main.dbFileName, "w+" ) as dbFile:
87 dbFile.write( "" )
88
89 stepResult = main.testSetUp.gitPulling()
90 except Exception as e:
91 main.testSetUp.envSetupException( e )
92 main.testSetUp.evnSetupConclusion( stepResult )
93
94 main.commit = main.commit.split( " " )[ 1 ]
95
96 with open( main.dbFileName, "a" ) as dbFile:
YPZhanga482c202016-02-18 17:03:07 -080097 temp = "'" + main.commit + "',"
98 temp += "'" + nic + "',"
Devin Lim58046fa2017-07-05 16:55:00 -070099 dbFile.write( temp )
YPZhanga482c202016-02-18 17:03:07 -0800100 dbFile.close()
Devin Lim58046fa2017-07-05 16:55:00 -0700101 def CASE1( self ):
102 # main.scale[ 0 ] determines the current number of ONOS controller
103 main.testSetUp.getNumCtrls( True )
104 main.testSetUp.envSetup( includeGitPull=False, makeMaxNodes=False )
YPZhanga482c202016-02-18 17:03:07 -0800105
106 def CASE2( self, main ):
107 """
108 - Uninstall ONOS cluster
109 - Verify ONOS start up
110 - Install ONOS cluster
111 - Connect to cli
112 """
Devin Lim58046fa2017-07-05 16:55:00 -0700113 main.testSetUp.ONOSSetUp( main.Mininet1, True,
114 cellName=main.cellName, killRemoveMax=False,
115 CtrlsSet=False )
YPZhanga482c202016-02-18 17:03:07 -0800116
117 def CASE11( self, main ):
118 main.log.info( "set and configure Application" )
119 import json
120 import time
121 time.sleep(main.startUpSleep)
122 main.step( "Activating org.onosproject.proxyarp" )
123 appStatus = utilities.retry( main.ONOSrest1.activateApp,
124 main.FALSE,
Devin Lim58046fa2017-07-05 16:55:00 -0700125 [ 'org.onosproject.proxyarp' ],
YPZhanga482c202016-02-18 17:03:07 -0800126 sleep=3,
127 attempts=3 )
128 utilities.assert_equals( expect=main.TRUE,
129 actual=appStatus,
130 onpass="Successfully activated proxyarp",
131 onfail="Failed to activated proxyarp")
132
133 main.step( "Set up Default Topology Provider" )
134 appStatus = main.TRUE
135 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
136 configParam = 'maxEvents'
137 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' )
138 configParam = 'maxBatchMs'
139 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
140 configParam = 'maxIdleMs'
141 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
142 utilities.assert_equals( expect=main.TRUE,
143 actual=appStatus,
144 onpass="Successfully set DefaultTopologyProvider",
145 onfail="Failed to set DefaultTopologyProvider" )
146
Devin Lim58046fa2017-07-05 16:55:00 -0700147 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800148 main.step('Starting mininet topology')
149 mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
150 utilities.assert_equals( expect=main.TRUE,
151 actual=mnStatus,
152 onpass="Successfully started Mininet",
153 onfail="Failed to activate Mininet" )
154 main.step("Assinging masters to switches")
155 switches = main.Mininet1.getSwitches()
156 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
157 utilities.assert_equals( expect=main.TRUE,
158 actual=swStatus,
159 onpass="Successfully assigned switches to masters",
160 onfail="Failed assign switches to masters" )
161
Devin Lim58046fa2017-07-05 16:55:00 -0700162 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800163
164 def CASE20(self, main):
165 """
166 host1 send arping package and measure latency
167
168 There are only 1 levels of latency measurements to this test:
169 1 ) ARPING-to-device measurement: Measurement the time from host1
170 send apring package to onos processing the host event
171
172 """
173 import time
174 import subprocess
175 import json
176 import requests
177 import os
178 import numpy
Devin Lim58046fa2017-07-05 16:55:00 -0700179 try:
180 from tests.dependencies.utils import Utils
181 except ImportError:
182 main.log.error( "Utils not found exiting the test" )
183 main.exit()
184 try:
185 main.Utils
186 except ( NameError, AttributeError ):
187 main.Utils = Utils()
YPZhanga482c202016-02-18 17:03:07 -0800188 # Host adding measurement
189 assertion = main.TRUE
190
191 main.log.report('Latency of adding one host to ONOS')
Devin Lim58046fa2017-07-05 16:55:00 -0700192 main.log.report('First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time')
193 main.log.report('Total iterations of test: ' + str( main.numlter ) )
YPZhanga482c202016-02-18 17:03:07 -0800194
195 addingHostTime = []
196 metricsResultList = []
Devin Lim58046fa2017-07-05 16:55:00 -0700197 for i in range( 0, int( main.numlter ) ):
198 main.log.info( 'Clean up data file' )
199 with open( main.tsharkResultPath, "w" ) as dbFile:
200 dbFile.write( "" )
YPZhanga482c202016-02-18 17:03:07 -0800201
202 main.log.info('Starting tshark capture')
Devin Lim58046fa2017-07-05 16:55:00 -0700203 main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath )
204 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800205
206 main.log.info('host 1 arping...')
207 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
208
Devin Lim58046fa2017-07-05 16:55:00 -0700209 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800210
211 main.log.info('Stopping all Tshark processes')
212 main.ONOSbench.tsharkStop()
213
Devin Lim58046fa2017-07-05 16:55:00 -0700214 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800215
216 # Get tshark output
Devin Lim58046fa2017-07-05 16:55:00 -0700217 with open( main.tsharkResultPath, "r" ) as resultFile:
YPZhanga482c202016-02-18 17:03:07 -0800218 resultText = resultFile.readline()
Devin Lim58046fa2017-07-05 16:55:00 -0700219 main.log.info( 'Capture result:' + resultText )
YPZhanga482c202016-02-18 17:03:07 -0800220 resultText = resultText.split(' ')
Devin Lim58046fa2017-07-05 16:55:00 -0700221 if len( resultText ) > 1:
222 tsharkResultTime = float( resultText[ 1 ] ) * 1000.0
YPZhanga482c202016-02-18 17:03:07 -0800223 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700224 main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' )
YPZhanga482c202016-02-18 17:03:07 -0800225 hostTime = 0
226 caseResult = main.FALSE
227 resultFile.close()
228 # Compare the timestemps, and get the lowest one.
229 temp = 0;
230 # Get host event timestamps from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700231 for node in range ( 0, main.numCtrls ):
232 metricsResult = json.loads( main.CLIs[ node ].topologyEventsMetrics() )
233 metricsResult = metricsResult.get( main.hostTimestampKey ).get( "value" )
234 main.log.info( "ONOS topology event matrics timestemp: {}".format( str( metricsResult ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800235
236 if temp < metricsResult:
237 temp = metricsResult
238 metricsResult = temp
239
Devin Lim58046fa2017-07-05 16:55:00 -0700240 addingHostTime.append( float( metricsResult ) - tsharkResultTime )
241 main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime) ) )
YPZhanga482c202016-02-18 17:03:07 -0800242 # gethost to remove
243 gethost = main.ONOSrest1.hosts()
244 HosttoRemove = []
Devin Lim58046fa2017-07-05 16:55:00 -0700245 HosttoRemove.append( json.loads( gethost[ 1:len( gethost )-1 ] ).get( 'id' ) )
246 main.CLIs[0].removeHost( HosttoRemove )
YPZhanga482c202016-02-18 17:03:07 -0800247
Devin Lim58046fa2017-07-05 16:55:00 -0700248 main.log.info( "Result List: {}".format( addingHostTime ) )
YPZhang82ca5892016-03-01 15:32:09 -0800249
YPZhanga482c202016-02-18 17:03:07 -0800250 # calculate average latency from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700251 averageResult = numpy.average( addingHostTime )
252 main.log.info( "Average Latency: {}".format( averageResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800253
254 # calculate std
255 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800256 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800257
258 # write to DB file
259 main.log.info("Writing results to DS file")
260 with open(main.dbFileName, "a") as dbFile:
261 # Scale number
262 temp = str(main.numCtrls)
263 temp += ",'" + "baremetal1" + "'"
264 # average latency
265 temp += "," + str( averageResult )
266 # std of latency
267 temp += "," + str(stdResult)
268 temp += "\n"
269 dbFile.write( temp )
270
271 assertion = main.TRUE
272
273 utilities.assert_equals(expect=main.TRUE, actual=assertion,
274 onpass='Host latency test successful',
275 onfail='Host latency test failed')
276
Devin Lim58046fa2017-07-05 16:55:00 -0700277 main.Utils.mininetCleanup( main.Mininet1 )