blob: 87d7378a94133fc5f39648558309fec746ffa0ce [file] [log] [blame]
kelvin-onlab8a832582015-01-16 17:06:11 -08001# TopoPerfNext
andrewonlab2a6c9342014-10-16 13:40:15 -04002#
kelvin-onlab8a832582015-01-16 17:06:11 -08003# Topology Performance test for ONOS-next
andrewonlab2a6c9342014-10-16 13:40:15 -04004#
kelvin-onlab8a832582015-01-16 17:06:11 -08005# andrew@onlab.us
andrewonlab4f50ec92014-11-11 14:24:45 -05006#
kelvin-onlab8a832582015-01-16 17:06:11 -08007# 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
kelvin-onlab8a832582015-01-16 17:06:11 -080016
andrewonlab2a6c9342014-10-16 13:40:15 -040017class TopoPerfNext:
kelvin-onlab8a832582015-01-16 17:06:11 -080018
19 def __init__( self ):
andrewonlab2a6c9342014-10-16 13:40:15 -040020 self.default = ''
21
kelvin-onlab8a832582015-01-16 17:06:11 -080022 def CASE1( self, main ):
23 """
andrewonlab2a6c9342014-10-16 13:40:15 -040024 ONOS startup sequence
kelvin-onlab8a832582015-01-16 17:06:11 -080025 """
andrewonlabe9fb6722014-10-24 12:20:35 -040026 import time
andrewonlab2a6c9342014-10-16 13:40:15 -040027
kelvin-onlab8a832582015-01-16 17:06:11 -080028 cell_name = main.params[ 'ENV' ][ 'cellName' ]
andrewonlab2a6c9342014-10-16 13:40:15 -040029
kelvin-onlab8a832582015-01-16 17:06:11 -080030 git_pull = main.params[ 'GIT' ][ 'autoPull' ]
31 checkout_branch = main.params[ 'GIT' ][ 'checkout' ]
32
33 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
34 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
35 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
36
andrewonlab6c8bbeb2014-11-14 12:43:48 -050037 #### Hardcoded ONOS nodes particular to my env ####
38 ONOS4_ip = "10.128.174.4"
39 ONOS5_ip = "10.128.174.5"
40 ONOS6_ip = "10.128.174.6"
41 ONOS7_ip = "10.128.174.7"
42 #### ####
43
kelvin-onlab8a832582015-01-16 17:06:11 -080044 MN1_ip = main.params[ 'MN' ][ 'ip1' ]
45 BENCH_ip = main.params[ 'BENCH' ][ 'ip' ]
andrewonlab2a6c9342014-10-16 13:40:15 -040046
kelvin-onlab8a832582015-01-16 17:06:11 -080047 topo_cfg_file = main.params[ 'TEST' ][ 'topo_config_file' ]
48 topo_cfg_name = main.params[ 'TEST' ][ 'topo_config_name' ]
andrewonlab0e1825c2014-11-20 20:07:00 -050049
kelvin-onlab8a832582015-01-16 17:06:11 -080050 main.case( "Setting up test environment" )
51 main.log.info( "Copying topology event accumulator config" +
52 " to ONOS /package/etc" )
53 main.ONOSbench.handle.sendline( "cp ~/" +
54 topo_cfg_file +
55 " ~/ONOS/tools/package/etc/" +
56 topo_cfg_name )
57 main.ONOSbench.handle.expect( "\$" )
andrewonlab2a6c9342014-10-16 13:40:15 -040058
kelvin-onlab8a832582015-01-16 17:06:11 -080059 main.log.report( "Setting up test environment" )
andrewonlab6c8bbeb2014-11-14 12:43:48 -050060
kelvin-onlab8a832582015-01-16 17:06:11 -080061 main.step( "Cleaning previously installed ONOS if any" )
62 main.ONOSbench.onos_uninstall( node_ip=ONOS4_ip )
63 main.ONOSbench.onos_uninstall( node_ip=ONOS5_ip )
64 main.ONOSbench.onos_uninstall( node_ip=ONOS6_ip )
65 main.ONOSbench.onos_uninstall( node_ip=ONOS7_ip )
66
67 main.step( "Creating cell file" )
andrewonlab2a6c9342014-10-16 13:40:15 -040068 cell_file_result = main.ONOSbench.create_cell_file(
kelvin-onlab8a832582015-01-16 17:06:11 -080069 BENCH_ip, cell_name, MN1_ip, "onos-core,onos-app-metrics",
70 ONOS1_ip, ONOS2_ip, ONOS3_ip )
andrewonlab2a6c9342014-10-16 13:40:15 -040071
kelvin-onlab8a832582015-01-16 17:06:11 -080072 main.step( "Applying cell file to environment" )
73 cell_apply_result = main.ONOSbench.set_cell( cell_name )
andrewonlab2a6c9342014-10-16 13:40:15 -040074 verify_cell_result = main.ONOSbench.verify_cell()
andrewonlab28b84eb2014-12-02 15:53:35 -050075
kelvin-onlab8a832582015-01-16 17:06:11 -080076 # NOTE: This step may be removed after proper
77 # copy cat log functionality
78 main.step( "Removing raft/copy-cat logs from ONOS nodes" )
79 main.ONOSbench.onos_remove_raft_logs()
80 time.sleep( 30 )
81
82 main.step( "Git checkout and pull " + checkout_branch )
andrewonlab2a6c9342014-10-16 13:40:15 -040083 if git_pull == 'on':
84 checkout_result = \
kelvin-onlab8a832582015-01-16 17:06:11 -080085 main.ONOSbench.git_checkout( checkout_branch )
andrewonlab2a6c9342014-10-16 13:40:15 -040086 pull_result = main.ONOSbench.git_pull()
87 else:
88 checkout_result = main.TRUE
89 pull_result = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -080090 main.log.info( "Skipped git checkout and pull" )
andrewonlab2a6c9342014-10-16 13:40:15 -040091
kelvin-onlab8a832582015-01-16 17:06:11 -080092 # TODO: Uncomment when wiki posting works
93 #main.log.report( "Commit information - " )
94 # main.ONOSbench.get_version( report=True )
andrewonlab92844342014-11-18 16:39:11 -050095
kelvin-onlab8a832582015-01-16 17:06:11 -080096 main.step( "Using mvn clean & install" )
andrewonlab8d29f122014-10-22 17:15:04 -040097 #mvn_result = main.ONOSbench.clean_install()
98 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040099
kelvin-onlab8a832582015-01-16 17:06:11 -0800100 main.step( "Set cell for ONOS cli env" )
101 main.ONOS1cli.set_cell( cell_name )
102 main.ONOS2cli.set_cell( cell_name )
103 main.ONOS3cli.set_cell( cell_name )
andrewonlabb1998c52014-11-10 13:31:43 -0500104
kelvin-onlab8a832582015-01-16 17:06:11 -0800105 main.step( "Creating ONOS package" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400106 package_result = main.ONOSbench.onos_package()
107
kelvin-onlab8a832582015-01-16 17:06:11 -0800108 main.step( "Installing ONOS package" )
109 install1_result = main.ONOSbench.onos_install( node=ONOS1_ip )
110 install2_result = main.ONOSbench.onos_install( node=ONOS2_ip )
111 install3_result = main.ONOSbench.onos_install( node=ONOS3_ip )
andrewonlab2a6c9342014-10-16 13:40:15 -0400112
kelvin-onlab8a832582015-01-16 17:06:11 -0800113 time.sleep( 10 )
andrewonlabe9fb6722014-10-24 12:20:35 -0400114
kelvin-onlab8a832582015-01-16 17:06:11 -0800115 main.step( "Start onos cli" )
116 cli1 = main.ONOS1cli.start_onos_cli( ONOS1_ip )
117 cli2 = main.ONOS2cli.start_onos_cli( ONOS2_ip )
118 cli3 = main.ONOS3cli.start_onos_cli( ONOS3_ip )
andrewonlabe9fb6722014-10-24 12:20:35 -0400119
kelvin-onlab8a832582015-01-16 17:06:11 -0800120 utilities.assert_equals( expect=main.TRUE,
121 actual=cell_file_result and cell_apply_result and
122 verify_cell_result and checkout_result and
123 pull_result and mvn_result and
124 install1_result and install2_result and
125 install3_result,
126 onpass="Test Environment setup successful",
127 onfail="Failed to setup test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400128
kelvin-onlab8a832582015-01-16 17:06:11 -0800129 def CASE2( self, main ):
130 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400131 Assign s1 to ONOS1 and measure latency
kelvin-onlab8a832582015-01-16 17:06:11 -0800132
andrewonlab3a7c3c72014-10-24 17:21:03 -0400133 There are 4 levels of latency measurements to this test:
kelvin-onlab8a832582015-01-16 17:06:11 -0800134 1 ) End-to-end measurement: Complete end-to-end measurement
135 from TCP ( SYN/ACK ) handshake to Graph change
136 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of
andrewonlab3a7c3c72014-10-24 17:21:03 -0400137 measurement from OFP Vendor message to Graph change
kelvin-onlab8a832582015-01-16 17:06:11 -0800138 3 ) OFP-to-device measurement: 'ONOS processing without
andrewonlab3a7c3c72014-10-24 17:21:03 -0400139 graph change' snippet of measurement from OFP vendor
140 message to Device change timestamp
kelvin-onlab8a832582015-01-16 17:06:11 -0800141 4 ) T0-to-device measurement: Measurement that includes
142 the switch handshake to devices timestamp without
143 the graph view change. ( TCP handshake -> Device
144 change )
145 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400146 import time
andrewonlabe6745342014-10-17 14:29:13 -0400147 import subprocess
148 import json
149 import requests
150 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500151 import numpy
andrewonlabba44bcf2014-10-16 16:54:41 -0400152
kelvin-onlab8a832582015-01-16 17:06:11 -0800153 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
154 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
155 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
156 ONOS_user = main.params[ 'CTRL' ][ 'user' ]
andrewonlabe6745342014-10-17 14:29:13 -0400157
kelvin-onlab8a832582015-01-16 17:06:11 -0800158 default_sw_port = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab4b5c8b92014-11-10 16:04:33 -0500159
kelvin-onlab8a832582015-01-16 17:06:11 -0800160 # Number of iterations of case
161 num_iter = main.params[ 'TEST' ][ 'numIter' ]
162 # Number of first 'x' iterations to ignore:
163 iter_ignore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab226024e2014-10-24 16:01:32 -0400164
kelvin-onlab8a832582015-01-16 17:06:11 -0800165 # Timestamp 'keys' for json metrics output.
166 # These are subject to change, hence moved into params
167 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
168 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlab58f7d702014-11-07 13:21:19 -0500169
kelvin-onlab8a832582015-01-16 17:06:11 -0800170 debug_mode = main.params[ 'TEST' ][ 'debugMode' ]
171 onos_log = main.params[ 'TEST' ][ 'onosLogFile' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500172
kelvin-onlab8a832582015-01-16 17:06:11 -0800173 # Threshold for the test
174 threshold_str = main.params[ 'TEST' ][ 'singleSwThreshold' ]
175 threshold_obj = threshold_str.split( "," )
176 threshold_min = int( threshold_obj[ 0 ] )
177 threshold_max = int( threshold_obj[ 1 ] )
178
179 # List of switch add latency collected from
180 # all iterations
andrewonlab226024e2014-10-24 16:01:32 -0400181 latency_end_to_end_list = []
182 latency_ofp_to_graph_list = []
183 latency_ofp_to_device_list = []
184 latency_t0_to_device_list = []
andrewonlab65d73892014-11-10 17:36:00 -0500185 latency_tcp_to_ofp_list = []
andrewonlab226024e2014-10-24 16:01:32 -0400186
kelvin-onlab8a832582015-01-16 17:06:11 -0800187 # Directory/file to store tshark results
andrewonlabba44bcf2014-10-16 16:54:41 -0400188 tshark_of_output = "/tmp/tshark_of_topo.txt"
189 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
190
kelvin-onlab8a832582015-01-16 17:06:11 -0800191 # String to grep in tshark output
192 tshark_tcp_string = "TCP 74 " + default_sw_port
andrewonlabba44bcf2014-10-16 16:54:41 -0400193 tshark_of_string = "OFP 86 Vendor"
kelvin-onlab8a832582015-01-16 17:06:11 -0800194
195 # Initialize assertion to TRUE
andrewonlabe6745342014-10-17 14:29:13 -0400196 assertion = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800197
198 local_time = time.strftime( '%x %X' )
199 local_time = local_time.replace( "/", "" )
200 local_time = local_time.replace( " ", "_" )
201 local_time = local_time.replace( ":", "" )
andrewonlab58f7d702014-11-07 13:21:19 -0500202 if debug_mode == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -0800203 main.ONOS1.tshark_pcap( "eth0",
204 "/tmp/single_sw_lat_pcap_" + local_time )
andrewonlabb1998c52014-11-10 13:31:43 -0500205
kelvin-onlab8a832582015-01-16 17:06:11 -0800206 main.log.info( "TEST" )
andrewonlab58f7d702014-11-07 13:21:19 -0500207
kelvin-onlab8a832582015-01-16 17:06:11 -0800208 main.log.report( "Latency of adding one switch to controller" )
209 main.log.report(
210 "First " +
211 str( iter_ignore ) +
212 " iterations ignored" +
213 " for jvm warmup time" )
214 main.log.report( "Total iterations of test: " + str( num_iter ) )
andrewonlabba44bcf2014-10-16 16:54:41 -0400215
kelvin-onlab8a832582015-01-16 17:06:11 -0800216 for i in range( 0, int( num_iter ) ):
217 main.log.info( "Starting tshark capture" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400218
kelvin-onlab8a832582015-01-16 17:06:11 -0800219 #* TCP [ ACK, SYN ] is used as t0_a, the
220 # very first "exchange" between ONOS and
andrewonlabba44bcf2014-10-16 16:54:41 -0400221 # the switch for end-to-end measurement
kelvin-onlab8a832582015-01-16 17:06:11 -0800222 #* OFP [ Stats Reply ] is used for t0_b
andrewonlabba44bcf2014-10-16 16:54:41 -0400223 # the very last OFP message between ONOS
224 # and the switch for ONOS measurement
kelvin-onlab8a832582015-01-16 17:06:11 -0800225 main.ONOS1.tshark_grep( tshark_tcp_string,
226 tshark_tcp_output )
227 main.ONOS1.tshark_grep( tshark_of_string,
228 tshark_of_output )
andrewonlabba44bcf2014-10-16 16:54:41 -0400229
kelvin-onlab8a832582015-01-16 17:06:11 -0800230 # Wait and ensure tshark is started and
231 # capturing
232 time.sleep( 10 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400233
kelvin-onlab8a832582015-01-16 17:06:11 -0800234 main.log.info( "Assigning s1 to controller" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400235
kelvin-onlab8a832582015-01-16 17:06:11 -0800236 main.Mininet1.assign_sw_controller(
237 sw="1",
238 ip1=ONOS1_ip,
239 port1=default_sw_port )
andrewonlabba44bcf2014-10-16 16:54:41 -0400240
kelvin-onlab8a832582015-01-16 17:06:11 -0800241 # Wait and ensure switch is assigned
242 # before stopping tshark
243 time.sleep( 30 )
244
245 main.log.info( "Stopping all Tshark processes" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400246 main.ONOS1.stop_tshark()
247
kelvin-onlab8a832582015-01-16 17:06:11 -0800248 # tshark output is saved in ONOS. Use subprocess
249 # to copy over files to TestON for parsing
250 main.log.info( "Copying over tshark files" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400251
kelvin-onlab8a832582015-01-16 17:06:11 -0800252 # TCP CAPTURE ****
253 # Copy the tshark output from ONOS machine to
254 # TestON machine in tshark_tcp_output directory>file
255 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
256 tshark_tcp_output + " /tmp/" )
257 tcp_file = open( tshark_tcp_output, 'r' )
258 temp_text = tcp_file.readline()
259 temp_text = temp_text.split( " " )
260
261 main.log.info( "Object read in from TCP capture: " +
262 str( temp_text ) )
263 if len( temp_text ) > 1:
264 t0_tcp = float( temp_text[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400265 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800266 main.log.error( "Tshark output file for TCP" +
267 " returned unexpected results" )
andrewonlabe6745342014-10-17 14:29:13 -0400268 t0_tcp = 0
269 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800270
andrewonlab8d29f122014-10-22 17:15:04 -0400271 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400272 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400273
kelvin-onlab8a832582015-01-16 17:06:11 -0800274 # OF CAPTURE ****
275 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
276 tshark_of_output + " /tmp/" )
277 of_file = open( tshark_of_output, 'r' )
278
andrewonlab8d29f122014-10-22 17:15:04 -0400279 line_ofp = ""
kelvin-onlab8a832582015-01-16 17:06:11 -0800280 # Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400281 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400282 temp_text = of_file.readline()
kelvin-onlab8a832582015-01-16 17:06:11 -0800283 if temp_text != '':
andrewonlabe6745342014-10-17 14:29:13 -0400284 line_ofp = temp_text
285 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800286 break
287 obj = line_ofp.split( " " )
288
289 main.log.info( "Object read in from OFP capture: " +
290 str( line_ofp ) )
291
292 if len( line_ofp ) > 1:
293 t0_ofp = float( obj[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400294 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800295 main.log.error( "Tshark output file for OFP" +
296 " returned unexpected results" )
andrewonlabe6745342014-10-17 14:29:13 -0400297 t0_ofp = 0
298 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800299
andrewonlab8d29f122014-10-22 17:15:04 -0400300 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400301 #****************
kelvin-onlab8a832582015-01-16 17:06:11 -0800302
andrewonlab867212a2014-10-22 20:13:38 -0400303 json_str_1 = main.ONOS1cli.topology_events_metrics()
304 json_str_2 = main.ONOS2cli.topology_events_metrics()
305 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400306
kelvin-onlab8a832582015-01-16 17:06:11 -0800307 json_obj_1 = json.loads( json_str_1 )
308 json_obj_2 = json.loads( json_str_2 )
309 json_obj_3 = json.loads( json_str_3 )
andrewonlab867212a2014-10-22 20:13:38 -0400310
kelvin-onlab8a832582015-01-16 17:06:11 -0800311 # Obtain graph timestamp. This timestsamp captures
312 # the epoch time at which the topology graph was updated.
andrewonlab226024e2014-10-24 16:01:32 -0400313 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800314 json_obj_1[ graphTimestamp ][ 'value' ]
andrewonlab226024e2014-10-24 16:01:32 -0400315 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800316 json_obj_2[ graphTimestamp ][ 'value' ]
andrewonlab226024e2014-10-24 16:01:32 -0400317 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800318 json_obj_3[ graphTimestamp ][ 'value' ]
andrewonlab867212a2014-10-22 20:13:38 -0400319
kelvin-onlab8a832582015-01-16 17:06:11 -0800320 # Obtain device timestamp. This timestamp captures
321 # the epoch time at which the device event happened
andrewonlab226024e2014-10-24 16:01:32 -0400322 device_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800323 json_obj_1[ deviceTimestamp ][ 'value' ]
andrewonlab226024e2014-10-24 16:01:32 -0400324 device_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800325 json_obj_2[ deviceTimestamp ][ 'value' ]
andrewonlab226024e2014-10-24 16:01:32 -0400326 device_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800327 json_obj_3[ deviceTimestamp ][ 'value' ]
andrewonlabe9fb6722014-10-24 12:20:35 -0400328
kelvin-onlab8a832582015-01-16 17:06:11 -0800329 # t0 to device processing latency
330 delta_device_1 = int( device_timestamp_1 ) - int( t0_tcp )
331 delta_device_2 = int( device_timestamp_2 ) - int( t0_tcp )
332 delta_device_3 = int( device_timestamp_3 ) - int( t0_tcp )
333
334 # Get average of delta from all instances
andrewonlab226024e2014-10-24 16:01:32 -0400335 avg_delta_device = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800336 ( int( delta_device_1 ) +
337 int( delta_device_2 ) +
338 int( delta_device_3 ) ) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400339
kelvin-onlab8a832582015-01-16 17:06:11 -0800340 # Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500341 if avg_delta_device > 0.0 and avg_delta_device < 10000\
kelvin-onlab8a832582015-01-16 17:06:11 -0800342 and int( i ) > iter_ignore:
343 latency_t0_to_device_list.append( avg_delta_device )
andrewonlabee4efeb2014-10-24 16:44:51 -0400344 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800345 main.log.info(
346 "Results for t0-to-device ignored" +
347 "due to excess in threshold / warmup iteration." )
andrewonlabee4efeb2014-10-24 16:44:51 -0400348
kelvin-onlab8a832582015-01-16 17:06:11 -0800349 # t0 to graph processing latency ( end-to-end )
350 delta_graph_1 = int( graph_timestamp_1 ) - int( t0_tcp )
351 delta_graph_2 = int( graph_timestamp_2 ) - int( t0_tcp )
352 delta_graph_3 = int( graph_timestamp_3 ) - int( t0_tcp )
353
354 # Get average of delta from all instances
andrewonlab226024e2014-10-24 16:01:32 -0400355 avg_delta_graph = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800356 ( int( delta_graph_1 ) +
357 int( delta_graph_2 ) +
358 int( delta_graph_3 ) ) / 3
andrewonlab226024e2014-10-24 16:01:32 -0400359
kelvin-onlab8a832582015-01-16 17:06:11 -0800360 # Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500361 if avg_delta_graph > 0.0 and avg_delta_graph < 10000\
kelvin-onlab8a832582015-01-16 17:06:11 -0800362 and int( i ) > iter_ignore:
363 latency_end_to_end_list.append( avg_delta_graph )
andrewonlabee4efeb2014-10-24 16:44:51 -0400364 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800365 main.log.info( "Results for end-to-end ignored" +
366 "due to excess in threshold" )
andrewonlab226024e2014-10-24 16:01:32 -0400367
kelvin-onlab8a832582015-01-16 17:06:11 -0800368 # ofp to graph processing latency ( ONOS processing )
369 delta_ofp_graph_1 = int( graph_timestamp_1 ) - int( t0_ofp )
370 delta_ofp_graph_2 = int( graph_timestamp_2 ) - int( t0_ofp )
371 delta_ofp_graph_3 = int( graph_timestamp_3 ) - int( t0_ofp )
372
andrewonlab226024e2014-10-24 16:01:32 -0400373 avg_delta_ofp_graph = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800374 ( int( delta_ofp_graph_1 ) +
375 int( delta_ofp_graph_2 ) +
376 int( delta_ofp_graph_3 ) ) / 3
377
andrewonlabe5bcef92014-11-06 17:53:20 -0500378 if avg_delta_ofp_graph > threshold_min \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500379 and avg_delta_ofp_graph < threshold_max\
kelvin-onlab8a832582015-01-16 17:06:11 -0800380 and int( i ) > iter_ignore:
381 latency_ofp_to_graph_list.append( avg_delta_ofp_graph )
382 elif avg_delta_ofp_graph > ( -10 ) and \
andrewonlab92844342014-11-18 16:39:11 -0500383 avg_delta_ofp_graph < 0.0 and\
kelvin-onlab8a832582015-01-16 17:06:11 -0800384 int( i ) > iter_ignore:
385 main.log.info( "Sub-millisecond result likely; " +
386 "negative result was rounded to 0" )
387 # NOTE: Current metrics framework does not
388 # support sub-millisecond accuracy. Therefore,
389 # if the result is negative, we can reasonably
390 # conclude sub-millisecond results and just
391 # append the best rounded effort - 0 ms.
392 latency_ofp_to_graph_list.append( 0 )
andrewonlabee4efeb2014-10-24 16:44:51 -0400393 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800394 main.log.info( "Results for ofp-to-graph " +
395 "ignored due to excess in threshold" )
andrewonlabee4efeb2014-10-24 16:44:51 -0400396
kelvin-onlab8a832582015-01-16 17:06:11 -0800397 # ofp to device processing latency ( ONOS processing )
398 delta_ofp_device_1 = float( device_timestamp_1 ) - float( t0_ofp )
399 delta_ofp_device_2 = float( device_timestamp_2 ) - float( t0_ofp )
400 delta_ofp_device_3 = float( device_timestamp_3 ) - float( t0_ofp )
401
andrewonlab226024e2014-10-24 16:01:32 -0400402 avg_delta_ofp_device = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800403 ( float( delta_ofp_device_1 ) +
404 float( delta_ofp_device_2 ) +
405 float( delta_ofp_device_3 ) ) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400406
kelvin-onlab8a832582015-01-16 17:06:11 -0800407 # NOTE: ofp - delta measurements are occasionally negative
408 # due to system time misalignment.
409 latency_ofp_to_device_list.append( avg_delta_ofp_device )
410
411 delta_ofp_tcp = int( t0_ofp ) - int( t0_tcp )
andrewonlab65d73892014-11-10 17:36:00 -0500412 if delta_ofp_tcp > threshold_min \
413 and delta_ofp_tcp < threshold_max and\
kelvin-onlab8a832582015-01-16 17:06:11 -0800414 int( i ) > iter_ignore:
415 latency_tcp_to_ofp_list.append( delta_ofp_tcp )
andrewonlab65d73892014-11-10 17:36:00 -0500416 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800417 main.log.info( "Results fo tcp-to-ofp " +
418 "ignored due to excess in threshold" )
andrewonlab65d73892014-11-10 17:36:00 -0500419
kelvin-onlab8a832582015-01-16 17:06:11 -0800420 # TODO:
421 # Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400422
kelvin-onlab8a832582015-01-16 17:06:11 -0800423 main.log.info( "ONOS1 delta end-to-end: " +
424 str( delta_graph_1 ) + " ms" )
425 main.log.info( "ONOS2 delta end-to-end: " +
426 str( delta_graph_2 ) + " ms" )
427 main.log.info( "ONOS3 delta end-to-end: " +
428 str( delta_graph_3 ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400429
kelvin-onlab8a832582015-01-16 17:06:11 -0800430 main.log.info( "ONOS1 delta OFP - graph: " +
431 str( delta_ofp_graph_1 ) + " ms" )
432 main.log.info( "ONOS2 delta OFP - graph: " +
433 str( delta_ofp_graph_2 ) + " ms" )
434 main.log.info( "ONOS3 delta OFP - graph: " +
435 str( delta_ofp_graph_3 ) + " ms" )
andrewonlab226024e2014-10-24 16:01:32 -0400436
kelvin-onlab8a832582015-01-16 17:06:11 -0800437 main.log.info( "ONOS1 delta device - t0: " +
438 str( delta_device_1 ) + " ms" )
439 main.log.info( "ONOS2 delta device - t0: " +
440 str( delta_device_2 ) + " ms" )
441 main.log.info( "ONOS3 delta device - t0: " +
442 str( delta_device_3 ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400443
kelvin-onlab8a832582015-01-16 17:06:11 -0800444 main.log.info( "TCP to OFP delta: " +
445 str( delta_ofp_tcp ) + " ms" )
446 # main.log.info( "ONOS1 delta OFP - device: "+
447 # str( delta_ofp_device_1 ) + " ms" )
448 # main.log.info( "ONOS2 delta OFP - device: "+
449 # str( delta_ofp_device_2 ) + " ms" )
450 # main.log.info( "ONOS3 delta OFP - device: "+
451 # str( delta_ofp_device_3 ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400452
kelvin-onlab8a832582015-01-16 17:06:11 -0800453 main.step( "Remove switch from controller" )
454 main.Mininet1.delete_sw_controller( "s1" )
andrewonlabf47993a2014-10-24 17:56:01 -0400455
kelvin-onlab8a832582015-01-16 17:06:11 -0800456 time.sleep( 5 )
457
458 # END of for loop iteration
459
460 # If there is at least 1 element in each list,
461 # pass the test case
462 if len( latency_end_to_end_list ) > 0 and\
463 len( latency_ofp_to_graph_list ) > 0 and\
464 len( latency_ofp_to_device_list ) > 0 and\
465 len( latency_t0_to_device_list ) > 0 and\
466 len( latency_tcp_to_ofp_list ) > 0:
andrewonlabc15c9582014-10-24 16:35:52 -0400467 assertion = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800468 elif len( latency_end_to_end_list ) == 0:
469 # The appending of 0 here is to prevent
470 # the min,max,sum functions from failing
471 # below
472 latency_end_to_end_list.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400473 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800474 elif len( latency_ofp_to_graph_list ) == 0:
475 latency_ofp_to_graph_list.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400476 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800477 elif len( latency_ofp_to_device_list ) == 0:
478 latency_ofp_to_device_list.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400479 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800480 elif len( latency_t0_to_device_list ) == 0:
481 latency_t0_to_device_list.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400482 assertion = main.FALSE
kelvin-onlab8a832582015-01-16 17:06:11 -0800483 elif len( latency_tcp_to_ofp_list ) == 0:
484 latency_tcp_to_ofp_list.append( 0 )
andrewonlab65d73892014-11-10 17:36:00 -0500485 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400486
kelvin-onlab8a832582015-01-16 17:06:11 -0800487 # Calculate min, max, avg of latency lists
andrewonlabc15c9582014-10-24 16:35:52 -0400488 latency_end_to_end_max = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800489 int( max( latency_end_to_end_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400490 latency_end_to_end_min = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800491 int( min( latency_end_to_end_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400492 latency_end_to_end_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800493 ( int( sum( latency_end_to_end_list ) ) /
494 len( latency_end_to_end_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500495 latency_end_to_end_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800496 str( round( numpy.std( latency_end_to_end_list ), 1 ) )
andrewonlab69864162014-11-11 16:28:48 -0500497
andrewonlabc15c9582014-10-24 16:35:52 -0400498 latency_ofp_to_graph_max = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800499 int( max( latency_ofp_to_graph_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400500 latency_ofp_to_graph_min = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800501 int( min( latency_ofp_to_graph_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400502 latency_ofp_to_graph_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800503 ( int( sum( latency_ofp_to_graph_list ) ) /
504 len( latency_ofp_to_graph_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500505 latency_ofp_to_graph_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800506 str( round( numpy.std( latency_ofp_to_graph_list ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400507
508 latency_ofp_to_device_max = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800509 int( max( latency_ofp_to_device_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400510 latency_ofp_to_device_min = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800511 int( min( latency_ofp_to_device_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400512 latency_ofp_to_device_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800513 ( int( sum( latency_ofp_to_device_list ) ) /
514 len( latency_ofp_to_device_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500515 latency_ofp_to_device_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800516 str( round( numpy.std( latency_ofp_to_device_list ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400517
518 latency_t0_to_device_max = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800519 int( max( latency_t0_to_device_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400520 latency_t0_to_device_min = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800521 int( min( latency_t0_to_device_list ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400522 latency_t0_to_device_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800523 ( int( sum( latency_t0_to_device_list ) ) /
524 len( latency_t0_to_device_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500525 latency_ofp_to_device_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800526 str( round( numpy.std( latency_t0_to_device_list ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400527
andrewonlab65d73892014-11-10 17:36:00 -0500528 latency_tcp_to_ofp_max = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800529 int( max( latency_tcp_to_ofp_list ) )
andrewonlab65d73892014-11-10 17:36:00 -0500530 latency_tcp_to_ofp_min = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800531 int( min( latency_tcp_to_ofp_list ) )
andrewonlab65d73892014-11-10 17:36:00 -0500532 latency_tcp_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800533 ( int( sum( latency_tcp_to_ofp_list ) ) /
534 len( latency_tcp_to_ofp_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500535 latency_tcp_to_ofp_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800536 str( round( numpy.std( latency_tcp_to_ofp_list ), 1 ) )
andrewonlab65d73892014-11-10 17:36:00 -0500537
kelvin-onlab8a832582015-01-16 17:06:11 -0800538 main.log.report(
539 "Switch add - End-to-end latency: " +
540 "Avg: " +
541 str( latency_end_to_end_avg ) +
542 " ms " +
543 "Std Deviation: " +
544 latency_end_to_end_std_dev +
545 " ms" )
546 main.log.report(
547 "Switch add - OFP-to-Graph latency: " +
548 "Note: results are not accurate to sub-millisecond. " +
549 "Any sub-millisecond results are rounded to 0 ms. " )
550 main.log.report(
551 "Avg: " +
552 str( latency_ofp_to_graph_avg ) +
553 " ms " +
554 "Std Deviation: " +
555 latency_ofp_to_graph_std_dev +
556 " ms" )
557 main.log.report(
558 "Switch add - TCP-to-OFP latency: " +
559 "Avg: " +
560 str( latency_tcp_to_ofp_avg ) +
561 " ms " +
562 "Std Deviation: " +
563 latency_tcp_to_ofp_std_dev +
564 " ms" )
andrewonlab226024e2014-10-24 16:01:32 -0400565
andrewonlabb1998c52014-11-10 13:31:43 -0500566 if debug_mode == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -0800567 main.ONOS1.cp_logs_to_dir( "/opt/onos/log/karaf.log",
568 "/tmp/", copy_file_name="sw_lat_karaf" )
andrewonlabb1998c52014-11-10 13:31:43 -0500569
kelvin-onlab8a832582015-01-16 17:06:11 -0800570 utilities.assert_equals( expect=main.TRUE, actual=assertion,
571 onpass="Switch latency test successful",
572 onfail="Switch latency test failed" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400573
kelvin-onlab8a832582015-01-16 17:06:11 -0800574 def CASE3( self, main ):
575 """
andrewonlab8d29f122014-10-22 17:15:04 -0400576 Bring port up / down and measure latency.
577 Port enable / disable is simulated by ifconfig up / down
kelvin-onlab8a832582015-01-16 17:06:11 -0800578
579 In ONOS-next, we must ensure that the port we are
andrewonlab393531a2014-10-27 18:36:26 -0400580 manipulating is connected to another switch with a valid
581 connection. Otherwise, graph view will not be updated.
kelvin-onlab8a832582015-01-16 17:06:11 -0800582 """
andrewonlab8d29f122014-10-22 17:15:04 -0400583 import time
584 import subprocess
585 import os
586 import requests
587 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500588 import numpy
andrewonlab2a6c9342014-10-16 13:40:15 -0400589
kelvin-onlab8a832582015-01-16 17:06:11 -0800590 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
591 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
592 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
593 ONOS_user = main.params[ 'CTRL' ][ 'user' ]
andrewonlab8d29f122014-10-22 17:15:04 -0400594
kelvin-onlab8a832582015-01-16 17:06:11 -0800595 default_sw_port = main.params[ 'CTRL' ][ 'port1' ]
596
andrewonlab8790abb2014-11-06 13:51:54 -0500597 assertion = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -0800598 # Number of iterations of case
599 num_iter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlab58f7d702014-11-07 13:21:19 -0500600
kelvin-onlab8a832582015-01-16 17:06:11 -0800601 # Timestamp 'keys' for json metrics output.
602 # These are subject to change, hence moved into params
603 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
604 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
605
606 debug_mode = main.params[ 'TEST' ][ 'debugMode' ]
607
608 local_time = time.strftime( '%x %X' )
609 local_time = local_time.replace( "/", "" )
610 local_time = local_time.replace( " ", "_" )
611 local_time = local_time.replace( ":", "" )
andrewonlab58f7d702014-11-07 13:21:19 -0500612 if debug_mode == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -0800613 main.ONOS1.tshark_pcap( "eth0",
614 "/tmp/port_lat_pcap_" + local_time )
andrewonlab393531a2014-10-27 18:36:26 -0400615
kelvin-onlab8a832582015-01-16 17:06:11 -0800616 # Threshold for this test case
617 up_threshold_str = main.params[ 'TEST' ][ 'portUpThreshold' ]
618 down_threshold_str = main.params[ 'TEST' ][ 'portDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500619
kelvin-onlab8a832582015-01-16 17:06:11 -0800620 up_threshold_obj = up_threshold_str.split( "," )
621 down_threshold_obj = down_threshold_str.split( "," )
andrewonlabe5bcef92014-11-06 17:53:20 -0500622
kelvin-onlab8a832582015-01-16 17:06:11 -0800623 up_threshold_min = int( up_threshold_obj[ 0 ] )
624 up_threshold_max = int( up_threshold_obj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -0500625
kelvin-onlab8a832582015-01-16 17:06:11 -0800626 down_threshold_min = int( down_threshold_obj[ 0 ] )
627 down_threshold_max = int( down_threshold_obj[ 1 ] )
628
629 # NOTE: Some hardcoded variables you may need to configure
andrewonlab393531a2014-10-27 18:36:26 -0400630 # besides the params
kelvin-onlab8a832582015-01-16 17:06:11 -0800631
andrewonlab8d29f122014-10-22 17:15:04 -0400632 tshark_port_status = "OFP 130 Port Status"
633
634 tshark_port_up = "/tmp/tshark_port_up.txt"
635 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400636 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400637
kelvin-onlab8a832582015-01-16 17:06:11 -0800638 main.log.report( "Port enable / disable latency" )
639 main.log.report( "Simulated by ifconfig up / down" )
640 main.log.report( "Total iterations of test: " + str( num_iter ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400641
kelvin-onlab8a832582015-01-16 17:06:11 -0800642 main.step( "Assign switches s1 and s2 to controller 1" )
643 main.Mininet1.assign_sw_controller( sw="1", ip1=ONOS1_ip,
644 port1=default_sw_port )
645 main.Mininet1.assign_sw_controller( sw="2", ip1=ONOS1_ip,
646 port1=default_sw_port )
andrewonlab8d29f122014-10-22 17:15:04 -0400647
kelvin-onlab8a832582015-01-16 17:06:11 -0800648 # Give enough time for metrics to propagate the
649 # assign controller event. Otherwise, these events may
650 # carry over to our measurements
651 time.sleep( 15 )
andrewonlab8d29f122014-10-22 17:15:04 -0400652
andrewonlab393531a2014-10-27 18:36:26 -0400653 port_up_device_to_ofp_list = []
654 port_up_graph_to_ofp_list = []
655 port_down_device_to_ofp_list = []
656 port_down_graph_to_ofp_list = []
657
kelvin-onlab8a832582015-01-16 17:06:11 -0800658 for i in range( 0, int( num_iter ) ):
659 main.step( "Starting wireshark capture for port status down" )
660 main.ONOS1.tshark_grep( tshark_port_status,
661 tshark_port_down )
andrewonlab8d29f122014-10-22 17:15:04 -0400662
kelvin-onlab8a832582015-01-16 17:06:11 -0800663 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400664
kelvin-onlab8a832582015-01-16 17:06:11 -0800665 # Disable interface that is connected to switch 2
666 main.step( "Disable port: " + interface_config )
667 main.Mininet1.handle.sendline( "sh ifconfig " +
668 interface_config + " down" )
669 main.Mininet1.handle.expect( "mininet>" )
670
671 time.sleep( 3 )
andrewonlab8d29f122014-10-22 17:15:04 -0400672 main.ONOS1.tshark_stop()
kelvin-onlab8a832582015-01-16 17:06:11 -0800673
674 main.step( "Obtain t1 by metrics call" )
andrewonlabb1998c52014-11-10 13:31:43 -0500675 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
676 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
677 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
678
kelvin-onlab8a832582015-01-16 17:06:11 -0800679 json_obj_1 = json.loads( json_str_up_1 )
680 json_obj_2 = json.loads( json_str_up_2 )
681 json_obj_3 = json.loads( json_str_up_3 )
andrewonlab8d29f122014-10-22 17:15:04 -0400682
kelvin-onlab8a832582015-01-16 17:06:11 -0800683 # Copy tshark output file from ONOS to TestON instance
684 #/tmp directory
685 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
686 tshark_port_down + " /tmp/" )
687
688 f_port_down = open( tshark_port_down, 'r' )
689 # Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400690 f_line = f_port_down.readline()
kelvin-onlab8a832582015-01-16 17:06:11 -0800691 obj_down = f_line.split( " " )
692 if len( f_line ) > 0:
693 timestamp_begin_pt_down = int( float( obj_down[ 1 ] ) * 1000 )
694 main.log.info( "Port down begin timestamp: " +
695 str( timestamp_begin_pt_down ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400696 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800697 main.log.info( "Tshark output file returned unexpected" +
698 " results: " + str( obj_down ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400699 timestamp_begin_pt_down = 0
kelvin-onlab8a832582015-01-16 17:06:11 -0800700
andrewonlab393531a2014-10-27 18:36:26 -0400701 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400702
kelvin-onlab8a832582015-01-16 17:06:11 -0800703 main.log.info( "TEST tshark obj: " + str( obj_down ) )
andrewonlab4e124482014-11-04 13:37:25 -0500704
kelvin-onlab8a832582015-01-16 17:06:11 -0800705 time.sleep( 3 )
andrewonlab393531a2014-10-27 18:36:26 -0400706
kelvin-onlab8a832582015-01-16 17:06:11 -0800707 # Obtain graph timestamp. This timestsamp captures
708 # the epoch time at which the topology graph was updated.
andrewonlab393531a2014-10-27 18:36:26 -0400709 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800710 json_obj_1[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400711 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800712 json_obj_2[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400713 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800714 json_obj_3[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400715
kelvin-onlab8a832582015-01-16 17:06:11 -0800716 main.log.info( "TEST graph timestamp ONOS1: " +
717 str( graph_timestamp_1 ) )
andrewonlabb1998c52014-11-10 13:31:43 -0500718
kelvin-onlab8a832582015-01-16 17:06:11 -0800719 # Obtain device timestamp. This timestamp captures
720 # the epoch time at which the device event happened
andrewonlab393531a2014-10-27 18:36:26 -0400721 device_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800722 json_obj_1[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400723 device_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800724 json_obj_2[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400725 device_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800726 json_obj_3[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400727
kelvin-onlab8a832582015-01-16 17:06:11 -0800728 # Get delta between graph event and OFP
729 pt_down_graph_to_ofp_1 = int( graph_timestamp_1 ) -\
730 int( timestamp_begin_pt_down )
731 pt_down_graph_to_ofp_2 = int( graph_timestamp_2 ) -\
732 int( timestamp_begin_pt_down )
733 pt_down_graph_to_ofp_3 = int( graph_timestamp_3 ) -\
734 int( timestamp_begin_pt_down )
andrewonlab393531a2014-10-27 18:36:26 -0400735
kelvin-onlab8a832582015-01-16 17:06:11 -0800736 # Get delta between device event and OFP
737 pt_down_device_to_ofp_1 = int( device_timestamp_1 ) -\
738 int( timestamp_begin_pt_down )
739 pt_down_device_to_ofp_2 = int( device_timestamp_2 ) -\
740 int( timestamp_begin_pt_down )
741 pt_down_device_to_ofp_3 = int( device_timestamp_3 ) -\
742 int( timestamp_begin_pt_down )
743
744 # Caluclate average across clusters
andrewonlab393531a2014-10-27 18:36:26 -0400745 pt_down_graph_to_ofp_avg =\
kelvin-onlab8a832582015-01-16 17:06:11 -0800746 ( int( pt_down_graph_to_ofp_1 ) +
747 int( pt_down_graph_to_ofp_2 ) +
748 int( pt_down_graph_to_ofp_3 ) ) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400749 pt_down_device_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800750 ( int( pt_down_device_to_ofp_1 ) +
751 int( pt_down_device_to_ofp_2 ) +
752 int( pt_down_device_to_ofp_3 ) ) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400753
andrewonlabb1998c52014-11-10 13:31:43 -0500754 if pt_down_graph_to_ofp_avg > down_threshold_min and \
755 pt_down_graph_to_ofp_avg < down_threshold_max:
andrewonlab393531a2014-10-27 18:36:26 -0400756 port_down_graph_to_ofp_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -0800757 pt_down_graph_to_ofp_avg )
758 main.log.info( "Port down: graph to ofp avg: " +
759 str( pt_down_graph_to_ofp_avg ) + " ms" )
andrewonlab393531a2014-10-27 18:36:26 -0400760 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800761 main.log.info( "Average port down graph-to-ofp result" +
762 " exceeded the threshold: " +
763 str( pt_down_graph_to_ofp_avg ) )
andrewonlab393531a2014-10-27 18:36:26 -0400764
andrewonlab3622beb2014-10-28 16:07:56 -0400765 if pt_down_device_to_ofp_avg > 0 and \
766 pt_down_device_to_ofp_avg < 1000:
767 port_down_device_to_ofp_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -0800768 pt_down_device_to_ofp_avg )
769 main.log.info( "Port down: device to ofp avg: " +
770 str( pt_down_device_to_ofp_avg ) + " ms" )
andrewonlab3622beb2014-10-28 16:07:56 -0400771 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800772 main.log.info( "Average port down device-to-ofp result" +
773 " exceeded the threshold: " +
774 str( pt_down_device_to_ofp_avg ) )
andrewonlab3622beb2014-10-28 16:07:56 -0400775
kelvin-onlab8a832582015-01-16 17:06:11 -0800776 # Port up events
777 main.step( "Enable port and obtain timestamp" )
778 main.step( "Starting wireshark capture for port status up" )
779 main.ONOS1.tshark_grep( tshark_port_status, tshark_port_up )
780 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400781
kelvin-onlab8a832582015-01-16 17:06:11 -0800782 main.Mininet1.handle.sendline( "sh ifconfig " +
783 interface_config + " up" )
784 main.Mininet1.handle.expect( "mininet>" )
785
786 # Allow time for tshark to capture event
787 time.sleep( 3 )
andrewonlab8790abb2014-11-06 13:51:54 -0500788 main.ONOS1.tshark_stop()
andrewonlab8d29f122014-10-22 17:15:04 -0400789
kelvin-onlab8a832582015-01-16 17:06:11 -0800790 # Obtain metrics shortly afterwards
791 # This timestsamp captures
792 # the epoch time at which the topology graph was updated.
793 main.step( "Obtain t1 by REST call" )
andrewonlabb1998c52014-11-10 13:31:43 -0500794 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
795 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
796 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
andrewonlabb1998c52014-11-10 13:31:43 -0500797
kelvin-onlab8a832582015-01-16 17:06:11 -0800798 json_obj_1 = json.loads( json_str_up_1 )
799 json_obj_2 = json.loads( json_str_up_2 )
800 json_obj_3 = json.loads( json_str_up_3 )
andrewonlab8d29f122014-10-22 17:15:04 -0400801
kelvin-onlab8a832582015-01-16 17:06:11 -0800802 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
803 tshark_port_up + " /tmp/" )
804
805 f_port_up = open( tshark_port_up, 'r' )
andrewonlab393531a2014-10-27 18:36:26 -0400806 f_line = f_port_up.readline()
kelvin-onlab8a832582015-01-16 17:06:11 -0800807 obj_up = f_line.split( " " )
808 if len( f_line ) > 0:
809 timestamp_begin_pt_up = int( float( obj_up[ 1 ] ) * 1000 )
810 main.log.info( "Port up begin timestamp: " +
811 str( timestamp_begin_pt_up ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400812 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800813 main.log.info( "Tshark output file returned unexpected" +
814 " results." )
andrewonlab8d29f122014-10-22 17:15:04 -0400815 timestamp_begin_pt_up = 0
kelvin-onlab8a832582015-01-16 17:06:11 -0800816
andrewonlab393531a2014-10-27 18:36:26 -0400817 f_port_up.close()
818
andrewonlab393531a2014-10-27 18:36:26 -0400819 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800820 json_obj_1[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400821 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800822 json_obj_2[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400823 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800824 json_obj_3[ graphTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400825
kelvin-onlab8a832582015-01-16 17:06:11 -0800826 # Obtain device timestamp. This timestamp captures
827 # the epoch time at which the device event happened
andrewonlab393531a2014-10-27 18:36:26 -0400828 device_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800829 json_obj_1[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400830 device_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800831 json_obj_2[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400832 device_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800833 json_obj_3[ deviceTimestamp ][ 'value' ]
andrewonlab393531a2014-10-27 18:36:26 -0400834
kelvin-onlab8a832582015-01-16 17:06:11 -0800835 # Get delta between graph event and OFP
836 pt_up_graph_to_ofp_1 = int( graph_timestamp_1 ) -\
837 int( timestamp_begin_pt_up )
838 pt_up_graph_to_ofp_2 = int( graph_timestamp_2 ) -\
839 int( timestamp_begin_pt_up )
840 pt_up_graph_to_ofp_3 = int( graph_timestamp_3 ) -\
841 int( timestamp_begin_pt_up )
andrewonlab393531a2014-10-27 18:36:26 -0400842
kelvin-onlab8a832582015-01-16 17:06:11 -0800843 # Get delta between device event and OFP
844 pt_up_device_to_ofp_1 = int( device_timestamp_1 ) -\
845 int( timestamp_begin_pt_up )
846 pt_up_device_to_ofp_2 = int( device_timestamp_2 ) -\
847 int( timestamp_begin_pt_up )
848 pt_up_device_to_ofp_3 = int( device_timestamp_3 ) -\
849 int( timestamp_begin_pt_up )
andrewonlab3622beb2014-10-28 16:07:56 -0400850
kelvin-onlab8a832582015-01-16 17:06:11 -0800851 main.log.info( "ONOS1 delta G2O: " + str( pt_up_graph_to_ofp_1 ) )
852 main.log.info( "ONOS2 delta G2O: " + str( pt_up_graph_to_ofp_2 ) )
853 main.log.info( "ONOS3 delta G2O: " + str( pt_up_graph_to_ofp_3 ) )
andrewonlabb1998c52014-11-10 13:31:43 -0500854
kelvin-onlab8a832582015-01-16 17:06:11 -0800855 main.log.info( "ONOS1 delta D2O: " + str( pt_up_device_to_ofp_1 ) )
856 main.log.info( "ONOS2 delta D2O: " + str( pt_up_device_to_ofp_2 ) )
857 main.log.info( "ONOS3 delta D2O: " + str( pt_up_device_to_ofp_3 ) )
andrewonlabb1998c52014-11-10 13:31:43 -0500858
andrewonlab3622beb2014-10-28 16:07:56 -0400859 pt_up_graph_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800860 ( int( pt_up_graph_to_ofp_1 ) +
861 int( pt_up_graph_to_ofp_2 ) +
862 int( pt_up_graph_to_ofp_3 ) ) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400863
864 pt_up_device_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800865 ( int( pt_up_device_to_ofp_1 ) +
866 int( pt_up_device_to_ofp_2 ) +
867 int( pt_up_device_to_ofp_3 ) ) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400868
andrewonlabe5bcef92014-11-06 17:53:20 -0500869 if pt_up_graph_to_ofp_avg > up_threshold_min and \
kelvin-onlab8a832582015-01-16 17:06:11 -0800870 pt_up_graph_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400871 port_up_graph_to_ofp_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -0800872 pt_up_graph_to_ofp_avg )
873 main.log.info( "Port down: graph to ofp avg: " +
874 str( pt_up_graph_to_ofp_avg ) + " ms" )
andrewonlab3622beb2014-10-28 16:07:56 -0400875 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800876 main.log.info( "Average port up graph-to-ofp result" +
877 " exceeded the threshold: " +
878 str( pt_up_graph_to_ofp_avg ) )
879
andrewonlabe5bcef92014-11-06 17:53:20 -0500880 if pt_up_device_to_ofp_avg > up_threshold_min and \
881 pt_up_device_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400882 port_up_device_to_ofp_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -0800883 pt_up_device_to_ofp_avg )
884 main.log.info( "Port up: device to ofp avg: " +
885 str( pt_up_device_to_ofp_avg ) + " ms" )
andrewonlab3622beb2014-10-28 16:07:56 -0400886 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800887 main.log.info( "Average port up device-to-ofp result" +
888 " exceeded the threshold: " +
889 str( pt_up_device_to_ofp_avg ) )
890
891 # END ITERATION FOR LOOP
892
893 # Check all list for latency existence and set assertion
894 if ( port_down_graph_to_ofp_list and port_down_device_to_ofp_list
895 and port_up_graph_to_ofp_list and port_up_device_to_ofp_list ):
andrewonlab8790abb2014-11-06 13:51:54 -0500896 assertion = main.TRUE
897
kelvin-onlab8a832582015-01-16 17:06:11 -0800898 # Calculate and report latency measurements
899 port_down_graph_to_ofp_min = min( port_down_graph_to_ofp_list )
900 port_down_graph_to_ofp_max = max( port_down_graph_to_ofp_list )
andrewonlab3622beb2014-10-28 16:07:56 -0400901 port_down_graph_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800902 ( sum( port_down_graph_to_ofp_list ) /
903 len( port_down_graph_to_ofp_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500904 port_down_graph_to_ofp_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800905 str( round( numpy.std( port_down_graph_to_ofp_list ), 1 ) )
906
907 main.log.report(
908 "Port down graph-to-ofp " +
909 "Avg: " +
910 str( port_down_graph_to_ofp_avg ) +
911 " ms " +
912 "Std Deviation: " +
913 port_down_graph_to_ofp_std_dev +
914 " ms" )
915
916 port_down_device_to_ofp_min = min( port_down_device_to_ofp_list )
917 port_down_device_to_ofp_max = max( port_down_device_to_ofp_list )
andrewonlababb11c32014-11-04 15:03:24 -0500918 port_down_device_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800919 ( sum( port_down_device_to_ofp_list ) /
920 len( port_down_device_to_ofp_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500921 port_down_device_to_ofp_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800922 str( round( numpy.std( port_down_device_to_ofp_list ), 1 ) )
923
924 main.log.report(
925 "Port down device-to-ofp " +
926 "Avg: " +
927 str( port_down_device_to_ofp_avg ) +
928 " ms " +
929 "Std Deviation: " +
930 port_down_device_to_ofp_std_dev +
931 " ms" )
932
933 port_up_graph_to_ofp_min = min( port_up_graph_to_ofp_list )
934 port_up_graph_to_ofp_max = max( port_up_graph_to_ofp_list )
andrewonlababb11c32014-11-04 15:03:24 -0500935 port_up_graph_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800936 ( sum( port_up_graph_to_ofp_list ) /
937 len( port_up_graph_to_ofp_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500938 port_up_graph_to_ofp_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800939 str( round( numpy.std( port_up_graph_to_ofp_list ), 1 ) )
940
941 main.log.report(
942 "Port up graph-to-ofp " +
943 "Avg: " +
944 str( port_up_graph_to_ofp_avg ) +
945 " ms " +
946 "Std Deviation: " +
947 port_up_graph_to_ofp_std_dev +
948 " ms" )
949
950 port_up_device_to_ofp_min = min( port_up_device_to_ofp_list )
951 port_up_device_to_ofp_max = max( port_up_device_to_ofp_list )
andrewonlab8790abb2014-11-06 13:51:54 -0500952 port_up_device_to_ofp_avg = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800953 ( sum( port_up_device_to_ofp_list ) /
954 len( port_up_device_to_ofp_list ) )
andrewonlab69864162014-11-11 16:28:48 -0500955 port_up_device_to_ofp_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -0800956 str( round( numpy.std( port_up_device_to_ofp_list ), 1 ) )
andrewonlab8790abb2014-11-06 13:51:54 -0500957
kelvin-onlab8a832582015-01-16 17:06:11 -0800958 main.log.report(
959 "Port up device-to-ofp " +
960 "Avg: " +
961 str( port_up_device_to_ofp_avg ) +
962 " ms " +
963 "Std Deviation: " +
964 port_up_device_to_ofp_std_dev +
965 " ms" )
andrewonlababb11c32014-11-04 15:03:24 -0500966
kelvin-onlab8a832582015-01-16 17:06:11 -0800967 utilities.assert_equals(
968 expect=main.TRUE,
969 actual=assertion,
970 onpass="Port discovery latency calculation successful",
971 onfail="Port discovery test failed" )
972
973 def CASE4( self, main ):
974 """
andrewonlab3622beb2014-10-28 16:07:56 -0400975 Link down event using loss rate 100%
kelvin-onlab8a832582015-01-16 17:06:11 -0800976
andrewonlab53b641c2014-10-31 19:44:44 -0400977 Important:
978 Use a simple 2 switch topology with 1 link between
kelvin-onlab8a832582015-01-16 17:06:11 -0800979 the two switches. Ensure that mac addresses of the
andrewonlab53b641c2014-10-31 19:44:44 -0400980 switches are 1 / 2 respectively
kelvin-onlab8a832582015-01-16 17:06:11 -0800981 """
andrewonlab3622beb2014-10-28 16:07:56 -0400982 import time
983 import subprocess
984 import os
985 import requests
986 import json
kelvin-onlab8a832582015-01-16 17:06:11 -0800987 import numpy
andrewonlab3622beb2014-10-28 16:07:56 -0400988
kelvin-onlab8a832582015-01-16 17:06:11 -0800989 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
990 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
991 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
992 ONOS_user = main.params[ 'CTRL' ][ 'user' ]
andrewonlab58f7d702014-11-07 13:21:19 -0500993
kelvin-onlab8a832582015-01-16 17:06:11 -0800994 default_sw_port = main.params[ 'CTRL' ][ 'port1' ]
995
996 # Number of iterations of case
997 num_iter = main.params[ 'TEST' ][ 'numIter' ]
998
999 # Timestamp 'keys' for json metrics output.
1000 # These are subject to change, hence moved into params
1001 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1002 linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ]
1003 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
1004
1005 debug_mode = main.params[ 'TEST' ][ 'debugMode' ]
1006
1007 local_time = time.strftime( '%x %X' )
1008 local_time = local_time.replace( "/", "" )
1009 local_time = local_time.replace( " ", "_" )
1010 local_time = local_time.replace( ":", "" )
andrewonlab58f7d702014-11-07 13:21:19 -05001011 if debug_mode == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -08001012 main.ONOS1.tshark_pcap( "eth0",
1013 "/tmp/link_lat_pcap_" + local_time )
andrewonlab53b641c2014-10-31 19:44:44 -04001014
kelvin-onlab8a832582015-01-16 17:06:11 -08001015 # Threshold for this test case
1016 up_threshold_str = main.params[ 'TEST' ][ 'linkUpThreshold' ]
1017 down_threshold_str = main.params[ 'TEST' ][ 'linkDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001018
kelvin-onlab8a832582015-01-16 17:06:11 -08001019 up_threshold_obj = up_threshold_str.split( "," )
1020 down_threshold_obj = down_threshold_str.split( "," )
andrewonlabe5bcef92014-11-06 17:53:20 -05001021
kelvin-onlab8a832582015-01-16 17:06:11 -08001022 up_threshold_min = int( up_threshold_obj[ 0 ] )
1023 up_threshold_max = int( up_threshold_obj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001024
kelvin-onlab8a832582015-01-16 17:06:11 -08001025 down_threshold_min = int( down_threshold_obj[ 0 ] )
1026 down_threshold_max = int( down_threshold_obj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001027
andrewonlab3622beb2014-10-28 16:07:56 -04001028 assertion = main.TRUE
kelvin-onlab8a832582015-01-16 17:06:11 -08001029 # Link event timestamp to system time list
andrewonlab3622beb2014-10-28 16:07:56 -04001030 link_down_link_to_system_list = []
1031 link_up_link_to_system_list = []
kelvin-onlab8a832582015-01-16 17:06:11 -08001032 # Graph event timestamp to system time list
andrewonlab3622beb2014-10-28 16:07:56 -04001033 link_down_graph_to_system_list = []
kelvin-onlab8a832582015-01-16 17:06:11 -08001034 link_up_graph_to_system_list = []
andrewonlab3622beb2014-10-28 16:07:56 -04001035
kelvin-onlab8a832582015-01-16 17:06:11 -08001036 main.log.report( "Link up / down discovery latency between " +
1037 "two switches" )
1038 main.log.report( "Simulated by setting loss-rate 100%" )
1039 main.log.report( "'tc qdisc add dev <intfs> root netem loss 100%'" )
1040 main.log.report( "Total iterations of test: " + str( num_iter ) )
andrewonlab3622beb2014-10-28 16:07:56 -04001041
kelvin-onlab8a832582015-01-16 17:06:11 -08001042 main.step( "Assign all switches" )
1043 main.Mininet1.assign_sw_controller(
1044 sw="1",
1045 ip1=ONOS1_ip,
1046 port1=default_sw_port )
1047 main.Mininet1.assign_sw_controller(
1048 sw="2",
1049 ip1=ONOS1_ip,
1050 port1=default_sw_port )
andrewonlab3622beb2014-10-28 16:07:56 -04001051
kelvin-onlab8a832582015-01-16 17:06:11 -08001052 main.step( "Verifying switch assignment" )
1053 result_s1 = main.Mininet1.get_sw_controller( sw="s1" )
1054 result_s2 = main.Mininet1.get_sw_controller( sw="s2" )
1055
1056 # Allow time for events to finish before taking measurements
1057 time.sleep( 10 )
andrewonlab3622beb2014-10-28 16:07:56 -04001058
andrewonlababb11c32014-11-04 15:03:24 -05001059 link_down1 = False
1060 link_down2 = False
1061 link_down3 = False
kelvin-onlab8a832582015-01-16 17:06:11 -08001062 # Start iteration of link event test
1063 for i in range( 0, int( num_iter ) ):
1064 main.step( "Getting initial system time as t0" )
andrewonlab3622beb2014-10-28 16:07:56 -04001065
kelvin-onlab8a832582015-01-16 17:06:11 -08001066 timestamp_link_down_t0 = time.time() * 1000
1067 # Link down is simulated by 100% loss rate using traffic
1068 # control command
1069 main.Mininet1.handle.sendline(
1070 "sh tc qdisc add dev s1-eth1 root netem loss 100%" )
1071
1072 # TODO: Iterate through 'links' command to verify that
1073 # link s1 -> s2 went down ( loop timeout 30 seconds )
andrewonlababb11c32014-11-04 15:03:24 -05001074 # on all 3 ONOS instances
kelvin-onlab8a832582015-01-16 17:06:11 -08001075 main.log.info( "Checking ONOS for link update" )
andrewonlab53b641c2014-10-31 19:44:44 -04001076 loop_count = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001077 while( not ( link_down1 and link_down2 and link_down3 )
andrewonlababb11c32014-11-04 15:03:24 -05001078 and loop_count < 30 ):
1079 json_str1 = main.ONOS1cli.links()
1080 json_str2 = main.ONOS2cli.links()
1081 json_str3 = main.ONOS3cli.links()
kelvin-onlab8a832582015-01-16 17:06:11 -08001082
1083 if not ( json_str1 and json_str2 and json_str3 ):
1084 main.log.error( "CLI command returned error " )
andrewonlab53b641c2014-10-31 19:44:44 -04001085 break
1086 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001087 json_obj1 = json.loads( json_str1 )
1088 json_obj2 = json.loads( json_str2 )
1089 json_obj3 = json.loads( json_str3 )
andrewonlababb11c32014-11-04 15:03:24 -05001090 for obj1 in json_obj1:
kelvin-onlab8a832582015-01-16 17:06:11 -08001091 if '01' not in obj1[ 'src' ][ 'device' ]:
andrewonlababb11c32014-11-04 15:03:24 -05001092 link_down1 = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001093 main.log.info( "Link down from " +
1094 "s1 -> s2 on ONOS1 detected" )
andrewonlababb11c32014-11-04 15:03:24 -05001095 for obj2 in json_obj2:
kelvin-onlab8a832582015-01-16 17:06:11 -08001096 if '01' not in obj2[ 'src' ][ 'device' ]:
andrewonlababb11c32014-11-04 15:03:24 -05001097 link_down2 = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001098 main.log.info( "Link down from " +
1099 "s1 -> s2 on ONOS2 detected" )
andrewonlababb11c32014-11-04 15:03:24 -05001100 for obj3 in json_obj3:
kelvin-onlab8a832582015-01-16 17:06:11 -08001101 if '01' not in obj3[ 'src' ][ 'device' ]:
andrewonlababb11c32014-11-04 15:03:24 -05001102 link_down3 = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001103 main.log.info( "Link down from " +
1104 "s1 -> s2 on ONOS3 detected" )
1105
andrewonlab53b641c2014-10-31 19:44:44 -04001106 loop_count += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001107 # If CLI doesn't like the continuous requests
1108 # and exits in this loop, increase the sleep here.
1109 # Consequently, while loop timeout will increase
1110 time.sleep( 1 )
1111
1112 # Give time for metrics measurement to catch up
1113 # NOTE: May need to be configured more accurately
1114 time.sleep( 10 )
1115 # If we exited the while loop and link down 1,2,3 are still
1116 # false, then ONOS has failed to discover link down event
1117 if not ( link_down1 and link_down2 and link_down3 ):
1118 main.log.info( "Link down discovery failed" )
1119
andrewonlab53b641c2014-10-31 19:44:44 -04001120 link_down_lat_graph1 = 0
1121 link_down_lat_graph2 = 0
1122 link_down_lat_graph3 = 0
1123 link_down_lat_device1 = 0
1124 link_down_lat_device2 = 0
1125 link_down_lat_device3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001126
andrewonlab53b641c2014-10-31 19:44:44 -04001127 assertion = main.FALSE
1128 else:
1129 json_topo_metrics_1 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001130 main.ONOS1cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001131 json_topo_metrics_2 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001132 main.ONOS2cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001133 json_topo_metrics_3 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001134 main.ONOS3cli.topology_events_metrics()
1135 json_topo_metrics_1 = json.loads( json_topo_metrics_1 )
1136 json_topo_metrics_2 = json.loads( json_topo_metrics_2 )
1137 json_topo_metrics_3 = json.loads( json_topo_metrics_3 )
andrewonlab53b641c2014-10-31 19:44:44 -04001138
kelvin-onlab8a832582015-01-16 17:06:11 -08001139 main.log.info( "Obtaining graph and device timestamp" )
andrewonlab53b641c2014-10-31 19:44:44 -04001140 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001141 json_topo_metrics_1[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001142 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001143 json_topo_metrics_2[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001144 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001145 json_topo_metrics_3[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001146
1147 link_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001148 json_topo_metrics_1[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001149 link_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001150 json_topo_metrics_2[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001151 link_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001152 json_topo_metrics_3[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001153
1154 if graph_timestamp_1 and graph_timestamp_2 and\
1155 graph_timestamp_3 and link_timestamp_1 and\
1156 link_timestamp_2 and link_timestamp_3:
kelvin-onlab8a832582015-01-16 17:06:11 -08001157 link_down_lat_graph1 = int( graph_timestamp_1 ) -\
1158 int( timestamp_link_down_t0 )
1159 link_down_lat_graph2 = int( graph_timestamp_2 ) -\
1160 int( timestamp_link_down_t0 )
1161 link_down_lat_graph3 = int( graph_timestamp_3 ) -\
1162 int( timestamp_link_down_t0 )
1163
1164 link_down_lat_link1 = int( link_timestamp_1 ) -\
1165 int( timestamp_link_down_t0 )
1166 link_down_lat_link2 = int( link_timestamp_2 ) -\
1167 int( timestamp_link_down_t0 )
1168 link_down_lat_link3 = int( link_timestamp_3 ) -\
1169 int( timestamp_link_down_t0 )
andrewonlab53b641c2014-10-31 19:44:44 -04001170 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001171 main.log.error( "There was an error calculating" +
1172 " the delta for link down event" )
andrewonlab53b641c2014-10-31 19:44:44 -04001173 link_down_lat_graph1 = 0
1174 link_down_lat_graph2 = 0
1175 link_down_lat_graph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001176
andrewonlab53b641c2014-10-31 19:44:44 -04001177 link_down_lat_device1 = 0
1178 link_down_lat_device2 = 0
1179 link_down_lat_device3 = 0
andrewonlab53b641c2014-10-31 19:44:44 -04001180
kelvin-onlab8a832582015-01-16 17:06:11 -08001181 main.log.info( "Link down latency ONOS1 iteration " +
1182 str( i ) + " (end-to-end): " +
1183 str( link_down_lat_graph1 ) + " ms" )
1184 main.log.info( "Link down latency ONOS2 iteration " +
1185 str( i ) + " (end-to-end): " +
1186 str( link_down_lat_graph2 ) + " ms" )
1187 main.log.info( "Link down latency ONOS3 iteration " +
1188 str( i ) + " (end-to-end): " +
1189 str( link_down_lat_graph3 ) + " ms" )
1190
1191 main.log.info( "Link down latency ONOS1 iteration " +
1192 str( i ) + " (link-event-to-system-timestamp): " +
1193 str( link_down_lat_link1 ) + " ms" )
1194 main.log.info( "Link down latency ONOS2 iteration " +
1195 str( i ) + " (link-event-to-system-timestamp): " +
1196 str( link_down_lat_link2 ) + " ms" )
1197 main.log.info( "Link down latency ONOS3 iteration " +
1198 str( i ) + " (link-event-to-system-timestamp): " +
1199 str( link_down_lat_link3 ) )
1200
1201 # Calculate avg of node calculations
1202 link_down_lat_graph_avg =\
1203 ( link_down_lat_graph1 +
1204 link_down_lat_graph2 +
1205 link_down_lat_graph3 ) / 3
1206 link_down_lat_link_avg =\
1207 ( link_down_lat_link1 +
1208 link_down_lat_link2 +
1209 link_down_lat_link3 ) / 3
1210
1211 # Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001212 if link_down_lat_graph_avg > down_threshold_min and\
1213 link_down_lat_graph_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001214 link_down_graph_to_system_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -08001215 link_down_lat_graph_avg )
andrewonlab8790abb2014-11-06 13:51:54 -05001216 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001217 main.log.info( "Link down latency exceeded threshold" )
1218 main.log.info( "Results for iteration " + str( i ) +
1219 "have been omitted" )
andrewonlabe5bcef92014-11-06 17:53:20 -05001220 if link_down_lat_link_avg > down_threshold_min and\
1221 link_down_lat_link_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001222 link_down_link_to_system_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -08001223 link_down_lat_link_avg )
andrewonlab8790abb2014-11-06 13:51:54 -05001224 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001225 main.log.info( "Link down latency exceeded threshold" )
1226 main.log.info( "Results for iteration " + str( i ) +
1227 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001228
kelvin-onlab8a832582015-01-16 17:06:11 -08001229 # NOTE: To remove loss rate and measure latency:
andrewonlab53b641c2014-10-31 19:44:44 -04001230 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlababb11c32014-11-04 15:03:24 -05001231 timestamp_link_up_t0 = time.time() * 1000
kelvin-onlab8a832582015-01-16 17:06:11 -08001232 main.Mininet1.handle.sendline( "sh tc qdisc del dev " +
1233 "s1-eth1 root" )
1234 main.Mininet1.handle.expect( "mininet>" )
1235
1236 main.log.info( "Checking ONOS for link update" )
1237
andrewonlababb11c32014-11-04 15:03:24 -05001238 link_down1 = True
1239 link_down2 = True
1240 link_down3 = True
1241 loop_count = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001242 while( ( link_down1 and link_down2 and link_down3 )
andrewonlababb11c32014-11-04 15:03:24 -05001243 and loop_count < 30 ):
1244 json_str1 = main.ONOS1cli.links()
1245 json_str2 = main.ONOS2cli.links()
1246 json_str3 = main.ONOS3cli.links()
kelvin-onlab8a832582015-01-16 17:06:11 -08001247 if not ( json_str1 and json_str2 and json_str3 ):
1248 main.log.error( "CLI command returned error " )
andrewonlababb11c32014-11-04 15:03:24 -05001249 break
1250 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001251 json_obj1 = json.loads( json_str1 )
1252 json_obj2 = json.loads( json_str2 )
1253 json_obj3 = json.loads( json_str3 )
1254
andrewonlababb11c32014-11-04 15:03:24 -05001255 for obj1 in json_obj1:
kelvin-onlab8a832582015-01-16 17:06:11 -08001256 if '01' in obj1[ 'src' ][ 'device' ]:
1257 link_down1 = False
1258 main.log.info( "Link up from " +
1259 "s1 -> s2 on ONOS1 detected" )
andrewonlababb11c32014-11-04 15:03:24 -05001260 for obj2 in json_obj2:
kelvin-onlab8a832582015-01-16 17:06:11 -08001261 if '01' in obj2[ 'src' ][ 'device' ]:
1262 link_down2 = False
1263 main.log.info( "Link up from " +
1264 "s1 -> s2 on ONOS2 detected" )
andrewonlababb11c32014-11-04 15:03:24 -05001265 for obj3 in json_obj3:
kelvin-onlab8a832582015-01-16 17:06:11 -08001266 if '01' in obj3[ 'src' ][ 'device' ]:
1267 link_down3 = False
1268 main.log.info( "Link up from " +
1269 "s1 -> s2 on ONOS3 detected" )
1270
andrewonlababb11c32014-11-04 15:03:24 -05001271 loop_count += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001272 time.sleep( 1 )
1273
1274 if ( link_down1 and link_down2 and link_down3 ):
1275 main.log.info( "Link up discovery failed" )
1276
andrewonlababb11c32014-11-04 15:03:24 -05001277 link_up_lat_graph1 = 0
1278 link_up_lat_graph2 = 0
1279 link_up_lat_graph3 = 0
1280 link_up_lat_device1 = 0
1281 link_up_lat_device2 = 0
1282 link_up_lat_device3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001283
andrewonlababb11c32014-11-04 15:03:24 -05001284 assertion = main.FALSE
1285 else:
1286 json_topo_metrics_1 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001287 main.ONOS1cli.topology_events_metrics()
andrewonlababb11c32014-11-04 15:03:24 -05001288 json_topo_metrics_2 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001289 main.ONOS2cli.topology_events_metrics()
andrewonlababb11c32014-11-04 15:03:24 -05001290 json_topo_metrics_3 =\
kelvin-onlab8a832582015-01-16 17:06:11 -08001291 main.ONOS3cli.topology_events_metrics()
1292 json_topo_metrics_1 = json.loads( json_topo_metrics_1 )
1293 json_topo_metrics_2 = json.loads( json_topo_metrics_2 )
1294 json_topo_metrics_3 = json.loads( json_topo_metrics_3 )
andrewonlababb11c32014-11-04 15:03:24 -05001295
kelvin-onlab8a832582015-01-16 17:06:11 -08001296 main.log.info( "Obtaining graph and device timestamp" )
andrewonlababb11c32014-11-04 15:03:24 -05001297 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001298 json_topo_metrics_1[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001299 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001300 json_topo_metrics_2[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001301 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001302 json_topo_metrics_3[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001303
1304 link_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001305 json_topo_metrics_1[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001306 link_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001307 json_topo_metrics_2[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001308 link_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001309 json_topo_metrics_3[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001310
1311 if graph_timestamp_1 and graph_timestamp_2 and\
1312 graph_timestamp_3 and link_timestamp_1 and\
1313 link_timestamp_2 and link_timestamp_3:
kelvin-onlab8a832582015-01-16 17:06:11 -08001314 link_up_lat_graph1 = int( graph_timestamp_1 ) -\
1315 int( timestamp_link_up_t0 )
1316 link_up_lat_graph2 = int( graph_timestamp_2 ) -\
1317 int( timestamp_link_up_t0 )
1318 link_up_lat_graph3 = int( graph_timestamp_3 ) -\
1319 int( timestamp_link_up_t0 )
1320
1321 link_up_lat_link1 = int( link_timestamp_1 ) -\
1322 int( timestamp_link_up_t0 )
1323 link_up_lat_link2 = int( link_timestamp_2 ) -\
1324 int( timestamp_link_up_t0 )
1325 link_up_lat_link3 = int( link_timestamp_3 ) -\
1326 int( timestamp_link_up_t0 )
andrewonlababb11c32014-11-04 15:03:24 -05001327 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001328 main.log.error( "There was an error calculating" +
1329 " the delta for link down event" )
andrewonlababb11c32014-11-04 15:03:24 -05001330 link_up_lat_graph1 = 0
1331 link_up_lat_graph2 = 0
1332 link_up_lat_graph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001333
andrewonlababb11c32014-11-04 15:03:24 -05001334 link_up_lat_device1 = 0
1335 link_up_lat_device2 = 0
1336 link_up_lat_device3 = 0
andrewonlababb11c32014-11-04 15:03:24 -05001337
kelvin-onlab8a832582015-01-16 17:06:11 -08001338 if debug_mode == 'on':
1339 main.log.info( "Link up latency ONOS1 iteration " +
1340 str( i ) + " (end-to-end): " +
1341 str( link_up_lat_graph1 ) + " ms" )
1342 main.log.info( "Link up latency ONOS2 iteration " +
1343 str( i ) + " (end-to-end): " +
1344 str( link_up_lat_graph2 ) + " ms" )
1345 main.log.info( "Link up latency ONOS3 iteration " +
1346 str( i ) + " (end-to-end): " +
1347 str( link_up_lat_graph3 ) + " ms" )
1348
1349 main.log.info(
1350 "Link up latency ONOS1 iteration " +
1351 str( i ) +
1352 " (link-event-to-system-timestamp): " +
1353 str( link_up_lat_link1 ) +
1354 " ms" )
1355 main.log.info(
1356 "Link up latency ONOS2 iteration " +
1357 str( i ) +
1358 " (link-event-to-system-timestamp): " +
1359 str( link_up_lat_link2 ) +
1360 " ms" )
1361 main.log.info(
1362 "Link up latency ONOS3 iteration " +
1363 str( i ) +
1364 " (link-event-to-system-timestamp): " +
1365 str( link_up_lat_link3 ) )
1366
1367 # Calculate avg of node calculations
1368 link_up_lat_graph_avg =\
1369 ( link_up_lat_graph1 +
1370 link_up_lat_graph2 +
1371 link_up_lat_graph3 ) / 3
1372 link_up_lat_link_avg =\
1373 ( link_up_lat_link1 +
1374 link_up_lat_link2 +
1375 link_up_lat_link3 ) / 3
1376
1377 # Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001378 if link_up_lat_graph_avg > up_threshold_min and\
1379 link_up_lat_graph_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001380 link_up_graph_to_system_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -08001381 link_up_lat_graph_avg )
andrewonlab8790abb2014-11-06 13:51:54 -05001382 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001383 main.log.info( "Link up latency exceeded threshold" )
1384 main.log.info( "Results for iteration " + str( i ) +
1385 "have been omitted" )
andrewonlabe5bcef92014-11-06 17:53:20 -05001386 if link_up_lat_link_avg > up_threshold_min and\
1387 link_up_lat_link_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001388 link_up_link_to_system_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -08001389 link_up_lat_link_avg )
andrewonlab8790abb2014-11-06 13:51:54 -05001390 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001391 main.log.info( "Link up latency exceeded threshold" )
1392 main.log.info( "Results for iteration " + str( i ) +
1393 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001394
kelvin-onlab8a832582015-01-16 17:06:11 -08001395 # Calculate min, max, avg of list and report
1396 link_down_min = min( link_down_graph_to_system_list )
1397 link_down_max = max( link_down_graph_to_system_list )
1398 link_down_avg = sum( link_down_graph_to_system_list ) / \
1399 len( link_down_graph_to_system_list )
1400 link_up_min = min( link_up_graph_to_system_list )
1401 link_up_max = max( link_up_graph_to_system_list )
1402 link_up_avg = sum( link_up_graph_to_system_list ) / \
1403 len( link_up_graph_to_system_list )
andrewonlab69864162014-11-11 16:28:48 -05001404 link_down_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001405 str( round( numpy.std( link_down_graph_to_system_list ), 1 ) )
andrewonlab69864162014-11-11 16:28:48 -05001406 link_up_std_dev = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001407 str( round( numpy.std( link_up_graph_to_system_list ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001408
kelvin-onlab8a832582015-01-16 17:06:11 -08001409 main.log.report( "Link down latency " +
1410 "Avg: " + str( link_down_avg ) + " ms " +
1411 "Std Deviation: " + link_down_std_dev + " ms" )
1412 main.log.report( "Link up latency " +
1413 "Avg: " + str( link_up_avg ) + " ms " +
1414 "Std Deviation: " + link_up_std_dev + " ms" )
andrewonlab4e124482014-11-04 13:37:25 -05001415
kelvin-onlab8a832582015-01-16 17:06:11 -08001416 utilities.assert_equals(
1417 expect=main.TRUE,
1418 actual=assertion,
1419 onpass="Link discovery latency calculation successful",
1420 onfail="Link discovery latency case failed" )
andrewonlab8790abb2014-11-06 13:51:54 -05001421
kelvin-onlab8a832582015-01-16 17:06:11 -08001422 def CASE5( self, main ):
1423 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001424 100 Switch discovery latency
1425
1426 Important:
kelvin-onlab8a832582015-01-16 17:06:11 -08001427 This test case can be potentially dangerous if
andrewonlab16ce4852014-10-30 13:41:09 -04001428 your machine has previously set iptables rules.
1429 One of the steps of the test case will flush
1430 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001431 Note:
kelvin-onlab8a832582015-01-16 17:06:11 -08001432 You can specify the number of switches in the
andrewonlab8790abb2014-11-06 13:51:54 -05001433 params file to adjust the switch discovery size
kelvin-onlab8a832582015-01-16 17:06:11 -08001434 ( and specify the corresponding topology in Mininet1
1435 .topo file )
1436 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001437 import time
1438 import subprocess
1439 import os
1440 import requests
1441 import json
1442
kelvin-onlab8a832582015-01-16 17:06:11 -08001443 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
1444 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
1445 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
1446 MN1_ip = main.params[ 'MN' ][ 'ip1' ]
1447 ONOS_user = main.params[ 'CTRL' ][ 'user' ]
andrewonlabb54b85b2014-10-28 18:43:57 -04001448
kelvin-onlab8a832582015-01-16 17:06:11 -08001449 default_sw_port = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001450
kelvin-onlab8a832582015-01-16 17:06:11 -08001451 # Number of iterations of case
1452 num_iter = main.params[ 'TEST' ][ 'numIter' ]
1453 num_sw = main.params[ 'TEST' ][ 'numSwitch' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001454
kelvin-onlab8a832582015-01-16 17:06:11 -08001455 # Timestamp 'keys' for json metrics output.
1456 # These are subject to change, hence moved into params
1457 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1458 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
1459
1460 debug_mode = main.params[ 'TEST' ][ 'debugMode' ]
1461
1462 local_time = time.strftime( '%X' )
1463 local_time = local_time.replace( "/", "" )
1464 local_time = local_time.replace( " ", "_" )
1465 local_time = local_time.replace( ":", "" )
andrewonlab58f7d702014-11-07 13:21:19 -05001466 if debug_mode == 'on':
kelvin-onlab8a832582015-01-16 17:06:11 -08001467 main.ONOS1.tshark_pcap( "eth0",
1468 "/tmp/100_sw_lat_pcap_" + local_time )
andrewonlabe5bcef92014-11-06 17:53:20 -05001469
kelvin-onlab8a832582015-01-16 17:06:11 -08001470 # Threshold for this test case
1471 sw_disc_threshold_str = main.params[ 'TEST' ][ 'swDisc100Threshold' ]
1472 sw_disc_threshold_obj = sw_disc_threshold_str.split( "," )
1473 sw_disc_threshold_min = int( sw_disc_threshold_obj[ 0 ] )
1474 sw_disc_threshold_max = int( sw_disc_threshold_obj[ 1 ] )
1475
1476 tshark_ofp_output = "/tmp/tshark_ofp_" + num_sw + "sw.txt"
1477 tshark_tcp_output = "/tmp/tshark_tcp_" + num_sw + "sw.txt"
andrewonlab53b641c2014-10-31 19:44:44 -04001478
1479 tshark_ofp_result_list = []
1480 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -04001481
andrewonlabe5bcef92014-11-06 17:53:20 -05001482 sw_discovery_lat_list = []
1483
kelvin-onlab8a832582015-01-16 17:06:11 -08001484 main.case( num_sw + " Switch discovery latency" )
1485 main.step( "Assigning all switches to ONOS1" )
1486 for i in range( 1, int( num_sw ) + 1 ):
andrewonlabb54b85b2014-10-28 18:43:57 -04001487 main.Mininet1.assign_sw_controller(
kelvin-onlab8a832582015-01-16 17:06:11 -08001488 sw=str( i ),
1489 ip1=ONOS1_ip,
1490 port1=default_sw_port )
andrewonlabb54b85b2014-10-28 18:43:57 -04001491
kelvin-onlab8a832582015-01-16 17:06:11 -08001492 # Ensure that nodes are configured with ptpd
1493 # Just a warning message
1494 main.log.info( "Please check ptpd configuration to ensure" +
1495 " All nodes' system times are in sync" )
1496 time.sleep( 5 )
1497
1498 for i in range( 0, int( num_iter ) ):
1499
1500 main.step( "Set iptables rule to block incoming sw connections" )
1501 # Set iptables rule to block incoming switch connections
1502 # The rule description is as follows:
andrewonlab53b641c2014-10-31 19:44:44 -04001503 # Append to INPUT rule,
1504 # behavior DROP that matches following:
1505 # * packet type: tcp
1506 # * source IP: MN1_ip
1507 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001508 main.ONOS1.handle.sendline(
kelvin-onlab8a832582015-01-16 17:06:11 -08001509 "sudo iptables -A INPUT -p tcp -s " + MN1_ip +
1510 " --dport " + default_sw_port + " -j DROP" )
1511 main.ONOS1.handle.expect( "\$" )
1512 # Append to OUTPUT rule,
andrewonlab53b641c2014-10-31 19:44:44 -04001513 # behavior DROP that matches following:
1514 # * packet type: tcp
1515 # * source IP: MN1_ip
1516 # * destination PORT: 6633
1517 main.ONOS1.handle.sendline(
kelvin-onlab8a832582015-01-16 17:06:11 -08001518 "sudo iptables -A OUTPUT -p tcp -s " + MN1_ip +
1519 " --dport " + default_sw_port + " -j DROP" )
1520 main.ONOS1.handle.expect( "\$" )
1521 # Give time to allow rule to take effect
1522 # NOTE: Sleep period may need to be configured
andrewonlab8790abb2014-11-06 13:51:54 -05001523 # based on the number of switches in the topology
kelvin-onlab8a832582015-01-16 17:06:11 -08001524 main.log.info( "Please wait for switch connection to " +
1525 "time out" )
1526 time.sleep( 60 )
andrewonlabb54b85b2014-10-28 18:43:57 -04001527
kelvin-onlab8a832582015-01-16 17:06:11 -08001528 # Gather vendor OFP with tshark
1529 main.ONOS1.tshark_grep( "OFP 86 Vendor",
1530 tshark_ofp_output )
1531 main.ONOS1.tshark_grep( "TCP 74 ",
1532 tshark_tcp_output )
1533
1534 # NOTE: Remove all iptables rule quickly ( flush )
1535 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001536 # removal took place
kelvin-onlab8a832582015-01-16 17:06:11 -08001537 # ( ensuring nodes are configured via ptp )
andrewonlabb54b85b2014-10-28 18:43:57 -04001538 # sudo iptables -F
kelvin-onlab8a832582015-01-16 17:06:11 -08001539
andrewonlab16ce4852014-10-30 13:41:09 -04001540 t0_system = time.time() * 1000
1541 main.ONOS1.handle.sendline(
kelvin-onlab8a832582015-01-16 17:06:11 -08001542 "sudo iptables -F" )
andrewonlabb54b85b2014-10-28 18:43:57 -04001543
kelvin-onlab8a832582015-01-16 17:06:11 -08001544 # Counter to track loop count
andrewonlab16ce4852014-10-30 13:41:09 -04001545 counter_loop = 0
1546 counter_avail1 = 0
1547 counter_avail2 = 0
1548 counter_avail3 = 0
1549 onos1_dev = False
1550 onos2_dev = False
1551 onos3_dev = False
1552 while counter_loop < 60:
kelvin-onlab8a832582015-01-16 17:06:11 -08001553 # Continue to check devices for all device
1554 # availability. When all devices in all 3
1555 # ONOS instances indicate that devices are available
1556 # obtain graph event timestamp for t1.
andrewonlab16ce4852014-10-30 13:41:09 -04001557 device_str_obj1 = main.ONOS1cli.devices()
1558 device_str_obj2 = main.ONOS2cli.devices()
1559 device_str_obj3 = main.ONOS3cli.devices()
1560
kelvin-onlab8a832582015-01-16 17:06:11 -08001561 device_json1 = json.loads( device_str_obj1 )
1562 device_json2 = json.loads( device_str_obj2 )
1563 device_json3 = json.loads( device_str_obj3 )
1564
andrewonlab16ce4852014-10-30 13:41:09 -04001565 for device1 in device_json1:
kelvin-onlab8a832582015-01-16 17:06:11 -08001566 if device1[ 'available' ]:
andrewonlab16ce4852014-10-30 13:41:09 -04001567 counter_avail1 += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001568 if counter_avail1 == int( num_sw ):
andrewonlab16ce4852014-10-30 13:41:09 -04001569 onos1_dev = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001570 main.log.info( "All devices have been " +
1571 "discovered on ONOS1" )
andrewonlab16ce4852014-10-30 13:41:09 -04001572 else:
1573 counter_avail1 = 0
1574 for device2 in device_json2:
kelvin-onlab8a832582015-01-16 17:06:11 -08001575 if device2[ 'available' ]:
andrewonlab16ce4852014-10-30 13:41:09 -04001576 counter_avail2 += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001577 if counter_avail2 == int( num_sw ):
andrewonlab16ce4852014-10-30 13:41:09 -04001578 onos2_dev = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001579 main.log.info( "All devices have been " +
1580 "discovered on ONOS2" )
andrewonlab16ce4852014-10-30 13:41:09 -04001581 else:
1582 counter_avail2 = 0
1583 for device3 in device_json3:
kelvin-onlab8a832582015-01-16 17:06:11 -08001584 if device3[ 'available' ]:
andrewonlab16ce4852014-10-30 13:41:09 -04001585 counter_avail3 += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001586 if counter_avail3 == int( num_sw ):
andrewonlab16ce4852014-10-30 13:41:09 -04001587 onos3_dev = True
kelvin-onlab8a832582015-01-16 17:06:11 -08001588 main.log.info( "All devices have been " +
1589 "discovered on ONOS3" )
andrewonlab16ce4852014-10-30 13:41:09 -04001590 else:
1591 counter_avail3 = 0
1592
1593 if onos1_dev and onos2_dev and onos3_dev:
kelvin-onlab8a832582015-01-16 17:06:11 -08001594 main.log.info( "All devices have been discovered " +
1595 "on all ONOS instances" )
andrewonlab16ce4852014-10-30 13:41:09 -04001596 json_str_topology_metrics_1 =\
1597 main.ONOS1cli.topology_events_metrics()
1598 json_str_topology_metrics_2 =\
1599 main.ONOS2cli.topology_events_metrics()
1600 json_str_topology_metrics_3 =\
1601 main.ONOS3cli.topology_events_metrics()
kelvin-onlab8a832582015-01-16 17:06:11 -08001602
1603 # Exit while loop if all devices discovered
1604 break
1605
andrewonlab16ce4852014-10-30 13:41:09 -04001606 counter_loop += 1
kelvin-onlab8a832582015-01-16 17:06:11 -08001607 # Give some time in between CLI calls
1608 #( will not affect measurement )
1609 time.sleep( 3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001610
1611 main.ONOS1.tshark_stop()
andrewonlab16ce4852014-10-30 13:41:09 -04001612
kelvin-onlab8a832582015-01-16 17:06:11 -08001613 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
1614 tshark_ofp_output + " /tmp/" )
1615 os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" +
1616 tshark_tcp_output + " /tmp/" )
1617
1618 # TODO: Automate OFP output analysis
1619 # Debug mode - print out packets captured at runtime
1620 if debug_mode == 'on':
1621 ofp_file = open( tshark_ofp_output, 'r' )
1622 main.log.info( "Tshark OFP Vendor output: " )
andrewonlab58f7d702014-11-07 13:21:19 -05001623 for line in ofp_file:
kelvin-onlab8a832582015-01-16 17:06:11 -08001624 tshark_ofp_result_list.append( line )
1625 main.log.info( line )
andrewonlab58f7d702014-11-07 13:21:19 -05001626 ofp_file.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001627
kelvin-onlab8a832582015-01-16 17:06:11 -08001628 tcp_file = open( tshark_tcp_output, 'r' )
1629 main.log.info( "Tshark TCP 74 output: " )
andrewonlab58f7d702014-11-07 13:21:19 -05001630 for line in tcp_file:
kelvin-onlab8a832582015-01-16 17:06:11 -08001631 tshark_tcp_result_list.append( line )
1632 main.log.info( line )
andrewonlab58f7d702014-11-07 13:21:19 -05001633 tcp_file.close()
andrewonlab53b641c2014-10-31 19:44:44 -04001634
kelvin-onlab8a832582015-01-16 17:06:11 -08001635 json_obj_1 = json.loads( json_str_topology_metrics_1 )
1636 json_obj_2 = json.loads( json_str_topology_metrics_2 )
1637 json_obj_3 = json.loads( json_str_topology_metrics_3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001638
1639 graph_timestamp_1 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001640 json_obj_1[ graphTimestamp ][ 'value' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001641 graph_timestamp_2 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001642 json_obj_2[ graphTimestamp ][ 'value' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001643 graph_timestamp_3 = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001644 json_obj_3[ graphTimestamp ][ 'value' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001645
kelvin-onlab8a832582015-01-16 17:06:11 -08001646 graph_lat_1 = int( graph_timestamp_1 ) - int( t0_system )
1647 graph_lat_2 = int( graph_timestamp_2 ) - int( t0_system )
1648 graph_lat_3 = int( graph_timestamp_3 ) - int( t0_system )
andrewonlab16ce4852014-10-30 13:41:09 -04001649
andrewonlabe5bcef92014-11-06 17:53:20 -05001650 avg_graph_lat = \
kelvin-onlab8a832582015-01-16 17:06:11 -08001651 ( int( graph_lat_1 ) +
1652 int( graph_lat_2 ) +
1653 int( graph_lat_3 ) ) / 3
1654
andrewonlabe5bcef92014-11-06 17:53:20 -05001655 if avg_graph_lat > sw_disc_threshold_min \
1656 and avg_graph_lat < sw_disc_threshold_max:
1657 sw_discovery_lat_list.append(
kelvin-onlab8a832582015-01-16 17:06:11 -08001658 avg_graph_lat )
andrewonlabe5bcef92014-11-06 17:53:20 -05001659 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001660 main.log.info( "100 Switch discovery latency " +
1661 "exceeded the threshold." )
andrewonlab16ce4852014-10-30 13:41:09 -04001662
kelvin-onlab8a832582015-01-16 17:06:11 -08001663 # END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001664
kelvin-onlab8a832582015-01-16 17:06:11 -08001665 sw_lat_min = min( sw_discovery_lat_list )
1666 sw_lat_max = max( sw_discovery_lat_list )
1667 sw_lat_avg = sum( sw_discovery_lat_list ) /\
1668 len( sw_discovery_lat_list )
andrewonlab16ce4852014-10-30 13:41:09 -04001669
kelvin-onlab8a832582015-01-16 17:06:11 -08001670 main.log.report( "100 Switch discovery lat " +
1671 "Min: " + str( sw_lat_min ) + " ms" +
1672 "Max: " + str( sw_lat_max ) + " ms" +
1673 "Avg: " + str( sw_lat_avg ) + " ms" )