kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1 | # TopoPerfNext |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 2 | # |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 3 | # Topology Performance test for ONOS-next |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 4 | # |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 5 | # andrew@onlab.us |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 6 | # |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 7 | # If your machine does not come with numpy |
| 8 | # run the following command: |
| 9 | # sudo apt-get install python-numpy python-scipy |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 10 | |
| 11 | import time |
| 12 | import sys |
| 13 | import os |
| 14 | import re |
| 15 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 16 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 17 | class TopoPerfNext: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 18 | |
| 19 | def __init__( self ): |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 20 | self.default = '' |
| 21 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 22 | def CASE1( self, main ): |
| 23 | """ |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 24 | ONOS startup sequence |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 25 | """ |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 26 | import time |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 27 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 28 | cell_name = main.params[ 'ENV' ][ 'cellName' ] |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 29 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 30 | 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 | |
andrewonlab | 6c8bbeb | 2014-11-14 12:43:48 -0500 | [diff] [blame] | 37 | #### 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 44 | MN1_ip = main.params[ 'MN' ][ 'ip1' ] |
| 45 | BENCH_ip = main.params[ 'BENCH' ][ 'ip' ] |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 46 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 47 | topo_cfg_file = main.params[ 'TEST' ][ 'topo_config_file' ] |
| 48 | topo_cfg_name = main.params[ 'TEST' ][ 'topo_config_name' ] |
andrewonlab | 0e1825c | 2014-11-20 20:07:00 -0500 | [diff] [blame] | 49 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 50 | 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( "\$" ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 58 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 59 | main.log.report( "Setting up test environment" ) |
andrewonlab | 6c8bbeb | 2014-11-14 12:43:48 -0500 | [diff] [blame] | 60 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 61 | 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" ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 68 | cell_file_result = main.ONOSbench.create_cell_file( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 69 | BENCH_ip, cell_name, MN1_ip, "onos-core,onos-app-metrics", |
| 70 | ONOS1_ip, ONOS2_ip, ONOS3_ip ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 71 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 72 | main.step( "Applying cell file to environment" ) |
| 73 | cell_apply_result = main.ONOSbench.set_cell( cell_name ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 74 | verify_cell_result = main.ONOSbench.verify_cell() |
andrewonlab | 28b84eb | 2014-12-02 15:53:35 -0500 | [diff] [blame] | 75 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 76 | # 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 ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 83 | if git_pull == 'on': |
| 84 | checkout_result = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 85 | main.ONOSbench.git_checkout( checkout_branch ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 86 | pull_result = main.ONOSbench.git_pull() |
| 87 | else: |
| 88 | checkout_result = main.TRUE |
| 89 | pull_result = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 90 | main.log.info( "Skipped git checkout and pull" ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 91 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 92 | # TODO: Uncomment when wiki posting works |
| 93 | #main.log.report( "Commit information - " ) |
| 94 | # main.ONOSbench.get_version( report=True ) |
andrewonlab | 9284434 | 2014-11-18 16:39:11 -0500 | [diff] [blame] | 95 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 96 | main.step( "Using mvn clean & install" ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 97 | #mvn_result = main.ONOSbench.clean_install() |
| 98 | mvn_result = main.TRUE |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 99 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 100 | 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 ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 104 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 105 | main.step( "Creating ONOS package" ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 106 | package_result = main.ONOSbench.onos_package() |
| 107 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 108 | 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 ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 112 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 113 | time.sleep( 10 ) |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 114 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 115 | 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 ) |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 119 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 120 | 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" ) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 128 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 129 | def CASE2( self, main ): |
| 130 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 131 | Assign s1 to ONOS1 and measure latency |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 132 | |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 133 | There are 4 levels of latency measurements to this test: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 134 | 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 |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 137 | measurement from OFP Vendor message to Graph change |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 138 | 3 ) OFP-to-device measurement: 'ONOS processing without |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 139 | graph change' snippet of measurement from OFP vendor |
| 140 | message to Device change timestamp |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 141 | 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 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 146 | import time |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 147 | import subprocess |
| 148 | import json |
| 149 | import requests |
| 150 | import os |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 151 | import numpy |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 152 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 153 | 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' ] |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 157 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 158 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 159 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 160 | # 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' ] ) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 164 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 165 | # 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' ] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 169 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 170 | debug_mode = main.params[ 'TEST' ][ 'debugMode' ] |
| 171 | onos_log = main.params[ 'TEST' ][ 'onosLogFile' ] |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 172 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 173 | # 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 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 181 | latency_end_to_end_list = [] |
| 182 | latency_ofp_to_graph_list = [] |
| 183 | latency_ofp_to_device_list = [] |
| 184 | latency_t0_to_device_list = [] |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 185 | latency_tcp_to_ofp_list = [] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 186 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 187 | # Directory/file to store tshark results |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 188 | tshark_of_output = "/tmp/tshark_of_topo.txt" |
| 189 | tshark_tcp_output = "/tmp/tshark_tcp_topo.txt" |
| 190 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 191 | # String to grep in tshark output |
| 192 | tshark_tcp_string = "TCP 74 " + default_sw_port |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 193 | tshark_of_string = "OFP 86 Vendor" |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 194 | |
| 195 | # Initialize assertion to TRUE |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 196 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 197 | |
| 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( ":", "" ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 202 | if debug_mode == 'on': |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 203 | main.ONOS1.tshark_pcap( "eth0", |
| 204 | "/tmp/single_sw_lat_pcap_" + local_time ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 205 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 206 | main.log.info( "TEST" ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 207 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 208 | 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 ) ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 215 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 216 | for i in range( 0, int( num_iter ) ): |
| 217 | main.log.info( "Starting tshark capture" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 218 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 219 | #* TCP [ ACK, SYN ] is used as t0_a, the |
| 220 | # very first "exchange" between ONOS and |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 221 | # the switch for end-to-end measurement |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 222 | #* OFP [ Stats Reply ] is used for t0_b |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 223 | # the very last OFP message between ONOS |
| 224 | # and the switch for ONOS measurement |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 225 | main.ONOS1.tshark_grep( tshark_tcp_string, |
| 226 | tshark_tcp_output ) |
| 227 | main.ONOS1.tshark_grep( tshark_of_string, |
| 228 | tshark_of_output ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 229 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 230 | # Wait and ensure tshark is started and |
| 231 | # capturing |
| 232 | time.sleep( 10 ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 233 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 234 | main.log.info( "Assigning s1 to controller" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 235 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 236 | main.Mininet1.assign_sw_controller( |
| 237 | sw="1", |
| 238 | ip1=ONOS1_ip, |
| 239 | port1=default_sw_port ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 240 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 241 | # Wait and ensure switch is assigned |
| 242 | # before stopping tshark |
| 243 | time.sleep( 30 ) |
| 244 | |
| 245 | main.log.info( "Stopping all Tshark processes" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 246 | main.ONOS1.stop_tshark() |
| 247 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 248 | # 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" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 251 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 252 | # 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 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 265 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 266 | main.log.error( "Tshark output file for TCP" + |
| 267 | " returned unexpected results" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 268 | t0_tcp = 0 |
| 269 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 270 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 271 | tcp_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 272 | #**************** |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 273 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 274 | # OF CAPTURE **** |
| 275 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 276 | tshark_of_output + " /tmp/" ) |
| 277 | of_file = open( tshark_of_output, 'r' ) |
| 278 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 279 | line_ofp = "" |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 280 | # Read until last line of file |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 281 | while True: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 282 | temp_text = of_file.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 283 | if temp_text != '': |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 284 | line_ofp = temp_text |
| 285 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 286 | 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 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 294 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 295 | main.log.error( "Tshark output file for OFP" + |
| 296 | " returned unexpected results" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 297 | t0_ofp = 0 |
| 298 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 299 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 300 | of_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 301 | #**************** |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 302 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 303 | 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() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 306 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 307 | 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 ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 310 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 311 | # Obtain graph timestamp. This timestsamp captures |
| 312 | # the epoch time at which the topology graph was updated. |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 313 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 314 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 315 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 316 | json_obj_2[ graphTimestamp ][ 'value' ] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 317 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 318 | json_obj_3[ graphTimestamp ][ 'value' ] |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 319 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 320 | # Obtain device timestamp. This timestamp captures |
| 321 | # the epoch time at which the device event happened |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 322 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 323 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 324 | device_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 325 | json_obj_2[ deviceTimestamp ][ 'value' ] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 326 | device_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 327 | json_obj_3[ deviceTimestamp ][ 'value' ] |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 328 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 329 | # 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 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 335 | avg_delta_device = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 336 | ( int( delta_device_1 ) + |
| 337 | int( delta_device_2 ) + |
| 338 | int( delta_device_3 ) ) / 3 |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 339 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 340 | # Ensure avg delta meets the threshold before appending |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 341 | if avg_delta_device > 0.0 and avg_delta_device < 10000\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 342 | and int( i ) > iter_ignore: |
| 343 | latency_t0_to_device_list.append( avg_delta_device ) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 344 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 345 | main.log.info( |
| 346 | "Results for t0-to-device ignored" + |
| 347 | "due to excess in threshold / warmup iteration." ) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 348 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 349 | # 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 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 355 | avg_delta_graph = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 356 | ( int( delta_graph_1 ) + |
| 357 | int( delta_graph_2 ) + |
| 358 | int( delta_graph_3 ) ) / 3 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 359 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 360 | # Ensure avg delta meets the threshold before appending |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 361 | if avg_delta_graph > 0.0 and avg_delta_graph < 10000\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 362 | and int( i ) > iter_ignore: |
| 363 | latency_end_to_end_list.append( avg_delta_graph ) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 364 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 365 | main.log.info( "Results for end-to-end ignored" + |
| 366 | "due to excess in threshold" ) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 367 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 368 | # 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 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 373 | avg_delta_ofp_graph = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 374 | ( int( delta_ofp_graph_1 ) + |
| 375 | int( delta_ofp_graph_2 ) + |
| 376 | int( delta_ofp_graph_3 ) ) / 3 |
| 377 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 378 | if avg_delta_ofp_graph > threshold_min \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 379 | and avg_delta_ofp_graph < threshold_max\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 380 | and int( i ) > iter_ignore: |
| 381 | latency_ofp_to_graph_list.append( avg_delta_ofp_graph ) |
| 382 | elif avg_delta_ofp_graph > ( -10 ) and \ |
andrewonlab | 9284434 | 2014-11-18 16:39:11 -0500 | [diff] [blame] | 383 | avg_delta_ofp_graph < 0.0 and\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 384 | 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 ) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 393 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 394 | main.log.info( "Results for ofp-to-graph " + |
| 395 | "ignored due to excess in threshold" ) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 396 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 397 | # 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 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 402 | avg_delta_ofp_device = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 403 | ( float( delta_ofp_device_1 ) + |
| 404 | float( delta_ofp_device_2 ) + |
| 405 | float( delta_ofp_device_3 ) ) / 3 |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 406 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 407 | # 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 ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 412 | if delta_ofp_tcp > threshold_min \ |
| 413 | and delta_ofp_tcp < threshold_max and\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 414 | int( i ) > iter_ignore: |
| 415 | latency_tcp_to_ofp_list.append( delta_ofp_tcp ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 416 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 417 | main.log.info( "Results fo tcp-to-ofp " + |
| 418 | "ignored due to excess in threshold" ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 419 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 420 | # TODO: |
| 421 | # Fetch logs upon threshold excess |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 422 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 423 | 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" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 429 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 430 | 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" ) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 436 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 437 | 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" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 443 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 444 | 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" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 452 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 453 | main.step( "Remove switch from controller" ) |
| 454 | main.Mininet1.delete_sw_controller( "s1" ) |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 455 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 456 | 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: |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 467 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 468 | 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 ) |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 473 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 474 | elif len( latency_ofp_to_graph_list ) == 0: |
| 475 | latency_ofp_to_graph_list.append( 0 ) |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 476 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 477 | elif len( latency_ofp_to_device_list ) == 0: |
| 478 | latency_ofp_to_device_list.append( 0 ) |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 479 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 480 | elif len( latency_t0_to_device_list ) == 0: |
| 481 | latency_t0_to_device_list.append( 0 ) |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 482 | assertion = main.FALSE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 483 | elif len( latency_tcp_to_ofp_list ) == 0: |
| 484 | latency_tcp_to_ofp_list.append( 0 ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 485 | assertion = main.FALSE |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 486 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 487 | # Calculate min, max, avg of latency lists |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 488 | latency_end_to_end_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 489 | int( max( latency_end_to_end_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 490 | latency_end_to_end_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 491 | int( min( latency_end_to_end_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 492 | latency_end_to_end_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 493 | ( int( sum( latency_end_to_end_list ) ) / |
| 494 | len( latency_end_to_end_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 495 | latency_end_to_end_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 496 | str( round( numpy.std( latency_end_to_end_list ), 1 ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 497 | |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 498 | latency_ofp_to_graph_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 499 | int( max( latency_ofp_to_graph_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 500 | latency_ofp_to_graph_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 501 | int( min( latency_ofp_to_graph_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 502 | latency_ofp_to_graph_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 503 | ( int( sum( latency_ofp_to_graph_list ) ) / |
| 504 | len( latency_ofp_to_graph_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 505 | latency_ofp_to_graph_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 506 | str( round( numpy.std( latency_ofp_to_graph_list ), 1 ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 507 | |
| 508 | latency_ofp_to_device_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 509 | int( max( latency_ofp_to_device_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 510 | latency_ofp_to_device_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 511 | int( min( latency_ofp_to_device_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 512 | latency_ofp_to_device_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 513 | ( int( sum( latency_ofp_to_device_list ) ) / |
| 514 | len( latency_ofp_to_device_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 515 | latency_ofp_to_device_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 516 | str( round( numpy.std( latency_ofp_to_device_list ), 1 ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 517 | |
| 518 | latency_t0_to_device_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 519 | int( max( latency_t0_to_device_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 520 | latency_t0_to_device_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 521 | int( min( latency_t0_to_device_list ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 522 | latency_t0_to_device_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 523 | ( int( sum( latency_t0_to_device_list ) ) / |
| 524 | len( latency_t0_to_device_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 525 | latency_ofp_to_device_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 526 | str( round( numpy.std( latency_t0_to_device_list ), 1 ) ) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 527 | |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 528 | latency_tcp_to_ofp_max = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 529 | int( max( latency_tcp_to_ofp_list ) ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 530 | latency_tcp_to_ofp_min = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 531 | int( min( latency_tcp_to_ofp_list ) ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 532 | latency_tcp_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 533 | ( int( sum( latency_tcp_to_ofp_list ) ) / |
| 534 | len( latency_tcp_to_ofp_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 535 | latency_tcp_to_ofp_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 536 | str( round( numpy.std( latency_tcp_to_ofp_list ), 1 ) ) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 537 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 538 | 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" ) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 565 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 566 | if debug_mode == 'on': |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 567 | main.ONOS1.cp_logs_to_dir( "/opt/onos/log/karaf.log", |
| 568 | "/tmp/", copy_file_name="sw_lat_karaf" ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 569 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 570 | utilities.assert_equals( expect=main.TRUE, actual=assertion, |
| 571 | onpass="Switch latency test successful", |
| 572 | onfail="Switch latency test failed" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 573 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 574 | def CASE3( self, main ): |
| 575 | """ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 576 | Bring port up / down and measure latency. |
| 577 | Port enable / disable is simulated by ifconfig up / down |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 578 | |
| 579 | In ONOS-next, we must ensure that the port we are |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 580 | manipulating is connected to another switch with a valid |
| 581 | connection. Otherwise, graph view will not be updated. |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 582 | """ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 583 | import time |
| 584 | import subprocess |
| 585 | import os |
| 586 | import requests |
| 587 | import json |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 588 | import numpy |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 589 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 590 | 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' ] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 594 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 595 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
| 596 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 597 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 598 | # Number of iterations of case |
| 599 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 600 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 601 | # 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( ":", "" ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 612 | if debug_mode == 'on': |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 613 | main.ONOS1.tshark_pcap( "eth0", |
| 614 | "/tmp/port_lat_pcap_" + local_time ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 615 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 616 | # Threshold for this test case |
| 617 | up_threshold_str = main.params[ 'TEST' ][ 'portUpThreshold' ] |
| 618 | down_threshold_str = main.params[ 'TEST' ][ 'portDownThreshold' ] |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 619 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 620 | up_threshold_obj = up_threshold_str.split( "," ) |
| 621 | down_threshold_obj = down_threshold_str.split( "," ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 622 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 623 | up_threshold_min = int( up_threshold_obj[ 0 ] ) |
| 624 | up_threshold_max = int( up_threshold_obj[ 1 ] ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 625 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 626 | 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 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 630 | # besides the params |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 631 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 632 | 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" |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 636 | interface_config = "s1-eth1" |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 637 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 638 | 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 ) ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 641 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 642 | 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 647 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 648 | # 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 652 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 653 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 658 | 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 662 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 663 | time.sleep( 5 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 664 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 665 | # 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 672 | main.ONOS1.tshark_stop() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 673 | |
| 674 | main.step( "Obtain t1 by metrics call" ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 675 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 679 | 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 682 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 683 | # 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 |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 690 | f_line = f_port_down.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 691 | 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 ) ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 696 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 697 | main.log.info( "Tshark output file returned unexpected" + |
| 698 | " results: " + str( obj_down ) ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 699 | timestamp_begin_pt_down = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 700 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 701 | f_port_down.close() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 702 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 703 | main.log.info( "TEST tshark obj: " + str( obj_down ) ) |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 704 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 705 | time.sleep( 3 ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 706 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 707 | # Obtain graph timestamp. This timestsamp captures |
| 708 | # the epoch time at which the topology graph was updated. |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 709 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 710 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 711 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 712 | json_obj_2[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 713 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 714 | json_obj_3[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 715 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 716 | main.log.info( "TEST graph timestamp ONOS1: " + |
| 717 | str( graph_timestamp_1 ) ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 718 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 719 | # Obtain device timestamp. This timestamp captures |
| 720 | # the epoch time at which the device event happened |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 721 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 722 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 723 | device_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 724 | json_obj_2[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 725 | device_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 726 | json_obj_3[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 727 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 728 | # 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 ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 735 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 736 | # 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 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 745 | pt_down_graph_to_ofp_avg =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 746 | ( int( pt_down_graph_to_ofp_1 ) + |
| 747 | int( pt_down_graph_to_ofp_2 ) + |
| 748 | int( pt_down_graph_to_ofp_3 ) ) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 749 | pt_down_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 750 | ( int( pt_down_device_to_ofp_1 ) + |
| 751 | int( pt_down_device_to_ofp_2 ) + |
| 752 | int( pt_down_device_to_ofp_3 ) ) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 753 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 754 | if pt_down_graph_to_ofp_avg > down_threshold_min and \ |
| 755 | pt_down_graph_to_ofp_avg < down_threshold_max: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 756 | port_down_graph_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 757 | 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" ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 760 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 761 | main.log.info( "Average port down graph-to-ofp result" + |
| 762 | " exceeded the threshold: " + |
| 763 | str( pt_down_graph_to_ofp_avg ) ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 764 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 765 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 768 | 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" ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 771 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 772 | main.log.info( "Average port down device-to-ofp result" + |
| 773 | " exceeded the threshold: " + |
| 774 | str( pt_down_device_to_ofp_avg ) ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 775 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 776 | # 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 781 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 782 | 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 ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 788 | main.ONOS1.tshark_stop() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 789 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 790 | # 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" ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 794 | 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() |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 797 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 798 | 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 ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 801 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 802 | os.system( "scp " + ONOS_user + "@" + ONOS1_ip + ":" + |
| 803 | tshark_port_up + " /tmp/" ) |
| 804 | |
| 805 | f_port_up = open( tshark_port_up, 'r' ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 806 | f_line = f_port_up.readline() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 807 | 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 ) ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 812 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 813 | main.log.info( "Tshark output file returned unexpected" + |
| 814 | " results." ) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 815 | timestamp_begin_pt_up = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 816 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 817 | f_port_up.close() |
| 818 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 819 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 820 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 821 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 822 | json_obj_2[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 823 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 824 | json_obj_3[ graphTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 825 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 826 | # Obtain device timestamp. This timestamp captures |
| 827 | # the epoch time at which the device event happened |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 828 | device_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 829 | json_obj_1[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 830 | device_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 831 | json_obj_2[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 832 | device_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 833 | json_obj_3[ deviceTimestamp ][ 'value' ] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 834 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 835 | # 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 ) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 842 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 843 | # 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 ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 850 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 851 | 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 ) ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 854 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 855 | 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 ) ) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 858 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 859 | pt_up_graph_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 860 | ( int( pt_up_graph_to_ofp_1 ) + |
| 861 | int( pt_up_graph_to_ofp_2 ) + |
| 862 | int( pt_up_graph_to_ofp_3 ) ) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 863 | |
| 864 | pt_up_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 865 | ( int( pt_up_device_to_ofp_1 ) + |
| 866 | int( pt_up_device_to_ofp_2 ) + |
| 867 | int( pt_up_device_to_ofp_3 ) ) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 868 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 869 | if pt_up_graph_to_ofp_avg > up_threshold_min and \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 870 | pt_up_graph_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 871 | port_up_graph_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 872 | 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" ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 875 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 876 | main.log.info( "Average port up graph-to-ofp result" + |
| 877 | " exceeded the threshold: " + |
| 878 | str( pt_up_graph_to_ofp_avg ) ) |
| 879 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 880 | if pt_up_device_to_ofp_avg > up_threshold_min and \ |
| 881 | pt_up_device_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 882 | port_up_device_to_ofp_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 883 | 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" ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 886 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 887 | 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 ): |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 896 | assertion = main.TRUE |
| 897 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 898 | # 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 ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 901 | port_down_graph_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 902 | ( sum( port_down_graph_to_ofp_list ) / |
| 903 | len( port_down_graph_to_ofp_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 904 | port_down_graph_to_ofp_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 905 | 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 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 918 | port_down_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 919 | ( sum( port_down_device_to_ofp_list ) / |
| 920 | len( port_down_device_to_ofp_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 921 | port_down_device_to_ofp_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 922 | 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 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 935 | port_up_graph_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 936 | ( sum( port_up_graph_to_ofp_list ) / |
| 937 | len( port_up_graph_to_ofp_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 938 | port_up_graph_to_ofp_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 939 | 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 ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 952 | port_up_device_to_ofp_avg = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 953 | ( sum( port_up_device_to_ofp_list ) / |
| 954 | len( port_up_device_to_ofp_list ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 955 | port_up_device_to_ofp_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 956 | str( round( numpy.std( port_up_device_to_ofp_list ), 1 ) ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 957 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 958 | 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" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 966 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 967 | 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 | """ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 975 | Link down event using loss rate 100% |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 976 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 977 | Important: |
| 978 | Use a simple 2 switch topology with 1 link between |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 979 | the two switches. Ensure that mac addresses of the |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 980 | switches are 1 / 2 respectively |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 981 | """ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 982 | import time |
| 983 | import subprocess |
| 984 | import os |
| 985 | import requests |
| 986 | import json |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 987 | import numpy |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 988 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 989 | 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' ] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 993 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 994 | 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( ":", "" ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1011 | if debug_mode == 'on': |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1012 | main.ONOS1.tshark_pcap( "eth0", |
| 1013 | "/tmp/link_lat_pcap_" + local_time ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1014 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1015 | # Threshold for this test case |
| 1016 | up_threshold_str = main.params[ 'TEST' ][ 'linkUpThreshold' ] |
| 1017 | down_threshold_str = main.params[ 'TEST' ][ 'linkDownThreshold' ] |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1018 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1019 | up_threshold_obj = up_threshold_str.split( "," ) |
| 1020 | down_threshold_obj = down_threshold_str.split( "," ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1021 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1022 | up_threshold_min = int( up_threshold_obj[ 0 ] ) |
| 1023 | up_threshold_max = int( up_threshold_obj[ 1 ] ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1024 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1025 | down_threshold_min = int( down_threshold_obj[ 0 ] ) |
| 1026 | down_threshold_max = int( down_threshold_obj[ 1 ] ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1027 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1028 | assertion = main.TRUE |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1029 | # Link event timestamp to system time list |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1030 | link_down_link_to_system_list = [] |
| 1031 | link_up_link_to_system_list = [] |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1032 | # Graph event timestamp to system time list |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1033 | link_down_graph_to_system_list = [] |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1034 | link_up_graph_to_system_list = [] |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1035 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1036 | 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 ) ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1041 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1042 | 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 ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1051 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1052 | 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 ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1058 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1059 | link_down1 = False |
| 1060 | link_down2 = False |
| 1061 | link_down3 = False |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1062 | # Start iteration of link event test |
| 1063 | for i in range( 0, int( num_iter ) ): |
| 1064 | main.step( "Getting initial system time as t0" ) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1065 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1066 | 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 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1074 | # on all 3 ONOS instances |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1075 | main.log.info( "Checking ONOS for link update" ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1076 | loop_count = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1077 | while( not ( link_down1 and link_down2 and link_down3 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1078 | and loop_count < 30 ): |
| 1079 | json_str1 = main.ONOS1cli.links() |
| 1080 | json_str2 = main.ONOS2cli.links() |
| 1081 | json_str3 = main.ONOS3cli.links() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1082 | |
| 1083 | if not ( json_str1 and json_str2 and json_str3 ): |
| 1084 | main.log.error( "CLI command returned error " ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1085 | break |
| 1086 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1087 | json_obj1 = json.loads( json_str1 ) |
| 1088 | json_obj2 = json.loads( json_str2 ) |
| 1089 | json_obj3 = json.loads( json_str3 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1090 | for obj1 in json_obj1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1091 | if '01' not in obj1[ 'src' ][ 'device' ]: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1092 | link_down1 = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1093 | main.log.info( "Link down from " + |
| 1094 | "s1 -> s2 on ONOS1 detected" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1095 | for obj2 in json_obj2: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1096 | if '01' not in obj2[ 'src' ][ 'device' ]: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1097 | link_down2 = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1098 | main.log.info( "Link down from " + |
| 1099 | "s1 -> s2 on ONOS2 detected" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1100 | for obj3 in json_obj3: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1101 | if '01' not in obj3[ 'src' ][ 'device' ]: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1102 | link_down3 = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1103 | main.log.info( "Link down from " + |
| 1104 | "s1 -> s2 on ONOS3 detected" ) |
| 1105 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1106 | loop_count += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1107 | # 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 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1120 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1126 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1127 | assertion = main.FALSE |
| 1128 | else: |
| 1129 | json_topo_metrics_1 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1130 | main.ONOS1cli.topology_events_metrics() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1131 | json_topo_metrics_2 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1132 | main.ONOS2cli.topology_events_metrics() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1133 | json_topo_metrics_3 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1134 | 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 ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1138 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1139 | main.log.info( "Obtaining graph and device timestamp" ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1140 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1141 | json_topo_metrics_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1142 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1143 | json_topo_metrics_2[ graphTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1144 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1145 | json_topo_metrics_3[ graphTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1146 | |
| 1147 | link_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1148 | json_topo_metrics_1[ linkTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1149 | link_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1150 | json_topo_metrics_2[ linkTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1151 | link_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1152 | json_topo_metrics_3[ linkTimestamp ][ 'value' ] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1153 | |
| 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1157 | 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 ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1170 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1171 | main.log.error( "There was an error calculating" + |
| 1172 | " the delta for link down event" ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1173 | link_down_lat_graph1 = 0 |
| 1174 | link_down_lat_graph2 = 0 |
| 1175 | link_down_lat_graph3 = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1176 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1177 | link_down_lat_device1 = 0 |
| 1178 | link_down_lat_device2 = 0 |
| 1179 | link_down_lat_device3 = 0 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1180 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1181 | 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 |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1212 | if link_down_lat_graph_avg > down_threshold_min and\ |
| 1213 | link_down_lat_graph_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1214 | link_down_graph_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1215 | link_down_lat_graph_avg ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1216 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1217 | main.log.info( "Link down latency exceeded threshold" ) |
| 1218 | main.log.info( "Results for iteration " + str( i ) + |
| 1219 | "have been omitted" ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1220 | if link_down_lat_link_avg > down_threshold_min and\ |
| 1221 | link_down_lat_link_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1222 | link_down_link_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1223 | link_down_lat_link_avg ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1224 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1225 | main.log.info( "Link down latency exceeded threshold" ) |
| 1226 | main.log.info( "Results for iteration " + str( i ) + |
| 1227 | "have been omitted" ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1228 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1229 | # NOTE: To remove loss rate and measure latency: |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1230 | # 'sh tc qdisc del dev s1-eth1 root' |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1231 | timestamp_link_up_t0 = time.time() * 1000 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1232 | 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 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1238 | link_down1 = True |
| 1239 | link_down2 = True |
| 1240 | link_down3 = True |
| 1241 | loop_count = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1242 | while( ( link_down1 and link_down2 and link_down3 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1243 | and loop_count < 30 ): |
| 1244 | json_str1 = main.ONOS1cli.links() |
| 1245 | json_str2 = main.ONOS2cli.links() |
| 1246 | json_str3 = main.ONOS3cli.links() |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1247 | if not ( json_str1 and json_str2 and json_str3 ): |
| 1248 | main.log.error( "CLI command returned error " ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1249 | break |
| 1250 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1251 | json_obj1 = json.loads( json_str1 ) |
| 1252 | json_obj2 = json.loads( json_str2 ) |
| 1253 | json_obj3 = json.loads( json_str3 ) |
| 1254 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1255 | for obj1 in json_obj1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1256 | if '01' in obj1[ 'src' ][ 'device' ]: |
| 1257 | link_down1 = False |
| 1258 | main.log.info( "Link up from " + |
| 1259 | "s1 -> s2 on ONOS1 detected" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1260 | for obj2 in json_obj2: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1261 | if '01' in obj2[ 'src' ][ 'device' ]: |
| 1262 | link_down2 = False |
| 1263 | main.log.info( "Link up from " + |
| 1264 | "s1 -> s2 on ONOS2 detected" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1265 | for obj3 in json_obj3: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1266 | if '01' in obj3[ 'src' ][ 'device' ]: |
| 1267 | link_down3 = False |
| 1268 | main.log.info( "Link up from " + |
| 1269 | "s1 -> s2 on ONOS3 detected" ) |
| 1270 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1271 | loop_count += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1272 | time.sleep( 1 ) |
| 1273 | |
| 1274 | if ( link_down1 and link_down2 and link_down3 ): |
| 1275 | main.log.info( "Link up discovery failed" ) |
| 1276 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1277 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1283 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1284 | assertion = main.FALSE |
| 1285 | else: |
| 1286 | json_topo_metrics_1 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1287 | main.ONOS1cli.topology_events_metrics() |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1288 | json_topo_metrics_2 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1289 | main.ONOS2cli.topology_events_metrics() |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1290 | json_topo_metrics_3 =\ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1291 | 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 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1295 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1296 | main.log.info( "Obtaining graph and device timestamp" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1297 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1298 | json_topo_metrics_1[ graphTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1299 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1300 | json_topo_metrics_2[ graphTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1301 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1302 | json_topo_metrics_3[ graphTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1303 | |
| 1304 | link_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1305 | json_topo_metrics_1[ linkTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1306 | link_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1307 | json_topo_metrics_2[ linkTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1308 | link_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1309 | json_topo_metrics_3[ linkTimestamp ][ 'value' ] |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1310 | |
| 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1314 | 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 ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1327 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1328 | main.log.error( "There was an error calculating" + |
| 1329 | " the delta for link down event" ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1330 | link_up_lat_graph1 = 0 |
| 1331 | link_up_lat_graph2 = 0 |
| 1332 | link_up_lat_graph3 = 0 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1333 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1334 | link_up_lat_device1 = 0 |
| 1335 | link_up_lat_device2 = 0 |
| 1336 | link_up_lat_device3 = 0 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1337 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1338 | 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 |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1378 | if link_up_lat_graph_avg > up_threshold_min and\ |
| 1379 | link_up_lat_graph_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1380 | link_up_graph_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1381 | link_up_lat_graph_avg ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1382 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1383 | main.log.info( "Link up latency exceeded threshold" ) |
| 1384 | main.log.info( "Results for iteration " + str( i ) + |
| 1385 | "have been omitted" ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1386 | if link_up_lat_link_avg > up_threshold_min and\ |
| 1387 | link_up_lat_link_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1388 | link_up_link_to_system_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1389 | link_up_lat_link_avg ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1390 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1391 | main.log.info( "Link up latency exceeded threshold" ) |
| 1392 | main.log.info( "Results for iteration " + str( i ) + |
| 1393 | "have been omitted" ) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1394 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1395 | # 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 ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1404 | link_down_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1405 | str( round( numpy.std( link_down_graph_to_system_list ), 1 ) ) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1406 | link_up_std_dev = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1407 | str( round( numpy.std( link_up_graph_to_system_list ), 1 ) ) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1408 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1409 | 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" ) |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1415 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1416 | utilities.assert_equals( |
| 1417 | expect=main.TRUE, |
| 1418 | actual=assertion, |
| 1419 | onpass="Link discovery latency calculation successful", |
| 1420 | onfail="Link discovery latency case failed" ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1421 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1422 | def CASE5( self, main ): |
| 1423 | """ |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1424 | 100 Switch discovery latency |
| 1425 | |
| 1426 | Important: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1427 | This test case can be potentially dangerous if |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1428 | your machine has previously set iptables rules. |
| 1429 | One of the steps of the test case will flush |
| 1430 | all existing iptables rules. |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1431 | Note: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1432 | You can specify the number of switches in the |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1433 | params file to adjust the switch discovery size |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1434 | ( and specify the corresponding topology in Mininet1 |
| 1435 | .topo file ) |
| 1436 | """ |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1437 | import time |
| 1438 | import subprocess |
| 1439 | import os |
| 1440 | import requests |
| 1441 | import json |
| 1442 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1443 | 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' ] |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1448 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1449 | default_sw_port = main.params[ 'CTRL' ][ 'port1' ] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1450 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1451 | # Number of iterations of case |
| 1452 | num_iter = main.params[ 'TEST' ][ 'numIter' ] |
| 1453 | num_sw = main.params[ 'TEST' ][ 'numSwitch' ] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1454 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1455 | # 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( ":", "" ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1466 | if debug_mode == 'on': |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1467 | main.ONOS1.tshark_pcap( "eth0", |
| 1468 | "/tmp/100_sw_lat_pcap_" + local_time ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1469 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1470 | # 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" |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1478 | |
| 1479 | tshark_ofp_result_list = [] |
| 1480 | tshark_tcp_result_list = [] |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1481 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1482 | sw_discovery_lat_list = [] |
| 1483 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1484 | 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 ): |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1487 | main.Mininet1.assign_sw_controller( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1488 | sw=str( i ), |
| 1489 | ip1=ONOS1_ip, |
| 1490 | port1=default_sw_port ) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1491 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1492 | # 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: |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1503 | # Append to INPUT rule, |
| 1504 | # behavior DROP that matches following: |
| 1505 | # * packet type: tcp |
| 1506 | # * source IP: MN1_ip |
| 1507 | # * destination PORT: 6633 |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1508 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1509 | "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, |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1513 | # behavior DROP that matches following: |
| 1514 | # * packet type: tcp |
| 1515 | # * source IP: MN1_ip |
| 1516 | # * destination PORT: 6633 |
| 1517 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1518 | "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 |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1523 | # based on the number of switches in the topology |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1524 | main.log.info( "Please wait for switch connection to " + |
| 1525 | "time out" ) |
| 1526 | time.sleep( 60 ) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1527 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1528 | # 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 |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1536 | # removal took place |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1537 | # ( ensuring nodes are configured via ptp ) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1538 | # sudo iptables -F |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1539 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1540 | t0_system = time.time() * 1000 |
| 1541 | main.ONOS1.handle.sendline( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1542 | "sudo iptables -F" ) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1543 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1544 | # Counter to track loop count |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1545 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1553 | # 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. |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1557 | device_str_obj1 = main.ONOS1cli.devices() |
| 1558 | device_str_obj2 = main.ONOS2cli.devices() |
| 1559 | device_str_obj3 = main.ONOS3cli.devices() |
| 1560 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1561 | device_json1 = json.loads( device_str_obj1 ) |
| 1562 | device_json2 = json.loads( device_str_obj2 ) |
| 1563 | device_json3 = json.loads( device_str_obj3 ) |
| 1564 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1565 | for device1 in device_json1: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1566 | if device1[ 'available' ]: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1567 | counter_avail1 += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1568 | if counter_avail1 == int( num_sw ): |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1569 | onos1_dev = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1570 | main.log.info( "All devices have been " + |
| 1571 | "discovered on ONOS1" ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1572 | else: |
| 1573 | counter_avail1 = 0 |
| 1574 | for device2 in device_json2: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1575 | if device2[ 'available' ]: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1576 | counter_avail2 += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1577 | if counter_avail2 == int( num_sw ): |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1578 | onos2_dev = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1579 | main.log.info( "All devices have been " + |
| 1580 | "discovered on ONOS2" ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1581 | else: |
| 1582 | counter_avail2 = 0 |
| 1583 | for device3 in device_json3: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1584 | if device3[ 'available' ]: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1585 | counter_avail3 += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1586 | if counter_avail3 == int( num_sw ): |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1587 | onos3_dev = True |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1588 | main.log.info( "All devices have been " + |
| 1589 | "discovered on ONOS3" ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1590 | else: |
| 1591 | counter_avail3 = 0 |
| 1592 | |
| 1593 | if onos1_dev and onos2_dev and onos3_dev: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1594 | main.log.info( "All devices have been discovered " + |
| 1595 | "on all ONOS instances" ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1596 | 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-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1602 | |
| 1603 | # Exit while loop if all devices discovered |
| 1604 | break |
| 1605 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1606 | counter_loop += 1 |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1607 | # Give some time in between CLI calls |
| 1608 | #( will not affect measurement ) |
| 1609 | time.sleep( 3 ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1610 | |
| 1611 | main.ONOS1.tshark_stop() |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1612 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1613 | 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: " ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1623 | for line in ofp_file: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1624 | tshark_ofp_result_list.append( line ) |
| 1625 | main.log.info( line ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1626 | ofp_file.close() |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1627 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1628 | tcp_file = open( tshark_tcp_output, 'r' ) |
| 1629 | main.log.info( "Tshark TCP 74 output: " ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1630 | for line in tcp_file: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1631 | tshark_tcp_result_list.append( line ) |
| 1632 | main.log.info( line ) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1633 | tcp_file.close() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1634 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1635 | 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 ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1638 | |
| 1639 | graph_timestamp_1 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1640 | json_obj_1[ graphTimestamp ][ 'value' ] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1641 | graph_timestamp_2 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1642 | json_obj_2[ graphTimestamp ][ 'value' ] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1643 | graph_timestamp_3 = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1644 | json_obj_3[ graphTimestamp ][ 'value' ] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1645 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1646 | 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 ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1649 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1650 | avg_graph_lat = \ |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1651 | ( int( graph_lat_1 ) + |
| 1652 | int( graph_lat_2 ) + |
| 1653 | int( graph_lat_3 ) ) / 3 |
| 1654 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1655 | if avg_graph_lat > sw_disc_threshold_min \ |
| 1656 | and avg_graph_lat < sw_disc_threshold_max: |
| 1657 | sw_discovery_lat_list.append( |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1658 | avg_graph_lat ) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1659 | else: |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1660 | main.log.info( "100 Switch discovery latency " + |
| 1661 | "exceeded the threshold." ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1662 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1663 | # END ITERATION FOR LOOP |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1664 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1665 | 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 ) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1669 | |
kelvin-onlab | 8a83258 | 2015-01-16 17:06:11 -0800 | [diff] [blame] | 1670 | 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" ) |