andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 1 | #TopoPerfNext |
| 2 | # |
| 3 | #Topology Performance test for ONOS-next |
| 4 | # |
| 5 | #andrew@onlab.us |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 6 | # |
| 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 | |
| 16 | class TopoPerfNext: |
| 17 | def __init__(self): |
| 18 | self.default = '' |
| 19 | |
| 20 | def CASE1(self, main): |
| 21 | ''' |
| 22 | ONOS startup sequence |
| 23 | ''' |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 24 | import time |
| 25 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 26 | cell_name = main.params['ENV']['cellName'] |
| 27 | |
| 28 | git_pull = main.params['GIT']['autoPull'] |
| 29 | checkout_branch = main.params['GIT']['checkout'] |
| 30 | |
| 31 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 32 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 33 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 6c8bbeb | 2014-11-14 12:43:48 -0500 | [diff] [blame] | 34 | |
| 35 | #### Hardcoded ONOS nodes particular to my env #### |
| 36 | ONOS4_ip = "10.128.174.4" |
| 37 | ONOS5_ip = "10.128.174.5" |
| 38 | ONOS6_ip = "10.128.174.6" |
| 39 | ONOS7_ip = "10.128.174.7" |
| 40 | #### #### |
| 41 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 42 | MN1_ip = main.params['MN']['ip1'] |
| 43 | BENCH_ip = main.params['BENCH']['ip'] |
| 44 | |
andrewonlab | 0e1825c | 2014-11-20 20:07:00 -0500 | [diff] [blame] | 45 | topo_cfg_file = main.params['TEST']['topo_config_file'] |
| 46 | topo_cfg_name = main.params['TEST']['topo_config_name'] |
| 47 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 48 | main.case("Setting up test environment") |
andrewonlab | 0e1825c | 2014-11-20 20:07:00 -0500 | [diff] [blame] | 49 | main.step("Copying topology event accumulator config file to "+ |
| 50 | "ONOS /package/etc") |
| 51 | main.ONOSbench.handle.sendline("cp ~/"+ |
| 52 | topo_cfg_file+ |
| 53 | "~/ONOS/tools/package/etc/"+ |
| 54 | topo_cfg_name) |
| 55 | main.ONOSbench.handle.expect("\$") |
| 56 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 57 | main.log.report("Setting up test environment") |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 58 | |
andrewonlab | 6c8bbeb | 2014-11-14 12:43:48 -0500 | [diff] [blame] | 59 | main.step("Cleaning previously installed ONOS if any") |
| 60 | main.ONOSbench.onos_uninstall(node_ip=ONOS4_ip) |
| 61 | main.ONOSbench.onos_uninstall(node_ip=ONOS5_ip) |
| 62 | main.ONOSbench.onos_uninstall(node_ip=ONOS6_ip) |
| 63 | main.ONOSbench.onos_uninstall(node_ip=ONOS7_ip) |
| 64 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 65 | main.step("Creating cell file") |
| 66 | cell_file_result = main.ONOSbench.create_cell_file( |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 67 | BENCH_ip, cell_name, MN1_ip, "onos-core", |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 68 | ONOS1_ip, ONOS2_ip, ONOS3_ip) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 69 | |
| 70 | main.step("Applying cell file to environment") |
| 71 | cell_apply_result = main.ONOSbench.set_cell(cell_name) |
| 72 | verify_cell_result = main.ONOSbench.verify_cell() |
| 73 | |
andrewonlab | 6e78adf | 2014-11-14 12:57:29 -0500 | [diff] [blame] | 74 | #NOTE: This step may be removed after proper |
| 75 | # copy cat log functionality |
| 76 | main.step("Removing raft/copy-cat logs from ONOS nodes") |
| 77 | main.ONOSbench.onos_remove_raft_logs() |
| 78 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 79 | main.step("Git checkout and pull "+checkout_branch) |
| 80 | if git_pull == 'on': |
| 81 | checkout_result = \ |
| 82 | main.ONOSbench.git_checkout(checkout_branch) |
| 83 | pull_result = main.ONOSbench.git_pull() |
| 84 | else: |
| 85 | checkout_result = main.TRUE |
| 86 | pull_result = main.TRUE |
| 87 | main.log.info("Skipped git checkout and pull") |
| 88 | |
andrewonlab | 9284434 | 2014-11-18 16:39:11 -0500 | [diff] [blame] | 89 | #TODO: Uncomment when wiki posting works |
| 90 | #main.log.report("Commit information - ") |
| 91 | #main.ONOSbench.get_version(report=True) |
| 92 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 93 | main.step("Using mvn clean & install") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 94 | #mvn_result = main.ONOSbench.clean_install() |
| 95 | mvn_result = main.TRUE |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 96 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 97 | main.step("Set cell for ONOS cli env") |
| 98 | main.ONOS1cli.set_cell(cell_name) |
| 99 | main.ONOS2cli.set_cell(cell_name) |
| 100 | main.ONOS3cli.set_cell(cell_name) |
| 101 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 102 | main.step("Creating ONOS package") |
| 103 | package_result = main.ONOSbench.onos_package() |
| 104 | |
| 105 | main.step("Installing ONOS package") |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 106 | install1_result = main.ONOSbench.onos_install(node=ONOS1_ip) |
| 107 | install2_result = main.ONOSbench.onos_install(node=ONOS2_ip) |
| 108 | install3_result = main.ONOSbench.onos_install(node=ONOS3_ip) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 109 | |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 110 | time.sleep(10) |
| 111 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 112 | main.step("Start onos cli") |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 113 | cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip) |
| 114 | cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip) |
| 115 | cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip) |
| 116 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 117 | main.step("Enable metrics feature") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 118 | main.ONOS1cli.feature_install("onos-app-metrics") |
| 119 | main.ONOS2cli.feature_install("onos-app-metrics") |
| 120 | main.ONOS3cli.feature_install("onos-app-metrics") |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 121 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 122 | utilities.assert_equals(expect=main.TRUE, |
| 123 | actual= cell_file_result and cell_apply_result and\ |
| 124 | verify_cell_result and checkout_result and\ |
| 125 | pull_result and mvn_result and\ |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 126 | install1_result and install2_result and\ |
| 127 | install3_result, |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 128 | onpass="Test Environment setup successful", |
| 129 | onfail="Failed to setup test environment") |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 130 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 131 | def CASE2(self, main): |
| 132 | ''' |
| 133 | Assign s1 to ONOS1 and measure latency |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 134 | |
| 135 | There are 4 levels of latency measurements to this test: |
| 136 | 1) End-to-end measurement: Complete end-to-end measurement |
| 137 | from TCP (SYN/ACK) handshake to Graph change |
| 138 | 2) OFP-to-graph measurement: 'ONOS processing' snippet of |
| 139 | measurement from OFP Vendor message to Graph change |
| 140 | 3) OFP-to-device measurement: 'ONOS processing without |
| 141 | graph change' snippet of measurement from OFP vendor |
| 142 | message to Device change timestamp |
| 143 | 4) T0-to-device measurement: Measurement that includes |
| 144 | the switch handshake to devices timestamp without |
| 145 | the graph view change. (TCP handshake -> Device |
| 146 | change) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 147 | ''' |
| 148 | import time |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 149 | import subprocess |
| 150 | import json |
| 151 | import requests |
| 152 | import os |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 153 | import numpy |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 154 | |
| 155 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 156 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 157 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 158 | ONOS_user = main.params['CTRL']['user'] |
| 159 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 160 | default_sw_port = main.params['CTRL']['port1'] |
| 161 | |
| 162 | #Number of iterations of case |
| 163 | num_iter = main.params['TEST']['numIter'] |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 164 | #Number of first 'x' iterations to ignore: |
| 165 | iter_ignore = int(main.params['TEST']['iterIgnore']) |
| 166 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 167 | #Timestamp 'keys' for json metrics output. |
| 168 | #These are subject to change, hence moved into params |
| 169 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 170 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 171 | |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 172 | debug_mode = main.params['TEST']['debugMode'] |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 173 | onos_log = main.params['TEST']['onosLogFile'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 174 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 175 | #Threshold for the test |
| 176 | threshold_str = main.params['TEST']['singleSwThreshold'] |
| 177 | threshold_obj = threshold_str.split(",") |
| 178 | threshold_min = int(threshold_obj[0]) |
| 179 | threshold_max = int(threshold_obj[1]) |
| 180 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 181 | #List of switch add latency collected from |
| 182 | #all iterations |
| 183 | latency_end_to_end_list = [] |
| 184 | latency_ofp_to_graph_list = [] |
| 185 | latency_ofp_to_device_list = [] |
| 186 | latency_t0_to_device_list = [] |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 187 | latency_tcp_to_ofp_list = [] |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 188 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 189 | #Directory/file to store tshark results |
| 190 | tshark_of_output = "/tmp/tshark_of_topo.txt" |
| 191 | tshark_tcp_output = "/tmp/tshark_tcp_topo.txt" |
| 192 | |
| 193 | #String to grep in tshark output |
| 194 | tshark_tcp_string = "TCP 74 "+default_sw_port |
| 195 | tshark_of_string = "OFP 86 Vendor" |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 196 | |
| 197 | #Initialize assertion to TRUE |
| 198 | assertion = main.TRUE |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 199 | |
| 200 | local_time = time.strftime('%x %X') |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 201 | local_time = local_time.replace("/","") |
| 202 | local_time = local_time.replace(" ","_") |
| 203 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 204 | if debug_mode == 'on': |
| 205 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 206 | "/tmp/single_sw_lat_pcap_"+local_time) |
| 207 | |
| 208 | main.log.info("TEST") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 209 | |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 210 | main.log.report("Latency of adding one switch to controller") |
| 211 | main.log.report("First "+str(iter_ignore)+" iterations ignored"+ |
| 212 | " for jvm warmup time") |
| 213 | main.log.report("Total iterations of test: "+str(num_iter)) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 214 | |
| 215 | for i in range(0, int(num_iter)): |
| 216 | main.log.info("Starting tshark capture") |
| 217 | |
| 218 | #* TCP [ACK, SYN] is used as t0_a, the |
| 219 | # very first "exchange" between ONOS and |
| 220 | # the switch for end-to-end measurement |
| 221 | #* OFP [Stats Reply] is used for t0_b |
| 222 | # the very last OFP message between ONOS |
| 223 | # and the switch for ONOS measurement |
| 224 | main.ONOS1.tshark_grep(tshark_tcp_string, |
| 225 | tshark_tcp_output) |
| 226 | main.ONOS1.tshark_grep(tshark_of_string, |
| 227 | tshark_of_output) |
| 228 | |
| 229 | #Wait and ensure tshark is started and |
| 230 | #capturing |
| 231 | time.sleep(10) |
| 232 | |
| 233 | main.log.info("Assigning s1 to controller") |
| 234 | |
| 235 | main.Mininet1.assign_sw_controller(sw="1", |
| 236 | ip1=ONOS1_ip, port1=default_sw_port) |
| 237 | |
| 238 | #Wait and ensure switch is assigned |
| 239 | #before stopping tshark |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 240 | time.sleep(30) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 241 | |
| 242 | main.log.info("Stopping all Tshark processes") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 243 | main.ONOS1.stop_tshark() |
| 244 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 245 | #tshark output is saved in ONOS. Use subprocess |
| 246 | #to copy over files to TestON for parsing |
| 247 | main.log.info("Copying over tshark files") |
| 248 | |
| 249 | #TCP CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 250 | #Copy the tshark output from ONOS machine to |
| 251 | #TestON machine in tshark_tcp_output directory>file |
| 252 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 253 | tshark_tcp_output+" /tmp/") |
| 254 | tcp_file = open(tshark_tcp_output, 'r') |
| 255 | temp_text = tcp_file.readline() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 256 | temp_text = temp_text.split(" ") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 257 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 258 | main.log.info("Object read in from TCP capture: "+ |
| 259 | str(temp_text)) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 260 | if len(temp_text) > 1: |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 261 | t0_tcp = float(temp_text[1])*1000.0 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 262 | else: |
| 263 | main.log.error("Tshark output file for TCP"+ |
| 264 | " returned unexpected results") |
| 265 | t0_tcp = 0 |
| 266 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 267 | |
| 268 | tcp_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 269 | #**************** |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 270 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 271 | #OF CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 272 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 273 | tshark_of_output+" /tmp/") |
| 274 | of_file = open(tshark_of_output, 'r') |
| 275 | |
| 276 | line_ofp = "" |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 277 | #Read until last line of file |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 278 | while True: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 279 | temp_text = of_file.readline() |
| 280 | if temp_text !='': |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 281 | line_ofp = temp_text |
| 282 | else: |
| 283 | break |
| 284 | obj = line_ofp.split(" ") |
| 285 | |
| 286 | main.log.info("Object read in from OFP capture: "+ |
| 287 | str(line_ofp)) |
| 288 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 289 | if len(line_ofp) > 1: |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 290 | t0_ofp = float(obj[1])*1000.0 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 291 | else: |
| 292 | main.log.error("Tshark output file for OFP"+ |
| 293 | " returned unexpected results") |
| 294 | t0_ofp = 0 |
| 295 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 296 | |
| 297 | of_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 298 | #**************** |
| 299 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 300 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 301 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 302 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 303 | |
| 304 | json_obj_1 = json.loads(json_str_1) |
| 305 | json_obj_2 = json.loads(json_str_2) |
| 306 | json_obj_3 = json.loads(json_str_3) |
| 307 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 308 | #Obtain graph timestamp. This timestsamp captures |
| 309 | #the epoch time at which the topology graph was updated. |
| 310 | graph_timestamp_1 = \ |
| 311 | json_obj_1[graphTimestamp]['value'] |
| 312 | graph_timestamp_2 = \ |
| 313 | json_obj_2[graphTimestamp]['value'] |
| 314 | graph_timestamp_3 = \ |
| 315 | json_obj_3[graphTimestamp]['value'] |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 316 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 317 | #Obtain device timestamp. This timestamp captures |
| 318 | #the epoch time at which the device event happened |
| 319 | device_timestamp_1 = \ |
| 320 | json_obj_1[deviceTimestamp]['value'] |
| 321 | device_timestamp_2 = \ |
| 322 | json_obj_2[deviceTimestamp]['value'] |
| 323 | device_timestamp_3 = \ |
| 324 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 325 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 326 | #t0 to device processing latency |
| 327 | delta_device_1 = int(device_timestamp_1) - int(t0_tcp) |
| 328 | delta_device_2 = int(device_timestamp_2) - int(t0_tcp) |
| 329 | delta_device_3 = int(device_timestamp_3) - int(t0_tcp) |
| 330 | |
| 331 | #Get average of delta from all instances |
| 332 | avg_delta_device = \ |
| 333 | (int(delta_device_1)+\ |
| 334 | int(delta_device_2)+\ |
| 335 | int(delta_device_3)) / 3 |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 336 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 337 | #Ensure avg delta meets the threshold before appending |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 338 | if avg_delta_device > 0.0 and avg_delta_device < 10000\ |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 339 | and int(i) > iter_ignore: |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 340 | latency_t0_to_device_list.append(avg_delta_device) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 341 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 342 | main.log.info("Results for t0-to-device ignored"+\ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 343 | "due to excess in threshold / warmup iteration.") |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 344 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 345 | #t0 to graph processing latency (end-to-end) |
| 346 | delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp) |
| 347 | delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp) |
| 348 | delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp) |
| 349 | |
| 350 | #Get average of delta from all instances |
| 351 | avg_delta_graph = \ |
| 352 | (int(delta_graph_1)+\ |
| 353 | int(delta_graph_2)+\ |
| 354 | int(delta_graph_3)) / 3 |
| 355 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 356 | #Ensure avg delta meets the threshold before appending |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 357 | if avg_delta_graph > 0.0 and avg_delta_graph < 10000\ |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 358 | and int(i) > iter_ignore: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 359 | latency_end_to_end_list.append(avg_delta_graph) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 360 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 361 | main.log.info("Results for end-to-end ignored"+\ |
| 362 | "due to excess in threshold") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 363 | |
| 364 | #ofp to graph processing latency (ONOS processing) |
| 365 | delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp) |
| 366 | delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp) |
| 367 | delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp) |
| 368 | |
| 369 | avg_delta_ofp_graph = \ |
| 370 | (int(delta_ofp_graph_1)+\ |
| 371 | int(delta_ofp_graph_2)+\ |
| 372 | int(delta_ofp_graph_3)) / 3 |
| 373 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 374 | if avg_delta_ofp_graph > threshold_min \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 375 | and avg_delta_ofp_graph < threshold_max\ |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 376 | and int(i) > iter_ignore: |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 377 | latency_ofp_to_graph_list.append(avg_delta_ofp_graph) |
andrewonlab | 9284434 | 2014-11-18 16:39:11 -0500 | [diff] [blame] | 378 | elif avg_delta_ofp_graph > (-10) and \ |
| 379 | avg_delta_ofp_graph < 0.0 and\ |
| 380 | int(i) > iter_ignore: |
| 381 | main.log.info("Sub-millisecond result likely; "+ |
| 382 | "negative result was rounded to 0") |
| 383 | #NOTE: Current metrics framework does not |
| 384 | #support sub-millisecond accuracy. Therefore, |
| 385 | #if the result is negative, we can reasonably |
| 386 | #conclude sub-millisecond results and just |
| 387 | #append the best rounded effort - 0 ms. |
| 388 | latency_ofp_to_graph_list.append(0) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 389 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 390 | main.log.info("Results for ofp-to-graph "+\ |
| 391 | "ignored due to excess in threshold") |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 392 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 393 | #ofp to device processing latency (ONOS processing) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 394 | delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp) |
| 395 | delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp) |
| 396 | delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 397 | |
| 398 | avg_delta_ofp_device = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 399 | (float(delta_ofp_device_1)+\ |
| 400 | float(delta_ofp_device_2)+\ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 401 | float(delta_ofp_device_3)) / 3 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 402 | |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 403 | #NOTE: ofp - delta measurements are occasionally negative |
| 404 | # due to system time misalignment. |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 405 | latency_ofp_to_device_list.append(avg_delta_ofp_device) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 406 | |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 407 | delta_ofp_tcp = int(t0_ofp) - int(t0_tcp) |
| 408 | if delta_ofp_tcp > threshold_min \ |
| 409 | and delta_ofp_tcp < threshold_max and\ |
| 410 | int(i) > iter_ignore: |
| 411 | latency_tcp_to_ofp_list.append(delta_ofp_tcp) |
| 412 | else: |
| 413 | main.log.info("Results fo tcp-to-ofp "+\ |
| 414 | "ignored due to excess in threshold") |
| 415 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 416 | #TODO: |
| 417 | #Fetch logs upon threshold excess |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 418 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 419 | main.log.info("ONOS1 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 420 | str(delta_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 421 | main.log.info("ONOS2 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 422 | str(delta_graph_2) + " ms") |
| 423 | main.log.info("ONOS3 delta end-to-end: "+ |
| 424 | str(delta_graph_3) + " ms") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 425 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 426 | main.log.info("ONOS1 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 427 | str(delta_ofp_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 428 | main.log.info("ONOS2 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 429 | str(delta_ofp_graph_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 430 | main.log.info("ONOS3 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 431 | str(delta_ofp_graph_3) + " ms") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 432 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 433 | main.log.info("ONOS1 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 434 | str(delta_device_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 435 | main.log.info("ONOS2 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 436 | str(delta_device_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 437 | main.log.info("ONOS3 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 438 | str(delta_device_3) + " ms") |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 439 | |
| 440 | main.log.info("TCP to OFP delta: "+ |
| 441 | str(delta_ofp_tcp) + " ms") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 442 | #main.log.info("ONOS1 delta OFP - device: "+ |
| 443 | # str(delta_ofp_device_1) + " ms") |
| 444 | #main.log.info("ONOS2 delta OFP - device: "+ |
| 445 | # str(delta_ofp_device_2) + " ms") |
| 446 | #main.log.info("ONOS3 delta OFP - device: "+ |
| 447 | # str(delta_ofp_device_3) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 448 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 449 | main.step("Remove switch from controller") |
| 450 | main.Mininet1.delete_sw_controller("s1") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 451 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 452 | time.sleep(5) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 453 | |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 454 | #END of for loop iteration |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 455 | |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 456 | #If there is at least 1 element in each list, |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 457 | #pass the test case |
| 458 | if len(latency_end_to_end_list) > 0 and\ |
| 459 | len(latency_ofp_to_graph_list) > 0 and\ |
| 460 | len(latency_ofp_to_device_list) > 0 and\ |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 461 | len(latency_t0_to_device_list) > 0 and\ |
| 462 | len(latency_tcp_to_ofp_list) > 0: |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 463 | assertion = main.TRUE |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 464 | elif len(latency_end_to_end_list) == 0: |
| 465 | #The appending of 0 here is to prevent |
| 466 | #the min,max,sum functions from failing |
| 467 | #below |
| 468 | latency_end_to_end_list.append(0) |
| 469 | assertion = main.FALSE |
| 470 | elif len(latency_ofp_to_graph_list) == 0: |
| 471 | latency_ofp_to_graph_list.append(0) |
| 472 | assertion = main.FALSE |
| 473 | elif len(latency_ofp_to_device_list) == 0: |
| 474 | latency_ofp_to_device_list.append(0) |
| 475 | assertion = main.FALSE |
| 476 | elif len(latency_t0_to_device_list) == 0: |
| 477 | latency_t0_to_device_list.append(0) |
| 478 | assertion = main.FALSE |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 479 | elif len(latency_tcp_to_ofp_list) == 0: |
| 480 | latency_tcp_to_ofp_list.append(0) |
| 481 | assertion = main.FALSE |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 482 | |
| 483 | #Calculate min, max, avg of latency lists |
| 484 | latency_end_to_end_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 485 | int(max(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 486 | latency_end_to_end_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 487 | int(min(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 488 | latency_end_to_end_avg = \ |
andrewonlab | c90667c | 2014-10-24 16:48:28 -0400 | [diff] [blame] | 489 | (int(sum(latency_end_to_end_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 490 | len(latency_end_to_end_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 491 | latency_end_to_end_std_dev = \ |
| 492 | str(round(numpy.std(latency_end_to_end_list),1)) |
| 493 | |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 494 | latency_ofp_to_graph_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 495 | int(max(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 496 | latency_ofp_to_graph_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 497 | int(min(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 498 | latency_ofp_to_graph_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 499 | (int(sum(latency_ofp_to_graph_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 500 | len(latency_ofp_to_graph_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 501 | latency_ofp_to_graph_std_dev = \ |
| 502 | str(round(numpy.std(latency_ofp_to_graph_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 503 | |
| 504 | latency_ofp_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 505 | int(max(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 506 | latency_ofp_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 507 | int(min(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 508 | latency_ofp_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 509 | (int(sum(latency_ofp_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 510 | len(latency_ofp_to_device_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 511 | latency_ofp_to_device_std_dev = \ |
| 512 | str(round(numpy.std(latency_ofp_to_device_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 513 | |
| 514 | latency_t0_to_device_max = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 515 | int(max(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 516 | latency_t0_to_device_min = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 517 | int(min(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 518 | latency_t0_to_device_avg = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 519 | (int(sum(latency_t0_to_device_list)) / \ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 520 | len(latency_t0_to_device_list)) |
| 521 | latency_ofp_to_device_std_dev = \ |
| 522 | str(round(numpy.std(latency_t0_to_device_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 523 | |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 524 | latency_tcp_to_ofp_max = \ |
| 525 | int(max(latency_tcp_to_ofp_list)) |
| 526 | latency_tcp_to_ofp_min = \ |
| 527 | int(min(latency_tcp_to_ofp_list)) |
| 528 | latency_tcp_to_ofp_avg = \ |
| 529 | (int(sum(latency_tcp_to_ofp_list)) / \ |
| 530 | len(latency_tcp_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 531 | latency_tcp_to_ofp_std_dev = \ |
| 532 | str(round(numpy.std(latency_tcp_to_ofp_list),1)) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 533 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 534 | main.log.report("Switch add - End-to-end latency: "+\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 535 | "Avg: "+str(latency_end_to_end_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 536 | "Std Deviation: "+latency_end_to_end_std_dev+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 537 | main.log.report("Switch add - OFP-to-Graph latency: "+\ |
andrewonlab | 9284434 | 2014-11-18 16:39:11 -0500 | [diff] [blame] | 538 | "Note: results are not accurate to sub-millisecond. "+ |
| 539 | "Any sub-millisecond results are rounded to 0 ms. ") |
| 540 | main.log.report("Avg: "+str(latency_ofp_to_graph_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 541 | "Std Deviation: "+latency_ofp_to_graph_std_dev+" ms") |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 542 | main.log.report("Switch add - TCP-to-OFP latency: "+\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 543 | "Avg: "+str(latency_tcp_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 544 | "Std Deviation: "+latency_tcp_to_ofp_std_dev+" ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 545 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 546 | if debug_mode == 'on': |
| 547 | main.ONOS1.cp_logs_to_dir("/opt/onos/log/karaf.log", |
| 548 | "/tmp/", copy_file_name="sw_lat_karaf") |
| 549 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 550 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 551 | onpass="Switch latency test successful", |
| 552 | onfail="Switch latency test failed") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 553 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 554 | def CASE3(self, main): |
| 555 | ''' |
| 556 | Bring port up / down and measure latency. |
| 557 | Port enable / disable is simulated by ifconfig up / down |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 558 | |
| 559 | In ONOS-next, we must ensure that the port we are |
| 560 | manipulating is connected to another switch with a valid |
| 561 | connection. Otherwise, graph view will not be updated. |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 562 | ''' |
| 563 | import time |
| 564 | import subprocess |
| 565 | import os |
| 566 | import requests |
| 567 | import json |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 568 | import numpy |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 569 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 570 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 571 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 572 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 573 | ONOS_user = main.params['CTRL']['user'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 574 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 575 | default_sw_port = main.params['CTRL']['port1'] |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 576 | |
| 577 | assertion = main.TRUE |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 578 | #Number of iterations of case |
| 579 | num_iter = main.params['TEST']['numIter'] |
| 580 | |
| 581 | #Timestamp 'keys' for json metrics output. |
| 582 | #These are subject to change, hence moved into params |
| 583 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 584 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 585 | |
| 586 | debug_mode = main.params['TEST']['debugMode'] |
| 587 | |
| 588 | local_time = time.strftime('%x %X') |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 589 | local_time = local_time.replace("/","") |
| 590 | local_time = local_time.replace(" ","_") |
| 591 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 592 | if debug_mode == 'on': |
| 593 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 594 | "/tmp/port_lat_pcap_"+local_time) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 595 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 596 | #Threshold for this test case |
| 597 | up_threshold_str = main.params['TEST']['portUpThreshold'] |
| 598 | down_threshold_str = main.params['TEST']['portDownThreshold'] |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 599 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 600 | up_threshold_obj = up_threshold_str.split(",") |
| 601 | down_threshold_obj = down_threshold_str.split(",") |
| 602 | |
| 603 | up_threshold_min = int(up_threshold_obj[0]) |
| 604 | up_threshold_max = int(up_threshold_obj[1]) |
| 605 | |
| 606 | down_threshold_min = int(down_threshold_obj[0]) |
| 607 | down_threshold_max = int(down_threshold_obj[1]) |
| 608 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 609 | #NOTE: Some hardcoded variables you may need to configure |
| 610 | # besides the params |
| 611 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 612 | tshark_port_status = "OFP 130 Port Status" |
| 613 | |
| 614 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 615 | tshark_port_down = "/tmp/tshark_port_down.txt" |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 616 | interface_config = "s1-eth1" |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 617 | |
| 618 | main.log.report("Port enable / disable latency") |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 619 | main.log.report("Simulated by ifconfig up / down") |
| 620 | main.log.report("Total iterations of test: "+str(num_iter)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 621 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 622 | main.step("Assign switches s1 and s2 to controller 1") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 623 | main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip, |
| 624 | port1=default_sw_port) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 625 | main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip, |
| 626 | port1=default_sw_port) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 627 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 628 | #Give enough time for metrics to propagate the |
| 629 | #assign controller event. Otherwise, these events may |
| 630 | #carry over to our measurements |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 631 | time.sleep(15) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 632 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 633 | port_up_device_to_ofp_list = [] |
| 634 | port_up_graph_to_ofp_list = [] |
| 635 | port_down_device_to_ofp_list = [] |
| 636 | port_down_graph_to_ofp_list = [] |
| 637 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 638 | for i in range(0, int(num_iter)): |
| 639 | main.step("Starting wireshark capture for port status down") |
| 640 | main.ONOS1.tshark_grep(tshark_port_status, |
| 641 | tshark_port_down) |
| 642 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 643 | time.sleep(5) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 644 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 645 | #Disable interface that is connected to switch 2 |
| 646 | main.step("Disable port: "+interface_config) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 647 | main.Mininet1.handle.sendline("sh ifconfig "+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 648 | interface_config+" down") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 649 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 650 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 651 | time.sleep(3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 652 | main.ONOS1.tshark_stop() |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 653 | |
| 654 | main.step("Obtain t1 by metrics call") |
| 655 | json_str_up_1 = main.ONOS1cli.topology_events_metrics() |
| 656 | json_str_up_2 = main.ONOS2cli.topology_events_metrics() |
| 657 | json_str_up_3 = main.ONOS3cli.topology_events_metrics() |
| 658 | |
| 659 | json_obj_1 = json.loads(json_str_up_1) |
| 660 | json_obj_2 = json.loads(json_str_up_2) |
| 661 | json_obj_3 = json.loads(json_str_up_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 662 | |
| 663 | #Copy tshark output file from ONOS to TestON instance |
| 664 | #/tmp directory |
| 665 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 666 | tshark_port_down+" /tmp/") |
| 667 | |
| 668 | f_port_down = open(tshark_port_down, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 669 | #Get first line of port down event from tshark |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 670 | f_line = f_port_down.readline() |
| 671 | obj_down = f_line.split(" ") |
| 672 | if len(f_line) > 0: |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 673 | timestamp_begin_pt_down = int(float(obj_down[1])*1000) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 674 | main.log.info("Port down begin timestamp: "+ |
| 675 | str(timestamp_begin_pt_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 676 | else: |
| 677 | main.log.info("Tshark output file returned unexpected"+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 678 | " results: "+str(obj_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 679 | timestamp_begin_pt_down = 0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 680 | |
| 681 | f_port_down.close() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 682 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 683 | main.log.info("TEST tshark obj: "+str(obj_down)) |
| 684 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 685 | time.sleep(3) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 686 | |
| 687 | #Obtain graph timestamp. This timestsamp captures |
| 688 | #the epoch time at which the topology graph was updated. |
| 689 | graph_timestamp_1 = \ |
| 690 | json_obj_1[graphTimestamp]['value'] |
| 691 | graph_timestamp_2 = \ |
| 692 | json_obj_2[graphTimestamp]['value'] |
| 693 | graph_timestamp_3 = \ |
| 694 | json_obj_3[graphTimestamp]['value'] |
| 695 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 696 | main.log.info("TEST graph timestamp ONOS1: "+ |
| 697 | str(graph_timestamp_1)) |
| 698 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 699 | #Obtain device timestamp. This timestamp captures |
| 700 | #the epoch time at which the device event happened |
| 701 | device_timestamp_1 = \ |
| 702 | json_obj_1[deviceTimestamp]['value'] |
| 703 | device_timestamp_2 = \ |
| 704 | json_obj_2[deviceTimestamp]['value'] |
| 705 | device_timestamp_3 = \ |
| 706 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 707 | |
| 708 | #Get delta between graph event and OFP |
| 709 | pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
| 710 | int(timestamp_begin_pt_down) |
| 711 | pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
| 712 | int(timestamp_begin_pt_down) |
| 713 | pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 714 | int(timestamp_begin_pt_down) |
| 715 | |
| 716 | #Get delta between device event and OFP |
| 717 | pt_down_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 718 | int(timestamp_begin_pt_down) |
| 719 | pt_down_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 720 | int(timestamp_begin_pt_down) |
| 721 | pt_down_device_to_ofp_3 = int(device_timestamp_3) -\ |
| 722 | int(timestamp_begin_pt_down) |
| 723 | |
| 724 | #Caluclate average across clusters |
| 725 | pt_down_graph_to_ofp_avg =\ |
| 726 | (int(pt_down_graph_to_ofp_1) + |
| 727 | int(pt_down_graph_to_ofp_2) + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 728 | int(pt_down_graph_to_ofp_3)) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 729 | pt_down_device_to_ofp_avg = \ |
| 730 | (int(pt_down_device_to_ofp_1) + |
| 731 | int(pt_down_device_to_ofp_2) + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 732 | int(pt_down_device_to_ofp_3)) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 733 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 734 | if pt_down_graph_to_ofp_avg > down_threshold_min and \ |
| 735 | pt_down_graph_to_ofp_avg < down_threshold_max: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 736 | port_down_graph_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 737 | pt_down_graph_to_ofp_avg) |
| 738 | main.log.info("Port down: graph to ofp avg: "+ |
| 739 | str(pt_down_graph_to_ofp_avg) + " ms") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 740 | else: |
| 741 | main.log.info("Average port down graph-to-ofp result" + |
| 742 | " exceeded the threshold: "+ |
| 743 | str(pt_down_graph_to_ofp_avg)) |
| 744 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 745 | if pt_down_device_to_ofp_avg > 0 and \ |
| 746 | pt_down_device_to_ofp_avg < 1000: |
| 747 | port_down_device_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 748 | pt_down_device_to_ofp_avg) |
| 749 | main.log.info("Port down: device to ofp avg: "+ |
| 750 | str(pt_down_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 751 | else: |
| 752 | main.log.info("Average port down device-to-ofp result" + |
| 753 | " exceeded the threshold: "+ |
| 754 | str(pt_down_device_to_ofp_avg)) |
| 755 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 756 | #Port up events |
| 757 | main.step("Enable port and obtain timestamp") |
| 758 | main.step("Starting wireshark capture for port status up") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 759 | main.ONOS1.tshark_grep(tshark_port_status, tshark_port_up) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 760 | time.sleep(5) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 761 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 762 | main.Mininet1.handle.sendline("sh ifconfig "+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 763 | interface_config+" up") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 764 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 765 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 766 | #Allow time for tshark to capture event |
| 767 | time.sleep(3) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 768 | main.ONOS1.tshark_stop() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 769 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 770 | #Obtain metrics shortly afterwards |
| 771 | #This timestsamp captures |
| 772 | #the epoch time at which the topology graph was updated. |
| 773 | main.step("Obtain t1 by REST call") |
| 774 | json_str_up_1 = main.ONOS1cli.topology_events_metrics() |
| 775 | json_str_up_2 = main.ONOS2cli.topology_events_metrics() |
| 776 | json_str_up_3 = main.ONOS3cli.topology_events_metrics() |
| 777 | |
| 778 | json_obj_1 = json.loads(json_str_up_1) |
| 779 | json_obj_2 = json.loads(json_str_up_2) |
| 780 | json_obj_3 = json.loads(json_str_up_3) |
| 781 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 782 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 783 | tshark_port_up+" /tmp/") |
| 784 | |
| 785 | f_port_up = open(tshark_port_up, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 786 | f_line = f_port_up.readline() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 787 | obj_up = f_line.split(" ") |
| 788 | if len(f_line) > 0: |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 789 | timestamp_begin_pt_up = int(float(obj_up[1])*1000) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 790 | main.log.info("Port up begin timestamp: "+ |
| 791 | str(timestamp_begin_pt_up)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 792 | else: |
| 793 | main.log.info("Tshark output file returned unexpected"+ |
| 794 | " results.") |
| 795 | timestamp_begin_pt_up = 0 |
| 796 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 797 | f_port_up.close() |
| 798 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 799 | graph_timestamp_1 = \ |
| 800 | json_obj_1[graphTimestamp]['value'] |
| 801 | graph_timestamp_2 = \ |
| 802 | json_obj_2[graphTimestamp]['value'] |
| 803 | graph_timestamp_3 = \ |
| 804 | json_obj_3[graphTimestamp]['value'] |
| 805 | |
| 806 | #Obtain device timestamp. This timestamp captures |
| 807 | #the epoch time at which the device event happened |
| 808 | device_timestamp_1 = \ |
| 809 | json_obj_1[deviceTimestamp]['value'] |
| 810 | device_timestamp_2 = \ |
| 811 | json_obj_2[deviceTimestamp]['value'] |
| 812 | device_timestamp_3 = \ |
| 813 | json_obj_3[deviceTimestamp]['value'] |
| 814 | |
| 815 | #Get delta between graph event and OFP |
| 816 | pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 817 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 818 | pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 819 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 820 | pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 821 | int(timestamp_begin_pt_up) |
| 822 | |
| 823 | #Get delta between device event and OFP |
| 824 | pt_up_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 825 | int(timestamp_begin_pt_up) |
| 826 | pt_up_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 827 | int(timestamp_begin_pt_up) |
| 828 | pt_up_device_to_ofp_3 = int(device_timestamp_3) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 829 | int(timestamp_begin_pt_up) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 830 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 831 | main.log.info("ONOS1 delta G2O: "+str(pt_up_graph_to_ofp_1)) |
| 832 | main.log.info("ONOS2 delta G2O: "+str(pt_up_graph_to_ofp_2)) |
| 833 | main.log.info("ONOS3 delta G2O: "+str(pt_up_graph_to_ofp_3)) |
| 834 | |
| 835 | main.log.info("ONOS1 delta D2O: "+str(pt_up_device_to_ofp_1)) |
| 836 | main.log.info("ONOS2 delta D2O: "+str(pt_up_device_to_ofp_2)) |
| 837 | main.log.info("ONOS3 delta D2O: "+str(pt_up_device_to_ofp_3)) |
| 838 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 839 | pt_up_graph_to_ofp_avg = \ |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 840 | (int(pt_up_graph_to_ofp_1) + |
| 841 | int(pt_up_graph_to_ofp_2) + |
| 842 | int(pt_up_graph_to_ofp_3)) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 843 | |
| 844 | pt_up_device_to_ofp_avg = \ |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 845 | (int(pt_up_device_to_ofp_1) + |
| 846 | int(pt_up_device_to_ofp_2) + |
| 847 | int(pt_up_device_to_ofp_3)) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 848 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 849 | if pt_up_graph_to_ofp_avg > up_threshold_min and \ |
| 850 | pt_up_graph_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 851 | port_up_graph_to_ofp_list.append( |
| 852 | pt_up_graph_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 853 | main.log.info("Port down: graph to ofp avg: "+ |
| 854 | str(pt_up_graph_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 855 | else: |
| 856 | main.log.info("Average port up graph-to-ofp result"+ |
| 857 | " exceeded the threshold: "+ |
| 858 | str(pt_up_graph_to_ofp_avg)) |
| 859 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 860 | if pt_up_device_to_ofp_avg > up_threshold_min and \ |
| 861 | pt_up_device_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 862 | port_up_device_to_ofp_list.append( |
| 863 | pt_up_device_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 864 | main.log.info("Port up: device to ofp avg: "+ |
| 865 | str(pt_up_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 866 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 867 | main.log.info("Average port up device-to-ofp result"+ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 868 | " exceeded the threshold: "+ |
| 869 | str(pt_up_device_to_ofp_avg)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 870 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 871 | #END ITERATION FOR LOOP |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 872 | |
| 873 | #Check all list for latency existence and set assertion |
| 874 | if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\ |
| 875 | and port_up_graph_to_ofp_list and port_up_device_to_ofp_list): |
| 876 | assertion = main.TRUE |
| 877 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 878 | #Calculate and report latency measurements |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 879 | port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list) |
| 880 | port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list) |
| 881 | port_down_graph_to_ofp_avg = \ |
| 882 | (sum(port_down_graph_to_ofp_list) / |
| 883 | len(port_down_graph_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 884 | port_down_graph_to_ofp_std_dev = \ |
| 885 | str(round(numpy.std(port_down_graph_to_ofp_list),1)) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 886 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 887 | main.log.report("Port down graph-to-ofp "+ |
| 888 | "Avg: "+str(port_down_graph_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 889 | "Std Deviation: "+port_down_graph_to_ofp_std_dev+" ms") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 890 | |
| 891 | port_down_device_to_ofp_min = min(port_down_device_to_ofp_list) |
| 892 | port_down_device_to_ofp_max = max(port_down_device_to_ofp_list) |
| 893 | port_down_device_to_ofp_avg = \ |
| 894 | (sum(port_down_device_to_ofp_list) /\ |
| 895 | len(port_down_device_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 896 | port_down_device_to_ofp_std_dev = \ |
| 897 | str(round(numpy.std(port_down_device_to_ofp_list),1)) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 898 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 899 | main.log.report("Port down device-to-ofp "+ |
| 900 | "Avg: "+str(port_down_device_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 901 | "Std Deviation: "+port_down_device_to_ofp_std_dev+" ms") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 902 | |
| 903 | port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list) |
| 904 | port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list) |
| 905 | port_up_graph_to_ofp_avg = \ |
| 906 | (sum(port_up_graph_to_ofp_list) /\ |
| 907 | len(port_up_graph_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 908 | port_up_graph_to_ofp_std_dev = \ |
| 909 | str(round(numpy.std(port_up_graph_to_ofp_list),1)) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 910 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 911 | main.log.report("Port up graph-to-ofp "+ |
| 912 | "Avg: "+str(port_up_graph_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 913 | "Std Deviation: "+port_up_graph_to_ofp_std_dev+" ms") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 914 | |
| 915 | port_up_device_to_ofp_min = min(port_up_device_to_ofp_list) |
| 916 | port_up_device_to_ofp_max = max(port_up_device_to_ofp_list) |
| 917 | port_up_device_to_ofp_avg = \ |
| 918 | (sum(port_up_device_to_ofp_list) /\ |
| 919 | len(port_up_device_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 920 | port_up_device_to_ofp_std_dev = \ |
| 921 | str(round(numpy.std(port_up_device_to_ofp_list),1)) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 922 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 923 | main.log.report("Port up device-to-ofp "+ |
| 924 | "Avg: "+str(port_up_device_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 925 | "Std Deviation: "+port_up_device_to_ofp_std_dev+" ms") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 926 | |
| 927 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 928 | onpass="Port discovery latency calculation successful", |
| 929 | onfail="Port discovery test failed") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 930 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 931 | def CASE4(self, main): |
| 932 | ''' |
| 933 | Link down event using loss rate 100% |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 934 | |
| 935 | Important: |
| 936 | Use a simple 2 switch topology with 1 link between |
| 937 | the two switches. Ensure that mac addresses of the |
| 938 | switches are 1 / 2 respectively |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 939 | ''' |
| 940 | import time |
| 941 | import subprocess |
| 942 | import os |
| 943 | import requests |
| 944 | import json |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 945 | import numpy |
| 946 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 947 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 948 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 949 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 950 | ONOS_user = main.params['CTRL']['user'] |
| 951 | |
| 952 | default_sw_port = main.params['CTRL']['port1'] |
| 953 | |
| 954 | #Number of iterations of case |
| 955 | num_iter = main.params['TEST']['numIter'] |
| 956 | |
| 957 | #Timestamp 'keys' for json metrics output. |
| 958 | #These are subject to change, hence moved into params |
| 959 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 960 | linkTimestamp = main.params['JSON']['linkTimestamp'] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 961 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 962 | |
| 963 | debug_mode = main.params['TEST']['debugMode'] |
| 964 | |
| 965 | local_time = time.strftime('%x %X') |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 966 | local_time = local_time.replace("/","") |
| 967 | local_time = local_time.replace(" ","_") |
| 968 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 969 | if debug_mode == 'on': |
| 970 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 971 | "/tmp/link_lat_pcap_"+local_time) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 972 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 973 | #Threshold for this test case |
| 974 | up_threshold_str = main.params['TEST']['linkUpThreshold'] |
| 975 | down_threshold_str = main.params['TEST']['linkDownThreshold'] |
| 976 | |
| 977 | up_threshold_obj = up_threshold_str.split(",") |
| 978 | down_threshold_obj = down_threshold_str.split(",") |
| 979 | |
| 980 | up_threshold_min = int(up_threshold_obj[0]) |
| 981 | up_threshold_max = int(up_threshold_obj[1]) |
| 982 | |
| 983 | down_threshold_min = int(down_threshold_obj[0]) |
| 984 | down_threshold_max = int(down_threshold_obj[1]) |
| 985 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 986 | assertion = main.TRUE |
| 987 | #Link event timestamp to system time list |
| 988 | link_down_link_to_system_list = [] |
| 989 | link_up_link_to_system_list = [] |
| 990 | #Graph event timestamp to system time list |
| 991 | link_down_graph_to_system_list = [] |
| 992 | link_up_graph_to_system_list = [] |
| 993 | |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 994 | main.log.report("Link up / down discovery latency between "+ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 995 | "two switches") |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 996 | main.log.report("Simulated by setting loss-rate 100%") |
| 997 | main.log.report("'tc qdisc add dev <intfs> root netem loss 100%'") |
| 998 | main.log.report("Total iterations of test: "+str(num_iter)) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 999 | |
| 1000 | main.step("Assign all switches") |
| 1001 | main.Mininet1.assign_sw_controller(sw="1", |
| 1002 | ip1=ONOS1_ip, port1=default_sw_port) |
| 1003 | main.Mininet1.assign_sw_controller(sw="2", |
| 1004 | ip1=ONOS1_ip, port1=default_sw_port) |
| 1005 | |
| 1006 | main.step("Verifying switch assignment") |
| 1007 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
| 1008 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1009 | |
| 1010 | #Allow time for events to finish before taking measurements |
| 1011 | time.sleep(10) |
| 1012 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1013 | link_down1 = False |
| 1014 | link_down2 = False |
| 1015 | link_down3 = False |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1016 | #Start iteration of link event test |
| 1017 | for i in range(0, int(num_iter)): |
| 1018 | main.step("Getting initial system time as t0") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 1019 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 1020 | timestamp_link_down_t0 = time.time() * 1000 |
| 1021 | #Link down is simulated by 100% loss rate using traffic |
| 1022 | #control command |
| 1023 | main.Mininet1.handle.sendline( |
| 1024 | "sh tc qdisc add dev s1-eth1 root netem loss 100%") |
| 1025 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1026 | #TODO: Iterate through 'links' command to verify that |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1027 | # link s1 -> s2 went down (loop timeout 30 seconds) |
| 1028 | # on all 3 ONOS instances |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1029 | main.log.info("Checking ONOS for link update") |
| 1030 | loop_count = 0 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1031 | while( not (link_down1 and link_down2 and link_down3)\ |
| 1032 | and loop_count < 30 ): |
| 1033 | json_str1 = main.ONOS1cli.links() |
| 1034 | json_str2 = main.ONOS2cli.links() |
| 1035 | json_str3 = main.ONOS3cli.links() |
| 1036 | |
| 1037 | if not (json_str1 and json_str2 and json_str3): |
| 1038 | main.log.error("CLI command returned error ") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1039 | break |
| 1040 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1041 | json_obj1 = json.loads(json_str1) |
| 1042 | json_obj2 = json.loads(json_str2) |
| 1043 | json_obj3 = json.loads(json_str3) |
| 1044 | for obj1 in json_obj1: |
| 1045 | if '01' not in obj1['src']['device']: |
| 1046 | link_down1 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1047 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1048 | "s1 -> s2 on ONOS1 detected") |
| 1049 | for obj2 in json_obj2: |
| 1050 | if '01' not in obj2['src']['device']: |
| 1051 | link_down2 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1052 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1053 | "s1 -> s2 on ONOS2 detected") |
| 1054 | for obj3 in json_obj3: |
| 1055 | if '01' not in obj3['src']['device']: |
| 1056 | link_down3 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1057 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1058 | "s1 -> s2 on ONOS3 detected") |
| 1059 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1060 | loop_count += 1 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1061 | #If CLI doesn't like the continuous requests |
| 1062 | #and exits in this loop, increase the sleep here. |
| 1063 | #Consequently, while loop timeout will increase |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1064 | time.sleep(1) |
| 1065 | |
| 1066 | #Give time for metrics measurement to catch up |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1067 | #NOTE: May need to be configured more accurately |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1068 | time.sleep(10) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1069 | #If we exited the while loop and link down 1,2,3 are still |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1070 | #false, then ONOS has failed to discover link down event |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1071 | if not (link_down1 and link_down2 and link_down3): |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1072 | main.log.info("Link down discovery failed") |
| 1073 | |
| 1074 | link_down_lat_graph1 = 0 |
| 1075 | link_down_lat_graph2 = 0 |
| 1076 | link_down_lat_graph3 = 0 |
| 1077 | link_down_lat_device1 = 0 |
| 1078 | link_down_lat_device2 = 0 |
| 1079 | link_down_lat_device3 = 0 |
| 1080 | |
| 1081 | assertion = main.FALSE |
| 1082 | else: |
| 1083 | json_topo_metrics_1 =\ |
| 1084 | main.ONOS1cli.topology_events_metrics() |
| 1085 | json_topo_metrics_2 =\ |
| 1086 | main.ONOS2cli.topology_events_metrics() |
| 1087 | json_topo_metrics_3 =\ |
| 1088 | main.ONOS3cli.topology_events_metrics() |
| 1089 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 1090 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 1091 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 1092 | |
| 1093 | main.log.info("Obtaining graph and device timestamp") |
| 1094 | graph_timestamp_1 = \ |
| 1095 | json_topo_metrics_1[graphTimestamp]['value'] |
| 1096 | graph_timestamp_2 = \ |
| 1097 | json_topo_metrics_2[graphTimestamp]['value'] |
| 1098 | graph_timestamp_3 = \ |
| 1099 | json_topo_metrics_3[graphTimestamp]['value'] |
| 1100 | |
| 1101 | link_timestamp_1 = \ |
| 1102 | json_topo_metrics_1[linkTimestamp]['value'] |
| 1103 | link_timestamp_2 = \ |
| 1104 | json_topo_metrics_2[linkTimestamp]['value'] |
| 1105 | link_timestamp_3 = \ |
| 1106 | json_topo_metrics_3[linkTimestamp]['value'] |
| 1107 | |
| 1108 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 1109 | graph_timestamp_3 and link_timestamp_1 and\ |
| 1110 | link_timestamp_2 and link_timestamp_3: |
| 1111 | link_down_lat_graph1 = int(graph_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1112 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1113 | link_down_lat_graph2 = int(graph_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1114 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1115 | link_down_lat_graph3 = int(graph_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1116 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1117 | |
| 1118 | link_down_lat_link1 = int(link_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1119 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1120 | link_down_lat_link2 = int(link_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1121 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1122 | link_down_lat_link3 = int(link_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1123 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1124 | else: |
| 1125 | main.log.error("There was an error calculating"+ |
| 1126 | " the delta for link down event") |
| 1127 | link_down_lat_graph1 = 0 |
| 1128 | link_down_lat_graph2 = 0 |
| 1129 | link_down_lat_graph3 = 0 |
| 1130 | |
| 1131 | link_down_lat_device1 = 0 |
| 1132 | link_down_lat_device2 = 0 |
| 1133 | link_down_lat_device3 = 0 |
| 1134 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1135 | main.log.info("Link down latency ONOS1 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1136 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1137 | str(link_down_lat_graph1)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1138 | main.log.info("Link down latency ONOS2 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1139 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1140 | str(link_down_lat_graph2)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1141 | main.log.info("Link down latency ONOS3 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1142 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1143 | str(link_down_lat_graph3)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1144 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1145 | main.log.info("Link down latency ONOS1 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1146 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1147 | str(link_down_lat_link1)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1148 | main.log.info("Link down latency ONOS2 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1149 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1150 | str(link_down_lat_link2)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1151 | main.log.info("Link down latency ONOS3 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1152 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1153 | str(link_down_lat_link3)) |
| 1154 | |
| 1155 | #Calculate avg of node calculations |
| 1156 | link_down_lat_graph_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1157 | (link_down_lat_graph1 + |
| 1158 | link_down_lat_graph2 + |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 1159 | link_down_lat_graph3) / 3 |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1160 | link_down_lat_link_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1161 | (link_down_lat_link1 + |
| 1162 | link_down_lat_link2 + |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 1163 | link_down_lat_link3) / 3 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1164 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1165 | #Set threshold and append latency to list |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1166 | if link_down_lat_graph_avg > down_threshold_min and\ |
| 1167 | link_down_lat_graph_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1168 | link_down_graph_to_system_list.append( |
| 1169 | link_down_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1170 | else: |
| 1171 | main.log.info("Link down latency exceeded threshold") |
| 1172 | main.log.info("Results for iteration "+str(i)+ |
| 1173 | "have been omitted") |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1174 | if link_down_lat_link_avg > down_threshold_min and\ |
| 1175 | link_down_lat_link_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1176 | link_down_link_to_system_list.append( |
| 1177 | link_down_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1178 | else: |
| 1179 | main.log.info("Link down latency exceeded threshold") |
| 1180 | main.log.info("Results for iteration "+str(i)+ |
| 1181 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1182 | |
| 1183 | #NOTE: To remove loss rate and measure latency: |
| 1184 | # 'sh tc qdisc del dev s1-eth1 root' |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1185 | timestamp_link_up_t0 = time.time() * 1000 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1186 | main.Mininet1.handle.sendline("sh tc qdisc del dev "+ |
| 1187 | "s1-eth1 root") |
| 1188 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1189 | |
| 1190 | main.log.info("Checking ONOS for link update") |
| 1191 | |
| 1192 | link_down1 = True |
| 1193 | link_down2 = True |
| 1194 | link_down3 = True |
| 1195 | loop_count = 0 |
| 1196 | while( (link_down1 and link_down2 and link_down3)\ |
| 1197 | and loop_count < 30 ): |
| 1198 | json_str1 = main.ONOS1cli.links() |
| 1199 | json_str2 = main.ONOS2cli.links() |
| 1200 | json_str3 = main.ONOS3cli.links() |
| 1201 | if not (json_str1 and json_str2 and json_str3): |
| 1202 | main.log.error("CLI command returned error ") |
| 1203 | break |
| 1204 | else: |
| 1205 | json_obj1 = json.loads(json_str1) |
| 1206 | json_obj2 = json.loads(json_str2) |
| 1207 | json_obj3 = json.loads(json_str3) |
| 1208 | |
| 1209 | for obj1 in json_obj1: |
| 1210 | if '01' in obj1['src']['device']: |
| 1211 | link_down1 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1212 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1213 | "s1 -> s2 on ONOS1 detected") |
| 1214 | for obj2 in json_obj2: |
| 1215 | if '01' in obj2['src']['device']: |
| 1216 | link_down2 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1217 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1218 | "s1 -> s2 on ONOS2 detected") |
| 1219 | for obj3 in json_obj3: |
| 1220 | if '01' in obj3['src']['device']: |
| 1221 | link_down3 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1222 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1223 | "s1 -> s2 on ONOS3 detected") |
| 1224 | |
| 1225 | loop_count += 1 |
| 1226 | time.sleep(1) |
| 1227 | |
| 1228 | if (link_down1 and link_down2 and link_down3): |
| 1229 | main.log.info("Link up discovery failed") |
| 1230 | |
| 1231 | link_up_lat_graph1 = 0 |
| 1232 | link_up_lat_graph2 = 0 |
| 1233 | link_up_lat_graph3 = 0 |
| 1234 | link_up_lat_device1 = 0 |
| 1235 | link_up_lat_device2 = 0 |
| 1236 | link_up_lat_device3 = 0 |
| 1237 | |
| 1238 | assertion = main.FALSE |
| 1239 | else: |
| 1240 | json_topo_metrics_1 =\ |
| 1241 | main.ONOS1cli.topology_events_metrics() |
| 1242 | json_topo_metrics_2 =\ |
| 1243 | main.ONOS2cli.topology_events_metrics() |
| 1244 | json_topo_metrics_3 =\ |
| 1245 | main.ONOS3cli.topology_events_metrics() |
| 1246 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 1247 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 1248 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 1249 | |
| 1250 | main.log.info("Obtaining graph and device timestamp") |
| 1251 | graph_timestamp_1 = \ |
| 1252 | json_topo_metrics_1[graphTimestamp]['value'] |
| 1253 | graph_timestamp_2 = \ |
| 1254 | json_topo_metrics_2[graphTimestamp]['value'] |
| 1255 | graph_timestamp_3 = \ |
| 1256 | json_topo_metrics_3[graphTimestamp]['value'] |
| 1257 | |
| 1258 | link_timestamp_1 = \ |
| 1259 | json_topo_metrics_1[linkTimestamp]['value'] |
| 1260 | link_timestamp_2 = \ |
| 1261 | json_topo_metrics_2[linkTimestamp]['value'] |
| 1262 | link_timestamp_3 = \ |
| 1263 | json_topo_metrics_3[linkTimestamp]['value'] |
| 1264 | |
| 1265 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 1266 | graph_timestamp_3 and link_timestamp_1 and\ |
| 1267 | link_timestamp_2 and link_timestamp_3: |
| 1268 | link_up_lat_graph1 = int(graph_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1269 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1270 | link_up_lat_graph2 = int(graph_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1271 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1272 | link_up_lat_graph3 = int(graph_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1273 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1274 | |
| 1275 | link_up_lat_link1 = int(link_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1276 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1277 | link_up_lat_link2 = int(link_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1278 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1279 | link_up_lat_link3 = int(link_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1280 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1281 | else: |
| 1282 | main.log.error("There was an error calculating"+ |
| 1283 | " the delta for link down event") |
| 1284 | link_up_lat_graph1 = 0 |
| 1285 | link_up_lat_graph2 = 0 |
| 1286 | link_up_lat_graph3 = 0 |
| 1287 | |
| 1288 | link_up_lat_device1 = 0 |
| 1289 | link_up_lat_device2 = 0 |
| 1290 | link_up_lat_device3 = 0 |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1291 | |
| 1292 | if debug_mode == 'on': |
| 1293 | main.log.info("Link up latency ONOS1 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1294 | str(i)+" (end-to-end): "+ |
| 1295 | str(link_up_lat_graph1)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1296 | main.log.info("Link up latency ONOS2 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1297 | str(i)+" (end-to-end): "+ |
| 1298 | str(link_up_lat_graph2)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1299 | main.log.info("Link up latency ONOS3 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1300 | str(i)+" (end-to-end): "+ |
| 1301 | str(link_up_lat_graph3)+" ms") |
| 1302 | |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1303 | main.log.info("Link up latency ONOS1 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1304 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1305 | str(link_up_lat_link1)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1306 | main.log.info("Link up latency ONOS2 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1307 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1308 | str(link_up_lat_link2)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1309 | main.log.info("Link up latency ONOS3 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1310 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1311 | str(link_up_lat_link3)) |
| 1312 | |
| 1313 | #Calculate avg of node calculations |
| 1314 | link_up_lat_graph_avg =\ |
| 1315 | (link_up_lat_graph1 + |
| 1316 | link_up_lat_graph2 + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1317 | link_up_lat_graph3) / 3 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1318 | link_up_lat_link_avg =\ |
| 1319 | (link_up_lat_link1 + |
| 1320 | link_up_lat_link2 + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1321 | link_up_lat_link3) / 3 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1322 | |
| 1323 | #Set threshold and append latency to list |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1324 | if link_up_lat_graph_avg > up_threshold_min and\ |
| 1325 | link_up_lat_graph_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1326 | link_up_graph_to_system_list.append( |
| 1327 | link_up_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1328 | else: |
| 1329 | main.log.info("Link up latency exceeded threshold") |
| 1330 | main.log.info("Results for iteration "+str(i)+ |
| 1331 | "have been omitted") |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1332 | if link_up_lat_link_avg > up_threshold_min and\ |
| 1333 | link_up_lat_link_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1334 | link_up_link_to_system_list.append( |
| 1335 | link_up_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1336 | else: |
| 1337 | main.log.info("Link up latency exceeded threshold") |
| 1338 | main.log.info("Results for iteration "+str(i)+ |
| 1339 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1340 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1341 | #Calculate min, max, avg of list and report |
| 1342 | link_down_min = min(link_down_graph_to_system_list) |
| 1343 | link_down_max = max(link_down_graph_to_system_list) |
| 1344 | link_down_avg = sum(link_down_graph_to_system_list) / \ |
| 1345 | len(link_down_graph_to_system_list) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1346 | link_up_min = min(link_up_graph_to_system_list) |
| 1347 | link_up_max = max(link_up_graph_to_system_list) |
| 1348 | link_up_avg = sum(link_up_graph_to_system_list) / \ |
| 1349 | len(link_up_graph_to_system_list) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1350 | link_down_std_dev = \ |
| 1351 | str(round(numpy.std(link_down_graph_to_system_list),1)) |
| 1352 | link_up_std_dev = \ |
| 1353 | str(round(numpy.std(link_up_graph_to_system_list),1)) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1354 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1355 | main.log.report("Link down latency " + |
| 1356 | "Avg: "+str(link_down_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1357 | "Std Deviation: "+link_down_std_dev+" ms") |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1358 | main.log.report("Link up latency "+ |
| 1359 | "Avg: "+str(link_up_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1360 | "Std Deviation: "+link_up_std_dev+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1361 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1362 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 1363 | onpass="Link discovery latency calculation successful", |
| 1364 | onfail="Link discovery latency case failed") |
| 1365 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1366 | def CASE5(self, main): |
| 1367 | ''' |
| 1368 | 100 Switch discovery latency |
| 1369 | |
| 1370 | Important: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1371 | This test case can be potentially dangerous if |
| 1372 | your machine has previously set iptables rules. |
| 1373 | One of the steps of the test case will flush |
| 1374 | all existing iptables rules. |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1375 | Note: |
| 1376 | You can specify the number of switches in the |
| 1377 | params file to adjust the switch discovery size |
| 1378 | (and specify the corresponding topology in Mininet1 |
| 1379 | .topo file) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1380 | ''' |
| 1381 | import time |
| 1382 | import subprocess |
| 1383 | import os |
| 1384 | import requests |
| 1385 | import json |
| 1386 | |
| 1387 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 1388 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 1389 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 1390 | MN1_ip = main.params['MN']['ip1'] |
| 1391 | ONOS_user = main.params['CTRL']['user'] |
| 1392 | |
| 1393 | default_sw_port = main.params['CTRL']['port1'] |
| 1394 | |
| 1395 | #Number of iterations of case |
| 1396 | num_iter = main.params['TEST']['numIter'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1397 | num_sw = main.params['TEST']['numSwitch'] |
| 1398 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1399 | #Timestamp 'keys' for json metrics output. |
| 1400 | #These are subject to change, hence moved into params |
| 1401 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1402 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1403 | |
| 1404 | debug_mode = main.params['TEST']['debugMode'] |
| 1405 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 1406 | local_time = time.strftime('%X') |
| 1407 | local_time = local_time.replace("/","") |
| 1408 | local_time = local_time.replace(" ","_") |
| 1409 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1410 | if debug_mode == 'on': |
| 1411 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 1412 | "/tmp/100_sw_lat_pcap_"+local_time) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1413 | |
| 1414 | #Threshold for this test case |
| 1415 | sw_disc_threshold_str = main.params['TEST']['swDisc100Threshold'] |
| 1416 | sw_disc_threshold_obj = sw_disc_threshold_str.split(",") |
| 1417 | sw_disc_threshold_min = int(sw_disc_threshold_obj[0]) |
| 1418 | sw_disc_threshold_max = int(sw_disc_threshold_obj[1]) |
| 1419 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1420 | tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt" |
| 1421 | tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt" |
| 1422 | |
| 1423 | tshark_ofp_result_list = [] |
| 1424 | tshark_tcp_result_list = [] |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1425 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1426 | sw_discovery_lat_list = [] |
| 1427 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1428 | main.case(num_sw+" Switch discovery latency") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1429 | main.step("Assigning all switches to ONOS1") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1430 | for i in range(1, int(num_sw)+1): |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1431 | main.Mininet1.assign_sw_controller( |
| 1432 | sw=str(i), |
| 1433 | ip1=ONOS1_ip, |
| 1434 | port1=default_sw_port) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1435 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1436 | #Ensure that nodes are configured with ptpd |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1437 | #Just a warning message |
| 1438 | main.log.info("Please check ptpd configuration to ensure"+\ |
| 1439 | " All nodes' system times are in sync") |
| 1440 | time.sleep(5) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1441 | |
| 1442 | for i in range(0, int(num_iter)): |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 1443 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1444 | main.step("Set iptables rule to block incoming sw connections") |
| 1445 | #Set iptables rule to block incoming switch connections |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1446 | #The rule description is as follows: |
| 1447 | # Append to INPUT rule, |
| 1448 | # behavior DROP that matches following: |
| 1449 | # * packet type: tcp |
| 1450 | # * source IP: MN1_ip |
| 1451 | # * destination PORT: 6633 |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1452 | main.ONOS1.handle.sendline( |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1453 | "sudo iptables -A INPUT -p tcp -s "+MN1_ip+ |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1454 | " --dport "+default_sw_port+" -j DROP") |
| 1455 | main.ONOS1.handle.expect("\$") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1456 | # Append to OUTPUT rule, |
| 1457 | # behavior DROP that matches following: |
| 1458 | # * packet type: tcp |
| 1459 | # * source IP: MN1_ip |
| 1460 | # * destination PORT: 6633 |
| 1461 | main.ONOS1.handle.sendline( |
| 1462 | "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+ |
| 1463 | " --dport "+default_sw_port+" -j DROP") |
| 1464 | main.ONOS1.handle.expect("\$") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1465 | #Give time to allow rule to take effect |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1466 | #NOTE: Sleep period may need to be configured |
| 1467 | # based on the number of switches in the topology |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1468 | main.log.info("Please wait for switch connection to "+ |
| 1469 | "time out") |
| 1470 | time.sleep(60) |
| 1471 | |
| 1472 | #Gather vendor OFP with tshark |
| 1473 | main.ONOS1.tshark_grep("OFP 86 Vendor", |
| 1474 | tshark_ofp_output) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1475 | main.ONOS1.tshark_grep("TCP 74 ", |
| 1476 | tshark_tcp_output) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1477 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1478 | #NOTE: Remove all iptables rule quickly (flush) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1479 | # Before removal, obtain TestON timestamp at which |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1480 | # removal took place |
| 1481 | # (ensuring nodes are configured via ptp) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1482 | # sudo iptables -F |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1483 | |
| 1484 | t0_system = time.time() * 1000 |
| 1485 | main.ONOS1.handle.sendline( |
| 1486 | "sudo iptables -F") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1487 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1488 | #Counter to track loop count |
| 1489 | counter_loop = 0 |
| 1490 | counter_avail1 = 0 |
| 1491 | counter_avail2 = 0 |
| 1492 | counter_avail3 = 0 |
| 1493 | onos1_dev = False |
| 1494 | onos2_dev = False |
| 1495 | onos3_dev = False |
| 1496 | while counter_loop < 60: |
| 1497 | #Continue to check devices for all device |
| 1498 | #availability. When all devices in all 3 |
| 1499 | #ONOS instances indicate that devices are available |
| 1500 | #obtain graph event timestamp for t1. |
| 1501 | device_str_obj1 = main.ONOS1cli.devices() |
| 1502 | device_str_obj2 = main.ONOS2cli.devices() |
| 1503 | device_str_obj3 = main.ONOS3cli.devices() |
| 1504 | |
| 1505 | device_json1 = json.loads(device_str_obj1) |
| 1506 | device_json2 = json.loads(device_str_obj2) |
| 1507 | device_json3 = json.loads(device_str_obj3) |
| 1508 | |
| 1509 | for device1 in device_json1: |
| 1510 | if device1['available'] == True: |
| 1511 | counter_avail1 += 1 |
| 1512 | if counter_avail1 == int(num_sw): |
| 1513 | onos1_dev = True |
| 1514 | main.log.info("All devices have been "+ |
| 1515 | "discovered on ONOS1") |
| 1516 | else: |
| 1517 | counter_avail1 = 0 |
| 1518 | for device2 in device_json2: |
| 1519 | if device2['available'] == True: |
| 1520 | counter_avail2 += 1 |
| 1521 | if counter_avail2 == int(num_sw): |
| 1522 | onos2_dev = True |
| 1523 | main.log.info("All devices have been "+ |
| 1524 | "discovered on ONOS2") |
| 1525 | else: |
| 1526 | counter_avail2 = 0 |
| 1527 | for device3 in device_json3: |
| 1528 | if device3['available'] == True: |
| 1529 | counter_avail3 += 1 |
| 1530 | if counter_avail3 == int(num_sw): |
| 1531 | onos3_dev = True |
| 1532 | main.log.info("All devices have been "+ |
| 1533 | "discovered on ONOS3") |
| 1534 | else: |
| 1535 | counter_avail3 = 0 |
| 1536 | |
| 1537 | if onos1_dev and onos2_dev and onos3_dev: |
| 1538 | main.log.info("All devices have been discovered "+ |
| 1539 | "on all ONOS instances") |
| 1540 | json_str_topology_metrics_1 =\ |
| 1541 | main.ONOS1cli.topology_events_metrics() |
| 1542 | json_str_topology_metrics_2 =\ |
| 1543 | main.ONOS2cli.topology_events_metrics() |
| 1544 | json_str_topology_metrics_3 =\ |
| 1545 | main.ONOS3cli.topology_events_metrics() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1546 | |
| 1547 | #Exit while loop if all devices discovered |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1548 | break |
| 1549 | |
| 1550 | counter_loop += 1 |
| 1551 | #Give some time in between CLI calls |
| 1552 | #(will not affect measurement) |
| 1553 | time.sleep(3) |
| 1554 | |
| 1555 | main.ONOS1.tshark_stop() |
| 1556 | |
| 1557 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1558 | tshark_ofp_output+" /tmp/") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1559 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1560 | tshark_tcp_output+" /tmp/") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1561 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1562 | #TODO: Automate OFP output analysis |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1563 | #Debug mode - print out packets captured at runtime |
| 1564 | if debug_mode == 'on': |
| 1565 | ofp_file = open(tshark_ofp_output, 'r') |
| 1566 | main.log.info("Tshark OFP Vendor output: ") |
| 1567 | for line in ofp_file: |
| 1568 | tshark_ofp_result_list.append(line) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1569 | main.log.info(line) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1570 | ofp_file.close() |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1571 | |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1572 | tcp_file = open(tshark_tcp_output, 'r') |
| 1573 | main.log.info("Tshark TCP 74 output: ") |
| 1574 | for line in tcp_file: |
| 1575 | tshark_tcp_result_list.append(line) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1576 | main.log.info(line) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1577 | tcp_file.close() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1578 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1579 | json_obj_1 = json.loads(json_str_topology_metrics_1) |
| 1580 | json_obj_2 = json.loads(json_str_topology_metrics_2) |
| 1581 | json_obj_3 = json.loads(json_str_topology_metrics_3) |
| 1582 | |
| 1583 | graph_timestamp_1 = \ |
| 1584 | json_obj_1[graphTimestamp]['value'] |
| 1585 | graph_timestamp_2 = \ |
| 1586 | json_obj_2[graphTimestamp]['value'] |
| 1587 | graph_timestamp_3 = \ |
| 1588 | json_obj_3[graphTimestamp]['value'] |
| 1589 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1590 | graph_lat_1 = int(graph_timestamp_1) - int(t0_system) |
| 1591 | graph_lat_2 = int(graph_timestamp_2) - int(t0_system) |
| 1592 | graph_lat_3 = int(graph_timestamp_3) - int(t0_system) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1593 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1594 | avg_graph_lat = \ |
| 1595 | (int(graph_lat_1) +\ |
| 1596 | int(graph_lat_2) +\ |
| 1597 | int(graph_lat_3)) / 3 |
| 1598 | |
| 1599 | if avg_graph_lat > sw_disc_threshold_min \ |
| 1600 | and avg_graph_lat < sw_disc_threshold_max: |
| 1601 | sw_discovery_lat_list.append( |
| 1602 | avg_graph_lat) |
| 1603 | else: |
| 1604 | main.log.info("100 Switch discovery latency "+ |
| 1605 | "exceeded the threshold.") |
| 1606 | |
| 1607 | #END ITERATION FOR LOOP |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1608 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1609 | sw_lat_min = min(sw_discovery_lat_list) |
| 1610 | sw_lat_max = max(sw_discovery_lat_list) |
| 1611 | sw_lat_avg = sum(sw_discovery_lat_list) /\ |
| 1612 | len(sw_discovery_lat_list) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1613 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1614 | main.log.report("100 Switch discovery lat "+\ |
| 1615 | "Min: "+str(sw_lat_min)+" ms"+\ |
| 1616 | "Max: "+str(sw_lat_max)+" ms"+\ |
| 1617 | "Avg: "+str(sw_lat_avg)+" ms") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1618 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1619 | |