kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1 | # TopoPerfNext |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 2 | # |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 3 | # Topology Performance test for ONOS-next |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 4 | #*** Revised for single node operation *** |
| 5 | # |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 6 | # andrew@onlab.us |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 7 | |
| 8 | import time |
| 9 | import sys |
| 10 | import os |
| 11 | import re |
| 12 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 13 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 14 | class TopoPerfNextSingleNode: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 15 | |
| 16 | def __init__( self ): |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 17 | self.default = '' |
| 18 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 19 | def CASE1( self, main ): |
| 20 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 21 | ONOS startup sequence |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 22 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 23 | import time |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 24 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 25 | cell_name = main.params[ 'ENV' ][ 'cellName' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 26 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 27 | git_pull = main.params[ 'GIT' ][ 'autoPull' ] |
| 28 | checkout_branch = main.params[ 'GIT' ][ 'checkout' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 29 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 30 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 31 | MN1_ip = main.params[ 'MN' ][ 'ip1' ] |
| 32 | BENCH_ip = main.params[ 'BENCH' ][ 'ip' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 33 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 34 | main.case( "Setting up test environment" ) |
| 35 | |
| 36 | main.step( "Creating cell file" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 37 | cell_file_result = main.ONOSbench.create_cell_file( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 38 | BENCH_ip, cell_name, MN1_ip, "onos-core", |
| 39 | ONOS1_ip ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 40 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 41 | main.step( "Applying cell file to environment" ) |
| 42 | cell_apply_result = main.ONOSbench.set_cell( cell_name ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 43 | verify_cell_result = main.ONOSbench.verify_cell() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 44 | |
| 45 | main.step( "Git checkout and pull " + checkout_branch ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 46 | if git_pull == 'on': |
| 47 | checkout_result = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 48 | main.ONOSbench.git_checkout( checkout_branch ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 49 | pull_result = main.ONOSbench.git_pull() |
| 50 | else: |
| 51 | checkout_result = main.TRUE |
| 52 | pull_result = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 53 | main.log.info( "Skipped git checkout and pull" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 54 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 55 | main.step( "Using mvn clean & install" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 56 | #mvn_result = main.ONOSbench.clean_install() |
| 57 | mvn_result = main.TRUE |
| 58 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 59 | main.step( "Creating ONOS package" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 60 | package_result = main.ONOSbench.onos_package() |
| 61 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 62 | main.step( "Installing ONOS package" ) |
| 63 | install1_result = main.ONOSbench.onos_install( node=ONOS1_ip ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 64 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 65 | # NOTE: This step may be unnecessary |
| 66 | #main.step( "Starting ONOS service" ) |
| 67 | #start_result = main.ONOSbench.onos_start( ONOS1_ip ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 68 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 69 | main.step( "Set cell for ONOS cli env" ) |
| 70 | main.ONOS1cli.set_cell( cell_name ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 71 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 72 | time.sleep( 10 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 73 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 74 | main.step( "Start onos cli" ) |
| 75 | cli1 = main.ONOS1cli.start_onos_cli( ONOS1_ip ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 76 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 77 | main.step( "Enable metrics feature" ) |
| 78 | main.ONOS1cli.feature_install( "onos-app-metrics" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 79 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 80 | utilities.assert_equals( expect=main.TRUE, |
| 81 | actual=cell_file_result and cell_apply_result and |
| 82 | verify_cell_result and checkout_result and |
| 83 | pull_result and mvn_result and |
| 84 | install1_result, |
| 85 | onpass="ONOS started successfully", |
| 86 | onfail="Failed to start ONOS" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 87 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 88 | def CASE2( self, main ): |
| 89 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 90 | Assign s1 to ONOS1 and measure latency |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 91 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 92 | There are 4 levels of latency measurements to this test: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 93 | 1 ) End-to-end measurement: Complete end-to-end measurement |
| 94 | from TCP ( SYN/ACK ) handshake to Graph change |
| 95 | 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 96 | measurement from OFP Vendor message to Graph change |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 97 | 3 ) OFP-to-device measurement: 'ONOS processing without |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 98 | graph change' snippet of measurement from OFP vendor |
| 99 | message to Device change timestamp |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 100 | 4 ) T0-to-device measurement: Measurement that includes |
| 101 | the switch handshake to devices timestamp without |
| 102 | the graph view change. ( TCP handshake -> Device |
| 103 | change ) |
| 104 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 105 | import time |
| 106 | import subprocess |
| 107 | import json |
| 108 | import requests |
| 109 | import os |
| 110 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 111 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 112 | ONOS_user = main.params[ 'CTRL' ][ 'user' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 113 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 114 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 115 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 116 | # Number of iterations of case |
| 117 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
| 118 | |
| 119 | # Timestamp 'keys' for json metrics output. |
| 120 | # These are subject to change, hence moved into params |
| 121 | deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ] |
| 122 | graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ] |
| 123 | |
| 124 | # List of switch add latency collected from |
| 125 | # all iterations |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 126 | latency_end_to_end_list = [] |
| 127 | latency_ofp_to_graph_list = [] |
| 128 | latency_ofp_to_device_list = [] |
| 129 | latency_t0_to_device_list = [] |
| 130 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 131 | # Directory/file to store tshark results |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 132 | tshark_of_output = "/tmp/tshark_of_topo.txt" |
| 133 | tshark_tcp_output = "/tmp/tshark_tcp_topo.txt" |
| 134 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 135 | # String to grep in tshark output |
| 136 | tshark_tcp_string = "TCP 74 " + default_sw_port |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 137 | tshark_of_string = "OFP 86 Vendor" |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 138 | |
| 139 | # Initialize assertion to TRUE |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 140 | assertion = main.TRUE |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 141 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 142 | main.log.report( "Latency of adding one switch" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 143 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 144 | for i in range( 0, int( num_iter ) ): |
| 145 | main.log.info( "Starting tshark capture" ) |
| 146 | |
| 147 | #* TCP [ ACK, SYN ] is used as t0_a, the |
| 148 | # very first "exchange" between ONOS and |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 149 | # the switch for end-to-end measurement |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 150 | #* OFP [ Stats Reply ] is used for t0_b |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 151 | # the very last OFP message between ONOS |
| 152 | # and the switch for ONOS measurement |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 153 | main.ONOS1.tshark_grep( tshark_tcp_string, |
| 154 | tshark_tcp_output ) |
| 155 | main.ONOS1.tshark_grep( tshark_of_string, |
| 156 | tshark_of_output ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 157 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 158 | # Wait and ensure tshark is started and |
| 159 | # capturing |
| 160 | time.sleep( 10 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 161 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 162 | main.log.info( "Assigning s1 to controller" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 163 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 164 | main.Mininet1.assign_sw_controller( |
| 165 | sw="1", |
| 166 | ip1=ONOS1_ip, |
| 167 | port1=default_sw_port ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 168 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 169 | # Wait and ensure switch is assigned |
| 170 | # before stopping tshark |
| 171 | time.sleep( 30 ) |
| 172 | |
| 173 | main.log.info( "Stopping all Tshark processes" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 174 | main.ONOS1.stop_tshark() |
| 175 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 176 | # tshark output is saved in ONOS. Use subprocess |
| 177 | # to copy over files to TestON for parsing |
| 178 | main.log.info( "Copying over tshark files" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 179 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 180 | # TCP CAPTURE **** |
| 181 | # Copy the tshark output from ONOS machine to |
| 182 | # TestON machine in tshark_tcp_output directory>file |
| 183 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 184 | tshark_tcp_output + " /tmp/" ) |
| 185 | tcp_file = open( tshark_tcp_output, 'r' ) |
| 186 | temp_text = tcp_file.readline() |
| 187 | temp_text = temp_text.split( " " ) |
| 188 | |
| 189 | main.log.info( "Object read in from TCP capture: " + |
| 190 | str( temp_text ) ) |
| 191 | if len( temp_text ) > 1: |
| 192 | t0_tcp = float( temp_text[ 1 ] ) * 1000.0 |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 193 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 194 | main.log.error( "Tshark output file for TCP" + |
| 195 | " returned unexpected results" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 196 | t0_tcp = 0 |
| 197 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 198 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 199 | tcp_file.close() |
| 200 | #**************** |
| 201 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 202 | # OF CAPTURE **** |
| 203 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 204 | tshark_of_output + " /tmp/" ) |
| 205 | of_file = open( tshark_of_output, 'r' ) |
| 206 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 207 | line_ofp = "" |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 208 | # Read until last line of file |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 209 | while True: |
| 210 | temp_text = of_file.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 211 | if temp_text != '': |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 212 | line_ofp = temp_text |
| 213 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 214 | break |
| 215 | obj = line_ofp.split( " " ) |
| 216 | |
| 217 | main.log.info( "Object read in from OFP capture: " + |
| 218 | str( line_ofp ) ) |
| 219 | |
| 220 | if len( line_ofp ) > 1: |
| 221 | t0_ofp = float( obj[ 1 ] ) * 1000.0 |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 222 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 223 | main.log.error( "Tshark output file for OFP" + |
| 224 | " returned unexpected results" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 225 | t0_ofp = 0 |
| 226 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 227 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 228 | of_file.close() |
| 229 | #**************** |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 230 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 231 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 232 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 233 | json_obj_1 = json.loads( json_str_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 234 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 235 | # Obtain graph timestamp. This timestsamp captures |
| 236 | # the epoch time at which the topology graph was updated. |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 237 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 238 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 239 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 240 | # Obtain device timestamp. This timestamp captures |
| 241 | # the epoch time at which the device event happened |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 242 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 243 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 244 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 245 | # t0 to device processing latency |
| 246 | delta_device_1 = int( device_timestamp_1 ) - int( t0_tcp ) |
| 247 | |
| 248 | # Get average of delta from all instances |
| 249 | avg_delta_device = ( int( delta_device_1 ) ) |
| 250 | |
| 251 | # Ensure avg delta meets the threshold before appending |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 252 | if avg_delta_device > 0.0 and avg_delta_device < 10000: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 253 | latency_t0_to_device_list.append( avg_delta_device ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 254 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 255 | main.log.info( "Results for t0-to-device ignored" + |
| 256 | "due to excess in threshold" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 257 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 258 | # t0 to graph processing latency ( end-to-end ) |
| 259 | delta_graph_1 = int( graph_timestamp_1 ) - int( t0_tcp ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 260 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 261 | # Get average of delta from all instances |
| 262 | avg_delta_graph = int( delta_graph_1 ) |
| 263 | |
| 264 | # Ensure avg delta meets the threshold before appending |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 265 | if avg_delta_graph > 0.0 and avg_delta_graph < 10000: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 266 | latency_end_to_end_list.append( avg_delta_graph ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 267 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 268 | main.log.info( "Results for end-to-end ignored" + |
| 269 | "due to excess in threshold" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 270 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 271 | # ofp to graph processing latency ( ONOS processing ) |
| 272 | delta_ofp_graph_1 = int( graph_timestamp_1 ) - int( t0_ofp ) |
| 273 | |
| 274 | avg_delta_ofp_graph = int( delta_ofp_graph_1 ) |
| 275 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 276 | if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 277 | latency_ofp_to_graph_list.append( avg_delta_ofp_graph ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 278 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 279 | main.log.info( "Results for ofp-to-graph " + |
| 280 | "ignored due to excess in threshold" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 281 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 282 | # ofp to device processing latency ( ONOS processing ) |
| 283 | delta_ofp_device_1 = float( device_timestamp_1 ) - float( t0_ofp ) |
| 284 | |
| 285 | avg_delta_ofp_device = float( delta_ofp_device_1 ) |
| 286 | |
| 287 | # NOTE: ofp - delta measurements are occasionally negative |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 288 | # due to system time misalignment. |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 289 | latency_ofp_to_device_list.append( avg_delta_ofp_device ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 290 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 291 | # TODO: |
| 292 | # Fetch logs upon threshold excess |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 293 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 294 | main.log.info( "ONOS1 delta end-to-end: " + |
| 295 | str( delta_graph_1 ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 296 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 297 | main.log.info( "ONOS1 delta OFP - graph: " + |
| 298 | str( delta_ofp_graph_1 ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 299 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 300 | main.log.info( "ONOS1 delta device - t0: " + |
| 301 | str( delta_device_1 ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 302 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 303 | main.step( "Remove switch from controller" ) |
| 304 | main.Mininet1.delete_sw_controller( "s1" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 305 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 306 | time.sleep( 5 ) |
| 307 | |
| 308 | # END of for loop iteration |
| 309 | |
| 310 | # If there is at least 1 element in each list, |
| 311 | # pass the test case |
| 312 | if len( latency_end_to_end_list ) > 0 and\ |
| 313 | len( latency_ofp_to_graph_list ) > 0 and\ |
| 314 | len( latency_ofp_to_device_list ) > 0 and\ |
| 315 | len( latency_t0_to_device_list ) > 0: |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 316 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 317 | elif len( latency_end_to_end_list ) == 0: |
| 318 | # The appending of 0 here is to prevent |
| 319 | # the min,max,sum functions from failing |
| 320 | # below |
| 321 | latency_end_to_end_list.append( 0 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 322 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 323 | elif len( latency_ofp_to_graph_list ) == 0: |
| 324 | latency_ofp_to_graph_list.append( 0 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 325 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 326 | elif len( latency_ofp_to_device_list ) == 0: |
| 327 | latency_ofp_to_device_list.append( 0 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 328 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 329 | elif len( latency_t0_to_device_list ) == 0: |
| 330 | latency_t0_to_device_list.append( 0 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 331 | assertion = main.FALSE |
| 332 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 333 | # Calculate min, max, avg of latency lists |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 334 | latency_end_to_end_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 335 | int( max( latency_end_to_end_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 336 | latency_end_to_end_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 337 | int( min( latency_end_to_end_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 338 | latency_end_to_end_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 339 | ( int( sum( latency_end_to_end_list ) ) / |
| 340 | len( latency_end_to_end_list ) ) |
| 341 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 342 | latency_ofp_to_graph_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 343 | int( max( latency_ofp_to_graph_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 344 | latency_ofp_to_graph_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 345 | int( min( latency_ofp_to_graph_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 346 | latency_ofp_to_graph_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 347 | ( int( sum( latency_ofp_to_graph_list ) ) / |
| 348 | len( latency_ofp_to_graph_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 349 | |
| 350 | latency_ofp_to_device_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 351 | int( max( latency_ofp_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 352 | latency_ofp_to_device_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 353 | int( min( latency_ofp_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 354 | latency_ofp_to_device_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 355 | ( int( sum( latency_ofp_to_device_list ) ) / |
| 356 | len( latency_ofp_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 357 | |
| 358 | latency_t0_to_device_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 359 | float( max( latency_t0_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 360 | latency_t0_to_device_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 361 | float( min( latency_t0_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 362 | latency_t0_to_device_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 363 | ( float( sum( latency_t0_to_device_list ) ) / |
| 364 | len( latency_ofp_to_device_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 365 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 366 | main.log.report( "Switch add - End-to-end latency: \n" + |
| 367 | "Min: " + str( latency_end_to_end_min ) + "\n" + |
| 368 | "Max: " + str( latency_end_to_end_max ) + "\n" + |
| 369 | "Avg: " + str( latency_end_to_end_avg ) ) |
| 370 | main.log.report( "Switch add - OFP-to-Graph latency: \n" + |
| 371 | "Min: " + str( latency_ofp_to_graph_min ) + "\n" + |
| 372 | "Max: " + str( latency_ofp_to_graph_max ) + "\n" + |
| 373 | "Avg: " + str( latency_ofp_to_graph_avg ) ) |
| 374 | main.log.report( "Switch add - t0-to-Device latency: \n" + |
| 375 | "Min: " + str( latency_t0_to_device_min ) + "\n" + |
| 376 | "Max: " + str( latency_t0_to_device_max ) + "\n" + |
| 377 | "Avg: " + str( latency_t0_to_device_avg ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 378 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 379 | utilities.assert_equals( expect=main.TRUE, actual=assertion, |
| 380 | onpass="Switch latency test successful", |
| 381 | onfail="Switch latency test failed" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 382 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 383 | def CASE3( self, main ): |
| 384 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 385 | Bring port up / down and measure latency. |
| 386 | Port enable / disable is simulated by ifconfig up / down |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 387 | |
| 388 | In ONOS-next, we must ensure that the port we are |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 389 | manipulating is connected to another switch with a valid |
| 390 | connection. Otherwise, graph view will not be updated. |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 391 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 392 | import time |
| 393 | import subprocess |
| 394 | import os |
| 395 | import requests |
| 396 | import json |
| 397 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 398 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 399 | ONOS_user = main.params[ 'CTRL' ][ 'user' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 400 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 401 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
| 402 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 403 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 404 | # Number of iterations of case |
| 405 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 406 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 407 | # Timestamp 'keys' for json metrics output. |
| 408 | # These are subject to change, hence moved into params |
| 409 | deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ] |
| 410 | graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ] |
| 411 | |
| 412 | # NOTE: Some hardcoded variables you may need to configure |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 413 | # besides the params |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 414 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 415 | tshark_port_status = "OFP 130 Port Status" |
| 416 | |
| 417 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 418 | tshark_port_down = "/tmp/tshark_port_down.txt" |
| 419 | interface_config = "s1-eth1" |
| 420 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 421 | main.log.report( "Port enable / disable latency" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 422 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 423 | main.step( "Assign switches s1 and s2 to controller 1" ) |
| 424 | main.Mininet1.assign_sw_controller( sw="1", ip1=ONOS1_ip, |
| 425 | port1=default_sw_port ) |
| 426 | main.Mininet1.assign_sw_controller( sw="2", ip1=ONOS1_ip, |
| 427 | port1=default_sw_port ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 428 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 429 | # Give enough time for metrics to propagate the |
| 430 | # assign controller event. Otherwise, these events may |
| 431 | # carry over to our measurements |
| 432 | time.sleep( 10 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 433 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 434 | main.step( "Verify switch is assigned correctly" ) |
| 435 | result_s1 = main.Mininet1.get_sw_controller( sw="s1" ) |
| 436 | result_s2 = main.Mininet1.get_sw_controller( sw="s2" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 437 | if result_s1 == main.FALSE or result_s2 == main.FALSE: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 438 | main.log.info( "Switch s1 was not assigned correctly" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 439 | assertion = main.FALSE |
| 440 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 441 | main.log.info( "Switch s1 was assigned correctly" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 442 | |
| 443 | port_up_device_to_ofp_list = [] |
| 444 | port_up_graph_to_ofp_list = [] |
| 445 | port_down_device_to_ofp_list = [] |
| 446 | port_down_graph_to_ofp_list = [] |
| 447 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 448 | for i in range( 0, int( num_iter ) ): |
| 449 | main.step( "Starting wireshark capture for port status down" ) |
| 450 | main.ONOS1.tshark_grep( tshark_port_status, |
| 451 | tshark_port_down ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 452 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 453 | time.sleep( 10 ) |
| 454 | |
| 455 | # Disable interface that is connected to switch 2 |
| 456 | main.step( "Disable port: " + interface_config ) |
| 457 | main.Mininet2.handle.sendline( "sudo ifconfig " + |
| 458 | interface_config + " down" ) |
| 459 | main.Mininet2.handle.expect( "\$" ) |
| 460 | time.sleep( 10 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 461 | |
| 462 | main.ONOS1.tshark_stop() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 463 | time.sleep( 5 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 464 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 465 | # Copy tshark output file from ONOS to TestON instance |
| 466 | #/tmp directory |
| 467 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 468 | tshark_port_down + " /tmp/" ) |
| 469 | |
| 470 | f_port_down = open( tshark_port_down, 'r' ) |
| 471 | # Get first line of port down event from tshark |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 472 | f_line = f_port_down.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 473 | obj_down = f_line.split( " " ) |
| 474 | if len( f_line ) > 0: |
| 475 | timestamp_begin_pt_down = int( float( obj_down[ 1 ] ) ) * 1000 |
| 476 | main.log.info( "Port down begin timestamp: " + |
| 477 | str( timestamp_begin_pt_down ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 478 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 479 | main.log.info( "Tshark output file returned unexpected" + |
| 480 | " results: " + str( obj_down ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 481 | timestamp_begin_pt_down = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 482 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 483 | f_port_down.close() |
| 484 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 485 | main.log.info( "TEST tshark obj: " + str( obj_down ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 486 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 487 | main.step( "Obtain t1 by REST call" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 488 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 489 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 490 | main.log.info( "TEST json_str 1: " + str( json_str_1 ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 491 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 492 | json_obj_1 = json.loads( json_str_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 493 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 494 | time.sleep( 5 ) |
| 495 | |
| 496 | # Obtain graph timestamp. This timestsamp captures |
| 497 | # the epoch time at which the topology graph was updated. |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 498 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 499 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 500 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 501 | # Obtain device timestamp. This timestamp captures |
| 502 | # the epoch time at which the device event happened |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 503 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 504 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 505 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 506 | # Get delta between graph event and OFP |
| 507 | pt_down_graph_to_ofp_1 = int( graph_timestamp_1 ) -\ |
| 508 | int( timestamp_begin_pt_down ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 509 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 510 | # Get delta between device event and OFP |
| 511 | pt_down_device_to_ofp_1 = int( device_timestamp_1 ) -\ |
| 512 | int( timestamp_begin_pt_down ) |
| 513 | |
| 514 | # Caluclate average across clusters |
| 515 | pt_down_graph_to_ofp_avg = int( pt_down_graph_to_ofp_1 ) |
| 516 | pt_down_device_to_ofp_avg = int( pt_down_device_to_ofp_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 517 | |
| 518 | if pt_down_graph_to_ofp_avg > 0.0 and \ |
| 519 | pt_down_graph_to_ofp_avg < 1000: |
| 520 | port_down_graph_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 521 | pt_down_graph_to_ofp_avg ) |
| 522 | main.log.info( "Port down: graph to ofp avg: " + |
| 523 | str( pt_down_graph_to_ofp_avg ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 524 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 525 | main.log.info( "Average port down graph-to-ofp result" + |
| 526 | " exceeded the threshold: " + |
| 527 | str( pt_down_graph_to_ofp_avg ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 528 | |
| 529 | if pt_down_device_to_ofp_avg > 0 and \ |
| 530 | pt_down_device_to_ofp_avg < 1000: |
| 531 | port_down_device_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 532 | pt_down_device_to_ofp_avg ) |
| 533 | main.log.info( "Port down: device to ofp avg: " + |
| 534 | str( pt_down_device_to_ofp_avg ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 535 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 536 | main.log.info( "Average port down device-to-ofp result" + |
| 537 | " exceeded the threshold: " + |
| 538 | str( pt_down_device_to_ofp_avg ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 539 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 540 | # Port up events |
| 541 | main.step( "Enable port and obtain timestamp" ) |
| 542 | main.step( "Starting wireshark capture for port status up" ) |
| 543 | main.ONOS1.tshark_grep( "OFP 130 Port Status", tshark_port_up ) |
| 544 | time.sleep( 5 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 545 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 546 | main.Mininet2.handle.sendline( "sudo ifconfig " + |
| 547 | interface_config + " up" ) |
| 548 | main.Mininet2.handle.expect( "\$" ) |
| 549 | time.sleep( 10 ) |
| 550 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 551 | main.ONOS1.tshark_stop() |
| 552 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 553 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 554 | tshark_port_up + " /tmp/" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 555 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 556 | f_port_up = open( tshark_port_up, 'r' ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 557 | f_line = f_port_up.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 558 | obj_up = f_line.split( " " ) |
| 559 | if len( f_line ) > 0: |
| 560 | timestamp_begin_pt_up = int( float( obj_up[ 1 ] ) ) * 1000 |
| 561 | main.log.info( "Port up begin timestamp: " + |
| 562 | str( timestamp_begin_pt_up ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 563 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 564 | main.log.info( "Tshark output file returned unexpected" + |
| 565 | " results." ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 566 | timestamp_begin_pt_up = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 567 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 568 | f_port_up.close() |
| 569 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 570 | main.step( "Obtain t1 by REST call" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 571 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 572 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 573 | json_obj_1 = json.loads( json_str_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 574 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 575 | # Obtain graph timestamp. This timestsamp captures |
| 576 | # the epoch time at which the topology graph was updated. |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 577 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 578 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 579 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 580 | # Obtain device timestamp. This timestamp captures |
| 581 | # the epoch time at which the device event happened |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 582 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 583 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 584 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 585 | # Get delta between graph event and OFP |
| 586 | pt_up_graph_to_ofp_1 = int( graph_timestamp_1 ) -\ |
| 587 | int( timestamp_begin_pt_up ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 588 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 589 | # Get delta between device event and OFP |
| 590 | pt_up_device_to_ofp_1 = int( device_timestamp_1 ) -\ |
| 591 | int( timestamp_begin_pt_up ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 592 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 593 | pt_up_graph_to_ofp_avg = float( pt_up_graph_to_ofp_1 ) |
| 594 | |
| 595 | pt_up_device_to_ofp_avg = float( pt_up_device_to_ofp_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 596 | |
| 597 | if pt_up_graph_to_ofp_avg > 0 and \ |
| 598 | pt_up_graph_to_ofp_avg < 1000: |
| 599 | port_up_graph_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 600 | pt_up_graph_to_ofp_avg ) |
| 601 | main.log.info( "Port down: graph to ofp avg: " + |
| 602 | str( pt_up_graph_to_ofp_avg ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 603 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 604 | main.log.info( "Average port up graph-to-ofp result" + |
| 605 | " exceeded the threshold: " + |
| 606 | str( pt_up_graph_to_ofp_avg ) ) |
| 607 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 608 | if pt_up_device_to_ofp_avg > 0 and \ |
| 609 | pt_up_device_to_ofp_avg < 1000: |
| 610 | port_up_device_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 611 | pt_up_device_to_ofp_avg ) |
| 612 | main.log.info( "Port up: device to ofp avg: " + |
| 613 | str( pt_up_device_to_ofp_avg ) + " ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 614 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 615 | main.log.info( "Average port up device-to-ofp result" + |
| 616 | " exceeded the threshold: " + |
| 617 | str( pt_up_device_to_ofp_avg ) ) |
| 618 | |
| 619 | # END ITERATION FOR LOOP |
| 620 | |
| 621 | # Check all list for latency existence and set assertion |
| 622 | if ( port_down_graph_to_ofp_list and port_down_device_to_ofp_list |
| 623 | and port_up_graph_to_ofp_list and port_up_device_to_ofp_list ): |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 624 | assertion = main.TRUE |
| 625 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 626 | # Calculate and report latency measurements |
| 627 | port_down_graph_to_ofp_min = min( port_down_graph_to_ofp_list ) |
| 628 | port_down_graph_to_ofp_max = max( port_down_graph_to_ofp_list ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 629 | port_down_graph_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 630 | ( sum( port_down_graph_to_ofp_list ) / |
| 631 | len( port_down_graph_to_ofp_list ) ) |
| 632 | |
| 633 | main.log.report( "Port down graph-to-ofp Min: " + |
| 634 | str( port_down_graph_to_ofp_min ) + " ms Max: " + |
| 635 | str( port_down_graph_to_ofp_max ) + " ms Avg: " + |
| 636 | str( port_down_graph_to_ofp_avg ) ) |
| 637 | |
| 638 | port_down_device_to_ofp_min = min( port_down_device_to_ofp_list ) |
| 639 | port_down_device_to_ofp_max = max( port_down_device_to_ofp_list ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 640 | port_down_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 641 | ( sum( port_down_device_to_ofp_list ) / |
| 642 | len( port_down_device_to_ofp_list ) ) |
| 643 | |
| 644 | main.log.report( "Port down device-to-ofp Min: " + |
| 645 | str( port_down_device_to_ofp_min ) + " ms Max: " + |
| 646 | str( port_down_device_to_ofp_max ) + " ms Avg: " + |
| 647 | str( port_down_device_to_ofp_avg ) ) |
| 648 | |
| 649 | port_up_graph_to_ofp_min = min( port_up_graph_to_ofp_list ) |
| 650 | port_up_graph_to_ofp_max = max( port_up_graph_to_ofp_list ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 651 | port_up_graph_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 652 | ( sum( port_up_graph_to_ofp_list ) / |
| 653 | len( port_up_graph_to_ofp_list ) ) |
| 654 | |
| 655 | main.log.report( "Port up graph-to-ofp Min: " + |
| 656 | str( port_up_graph_to_ofp_min ) + " ms Max: " + |
| 657 | str( port_up_graph_to_ofp_max ) + " ms Avg: " + |
| 658 | str( port_up_graph_to_ofp_avg ) ) |
| 659 | |
| 660 | port_up_device_to_ofp_min = min( port_up_device_to_ofp_list ) |
| 661 | port_up_device_to_ofp_max = max( port_up_device_to_ofp_list ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 662 | port_up_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 663 | ( sum( port_up_device_to_ofp_list ) / |
| 664 | len( port_up_device_to_ofp_list ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 665 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 666 | main.log.report( "Port up device-to-ofp Min: " + |
| 667 | str( port_up_device_to_ofp_min ) + " ms Max: " + |
| 668 | str( port_up_device_to_ofp_max ) + " ms Avg: " + |
| 669 | str( port_up_device_to_ofp_avg ) ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 670 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 671 | utilities.assert_equals( |
| 672 | expect=main.TRUE, |
| 673 | actual=assertion, |
| 674 | onpass="Port discovery latency calculation successful", |
| 675 | onfail="Port discovery test failed" ) |
| 676 | |
| 677 | def CASE4( self, main ): |
| 678 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 679 | Link down event using loss rate 100% |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 680 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 681 | Important: |
| 682 | Use a simple 2 switch topology with 1 link between |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 683 | the two switches. Ensure that mac addresses of the |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 684 | switches are 1 / 2 respectively |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 685 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 686 | import time |
| 687 | import subprocess |
| 688 | import os |
| 689 | import requests |
| 690 | import json |
| 691 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 692 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 693 | ONOS_user = main.params[ 'CTRL' ][ 'user' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 694 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 695 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
| 696 | |
| 697 | # Number of iterations of case |
| 698 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
| 699 | |
| 700 | # Timestamp 'keys' for json metrics output. |
| 701 | # These are subject to change, hence moved into params |
| 702 | deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ] |
| 703 | linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ] |
| 704 | graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 705 | |
| 706 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 707 | # Link event timestamp to system time list |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 708 | link_down_link_to_system_list = [] |
| 709 | link_up_link_to_system_list = [] |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 710 | # Graph event timestamp to system time list |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 711 | link_down_graph_to_system_list = [] |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 712 | link_up_graph_to_system_list = [] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 713 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 714 | main.log.report( "Add / remove link latency between " + |
| 715 | "two switches" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 716 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 717 | main.step( "Assign all switches" ) |
| 718 | main.Mininet1.assign_sw_controller( |
| 719 | sw="1", |
| 720 | ip1=ONOS1_ip, |
| 721 | port1=default_sw_port ) |
| 722 | main.Mininet1.assign_sw_controller( |
| 723 | sw="2", |
| 724 | ip1=ONOS1_ip, |
| 725 | port1=default_sw_port ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 726 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 727 | main.step( "Verifying switch assignment" ) |
| 728 | result_s1 = main.Mininet1.get_sw_controller( sw="s1" ) |
| 729 | result_s2 = main.Mininet1.get_sw_controller( sw="s2" ) |
| 730 | |
| 731 | # Allow time for events to finish before taking measurements |
| 732 | time.sleep( 10 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 733 | |
| 734 | link_down = False |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 735 | # Start iteration of link event test |
| 736 | for i in range( 0, int( num_iter ) ): |
| 737 | main.step( "Getting initial system time as t0" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 738 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 739 | timestamp_link_down_t0 = time.time() * 1000 |
| 740 | # Link down is simulated by 100% loss rate using traffic |
| 741 | # control command |
| 742 | main.Mininet1.handle.sendline( |
| 743 | "sh tc qdisc add dev s1-eth1 root netem loss 100%" ) |
| 744 | |
| 745 | # TODO: Iterate through 'links' command to verify that |
| 746 | # link s1 -> s2 went down ( loop timeout 30 seconds ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 747 | # on all 3 ONOS instances |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 748 | main.log.info( "Checking ONOS for link update" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 749 | loop_count = 0 |
| 750 | while( not link_down and loop_count < 30 ): |
| 751 | json_str = main.ONOS1cli.links() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 752 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 753 | if not json_str: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 754 | main.log.error( "CLI command returned error " ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 755 | break |
| 756 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 757 | json_obj = json.loads( json_str ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 758 | for obj in json_obj: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 759 | if '01' not in obj[ 'src' ][ 'device' ]: |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 760 | link_down = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 761 | main.log.report( "Link down from " + |
| 762 | "s1 -> s2 on ONOS1 detected" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 763 | loop_count += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 764 | # If CLI doesn't like the continuous requests |
| 765 | # and exits in this loop, increase the sleep here. |
| 766 | # Consequently, while loop timeout will increase |
| 767 | time.sleep( 1 ) |
| 768 | |
| 769 | # Give time for metrics measurement to catch up |
| 770 | # NOTE: May need to be configured more accurately |
| 771 | time.sleep( 10 ) |
| 772 | # If we exited the while loop and link down 1,2,3 are still |
| 773 | # false, then ONOS has failed to discover link down event |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 774 | if not link_down: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 775 | main.log.info( "Link down discovery failed" ) |
| 776 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 777 | link_down_lat_graph1 = 0 |
| 778 | link_down_lat_device1 = 0 |
| 779 | assertion = main.FALSE |
| 780 | else: |
| 781 | json_topo_metrics_1 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 782 | main.ONOS1cli.topology_events_metrics() |
| 783 | json_topo_metrics_1 = json.loads( json_topo_metrics_1 ) |
| 784 | |
| 785 | main.log.info( "Obtaining graph and device timestamp" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 786 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 787 | json_topo_metrics_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 788 | |
| 789 | link_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 790 | json_topo_metrics_1[ linkTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 791 | |
| 792 | if graph_timestamp_1 and link_timestamp_1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 793 | link_down_lat_graph1 = int( graph_timestamp_1 ) -\ |
| 794 | timestamp_link_down_t0 |
| 795 | |
| 796 | link_down_lat_link1 = int( link_timestamp_1 ) -\ |
| 797 | timestamp_link_down_t0 |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 798 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 799 | main.log.error( "There was an error calculating" + |
| 800 | " the delta for link down event" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 801 | link_down_lat_graph1 = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 802 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 803 | link_down_lat_device1 = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 804 | |
| 805 | main.log.report( "Link down latency ONOS1 iteration " + |
| 806 | str( i ) + " (end-to-end): " + |
| 807 | str( link_down_lat_graph1 ) + " ms" ) |
| 808 | |
| 809 | main.log.report( "Link down latency ONOS1 iteration " + |
| 810 | str( i ) + " (link-event-to-system-timestamp): " + |
| 811 | str( link_down_lat_link1 ) + " ms" ) |
| 812 | |
| 813 | # Calculate avg of node calculations |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 814 | link_down_lat_graph_avg = link_down_lat_graph1 |
| 815 | link_down_lat_link_avg = link_down_lat_link1 |
| 816 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 817 | # Set threshold and append latency to list |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 818 | if link_down_lat_graph_avg > 0.0 and\ |
| 819 | link_down_lat_graph_avg < 30000: |
| 820 | link_down_graph_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 821 | link_down_lat_graph_avg ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 822 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 823 | main.log.info( "Link down latency exceeded threshold" ) |
| 824 | main.log.info( "Results for iteration " + str( i ) + |
| 825 | "have been omitted" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 826 | if link_down_lat_link_avg > 0.0 and\ |
| 827 | link_down_lat_link_avg < 30000: |
| 828 | link_down_link_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 829 | link_down_lat_link_avg ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 830 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 831 | main.log.info( "Link down latency exceeded threshold" ) |
| 832 | main.log.info( "Results for iteration " + str( i ) + |
| 833 | "have been omitted" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 834 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 835 | # NOTE: To remove loss rate and measure latency: |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 836 | # 'sh tc qdisc del dev s1-eth1 root' |
| 837 | timestamp_link_up_t0 = time.time() * 1000 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 838 | main.Mininet1.handle.sendline( "sh tc qdisc del dev " + |
| 839 | "s1-eth1 root" ) |
| 840 | main.Mininet1.handle.expect( "mininet>" ) |
| 841 | |
| 842 | main.log.info( "Checking ONOS for link update" ) |
| 843 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 844 | link_down1 = True |
| 845 | loop_count = 0 |
| 846 | while( link_down1 and loop_count < 30 ): |
| 847 | json_str1 = main.ONOS1cli.links() |
| 848 | if not json_str1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 849 | main.log.error( "CLI command returned error " ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 850 | break |
| 851 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 852 | json_obj1 = json.loads( json_str1 ) |
| 853 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 854 | for obj1 in json_obj1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 855 | if '01' in obj1[ 'src' ][ 'device' ]: |
| 856 | link_down1 = False |
| 857 | main.log.report( "Link up from " + |
| 858 | "s1 -> s2 on ONOS1 detected" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 859 | loop_count += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 860 | time.sleep( 1 ) |
| 861 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 862 | if link_down1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 863 | main.log.info( "Link up discovery failed" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 864 | link_up_lat_graph1 = 0 |
| 865 | link_up_lat_device1 = 0 |
| 866 | assertion = main.FALSE |
| 867 | else: |
| 868 | json_topo_metrics_1 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 869 | main.ONOS1cli.topology_events_metrics() |
| 870 | json_topo_metrics_1 = json.loads( json_topo_metrics_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 871 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 872 | main.log.info( "Obtaining graph and device timestamp" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 873 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 874 | json_topo_metrics_1[ graphTimestamp ][ 'value' ] |
| 875 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 876 | link_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 877 | json_topo_metrics_1[ linkTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 878 | |
| 879 | if graph_timestamp_1 and link_timestamp_1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 880 | link_up_lat_graph1 = int( graph_timestamp_1 ) -\ |
| 881 | timestamp_link_up_t0 |
| 882 | link_up_lat_link1 = int( link_timestamp_1 ) -\ |
| 883 | timestamp_link_up_t0 |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 884 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 885 | main.log.error( "There was an error calculating" + |
| 886 | " the delta for link down event" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 887 | link_up_lat_graph1 = 0 |
| 888 | link_up_lat_device1 = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 889 | |
| 890 | main.log.info( "Link up latency ONOS1 iteration " + |
| 891 | str( i ) + " (end-to-end): " + |
| 892 | str( link_up_lat_graph1 ) + " ms" ) |
| 893 | |
| 894 | main.log.info( "Link up latency ONOS1 iteration " + |
| 895 | str( i ) + " (link-event-to-system-timestamp): " + |
| 896 | str( link_up_lat_link1 ) + " ms" ) |
| 897 | |
| 898 | # Calculate avg of node calculations |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 899 | link_up_lat_graph_avg = link_up_lat_graph1 |
| 900 | link_up_lat_link_avg = link_up_lat_link1 |
| 901 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 902 | # Set threshold and append latency to list |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 903 | if link_up_lat_graph_avg > 0.0 and\ |
| 904 | link_up_lat_graph_avg < 30000: |
| 905 | link_up_graph_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 906 | link_up_lat_graph_avg ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 907 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 908 | main.log.info( "Link up latency exceeded threshold" ) |
| 909 | main.log.info( "Results for iteration " + str( i ) + |
| 910 | "have been omitted" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 911 | if link_up_lat_link_avg > 0.0 and\ |
| 912 | link_up_lat_link_avg < 30000: |
| 913 | link_up_link_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 914 | link_up_lat_link_avg ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 915 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 916 | main.log.info( "Link up latency exceeded threshold" ) |
| 917 | main.log.info( "Results for iteration " + str( i ) + |
| 918 | "have been omitted" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 919 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 920 | # Calculate min, max, avg of list and report |
| 921 | link_down_min = min( link_down_graph_to_system_list ) |
| 922 | link_down_max = max( link_down_graph_to_system_list ) |
| 923 | link_down_avg = sum( link_down_graph_to_system_list ) / \ |
| 924 | len( link_down_graph_to_system_list ) |
| 925 | link_up_min = min( link_up_graph_to_system_list ) |
| 926 | link_up_max = max( link_up_graph_to_system_list ) |
| 927 | link_up_avg = sum( link_up_graph_to_system_list ) / \ |
| 928 | len( link_up_graph_to_system_list ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 929 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 930 | main.log.report( "Link down latency - Min: " + |
| 931 | str( link_down_min ) + "ms Max: " + |
| 932 | str( link_down_max ) + "ms Avg: " + |
| 933 | str( link_down_avg ) + "ms" ) |
| 934 | main.log.report( "Link up latency - Min: " + |
| 935 | str( link_up_min ) + "ms Max: " + |
| 936 | str( link_up_max ) + "ms Avg: " + |
| 937 | str( link_up_avg ) + "ms" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 938 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 939 | utilities.assert_equals( |
| 940 | expect=main.TRUE, |
| 941 | actual=assertion, |
| 942 | onpass="Link discovery latency calculation successful", |
| 943 | onfail="Link discovery latency case failed" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 944 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 945 | def CASE5( self, main ): |
| 946 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 947 | 100 Switch discovery latency |
| 948 | |
| 949 | Important: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 950 | This test case can be potentially dangerous if |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 951 | your machine has previously set iptables rules. |
| 952 | One of the steps of the test case will flush |
| 953 | all existing iptables rules. |
| 954 | Note: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 955 | You can specify the number of switches in the |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 956 | params file to adjust the switch discovery size |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 957 | ( and specify the corresponding topology in Mininet1 |
| 958 | .topo file ) |
| 959 | """ |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 960 | import time |
| 961 | import subprocess |
| 962 | import os |
| 963 | import requests |
| 964 | import json |
| 965 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 966 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 967 | MN1_ip = main.params[ 'MN' ][ 'ip1' ] |
| 968 | ONOS_user = main.params[ 'CTRL' ][ 'user' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 969 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 970 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 971 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 972 | # Number of iterations of case |
| 973 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
| 974 | num_sw = main.params[ 'TEST' ][ 'numSwitch' ] |
| 975 | |
| 976 | # Timestamp 'keys' for json metrics output. |
| 977 | # These are subject to change, hence moved into params |
| 978 | deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ] |
| 979 | graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ] |
| 980 | |
| 981 | tshark_ofp_output = "/tmp/tshark_ofp_" + num_sw + "sw.txt" |
| 982 | tshark_tcp_output = "/tmp/tshark_tcp_" + num_sw + "sw.txt" |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 983 | |
| 984 | tshark_ofp_result_list = [] |
| 985 | tshark_tcp_result_list = [] |
| 986 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 987 | main.case( num_sw + " Switch discovery latency" ) |
| 988 | main.step( "Assigning all switches to ONOS1" ) |
| 989 | for i in range( 1, int( num_sw ) + 1 ): |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 990 | main.Mininet1.assign_sw_controller( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 991 | sw=str( i ), |
| 992 | ip1=ONOS1_ip, |
| 993 | port1=default_sw_port ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 994 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 995 | # Ensure that nodes are configured with ptpd |
| 996 | # Just a warning message |
| 997 | main.log.info( "Please check ptpd configuration to ensure" + |
| 998 | " All nodes' system times are in sync" ) |
| 999 | time.sleep( 5 ) |
| 1000 | |
| 1001 | for i in range( 0, int( num_iter ) ): |
| 1002 | |
| 1003 | main.step( "Set iptables rule to block incoming sw connections" ) |
| 1004 | # Set iptables rule to block incoming switch connections |
| 1005 | # The rule description is as follows: |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1006 | # Append to INPUT rule, |
| 1007 | # behavior DROP that matches following: |
| 1008 | # * packet type: tcp |
| 1009 | # * source IP: MN1_ip |
| 1010 | # * destination PORT: 6633 |
| 1011 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1012 | "sudo iptables -A INPUT -p tcp -s " + MN1_ip + |
| 1013 | " --dport " + default_sw_port + " -j DROP" ) |
| 1014 | main.ONOS1.handle.expect( "\$" ) |
| 1015 | # Append to OUTPUT rule, |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1016 | # behavior DROP that matches following: |
| 1017 | # * packet type: tcp |
| 1018 | # * source IP: MN1_ip |
| 1019 | # * destination PORT: 6633 |
| 1020 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1021 | "sudo iptables -A OUTPUT -p tcp -s " + MN1_ip + |
| 1022 | " --dport " + default_sw_port + " -j DROP" ) |
| 1023 | main.ONOS1.handle.expect( "\$" ) |
| 1024 | # Give time to allow rule to take effect |
| 1025 | # NOTE: Sleep period may need to be configured |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1026 | # based on the number of switches in the topology |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1027 | main.log.info( "Please wait for switch connection to " + |
| 1028 | "time out" ) |
| 1029 | time.sleep( 60 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1030 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1031 | # Gather vendor OFP with tshark |
| 1032 | main.ONOS1.tshark_grep( "OFP 86 Vendor", |
| 1033 | tshark_ofp_output ) |
| 1034 | main.ONOS1.tshark_grep( "TCP 74 ", |
| 1035 | tshark_tcp_output ) |
| 1036 | |
| 1037 | # NOTE: Remove all iptables rule quickly ( flush ) |
| 1038 | # Before removal, obtain TestON timestamp at which |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1039 | # removal took place |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1040 | # ( ensuring nodes are configured via ptp ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1041 | # sudo iptables -F |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1042 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1043 | t0_system = time.time() * 1000 |
| 1044 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1045 | "sudo iptables -F" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1046 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1047 | # Counter to track loop count |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1048 | counter_loop = 0 |
| 1049 | counter_avail1 = 0 |
| 1050 | onos1_dev = False |
| 1051 | while counter_loop < 60: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1052 | # Continue to check devices for all device |
| 1053 | # availability. When all devices in all 3 |
| 1054 | # ONOS instances indicate that devices are available |
| 1055 | # obtain graph event timestamp for t1. |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1056 | device_str_obj1 = main.ONOS1cli.devices() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1057 | device_json1 = json.loads( device_str_obj1 ) |
| 1058 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1059 | for device1 in device_json1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1060 | if device1[ 'available' ]: |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1061 | counter_avail1 += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1062 | if counter_avail1 == int( num_sw ): |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1063 | onos1_dev = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1064 | main.log.info( "All devices have been " + |
| 1065 | "discovered on ONOS1" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1066 | else: |
| 1067 | counter_avail1 = 0 |
| 1068 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1069 | if onos1_dev: |
| 1070 | main.log.info( "All devices have been discovered " + |
| 1071 | "on all ONOS instances" ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1072 | json_str_topology_metrics_1 =\ |
| 1073 | main.ONOS1cli.topology_events_metrics() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1074 | # Exit while loop if all devices discovered |
| 1075 | break |
| 1076 | |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1077 | counter_loop += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1078 | # Give some time in between CLI calls |
| 1079 | #( will not affect measurement ) |
| 1080 | time.sleep( 3 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1081 | |
| 1082 | main.ONOS1.tshark_stop() |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1083 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1084 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 1085 | tshark_ofp_output + " /tmp/" ) |
| 1086 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 1087 | tshark_tcp_output + " /tmp/" ) |
| 1088 | ofp_file = open( tshark_ofp_output, 'r' ) |
| 1089 | |
| 1090 | # The following is for information purpose only. |
| 1091 | # TODO: Automate OFP output analysis |
| 1092 | main.log.info( "Tshark OFP Vendor output: " ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1093 | for line in ofp_file: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1094 | tshark_ofp_result_list.append( line ) |
| 1095 | main.log.info( line ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1096 | |
| 1097 | ofp_file.close() |
| 1098 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1099 | tcp_file = open( tshark_tcp_output, 'r' ) |
| 1100 | main.log.info( "Tshark TCP 74 output: " ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1101 | for line in tcp_file: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1102 | tshark_tcp_result_list.append( line ) |
| 1103 | main.log.info( line ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1104 | |
| 1105 | tcp_file.close() |
| 1106 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1107 | json_obj_1 = json.loads( json_str_topology_metrics_1 ) |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1108 | |
| 1109 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1110 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 47eddf2 | 2014-11-06 17:10:54 -0500 | [diff] [blame] | 1111 | |
| 1112 | main.log.info( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1113 | int( graph_timestamp_1 ) - int( t0_system ) ) |