blob: 4298c3d97222aa64ccbe3cae26d5996666c36771 [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
Devin Lim142b5342017-07-20 15:22:39 -070036 def CASE0( self, main ):
YPZhanga482c202016-02-18 17:03:07 -080037 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" )
Devin Lim44075962017-08-11 10:56:37 -070047 main.cleanAndExit()
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
Devin Lim87e12c42017-07-20 13:53:04 -070079 main.nic = main.params[ 'DATABASE' ][ 'nic' ]
Devin Lim58046fa2017-07-05 16:55:00 -070080 node = main.params[ 'DATABASE' ][ 'node' ]
81 stepResult = main.TRUE
82
83 main.log.info( "Cresting DB file" )
84 with open( main.dbFileName, "w+" ) as dbFile:
85 dbFile.write( "" )
Devin Lim142b5342017-07-20 15:22:39 -070086 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070087 except Exception as e:
88 main.testSetUp.envSetupException( e )
89 main.testSetUp.evnSetupConclusion( stepResult )
90
91 main.commit = main.commit.split( " " )[ 1 ]
92
YPZhanga482c202016-02-18 17:03:07 -080093 def CASE2( self, main ):
94 """
95 - Uninstall ONOS cluster
96 - Verify ONOS start up
97 - Install ONOS cluster
98 - Connect to cli
99 """
Devin Lim142b5342017-07-20 15:22:39 -0700100 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster, True,
101 cellName=main.cellName, killRemoveMax=False )
YPZhanga482c202016-02-18 17:03:07 -0800102
103 def CASE11( self, main ):
104 main.log.info( "set and configure Application" )
105 import json
106 import time
Devin Lim142b5342017-07-20 15:22:39 -0700107 time.sleep( main.startUpSleep )
YPZhanga482c202016-02-18 17:03:07 -0800108 main.step( "Activating org.onosproject.proxyarp" )
Devin Lim142b5342017-07-20 15:22:39 -0700109 appStatus = utilities.retry( main.Cluster.active( 0 ).REST.activateApp,
YPZhanga482c202016-02-18 17:03:07 -0800110 main.FALSE,
Devin Lim58046fa2017-07-05 16:55:00 -0700111 [ 'org.onosproject.proxyarp' ],
YPZhanga482c202016-02-18 17:03:07 -0800112 sleep=3,
113 attempts=3 )
114 utilities.assert_equals( expect=main.TRUE,
115 actual=appStatus,
116 onpass="Successfully activated proxyarp",
Devin Lim142b5342017-07-20 15:22:39 -0700117 onfail="Failed to activated proxyarp" )
YPZhanga482c202016-02-18 17:03:07 -0800118
119 main.step( "Set up Default Topology Provider" )
120 appStatus = main.TRUE
121 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
122 configParam = 'maxEvents'
Devin Lim142b5342017-07-20 15:22:39 -0700123 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '1' )
YPZhanga482c202016-02-18 17:03:07 -0800124 configParam = 'maxBatchMs'
Devin Lim142b5342017-07-20 15:22:39 -0700125 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '0' )
YPZhanga482c202016-02-18 17:03:07 -0800126 configParam = 'maxIdleMs'
Devin Lim142b5342017-07-20 15:22:39 -0700127 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '0' )
YPZhanga482c202016-02-18 17:03:07 -0800128 utilities.assert_equals( expect=main.TRUE,
129 actual=appStatus,
130 onpass="Successfully set DefaultTopologyProvider",
131 onfail="Failed to set DefaultTopologyProvider" )
132
Devin Lim142b5342017-07-20 15:22:39 -0700133 time.sleep( main.startUpSleep )
134 main.step( 'Starting mininet topology' )
135 mnStatus = main.Mininet1.startNet( args='--topo=linear,1' )
YPZhanga482c202016-02-18 17:03:07 -0800136 utilities.assert_equals( expect=main.TRUE,
137 actual=mnStatus,
138 onpass="Successfully started Mininet",
139 onfail="Failed to activate Mininet" )
Devin Lim142b5342017-07-20 15:22:39 -0700140 main.step( "Assinging masters to switches" )
YPZhanga482c202016-02-18 17:03:07 -0800141 switches = main.Mininet1.getSwitches()
Devin Lim142b5342017-07-20 15:22:39 -0700142 swStatus = main.Mininet1.assignSwController( sw=switches.keys(),
143 ip=main.Cluster.active( 0 ).ipAddress )
YPZhanga482c202016-02-18 17:03:07 -0800144 utilities.assert_equals( expect=main.TRUE,
145 actual=swStatus,
146 onpass="Successfully assigned switches to masters",
147 onfail="Failed assign switches to masters" )
148
Devin Lim142b5342017-07-20 15:22:39 -0700149 time.sleep( main.startUpSleep )
YPZhanga482c202016-02-18 17:03:07 -0800150
Devin Lim142b5342017-07-20 15:22:39 -0700151 def CASE20( self, main ):
YPZhanga482c202016-02-18 17:03:07 -0800152 """
153 host1 send arping package and measure latency
154
155 There are only 1 levels of latency measurements to this test:
156 1 ) ARPING-to-device measurement: Measurement the time from host1
157 send apring package to onos processing the host event
158
159 """
160 import time
161 import subprocess
162 import json
163 import requests
164 import os
165 import numpy
Devin Lim58046fa2017-07-05 16:55:00 -0700166 try:
167 from tests.dependencies.utils import Utils
168 except ImportError:
169 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700170 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700171 try:
172 main.Utils
173 except ( NameError, AttributeError ):
174 main.Utils = Utils()
YPZhanga482c202016-02-18 17:03:07 -0800175 # Host adding measurement
176 assertion = main.TRUE
177
Devin Lim142b5342017-07-20 15:22:39 -0700178 main.log.report( 'Latency of adding one host to ONOS' )
179 main.log.report( 'First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time' )
180 main.log.report( 'Total iterations of test: ' + str( main.numlter ) )
YPZhanga482c202016-02-18 17:03:07 -0800181
182 addingHostTime = []
183 metricsResultList = []
Devin Lim58046fa2017-07-05 16:55:00 -0700184 for i in range( 0, int( main.numlter ) ):
185 main.log.info( 'Clean up data file' )
186 with open( main.tsharkResultPath, "w" ) as dbFile:
187 dbFile.write( "" )
YPZhanga482c202016-02-18 17:03:07 -0800188
Devin Lim142b5342017-07-20 15:22:39 -0700189 main.log.info( 'Starting tshark capture' )
Devin Lim58046fa2017-07-05 16:55:00 -0700190 main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath )
191 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800192
Devin Lim142b5342017-07-20 15:22:39 -0700193 main.log.info( 'host 1 arping...' )
194 main.Mininet1.arping( srcHost='h1', dstHost='10.0.0.2' )
YPZhanga482c202016-02-18 17:03:07 -0800195
Devin Lim58046fa2017-07-05 16:55:00 -0700196 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800197
Devin Lim142b5342017-07-20 15:22:39 -0700198 main.log.info( 'Stopping all Tshark processes' )
YPZhanga482c202016-02-18 17:03:07 -0800199 main.ONOSbench.tsharkStop()
200
Devin Lim58046fa2017-07-05 16:55:00 -0700201 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800202
203 # Get tshark output
Devin Lim58046fa2017-07-05 16:55:00 -0700204 with open( main.tsharkResultPath, "r" ) as resultFile:
YPZhanga482c202016-02-18 17:03:07 -0800205 resultText = resultFile.readline()
Devin Lim58046fa2017-07-05 16:55:00 -0700206 main.log.info( 'Capture result:' + resultText )
Devin Lim142b5342017-07-20 15:22:39 -0700207 resultText = resultText.split( ' ' )
Devin Lim58046fa2017-07-05 16:55:00 -0700208 if len( resultText ) > 1:
209 tsharkResultTime = float( resultText[ 1 ] ) * 1000.0
YPZhanga482c202016-02-18 17:03:07 -0800210 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700211 main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' )
YPZhanga482c202016-02-18 17:03:07 -0800212 hostTime = 0
213 caseResult = main.FALSE
214 resultFile.close()
215 # Compare the timestemps, and get the lowest one.
216 temp = 0;
217 # Get host event timestamps from each nodes
Devin Lim142b5342017-07-20 15:22:39 -0700218 for ctrl in main.Cluster.active():
219 metricsResult = json.loads( ctrl.CLI.topologyEventsMetrics() )
Devin Lim58046fa2017-07-05 16:55:00 -0700220 metricsResult = metricsResult.get( main.hostTimestampKey ).get( "value" )
221 main.log.info( "ONOS topology event matrics timestemp: {}".format( str( metricsResult ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800222
223 if temp < metricsResult:
224 temp = metricsResult
225 metricsResult = temp
226
Devin Lim58046fa2017-07-05 16:55:00 -0700227 addingHostTime.append( float( metricsResult ) - tsharkResultTime )
Devin Lim142b5342017-07-20 15:22:39 -0700228 main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800229 # gethost to remove
Devin Lim142b5342017-07-20 15:22:39 -0700230 gethost = main.Cluster.active( 0 ).REST.hosts()
YPZhanga482c202016-02-18 17:03:07 -0800231 HosttoRemove = []
Devin Lim58046fa2017-07-05 16:55:00 -0700232 HosttoRemove.append( json.loads( gethost[ 1:len( gethost )-1 ] ).get( 'id' ) )
Devin Lim142b5342017-07-20 15:22:39 -0700233 main.Cluster.active( 0 ).CLI.removeHost( HosttoRemove )
YPZhanga482c202016-02-18 17:03:07 -0800234
Devin Lim58046fa2017-07-05 16:55:00 -0700235 main.log.info( "Result List: {}".format( addingHostTime ) )
YPZhang82ca5892016-03-01 15:32:09 -0800236
YPZhanga482c202016-02-18 17:03:07 -0800237 # calculate average latency from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700238 averageResult = numpy.average( addingHostTime )
239 main.log.info( "Average Latency: {}".format( averageResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800240
241 # calculate std
Devin Lim142b5342017-07-20 15:22:39 -0700242 stdResult = numpy.std( addingHostTime )
243 main.log.info( "std: {}".format( stdResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800244
245 # write to DB file
Devin Lim142b5342017-07-20 15:22:39 -0700246 main.log.info( "Writing results to DS file" )
247 with open( main.dbFileName, "a" ) as dbFile:
Devin Lim87e12c42017-07-20 13:53:04 -0700248 temp = "'" + main.commit + "',"
249 temp += "'" + main.nic + "',"
YPZhanga482c202016-02-18 17:03:07 -0800250 # Scale number
Devin Lim142b5342017-07-20 15:22:39 -0700251 temp += str( main.Cluster.numCtrls )
YPZhanga482c202016-02-18 17:03:07 -0800252 temp += ",'" + "baremetal1" + "'"
253 # average latency
254 temp += "," + str( averageResult )
255 # std of latency
Devin Lim142b5342017-07-20 15:22:39 -0700256 temp += "," + str( stdResult )
YPZhanga482c202016-02-18 17:03:07 -0800257 temp += "\n"
258 dbFile.write( temp )
259
260 assertion = main.TRUE
261
Devin Lim142b5342017-07-20 15:22:39 -0700262 utilities.assert_equals( expect=main.TRUE, actual=assertion,
YPZhanga482c202016-02-18 17:03:07 -0800263 onpass='Host latency test successful',
Devin Lim142b5342017-07-20 15:22:39 -0700264 onfail='Host latency test failed' )
YPZhanga482c202016-02-18 17:03:07 -0800265
Devin Lim58046fa2017-07-05 16:55:00 -0700266 main.Utils.mininetCleanup( main.Mininet1 )