blob: 0d2a5967352b5283592c139cfcaaf341d42a17fb [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
andrewonlab86e9e082015-02-13 12:07:39 -050030 #TODO: fix run number implementation
31 global runNum
andrewonlab79244cc2015-01-26 01:11:49 -050032 # Set initial cluster count
33 clusterCount = 1
andrewonlaba57a3042015-01-23 13:53:05 -050034 ##
andrewonlab2a6c9342014-10-16 13:40:15 -040035
andrewonlab86e9e082015-02-13 12:07:39 -050036 runNum = time.strftime("%d%H%M%S")
37
andrewonlab79244cc2015-01-26 01:11:49 -050038 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlab2a6c9342014-10-16 13:40:15 -040039
andrewonlab79244cc2015-01-26 01:11:49 -050040 gitPull = main.params[ 'GIT' ][ 'autoPull' ]
41 checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
kelvin-onlab8a832582015-01-16 17:06:11 -080042
andrewonlab79244cc2015-01-26 01:11:49 -050043 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
44 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
45 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
46 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
47 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
48 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
49 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
50
51 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
52 BENCHIp = main.params[ 'BENCH' ][ 'ip' ]
53
54 topoCfgFile = main.params[ 'TEST' ][ 'topoConfigFile' ]
55 topoCfgName = main.params[ 'TEST' ][ 'topoConfigName' ]
56
57 mvnCleanInstall = main.params[ 'TEST' ][ 'mci' ]
andrewonlaba57a3042015-01-23 13:53:05 -050058
andrewonlab79244cc2015-01-26 01:11:49 -050059 main.case( "Setting up test environment" )
60 main.log.info( "Copying topology event accumulator config" +
61 " to ONOS /package/etc" )
62 main.ONOSbench.handle.sendline( "cp ~/" +
63 topoCfgFile +
64 " ~/ONOS/tools/package/etc/" +
65 topoCfgName )
66 main.ONOSbench.handle.expect( "\$" )
andrewonlab6c8bbeb2014-11-14 12:43:48 -050067
andrewonlab79244cc2015-01-26 01:11:49 -050068 main.log.report( "Setting up test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -040069
andrewonlab5b954b02015-02-05 13:03:46 -050070 main.step( "Starting mininet topology " )
71 main.Mininet1.startNet()
72
andrewonlab79244cc2015-01-26 01:11:49 -050073 main.step( "Cleaning previously installed ONOS if any" )
74 main.ONOSbench.onosUninstall( nodeIp=ONOS2Ip )
75 main.ONOSbench.onosUninstall( nodeIp=ONOS3Ip )
76 main.ONOSbench.onosUninstall( nodeIp=ONOS4Ip )
77 main.ONOSbench.onosUninstall( nodeIp=ONOS5Ip )
78 main.ONOSbench.onosUninstall( nodeIp=ONOS6Ip )
andrewonlab67630692015-01-29 20:16:01 -050079 main.ONOSbench.onosUninstall( nodeIp=ONOS7Ip )
andrewonlab0e1825c2014-11-20 20:07:00 -050080
andrewonlab79244cc2015-01-26 01:11:49 -050081 main.step( "Creating cell file" )
82 cellFileResult = main.ONOSbench.createCellFile(
83 BENCHIp, cellName, MN1Ip,
84 "onos-core,onos-app-metrics,onos-app-gui",
85 ONOS1Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -040086
andrewonlab79244cc2015-01-26 01:11:49 -050087 main.step( "Applying cell file to environment" )
88 cellApplyResult = main.ONOSbench.setCell( cellName )
89 verifyCellResult = main.ONOSbench.verifyCell()
andrewonlab6c8bbeb2014-11-14 12:43:48 -050090
andrewonlab79244cc2015-01-26 01:11:49 -050091 # NOTE: This step may be removed after proper
kelvin-onlab8a832582015-01-16 17:06:11 -080092 # copy cat log functionality
andrewonlab79244cc2015-01-26 01:11:49 -050093 main.step( "Removing raft/copy-cat logs from ONOS nodes" )
94 main.ONOSbench.onosRemoveRaftLogs()
95 time.sleep( 30 )
kelvin-onlab8a832582015-01-16 17:06:11 -080096
andrewonlab79244cc2015-01-26 01:11:49 -050097 main.step( "Git checkout and pull " + checkoutBranch )
98 if gitPull == 'on':
99 # checkoutResult = \
100 # main.ONOSbench.gitCheckout( checkoutBranch )
101 checkoutResult = main.TRUE
102 pullResult = main.ONOSbench.gitPull()
andrewonlab2a6c9342014-10-16 13:40:15 -0400103 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500104 checkoutResult = main.TRUE
105 pullResult = main.TRUE
106 main.log.info( "Skipped git checkout and pull" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400107
andrewonlab79244cc2015-01-26 01:11:49 -0500108 main.log.report( "Commit information - " )
109 main.ONOSbench.getVersion( report=True )
andrewonlab92844342014-11-18 16:39:11 -0500110
andrewonlab79244cc2015-01-26 01:11:49 -0500111 main.step( "Using mvn clean & install" )
112 if mvnCleanInstall == 'on':
113 mvnResult = main.ONOSbench.cleanInstall()
114 elif mvnCleanInstall == 'off':
115 main.log.info("mci turned off by settings")
116 mvnResult = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -0400117
andrewonlab79244cc2015-01-26 01:11:49 -0500118 main.step( "Set cell for ONOS cli env" )
119 main.ONOS1cli.setCell( cellName )
120 # main.ONOS2cli.setCell( cellName )
121 # main.ONOS3cli.setCell( cellName )
andrewonlabb1998c52014-11-10 13:31:43 -0500122
andrewonlab79244cc2015-01-26 01:11:49 -0500123 main.step( "Creating ONOS package" )
124 packageResult = main.ONOSbench.onosPackage()
andrewonlab2a6c9342014-10-16 13:40:15 -0400125
andrewonlab79244cc2015-01-26 01:11:49 -0500126 main.step( "Installing ONOS package" )
127 install1Result = main.ONOSbench.onosInstall( node=ONOS1Ip )
128 #install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip )
129 #install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -0400130
andrewonlab79244cc2015-01-26 01:11:49 -0500131 time.sleep( 10 )
andrewonlabe9fb6722014-10-24 12:20:35 -0400132
andrewonlab79244cc2015-01-26 01:11:49 -0500133 main.step( "Start onos cli" )
134 cli1 = main.ONOS1cli.startOnosCli( ONOS1Ip )
135 #cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip )
136 #cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlabe9fb6722014-10-24 12:20:35 -0400137
andrewonlab79244cc2015-01-26 01:11:49 -0500138 utilities.assert_equals( expect=main.TRUE,
139 actual=cellFileResult and cellApplyResult and
140 verifyCellResult and checkoutResult and
141 pullResult and mvnResult and
142 install1Result, # and install2Result and
143 # install3Result,
144 onpass="Test Environment setup successful",
145 onfail="Failed to setup test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400146
andrewonlab79244cc2015-01-26 01:11:49 -0500147 def CASE2( self, main ):
148 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400149 Assign s1 to ONOS1 and measure latency
andrewonlab79244cc2015-01-26 01:11:49 -0500150
andrewonlab3a7c3c72014-10-24 17:21:03 -0400151 There are 4 levels of latency measurements to this test:
andrewonlab79244cc2015-01-26 01:11:49 -0500152 1 ) End-to-end measurement: Complete end-to-end measurement
153 from TCP ( SYN/ACK ) handshake to Graph change
154 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of
andrewonlab3a7c3c72014-10-24 17:21:03 -0400155 measurement from OFP Vendor message to Graph change
andrewonlab79244cc2015-01-26 01:11:49 -0500156 3 ) OFP-to-device measurement: 'ONOS processing without
andrewonlab3a7c3c72014-10-24 17:21:03 -0400157 graph change' snippet of measurement from OFP vendor
158 message to Device change timestamp
andrewonlab79244cc2015-01-26 01:11:49 -0500159 4 ) T0-to-device measurement: Measurement that includes
160 the switch handshake to devices timestamp without
161 the graph view change. ( TCP handshake -> Device
162 change )
163 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400164 import time
andrewonlabe6745342014-10-17 14:29:13 -0400165 import subprocess
166 import json
167 import requests
168 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500169 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500170 global clusterCount
andrewonlabba44bcf2014-10-16 16:54:41 -0400171
andrewonlab79244cc2015-01-26 01:11:49 -0500172 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
173 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
174 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
175 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
176 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
177 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
178 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlabe6745342014-10-17 14:29:13 -0400179
andrewonlab79244cc2015-01-26 01:11:49 -0500180 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab4b5c8b92014-11-10 16:04:33 -0500181
andrewonlab79244cc2015-01-26 01:11:49 -0500182 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab226024e2014-10-24 16:01:32 -0400183
andrewonlab79244cc2015-01-26 01:11:49 -0500184 # Number of iterations of case
185 numIter = main.params[ 'TEST' ][ 'numIter' ]
186 # Number of first 'x' iterations to ignore:
187 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500188
andrewonlab79244cc2015-01-26 01:11:49 -0500189 # Timestamp 'keys' for json metrics output.
190 # These are subject to change, hence moved into params
191 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
192 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500193
andrewonlab79244cc2015-01-26 01:11:49 -0500194 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
195 onosLog = main.params[ 'TEST' ][ 'onosLogFile' ]
kelvin-onlab8a832582015-01-16 17:06:11 -0800196
andrewonlab79244cc2015-01-26 01:11:49 -0500197 # Threshold for the test
198 thresholdStr = main.params[ 'TEST' ][ 'singleSwThreshold' ]
199 thresholdObj = thresholdStr.split( "," )
200 thresholdMin = int( thresholdObj[ 0 ] )
201 thresholdMax = int( thresholdObj[ 1 ] )
andrewonlab226024e2014-10-24 16:01:32 -0400202
andrewonlab79244cc2015-01-26 01:11:49 -0500203 # List of switch add latency collected from
204 # all iterations
205 latencyEndToEndList = []
206 latencyOfpToGraphList = []
207 latencyOfpToDeviceList = []
208 latencyT0ToDeviceList = []
209 latencyTcpToOfpList = []
andrewonlabba44bcf2014-10-16 16:54:41 -0400210
andrewonlab67630692015-01-29 20:16:01 -0500211 # Initialize 2d array for [node][iteration] storage
212 endToEndLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
213 ofpToGraphLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
214 # tcp-to-ofp measurements are same throughout each iteration
215 tcpToOfpLatIter = []
216
andrewonlab79244cc2015-01-26 01:11:49 -0500217 # Directory/file to store tshark results
218 tsharkOfOutput = "/tmp/tshark_of_topo.txt"
219 tsharkTcpOutput = "/tmp/tshark_tcp_topo.txt"
220
221 # String to grep in tshark output
222 tsharkTcpString = "TCP 74 " + defaultSwPort
223 tsharkOfString = "OFP 86 Vendor"
224
225 # Initialize assertion to TRUE
andrewonlabe6745342014-10-17 14:29:13 -0400226 assertion = main.TRUE
andrewonlabb1998c52014-11-10 13:31:43 -0500227
andrewonlab79244cc2015-01-26 01:11:49 -0500228 localTime = time.strftime( '%x %X' )
229 localTime = localTime.replace( "/", "" )
230 localTime = localTime.replace( " ", "_" )
231 localTime = localTime.replace( ":", "" )
232 if debugMode == 'on':
233 main.ONOS1.tsharkPcap( "eth0",
234 "/tmp/single_sw_lat_pcap_" + localTime )
andrewonlab58f7d702014-11-07 13:21:19 -0500235
andrewonlab79244cc2015-01-26 01:11:49 -0500236 main.log.info( "Debug mode is on" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400237
andrewonlab79244cc2015-01-26 01:11:49 -0500238 main.log.report( "Latency of adding one switch to controller" )
239 main.log.report( "First " + str( iterIgnore ) + " iterations ignored" +
240 " for jvm warmup time" )
241 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlabba44bcf2014-10-16 16:54:41 -0400242
andrewonlab79244cc2015-01-26 01:11:49 -0500243 for i in range( 0, int( numIter ) ):
244 main.log.info( "Starting tshark capture" )
245
246 #* TCP [ ACK, SYN ] is used as t0A, the
247 # very first "exchange" between ONOS and
andrewonlabba44bcf2014-10-16 16:54:41 -0400248 # the switch for end-to-end measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500249 #* OFP [ Stats Reply ] is used for t0B
andrewonlabba44bcf2014-10-16 16:54:41 -0400250 # the very last OFP message between ONOS
251 # and the switch for ONOS measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500252 main.ONOS1.tsharkGrep( tsharkTcpString,
253 tsharkTcpOutput )
254 main.ONOS1.tsharkGrep( tsharkOfString,
255 tsharkOfOutput )
andrewonlabba44bcf2014-10-16 16:54:41 -0400256
andrewonlab79244cc2015-01-26 01:11:49 -0500257 # Wait and ensure tshark is started and
258 # capturing
259 time.sleep( 10 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400260
andrewonlab79244cc2015-01-26 01:11:49 -0500261 main.log.info( "Assigning s1 to controller" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400262
andrewonlab79244cc2015-01-26 01:11:49 -0500263 main.Mininet1.assignSwController(
264 sw="1",
265 ip1=ONOS1Ip,
266 port1=defaultSwPort )
andrewonlabba44bcf2014-10-16 16:54:41 -0400267
andrewonlab79244cc2015-01-26 01:11:49 -0500268 # Wait and ensure switch is assigned
269 # before stopping tshark
270 time.sleep( 30 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400271
andrewonlab79244cc2015-01-26 01:11:49 -0500272 main.log.info( "Stopping all Tshark processes" )
273 main.ONOS1.stopTshark()
kelvin-onlab8a832582015-01-16 17:06:11 -0800274
andrewonlab79244cc2015-01-26 01:11:49 -0500275 # tshark output is saved in ONOS. Use subprocess
276 # to copy over files to TestON for parsing
277 main.log.info( "Copying over tshark files" )
278
279 # TCP CAPTURE ****
280 # Copy the tshark output from ONOS machine to
281 # TestON machine in tsharkTcpOutput directory>file
282 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
283 tsharkTcpOutput + " /tmp/" )
284 tcpFile = open( tsharkTcpOutput, 'r' )
285 tempText = tcpFile.readline()
286 tempText = tempText.split( " " )
287
288 main.log.info( "Object read in from TCP capture: " +
289 str( tempText ) )
290 if len( tempText ) > 1:
291 t0Tcp = float( tempText[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400292 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500293 main.log.error( "Tshark output file for TCP" +
294 " returned unexpected results" )
295 t0Tcp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400296 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500297
298 tcpFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400299 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400300
andrewonlab79244cc2015-01-26 01:11:49 -0500301 # OF CAPTURE ****
302 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
303 tsharkOfOutput + " /tmp/" )
304 ofFile = open( tsharkOfOutput, 'r' )
305
306 lineOfp = ""
307 # Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400308 while True:
andrewonlab79244cc2015-01-26 01:11:49 -0500309 tempText = ofFile.readline()
310 if tempText != '':
311 lineOfp = tempText
andrewonlabe6745342014-10-17 14:29:13 -0400312 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500313 break
314 obj = lineOfp.split( " " )
315
316 main.log.info( "Object read in from OFP capture: " +
317 str( lineOfp ) )
318
andrewonlab5b954b02015-02-05 13:03:46 -0500319 if len( obj ) > 1:
andrewonlab79244cc2015-01-26 01:11:49 -0500320 t0Ofp = float( obj[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400321 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500322 main.log.error( "Tshark output file for OFP" +
323 " returned unexpected results" )
324 t0Ofp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400325 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500326
327 ofFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400328 #****************
andrewonlab867212a2014-10-22 20:13:38 -0400329
andrewonlab79244cc2015-01-26 01:11:49 -0500330 jsonStr1 = main.ONOS1cli.topologyEventsMetrics()
331 # Initialize scale-out variables
332 jsonStr2 = ""
333 jsonStr3 = ""
334 jsonStr4 = ""
335 jsonStr5 = ""
336 jsonStr6 = ""
337 jsonStr7 = ""
andrewonlabe9fb6722014-10-24 12:20:35 -0400338
andrewonlab79244cc2015-01-26 01:11:49 -0500339 jsonObj1 = json.loads( jsonStr1 )
340 # Initialize scale-out variables
341 jsonObj2 = ""
342 jsonObj3 = ""
343 jsonObj4 = ""
344 jsonObj5 = ""
345 jsonObj6 = ""
346 jsonObj7 = ""
kelvin-onlab8a832582015-01-16 17:06:11 -0800347
andrewonlab79244cc2015-01-26 01:11:49 -0500348 # Obtain graph timestamp. This timestsamp captures
349 # the epoch time at which the topology graph was updated.
350 graphTimestamp1 = \
351 jsonObj1[ graphTimestamp ][ 'value' ]
352 # Obtain device timestamp. This timestamp captures
353 # the epoch time at which the device event happened
354 deviceTimestamp1 = \
355 jsonObj1[ deviceTimestamp ][ 'value' ]
356
357 # t0 to device processing latency
358 deltaDevice1 = int( deviceTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500359 # t0 to graph processing latency ( end-to-end )
360 deltaGraph1 = int( graphTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500361 # ofp to graph processing latency ( ONOS processing )
362 deltaOfpGraph1 = int( graphTimestamp1 ) - int( t0Ofp )
andrewonlab79244cc2015-01-26 01:11:49 -0500363 # ofp to device processing latency ( ONOS processing )
364 deltaOfpDevice1 = float( deviceTimestamp1 ) - float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500365 # tcp to ofp processing latency ( switch connection )
366 deltaTcpOfp1 = int(t0Ofp) - int(t0Tcp)
367
368 if deltaTcpOfp1 > thresholdMin and deltaTcpOfp1 < thresholdMax\
369 and i >= iterIgnore:
370 tcpToOfpLatIter.append(deltaTcpOfp1)
371 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
372 str(deltaTcpOfp1)+" ms")
373 else:
374 tcpToOfpLatIter.append(0)
375 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
376 str(deltaTcpOfp1)+" ms - ignored this iteration")
377
378 # Store initial measurements in data array
379 #This measurement is for node 1
380
381 if deltaGraph1 > thresholdMin and deltaGraph1 < thresholdMax\
382 and i >= iterIgnore:
383 endToEndLatNodeIter[0][i] = deltaGraph1
384 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
385 str(deltaGraph1)+" ms")
386 else:
387 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
388 str(deltaGraph1)+" ms - ignored this iteration")
389
390
391 if deltaOfpGraph1 > thresholdMin and deltaOfpGraph1 < thresholdMax\
392 and i >= iterIgnore:
393 ofpToGraphLatNodeIter[0][i] = deltaOfpGraph1
394
395 main.log.info("ONOS1 iter"+str(i)+" ofp-to-graph: "+
396 str(deltaOfpGraph1)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -0500397
398 # TODO: Create even cluster number events
399
400 # Include scale-out measurements when applicable
401 if clusterCount >= 3:
402 jsonStr2 = main.ONOS2cli.topologyEventsMetrics()
403 jsonStr3 = main.ONOS3cli.topologyEventsMetrics()
404 jsonObj2 = json.loads( jsonStr2 )
405 jsonObj3 = json.loads( jsonStr3 )
406 graphTimestamp2 = \
407 jsonObj2[ graphTimestamp ][ 'value' ]
408 graphTimestamp3 = \
409 jsonObj3[ graphTimestamp ][ 'value' ]
410 deviceTimestamp2 = \
411 jsonObj2[ deviceTimestamp ][ 'value' ]
412 deviceTimestamp3 = \
413 jsonObj3[ deviceTimestamp ][ 'value' ]
414 deltaDevice2 = int( deviceTimestamp2 ) - int( t0Tcp )
415 deltaDevice3 = int( deviceTimestamp3 ) - int( t0Tcp )
416 deltaGraph2 = int( graphTimestamp2 ) - int( t0Tcp )
417 deltaGraph3 = int( graphTimestamp3 ) - int( t0Tcp )
418 deltaOfpGraph2 = int( graphTimestamp2 ) - int( t0Ofp )
419 deltaOfpGraph3 = int( graphTimestamp3 ) - int( t0Ofp )
420 deltaOfpDevice2 = float( deviceTimestamp2 ) -\
421 float( t0Ofp )
422 deltaOfpDevice3 = float( deviceTimestamp3 ) -\
423 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500424
andrewonlab67630692015-01-29 20:16:01 -0500425 if deltaGraph2 > thresholdMin and\
426 deltaGraph2 < thresholdMax and i >= iterIgnore:
427 endToEndLatNodeIter[1][i] = deltaGraph2
428 main.log.info("ONOS2 iter"+str(i)+" end-to-end: "+
429 str(deltaGraph2)+" ms")
430
431 if deltaOfpGraph2 > thresholdMin and\
432 deltaOfpGraph2 < thresholdMax and i >= iterIgnore:
433 ofpToGraphLatNodeIter[1][i] = deltaOfpGraph2
434 main.log.info("ONOS2 iter"+str(i)+" ofp-to-graph: "+
435 str(deltaOfpGraph2)+" ms")
436
437 if deltaGraph3 > thresholdMin and\
438 deltaGraph3 < thresholdMax and i >= iterIgnore:
439 endToEndLatNodeIter[2][i] = deltaGraph3
440 main.log.info("ONOS3 iter"+str(i)+" end-to-end: "+
441 str(deltaGraph3)+" ms")
442
443 if deltaOfpGraph3 > thresholdMin and\
444 deltaOfpGraph3 < thresholdMax and i >= iterIgnore:
445 ofpToGraphLatNodeIter[2][i] = deltaOfpGraph3
446 main.log.info("ONOS3 iter"+str(i)+" ofp-to-graph: "+
447 str(deltaOfpGraph3)+" ms")
448
andrewonlab79244cc2015-01-26 01:11:49 -0500449 if clusterCount >= 5:
450 jsonStr4 = main.ONOS4cli.topologyEventsMetrics()
451 jsonStr5 = main.ONOS5cli.topologyEventsMetrics()
452 jsonObj4 = json.loads( jsonStr4 )
453 jsonObj5 = json.loads( jsonStr5 )
454 graphTimestamp4 = \
455 jsonObj4[ graphTimestamp ][ 'value' ]
456 graphTimestamp5 = \
457 jsonObj5[ graphTimestamp ][ 'value' ]
458 deviceTimestamp4 = \
459 jsonObj4[ deviceTimestamp ][ 'value' ]
460 deviceTimestamp5 = \
461 jsonObj5[ deviceTimestamp ][ 'value' ]
462 deltaDevice4 = int( deviceTimestamp4 ) - int( t0Tcp )
463 deltaDevice5 = int( deviceTimestamp5 ) - int( t0Tcp )
464 deltaGraph4 = int( graphTimestamp4 ) - int( t0Tcp )
465 deltaGraph5 = int( graphTimestamp5 ) - int( t0Tcp )
466 deltaOfpGraph4 = int( graphTimestamp4 ) - int( t0Ofp )
467 deltaOfpGraph5 = int( graphTimestamp5 ) - int( t0Ofp )
468 deltaOfpDevice4 = float( deviceTimestamp4 ) -\
469 float( t0Ofp )
470 deltaOfpDevice5 = float( deviceTimestamp5 ) -\
471 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500472
473 if deltaGraph4 > thresholdMin and\
474 deltaGraph4 < thresholdMax and i >= iterIgnore:
475 endToEndLatNodeIter[3][i] = deltaGraph4
476 main.log.info("ONOS4 iter"+str(i)+" end-to-end: "+
477 str(deltaGraph4)+" ms")
478
479 #TODO:
480 if deltaOfpGraph4 > thresholdMin and\
481 deltaOfpGraph4 < thresholdMax and i >= iterIgnore:
482 ofpToGraphLatNodeIter[3][i] = deltaOfpGraph4
483 main.log.info("ONOS4 iter"+str(i)+" ofp-to-graph: "+
484 str(deltaOfpGraph4)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500485
andrewonlab67630692015-01-29 20:16:01 -0500486 if deltaGraph5 > thresholdMin and\
487 deltaGraph5 < thresholdMax and i >= iterIgnore:
488 endToEndLatNodeIter[4][i] = deltaGraph5
489 main.log.info("ONOS5 iter"+str(i)+" end-to-end: "+
490 str(deltaGraph5)+" ms")
491
492 if deltaOfpGraph5 > thresholdMin and\
493 deltaOfpGraph5 < thresholdMax and i >= iterIgnore:
494 ofpToGraphLatNodeIter[4][i] = deltaOfpGraph5
495 main.log.info("ONOS5 iter"+str(i)+" ofp-to-graph: "+
496 str(deltaOfpGraph5)+" ms")
497
andrewonlab79244cc2015-01-26 01:11:49 -0500498 if clusterCount >= 7:
499 jsonStr6 = main.ONOS6cli.topologyEventsMetrics()
500 jsonStr7 = main.ONOS7cli.topologyEventsMetrics()
501 jsonObj6 = json.loads( jsonStr6 )
502 jsonObj7 = json.loads( jsonStr7 )
503 graphTimestamp6 = \
504 jsonObj6[ graphTimestamp ][ 'value' ]
505 graphTimestamp7 = \
506 jsonObj7[ graphTimestamp ][ 'value' ]
507 deviceTimestamp6 = \
508 jsonObj6[ deviceTimestamp ][ 'value' ]
509 deviceTimestamp7 = \
510 jsonObj7[ deviceTimestamp ][ 'value' ]
511 deltaDevice6 = int( deviceTimestamp6 ) - int( t0Tcp )
512 deltaDevice7 = int( deviceTimestamp7 ) - int( t0Tcp )
513 deltaGraph6 = int( graphTimestamp6 ) - int( t0Tcp )
514 deltaGraph7 = int( graphTimestamp7 ) - int( t0Tcp )
515 deltaOfpGraph6 = int( graphTimestamp6 ) - int( t0Ofp )
516 deltaOfpGraph7 = int( graphTimestamp7 ) - int( t0Ofp )
517 deltaOfpDevice6 = float( deviceTimestamp6 ) -\
518 float( t0Ofp )
519 deltaOfpDevice7 = float( deviceTimestamp7 ) -\
520 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500521
522 if deltaGraph6 > thresholdMin and\
523 deltaGraph6 < thresholdMax and i >= iterIgnore:
524 endToEndLatNodeIter[5][i] = deltaGraph6
525 main.log.info("ONOS6 iter"+str(i)+" end-to-end: "+
526 str(deltaGraph6)+" ms")
527
528 #TODO:
529 if deltaOfpGraph6 > thresholdMin and\
530 deltaOfpGraph6 < thresholdMax and i >= iterIgnore:
531 ofpToGraphLatNodeIter[5][i] = deltaOfpGraph6
532 main.log.info("ONOS6 iter"+str(i)+" ofp-to-graph: "+
533 str(deltaOfpGraph6)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500534
andrewonlab67630692015-01-29 20:16:01 -0500535 if deltaGraph7 > thresholdMin and\
536 deltaGraph7 < thresholdMax and i >= iterIgnore:
537 endToEndLatNodeIter[6][i] = deltaGraph7
538 main.log.info("ONOS7 iter"+str(i)+" end-to-end: "+
539 str(deltaGraph7)+" ms")
540
541 if deltaOfpGraph7 > thresholdMin and\
542 deltaOfpGraph7 < thresholdMax and i >= iterIgnore:
543 ofpToGraphLatNodeIter[6][i] = deltaOfpGraph7
544 main.log.info("ONOS7 iter"+str(i)+" ofp-to-graph: "+
545 str(deltaOfpGraph7)+" ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400546
andrewonlab79244cc2015-01-26 01:11:49 -0500547 main.step( "Remove switch from controller" )
548 main.Mininet1.deleteSwController( "s1" )
andrewonlabf47993a2014-10-24 17:56:01 -0400549
andrewonlab79244cc2015-01-26 01:11:49 -0500550 time.sleep( 5 )
551
552 # END of for loop iteration
553
andrewonlab67630692015-01-29 20:16:01 -0500554 #str( round( numpy.std( latencyT0ToDeviceList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400555
andrewonlab67630692015-01-29 20:16:01 -0500556 endToEndAvg = 0
557 ofpToGraphAvg = 0
558 endToEndList = []
559 ofpToGraphList = []
andrewonlab69864162014-11-11 16:28:48 -0500560
andrewonlab67630692015-01-29 20:16:01 -0500561 for node in range( 0, clusterCount ):
562 # The latency 2d array was initialized to 0.
563 # If an iteration was ignored, then we have some 0's in
564 # our calculation. To avoid having this interfere with our
565 # results, we must delete any index where 0 is found...
566 # WARN: Potentially, we could have latency that hovers at
567 # 0 ms once we have optimized code. FIXME for when this is
568 # the case. Being able to obtain sub-millisecond accuracy
569 # can prevent this from happening
570 for item in endToEndLatNodeIter[node]:
571 if item > 0.0:
572 endToEndList.append(item)
573 for item in ofpToGraphLatNodeIter[node]:
574 if item > 0.0:
575 ofpToGraphList.append(item)
andrewonlabc15c9582014-10-24 16:35:52 -0400576
andrewonlab67630692015-01-29 20:16:01 -0500577 endToEndAvg = numpy.mean(endToEndList)
578 ofpToGraphAvg = numpy.mean(ofpToGraphList)
andrewonlabc15c9582014-10-24 16:35:52 -0400579
andrewonlab67630692015-01-29 20:16:01 -0500580 main.log.report( " - Node "+str(node+1)+" Summary - " )
581 main.log.report( " End-to-end Avg: "+
582 str(round(endToEndAvg,2))+" ms"+
583 " End-to-end Std dev: "+
584 str(round(numpy.std(endToEndList),2))+" ms")
andrewonlabd5367a42015-01-30 14:46:17 -0500585 #main.log.report( " Ofp-to-graph Avg: "+
586 # str(round(ofpToGraphAvg,2))+" ms"+
587 # " Ofp-to-graph Std dev: "+
588 # str(round(numpy.std(ofpToGraphList),2))+
589 # " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400590
andrewonlab79244cc2015-01-26 01:11:49 -0500591 if debugMode == 'on':
592 main.ONOS1.cpLogsToDir( "/opt/onos/log/karaf.log",
593 "/tmp/", copyFileName="sw_lat_karaf" )
andrewonlabb1998c52014-11-10 13:31:43 -0500594
andrewonlab67630692015-01-29 20:16:01 -0500595 #TODO: correct assert
596 assertion = main.TRUE
597
andrewonlab79244cc2015-01-26 01:11:49 -0500598 utilities.assert_equals( expect=main.TRUE, actual=assertion,
599 onpass="Switch latency test successful",
600 onfail="Switch latency test failed" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400601
andrewonlab79244cc2015-01-26 01:11:49 -0500602 def CASE3( self, main ):
603 """
andrewonlab8d29f122014-10-22 17:15:04 -0400604 Bring port up / down and measure latency.
605 Port enable / disable is simulated by ifconfig up / down
andrewonlab79244cc2015-01-26 01:11:49 -0500606
607 In ONOS-next, we must ensure that the port we are
andrewonlab393531a2014-10-27 18:36:26 -0400608 manipulating is connected to another switch with a valid
609 connection. Otherwise, graph view will not be updated.
andrewonlab79244cc2015-01-26 01:11:49 -0500610 """
andrewonlab8d29f122014-10-22 17:15:04 -0400611 import time
612 import subprocess
613 import os
614 import requests
615 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500616 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500617 global clusterCount
andrewonlab86e9e082015-02-13 12:07:39 -0500618 global runNum
andrewonlab2a6c9342014-10-16 13:40:15 -0400619
andrewonlab79244cc2015-01-26 01:11:49 -0500620 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
621 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
622 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
623 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab8d29f122014-10-22 17:15:04 -0400624
andrewonlab79244cc2015-01-26 01:11:49 -0500625 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
626
andrewonlab8790abb2014-11-06 13:51:54 -0500627 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -0500628 # Number of iterations of case
629 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabd5367a42015-01-30 14:46:17 -0500630 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500631
andrewonlab79244cc2015-01-26 01:11:49 -0500632 # Timestamp 'keys' for json metrics output.
633 # These are subject to change, hence moved into params
634 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
635 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlab393531a2014-10-27 18:36:26 -0400636
andrewonlab79244cc2015-01-26 01:11:49 -0500637 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlab86e9e082015-02-13 12:07:39 -0500638 postToDB = main.params[ 'DB' ][ 'postToDB' ]
639 resultPath = main.params[ 'DB' ][ 'portEventResultPath' ]
640 timeToPost = time.strftime("%Y-%m-%d %H:%M:%S")
andrewonlabe5bcef92014-11-06 17:53:20 -0500641
andrewonlab79244cc2015-01-26 01:11:49 -0500642 localTime = time.strftime( '%x %X' )
643 localTime = localTime.replace( "/", "" )
644 localTime = localTime.replace( " ", "_" )
645 localTime = localTime.replace( ":", "" )
646 if debugMode == 'on':
647 main.ONOS1.tsharkPcap( "eth0",
648 "/tmp/port_lat_pcap_" + localTime )
andrewonlabe5bcef92014-11-06 17:53:20 -0500649
andrewonlab79244cc2015-01-26 01:11:49 -0500650 # Threshold for this test case
651 upThresholdStr = main.params[ 'TEST' ][ 'portUpThreshold' ]
652 downThresholdStr = main.params[ 'TEST' ][ 'portDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500653
andrewonlab79244cc2015-01-26 01:11:49 -0500654 upThresholdObj = upThresholdStr.split( "," )
655 downThresholdObj = downThresholdStr.split( "," )
656
657 upThresholdMin = int( upThresholdObj[ 0 ] )
658 upThresholdMax = int( upThresholdObj[ 1 ] )
659
660 downThresholdMin = int( downThresholdObj[ 0 ] )
661 downThresholdMax = int( downThresholdObj[ 1 ] )
662
663 # NOTE: Some hardcoded variables you may need to configure
andrewonlab393531a2014-10-27 18:36:26 -0400664 # besides the params
andrewonlab8d29f122014-10-22 17:15:04 -0400665
andrewonlab79244cc2015-01-26 01:11:49 -0500666 tsharkPortStatus = "OFP 130 Port Status"
andrewonlab8d29f122014-10-22 17:15:04 -0400667
andrewonlab79244cc2015-01-26 01:11:49 -0500668 tsharkPortUp = "/tmp/tshark_port_up.txt"
669 tsharkPortDown = "/tmp/tshark_port_down.txt"
670 interfaceConfig = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400671
andrewonlab79244cc2015-01-26 01:11:49 -0500672 main.log.report( "Port enable / disable latency" )
673 main.log.report( "Simulated by ifconfig up / down" )
674 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400675
andrewonlab79244cc2015-01-26 01:11:49 -0500676 main.step( "Assign switches s1 and s2 to controller 1" )
677 main.Mininet1.assignSwController( sw="1", ip1=ONOS1Ip,
678 port1=defaultSwPort )
679 main.Mininet1.assignSwController( sw="2", ip1=ONOS1Ip,
680 port1=defaultSwPort )
andrewonlab8d29f122014-10-22 17:15:04 -0400681
andrewonlab79244cc2015-01-26 01:11:49 -0500682 # Give enough time for metrics to propagate the
683 # assign controller event. Otherwise, these events may
684 # carry over to our measurements
685 time.sleep( 15 )
andrewonlab393531a2014-10-27 18:36:26 -0400686
andrewonlab79244cc2015-01-26 01:11:49 -0500687 portUpDeviceToOfpList = []
688 portUpGraphToOfpList = []
689 portDownDeviceToOfpList = []
690 portDownGraphToOfpList = []
andrewonlabd5367a42015-01-30 14:46:17 -0500691
692 # Initialize 2d array filled with 0's
693 # arraySizeFormat[clusterCount][numIter]
694 portUpDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
695 portUpGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
696 portDownDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
697 portDownGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
andrewonlab8d29f122014-10-22 17:15:04 -0400698
andrewonlab79244cc2015-01-26 01:11:49 -0500699 for i in range( 0, int( numIter ) ):
700 main.step( "Starting wireshark capture for port status down" )
701 main.ONOS1.tsharkGrep( tsharkPortStatus,
702 tsharkPortDown )
andrewonlab8d29f122014-10-22 17:15:04 -0400703
andrewonlab79244cc2015-01-26 01:11:49 -0500704 time.sleep( 5 )
705
706 # Disable interface that is connected to switch 2
707 main.step( "Disable port: " + interfaceConfig )
708 main.Mininet1.handle.sendline( "sh ifconfig " +
709 interfaceConfig + " down" )
710 main.Mininet1.handle.expect( "mininet>" )
711
712 time.sleep( 3 )
713 main.ONOS1.tsharkStop()
714
715 # Copy tshark output file from ONOS to TestON instance
kelvin-onlab8a832582015-01-16 17:06:11 -0800716 #/tmp directory
andrewonlab79244cc2015-01-26 01:11:49 -0500717 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
718 tsharkPortDown + " /tmp/" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800719
andrewonlab79244cc2015-01-26 01:11:49 -0500720 fPortDown = open( tsharkPortDown, 'r' )
721 # Get first line of port down event from tshark
722 fLine = fPortDown.readline()
723 objDown = fLine.split( " " )
724 if len( fLine ) > 0:
725 # NOTE: objDown[ 1 ] is a very unreliable
726 # way to determine the timestamp. If
727 # results seem way off, check the object
andrewonlaba57a3042015-01-23 13:53:05 -0500728 # itself by printing it out
andrewonlab79244cc2015-01-26 01:11:49 -0500729 timestampBeginPtDown = int( float( objDown[ 1 ] ) * 1000 )
730 # For some reason, wireshark decides to record the
andrewonlaba57a3042015-01-23 13:53:05 -0500731 # timestamp at the 3rd object position instead of
andrewonlab79244cc2015-01-26 01:11:49 -0500732 # 2nd at unpredictable times. This statement is
andrewonlaba57a3042015-01-23 13:53:05 -0500733 # used to capture that odd behavior and use the
734 # correct epoch time
andrewonlab79244cc2015-01-26 01:11:49 -0500735 if timestampBeginPtDown < 1400000000000:
736 timestampBeginPtDown = \
737 int( float( objDown[ 2 ] ) * 1000 )
andrewonlaba57a3042015-01-23 13:53:05 -0500738
andrewonlab79244cc2015-01-26 01:11:49 -0500739 main.log.info( "Port down begin timestamp: " +
740 str( timestampBeginPtDown ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400741 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500742 main.log.info( "Tshark output file returned unexpected" +
743 " results: " + str( objDown ) )
744 timestampBeginPtDown = 0
745 fPortDown.close()
746
747 main.step( "Obtain t1 by metrics call" )
748 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
749 jsonObj1 = json.loads( jsonStrUp1 )
750 # Obtain graph timestamp. This timestsamp captures
751 # the epoch time at which the topology graph was updated.
752 graphTimestamp1 = \
753 jsonObj1[ graphTimestamp ][ 'value' ]
754 # Obtain device timestamp. This timestamp captures
755 # the epoch time at which the device event happened
756 deviceTimestamp1 = \
757 jsonObj1[ deviceTimestamp ][ 'value' ]
758 # Get delta between graph event and OFP
759 ptDownGraphToOfp1 = int( graphTimestamp1 ) -\
760 int( timestampBeginPtDown )
761 # Get delta between device event and OFP
762 ptDownDeviceToOfp1 = int( deviceTimestamp1 ) -\
763 int( timestampBeginPtDown )
764
andrewonlabd5367a42015-01-30 14:46:17 -0500765 if ptDownGraphToOfp1 > downThresholdMin and\
766 ptDownGraphToOfp1 < downThresholdMax and i > iterIgnore:
767 portDownGraphNodeIter[0][i] = ptDownGraphToOfp1
768 main.log.info("iter"+str(i)+" port down graph-to-ofp: "+
769 str(ptDownGraphToOfp1)+" ms")
770 else:
771 main.log.info("iter"+str(i)+" skipped. Result: "+
772 str(ptDownGraphToOfp1)+" ms")
773 if ptDownDeviceToOfp1 > downThresholdMin and\
774 ptDownDeviceToOfp1 < downThresholdMax and i > iterIgnore:
775 portDownDevNodeIter[0][i] = ptDownDeviceToOfp1
776 main.log.info("iter"+str(i)+" port down device-to-ofp: "+
777 str(ptDownDeviceToOfp1)+" ms")
778 else:
779 main.log.info("iter"+str(i)+" skipped. Result: "+
780 str(ptDownDeviceToOfp1)+" ms")
781
andrewonlab79244cc2015-01-26 01:11:49 -0500782 if clusterCount >= 3:
783 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
784 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
785 jsonObj2 = json.loads( jsonStrUp2 )
786 jsonObj3 = json.loads( jsonStrUp3 )
787 graphTimestamp2 = \
788 jsonObj2[ graphTimestamp ][ 'value' ]
789 graphTimestamp3 = \
790 jsonObj3[ graphTimestamp ][ 'value' ]
791 deviceTimestamp2 = \
792 jsonObj2[ deviceTimestamp ][ 'value' ]
793 deviceTimestamp3 = \
794 jsonObj3[ deviceTimestamp ][ 'value' ]
795 ptDownGraphToOfp2 = int( graphTimestamp2 ) -\
796 int( timestampBeginPtDown )
797 ptDownGraphToOfp3 = int( graphTimestamp3 ) -\
798 int( timestampBeginPtDown )
799 ptDownDeviceToOfp2 = int( deviceTimestamp2 ) -\
800 int( timestampBeginPtDown )
801 ptDownDeviceToOfp3 = int( deviceTimestamp3 ) -\
802 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500803
804 if ptDownGraphToOfp2 > downThresholdMin and\
805 ptDownGraphToOfp2 < downThresholdMax and i > iterIgnore:
806 portDownGraphNodeIter[1][i] = ptDownGraphToOfp2
807 main.log.info("ONOS2 iter"+str(i)+" graph-to-ofp: "+
808 str(ptDownGraphToOfp2)+" ms")
809
810 if ptDownDeviceToOfp2 > downThresholdMin and\
811 ptDownDeviceToOfp2 < downThresholdMax and i > iterIgnore:
812 portDownDevNodeIter[1][i] = ptDownDeviceToOfp2
813 main.log.info("ONOS2 iter"+str(i)+" device-to-ofp: "+
814 str(ptDownDeviceToOfp2)+" ms")
815
816 if ptDownGraphToOfp3 > downThresholdMin and\
817 ptDownGraphToOfp3 < downThresholdMax and i > iterIgnore:
818 portDownGraphNodeIter[2][i] = ptDownGraphToOfp3
819 main.log.info("ONOS3 iter"+str(i)+" graph-to-ofp: "+
820 str(ptDownGraphToOfp3)+" ms")
821
822 if ptDownDeviceToOfp3 > downThresholdMin and\
823 ptDownDeviceToOfp3 < downThresholdMax and i > iterIgnore:
824 portDownDevNodeIter[2][i] = ptDownDeviceToOfp3
825 main.log.info("ONOS3 iter"+str(i)+" device-to-ofp: "+
826 str(ptDownDeviceToOfp3)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400827
andrewonlab79244cc2015-01-26 01:11:49 -0500828 if clusterCount >= 5:
829 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
830 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
831 jsonObj4 = json.loads( jsonStrUp4 )
832 jsonObj5 = json.loads( jsonStrUp5 )
833 graphTimestamp4 = \
834 jsonObj4[ graphTimestamp ][ 'value' ]
835 graphTimestamp5 = \
836 jsonObj5[ graphTimestamp ][ 'value' ]
837 deviceTimestamp4 = \
838 jsonObj4[ deviceTimestamp ][ 'value' ]
839 deviceTimestamp5 = \
840 jsonObj5[ deviceTimestamp ][ 'value' ]
841 ptDownGraphToOfp4 = int( graphTimestamp4 ) -\
842 int( timestampBeginPtDown )
843 ptDownGraphToOfp5 = int( graphTimestamp5 ) -\
844 int( timestampBeginPtDown )
845 ptDownDeviceToOfp4 = int( deviceTimestamp4 ) -\
846 int( timestampBeginPtDown )
847 ptDownDeviceToOfp5 = int( deviceTimestamp5 ) -\
848 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500849
850 if ptDownGraphToOfp4 > downThresholdMin and\
851 ptDownGraphToOfp4 < downThresholdMax and i > iterIgnore:
852 portDownGraphNodeIter[3][i] = ptDownGraphToOfp4
853 main.log.info("ONOS4 iter"+str(i)+" graph-to-ofp: "+
854 str(ptDownGraphToOfp4)+" ms")
855
856 if ptDownDeviceToOfp4 > downThresholdMin and\
857 ptDownDeviceToOfp4 < downThresholdMax and i > iterIgnore:
858 portDownDevNodeIter[3][i] = ptDownDeviceToOfp4
859 main.log.info("ONOS4 iter"+str(i)+" device-to-ofp: "+
860 str(ptDownDeviceToOfp4)+" ms")
861
862 if ptDownGraphToOfp5 > downThresholdMin and\
863 ptDownGraphToOfp5 < downThresholdMax and i > iterIgnore:
864 portDownGraphNodeIter[4][i] = ptDownGraphToOfp5
865 main.log.info("ONOS5 iter"+str(i)+" graph-to-ofp: "+
866 str(ptDownGraphToOfp5)+" ms")
867
868 if ptDownDeviceToOfp5 > downThresholdMin and\
869 ptDownDeviceToOfp5 < downThresholdMax and i > iterIgnore:
870 portDownDevNodeIter[4][i] = ptDownDeviceToOfp5
871 main.log.info("ONOS5 iter"+str(i)+" device-to-ofp: "+
872 str(ptDownDeviceToOfp5)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400873
andrewonlab79244cc2015-01-26 01:11:49 -0500874 if clusterCount >= 7:
875 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
876 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
877 jsonObj6 = json.loads( jsonStrUp6 )
878 jsonObj7 = json.loads( jsonStrUp7 )
879 graphTimestamp6 = \
880 jsonObj6[ graphTimestamp ][ 'value' ]
881 graphTimestamp7 = \
882 jsonObj7[ graphTimestamp ][ 'value' ]
883 deviceTimestamp6 = \
884 jsonObj6[ deviceTimestamp ][ 'value' ]
885 deviceTimestamp7 = \
886 jsonObj7[ deviceTimestamp ][ 'value' ]
887 ptDownGraphToOfp6 = int( graphTimestamp6 ) -\
888 int( timestampBeginPtDown )
889 ptDownGraphToOfp7 = int( graphTimestamp7 ) -\
890 int( timestampBeginPtDown )
891 ptDownDeviceToOfp6 = int( deviceTimestamp6 ) -\
892 int( timestampBeginPtDown )
893 ptDownDeviceToOfp7 = int( deviceTimestamp7 ) -\
894 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500895
896 if ptDownGraphToOfp6 > downThresholdMin and\
897 ptDownGraphToOfp6 < downThresholdMax and i > iterIgnore:
898 portDownGraphNodeIter[5][i] = ptDownGraphToOfp6
899 main.log.info("ONOS6 iter"+str(i)+" graph-to-ofp: "+
900 str(ptDownGraphToOfp6)+" ms")
901
902 if ptDownDeviceToOfp6 > downThresholdMin and\
903 ptDownDeviceToOfp6 < downThresholdMax and i > iterIgnore:
904 portDownDevNodeIter[5][i] = ptDownDeviceToOfp6
905 main.log.info("ONOS6 iter"+str(i)+" device-to-ofp: "+
906 str(ptDownDeviceToOfp6)+" ms")
907
908 if ptDownGraphToOfp7 > downThresholdMin and\
909 ptDownGraphToOfp7 < downThresholdMax and i > iterIgnore:
910 portDownGraphNodeIter[6][i] = ptDownGraphToOfp7
911 main.log.info("ONOS7 iter"+str(i)+" graph-to-ofp: "+
912 str(ptDownGraphToOfp7)+" ms")
913
914 if ptDownDeviceToOfp7 > downThresholdMin and\
915 ptDownDeviceToOfp7 < downThresholdMax and i > iterIgnore:
916 portDownDevNodeIter[6][i] = ptDownDeviceToOfp7
917 main.log.info("ONOS7 iter"+str(i)+" device-to-ofp: "+
918 str(ptDownDeviceToOfp7)+" ms")
kelvin-onlab8a832582015-01-16 17:06:11 -0800919
andrewonlab79244cc2015-01-26 01:11:49 -0500920 time.sleep( 3 )
andrewonlaba57a3042015-01-23 13:53:05 -0500921
andrewonlab79244cc2015-01-26 01:11:49 -0500922 # Port up events
923 main.step( "Enable port and obtain timestamp" )
924 main.step( "Starting wireshark capture for port status up" )
925 main.ONOS1.tsharkGrep( tsharkPortStatus, tsharkPortUp )
926 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400927
andrewonlab79244cc2015-01-26 01:11:49 -0500928 main.Mininet1.handle.sendline( "sh ifconfig " +
929 interfaceConfig + " up" )
930 main.Mininet1.handle.expect( "mininet>" )
931
932 # Allow time for tshark to capture event
933 time.sleep( 5 )
934 main.ONOS1.tsharkStop()
935
936 time.sleep( 3 )
937 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
938 tsharkPortUp + " /tmp/" )
939 fPortUp = open( tsharkPortUp, 'r' )
940 fLine = fPortUp.readline()
941 objUp = fLine.split( " " )
942 if len( fLine ) > 0:
943 timestampBeginPtUp = int( float( objUp[ 1 ] ) * 1000 )
944 if timestampBeginPtUp < 1400000000000:
945 timestampBeginPtUp = \
946 int( float( objUp[ 2 ] ) * 1000 )
947 main.log.info( "Port up begin timestamp: " +
948 str( timestampBeginPtUp ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400949 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500950 main.log.info( "Tshark output file returned unexpected" +
951 " results." )
952 timestampBeginPtUp = 0
953 fPortUp.close()
andrewonlab393531a2014-10-27 18:36:26 -0400954
andrewonlab79244cc2015-01-26 01:11:49 -0500955 # Obtain metrics shortly afterwards
956 # This timestsamp captures
957 # the epoch time at which the topology graph was updated.
958 main.step( "Obtain t1 by REST call" )
959 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
960 jsonObj1 = json.loads( jsonStrUp1 )
961 graphTimestamp1 = \
962 jsonObj1[ graphTimestamp ][ 'value' ]
963 # Obtain device timestamp. This timestamp captures
964 # the epoch time at which the device event happened
965 deviceTimestamp1 = \
966 jsonObj1[ deviceTimestamp ][ 'value' ]
967 # Get delta between graph event and OFP
968 ptUpGraphToOfp1 = int( graphTimestamp1 ) -\
969 int( timestampBeginPtUp )
970 # Get delta between device event and OFP
971 ptUpDeviceToOfp1 = int( deviceTimestamp1 ) -\
972 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -0500973
974 if ptUpGraphToOfp1 > upThresholdMin and\
975 ptUpGraphToOfp1 < upThresholdMax and i > iterIgnore:
976 portUpGraphNodeIter[0][i] = ptUpGraphToOfp1
977 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
978 str(ptUpGraphToOfp1)+" ms")
979 else:
980 main.log.info("iter"+str(i)+" skipped. Result: "+
981 str(ptUpGraphToOfp1)+" ms")
982
983 if ptUpDeviceToOfp1 > upThresholdMin and\
984 ptUpDeviceToOfp1 < upThresholdMax and i > iterIgnore:
985 portUpDevNodeIter[0][i] = ptUpDeviceToOfp1
986 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
987 str(ptUpDeviceToOfp1)+" ms")
988 else:
989 main.log.info("iter"+str(i)+" skipped. Result: "+
990 str(ptUpDeviceToOfp1)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400991
andrewonlab79244cc2015-01-26 01:11:49 -0500992 if clusterCount >= 3:
993 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
994 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
995 jsonObj2 = json.loads( jsonStrUp2 )
996 jsonObj3 = json.loads( jsonStrUp3 )
997 graphTimestamp2 = \
998 jsonObj2[ graphTimestamp ][ 'value' ]
999 graphTimestamp3 = \
1000 jsonObj3[ graphTimestamp ][ 'value' ]
1001 deviceTimestamp2 = \
1002 jsonObj2[ deviceTimestamp ][ 'value' ]
1003 deviceTimestamp3 = \
1004 jsonObj3[ deviceTimestamp ][ 'value' ]
1005 ptUpGraphToOfp2 = int( graphTimestamp2 ) -\
1006 int( timestampBeginPtUp )
1007 ptUpGraphToOfp3 = int( graphTimestamp3 ) -\
1008 int( timestampBeginPtUp )
1009 ptUpDeviceToOfp2 = int( deviceTimestamp2 ) -\
1010 int( timestampBeginPtUp )
1011 ptUpDeviceToOfp3 = int( deviceTimestamp3 ) -\
1012 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001013
1014 if ptUpGraphToOfp2 > upThresholdMin and\
1015 ptUpGraphToOfp2 < upThresholdMax and i > iterIgnore:
1016 portUpGraphNodeIter[1][i] = ptUpGraphToOfp2
1017 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1018 str(ptUpGraphToOfp2)+" ms")
1019
1020 if ptUpDeviceToOfp2 > upThresholdMin and\
1021 ptUpDeviceToOfp2 < upThresholdMax and i > iterIgnore:
1022 portUpDevNodeIter[1][i] = ptUpDeviceToOfp2
1023 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1024 str(ptUpDeviceToOfp2)+" ms")
1025
1026 if ptUpGraphToOfp3 > upThresholdMin and\
1027 ptUpGraphToOfp3 < upThresholdMax and i > iterIgnore:
1028 portUpGraphNodeIter[2][i] = ptUpGraphToOfp3
1029 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1030 str(ptUpGraphToOfp3)+" ms")
1031
1032 if ptUpDeviceToOfp3 > upThresholdMin and\
1033 ptUpDeviceToOfp3 < upThresholdMax and i > iterIgnore:
1034 portUpDevNodeIter[2][i] = ptUpDeviceToOfp3
1035 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1036 str(ptUpDeviceToOfp3)+" ms")
andrewonlabb1998c52014-11-10 13:31:43 -05001037
andrewonlab79244cc2015-01-26 01:11:49 -05001038 if clusterCount >= 5:
1039 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
1040 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
1041 jsonObj4 = json.loads( jsonStrUp4 )
1042 jsonObj5 = json.loads( jsonStrUp5 )
1043 graphTimestamp4 = \
1044 jsonObj4[ graphTimestamp ][ 'value' ]
1045 graphTimestamp5 = \
1046 jsonObj5[ graphTimestamp ][ 'value' ]
1047 deviceTimestamp4 = \
1048 jsonObj4[ deviceTimestamp ][ 'value' ]
1049 deviceTimestamp5 = \
1050 jsonObj5[ deviceTimestamp ][ 'value' ]
1051 ptUpGraphToOfp4 = int( graphTimestamp4 ) -\
1052 int( timestampBeginPtUp )
1053 ptUpGraphToOfp5 = int( graphTimestamp5 ) -\
1054 int( timestampBeginPtUp )
1055 ptUpDeviceToOfp4 = int( deviceTimestamp4 ) -\
1056 int( timestampBeginPtUp )
1057 ptUpDeviceToOfp5 = int( deviceTimestamp5 ) -\
1058 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001059
1060 if ptUpGraphToOfp4 > upThresholdMin and\
1061 ptUpGraphToOfp4 < upThresholdMax and i > iterIgnore:
1062 portUpGraphNodeIter[3][i] = ptUpGraphToOfp4
1063 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1064 str(ptUpGraphToOfp4)+" ms")
1065
1066 if ptUpDeviceToOfp4 > upThresholdMin and\
1067 ptUpDeviceToOfp4 < upThresholdMax and i > iterIgnore:
1068 portUpDevNodeIter[3][i] = ptUpDeviceToOfp4
1069 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1070 str(ptUpDeviceToOfp4)+" ms")
1071
1072 if ptUpGraphToOfp5 > upThresholdMin and\
1073 ptUpGraphToOfp5 < upThresholdMax and i > iterIgnore:
1074 portUpGraphNodeIter[4][i] = ptUpGraphToOfp5
1075 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1076 str(ptUpGraphToOfp5)+" ms")
1077
1078 if ptUpDeviceToOfp5 > upThresholdMin and\
1079 ptUpDeviceToOfp5 < upThresholdMax and i > iterIgnore:
1080 portUpDevNodeIter[4][i] = ptUpDeviceToOfp5
1081 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1082 str(ptUpDeviceToOfp5)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001083
1084 if clusterCount >= 7:
1085 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
1086 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
1087 jsonObj6 = json.loads( jsonStrUp6 )
1088 jsonObj7 = json.loads( jsonStrUp7 )
1089 graphTimestamp6 = \
1090 jsonObj6[ graphTimestamp ][ 'value' ]
1091 graphTimestamp7 = \
1092 jsonObj7[ graphTimestamp ][ 'value' ]
1093 deviceTimestamp6 = \
1094 jsonObj6[ deviceTimestamp ][ 'value' ]
1095 deviceTimestamp7 = \
1096 jsonObj7[ deviceTimestamp ][ 'value' ]
1097 ptUpGraphToOfp6 = int( graphTimestamp6 ) -\
1098 int( timestampBeginPtUp )
1099 ptUpGraphToOfp7 = int( graphTimestamp7 ) -\
1100 int( timestampBeginPtUp )
1101 ptUpDeviceToOfp6 = int( deviceTimestamp6 ) -\
1102 int( timestampBeginPtUp )
1103 ptUpDeviceToOfp7 = int( deviceTimestamp7 ) -\
1104 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001105
1106 if ptUpGraphToOfp6 > upThresholdMin and\
1107 ptUpGraphToOfp6 < upThresholdMax and i > iterIgnore:
1108 portUpGraphNodeIter[5][i] = ptUpGraphToOfp6
1109 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1110 str(ptUpGraphToOfp6)+" ms")
1111
1112 if ptUpDeviceToOfp6 > upThresholdMin and\
1113 ptUpDeviceToOfp6 < upThresholdMax and i > iterIgnore:
1114 portUpDevNodeIter[5][i] = ptUpDeviceToOfp6
1115 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1116 str(ptUpDeviceToOfp6)+" ms")
1117
1118 if ptUpGraphToOfp7 > upThresholdMin and\
1119 ptUpGraphToOfp7 < upThresholdMax and i > iterIgnore:
1120 portUpGraphNodeIter[6][i] = ptUpGraphToOfp7
1121 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1122 str(ptUpGraphToOfp7)+" ms")
1123
1124 if ptUpDeviceToOfp7 > upThresholdMin and\
1125 ptUpDeviceToOfp7 < upThresholdMax and i > iterIgnore:
1126 portUpDevNodeIter[6][i] = ptUpDeviceToOfp7
1127 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1128 str(ptUpDeviceToOfp7)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001129
1130 # END ITERATION FOR LOOP
andrewonlabd5367a42015-01-30 14:46:17 -05001131
1132 portUpDevList = []
1133 portUpGraphList = []
1134 portDownDevList = []
1135 portDownGraphList = []
andrewonlab79244cc2015-01-26 01:11:49 -05001136
andrewonlabd5367a42015-01-30 14:46:17 -05001137 portUpDevAvg = 0
1138 portUpGraphAvg = 0
1139 portDownDevAvg = 0
1140 portDownGraphAvg = 0
andrewonlab8790abb2014-11-06 13:51:54 -05001141
andrewonlab86e9e082015-02-13 12:07:39 -05001142 dbCmdList = []
1143
andrewonlabd5367a42015-01-30 14:46:17 -05001144 for node in range( 0, clusterCount ):
andrewonlababb11c32014-11-04 15:03:24 -05001145
andrewonlabd5367a42015-01-30 14:46:17 -05001146 # NOTE:
1147 # Currently the 2d array is initialized with 0's.
1148 # We want to avoid skewing our results if the array
1149 # was not modified with the correct latency.
1150 for item in portUpDevNodeIter[node]:
1151 if item > 0.0:
1152 portUpDevList.append(item)
1153 for item in portUpGraphNodeIter[node]:
1154 if item > 0.0:
1155 portUpGraphList.append(item)
1156 for item in portDownDevNodeIter[node]:
1157 if item > 0.0:
1158 portDownDevList.append(item)
1159 for item in portDownGraphNodeIter[node]:
1160 if item > 0.0:
1161 portDownGraphList.append(item)
1162
andrewonlab86e9e082015-02-13 12:07:39 -05001163 portUpDevAvg = round(numpy.mean(portUpDevList), 2)
1164 portUpGraphAvg = round(numpy.mean(portUpGraphList), 2)
1165 portDownDevAvg = round(numpy.mean(portDownDevList), 2)
1166 portDownGraphAvg = round(numpy.mean(portDownGraphList), 2)
andrewonlab79244cc2015-01-26 01:11:49 -05001167
andrewonlabd5367a42015-01-30 14:46:17 -05001168 main.log.report( " - Node "+str(node+1)+" Summary - " )
1169 #main.log.report( " Port up ofp-to-device "+
1170 # str(round(portUpDevAvg, 2))+" ms")
1171 main.log.report( " Port up ofp-to-graph "+
andrewonlab86e9e082015-02-13 12:07:39 -05001172 str(portUpGraphAvg)+" ms")
andrewonlabd5367a42015-01-30 14:46:17 -05001173 #main.log.report( " Port down ofp-to-device "+
1174 # str(round(portDownDevAvg, 2))+" ms")
1175 main.log.report( " Port down ofp-to-graph "+
andrewonlab86e9e082015-02-13 12:07:39 -05001176 str(portDownGraphAvg)+" ms")
1177
1178 dbCmdList.append(
1179 "INSERT INTO port_latency_tests VALUES("
1180 "'"+timeToPost+"','port_latency_results',"
1181 ""+runNum+","+str(clusterCount)+",'baremetal"+str(node+1)+"',"
1182 ""+str(portUpGraphAvg)+",0,"+str(portDownGraphAvg)+",0);"
1183 )
1184
1185 #Write to file for posting to DB
1186 fResult = open(resultPath, 'a')
1187 for line in dbCmdList:
1188 if line:
1189 fResult.write(line+"\n")
1190 fResult.close()
andrewonlab79244cc2015-01-26 01:11:49 -05001191
1192 # Remove switches from controller for next test
1193 main.Mininet1.deleteSwController( "s1" )
1194 main.Mininet1.deleteSwController( "s2" )
1195
andrewonlabd5367a42015-01-30 14:46:17 -05001196 #TODO: correct assertion
1197
andrewonlab79244cc2015-01-26 01:11:49 -05001198 utilities.assert_equals(
1199 expect=main.TRUE,
1200 actual=assertion,
1201 onpass="Port discovery latency calculation successful",
1202 onfail="Port discovery test failed" )
1203
1204 def CASE4( self, main ):
1205 """
andrewonlab3622beb2014-10-28 16:07:56 -04001206 Link down event using loss rate 100%
andrewonlab79244cc2015-01-26 01:11:49 -05001207
andrewonlab53b641c2014-10-31 19:44:44 -04001208 Important:
1209 Use a simple 2 switch topology with 1 link between
andrewonlab79244cc2015-01-26 01:11:49 -05001210 the two switches. Ensure that mac addresses of the
andrewonlab53b641c2014-10-31 19:44:44 -04001211 switches are 1 / 2 respectively
andrewonlab79244cc2015-01-26 01:11:49 -05001212 """
andrewonlab3622beb2014-10-28 16:07:56 -04001213 import time
1214 import subprocess
1215 import os
1216 import requests
1217 import json
andrewonlab79244cc2015-01-26 01:11:49 -05001218 import numpy
andrewonlab3622beb2014-10-28 16:07:56 -04001219
andrewonlab79244cc2015-01-26 01:11:49 -05001220 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1221 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1222 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1223 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001224
andrewonlab79244cc2015-01-26 01:11:49 -05001225 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001226
andrewonlab79244cc2015-01-26 01:11:49 -05001227 # Number of iterations of case
1228 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001229
andrewonlab79244cc2015-01-26 01:11:49 -05001230 # Timestamp 'keys' for json metrics output.
1231 # These are subject to change, hence moved into params
1232 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1233 linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ]
1234 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001235
andrewonlab79244cc2015-01-26 01:11:49 -05001236 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001237
andrewonlab79244cc2015-01-26 01:11:49 -05001238 localTime = time.strftime( '%x %X' )
1239 localTime = localTime.replace( "/", "" )
1240 localTime = localTime.replace( " ", "_" )
1241 localTime = localTime.replace( ":", "" )
1242 if debugMode == 'on':
1243 main.ONOS1.tsharkPcap( "eth0",
1244 "/tmp/link_lat_pcap_" + localTime )
1245
1246 # Threshold for this test case
1247 upThresholdStr = main.params[ 'TEST' ][ 'linkUpThreshold' ]
1248 downThresholdStr = main.params[ 'TEST' ][ 'linkDownThreshold' ]
1249
1250 upThresholdObj = upThresholdStr.split( "," )
1251 downThresholdObj = downThresholdStr.split( "," )
1252
1253 upThresholdMin = int( upThresholdObj[ 0 ] )
1254 upThresholdMax = int( upThresholdObj[ 1 ] )
1255
1256 downThresholdMin = int( downThresholdObj[ 0 ] )
1257 downThresholdMax = int( downThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001258
andrewonlab3622beb2014-10-28 16:07:56 -04001259 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -05001260 # Link event timestamp to system time list
1261 linkDownLinkToSystemList = []
1262 linkUpLinkToSystemList = []
1263 # Graph event timestamp to system time list
1264 linkDownGraphToSystemList = []
1265 linkUpGraphToSystemList = []
andrewonlab3622beb2014-10-28 16:07:56 -04001266
andrewonlab79244cc2015-01-26 01:11:49 -05001267 main.log.report( "Link up / down discovery latency between " +
1268 "two switches" )
1269 main.log.report( "Simulated by setting loss-rate 100%" )
1270 main.log.report( "'tc qdisc add dev <intfs> root netem loss 100%'" )
1271 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab3622beb2014-10-28 16:07:56 -04001272
andrewonlab79244cc2015-01-26 01:11:49 -05001273 main.step( "Assign all switches" )
1274 main.Mininet1.assignSwController( sw="1",
1275 ip1=ONOS1Ip, port1=defaultSwPort )
1276 main.Mininet1.assignSwController( sw="2",
1277 ip1=ONOS1Ip, port1=defaultSwPort )
andrewonlab3622beb2014-10-28 16:07:56 -04001278
andrewonlab79244cc2015-01-26 01:11:49 -05001279 main.step( "Verifying switch assignment" )
1280 resultS1 = main.Mininet1.getSwController( sw="s1" )
1281 resultS2 = main.Mininet1.getSwController( sw="s2" )
andrewonlab3622beb2014-10-28 16:07:56 -04001282
andrewonlab79244cc2015-01-26 01:11:49 -05001283 # Allow time for events to finish before taking measurements
1284 time.sleep( 10 )
1285
1286 linkDown1 = False
1287 linkDown2 = False
1288 linkDown3 = False
1289 # Start iteration of link event test
1290 for i in range( 0, int( numIter ) ):
1291 main.step( "Getting initial system time as t0" )
1292
1293 # System time in epoch ms
1294 timestampLinkDownT0 = time.time() * 1000
1295 # Link down is simulated by 100% loss rate using traffic
1296 # control command
kelvin-onlab8a832582015-01-16 17:06:11 -08001297 main.Mininet1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001298 "sh tc qdisc add dev s1-eth1 root netem loss 100%" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001299
andrewonlab79244cc2015-01-26 01:11:49 -05001300 # TODO: Iterate through 'links' command to verify that
1301 # link s1 -> s2 went down ( loop timeout 30 seconds )
andrewonlababb11c32014-11-04 15:03:24 -05001302 # on all 3 ONOS instances
andrewonlab79244cc2015-01-26 01:11:49 -05001303 main.log.info( "Checking ONOS for link update" )
1304 loopCount = 0
1305 while( not ( linkDown1 and linkDown2 and linkDown3 )
1306 and loopCount < 30 ):
1307 jsonStr1 = main.ONOS1cli.links()
1308 jsonStr2 = main.ONOS2cli.links()
1309 jsonStr3 = main.ONOS3cli.links()
1310
1311 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1312 main.log.error( "CLI command returned error " )
andrewonlab53b641c2014-10-31 19:44:44 -04001313 break
1314 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001315 jsonObj1 = json.loads( jsonStr1 )
1316 jsonObj2 = json.loads( jsonStr2 )
1317 jsonObj3 = json.loads( jsonStr3 )
1318 for obj1 in jsonObj1:
1319 if '01' not in obj1[ 'src' ][ 'device' ]:
1320 linkDown1 = True
1321 main.log.info( "Link down from " +
1322 "s1 -> s2 on ONOS1 detected" )
1323 for obj2 in jsonObj2:
1324 if '01' not in obj2[ 'src' ][ 'device' ]:
1325 linkDown2 = True
1326 main.log.info( "Link down from " +
1327 "s1 -> s2 on ONOS2 detected" )
1328 for obj3 in jsonObj3:
1329 if '01' not in obj3[ 'src' ][ 'device' ]:
1330 linkDown3 = True
1331 main.log.info( "Link down from " +
1332 "s1 -> s2 on ONOS3 detected" )
1333
1334 loopCount += 1
1335 # If CLI doesn't like the continuous requests
1336 # and exits in this loop, increase the sleep here.
1337 # Consequently, while loop timeout will increase
1338 time.sleep( 1 )
1339
1340 # Give time for metrics measurement to catch up
1341 # NOTE: May need to be configured more accurately
1342 time.sleep( 10 )
1343 # If we exited the while loop and link down 1,2,3 are still
1344 # false, then ONOS has failed to discover link down event
1345 if not ( linkDown1 and linkDown2 and linkDown3 ):
1346 main.log.info( "Link down discovery failed" )
1347
1348 linkDownLatGraph1 = 0
1349 linkDownLatGraph2 = 0
1350 linkDownLatGraph3 = 0
1351 linkDownLatDevice1 = 0
1352 linkDownLatDevice2 = 0
1353 linkDownLatDevice3 = 0
1354
andrewonlab53b641c2014-10-31 19:44:44 -04001355 assertion = main.FALSE
1356 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001357 jsonTopoMetrics1 =\
1358 main.ONOS1cli.topologyEventsMetrics()
1359 jsonTopoMetrics2 =\
1360 main.ONOS2cli.topologyEventsMetrics()
1361 jsonTopoMetrics3 =\
1362 main.ONOS3cli.topologyEventsMetrics()
1363 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1364 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1365 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlab53b641c2014-10-31 19:44:44 -04001366
andrewonlab79244cc2015-01-26 01:11:49 -05001367 main.log.info( "Obtaining graph and device timestamp" )
1368 graphTimestamp1 = \
1369 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1370 graphTimestamp2 = \
1371 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1372 graphTimestamp3 = \
1373 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001374
andrewonlab79244cc2015-01-26 01:11:49 -05001375 linkTimestamp1 = \
1376 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1377 linkTimestamp2 = \
1378 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1379 linkTimestamp3 = \
1380 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001381
andrewonlab79244cc2015-01-26 01:11:49 -05001382 if graphTimestamp1 and graphTimestamp2 and\
1383 graphTimestamp3 and linkTimestamp1 and\
1384 linkTimestamp2 and linkTimestamp3:
1385 linkDownLatGraph1 = int( graphTimestamp1 ) -\
1386 int( timestampLinkDownT0 )
1387 linkDownLatGraph2 = int( graphTimestamp2 ) -\
1388 int( timestampLinkDownT0 )
1389 linkDownLatGraph3 = int( graphTimestamp3 ) -\
1390 int( timestampLinkDownT0 )
1391
1392 linkDownLatLink1 = int( linkTimestamp1 ) -\
1393 int( timestampLinkDownT0 )
1394 linkDownLatLink2 = int( linkTimestamp2 ) -\
1395 int( timestampLinkDownT0 )
1396 linkDownLatLink3 = int( linkTimestamp3 ) -\
1397 int( timestampLinkDownT0 )
andrewonlab53b641c2014-10-31 19:44:44 -04001398 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001399 main.log.error( "There was an error calculating" +
1400 " the delta for link down event" )
1401 linkDownLatGraph1 = 0
1402 linkDownLatGraph2 = 0
1403 linkDownLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001404
andrewonlab79244cc2015-01-26 01:11:49 -05001405 linkDownLatDevice1 = 0
1406 linkDownLatDevice2 = 0
1407 linkDownLatDevice3 = 0
andrewonlab53b641c2014-10-31 19:44:44 -04001408
andrewonlab79244cc2015-01-26 01:11:49 -05001409 main.log.info( "Link down latency ONOS1 iteration " +
1410 str( i ) + " (end-to-end): " +
1411 str( linkDownLatGraph1 ) + " ms" )
1412 main.log.info( "Link down latency ONOS2 iteration " +
1413 str( i ) + " (end-to-end): " +
1414 str( linkDownLatGraph2 ) + " ms" )
1415 main.log.info( "Link down latency ONOS3 iteration " +
1416 str( i ) + " (end-to-end): " +
1417 str( linkDownLatGraph3 ) + " ms" )
1418
1419 main.log.info( "Link down latency ONOS1 iteration " +
1420 str( i ) + " (link-event-to-system-timestamp): " +
1421 str( linkDownLatLink1 ) + " ms" )
1422 main.log.info( "Link down latency ONOS2 iteration " +
1423 str( i ) + " (link-event-to-system-timestamp): " +
1424 str( linkDownLatLink2 ) + " ms" )
1425 main.log.info( "Link down latency ONOS3 iteration " +
1426 str( i ) + " (link-event-to-system-timestamp): " +
1427 str( linkDownLatLink3 ) )
1428
1429 # Calculate avg of node calculations
1430 linkDownLatGraphAvg =\
1431 ( linkDownLatGraph1 +
1432 linkDownLatGraph2 +
1433 linkDownLatGraph3 ) / 3
1434 linkDownLatLinkAvg =\
1435 ( linkDownLatLink1 +
1436 linkDownLatLink2 +
1437 linkDownLatLink3 ) / 3
1438
1439 # Set threshold and append latency to list
1440 if linkDownLatGraphAvg > downThresholdMin and\
1441 linkDownLatGraphAvg < downThresholdMax:
1442 linkDownGraphToSystemList.append(
1443 linkDownLatGraphAvg )
1444 else:
1445 main.log.info( "Link down latency exceeded threshold" )
1446 main.log.info( "Results for iteration " + str( i ) +
1447 "have been omitted" )
1448 if linkDownLatLinkAvg > downThresholdMin and\
1449 linkDownLatLinkAvg < downThresholdMax:
1450 linkDownLinkToSystemList.append(
1451 linkDownLatLinkAvg )
1452 else:
1453 main.log.info( "Link down latency exceeded threshold" )
1454 main.log.info( "Results for iteration " + str( i ) +
1455 "have been omitted" )
1456
1457 # NOTE: To remove loss rate and measure latency:
andrewonlab53b641c2014-10-31 19:44:44 -04001458 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlab79244cc2015-01-26 01:11:49 -05001459 timestampLinkUpT0 = time.time() * 1000
1460 main.Mininet1.handle.sendline( "sh tc qdisc del dev " +
1461 "s1-eth1 root" )
1462 main.Mininet1.handle.expect( "mininet>" )
1463
1464 main.log.info( "Checking ONOS for link update" )
1465
1466 linkDown1 = True
1467 linkDown2 = True
1468 linkDown3 = True
1469 loopCount = 0
1470 while( ( linkDown1 and linkDown2 and linkDown3 )
1471 and loopCount < 30 ):
1472 jsonStr1 = main.ONOS1cli.links()
1473 jsonStr2 = main.ONOS2cli.links()
1474 jsonStr3 = main.ONOS3cli.links()
1475 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1476 main.log.error( "CLI command returned error " )
andrewonlababb11c32014-11-04 15:03:24 -05001477 break
1478 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001479 jsonObj1 = json.loads( jsonStr1 )
1480 jsonObj2 = json.loads( jsonStr2 )
1481 jsonObj3 = json.loads( jsonStr3 )
1482
1483 for obj1 in jsonObj1:
1484 if '01' in obj1[ 'src' ][ 'device' ]:
1485 linkDown1 = False
1486 main.log.info( "Link up from " +
1487 "s1 -> s2 on ONOS1 detected" )
1488 for obj2 in jsonObj2:
1489 if '01' in obj2[ 'src' ][ 'device' ]:
1490 linkDown2 = False
1491 main.log.info( "Link up from " +
1492 "s1 -> s2 on ONOS2 detected" )
1493 for obj3 in jsonObj3:
1494 if '01' in obj3[ 'src' ][ 'device' ]:
1495 linkDown3 = False
1496 main.log.info( "Link up from " +
1497 "s1 -> s2 on ONOS3 detected" )
1498
1499 loopCount += 1
1500 time.sleep( 1 )
1501
1502 if ( linkDown1 and linkDown2 and linkDown3 ):
1503 main.log.info( "Link up discovery failed" )
1504
1505 linkUpLatGraph1 = 0
1506 linkUpLatGraph2 = 0
1507 linkUpLatGraph3 = 0
1508 linkUpLatDevice1 = 0
1509 linkUpLatDevice2 = 0
1510 linkUpLatDevice3 = 0
1511
andrewonlababb11c32014-11-04 15:03:24 -05001512 assertion = main.FALSE
1513 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001514 jsonTopoMetrics1 =\
1515 main.ONOS1cli.topologyEventsMetrics()
1516 jsonTopoMetrics2 =\
1517 main.ONOS2cli.topologyEventsMetrics()
1518 jsonTopoMetrics3 =\
1519 main.ONOS3cli.topologyEventsMetrics()
1520 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1521 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1522 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlababb11c32014-11-04 15:03:24 -05001523
andrewonlab79244cc2015-01-26 01:11:49 -05001524 main.log.info( "Obtaining graph and device timestamp" )
1525 graphTimestamp1 = \
1526 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1527 graphTimestamp2 = \
1528 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1529 graphTimestamp3 = \
1530 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001531
andrewonlab79244cc2015-01-26 01:11:49 -05001532 linkTimestamp1 = \
1533 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1534 linkTimestamp2 = \
1535 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1536 linkTimestamp3 = \
1537 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001538
andrewonlab79244cc2015-01-26 01:11:49 -05001539 if graphTimestamp1 and graphTimestamp2 and\
1540 graphTimestamp3 and linkTimestamp1 and\
1541 linkTimestamp2 and linkTimestamp3:
1542 linkUpLatGraph1 = int( graphTimestamp1 ) -\
1543 int( timestampLinkUpT0 )
1544 linkUpLatGraph2 = int( graphTimestamp2 ) -\
1545 int( timestampLinkUpT0 )
1546 linkUpLatGraph3 = int( graphTimestamp3 ) -\
1547 int( timestampLinkUpT0 )
1548
1549 linkUpLatLink1 = int( linkTimestamp1 ) -\
1550 int( timestampLinkUpT0 )
1551 linkUpLatLink2 = int( linkTimestamp2 ) -\
1552 int( timestampLinkUpT0 )
1553 linkUpLatLink3 = int( linkTimestamp3 ) -\
1554 int( timestampLinkUpT0 )
andrewonlababb11c32014-11-04 15:03:24 -05001555 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001556 main.log.error( "There was an error calculating" +
1557 " the delta for link down event" )
1558 linkUpLatGraph1 = 0
1559 linkUpLatGraph2 = 0
1560 linkUpLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001561
andrewonlab79244cc2015-01-26 01:11:49 -05001562 linkUpLatDevice1 = 0
1563 linkUpLatDevice2 = 0
1564 linkUpLatDevice3 = 0
1565
1566 if debugMode == 'on':
1567 main.log.info( "Link up latency ONOS1 iteration " +
1568 str( i ) + " (end-to-end): " +
1569 str( linkUpLatGraph1 ) + " ms" )
1570 main.log.info( "Link up latency ONOS2 iteration " +
1571 str( i ) + " (end-to-end): " +
1572 str( linkUpLatGraph2 ) + " ms" )
1573 main.log.info( "Link up latency ONOS3 iteration " +
1574 str( i ) + " (end-to-end): " +
1575 str( linkUpLatGraph3 ) + " ms" )
1576
1577 main.log.info(
1578 "Link up latency ONOS1 iteration " +
1579 str( i ) +
1580 " (link-event-to-system-timestamp): " +
1581 str( linkUpLatLink1 ) +
1582 " ms" )
1583 main.log.info(
1584 "Link up latency ONOS2 iteration " +
1585 str( i ) +
1586 " (link-event-to-system-timestamp): " +
1587 str( linkUpLatLink2 ) +
1588 " ms" )
1589 main.log.info(
1590 "Link up latency ONOS3 iteration " +
1591 str( i ) +
1592 " (link-event-to-system-timestamp): " +
1593 str( linkUpLatLink3 ) )
1594
1595 # Calculate avg of node calculations
1596 linkUpLatGraphAvg =\
1597 ( linkUpLatGraph1 +
1598 linkUpLatGraph2 +
1599 linkUpLatGraph3 ) / 3
1600 linkUpLatLinkAvg =\
1601 ( linkUpLatLink1 +
1602 linkUpLatLink2 +
1603 linkUpLatLink3 ) / 3
1604
1605 # Set threshold and append latency to list
1606 if linkUpLatGraphAvg > upThresholdMin and\
1607 linkUpLatGraphAvg < upThresholdMax:
1608 linkUpGraphToSystemList.append(
1609 linkUpLatGraphAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001610 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001611 main.log.info( "Link up latency exceeded threshold" )
1612 main.log.info( "Results for iteration " + str( i ) +
1613 "have been omitted" )
1614 if linkUpLatLinkAvg > upThresholdMin and\
1615 linkUpLatLinkAvg < upThresholdMax:
1616 linkUpLinkToSystemList.append(
1617 linkUpLatLinkAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001618 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001619 main.log.info( "Link up latency exceeded threshold" )
1620 main.log.info( "Results for iteration " + str( i ) +
1621 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001622
andrewonlab79244cc2015-01-26 01:11:49 -05001623 # Calculate min, max, avg of list and report
1624 linkDownMin = min( linkDownGraphToSystemList )
1625 linkDownMax = max( linkDownGraphToSystemList )
1626 linkDownAvg = sum( linkDownGraphToSystemList ) / \
1627 len( linkDownGraphToSystemList )
1628 linkUpMin = min( linkUpGraphToSystemList )
1629 linkUpMax = max( linkUpGraphToSystemList )
1630 linkUpAvg = sum( linkUpGraphToSystemList ) / \
1631 len( linkUpGraphToSystemList )
1632 linkDownStdDev = \
1633 str( round( numpy.std( linkDownGraphToSystemList ), 1 ) )
1634 linkUpStdDev = \
1635 str( round( numpy.std( linkUpGraphToSystemList ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001636
andrewonlab79244cc2015-01-26 01:11:49 -05001637 main.log.report( "Link down latency " +
1638 "Avg: " + str( linkDownAvg ) + " ms " +
1639 "Std Deviation: " + linkDownStdDev + " ms" )
1640 main.log.report( "Link up latency " +
1641 "Avg: " + str( linkUpAvg ) + " ms " +
1642 "Std Deviation: " + linkUpStdDev + " ms" )
andrewonlab4e124482014-11-04 13:37:25 -05001643
andrewonlab79244cc2015-01-26 01:11:49 -05001644 utilities.assert_equals(
1645 expect=main.TRUE,
1646 actual=assertion,
1647 onpass="Link discovery latency calculation successful",
1648 onfail="Link discovery latency case failed" )
andrewonlab8790abb2014-11-06 13:51:54 -05001649
andrewonlab79244cc2015-01-26 01:11:49 -05001650 def CASE5( self, main ):
1651 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001652 100 Switch discovery latency
1653
1654 Important:
andrewonlab79244cc2015-01-26 01:11:49 -05001655 This test case can be potentially dangerous if
andrewonlab16ce4852014-10-30 13:41:09 -04001656 your machine has previously set iptables rules.
1657 One of the steps of the test case will flush
1658 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001659 Note:
andrewonlab79244cc2015-01-26 01:11:49 -05001660 You can specify the number of switches in the
andrewonlab8790abb2014-11-06 13:51:54 -05001661 params file to adjust the switch discovery size
andrewonlab79244cc2015-01-26 01:11:49 -05001662 ( and specify the corresponding topology in Mininet1
1663 .topo file )
1664 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001665 import time
1666 import subprocess
1667 import os
1668 import requests
1669 import json
1670
andrewonlab79244cc2015-01-26 01:11:49 -05001671 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1672 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1673 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1674 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
1675 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlabb54b85b2014-10-28 18:43:57 -04001676
andrewonlab79244cc2015-01-26 01:11:49 -05001677 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001678
andrewonlab79244cc2015-01-26 01:11:49 -05001679 # Number of iterations of case
1680 numIter = main.params[ 'TEST' ][ 'numIter' ]
1681 numSw = main.params[ 'TEST' ][ 'numSwitch' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001682
andrewonlab79244cc2015-01-26 01:11:49 -05001683 # Timestamp 'keys' for json metrics output.
1684 # These are subject to change, hence moved into params
1685 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1686 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001687
andrewonlab79244cc2015-01-26 01:11:49 -05001688 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001689
andrewonlab79244cc2015-01-26 01:11:49 -05001690 localTime = time.strftime( '%X' )
1691 localTime = localTime.replace( "/", "" )
1692 localTime = localTime.replace( " ", "_" )
1693 localTime = localTime.replace( ":", "" )
1694 if debugMode == 'on':
1695 main.ONOS1.tsharkPcap( "eth0",
1696 "/tmp/100_sw_lat_pcap_" + localTime )
andrewonlabb54b85b2014-10-28 18:43:57 -04001697
andrewonlab79244cc2015-01-26 01:11:49 -05001698 # Threshold for this test case
1699 swDiscThresholdStr = main.params[ 'TEST' ][ 'swDisc100Threshold' ]
1700 swDiscThresholdObj = swDiscThresholdStr.split( "," )
1701 swDiscThresholdMin = int( swDiscThresholdObj[ 0 ] )
1702 swDiscThresholdMax = int( swDiscThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001703
andrewonlab79244cc2015-01-26 01:11:49 -05001704 tsharkOfpOutput = "/tmp/tshark_ofp_" + numSw + "sw.txt"
1705 tsharkTcpOutput = "/tmp/tshark_tcp_" + numSw + "sw.txt"
andrewonlabb54b85b2014-10-28 18:43:57 -04001706
andrewonlab79244cc2015-01-26 01:11:49 -05001707 tsharkOfpResultList = []
1708 tsharkTcpResultList = []
1709
1710 swDiscoveryLatList = []
1711
1712 main.case( numSw + " Switch discovery latency" )
1713 main.step( "Assigning all switches to ONOS1" )
1714 for i in range( 1, int( numSw ) + 1 ):
1715 main.Mininet1.assignSwController(
1716 sw=str( i ),
1717 ip1=ONOS1Ip,
1718 port1=defaultSwPort )
1719
1720 # Ensure that nodes are configured with ptpd
1721 # Just a warning message
1722 main.log.info( "Please check ptpd configuration to ensure" +
1723 " All nodes' system times are in sync" )
1724 time.sleep( 5 )
1725
1726 for i in range( 0, int( numIter ) ):
1727
1728 main.step( "Set iptables rule to block incoming sw connections" )
1729 # Set iptables rule to block incoming switch connections
1730 # The rule description is as follows:
andrewonlab53b641c2014-10-31 19:44:44 -04001731 # Append to INPUT rule,
1732 # behavior DROP that matches following:
1733 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001734 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001735 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001736 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001737 "sudo iptables -A INPUT -p tcp -s " + MN1Ip +
1738 " --dport " + defaultSwPort + " -j DROP" )
1739 main.ONOS1.handle.expect( "\$" )
1740 # Append to OUTPUT rule,
andrewonlab53b641c2014-10-31 19:44:44 -04001741 # behavior DROP that matches following:
1742 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001743 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001744 # * destination PORT: 6633
1745 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001746 "sudo iptables -A OUTPUT -p tcp -s " + MN1Ip +
1747 " --dport " + defaultSwPort + " -j DROP" )
1748 main.ONOS1.handle.expect( "\$" )
1749 # Give time to allow rule to take effect
1750 # NOTE: Sleep period may need to be configured
andrewonlab8790abb2014-11-06 13:51:54 -05001751 # based on the number of switches in the topology
andrewonlab79244cc2015-01-26 01:11:49 -05001752 main.log.info( "Please wait for switch connection to " +
1753 "time out" )
1754 time.sleep( 60 )
andrewonlabb54b85b2014-10-28 18:43:57 -04001755
andrewonlab79244cc2015-01-26 01:11:49 -05001756 # Gather vendor OFP with tshark
1757 main.ONOS1.tsharkGrep( "OFP 86 Vendor",
1758 tsharkOfpOutput )
1759 main.ONOS1.tsharkGrep( "TCP 74 ",
1760 tsharkTcpOutput )
1761
1762 # NOTE: Remove all iptables rule quickly ( flush )
1763 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001764 # removal took place
andrewonlab79244cc2015-01-26 01:11:49 -05001765 # ( ensuring nodes are configured via ptp )
andrewonlabb54b85b2014-10-28 18:43:57 -04001766 # sudo iptables -F
andrewonlab79244cc2015-01-26 01:11:49 -05001767
1768 t0System = time.time() * 1000
andrewonlab16ce4852014-10-30 13:41:09 -04001769 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001770 "sudo iptables -F" )
andrewonlabb54b85b2014-10-28 18:43:57 -04001771
andrewonlab79244cc2015-01-26 01:11:49 -05001772 # Counter to track loop count
1773 counterLoop = 0
1774 counterAvail1 = 0
1775 counterAvail2 = 0
1776 counterAvail3 = 0
1777 onos1Dev = False
1778 onos2Dev = False
1779 onos3Dev = False
1780 while counterLoop < 60:
1781 # Continue to check devices for all device
1782 # availability. When all devices in all 3
1783 # ONOS instances indicate that devices are available
1784 # obtain graph event timestamp for t1.
1785 deviceStrObj1 = main.ONOS1cli.devices()
1786 deviceStrObj2 = main.ONOS2cli.devices()
1787 deviceStrObj3 = main.ONOS3cli.devices()
andrewonlab16ce4852014-10-30 13:41:09 -04001788
andrewonlab79244cc2015-01-26 01:11:49 -05001789 deviceJson1 = json.loads( deviceStrObj1 )
1790 deviceJson2 = json.loads( deviceStrObj2 )
1791 deviceJson3 = json.loads( deviceStrObj3 )
1792
1793 for device1 in deviceJson1:
1794 if device1[ 'available' ]:
1795 counterAvail1 += 1
1796 if counterAvail1 == int( numSw ):
1797 onos1Dev = True
1798 main.log.info( "All devices have been " +
1799 "discovered on ONOS1" )
andrewonlab16ce4852014-10-30 13:41:09 -04001800 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001801 counterAvail1 = 0
1802 for device2 in deviceJson2:
1803 if device2[ 'available' ]:
1804 counterAvail2 += 1
1805 if counterAvail2 == int( numSw ):
1806 onos2Dev = True
1807 main.log.info( "All devices have been " +
1808 "discovered on ONOS2" )
andrewonlab16ce4852014-10-30 13:41:09 -04001809 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001810 counterAvail2 = 0
1811 for device3 in deviceJson3:
1812 if device3[ 'available' ]:
1813 counterAvail3 += 1
1814 if counterAvail3 == int( numSw ):
1815 onos3Dev = True
1816 main.log.info( "All devices have been " +
1817 "discovered on ONOS3" )
andrewonlab16ce4852014-10-30 13:41:09 -04001818 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001819 counterAvail3 = 0
andrewonlab16ce4852014-10-30 13:41:09 -04001820
andrewonlab79244cc2015-01-26 01:11:49 -05001821 if onos1Dev and onos2Dev and onos3Dev:
1822 main.log.info( "All devices have been discovered " +
1823 "on all ONOS instances" )
1824 jsonStrTopologyMetrics1 =\
1825 main.ONOS1cli.topologyEventsMetrics()
1826 jsonStrTopologyMetrics2 =\
1827 main.ONOS2cli.topologyEventsMetrics()
1828 jsonStrTopologyMetrics3 =\
1829 main.ONOS3cli.topologyEventsMetrics()
andrewonlab16ce4852014-10-30 13:41:09 -04001830
andrewonlab79244cc2015-01-26 01:11:49 -05001831 # Exit while loop if all devices discovered
1832 break
andrewonlab16ce4852014-10-30 13:41:09 -04001833
andrewonlab79244cc2015-01-26 01:11:49 -05001834 counterLoop += 1
1835 # Give some time in between CLI calls
1836 #( will not affect measurement )
1837 time.sleep( 3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001838
andrewonlab79244cc2015-01-26 01:11:49 -05001839 main.ONOS1.tsharkStop()
andrewonlab53b641c2014-10-31 19:44:44 -04001840
andrewonlab79244cc2015-01-26 01:11:49 -05001841 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1842 tsharkOfpOutput + " /tmp/" )
1843 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1844 tsharkTcpOutput + " /tmp/" )
andrewonlab16ce4852014-10-30 13:41:09 -04001845
andrewonlab79244cc2015-01-26 01:11:49 -05001846 # TODO: Automate OFP output analysis
1847 # Debug mode - print out packets captured at runtime
1848 if debugMode == 'on':
1849 ofpFile = open( tsharkOfpOutput, 'r' )
1850 main.log.info( "Tshark OFP Vendor output: " )
1851 for line in ofpFile:
1852 tsharkOfpResultList.append( line )
1853 main.log.info( line )
1854 ofpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001855
andrewonlab79244cc2015-01-26 01:11:49 -05001856 tcpFile = open( tsharkTcpOutput, 'r' )
1857 main.log.info( "Tshark TCP 74 output: " )
1858 for line in tcpFile:
1859 tsharkTcpResultList.append( line )
1860 main.log.info( line )
1861 tcpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001862
andrewonlab79244cc2015-01-26 01:11:49 -05001863 jsonObj1 = json.loads( jsonStrTopologyMetrics1 )
1864 jsonObj2 = json.loads( jsonStrTopologyMetrics2 )
1865 jsonObj3 = json.loads( jsonStrTopologyMetrics3 )
1866
1867 graphTimestamp1 = \
1868 jsonObj1[ graphTimestamp ][ 'value' ]
1869 graphTimestamp2 = \
1870 jsonObj2[ graphTimestamp ][ 'value' ]
1871 graphTimestamp3 = \
1872 jsonObj3[ graphTimestamp ][ 'value' ]
1873
1874 graphLat1 = int( graphTimestamp1 ) - int( t0System )
1875 graphLat2 = int( graphTimestamp2 ) - int( t0System )
1876 graphLat3 = int( graphTimestamp3 ) - int( t0System )
1877
1878 avgGraphLat = \
1879 ( int( graphLat1 ) +
1880 int( graphLat2 ) +
1881 int( graphLat3 ) ) / 3
1882
1883 if avgGraphLat > swDiscThresholdMin \
1884 and avgGraphLat < swDiscThresholdMax:
1885 swDiscoveryLatList.append(
1886 avgGraphLat )
andrewonlabe5bcef92014-11-06 17:53:20 -05001887 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001888 main.log.info( "100 Switch discovery latency " +
1889 "exceeded the threshold." )
andrewonlab16ce4852014-10-30 13:41:09 -04001890
andrewonlab79244cc2015-01-26 01:11:49 -05001891 # END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001892
andrewonlab79244cc2015-01-26 01:11:49 -05001893 swLatMin = min( swDiscoveryLatList )
1894 swLatMax = max( swDiscoveryLatList )
1895 swLatAvg = sum( swDiscoveryLatList ) /\
1896 len( swDiscoveryLatList )
andrewonlab16ce4852014-10-30 13:41:09 -04001897
andrewonlab79244cc2015-01-26 01:11:49 -05001898 main.log.report( "100 Switch discovery lat " +
1899 "Min: " + str( swLatMin ) + " ms" +
1900 "Max: " + str( swLatMax ) + " ms" +
1901 "Avg: " + str( swLatAvg ) + " ms" )
1902
1903 def CASE6( self, main ):
1904 """
andrewonlaba57a3042015-01-23 13:53:05 -05001905 Increase number of nodes and initiate CLI
andrewonlab79244cc2015-01-26 01:11:49 -05001906 """
andrewonlaba57a3042015-01-23 13:53:05 -05001907 import time
andrewonlaba57a3042015-01-23 13:53:05 -05001908
andrewonlab79244cc2015-01-26 01:11:49 -05001909 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1910 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1911 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1912 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
1913 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
1914 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
1915 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001916
andrewonlab79244cc2015-01-26 01:11:49 -05001917 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001918
andrewonlab79244cc2015-01-26 01:11:49 -05001919 global clusterCount
andrewonlaba57a3042015-01-23 13:53:05 -05001920
andrewonlab79244cc2015-01-26 01:11:49 -05001921 # Cluster size increased everytime the case is defined
1922 clusterCount += 2
andrewonlaba57a3042015-01-23 13:53:05 -05001923
andrewonlab79244cc2015-01-26 01:11:49 -05001924 main.log.report( "Increasing cluster size to " +
1925 str( clusterCount ) )
andrewonlaba57a3042015-01-23 13:53:05 -05001926
andrewonlab79244cc2015-01-26 01:11:49 -05001927 installResult = main.FALSE
1928 if clusterCount == 3:
1929 main.log.info( "Installing nodes 2 and 3" )
1930 node2Result = \
1931 main.ONOSbench.onosInstall( node=ONOS2Ip )
1932 node3Result = \
1933 main.ONOSbench.onosInstall( node=ONOS3Ip )
1934 installResult = node2Result and node3Result
andrewonlaba57a3042015-01-23 13:53:05 -05001935
andrewonlab79244cc2015-01-26 01:11:49 -05001936 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001937
andrewonlab79244cc2015-01-26 01:11:49 -05001938 main.ONOS2cli.startOnosCli( ONOS2Ip )
1939 main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001940
andrewonlab79244cc2015-01-26 01:11:49 -05001941 elif clusterCount == 5:
1942 main.log.info( "Installing nodes 4 and 5" )
1943 node4Result = \
1944 main.ONOSbench.onosInstall( node=ONOS4Ip )
1945 node5Result = \
1946 main.ONOSbench.onosInstall( node=ONOS5Ip )
1947 installResult = node4Result and node5Result
andrewonlaba57a3042015-01-23 13:53:05 -05001948
andrewonlab79244cc2015-01-26 01:11:49 -05001949 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001950
andrewonlab79244cc2015-01-26 01:11:49 -05001951 main.ONOS4cli.startOnosCli( ONOS4Ip )
1952 main.ONOS5cli.startOnosCli( ONOS5Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001953
andrewonlab79244cc2015-01-26 01:11:49 -05001954 elif clusterCount == 7:
andrewonlab67630692015-01-29 20:16:01 -05001955 main.log.info( "Installing nodes 6 and 7" )
andrewonlab79244cc2015-01-26 01:11:49 -05001956 node6Result = \
1957 main.ONOSbench.onosInstall( node=ONOS6Ip )
1958 node7Result = \
1959 main.ONOSbench.onosInstall( node=ONOS7Ip )
1960 installResult = node6Result and node7Result
andrewonlaba57a3042015-01-23 13:53:05 -05001961
andrewonlab79244cc2015-01-26 01:11:49 -05001962 time.sleep( 5 )
1963
1964 main.ONOS6cli.startOnosCli( ONOS6Ip )
1965 main.ONOS7cli.startOnosCli( ONOS7Ip )