blob: 24e3c9f692913cfd6dacff90cae1163f2b7e0dab [file] [log] [blame]
andrewonlab79244cc2015-01-26 01:11:49 -05001# TopoPerfNext
andrewonlab2a6c9342014-10-16 13:40:15 -04002#
andrewonlab79244cc2015-01-26 01:11:49 -05003# Topology Performance test for ONOS-next
andrewonlab2a6c9342014-10-16 13:40:15 -04004#
andrewonlab79244cc2015-01-26 01:11:49 -05005# andrew@onlab.us
andrewonlab4f50ec92014-11-11 14:24:45 -05006#
andrewonlab79244cc2015-01-26 01:11:49 -05007# If your machine does not come with numpy
8# run the following command:
9# sudo apt-get install python-numpy python-scipy
andrewonlab2a6c9342014-10-16 13:40:15 -040010
11import time
12import sys
13import os
14import re
15
andrewonlab79244cc2015-01-26 01:11:49 -050016
andrewonlab2a6c9342014-10-16 13:40:15 -040017class TopoPerfNext:
andrewonlab79244cc2015-01-26 01:11:49 -050018
19 def __init__( self ):
andrewonlab2a6c9342014-10-16 13:40:15 -040020 self.default = ''
21
andrewonlab79244cc2015-01-26 01:11:49 -050022 def CASE1( self, main ):
23 """
andrewonlab2a6c9342014-10-16 13:40:15 -040024 ONOS startup sequence
andrewonlab79244cc2015-01-26 01:11:49 -050025 """
andrewonlabe9fb6722014-10-24 12:20:35 -040026 import time
andrewonlab79244cc2015-01-26 01:11:49 -050027
28 # Global cluster count for scale-out purposes
29 global clusterCount
30 # Set initial cluster count
31 clusterCount = 1
andrewonlaba57a3042015-01-23 13:53:05 -050032 ##
andrewonlab2a6c9342014-10-16 13:40:15 -040033
andrewonlab79244cc2015-01-26 01:11:49 -050034 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlab2a6c9342014-10-16 13:40:15 -040035
andrewonlab79244cc2015-01-26 01:11:49 -050036 gitPull = main.params[ 'GIT' ][ 'autoPull' ]
37 checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
kelvin-onlab8a832582015-01-16 17:06:11 -080038
andrewonlab79244cc2015-01-26 01:11:49 -050039 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
40 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
41 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
42 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
43 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
44 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
45 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
46
47 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
48 BENCHIp = main.params[ 'BENCH' ][ 'ip' ]
49
50 topoCfgFile = main.params[ 'TEST' ][ 'topoConfigFile' ]
51 topoCfgName = main.params[ 'TEST' ][ 'topoConfigName' ]
52
53 mvnCleanInstall = main.params[ 'TEST' ][ 'mci' ]
andrewonlaba57a3042015-01-23 13:53:05 -050054
andrewonlab79244cc2015-01-26 01:11:49 -050055 main.case( "Setting up test environment" )
56 main.log.info( "Copying topology event accumulator config" +
57 " to ONOS /package/etc" )
58 main.ONOSbench.handle.sendline( "cp ~/" +
59 topoCfgFile +
60 " ~/ONOS/tools/package/etc/" +
61 topoCfgName )
62 main.ONOSbench.handle.expect( "\$" )
andrewonlab6c8bbeb2014-11-14 12:43:48 -050063
andrewonlab79244cc2015-01-26 01:11:49 -050064 main.log.report( "Setting up test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlab5b954b02015-02-05 13:03:46 -050066 main.step( "Starting mininet topology " )
67 main.Mininet1.startNet()
68
andrewonlab79244cc2015-01-26 01:11:49 -050069 main.step( "Cleaning previously installed ONOS if any" )
70 main.ONOSbench.onosUninstall( nodeIp=ONOS2Ip )
71 main.ONOSbench.onosUninstall( nodeIp=ONOS3Ip )
72 main.ONOSbench.onosUninstall( nodeIp=ONOS4Ip )
73 main.ONOSbench.onosUninstall( nodeIp=ONOS5Ip )
74 main.ONOSbench.onosUninstall( nodeIp=ONOS6Ip )
andrewonlab67630692015-01-29 20:16:01 -050075 main.ONOSbench.onosUninstall( nodeIp=ONOS7Ip )
andrewonlab0e1825c2014-11-20 20:07:00 -050076
andrewonlab79244cc2015-01-26 01:11:49 -050077 main.step( "Creating cell file" )
78 cellFileResult = main.ONOSbench.createCellFile(
79 BENCHIp, cellName, MN1Ip,
80 "onos-core,onos-app-metrics,onos-app-gui",
81 ONOS1Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -040082
andrewonlab79244cc2015-01-26 01:11:49 -050083 main.step( "Applying cell file to environment" )
84 cellApplyResult = main.ONOSbench.setCell( cellName )
85 verifyCellResult = main.ONOSbench.verifyCell()
andrewonlab6c8bbeb2014-11-14 12:43:48 -050086
andrewonlab79244cc2015-01-26 01:11:49 -050087 # NOTE: This step may be removed after proper
kelvin-onlab8a832582015-01-16 17:06:11 -080088 # copy cat log functionality
andrewonlab79244cc2015-01-26 01:11:49 -050089 main.step( "Removing raft/copy-cat logs from ONOS nodes" )
90 main.ONOSbench.onosRemoveRaftLogs()
91 time.sleep( 30 )
kelvin-onlab8a832582015-01-16 17:06:11 -080092
andrewonlab79244cc2015-01-26 01:11:49 -050093 main.step( "Git checkout and pull " + checkoutBranch )
94 if gitPull == 'on':
95 # checkoutResult = \
96 # main.ONOSbench.gitCheckout( checkoutBranch )
97 checkoutResult = main.TRUE
98 pullResult = main.ONOSbench.gitPull()
andrewonlab2a6c9342014-10-16 13:40:15 -040099 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500100 checkoutResult = main.TRUE
101 pullResult = main.TRUE
102 main.log.info( "Skipped git checkout and pull" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400103
andrewonlab79244cc2015-01-26 01:11:49 -0500104 main.log.report( "Commit information - " )
105 main.ONOSbench.getVersion( report=True )
andrewonlab92844342014-11-18 16:39:11 -0500106
andrewonlab79244cc2015-01-26 01:11:49 -0500107 main.step( "Using mvn clean & install" )
108 if mvnCleanInstall == 'on':
109 mvnResult = main.ONOSbench.cleanInstall()
110 elif mvnCleanInstall == 'off':
111 main.log.info("mci turned off by settings")
112 mvnResult = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -0400113
andrewonlab79244cc2015-01-26 01:11:49 -0500114 main.step( "Set cell for ONOS cli env" )
115 main.ONOS1cli.setCell( cellName )
116 # main.ONOS2cli.setCell( cellName )
117 # main.ONOS3cli.setCell( cellName )
andrewonlabb1998c52014-11-10 13:31:43 -0500118
andrewonlab79244cc2015-01-26 01:11:49 -0500119 main.step( "Creating ONOS package" )
120 packageResult = main.ONOSbench.onosPackage()
andrewonlab2a6c9342014-10-16 13:40:15 -0400121
andrewonlab79244cc2015-01-26 01:11:49 -0500122 main.step( "Installing ONOS package" )
123 install1Result = main.ONOSbench.onosInstall( node=ONOS1Ip )
124 #install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip )
125 #install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -0400126
andrewonlab79244cc2015-01-26 01:11:49 -0500127 time.sleep( 10 )
andrewonlabe9fb6722014-10-24 12:20:35 -0400128
andrewonlab79244cc2015-01-26 01:11:49 -0500129 main.step( "Start onos cli" )
130 cli1 = main.ONOS1cli.startOnosCli( ONOS1Ip )
131 #cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip )
132 #cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlabe9fb6722014-10-24 12:20:35 -0400133
andrewonlab79244cc2015-01-26 01:11:49 -0500134 utilities.assert_equals( expect=main.TRUE,
135 actual=cellFileResult and cellApplyResult and
136 verifyCellResult and checkoutResult and
137 pullResult and mvnResult and
138 install1Result, # and install2Result and
139 # install3Result,
140 onpass="Test Environment setup successful",
141 onfail="Failed to setup test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400142
andrewonlab79244cc2015-01-26 01:11:49 -0500143 def CASE2( self, main ):
144 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400145 Assign s1 to ONOS1 and measure latency
andrewonlab79244cc2015-01-26 01:11:49 -0500146
andrewonlab3a7c3c72014-10-24 17:21:03 -0400147 There are 4 levels of latency measurements to this test:
andrewonlab79244cc2015-01-26 01:11:49 -0500148 1 ) End-to-end measurement: Complete end-to-end measurement
149 from TCP ( SYN/ACK ) handshake to Graph change
150 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of
andrewonlab3a7c3c72014-10-24 17:21:03 -0400151 measurement from OFP Vendor message to Graph change
andrewonlab79244cc2015-01-26 01:11:49 -0500152 3 ) OFP-to-device measurement: 'ONOS processing without
andrewonlab3a7c3c72014-10-24 17:21:03 -0400153 graph change' snippet of measurement from OFP vendor
154 message to Device change timestamp
andrewonlab79244cc2015-01-26 01:11:49 -0500155 4 ) T0-to-device measurement: Measurement that includes
156 the switch handshake to devices timestamp without
157 the graph view change. ( TCP handshake -> Device
158 change )
159 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400160 import time
andrewonlabe6745342014-10-17 14:29:13 -0400161 import subprocess
162 import json
163 import requests
164 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500165 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500166 global clusterCount
andrewonlabba44bcf2014-10-16 16:54:41 -0400167
andrewonlab79244cc2015-01-26 01:11:49 -0500168 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
169 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
170 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
171 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
172 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
173 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
174 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlabe6745342014-10-17 14:29:13 -0400175
andrewonlab79244cc2015-01-26 01:11:49 -0500176 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab4b5c8b92014-11-10 16:04:33 -0500177
andrewonlab79244cc2015-01-26 01:11:49 -0500178 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab226024e2014-10-24 16:01:32 -0400179
andrewonlab79244cc2015-01-26 01:11:49 -0500180 # Number of iterations of case
181 numIter = main.params[ 'TEST' ][ 'numIter' ]
182 # Number of first 'x' iterations to ignore:
183 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500184
andrewonlab79244cc2015-01-26 01:11:49 -0500185 # Timestamp 'keys' for json metrics output.
186 # These are subject to change, hence moved into params
187 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
188 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500189
andrewonlab79244cc2015-01-26 01:11:49 -0500190 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
191 onosLog = main.params[ 'TEST' ][ 'onosLogFile' ]
kelvin-onlab8a832582015-01-16 17:06:11 -0800192
andrewonlab79244cc2015-01-26 01:11:49 -0500193 # Threshold for the test
194 thresholdStr = main.params[ 'TEST' ][ 'singleSwThreshold' ]
195 thresholdObj = thresholdStr.split( "," )
196 thresholdMin = int( thresholdObj[ 0 ] )
197 thresholdMax = int( thresholdObj[ 1 ] )
andrewonlab226024e2014-10-24 16:01:32 -0400198
andrewonlab79244cc2015-01-26 01:11:49 -0500199 # List of switch add latency collected from
200 # all iterations
201 latencyEndToEndList = []
202 latencyOfpToGraphList = []
203 latencyOfpToDeviceList = []
204 latencyT0ToDeviceList = []
205 latencyTcpToOfpList = []
andrewonlabba44bcf2014-10-16 16:54:41 -0400206
andrewonlab67630692015-01-29 20:16:01 -0500207 # Initialize 2d array for [node][iteration] storage
208 endToEndLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
209 ofpToGraphLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
210 # tcp-to-ofp measurements are same throughout each iteration
211 tcpToOfpLatIter = []
212
andrewonlab79244cc2015-01-26 01:11:49 -0500213 # Directory/file to store tshark results
214 tsharkOfOutput = "/tmp/tshark_of_topo.txt"
215 tsharkTcpOutput = "/tmp/tshark_tcp_topo.txt"
216
217 # String to grep in tshark output
218 tsharkTcpString = "TCP 74 " + defaultSwPort
219 tsharkOfString = "OFP 86 Vendor"
220
221 # Initialize assertion to TRUE
andrewonlabe6745342014-10-17 14:29:13 -0400222 assertion = main.TRUE
andrewonlabb1998c52014-11-10 13:31:43 -0500223
andrewonlab79244cc2015-01-26 01:11:49 -0500224 localTime = time.strftime( '%x %X' )
225 localTime = localTime.replace( "/", "" )
226 localTime = localTime.replace( " ", "_" )
227 localTime = localTime.replace( ":", "" )
228 if debugMode == 'on':
229 main.ONOS1.tsharkPcap( "eth0",
230 "/tmp/single_sw_lat_pcap_" + localTime )
andrewonlab58f7d702014-11-07 13:21:19 -0500231
andrewonlab79244cc2015-01-26 01:11:49 -0500232 main.log.info( "Debug mode is on" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400233
andrewonlab79244cc2015-01-26 01:11:49 -0500234 main.log.report( "Latency of adding one switch to controller" )
235 main.log.report( "First " + str( iterIgnore ) + " iterations ignored" +
236 " for jvm warmup time" )
237 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlabba44bcf2014-10-16 16:54:41 -0400238
andrewonlab79244cc2015-01-26 01:11:49 -0500239 for i in range( 0, int( numIter ) ):
240 main.log.info( "Starting tshark capture" )
241
242 #* TCP [ ACK, SYN ] is used as t0A, the
243 # very first "exchange" between ONOS and
andrewonlabba44bcf2014-10-16 16:54:41 -0400244 # the switch for end-to-end measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500245 #* OFP [ Stats Reply ] is used for t0B
andrewonlabba44bcf2014-10-16 16:54:41 -0400246 # the very last OFP message between ONOS
247 # and the switch for ONOS measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500248 main.ONOS1.tsharkGrep( tsharkTcpString,
249 tsharkTcpOutput )
250 main.ONOS1.tsharkGrep( tsharkOfString,
251 tsharkOfOutput )
andrewonlabba44bcf2014-10-16 16:54:41 -0400252
andrewonlab79244cc2015-01-26 01:11:49 -0500253 # Wait and ensure tshark is started and
254 # capturing
255 time.sleep( 10 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400256
andrewonlab79244cc2015-01-26 01:11:49 -0500257 main.log.info( "Assigning s1 to controller" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400258
andrewonlab79244cc2015-01-26 01:11:49 -0500259 main.Mininet1.assignSwController(
260 sw="1",
261 ip1=ONOS1Ip,
262 port1=defaultSwPort )
andrewonlabba44bcf2014-10-16 16:54:41 -0400263
andrewonlab79244cc2015-01-26 01:11:49 -0500264 # Wait and ensure switch is assigned
265 # before stopping tshark
266 time.sleep( 30 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400267
andrewonlab79244cc2015-01-26 01:11:49 -0500268 main.log.info( "Stopping all Tshark processes" )
269 main.ONOS1.stopTshark()
kelvin-onlab8a832582015-01-16 17:06:11 -0800270
andrewonlab79244cc2015-01-26 01:11:49 -0500271 # tshark output is saved in ONOS. Use subprocess
272 # to copy over files to TestON for parsing
273 main.log.info( "Copying over tshark files" )
274
275 # TCP CAPTURE ****
276 # Copy the tshark output from ONOS machine to
277 # TestON machine in tsharkTcpOutput directory>file
278 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
279 tsharkTcpOutput + " /tmp/" )
280 tcpFile = open( tsharkTcpOutput, 'r' )
281 tempText = tcpFile.readline()
282 tempText = tempText.split( " " )
283
284 main.log.info( "Object read in from TCP capture: " +
285 str( tempText ) )
286 if len( tempText ) > 1:
287 t0Tcp = float( tempText[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400288 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500289 main.log.error( "Tshark output file for TCP" +
290 " returned unexpected results" )
291 t0Tcp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400292 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500293
294 tcpFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400295 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400296
andrewonlab79244cc2015-01-26 01:11:49 -0500297 # OF CAPTURE ****
298 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
299 tsharkOfOutput + " /tmp/" )
300 ofFile = open( tsharkOfOutput, 'r' )
301
302 lineOfp = ""
303 # Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400304 while True:
andrewonlab79244cc2015-01-26 01:11:49 -0500305 tempText = ofFile.readline()
306 if tempText != '':
307 lineOfp = tempText
andrewonlabe6745342014-10-17 14:29:13 -0400308 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500309 break
310 obj = lineOfp.split( " " )
311
312 main.log.info( "Object read in from OFP capture: " +
313 str( lineOfp ) )
314
andrewonlab5b954b02015-02-05 13:03:46 -0500315 if len( obj ) > 1:
andrewonlab79244cc2015-01-26 01:11:49 -0500316 t0Ofp = float( obj[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400317 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500318 main.log.error( "Tshark output file for OFP" +
319 " returned unexpected results" )
320 t0Ofp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400321 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500322
323 ofFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400324 #****************
andrewonlab867212a2014-10-22 20:13:38 -0400325
andrewonlab79244cc2015-01-26 01:11:49 -0500326 jsonStr1 = main.ONOS1cli.topologyEventsMetrics()
327 # Initialize scale-out variables
328 jsonStr2 = ""
329 jsonStr3 = ""
330 jsonStr4 = ""
331 jsonStr5 = ""
332 jsonStr6 = ""
333 jsonStr7 = ""
andrewonlabe9fb6722014-10-24 12:20:35 -0400334
andrewonlab79244cc2015-01-26 01:11:49 -0500335 jsonObj1 = json.loads( jsonStr1 )
336 # Initialize scale-out variables
337 jsonObj2 = ""
338 jsonObj3 = ""
339 jsonObj4 = ""
340 jsonObj5 = ""
341 jsonObj6 = ""
342 jsonObj7 = ""
kelvin-onlab8a832582015-01-16 17:06:11 -0800343
andrewonlab79244cc2015-01-26 01:11:49 -0500344 # Obtain graph timestamp. This timestsamp captures
345 # the epoch time at which the topology graph was updated.
346 graphTimestamp1 = \
347 jsonObj1[ graphTimestamp ][ 'value' ]
348 # Obtain device timestamp. This timestamp captures
349 # the epoch time at which the device event happened
350 deviceTimestamp1 = \
351 jsonObj1[ deviceTimestamp ][ 'value' ]
352
353 # t0 to device processing latency
354 deltaDevice1 = int( deviceTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500355 # t0 to graph processing latency ( end-to-end )
356 deltaGraph1 = int( graphTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500357 # ofp to graph processing latency ( ONOS processing )
358 deltaOfpGraph1 = int( graphTimestamp1 ) - int( t0Ofp )
andrewonlab79244cc2015-01-26 01:11:49 -0500359 # ofp to device processing latency ( ONOS processing )
360 deltaOfpDevice1 = float( deviceTimestamp1 ) - float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500361 # tcp to ofp processing latency ( switch connection )
362 deltaTcpOfp1 = int(t0Ofp) - int(t0Tcp)
363
364 if deltaTcpOfp1 > thresholdMin and deltaTcpOfp1 < thresholdMax\
365 and i >= iterIgnore:
366 tcpToOfpLatIter.append(deltaTcpOfp1)
367 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
368 str(deltaTcpOfp1)+" ms")
369 else:
370 tcpToOfpLatIter.append(0)
371 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
372 str(deltaTcpOfp1)+" ms - ignored this iteration")
373
374 # Store initial measurements in data array
375 #This measurement is for node 1
376
377 if deltaGraph1 > thresholdMin and deltaGraph1 < thresholdMax\
378 and i >= iterIgnore:
379 endToEndLatNodeIter[0][i] = deltaGraph1
380 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
381 str(deltaGraph1)+" ms")
382 else:
383 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
384 str(deltaGraph1)+" ms - ignored this iteration")
385
386
387 if deltaOfpGraph1 > thresholdMin and deltaOfpGraph1 < thresholdMax\
388 and i >= iterIgnore:
389 ofpToGraphLatNodeIter[0][i] = deltaOfpGraph1
390
391 main.log.info("ONOS1 iter"+str(i)+" ofp-to-graph: "+
392 str(deltaOfpGraph1)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -0500393
394 # TODO: Create even cluster number events
395
396 # Include scale-out measurements when applicable
397 if clusterCount >= 3:
398 jsonStr2 = main.ONOS2cli.topologyEventsMetrics()
399 jsonStr3 = main.ONOS3cli.topologyEventsMetrics()
400 jsonObj2 = json.loads( jsonStr2 )
401 jsonObj3 = json.loads( jsonStr3 )
402 graphTimestamp2 = \
403 jsonObj2[ graphTimestamp ][ 'value' ]
404 graphTimestamp3 = \
405 jsonObj3[ graphTimestamp ][ 'value' ]
406 deviceTimestamp2 = \
407 jsonObj2[ deviceTimestamp ][ 'value' ]
408 deviceTimestamp3 = \
409 jsonObj3[ deviceTimestamp ][ 'value' ]
410 deltaDevice2 = int( deviceTimestamp2 ) - int( t0Tcp )
411 deltaDevice3 = int( deviceTimestamp3 ) - int( t0Tcp )
412 deltaGraph2 = int( graphTimestamp2 ) - int( t0Tcp )
413 deltaGraph3 = int( graphTimestamp3 ) - int( t0Tcp )
414 deltaOfpGraph2 = int( graphTimestamp2 ) - int( t0Ofp )
415 deltaOfpGraph3 = int( graphTimestamp3 ) - int( t0Ofp )
416 deltaOfpDevice2 = float( deviceTimestamp2 ) -\
417 float( t0Ofp )
418 deltaOfpDevice3 = float( deviceTimestamp3 ) -\
419 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500420
andrewonlab67630692015-01-29 20:16:01 -0500421 if deltaGraph2 > thresholdMin and\
422 deltaGraph2 < thresholdMax and i >= iterIgnore:
423 endToEndLatNodeIter[1][i] = deltaGraph2
424 main.log.info("ONOS2 iter"+str(i)+" end-to-end: "+
425 str(deltaGraph2)+" ms")
426
427 if deltaOfpGraph2 > thresholdMin and\
428 deltaOfpGraph2 < thresholdMax and i >= iterIgnore:
429 ofpToGraphLatNodeIter[1][i] = deltaOfpGraph2
430 main.log.info("ONOS2 iter"+str(i)+" ofp-to-graph: "+
431 str(deltaOfpGraph2)+" ms")
432
433 if deltaGraph3 > thresholdMin and\
434 deltaGraph3 < thresholdMax and i >= iterIgnore:
435 endToEndLatNodeIter[2][i] = deltaGraph3
436 main.log.info("ONOS3 iter"+str(i)+" end-to-end: "+
437 str(deltaGraph3)+" ms")
438
439 if deltaOfpGraph3 > thresholdMin and\
440 deltaOfpGraph3 < thresholdMax and i >= iterIgnore:
441 ofpToGraphLatNodeIter[2][i] = deltaOfpGraph3
442 main.log.info("ONOS3 iter"+str(i)+" ofp-to-graph: "+
443 str(deltaOfpGraph3)+" ms")
444
andrewonlab79244cc2015-01-26 01:11:49 -0500445 if clusterCount >= 5:
446 jsonStr4 = main.ONOS4cli.topologyEventsMetrics()
447 jsonStr5 = main.ONOS5cli.topologyEventsMetrics()
448 jsonObj4 = json.loads( jsonStr4 )
449 jsonObj5 = json.loads( jsonStr5 )
450 graphTimestamp4 = \
451 jsonObj4[ graphTimestamp ][ 'value' ]
452 graphTimestamp5 = \
453 jsonObj5[ graphTimestamp ][ 'value' ]
454 deviceTimestamp4 = \
455 jsonObj4[ deviceTimestamp ][ 'value' ]
456 deviceTimestamp5 = \
457 jsonObj5[ deviceTimestamp ][ 'value' ]
458 deltaDevice4 = int( deviceTimestamp4 ) - int( t0Tcp )
459 deltaDevice5 = int( deviceTimestamp5 ) - int( t0Tcp )
460 deltaGraph4 = int( graphTimestamp4 ) - int( t0Tcp )
461 deltaGraph5 = int( graphTimestamp5 ) - int( t0Tcp )
462 deltaOfpGraph4 = int( graphTimestamp4 ) - int( t0Ofp )
463 deltaOfpGraph5 = int( graphTimestamp5 ) - int( t0Ofp )
464 deltaOfpDevice4 = float( deviceTimestamp4 ) -\
465 float( t0Ofp )
466 deltaOfpDevice5 = float( deviceTimestamp5 ) -\
467 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500468
469 if deltaGraph4 > thresholdMin and\
470 deltaGraph4 < thresholdMax and i >= iterIgnore:
471 endToEndLatNodeIter[3][i] = deltaGraph4
472 main.log.info("ONOS4 iter"+str(i)+" end-to-end: "+
473 str(deltaGraph4)+" ms")
474
475 #TODO:
476 if deltaOfpGraph4 > thresholdMin and\
477 deltaOfpGraph4 < thresholdMax and i >= iterIgnore:
478 ofpToGraphLatNodeIter[3][i] = deltaOfpGraph4
479 main.log.info("ONOS4 iter"+str(i)+" ofp-to-graph: "+
480 str(deltaOfpGraph4)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500481
andrewonlab67630692015-01-29 20:16:01 -0500482 if deltaGraph5 > thresholdMin and\
483 deltaGraph5 < thresholdMax and i >= iterIgnore:
484 endToEndLatNodeIter[4][i] = deltaGraph5
485 main.log.info("ONOS5 iter"+str(i)+" end-to-end: "+
486 str(deltaGraph5)+" ms")
487
488 if deltaOfpGraph5 > thresholdMin and\
489 deltaOfpGraph5 < thresholdMax and i >= iterIgnore:
490 ofpToGraphLatNodeIter[4][i] = deltaOfpGraph5
491 main.log.info("ONOS5 iter"+str(i)+" ofp-to-graph: "+
492 str(deltaOfpGraph5)+" ms")
493
andrewonlab79244cc2015-01-26 01:11:49 -0500494 if clusterCount >= 7:
495 jsonStr6 = main.ONOS6cli.topologyEventsMetrics()
496 jsonStr7 = main.ONOS7cli.topologyEventsMetrics()
497 jsonObj6 = json.loads( jsonStr6 )
498 jsonObj7 = json.loads( jsonStr7 )
499 graphTimestamp6 = \
500 jsonObj6[ graphTimestamp ][ 'value' ]
501 graphTimestamp7 = \
502 jsonObj7[ graphTimestamp ][ 'value' ]
503 deviceTimestamp6 = \
504 jsonObj6[ deviceTimestamp ][ 'value' ]
505 deviceTimestamp7 = \
506 jsonObj7[ deviceTimestamp ][ 'value' ]
507 deltaDevice6 = int( deviceTimestamp6 ) - int( t0Tcp )
508 deltaDevice7 = int( deviceTimestamp7 ) - int( t0Tcp )
509 deltaGraph6 = int( graphTimestamp6 ) - int( t0Tcp )
510 deltaGraph7 = int( graphTimestamp7 ) - int( t0Tcp )
511 deltaOfpGraph6 = int( graphTimestamp6 ) - int( t0Ofp )
512 deltaOfpGraph7 = int( graphTimestamp7 ) - int( t0Ofp )
513 deltaOfpDevice6 = float( deviceTimestamp6 ) -\
514 float( t0Ofp )
515 deltaOfpDevice7 = float( deviceTimestamp7 ) -\
516 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500517
518 if deltaGraph6 > thresholdMin and\
519 deltaGraph6 < thresholdMax and i >= iterIgnore:
520 endToEndLatNodeIter[5][i] = deltaGraph6
521 main.log.info("ONOS6 iter"+str(i)+" end-to-end: "+
522 str(deltaGraph6)+" ms")
523
524 #TODO:
525 if deltaOfpGraph6 > thresholdMin and\
526 deltaOfpGraph6 < thresholdMax and i >= iterIgnore:
527 ofpToGraphLatNodeIter[5][i] = deltaOfpGraph6
528 main.log.info("ONOS6 iter"+str(i)+" ofp-to-graph: "+
529 str(deltaOfpGraph6)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500530
andrewonlab67630692015-01-29 20:16:01 -0500531 if deltaGraph7 > thresholdMin and\
532 deltaGraph7 < thresholdMax and i >= iterIgnore:
533 endToEndLatNodeIter[6][i] = deltaGraph7
534 main.log.info("ONOS7 iter"+str(i)+" end-to-end: "+
535 str(deltaGraph7)+" ms")
536
537 if deltaOfpGraph7 > thresholdMin and\
538 deltaOfpGraph7 < thresholdMax and i >= iterIgnore:
539 ofpToGraphLatNodeIter[6][i] = deltaOfpGraph7
540 main.log.info("ONOS7 iter"+str(i)+" ofp-to-graph: "+
541 str(deltaOfpGraph7)+" ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400542
andrewonlab79244cc2015-01-26 01:11:49 -0500543 main.step( "Remove switch from controller" )
544 main.Mininet1.deleteSwController( "s1" )
andrewonlabf47993a2014-10-24 17:56:01 -0400545
andrewonlab79244cc2015-01-26 01:11:49 -0500546 time.sleep( 5 )
547
548 # END of for loop iteration
549
andrewonlab67630692015-01-29 20:16:01 -0500550 #str( round( numpy.std( latencyT0ToDeviceList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400551
andrewonlab67630692015-01-29 20:16:01 -0500552 endToEndAvg = 0
553 ofpToGraphAvg = 0
554 endToEndList = []
555 ofpToGraphList = []
andrewonlab69864162014-11-11 16:28:48 -0500556
andrewonlab67630692015-01-29 20:16:01 -0500557 for node in range( 0, clusterCount ):
558 # The latency 2d array was initialized to 0.
559 # If an iteration was ignored, then we have some 0's in
560 # our calculation. To avoid having this interfere with our
561 # results, we must delete any index where 0 is found...
562 # WARN: Potentially, we could have latency that hovers at
563 # 0 ms once we have optimized code. FIXME for when this is
564 # the case. Being able to obtain sub-millisecond accuracy
565 # can prevent this from happening
566 for item in endToEndLatNodeIter[node]:
567 if item > 0.0:
568 endToEndList.append(item)
569 for item in ofpToGraphLatNodeIter[node]:
570 if item > 0.0:
571 ofpToGraphList.append(item)
andrewonlabc15c9582014-10-24 16:35:52 -0400572
andrewonlab67630692015-01-29 20:16:01 -0500573 endToEndAvg = numpy.mean(endToEndList)
574 ofpToGraphAvg = numpy.mean(ofpToGraphList)
andrewonlabc15c9582014-10-24 16:35:52 -0400575
andrewonlab67630692015-01-29 20:16:01 -0500576 main.log.report( " - Node "+str(node+1)+" Summary - " )
577 main.log.report( " End-to-end Avg: "+
578 str(round(endToEndAvg,2))+" ms"+
579 " End-to-end Std dev: "+
580 str(round(numpy.std(endToEndList),2))+" ms")
andrewonlabd5367a42015-01-30 14:46:17 -0500581 #main.log.report( " Ofp-to-graph Avg: "+
582 # str(round(ofpToGraphAvg,2))+" ms"+
583 # " Ofp-to-graph Std dev: "+
584 # str(round(numpy.std(ofpToGraphList),2))+
585 # " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400586
andrewonlab79244cc2015-01-26 01:11:49 -0500587 if debugMode == 'on':
588 main.ONOS1.cpLogsToDir( "/opt/onos/log/karaf.log",
589 "/tmp/", copyFileName="sw_lat_karaf" )
andrewonlabb1998c52014-11-10 13:31:43 -0500590
andrewonlab67630692015-01-29 20:16:01 -0500591 #TODO: correct assert
592 assertion = main.TRUE
593
andrewonlab79244cc2015-01-26 01:11:49 -0500594 utilities.assert_equals( expect=main.TRUE, actual=assertion,
595 onpass="Switch latency test successful",
596 onfail="Switch latency test failed" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400597
andrewonlab79244cc2015-01-26 01:11:49 -0500598 def CASE3( self, main ):
599 """
andrewonlab8d29f122014-10-22 17:15:04 -0400600 Bring port up / down and measure latency.
601 Port enable / disable is simulated by ifconfig up / down
andrewonlab79244cc2015-01-26 01:11:49 -0500602
603 In ONOS-next, we must ensure that the port we are
andrewonlab393531a2014-10-27 18:36:26 -0400604 manipulating is connected to another switch with a valid
605 connection. Otherwise, graph view will not be updated.
andrewonlab79244cc2015-01-26 01:11:49 -0500606 """
andrewonlab8d29f122014-10-22 17:15:04 -0400607 import time
608 import subprocess
609 import os
610 import requests
611 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500612 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500613 global clusterCount
andrewonlab2a6c9342014-10-16 13:40:15 -0400614
andrewonlab79244cc2015-01-26 01:11:49 -0500615 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
616 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
617 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
618 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab8d29f122014-10-22 17:15:04 -0400619
andrewonlab79244cc2015-01-26 01:11:49 -0500620 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
621
andrewonlab8790abb2014-11-06 13:51:54 -0500622 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -0500623 # Number of iterations of case
624 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabd5367a42015-01-30 14:46:17 -0500625 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500626
andrewonlab79244cc2015-01-26 01:11:49 -0500627 # Timestamp 'keys' for json metrics output.
628 # These are subject to change, hence moved into params
629 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
630 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlab393531a2014-10-27 18:36:26 -0400631
andrewonlab79244cc2015-01-26 01:11:49 -0500632 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500633
andrewonlab79244cc2015-01-26 01:11:49 -0500634 localTime = time.strftime( '%x %X' )
635 localTime = localTime.replace( "/", "" )
636 localTime = localTime.replace( " ", "_" )
637 localTime = localTime.replace( ":", "" )
638 if debugMode == 'on':
639 main.ONOS1.tsharkPcap( "eth0",
640 "/tmp/port_lat_pcap_" + localTime )
andrewonlabe5bcef92014-11-06 17:53:20 -0500641
andrewonlab79244cc2015-01-26 01:11:49 -0500642 # Threshold for this test case
643 upThresholdStr = main.params[ 'TEST' ][ 'portUpThreshold' ]
644 downThresholdStr = main.params[ 'TEST' ][ 'portDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500645
andrewonlab79244cc2015-01-26 01:11:49 -0500646 upThresholdObj = upThresholdStr.split( "," )
647 downThresholdObj = downThresholdStr.split( "," )
648
649 upThresholdMin = int( upThresholdObj[ 0 ] )
650 upThresholdMax = int( upThresholdObj[ 1 ] )
651
652 downThresholdMin = int( downThresholdObj[ 0 ] )
653 downThresholdMax = int( downThresholdObj[ 1 ] )
654
655 # NOTE: Some hardcoded variables you may need to configure
andrewonlab393531a2014-10-27 18:36:26 -0400656 # besides the params
andrewonlab8d29f122014-10-22 17:15:04 -0400657
andrewonlab79244cc2015-01-26 01:11:49 -0500658 tsharkPortStatus = "OFP 130 Port Status"
andrewonlab8d29f122014-10-22 17:15:04 -0400659
andrewonlab79244cc2015-01-26 01:11:49 -0500660 tsharkPortUp = "/tmp/tshark_port_up.txt"
661 tsharkPortDown = "/tmp/tshark_port_down.txt"
662 interfaceConfig = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400663
andrewonlab79244cc2015-01-26 01:11:49 -0500664 main.log.report( "Port enable / disable latency" )
665 main.log.report( "Simulated by ifconfig up / down" )
666 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400667
andrewonlab79244cc2015-01-26 01:11:49 -0500668 main.step( "Assign switches s1 and s2 to controller 1" )
669 main.Mininet1.assignSwController( sw="1", ip1=ONOS1Ip,
670 port1=defaultSwPort )
671 main.Mininet1.assignSwController( sw="2", ip1=ONOS1Ip,
672 port1=defaultSwPort )
andrewonlab8d29f122014-10-22 17:15:04 -0400673
andrewonlab79244cc2015-01-26 01:11:49 -0500674 # Give enough time for metrics to propagate the
675 # assign controller event. Otherwise, these events may
676 # carry over to our measurements
677 time.sleep( 15 )
andrewonlab393531a2014-10-27 18:36:26 -0400678
andrewonlab79244cc2015-01-26 01:11:49 -0500679 portUpDeviceToOfpList = []
680 portUpGraphToOfpList = []
681 portDownDeviceToOfpList = []
682 portDownGraphToOfpList = []
andrewonlabd5367a42015-01-30 14:46:17 -0500683
684 # Initialize 2d array filled with 0's
685 # arraySizeFormat[clusterCount][numIter]
686 portUpDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
687 portUpGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
688 portDownDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
689 portDownGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
andrewonlab8d29f122014-10-22 17:15:04 -0400690
andrewonlab79244cc2015-01-26 01:11:49 -0500691 for i in range( 0, int( numIter ) ):
692 main.step( "Starting wireshark capture for port status down" )
693 main.ONOS1.tsharkGrep( tsharkPortStatus,
694 tsharkPortDown )
andrewonlab8d29f122014-10-22 17:15:04 -0400695
andrewonlab79244cc2015-01-26 01:11:49 -0500696 time.sleep( 5 )
697
698 # Disable interface that is connected to switch 2
699 main.step( "Disable port: " + interfaceConfig )
700 main.Mininet1.handle.sendline( "sh ifconfig " +
701 interfaceConfig + " down" )
702 main.Mininet1.handle.expect( "mininet>" )
703
704 time.sleep( 3 )
705 main.ONOS1.tsharkStop()
706
707 # Copy tshark output file from ONOS to TestON instance
kelvin-onlab8a832582015-01-16 17:06:11 -0800708 #/tmp directory
andrewonlab79244cc2015-01-26 01:11:49 -0500709 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
710 tsharkPortDown + " /tmp/" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800711
andrewonlab79244cc2015-01-26 01:11:49 -0500712 fPortDown = open( tsharkPortDown, 'r' )
713 # Get first line of port down event from tshark
714 fLine = fPortDown.readline()
715 objDown = fLine.split( " " )
716 if len( fLine ) > 0:
717 # NOTE: objDown[ 1 ] is a very unreliable
718 # way to determine the timestamp. If
719 # results seem way off, check the object
andrewonlaba57a3042015-01-23 13:53:05 -0500720 # itself by printing it out
andrewonlab79244cc2015-01-26 01:11:49 -0500721 timestampBeginPtDown = int( float( objDown[ 1 ] ) * 1000 )
722 # For some reason, wireshark decides to record the
andrewonlaba57a3042015-01-23 13:53:05 -0500723 # timestamp at the 3rd object position instead of
andrewonlab79244cc2015-01-26 01:11:49 -0500724 # 2nd at unpredictable times. This statement is
andrewonlaba57a3042015-01-23 13:53:05 -0500725 # used to capture that odd behavior and use the
726 # correct epoch time
andrewonlab79244cc2015-01-26 01:11:49 -0500727 if timestampBeginPtDown < 1400000000000:
728 timestampBeginPtDown = \
729 int( float( objDown[ 2 ] ) * 1000 )
andrewonlaba57a3042015-01-23 13:53:05 -0500730
andrewonlab79244cc2015-01-26 01:11:49 -0500731 main.log.info( "Port down begin timestamp: " +
732 str( timestampBeginPtDown ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400733 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500734 main.log.info( "Tshark output file returned unexpected" +
735 " results: " + str( objDown ) )
736 timestampBeginPtDown = 0
737 fPortDown.close()
738
739 main.step( "Obtain t1 by metrics call" )
740 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
741 jsonObj1 = json.loads( jsonStrUp1 )
742 # Obtain graph timestamp. This timestsamp captures
743 # the epoch time at which the topology graph was updated.
744 graphTimestamp1 = \
745 jsonObj1[ graphTimestamp ][ 'value' ]
746 # Obtain device timestamp. This timestamp captures
747 # the epoch time at which the device event happened
748 deviceTimestamp1 = \
749 jsonObj1[ deviceTimestamp ][ 'value' ]
750 # Get delta between graph event and OFP
751 ptDownGraphToOfp1 = int( graphTimestamp1 ) -\
752 int( timestampBeginPtDown )
753 # Get delta between device event and OFP
754 ptDownDeviceToOfp1 = int( deviceTimestamp1 ) -\
755 int( timestampBeginPtDown )
756
andrewonlabd5367a42015-01-30 14:46:17 -0500757 if ptDownGraphToOfp1 > downThresholdMin and\
758 ptDownGraphToOfp1 < downThresholdMax and i > iterIgnore:
759 portDownGraphNodeIter[0][i] = ptDownGraphToOfp1
760 main.log.info("iter"+str(i)+" port down graph-to-ofp: "+
761 str(ptDownGraphToOfp1)+" ms")
762 else:
763 main.log.info("iter"+str(i)+" skipped. Result: "+
764 str(ptDownGraphToOfp1)+" ms")
765 if ptDownDeviceToOfp1 > downThresholdMin and\
766 ptDownDeviceToOfp1 < downThresholdMax and i > iterIgnore:
767 portDownDevNodeIter[0][i] = ptDownDeviceToOfp1
768 main.log.info("iter"+str(i)+" port down device-to-ofp: "+
769 str(ptDownDeviceToOfp1)+" ms")
770 else:
771 main.log.info("iter"+str(i)+" skipped. Result: "+
772 str(ptDownDeviceToOfp1)+" ms")
773
andrewonlab79244cc2015-01-26 01:11:49 -0500774 if clusterCount >= 3:
775 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
776 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
777 jsonObj2 = json.loads( jsonStrUp2 )
778 jsonObj3 = json.loads( jsonStrUp3 )
779 graphTimestamp2 = \
780 jsonObj2[ graphTimestamp ][ 'value' ]
781 graphTimestamp3 = \
782 jsonObj3[ graphTimestamp ][ 'value' ]
783 deviceTimestamp2 = \
784 jsonObj2[ deviceTimestamp ][ 'value' ]
785 deviceTimestamp3 = \
786 jsonObj3[ deviceTimestamp ][ 'value' ]
787 ptDownGraphToOfp2 = int( graphTimestamp2 ) -\
788 int( timestampBeginPtDown )
789 ptDownGraphToOfp3 = int( graphTimestamp3 ) -\
790 int( timestampBeginPtDown )
791 ptDownDeviceToOfp2 = int( deviceTimestamp2 ) -\
792 int( timestampBeginPtDown )
793 ptDownDeviceToOfp3 = int( deviceTimestamp3 ) -\
794 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500795
796 if ptDownGraphToOfp2 > downThresholdMin and\
797 ptDownGraphToOfp2 < downThresholdMax and i > iterIgnore:
798 portDownGraphNodeIter[1][i] = ptDownGraphToOfp2
799 main.log.info("ONOS2 iter"+str(i)+" graph-to-ofp: "+
800 str(ptDownGraphToOfp2)+" ms")
801
802 if ptDownDeviceToOfp2 > downThresholdMin and\
803 ptDownDeviceToOfp2 < downThresholdMax and i > iterIgnore:
804 portDownDevNodeIter[1][i] = ptDownDeviceToOfp2
805 main.log.info("ONOS2 iter"+str(i)+" device-to-ofp: "+
806 str(ptDownDeviceToOfp2)+" ms")
807
808 if ptDownGraphToOfp3 > downThresholdMin and\
809 ptDownGraphToOfp3 < downThresholdMax and i > iterIgnore:
810 portDownGraphNodeIter[2][i] = ptDownGraphToOfp3
811 main.log.info("ONOS3 iter"+str(i)+" graph-to-ofp: "+
812 str(ptDownGraphToOfp3)+" ms")
813
814 if ptDownDeviceToOfp3 > downThresholdMin and\
815 ptDownDeviceToOfp3 < downThresholdMax and i > iterIgnore:
816 portDownDevNodeIter[2][i] = ptDownDeviceToOfp3
817 main.log.info("ONOS3 iter"+str(i)+" device-to-ofp: "+
818 str(ptDownDeviceToOfp3)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400819
andrewonlab79244cc2015-01-26 01:11:49 -0500820 if clusterCount >= 5:
821 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
822 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
823 jsonObj4 = json.loads( jsonStrUp4 )
824 jsonObj5 = json.loads( jsonStrUp5 )
825 graphTimestamp4 = \
826 jsonObj4[ graphTimestamp ][ 'value' ]
827 graphTimestamp5 = \
828 jsonObj5[ graphTimestamp ][ 'value' ]
829 deviceTimestamp4 = \
830 jsonObj4[ deviceTimestamp ][ 'value' ]
831 deviceTimestamp5 = \
832 jsonObj5[ deviceTimestamp ][ 'value' ]
833 ptDownGraphToOfp4 = int( graphTimestamp4 ) -\
834 int( timestampBeginPtDown )
835 ptDownGraphToOfp5 = int( graphTimestamp5 ) -\
836 int( timestampBeginPtDown )
837 ptDownDeviceToOfp4 = int( deviceTimestamp4 ) -\
838 int( timestampBeginPtDown )
839 ptDownDeviceToOfp5 = int( deviceTimestamp5 ) -\
840 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500841
842 if ptDownGraphToOfp4 > downThresholdMin and\
843 ptDownGraphToOfp4 < downThresholdMax and i > iterIgnore:
844 portDownGraphNodeIter[3][i] = ptDownGraphToOfp4
845 main.log.info("ONOS4 iter"+str(i)+" graph-to-ofp: "+
846 str(ptDownGraphToOfp4)+" ms")
847
848 if ptDownDeviceToOfp4 > downThresholdMin and\
849 ptDownDeviceToOfp4 < downThresholdMax and i > iterIgnore:
850 portDownDevNodeIter[3][i] = ptDownDeviceToOfp4
851 main.log.info("ONOS4 iter"+str(i)+" device-to-ofp: "+
852 str(ptDownDeviceToOfp4)+" ms")
853
854 if ptDownGraphToOfp5 > downThresholdMin and\
855 ptDownGraphToOfp5 < downThresholdMax and i > iterIgnore:
856 portDownGraphNodeIter[4][i] = ptDownGraphToOfp5
857 main.log.info("ONOS5 iter"+str(i)+" graph-to-ofp: "+
858 str(ptDownGraphToOfp5)+" ms")
859
860 if ptDownDeviceToOfp5 > downThresholdMin and\
861 ptDownDeviceToOfp5 < downThresholdMax and i > iterIgnore:
862 portDownDevNodeIter[4][i] = ptDownDeviceToOfp5
863 main.log.info("ONOS5 iter"+str(i)+" device-to-ofp: "+
864 str(ptDownDeviceToOfp5)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400865
andrewonlab79244cc2015-01-26 01:11:49 -0500866 if clusterCount >= 7:
867 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
868 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
869 jsonObj6 = json.loads( jsonStrUp6 )
870 jsonObj7 = json.loads( jsonStrUp7 )
871 graphTimestamp6 = \
872 jsonObj6[ graphTimestamp ][ 'value' ]
873 graphTimestamp7 = \
874 jsonObj7[ graphTimestamp ][ 'value' ]
875 deviceTimestamp6 = \
876 jsonObj6[ deviceTimestamp ][ 'value' ]
877 deviceTimestamp7 = \
878 jsonObj7[ deviceTimestamp ][ 'value' ]
879 ptDownGraphToOfp6 = int( graphTimestamp6 ) -\
880 int( timestampBeginPtDown )
881 ptDownGraphToOfp7 = int( graphTimestamp7 ) -\
882 int( timestampBeginPtDown )
883 ptDownDeviceToOfp6 = int( deviceTimestamp6 ) -\
884 int( timestampBeginPtDown )
885 ptDownDeviceToOfp7 = int( deviceTimestamp7 ) -\
886 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500887
888 if ptDownGraphToOfp6 > downThresholdMin and\
889 ptDownGraphToOfp6 < downThresholdMax and i > iterIgnore:
890 portDownGraphNodeIter[5][i] = ptDownGraphToOfp6
891 main.log.info("ONOS6 iter"+str(i)+" graph-to-ofp: "+
892 str(ptDownGraphToOfp6)+" ms")
893
894 if ptDownDeviceToOfp6 > downThresholdMin and\
895 ptDownDeviceToOfp6 < downThresholdMax and i > iterIgnore:
896 portDownDevNodeIter[5][i] = ptDownDeviceToOfp6
897 main.log.info("ONOS6 iter"+str(i)+" device-to-ofp: "+
898 str(ptDownDeviceToOfp6)+" ms")
899
900 if ptDownGraphToOfp7 > downThresholdMin and\
901 ptDownGraphToOfp7 < downThresholdMax and i > iterIgnore:
902 portDownGraphNodeIter[6][i] = ptDownGraphToOfp7
903 main.log.info("ONOS7 iter"+str(i)+" graph-to-ofp: "+
904 str(ptDownGraphToOfp7)+" ms")
905
906 if ptDownDeviceToOfp7 > downThresholdMin and\
907 ptDownDeviceToOfp7 < downThresholdMax and i > iterIgnore:
908 portDownDevNodeIter[6][i] = ptDownDeviceToOfp7
909 main.log.info("ONOS7 iter"+str(i)+" device-to-ofp: "+
910 str(ptDownDeviceToOfp7)+" ms")
kelvin-onlab8a832582015-01-16 17:06:11 -0800911
andrewonlab79244cc2015-01-26 01:11:49 -0500912 time.sleep( 3 )
andrewonlaba57a3042015-01-23 13:53:05 -0500913
andrewonlab79244cc2015-01-26 01:11:49 -0500914 # Port up events
915 main.step( "Enable port and obtain timestamp" )
916 main.step( "Starting wireshark capture for port status up" )
917 main.ONOS1.tsharkGrep( tsharkPortStatus, tsharkPortUp )
918 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400919
andrewonlab79244cc2015-01-26 01:11:49 -0500920 main.Mininet1.handle.sendline( "sh ifconfig " +
921 interfaceConfig + " up" )
922 main.Mininet1.handle.expect( "mininet>" )
923
924 # Allow time for tshark to capture event
925 time.sleep( 5 )
926 main.ONOS1.tsharkStop()
927
928 time.sleep( 3 )
929 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
930 tsharkPortUp + " /tmp/" )
931 fPortUp = open( tsharkPortUp, 'r' )
932 fLine = fPortUp.readline()
933 objUp = fLine.split( " " )
934 if len( fLine ) > 0:
935 timestampBeginPtUp = int( float( objUp[ 1 ] ) * 1000 )
936 if timestampBeginPtUp < 1400000000000:
937 timestampBeginPtUp = \
938 int( float( objUp[ 2 ] ) * 1000 )
939 main.log.info( "Port up begin timestamp: " +
940 str( timestampBeginPtUp ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400941 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500942 main.log.info( "Tshark output file returned unexpected" +
943 " results." )
944 timestampBeginPtUp = 0
945 fPortUp.close()
andrewonlab393531a2014-10-27 18:36:26 -0400946
andrewonlab79244cc2015-01-26 01:11:49 -0500947 # Obtain metrics shortly afterwards
948 # This timestsamp captures
949 # the epoch time at which the topology graph was updated.
950 main.step( "Obtain t1 by REST call" )
951 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
952 jsonObj1 = json.loads( jsonStrUp1 )
953 graphTimestamp1 = \
954 jsonObj1[ graphTimestamp ][ 'value' ]
955 # Obtain device timestamp. This timestamp captures
956 # the epoch time at which the device event happened
957 deviceTimestamp1 = \
958 jsonObj1[ deviceTimestamp ][ 'value' ]
959 # Get delta between graph event and OFP
960 ptUpGraphToOfp1 = int( graphTimestamp1 ) -\
961 int( timestampBeginPtUp )
962 # Get delta between device event and OFP
963 ptUpDeviceToOfp1 = int( deviceTimestamp1 ) -\
964 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -0500965
966 if ptUpGraphToOfp1 > upThresholdMin and\
967 ptUpGraphToOfp1 < upThresholdMax and i > iterIgnore:
968 portUpGraphNodeIter[0][i] = ptUpGraphToOfp1
969 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
970 str(ptUpGraphToOfp1)+" ms")
971 else:
972 main.log.info("iter"+str(i)+" skipped. Result: "+
973 str(ptUpGraphToOfp1)+" ms")
974
975 if ptUpDeviceToOfp1 > upThresholdMin and\
976 ptUpDeviceToOfp1 < upThresholdMax and i > iterIgnore:
977 portUpDevNodeIter[0][i] = ptUpDeviceToOfp1
978 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
979 str(ptUpDeviceToOfp1)+" ms")
980 else:
981 main.log.info("iter"+str(i)+" skipped. Result: "+
982 str(ptUpDeviceToOfp1)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400983
andrewonlab79244cc2015-01-26 01:11:49 -0500984 if clusterCount >= 3:
985 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
986 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
987 jsonObj2 = json.loads( jsonStrUp2 )
988 jsonObj3 = json.loads( jsonStrUp3 )
989 graphTimestamp2 = \
990 jsonObj2[ graphTimestamp ][ 'value' ]
991 graphTimestamp3 = \
992 jsonObj3[ graphTimestamp ][ 'value' ]
993 deviceTimestamp2 = \
994 jsonObj2[ deviceTimestamp ][ 'value' ]
995 deviceTimestamp3 = \
996 jsonObj3[ deviceTimestamp ][ 'value' ]
997 ptUpGraphToOfp2 = int( graphTimestamp2 ) -\
998 int( timestampBeginPtUp )
999 ptUpGraphToOfp3 = int( graphTimestamp3 ) -\
1000 int( timestampBeginPtUp )
1001 ptUpDeviceToOfp2 = int( deviceTimestamp2 ) -\
1002 int( timestampBeginPtUp )
1003 ptUpDeviceToOfp3 = int( deviceTimestamp3 ) -\
1004 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001005
1006 if ptUpGraphToOfp2 > upThresholdMin and\
1007 ptUpGraphToOfp2 < upThresholdMax and i > iterIgnore:
1008 portUpGraphNodeIter[1][i] = ptUpGraphToOfp2
1009 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1010 str(ptUpGraphToOfp2)+" ms")
1011
1012 if ptUpDeviceToOfp2 > upThresholdMin and\
1013 ptUpDeviceToOfp2 < upThresholdMax and i > iterIgnore:
1014 portUpDevNodeIter[1][i] = ptUpDeviceToOfp2
1015 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1016 str(ptUpDeviceToOfp2)+" ms")
1017
1018 if ptUpGraphToOfp3 > upThresholdMin and\
1019 ptUpGraphToOfp3 < upThresholdMax and i > iterIgnore:
1020 portUpGraphNodeIter[2][i] = ptUpGraphToOfp3
1021 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1022 str(ptUpGraphToOfp3)+" ms")
1023
1024 if ptUpDeviceToOfp3 > upThresholdMin and\
1025 ptUpDeviceToOfp3 < upThresholdMax and i > iterIgnore:
1026 portUpDevNodeIter[2][i] = ptUpDeviceToOfp3
1027 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1028 str(ptUpDeviceToOfp3)+" ms")
andrewonlabb1998c52014-11-10 13:31:43 -05001029
andrewonlab79244cc2015-01-26 01:11:49 -05001030 if clusterCount >= 5:
1031 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
1032 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
1033 jsonObj4 = json.loads( jsonStrUp4 )
1034 jsonObj5 = json.loads( jsonStrUp5 )
1035 graphTimestamp4 = \
1036 jsonObj4[ graphTimestamp ][ 'value' ]
1037 graphTimestamp5 = \
1038 jsonObj5[ graphTimestamp ][ 'value' ]
1039 deviceTimestamp4 = \
1040 jsonObj4[ deviceTimestamp ][ 'value' ]
1041 deviceTimestamp5 = \
1042 jsonObj5[ deviceTimestamp ][ 'value' ]
1043 ptUpGraphToOfp4 = int( graphTimestamp4 ) -\
1044 int( timestampBeginPtUp )
1045 ptUpGraphToOfp5 = int( graphTimestamp5 ) -\
1046 int( timestampBeginPtUp )
1047 ptUpDeviceToOfp4 = int( deviceTimestamp4 ) -\
1048 int( timestampBeginPtUp )
1049 ptUpDeviceToOfp5 = int( deviceTimestamp5 ) -\
1050 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001051
1052 if ptUpGraphToOfp4 > upThresholdMin and\
1053 ptUpGraphToOfp4 < upThresholdMax and i > iterIgnore:
1054 portUpGraphNodeIter[3][i] = ptUpGraphToOfp4
1055 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1056 str(ptUpGraphToOfp4)+" ms")
1057
1058 if ptUpDeviceToOfp4 > upThresholdMin and\
1059 ptUpDeviceToOfp4 < upThresholdMax and i > iterIgnore:
1060 portUpDevNodeIter[3][i] = ptUpDeviceToOfp4
1061 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1062 str(ptUpDeviceToOfp4)+" ms")
1063
1064 if ptUpGraphToOfp5 > upThresholdMin and\
1065 ptUpGraphToOfp5 < upThresholdMax and i > iterIgnore:
1066 portUpGraphNodeIter[4][i] = ptUpGraphToOfp5
1067 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1068 str(ptUpGraphToOfp5)+" ms")
1069
1070 if ptUpDeviceToOfp5 > upThresholdMin and\
1071 ptUpDeviceToOfp5 < upThresholdMax and i > iterIgnore:
1072 portUpDevNodeIter[4][i] = ptUpDeviceToOfp5
1073 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1074 str(ptUpDeviceToOfp5)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001075
1076 if clusterCount >= 7:
1077 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
1078 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
1079 jsonObj6 = json.loads( jsonStrUp6 )
1080 jsonObj7 = json.loads( jsonStrUp7 )
1081 graphTimestamp6 = \
1082 jsonObj6[ graphTimestamp ][ 'value' ]
1083 graphTimestamp7 = \
1084 jsonObj7[ graphTimestamp ][ 'value' ]
1085 deviceTimestamp6 = \
1086 jsonObj6[ deviceTimestamp ][ 'value' ]
1087 deviceTimestamp7 = \
1088 jsonObj7[ deviceTimestamp ][ 'value' ]
1089 ptUpGraphToOfp6 = int( graphTimestamp6 ) -\
1090 int( timestampBeginPtUp )
1091 ptUpGraphToOfp7 = int( graphTimestamp7 ) -\
1092 int( timestampBeginPtUp )
1093 ptUpDeviceToOfp6 = int( deviceTimestamp6 ) -\
1094 int( timestampBeginPtUp )
1095 ptUpDeviceToOfp7 = int( deviceTimestamp7 ) -\
1096 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001097
1098 if ptUpGraphToOfp6 > upThresholdMin and\
1099 ptUpGraphToOfp6 < upThresholdMax and i > iterIgnore:
1100 portUpGraphNodeIter[5][i] = ptUpGraphToOfp6
1101 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1102 str(ptUpGraphToOfp6)+" ms")
1103
1104 if ptUpDeviceToOfp6 > upThresholdMin and\
1105 ptUpDeviceToOfp6 < upThresholdMax and i > iterIgnore:
1106 portUpDevNodeIter[5][i] = ptUpDeviceToOfp6
1107 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1108 str(ptUpDeviceToOfp6)+" ms")
1109
1110 if ptUpGraphToOfp7 > upThresholdMin and\
1111 ptUpGraphToOfp7 < upThresholdMax and i > iterIgnore:
1112 portUpGraphNodeIter[6][i] = ptUpGraphToOfp7
1113 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1114 str(ptUpGraphToOfp7)+" ms")
1115
1116 if ptUpDeviceToOfp7 > upThresholdMin and\
1117 ptUpDeviceToOfp7 < upThresholdMax and i > iterIgnore:
1118 portUpDevNodeIter[6][i] = ptUpDeviceToOfp7
1119 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1120 str(ptUpDeviceToOfp7)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001121
1122 # END ITERATION FOR LOOP
andrewonlabd5367a42015-01-30 14:46:17 -05001123
1124 portUpDevList = []
1125 portUpGraphList = []
1126 portDownDevList = []
1127 portDownGraphList = []
andrewonlab79244cc2015-01-26 01:11:49 -05001128
andrewonlabd5367a42015-01-30 14:46:17 -05001129 portUpDevAvg = 0
1130 portUpGraphAvg = 0
1131 portDownDevAvg = 0
1132 portDownGraphAvg = 0
andrewonlab8790abb2014-11-06 13:51:54 -05001133
andrewonlabd5367a42015-01-30 14:46:17 -05001134 for node in range( 0, clusterCount ):
andrewonlababb11c32014-11-04 15:03:24 -05001135
andrewonlabd5367a42015-01-30 14:46:17 -05001136 # NOTE:
1137 # Currently the 2d array is initialized with 0's.
1138 # We want to avoid skewing our results if the array
1139 # was not modified with the correct latency.
1140 for item in portUpDevNodeIter[node]:
1141 if item > 0.0:
1142 portUpDevList.append(item)
1143 for item in portUpGraphNodeIter[node]:
1144 if item > 0.0:
1145 portUpGraphList.append(item)
1146 for item in portDownDevNodeIter[node]:
1147 if item > 0.0:
1148 portDownDevList.append(item)
1149 for item in portDownGraphNodeIter[node]:
1150 if item > 0.0:
1151 portDownGraphList.append(item)
1152
1153 portUpDevAvg = numpy.mean(portUpDevList)
1154 portUpGraphAvg = numpy.mean(portUpGraphList)
1155 portDownDevAvg = numpy.mean(portDownDevList)
1156 portDownGraphAvg = numpy.mean(portDownGraphList)
andrewonlab79244cc2015-01-26 01:11:49 -05001157
andrewonlabd5367a42015-01-30 14:46:17 -05001158 main.log.report( " - Node "+str(node+1)+" Summary - " )
1159 #main.log.report( " Port up ofp-to-device "+
1160 # str(round(portUpDevAvg, 2))+" ms")
1161 main.log.report( " Port up ofp-to-graph "+
1162 str(round(portUpGraphAvg, 2))+" ms")
1163 #main.log.report( " Port down ofp-to-device "+
1164 # str(round(portDownDevAvg, 2))+" ms")
1165 main.log.report( " Port down ofp-to-graph "+
1166 str(round(portDownGraphAvg, 2))+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001167
1168 # Remove switches from controller for next test
1169 main.Mininet1.deleteSwController( "s1" )
1170 main.Mininet1.deleteSwController( "s2" )
1171
andrewonlabd5367a42015-01-30 14:46:17 -05001172 #TODO: correct assertion
1173
andrewonlab79244cc2015-01-26 01:11:49 -05001174 utilities.assert_equals(
1175 expect=main.TRUE,
1176 actual=assertion,
1177 onpass="Port discovery latency calculation successful",
1178 onfail="Port discovery test failed" )
1179
1180 def CASE4( self, main ):
1181 """
andrewonlab3622beb2014-10-28 16:07:56 -04001182 Link down event using loss rate 100%
andrewonlab79244cc2015-01-26 01:11:49 -05001183
andrewonlab53b641c2014-10-31 19:44:44 -04001184 Important:
1185 Use a simple 2 switch topology with 1 link between
andrewonlab79244cc2015-01-26 01:11:49 -05001186 the two switches. Ensure that mac addresses of the
andrewonlab53b641c2014-10-31 19:44:44 -04001187 switches are 1 / 2 respectively
andrewonlab79244cc2015-01-26 01:11:49 -05001188 """
andrewonlab3622beb2014-10-28 16:07:56 -04001189 import time
1190 import subprocess
1191 import os
1192 import requests
1193 import json
andrewonlab79244cc2015-01-26 01:11:49 -05001194 import numpy
andrewonlab3622beb2014-10-28 16:07:56 -04001195
andrewonlab79244cc2015-01-26 01:11:49 -05001196 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1197 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1198 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1199 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001200
andrewonlab79244cc2015-01-26 01:11:49 -05001201 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001202
andrewonlab79244cc2015-01-26 01:11:49 -05001203 # Number of iterations of case
1204 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001205
andrewonlab79244cc2015-01-26 01:11:49 -05001206 # Timestamp 'keys' for json metrics output.
1207 # These are subject to change, hence moved into params
1208 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1209 linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ]
1210 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001211
andrewonlab79244cc2015-01-26 01:11:49 -05001212 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001213
andrewonlab79244cc2015-01-26 01:11:49 -05001214 localTime = time.strftime( '%x %X' )
1215 localTime = localTime.replace( "/", "" )
1216 localTime = localTime.replace( " ", "_" )
1217 localTime = localTime.replace( ":", "" )
1218 if debugMode == 'on':
1219 main.ONOS1.tsharkPcap( "eth0",
1220 "/tmp/link_lat_pcap_" + localTime )
1221
1222 # Threshold for this test case
1223 upThresholdStr = main.params[ 'TEST' ][ 'linkUpThreshold' ]
1224 downThresholdStr = main.params[ 'TEST' ][ 'linkDownThreshold' ]
1225
1226 upThresholdObj = upThresholdStr.split( "," )
1227 downThresholdObj = downThresholdStr.split( "," )
1228
1229 upThresholdMin = int( upThresholdObj[ 0 ] )
1230 upThresholdMax = int( upThresholdObj[ 1 ] )
1231
1232 downThresholdMin = int( downThresholdObj[ 0 ] )
1233 downThresholdMax = int( downThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001234
andrewonlab3622beb2014-10-28 16:07:56 -04001235 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -05001236 # Link event timestamp to system time list
1237 linkDownLinkToSystemList = []
1238 linkUpLinkToSystemList = []
1239 # Graph event timestamp to system time list
1240 linkDownGraphToSystemList = []
1241 linkUpGraphToSystemList = []
andrewonlab3622beb2014-10-28 16:07:56 -04001242
andrewonlab79244cc2015-01-26 01:11:49 -05001243 main.log.report( "Link up / down discovery latency between " +
1244 "two switches" )
1245 main.log.report( "Simulated by setting loss-rate 100%" )
1246 main.log.report( "'tc qdisc add dev <intfs> root netem loss 100%'" )
1247 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab3622beb2014-10-28 16:07:56 -04001248
andrewonlab79244cc2015-01-26 01:11:49 -05001249 main.step( "Assign all switches" )
1250 main.Mininet1.assignSwController( sw="1",
1251 ip1=ONOS1Ip, port1=defaultSwPort )
1252 main.Mininet1.assignSwController( sw="2",
1253 ip1=ONOS1Ip, port1=defaultSwPort )
andrewonlab3622beb2014-10-28 16:07:56 -04001254
andrewonlab79244cc2015-01-26 01:11:49 -05001255 main.step( "Verifying switch assignment" )
1256 resultS1 = main.Mininet1.getSwController( sw="s1" )
1257 resultS2 = main.Mininet1.getSwController( sw="s2" )
andrewonlab3622beb2014-10-28 16:07:56 -04001258
andrewonlab79244cc2015-01-26 01:11:49 -05001259 # Allow time for events to finish before taking measurements
1260 time.sleep( 10 )
1261
1262 linkDown1 = False
1263 linkDown2 = False
1264 linkDown3 = False
1265 # Start iteration of link event test
1266 for i in range( 0, int( numIter ) ):
1267 main.step( "Getting initial system time as t0" )
1268
1269 # System time in epoch ms
1270 timestampLinkDownT0 = time.time() * 1000
1271 # Link down is simulated by 100% loss rate using traffic
1272 # control command
kelvin-onlab8a832582015-01-16 17:06:11 -08001273 main.Mininet1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001274 "sh tc qdisc add dev s1-eth1 root netem loss 100%" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001275
andrewonlab79244cc2015-01-26 01:11:49 -05001276 # TODO: Iterate through 'links' command to verify that
1277 # link s1 -> s2 went down ( loop timeout 30 seconds )
andrewonlababb11c32014-11-04 15:03:24 -05001278 # on all 3 ONOS instances
andrewonlab79244cc2015-01-26 01:11:49 -05001279 main.log.info( "Checking ONOS for link update" )
1280 loopCount = 0
1281 while( not ( linkDown1 and linkDown2 and linkDown3 )
1282 and loopCount < 30 ):
1283 jsonStr1 = main.ONOS1cli.links()
1284 jsonStr2 = main.ONOS2cli.links()
1285 jsonStr3 = main.ONOS3cli.links()
1286
1287 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1288 main.log.error( "CLI command returned error " )
andrewonlab53b641c2014-10-31 19:44:44 -04001289 break
1290 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001291 jsonObj1 = json.loads( jsonStr1 )
1292 jsonObj2 = json.loads( jsonStr2 )
1293 jsonObj3 = json.loads( jsonStr3 )
1294 for obj1 in jsonObj1:
1295 if '01' not in obj1[ 'src' ][ 'device' ]:
1296 linkDown1 = True
1297 main.log.info( "Link down from " +
1298 "s1 -> s2 on ONOS1 detected" )
1299 for obj2 in jsonObj2:
1300 if '01' not in obj2[ 'src' ][ 'device' ]:
1301 linkDown2 = True
1302 main.log.info( "Link down from " +
1303 "s1 -> s2 on ONOS2 detected" )
1304 for obj3 in jsonObj3:
1305 if '01' not in obj3[ 'src' ][ 'device' ]:
1306 linkDown3 = True
1307 main.log.info( "Link down from " +
1308 "s1 -> s2 on ONOS3 detected" )
1309
1310 loopCount += 1
1311 # If CLI doesn't like the continuous requests
1312 # and exits in this loop, increase the sleep here.
1313 # Consequently, while loop timeout will increase
1314 time.sleep( 1 )
1315
1316 # Give time for metrics measurement to catch up
1317 # NOTE: May need to be configured more accurately
1318 time.sleep( 10 )
1319 # If we exited the while loop and link down 1,2,3 are still
1320 # false, then ONOS has failed to discover link down event
1321 if not ( linkDown1 and linkDown2 and linkDown3 ):
1322 main.log.info( "Link down discovery failed" )
1323
1324 linkDownLatGraph1 = 0
1325 linkDownLatGraph2 = 0
1326 linkDownLatGraph3 = 0
1327 linkDownLatDevice1 = 0
1328 linkDownLatDevice2 = 0
1329 linkDownLatDevice3 = 0
1330
andrewonlab53b641c2014-10-31 19:44:44 -04001331 assertion = main.FALSE
1332 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001333 jsonTopoMetrics1 =\
1334 main.ONOS1cli.topologyEventsMetrics()
1335 jsonTopoMetrics2 =\
1336 main.ONOS2cli.topologyEventsMetrics()
1337 jsonTopoMetrics3 =\
1338 main.ONOS3cli.topologyEventsMetrics()
1339 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1340 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1341 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlab53b641c2014-10-31 19:44:44 -04001342
andrewonlab79244cc2015-01-26 01:11:49 -05001343 main.log.info( "Obtaining graph and device timestamp" )
1344 graphTimestamp1 = \
1345 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1346 graphTimestamp2 = \
1347 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1348 graphTimestamp3 = \
1349 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001350
andrewonlab79244cc2015-01-26 01:11:49 -05001351 linkTimestamp1 = \
1352 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1353 linkTimestamp2 = \
1354 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1355 linkTimestamp3 = \
1356 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001357
andrewonlab79244cc2015-01-26 01:11:49 -05001358 if graphTimestamp1 and graphTimestamp2 and\
1359 graphTimestamp3 and linkTimestamp1 and\
1360 linkTimestamp2 and linkTimestamp3:
1361 linkDownLatGraph1 = int( graphTimestamp1 ) -\
1362 int( timestampLinkDownT0 )
1363 linkDownLatGraph2 = int( graphTimestamp2 ) -\
1364 int( timestampLinkDownT0 )
1365 linkDownLatGraph3 = int( graphTimestamp3 ) -\
1366 int( timestampLinkDownT0 )
1367
1368 linkDownLatLink1 = int( linkTimestamp1 ) -\
1369 int( timestampLinkDownT0 )
1370 linkDownLatLink2 = int( linkTimestamp2 ) -\
1371 int( timestampLinkDownT0 )
1372 linkDownLatLink3 = int( linkTimestamp3 ) -\
1373 int( timestampLinkDownT0 )
andrewonlab53b641c2014-10-31 19:44:44 -04001374 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001375 main.log.error( "There was an error calculating" +
1376 " the delta for link down event" )
1377 linkDownLatGraph1 = 0
1378 linkDownLatGraph2 = 0
1379 linkDownLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001380
andrewonlab79244cc2015-01-26 01:11:49 -05001381 linkDownLatDevice1 = 0
1382 linkDownLatDevice2 = 0
1383 linkDownLatDevice3 = 0
andrewonlab53b641c2014-10-31 19:44:44 -04001384
andrewonlab79244cc2015-01-26 01:11:49 -05001385 main.log.info( "Link down latency ONOS1 iteration " +
1386 str( i ) + " (end-to-end): " +
1387 str( linkDownLatGraph1 ) + " ms" )
1388 main.log.info( "Link down latency ONOS2 iteration " +
1389 str( i ) + " (end-to-end): " +
1390 str( linkDownLatGraph2 ) + " ms" )
1391 main.log.info( "Link down latency ONOS3 iteration " +
1392 str( i ) + " (end-to-end): " +
1393 str( linkDownLatGraph3 ) + " ms" )
1394
1395 main.log.info( "Link down latency ONOS1 iteration " +
1396 str( i ) + " (link-event-to-system-timestamp): " +
1397 str( linkDownLatLink1 ) + " ms" )
1398 main.log.info( "Link down latency ONOS2 iteration " +
1399 str( i ) + " (link-event-to-system-timestamp): " +
1400 str( linkDownLatLink2 ) + " ms" )
1401 main.log.info( "Link down latency ONOS3 iteration " +
1402 str( i ) + " (link-event-to-system-timestamp): " +
1403 str( linkDownLatLink3 ) )
1404
1405 # Calculate avg of node calculations
1406 linkDownLatGraphAvg =\
1407 ( linkDownLatGraph1 +
1408 linkDownLatGraph2 +
1409 linkDownLatGraph3 ) / 3
1410 linkDownLatLinkAvg =\
1411 ( linkDownLatLink1 +
1412 linkDownLatLink2 +
1413 linkDownLatLink3 ) / 3
1414
1415 # Set threshold and append latency to list
1416 if linkDownLatGraphAvg > downThresholdMin and\
1417 linkDownLatGraphAvg < downThresholdMax:
1418 linkDownGraphToSystemList.append(
1419 linkDownLatGraphAvg )
1420 else:
1421 main.log.info( "Link down latency exceeded threshold" )
1422 main.log.info( "Results for iteration " + str( i ) +
1423 "have been omitted" )
1424 if linkDownLatLinkAvg > downThresholdMin and\
1425 linkDownLatLinkAvg < downThresholdMax:
1426 linkDownLinkToSystemList.append(
1427 linkDownLatLinkAvg )
1428 else:
1429 main.log.info( "Link down latency exceeded threshold" )
1430 main.log.info( "Results for iteration " + str( i ) +
1431 "have been omitted" )
1432
1433 # NOTE: To remove loss rate and measure latency:
andrewonlab53b641c2014-10-31 19:44:44 -04001434 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlab79244cc2015-01-26 01:11:49 -05001435 timestampLinkUpT0 = time.time() * 1000
1436 main.Mininet1.handle.sendline( "sh tc qdisc del dev " +
1437 "s1-eth1 root" )
1438 main.Mininet1.handle.expect( "mininet>" )
1439
1440 main.log.info( "Checking ONOS for link update" )
1441
1442 linkDown1 = True
1443 linkDown2 = True
1444 linkDown3 = True
1445 loopCount = 0
1446 while( ( linkDown1 and linkDown2 and linkDown3 )
1447 and loopCount < 30 ):
1448 jsonStr1 = main.ONOS1cli.links()
1449 jsonStr2 = main.ONOS2cli.links()
1450 jsonStr3 = main.ONOS3cli.links()
1451 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1452 main.log.error( "CLI command returned error " )
andrewonlababb11c32014-11-04 15:03:24 -05001453 break
1454 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001455 jsonObj1 = json.loads( jsonStr1 )
1456 jsonObj2 = json.loads( jsonStr2 )
1457 jsonObj3 = json.loads( jsonStr3 )
1458
1459 for obj1 in jsonObj1:
1460 if '01' in obj1[ 'src' ][ 'device' ]:
1461 linkDown1 = False
1462 main.log.info( "Link up from " +
1463 "s1 -> s2 on ONOS1 detected" )
1464 for obj2 in jsonObj2:
1465 if '01' in obj2[ 'src' ][ 'device' ]:
1466 linkDown2 = False
1467 main.log.info( "Link up from " +
1468 "s1 -> s2 on ONOS2 detected" )
1469 for obj3 in jsonObj3:
1470 if '01' in obj3[ 'src' ][ 'device' ]:
1471 linkDown3 = False
1472 main.log.info( "Link up from " +
1473 "s1 -> s2 on ONOS3 detected" )
1474
1475 loopCount += 1
1476 time.sleep( 1 )
1477
1478 if ( linkDown1 and linkDown2 and linkDown3 ):
1479 main.log.info( "Link up discovery failed" )
1480
1481 linkUpLatGraph1 = 0
1482 linkUpLatGraph2 = 0
1483 linkUpLatGraph3 = 0
1484 linkUpLatDevice1 = 0
1485 linkUpLatDevice2 = 0
1486 linkUpLatDevice3 = 0
1487
andrewonlababb11c32014-11-04 15:03:24 -05001488 assertion = main.FALSE
1489 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001490 jsonTopoMetrics1 =\
1491 main.ONOS1cli.topologyEventsMetrics()
1492 jsonTopoMetrics2 =\
1493 main.ONOS2cli.topologyEventsMetrics()
1494 jsonTopoMetrics3 =\
1495 main.ONOS3cli.topologyEventsMetrics()
1496 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1497 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1498 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlababb11c32014-11-04 15:03:24 -05001499
andrewonlab79244cc2015-01-26 01:11:49 -05001500 main.log.info( "Obtaining graph and device timestamp" )
1501 graphTimestamp1 = \
1502 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1503 graphTimestamp2 = \
1504 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1505 graphTimestamp3 = \
1506 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001507
andrewonlab79244cc2015-01-26 01:11:49 -05001508 linkTimestamp1 = \
1509 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1510 linkTimestamp2 = \
1511 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1512 linkTimestamp3 = \
1513 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001514
andrewonlab79244cc2015-01-26 01:11:49 -05001515 if graphTimestamp1 and graphTimestamp2 and\
1516 graphTimestamp3 and linkTimestamp1 and\
1517 linkTimestamp2 and linkTimestamp3:
1518 linkUpLatGraph1 = int( graphTimestamp1 ) -\
1519 int( timestampLinkUpT0 )
1520 linkUpLatGraph2 = int( graphTimestamp2 ) -\
1521 int( timestampLinkUpT0 )
1522 linkUpLatGraph3 = int( graphTimestamp3 ) -\
1523 int( timestampLinkUpT0 )
1524
1525 linkUpLatLink1 = int( linkTimestamp1 ) -\
1526 int( timestampLinkUpT0 )
1527 linkUpLatLink2 = int( linkTimestamp2 ) -\
1528 int( timestampLinkUpT0 )
1529 linkUpLatLink3 = int( linkTimestamp3 ) -\
1530 int( timestampLinkUpT0 )
andrewonlababb11c32014-11-04 15:03:24 -05001531 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001532 main.log.error( "There was an error calculating" +
1533 " the delta for link down event" )
1534 linkUpLatGraph1 = 0
1535 linkUpLatGraph2 = 0
1536 linkUpLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001537
andrewonlab79244cc2015-01-26 01:11:49 -05001538 linkUpLatDevice1 = 0
1539 linkUpLatDevice2 = 0
1540 linkUpLatDevice3 = 0
1541
1542 if debugMode == 'on':
1543 main.log.info( "Link up latency ONOS1 iteration " +
1544 str( i ) + " (end-to-end): " +
1545 str( linkUpLatGraph1 ) + " ms" )
1546 main.log.info( "Link up latency ONOS2 iteration " +
1547 str( i ) + " (end-to-end): " +
1548 str( linkUpLatGraph2 ) + " ms" )
1549 main.log.info( "Link up latency ONOS3 iteration " +
1550 str( i ) + " (end-to-end): " +
1551 str( linkUpLatGraph3 ) + " ms" )
1552
1553 main.log.info(
1554 "Link up latency ONOS1 iteration " +
1555 str( i ) +
1556 " (link-event-to-system-timestamp): " +
1557 str( linkUpLatLink1 ) +
1558 " ms" )
1559 main.log.info(
1560 "Link up latency ONOS2 iteration " +
1561 str( i ) +
1562 " (link-event-to-system-timestamp): " +
1563 str( linkUpLatLink2 ) +
1564 " ms" )
1565 main.log.info(
1566 "Link up latency ONOS3 iteration " +
1567 str( i ) +
1568 " (link-event-to-system-timestamp): " +
1569 str( linkUpLatLink3 ) )
1570
1571 # Calculate avg of node calculations
1572 linkUpLatGraphAvg =\
1573 ( linkUpLatGraph1 +
1574 linkUpLatGraph2 +
1575 linkUpLatGraph3 ) / 3
1576 linkUpLatLinkAvg =\
1577 ( linkUpLatLink1 +
1578 linkUpLatLink2 +
1579 linkUpLatLink3 ) / 3
1580
1581 # Set threshold and append latency to list
1582 if linkUpLatGraphAvg > upThresholdMin and\
1583 linkUpLatGraphAvg < upThresholdMax:
1584 linkUpGraphToSystemList.append(
1585 linkUpLatGraphAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001586 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001587 main.log.info( "Link up latency exceeded threshold" )
1588 main.log.info( "Results for iteration " + str( i ) +
1589 "have been omitted" )
1590 if linkUpLatLinkAvg > upThresholdMin and\
1591 linkUpLatLinkAvg < upThresholdMax:
1592 linkUpLinkToSystemList.append(
1593 linkUpLatLinkAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001594 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001595 main.log.info( "Link up latency exceeded threshold" )
1596 main.log.info( "Results for iteration " + str( i ) +
1597 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001598
andrewonlab79244cc2015-01-26 01:11:49 -05001599 # Calculate min, max, avg of list and report
1600 linkDownMin = min( linkDownGraphToSystemList )
1601 linkDownMax = max( linkDownGraphToSystemList )
1602 linkDownAvg = sum( linkDownGraphToSystemList ) / \
1603 len( linkDownGraphToSystemList )
1604 linkUpMin = min( linkUpGraphToSystemList )
1605 linkUpMax = max( linkUpGraphToSystemList )
1606 linkUpAvg = sum( linkUpGraphToSystemList ) / \
1607 len( linkUpGraphToSystemList )
1608 linkDownStdDev = \
1609 str( round( numpy.std( linkDownGraphToSystemList ), 1 ) )
1610 linkUpStdDev = \
1611 str( round( numpy.std( linkUpGraphToSystemList ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001612
andrewonlab79244cc2015-01-26 01:11:49 -05001613 main.log.report( "Link down latency " +
1614 "Avg: " + str( linkDownAvg ) + " ms " +
1615 "Std Deviation: " + linkDownStdDev + " ms" )
1616 main.log.report( "Link up latency " +
1617 "Avg: " + str( linkUpAvg ) + " ms " +
1618 "Std Deviation: " + linkUpStdDev + " ms" )
andrewonlab4e124482014-11-04 13:37:25 -05001619
andrewonlab79244cc2015-01-26 01:11:49 -05001620 utilities.assert_equals(
1621 expect=main.TRUE,
1622 actual=assertion,
1623 onpass="Link discovery latency calculation successful",
1624 onfail="Link discovery latency case failed" )
andrewonlab8790abb2014-11-06 13:51:54 -05001625
andrewonlab79244cc2015-01-26 01:11:49 -05001626 def CASE5( self, main ):
1627 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001628 100 Switch discovery latency
1629
1630 Important:
andrewonlab79244cc2015-01-26 01:11:49 -05001631 This test case can be potentially dangerous if
andrewonlab16ce4852014-10-30 13:41:09 -04001632 your machine has previously set iptables rules.
1633 One of the steps of the test case will flush
1634 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001635 Note:
andrewonlab79244cc2015-01-26 01:11:49 -05001636 You can specify the number of switches in the
andrewonlab8790abb2014-11-06 13:51:54 -05001637 params file to adjust the switch discovery size
andrewonlab79244cc2015-01-26 01:11:49 -05001638 ( and specify the corresponding topology in Mininet1
1639 .topo file )
1640 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001641 import time
1642 import subprocess
1643 import os
1644 import requests
1645 import json
1646
andrewonlab79244cc2015-01-26 01:11:49 -05001647 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1648 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1649 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1650 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
1651 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlabb54b85b2014-10-28 18:43:57 -04001652
andrewonlab79244cc2015-01-26 01:11:49 -05001653 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001654
andrewonlab79244cc2015-01-26 01:11:49 -05001655 # Number of iterations of case
1656 numIter = main.params[ 'TEST' ][ 'numIter' ]
1657 numSw = main.params[ 'TEST' ][ 'numSwitch' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001658
andrewonlab79244cc2015-01-26 01:11:49 -05001659 # Timestamp 'keys' for json metrics output.
1660 # These are subject to change, hence moved into params
1661 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1662 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001663
andrewonlab79244cc2015-01-26 01:11:49 -05001664 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001665
andrewonlab79244cc2015-01-26 01:11:49 -05001666 localTime = time.strftime( '%X' )
1667 localTime = localTime.replace( "/", "" )
1668 localTime = localTime.replace( " ", "_" )
1669 localTime = localTime.replace( ":", "" )
1670 if debugMode == 'on':
1671 main.ONOS1.tsharkPcap( "eth0",
1672 "/tmp/100_sw_lat_pcap_" + localTime )
andrewonlabb54b85b2014-10-28 18:43:57 -04001673
andrewonlab79244cc2015-01-26 01:11:49 -05001674 # Threshold for this test case
1675 swDiscThresholdStr = main.params[ 'TEST' ][ 'swDisc100Threshold' ]
1676 swDiscThresholdObj = swDiscThresholdStr.split( "," )
1677 swDiscThresholdMin = int( swDiscThresholdObj[ 0 ] )
1678 swDiscThresholdMax = int( swDiscThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001679
andrewonlab79244cc2015-01-26 01:11:49 -05001680 tsharkOfpOutput = "/tmp/tshark_ofp_" + numSw + "sw.txt"
1681 tsharkTcpOutput = "/tmp/tshark_tcp_" + numSw + "sw.txt"
andrewonlabb54b85b2014-10-28 18:43:57 -04001682
andrewonlab79244cc2015-01-26 01:11:49 -05001683 tsharkOfpResultList = []
1684 tsharkTcpResultList = []
1685
1686 swDiscoveryLatList = []
1687
1688 main.case( numSw + " Switch discovery latency" )
1689 main.step( "Assigning all switches to ONOS1" )
1690 for i in range( 1, int( numSw ) + 1 ):
1691 main.Mininet1.assignSwController(
1692 sw=str( i ),
1693 ip1=ONOS1Ip,
1694 port1=defaultSwPort )
1695
1696 # Ensure that nodes are configured with ptpd
1697 # Just a warning message
1698 main.log.info( "Please check ptpd configuration to ensure" +
1699 " All nodes' system times are in sync" )
1700 time.sleep( 5 )
1701
1702 for i in range( 0, int( numIter ) ):
1703
1704 main.step( "Set iptables rule to block incoming sw connections" )
1705 # Set iptables rule to block incoming switch connections
1706 # The rule description is as follows:
andrewonlab53b641c2014-10-31 19:44:44 -04001707 # Append to INPUT rule,
1708 # behavior DROP that matches following:
1709 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001710 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001711 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001712 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001713 "sudo iptables -A INPUT -p tcp -s " + MN1Ip +
1714 " --dport " + defaultSwPort + " -j DROP" )
1715 main.ONOS1.handle.expect( "\$" )
1716 # Append to OUTPUT rule,
andrewonlab53b641c2014-10-31 19:44:44 -04001717 # behavior DROP that matches following:
1718 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001719 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001720 # * destination PORT: 6633
1721 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001722 "sudo iptables -A OUTPUT -p tcp -s " + MN1Ip +
1723 " --dport " + defaultSwPort + " -j DROP" )
1724 main.ONOS1.handle.expect( "\$" )
1725 # Give time to allow rule to take effect
1726 # NOTE: Sleep period may need to be configured
andrewonlab8790abb2014-11-06 13:51:54 -05001727 # based on the number of switches in the topology
andrewonlab79244cc2015-01-26 01:11:49 -05001728 main.log.info( "Please wait for switch connection to " +
1729 "time out" )
1730 time.sleep( 60 )
andrewonlabb54b85b2014-10-28 18:43:57 -04001731
andrewonlab79244cc2015-01-26 01:11:49 -05001732 # Gather vendor OFP with tshark
1733 main.ONOS1.tsharkGrep( "OFP 86 Vendor",
1734 tsharkOfpOutput )
1735 main.ONOS1.tsharkGrep( "TCP 74 ",
1736 tsharkTcpOutput )
1737
1738 # NOTE: Remove all iptables rule quickly ( flush )
1739 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001740 # removal took place
andrewonlab79244cc2015-01-26 01:11:49 -05001741 # ( ensuring nodes are configured via ptp )
andrewonlabb54b85b2014-10-28 18:43:57 -04001742 # sudo iptables -F
andrewonlab79244cc2015-01-26 01:11:49 -05001743
1744 t0System = time.time() * 1000
andrewonlab16ce4852014-10-30 13:41:09 -04001745 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001746 "sudo iptables -F" )
andrewonlabb54b85b2014-10-28 18:43:57 -04001747
andrewonlab79244cc2015-01-26 01:11:49 -05001748 # Counter to track loop count
1749 counterLoop = 0
1750 counterAvail1 = 0
1751 counterAvail2 = 0
1752 counterAvail3 = 0
1753 onos1Dev = False
1754 onos2Dev = False
1755 onos3Dev = False
1756 while counterLoop < 60:
1757 # Continue to check devices for all device
1758 # availability. When all devices in all 3
1759 # ONOS instances indicate that devices are available
1760 # obtain graph event timestamp for t1.
1761 deviceStrObj1 = main.ONOS1cli.devices()
1762 deviceStrObj2 = main.ONOS2cli.devices()
1763 deviceStrObj3 = main.ONOS3cli.devices()
andrewonlab16ce4852014-10-30 13:41:09 -04001764
andrewonlab79244cc2015-01-26 01:11:49 -05001765 deviceJson1 = json.loads( deviceStrObj1 )
1766 deviceJson2 = json.loads( deviceStrObj2 )
1767 deviceJson3 = json.loads( deviceStrObj3 )
1768
1769 for device1 in deviceJson1:
1770 if device1[ 'available' ]:
1771 counterAvail1 += 1
1772 if counterAvail1 == int( numSw ):
1773 onos1Dev = True
1774 main.log.info( "All devices have been " +
1775 "discovered on ONOS1" )
andrewonlab16ce4852014-10-30 13:41:09 -04001776 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001777 counterAvail1 = 0
1778 for device2 in deviceJson2:
1779 if device2[ 'available' ]:
1780 counterAvail2 += 1
1781 if counterAvail2 == int( numSw ):
1782 onos2Dev = True
1783 main.log.info( "All devices have been " +
1784 "discovered on ONOS2" )
andrewonlab16ce4852014-10-30 13:41:09 -04001785 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001786 counterAvail2 = 0
1787 for device3 in deviceJson3:
1788 if device3[ 'available' ]:
1789 counterAvail3 += 1
1790 if counterAvail3 == int( numSw ):
1791 onos3Dev = True
1792 main.log.info( "All devices have been " +
1793 "discovered on ONOS3" )
andrewonlab16ce4852014-10-30 13:41:09 -04001794 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001795 counterAvail3 = 0
andrewonlab16ce4852014-10-30 13:41:09 -04001796
andrewonlab79244cc2015-01-26 01:11:49 -05001797 if onos1Dev and onos2Dev and onos3Dev:
1798 main.log.info( "All devices have been discovered " +
1799 "on all ONOS instances" )
1800 jsonStrTopologyMetrics1 =\
1801 main.ONOS1cli.topologyEventsMetrics()
1802 jsonStrTopologyMetrics2 =\
1803 main.ONOS2cli.topologyEventsMetrics()
1804 jsonStrTopologyMetrics3 =\
1805 main.ONOS3cli.topologyEventsMetrics()
andrewonlab16ce4852014-10-30 13:41:09 -04001806
andrewonlab79244cc2015-01-26 01:11:49 -05001807 # Exit while loop if all devices discovered
1808 break
andrewonlab16ce4852014-10-30 13:41:09 -04001809
andrewonlab79244cc2015-01-26 01:11:49 -05001810 counterLoop += 1
1811 # Give some time in between CLI calls
1812 #( will not affect measurement )
1813 time.sleep( 3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001814
andrewonlab79244cc2015-01-26 01:11:49 -05001815 main.ONOS1.tsharkStop()
andrewonlab53b641c2014-10-31 19:44:44 -04001816
andrewonlab79244cc2015-01-26 01:11:49 -05001817 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1818 tsharkOfpOutput + " /tmp/" )
1819 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1820 tsharkTcpOutput + " /tmp/" )
andrewonlab16ce4852014-10-30 13:41:09 -04001821
andrewonlab79244cc2015-01-26 01:11:49 -05001822 # TODO: Automate OFP output analysis
1823 # Debug mode - print out packets captured at runtime
1824 if debugMode == 'on':
1825 ofpFile = open( tsharkOfpOutput, 'r' )
1826 main.log.info( "Tshark OFP Vendor output: " )
1827 for line in ofpFile:
1828 tsharkOfpResultList.append( line )
1829 main.log.info( line )
1830 ofpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001831
andrewonlab79244cc2015-01-26 01:11:49 -05001832 tcpFile = open( tsharkTcpOutput, 'r' )
1833 main.log.info( "Tshark TCP 74 output: " )
1834 for line in tcpFile:
1835 tsharkTcpResultList.append( line )
1836 main.log.info( line )
1837 tcpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001838
andrewonlab79244cc2015-01-26 01:11:49 -05001839 jsonObj1 = json.loads( jsonStrTopologyMetrics1 )
1840 jsonObj2 = json.loads( jsonStrTopologyMetrics2 )
1841 jsonObj3 = json.loads( jsonStrTopologyMetrics3 )
1842
1843 graphTimestamp1 = \
1844 jsonObj1[ graphTimestamp ][ 'value' ]
1845 graphTimestamp2 = \
1846 jsonObj2[ graphTimestamp ][ 'value' ]
1847 graphTimestamp3 = \
1848 jsonObj3[ graphTimestamp ][ 'value' ]
1849
1850 graphLat1 = int( graphTimestamp1 ) - int( t0System )
1851 graphLat2 = int( graphTimestamp2 ) - int( t0System )
1852 graphLat3 = int( graphTimestamp3 ) - int( t0System )
1853
1854 avgGraphLat = \
1855 ( int( graphLat1 ) +
1856 int( graphLat2 ) +
1857 int( graphLat3 ) ) / 3
1858
1859 if avgGraphLat > swDiscThresholdMin \
1860 and avgGraphLat < swDiscThresholdMax:
1861 swDiscoveryLatList.append(
1862 avgGraphLat )
andrewonlabe5bcef92014-11-06 17:53:20 -05001863 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001864 main.log.info( "100 Switch discovery latency " +
1865 "exceeded the threshold." )
andrewonlab16ce4852014-10-30 13:41:09 -04001866
andrewonlab79244cc2015-01-26 01:11:49 -05001867 # END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001868
andrewonlab79244cc2015-01-26 01:11:49 -05001869 swLatMin = min( swDiscoveryLatList )
1870 swLatMax = max( swDiscoveryLatList )
1871 swLatAvg = sum( swDiscoveryLatList ) /\
1872 len( swDiscoveryLatList )
andrewonlab16ce4852014-10-30 13:41:09 -04001873
andrewonlab79244cc2015-01-26 01:11:49 -05001874 main.log.report( "100 Switch discovery lat " +
1875 "Min: " + str( swLatMin ) + " ms" +
1876 "Max: " + str( swLatMax ) + " ms" +
1877 "Avg: " + str( swLatAvg ) + " ms" )
1878
1879 def CASE6( self, main ):
1880 """
andrewonlaba57a3042015-01-23 13:53:05 -05001881 Increase number of nodes and initiate CLI
andrewonlab79244cc2015-01-26 01:11:49 -05001882 """
andrewonlaba57a3042015-01-23 13:53:05 -05001883 import time
andrewonlaba57a3042015-01-23 13:53:05 -05001884
andrewonlab79244cc2015-01-26 01:11:49 -05001885 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1886 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1887 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1888 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
1889 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
1890 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
1891 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001892
andrewonlab79244cc2015-01-26 01:11:49 -05001893 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001894
andrewonlab79244cc2015-01-26 01:11:49 -05001895 global clusterCount
andrewonlaba57a3042015-01-23 13:53:05 -05001896
andrewonlab79244cc2015-01-26 01:11:49 -05001897 # Cluster size increased everytime the case is defined
1898 clusterCount += 2
andrewonlaba57a3042015-01-23 13:53:05 -05001899
andrewonlab79244cc2015-01-26 01:11:49 -05001900 main.log.report( "Increasing cluster size to " +
1901 str( clusterCount ) )
andrewonlaba57a3042015-01-23 13:53:05 -05001902
andrewonlab79244cc2015-01-26 01:11:49 -05001903 installResult = main.FALSE
1904 if clusterCount == 3:
1905 main.log.info( "Installing nodes 2 and 3" )
1906 node2Result = \
1907 main.ONOSbench.onosInstall( node=ONOS2Ip )
1908 node3Result = \
1909 main.ONOSbench.onosInstall( node=ONOS3Ip )
1910 installResult = node2Result and node3Result
andrewonlaba57a3042015-01-23 13:53:05 -05001911
andrewonlab79244cc2015-01-26 01:11:49 -05001912 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001913
andrewonlab79244cc2015-01-26 01:11:49 -05001914 main.ONOS2cli.startOnosCli( ONOS2Ip )
1915 main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001916
andrewonlab79244cc2015-01-26 01:11:49 -05001917 elif clusterCount == 5:
1918 main.log.info( "Installing nodes 4 and 5" )
1919 node4Result = \
1920 main.ONOSbench.onosInstall( node=ONOS4Ip )
1921 node5Result = \
1922 main.ONOSbench.onosInstall( node=ONOS5Ip )
1923 installResult = node4Result and node5Result
andrewonlaba57a3042015-01-23 13:53:05 -05001924
andrewonlab79244cc2015-01-26 01:11:49 -05001925 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001926
andrewonlab79244cc2015-01-26 01:11:49 -05001927 main.ONOS4cli.startOnosCli( ONOS4Ip )
1928 main.ONOS5cli.startOnosCli( ONOS5Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001929
andrewonlab79244cc2015-01-26 01:11:49 -05001930 elif clusterCount == 7:
andrewonlab67630692015-01-29 20:16:01 -05001931 main.log.info( "Installing nodes 6 and 7" )
andrewonlab79244cc2015-01-26 01:11:49 -05001932 node6Result = \
1933 main.ONOSbench.onosInstall( node=ONOS6Ip )
1934 node7Result = \
1935 main.ONOSbench.onosInstall( node=ONOS7Ip )
1936 installResult = node6Result and node7Result
andrewonlaba57a3042015-01-23 13:53:05 -05001937
andrewonlab79244cc2015-01-26 01:11:49 -05001938 time.sleep( 5 )
1939
1940 main.ONOS6cli.startOnosCli( ONOS6Ip )
1941 main.ONOS7cli.startOnosCli( ONOS7Ip )