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