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 |
| 6 | |
| 7 | import time |
| 8 | import sys |
| 9 | import os |
| 10 | import re |
| 11 | |
| 12 | class TopoPerfNext: |
| 13 | def __init__(self): |
| 14 | self.default = '' |
| 15 | |
| 16 | def CASE1(self, main): |
| 17 | ''' |
| 18 | ONOS startup sequence |
| 19 | ''' |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 20 | import time |
| 21 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 22 | cell_name = main.params['ENV']['cellName'] |
| 23 | |
| 24 | git_pull = main.params['GIT']['autoPull'] |
| 25 | checkout_branch = main.params['GIT']['checkout'] |
| 26 | |
| 27 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 28 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 29 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 30 | MN1_ip = main.params['MN']['ip1'] |
| 31 | BENCH_ip = main.params['BENCH']['ip'] |
| 32 | |
| 33 | main.case("Setting up test environment") |
| 34 | |
| 35 | main.step("Creating cell file") |
| 36 | cell_file_result = main.ONOSbench.create_cell_file( |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 37 | BENCH_ip, cell_name, MN1_ip, "onos-core", |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 38 | ONOS1_ip, ONOS2_ip, ONOS3_ip) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 39 | |
| 40 | main.step("Applying cell file to environment") |
| 41 | cell_apply_result = main.ONOSbench.set_cell(cell_name) |
| 42 | verify_cell_result = main.ONOSbench.verify_cell() |
| 43 | |
| 44 | main.step("Git checkout and pull "+checkout_branch) |
| 45 | if git_pull == 'on': |
| 46 | checkout_result = \ |
| 47 | main.ONOSbench.git_checkout(checkout_branch) |
| 48 | pull_result = main.ONOSbench.git_pull() |
| 49 | else: |
| 50 | checkout_result = main.TRUE |
| 51 | pull_result = main.TRUE |
| 52 | main.log.info("Skipped git checkout and pull") |
| 53 | |
| 54 | main.step("Using mvn clean & install") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 55 | #mvn_result = main.ONOSbench.clean_install() |
| 56 | mvn_result = main.TRUE |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 57 | |
| 58 | main.step("Creating ONOS package") |
| 59 | package_result = main.ONOSbench.onos_package() |
| 60 | |
| 61 | main.step("Installing ONOS package") |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 62 | install1_result = main.ONOSbench.onos_install(node=ONOS1_ip) |
| 63 | install2_result = main.ONOSbench.onos_install(node=ONOS2_ip) |
| 64 | install3_result = main.ONOSbench.onos_install(node=ONOS3_ip) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 65 | |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 66 | #NOTE: This step may be unnecessary |
| 67 | #main.step("Starting ONOS service") |
| 68 | #start_result = main.ONOSbench.onos_start(ONOS1_ip) |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 69 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 70 | main.step("Set cell for ONOS cli env") |
| 71 | main.ONOS1cli.set_cell(cell_name) |
| 72 | main.ONOS2cli.set_cell(cell_name) |
| 73 | main.ONOS3cli.set_cell(cell_name) |
| 74 | |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 75 | time.sleep(10) |
| 76 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 77 | main.step("Start onos cli") |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 78 | cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip) |
| 79 | cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip) |
| 80 | cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip) |
| 81 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 82 | main.step("Enable metrics feature") |
| 83 | main.ONOS1cli.feature_install("onos-app-metrics-topology") |
| 84 | main.ONOS2cli.feature_install("onos-app-metrics-topology") |
| 85 | main.ONOS3cli.feature_install("onos-app-metrics-topology") |
| 86 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 87 | utilities.assert_equals(expect=main.TRUE, |
| 88 | actual= cell_file_result and cell_apply_result and\ |
| 89 | verify_cell_result and checkout_result and\ |
| 90 | pull_result and mvn_result and\ |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 91 | install1_result and install2_result and\ |
| 92 | install3_result, |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 93 | onpass="ONOS started successfully", |
| 94 | onfail="Failed to start ONOS") |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 95 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 96 | def CASE2(self, main): |
| 97 | ''' |
| 98 | Assign s1 to ONOS1 and measure latency |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 99 | |
| 100 | There are 4 levels of latency measurements to this test: |
| 101 | 1) End-to-end measurement: Complete end-to-end measurement |
| 102 | from TCP (SYN/ACK) handshake to Graph change |
| 103 | 2) OFP-to-graph measurement: 'ONOS processing' snippet of |
| 104 | measurement from OFP Vendor message to Graph change |
| 105 | 3) OFP-to-device measurement: 'ONOS processing without |
| 106 | graph change' snippet of measurement from OFP vendor |
| 107 | message to Device change timestamp |
| 108 | 4) T0-to-device measurement: Measurement that includes |
| 109 | the switch handshake to devices timestamp without |
| 110 | the graph view change. (TCP handshake -> Device |
| 111 | change) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 112 | ''' |
| 113 | import time |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 114 | import subprocess |
| 115 | import json |
| 116 | import requests |
| 117 | import os |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 118 | |
| 119 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 120 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 121 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 122 | ONOS_user = main.params['CTRL']['user'] |
| 123 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 124 | default_sw_port = main.params['CTRL']['port1'] |
| 125 | |
| 126 | #Number of iterations of case |
| 127 | num_iter = main.params['TEST']['numIter'] |
| 128 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 129 | #Timestamp 'keys' for json metrics output. |
| 130 | #These are subject to change, hence moved into params |
| 131 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 132 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 133 | |
| 134 | #List of switch add latency collected from |
| 135 | #all iterations |
| 136 | latency_end_to_end_list = [] |
| 137 | latency_ofp_to_graph_list = [] |
| 138 | latency_ofp_to_device_list = [] |
| 139 | latency_t0_to_device_list = [] |
| 140 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 141 | #Directory/file to store tshark results |
| 142 | tshark_of_output = "/tmp/tshark_of_topo.txt" |
| 143 | tshark_tcp_output = "/tmp/tshark_tcp_topo.txt" |
| 144 | |
| 145 | #String to grep in tshark output |
| 146 | tshark_tcp_string = "TCP 74 "+default_sw_port |
| 147 | tshark_of_string = "OFP 86 Vendor" |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 148 | |
| 149 | #Initialize assertion to TRUE |
| 150 | assertion = main.TRUE |
| 151 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 152 | main.log.report("Latency of adding one switch") |
| 153 | |
| 154 | for i in range(0, int(num_iter)): |
| 155 | main.log.info("Starting tshark capture") |
| 156 | |
| 157 | #* TCP [ACK, SYN] is used as t0_a, the |
| 158 | # very first "exchange" between ONOS and |
| 159 | # the switch for end-to-end measurement |
| 160 | #* OFP [Stats Reply] is used for t0_b |
| 161 | # the very last OFP message between ONOS |
| 162 | # and the switch for ONOS measurement |
| 163 | main.ONOS1.tshark_grep(tshark_tcp_string, |
| 164 | tshark_tcp_output) |
| 165 | main.ONOS1.tshark_grep(tshark_of_string, |
| 166 | tshark_of_output) |
| 167 | |
| 168 | #Wait and ensure tshark is started and |
| 169 | #capturing |
| 170 | time.sleep(10) |
| 171 | |
| 172 | main.log.info("Assigning s1 to controller") |
| 173 | |
| 174 | main.Mininet1.assign_sw_controller(sw="1", |
| 175 | ip1=ONOS1_ip, port1=default_sw_port) |
| 176 | |
| 177 | #Wait and ensure switch is assigned |
| 178 | #before stopping tshark |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 179 | time.sleep(30) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 180 | |
| 181 | main.log.info("Stopping all Tshark processes") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 182 | main.ONOS1.stop_tshark() |
| 183 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 184 | #tshark output is saved in ONOS. Use subprocess |
| 185 | #to copy over files to TestON for parsing |
| 186 | main.log.info("Copying over tshark files") |
| 187 | |
| 188 | #TCP CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 189 | #Copy the tshark output from ONOS machine to |
| 190 | #TestON machine in tshark_tcp_output directory>file |
| 191 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 192 | tshark_tcp_output+" /tmp/") |
| 193 | tcp_file = open(tshark_tcp_output, 'r') |
| 194 | temp_text = tcp_file.readline() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 195 | temp_text = temp_text.split(" ") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 196 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 197 | main.log.info("Object read in from TCP capture: "+ |
| 198 | str(temp_text)) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 199 | if len(temp_text) > 1: |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 200 | t0_tcp = float(temp_text[1])*1000.0 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 201 | else: |
| 202 | main.log.error("Tshark output file for TCP"+ |
| 203 | " returned unexpected results") |
| 204 | t0_tcp = 0 |
| 205 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 206 | |
| 207 | tcp_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 208 | #**************** |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 209 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 210 | #OF CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 211 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 212 | tshark_of_output+" /tmp/") |
| 213 | of_file = open(tshark_of_output, 'r') |
| 214 | |
| 215 | line_ofp = "" |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 216 | #Read until last line of file |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 217 | while True: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 218 | temp_text = of_file.readline() |
| 219 | if temp_text !='': |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 220 | line_ofp = temp_text |
| 221 | else: |
| 222 | break |
| 223 | obj = line_ofp.split(" ") |
| 224 | |
| 225 | main.log.info("Object read in from OFP capture: "+ |
| 226 | str(line_ofp)) |
| 227 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 228 | if len(line_ofp) > 1: |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 229 | t0_ofp = float(obj[1])*1000.0 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 230 | else: |
| 231 | main.log.error("Tshark output file for OFP"+ |
| 232 | " returned unexpected results") |
| 233 | t0_ofp = 0 |
| 234 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 235 | |
| 236 | of_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 237 | #**************** |
| 238 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 239 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 240 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 241 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 242 | |
| 243 | json_obj_1 = json.loads(json_str_1) |
| 244 | json_obj_2 = json.loads(json_str_2) |
| 245 | json_obj_3 = json.loads(json_str_3) |
| 246 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 247 | #Obtain graph timestamp. This timestsamp captures |
| 248 | #the epoch time at which the topology graph was updated. |
| 249 | graph_timestamp_1 = \ |
| 250 | json_obj_1[graphTimestamp]['value'] |
| 251 | graph_timestamp_2 = \ |
| 252 | json_obj_2[graphTimestamp]['value'] |
| 253 | graph_timestamp_3 = \ |
| 254 | json_obj_3[graphTimestamp]['value'] |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 255 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 256 | #Obtain device timestamp. This timestamp captures |
| 257 | #the epoch time at which the device event happened |
| 258 | device_timestamp_1 = \ |
| 259 | json_obj_1[deviceTimestamp]['value'] |
| 260 | device_timestamp_2 = \ |
| 261 | json_obj_2[deviceTimestamp]['value'] |
| 262 | device_timestamp_3 = \ |
| 263 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 264 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 265 | #t0 to device processing latency |
| 266 | delta_device_1 = int(device_timestamp_1) - int(t0_tcp) |
| 267 | delta_device_2 = int(device_timestamp_2) - int(t0_tcp) |
| 268 | delta_device_3 = int(device_timestamp_3) - int(t0_tcp) |
| 269 | |
| 270 | #Get average of delta from all instances |
| 271 | avg_delta_device = \ |
| 272 | (int(delta_device_1)+\ |
| 273 | int(delta_device_2)+\ |
| 274 | int(delta_device_3)) / 3 |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 275 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 276 | #Ensure avg delta meets the threshold before appending |
| 277 | if avg_delta_device > 0.0 and avg_delta_device < 10000: |
| 278 | latency_t0_to_device_list.append(avg_delta_device) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 279 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 280 | main.log.info("Results for t0-to-device ignored"+\ |
| 281 | "due to excess in threshold") |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 282 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 283 | #t0 to graph processing latency (end-to-end) |
| 284 | delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp) |
| 285 | delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp) |
| 286 | delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp) |
| 287 | |
| 288 | #Get average of delta from all instances |
| 289 | avg_delta_graph = \ |
| 290 | (int(delta_graph_1)+\ |
| 291 | int(delta_graph_2)+\ |
| 292 | int(delta_graph_3)) / 3 |
| 293 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 294 | #Ensure avg delta meets the threshold before appending |
| 295 | if avg_delta_graph > 0.0 and avg_delta_graph < 10000: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 296 | latency_end_to_end_list.append(avg_delta_graph) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 297 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 298 | main.log.info("Results for end-to-end ignored"+\ |
| 299 | "due to excess in threshold") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 300 | |
| 301 | #ofp to graph processing latency (ONOS processing) |
| 302 | delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp) |
| 303 | delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp) |
| 304 | delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp) |
| 305 | |
| 306 | avg_delta_ofp_graph = \ |
| 307 | (int(delta_ofp_graph_1)+\ |
| 308 | int(delta_ofp_graph_2)+\ |
| 309 | int(delta_ofp_graph_3)) / 3 |
| 310 | |
| 311 | if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000: |
| 312 | latency_ofp_to_graph_list.append(avg_delta_ofp_graph) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 313 | else: |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 314 | main.log.info("Results for ofp-to-graph "+\ |
| 315 | "ignored due to excess in threshold") |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 316 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 317 | #ofp to device processing latency (ONOS processing) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 318 | delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp) |
| 319 | delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp) |
| 320 | delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 321 | |
| 322 | avg_delta_ofp_device = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 323 | (float(delta_ofp_device_1)+\ |
| 324 | float(delta_ofp_device_2)+\ |
| 325 | float(delta_ofp_device_3)) / 3.0 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 326 | |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 327 | #NOTE: ofp - delta measurements are occasionally negative |
| 328 | # due to system time misalignment. |
| 329 | #TODO: Implement ptp across all clusters |
| 330 | #Just add the calculation to list for now |
| 331 | latency_ofp_to_device_list.append(avg_delta_ofp_device) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 332 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 333 | #TODO: |
| 334 | #Fetch logs upon threshold excess |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 335 | |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 336 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 337 | main.log.info("ONOS1 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 338 | str(delta_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 339 | main.log.info("ONOS2 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 340 | str(delta_graph_2) + " ms") |
| 341 | main.log.info("ONOS3 delta end-to-end: "+ |
| 342 | str(delta_graph_3) + " ms") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 343 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 344 | main.log.info("ONOS1 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 345 | str(delta_ofp_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 346 | main.log.info("ONOS2 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 347 | str(delta_ofp_graph_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 348 | main.log.info("ONOS3 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 349 | str(delta_ofp_graph_3) + " ms") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 350 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 351 | main.log.info("ONOS1 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 352 | str(delta_device_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 353 | main.log.info("ONOS2 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 354 | str(delta_device_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 355 | main.log.info("ONOS3 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 356 | str(delta_device_3) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 357 | |
| 358 | main.log.info("ONOS1 delta OFP - device: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 359 | str(delta_ofp_device_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 360 | main.log.info("ONOS2 delta OFP - device: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 361 | str(delta_ofp_device_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 362 | main.log.info("ONOS3 delta OFP - device: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 363 | str(delta_ofp_device_3) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 364 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 365 | main.step("Remove switch from controller") |
| 366 | main.Mininet1.delete_sw_controller("s1") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 367 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 368 | time.sleep(5) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 369 | |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 370 | #END of for loop iteration |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 371 | |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 372 | #If there is at least 1 element in each list, |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 373 | #pass the test case |
| 374 | if len(latency_end_to_end_list) > 0 and\ |
| 375 | len(latency_ofp_to_graph_list) > 0 and\ |
| 376 | len(latency_ofp_to_device_list) > 0 and\ |
| 377 | len(latency_t0_to_device_list) > 0: |
| 378 | assertion = main.TRUE |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 379 | elif len(latency_end_to_end_list) == 0: |
| 380 | #The appending of 0 here is to prevent |
| 381 | #the min,max,sum functions from failing |
| 382 | #below |
| 383 | latency_end_to_end_list.append(0) |
| 384 | assertion = main.FALSE |
| 385 | elif len(latency_ofp_to_graph_list) == 0: |
| 386 | latency_ofp_to_graph_list.append(0) |
| 387 | assertion = main.FALSE |
| 388 | elif len(latency_ofp_to_device_list) == 0: |
| 389 | latency_ofp_to_device_list.append(0) |
| 390 | assertion = main.FALSE |
| 391 | elif len(latency_t0_to_device_list) == 0: |
| 392 | latency_t0_to_device_list.append(0) |
| 393 | assertion = main.FALSE |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 394 | |
| 395 | #Calculate min, max, avg of latency lists |
| 396 | latency_end_to_end_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 397 | int(max(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 398 | latency_end_to_end_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 399 | int(min(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 400 | latency_end_to_end_avg = \ |
andrewonlab | c90667c | 2014-10-24 16:48:28 -0400 | [diff] [blame] | 401 | (int(sum(latency_end_to_end_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 402 | len(latency_end_to_end_list)) |
| 403 | |
| 404 | latency_ofp_to_graph_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 405 | int(max(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 406 | latency_ofp_to_graph_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 407 | int(min(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 408 | latency_ofp_to_graph_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 409 | (int(sum(latency_ofp_to_graph_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 410 | len(latency_ofp_to_graph_list)) |
| 411 | |
| 412 | latency_ofp_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 413 | int(max(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 414 | latency_ofp_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 415 | int(min(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 416 | latency_ofp_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 417 | (int(sum(latency_ofp_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 418 | len(latency_ofp_to_device_list)) |
| 419 | |
| 420 | latency_t0_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 421 | float(max(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 422 | latency_t0_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 423 | float(min(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 424 | latency_t0_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 425 | (float(sum(latency_t0_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 426 | len(latency_ofp_to_device_list)) |
| 427 | |
| 428 | main.log.report("Switch add - End-to-end latency: \n"+\ |
| 429 | "Min: "+str(latency_end_to_end_min)+"\n"+\ |
| 430 | "Max: "+str(latency_end_to_end_max)+"\n"+\ |
| 431 | "Avg: "+str(latency_end_to_end_avg)) |
| 432 | main.log.report("Switch add - OFP-to-Graph latency: \n"+\ |
| 433 | "Min: "+str(latency_ofp_to_graph_min)+"\n"+\ |
| 434 | "Max: "+str(latency_ofp_to_graph_max)+"\n"+\ |
| 435 | "Avg: "+str(latency_ofp_to_graph_avg)) |
| 436 | main.log.report("Switch add - OFP-to-Device latency: \n"+\ |
| 437 | "Min: "+str(latency_ofp_to_device_min)+"\n"+\ |
| 438 | "Max: "+str(latency_ofp_to_device_max)+"\n"+\ |
| 439 | "Avg: "+str(latency_ofp_to_device_avg)) |
| 440 | main.log.report("Switch add - t0-to-Device latency: \n"+\ |
| 441 | "Min: "+str(latency_t0_to_device_min)+"\n"+\ |
| 442 | "Max: "+str(latency_t0_to_device_max)+"\n"+\ |
| 443 | "Avg: "+str(latency_t0_to_device_avg)) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 444 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 445 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 446 | onpass="Switch latency test successful", |
| 447 | onfail="Switch latency test failed") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 448 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 449 | def CASE3(self, main): |
| 450 | ''' |
| 451 | Bring port up / down and measure latency. |
| 452 | Port enable / disable is simulated by ifconfig up / down |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 453 | |
| 454 | In ONOS-next, we must ensure that the port we are |
| 455 | manipulating is connected to another switch with a valid |
| 456 | connection. Otherwise, graph view will not be updated. |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 457 | ''' |
| 458 | import time |
| 459 | import subprocess |
| 460 | import os |
| 461 | import requests |
| 462 | import json |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 463 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 464 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 465 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 466 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 467 | ONOS_user = main.params['CTRL']['user'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 468 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 469 | default_sw_port = main.params['CTRL']['port1'] |
| 470 | |
| 471 | #Number of iterations of case |
| 472 | num_iter = main.params['TEST']['numIter'] |
| 473 | |
| 474 | #Timestamp 'keys' for json metrics output. |
| 475 | #These are subject to change, hence moved into params |
| 476 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 477 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 478 | |
| 479 | #NOTE: Some hardcoded variables you may need to configure |
| 480 | # besides the params |
| 481 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 482 | tshark_port_status = "OFP 130 Port Status" |
| 483 | |
| 484 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 485 | tshark_port_down = "/tmp/tshark_port_down.txt" |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 486 | interface_config = "s1-eth1" |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 487 | |
| 488 | main.log.report("Port enable / disable latency") |
| 489 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 490 | main.step("Assign switches s1 and s2 to controller 1") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 491 | main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip, |
| 492 | port1=default_sw_port) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 493 | main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip, |
| 494 | port1=default_sw_port) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 495 | |
| 496 | main.step("Verify switch is assigned correctly") |
| 497 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 498 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
| 499 | if result_s1 == main.FALSE or result_s2 == main.FALSE: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 500 | main.log.info("Switch s1 was not assigned correctly") |
| 501 | assertion = main.FALSE |
| 502 | else: |
| 503 | main.log.info("Switch s1 was assigned correctly") |
| 504 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 505 | port_up_device_to_ofp_list = [] |
| 506 | port_up_graph_to_ofp_list = [] |
| 507 | port_down_device_to_ofp_list = [] |
| 508 | port_down_graph_to_ofp_list = [] |
| 509 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 510 | for i in range(0, int(num_iter)): |
| 511 | main.step("Starting wireshark capture for port status down") |
| 512 | main.ONOS1.tshark_grep(tshark_port_status, |
| 513 | tshark_port_down) |
| 514 | |
| 515 | time.sleep(10) |
| 516 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 517 | #Disable interface that is connected to switch 2 |
| 518 | main.step("Disable port: "+interface_config) |
| 519 | main.Mininet2.handle.sendline("sudo ifconfig "+ |
| 520 | interface_config+" down") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 521 | main.Mininet2.handle.expect("\$") |
| 522 | time.sleep(20) |
| 523 | |
| 524 | main.ONOS1.tshark_stop() |
| 525 | time.sleep(5) |
| 526 | |
| 527 | #Copy tshark output file from ONOS to TestON instance |
| 528 | #/tmp directory |
| 529 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 530 | tshark_port_down+" /tmp/") |
| 531 | |
| 532 | f_port_down = open(tshark_port_down, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 533 | #Get first line of port down event from tshark |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 534 | f_line = f_port_down.readline() |
| 535 | obj_down = f_line.split(" ") |
| 536 | if len(f_line) > 0: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 537 | timestamp_begin_pt_down = int(float(obj_down[1]))*1000 |
| 538 | main.log.info("Port down begin timestamp: "+ |
| 539 | str(timestamp_begin_pt_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 540 | else: |
| 541 | main.log.info("Tshark output file returned unexpected"+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 542 | " results: "+str(obj_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 543 | timestamp_begin_pt_down = 0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 544 | |
| 545 | f_port_down.close() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 546 | |
| 547 | main.step("Obtain t1 by REST call") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 548 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 549 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 550 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 551 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 552 | json_obj_1 = json.loads(json_str_1) |
| 553 | json_obj_2 = json.loads(json_str_2) |
| 554 | json_obj_3 = json.loads(json_str_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 555 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 556 | time.sleep(5) |
| 557 | |
| 558 | #Obtain graph timestamp. This timestsamp captures |
| 559 | #the epoch time at which the topology graph was updated. |
| 560 | graph_timestamp_1 = \ |
| 561 | json_obj_1[graphTimestamp]['value'] |
| 562 | graph_timestamp_2 = \ |
| 563 | json_obj_2[graphTimestamp]['value'] |
| 564 | graph_timestamp_3 = \ |
| 565 | json_obj_3[graphTimestamp]['value'] |
| 566 | |
| 567 | #TODO: Test purposes, remove later |
| 568 | main.log.info("json_timestamp graph: "+str(graph_timestamp_1)) |
| 569 | main.log.info("json_timestamp graph: "+str(graph_timestamp_2)) |
| 570 | main.log.info("json_timestamp graph: "+str(graph_timestamp_3)) |
| 571 | |
| 572 | #Obtain device timestamp. This timestamp captures |
| 573 | #the epoch time at which the device event happened |
| 574 | device_timestamp_1 = \ |
| 575 | json_obj_1[deviceTimestamp]['value'] |
| 576 | device_timestamp_2 = \ |
| 577 | json_obj_2[deviceTimestamp]['value'] |
| 578 | device_timestamp_3 = \ |
| 579 | json_obj_3[deviceTimestamp]['value'] |
| 580 | |
| 581 | #TODO: Test purposes, remove later |
| 582 | main.log.info("json_timestamp device: "+str(device_timestamp_1)) |
| 583 | main.log.info("json_timestamp device: "+str(device_timestamp_2)) |
| 584 | main.log.info("json_timestamp device: "+str(device_timestamp_3)) |
| 585 | |
| 586 | #Get delta between graph event and OFP |
| 587 | pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
| 588 | int(timestamp_begin_pt_down) |
| 589 | pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
| 590 | int(timestamp_begin_pt_down) |
| 591 | pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 592 | int(timestamp_begin_pt_down) |
| 593 | |
| 594 | #Get delta between device event and OFP |
| 595 | pt_down_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 596 | int(timestamp_begin_pt_down) |
| 597 | pt_down_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 598 | int(timestamp_begin_pt_down) |
| 599 | pt_down_device_to_ofp_3 = int(device_timestamp_3) -\ |
| 600 | int(timestamp_begin_pt_down) |
| 601 | |
| 602 | #Caluclate average across clusters |
| 603 | pt_down_graph_to_ofp_avg =\ |
| 604 | (int(pt_down_graph_to_ofp_1) + |
| 605 | int(pt_down_graph_to_ofp_2) + |
| 606 | int(pt_down_graph_to_ofp_3)) / 3 |
| 607 | pt_down_device_to_ofp_avg = \ |
| 608 | (int(pt_down_device_to_ofp_1) + |
| 609 | int(pt_down_device_to_ofp_2) + |
| 610 | int(pt_down_device_to_ofp_3)) / 3 |
| 611 | |
| 612 | if pt_down_graph_to_ofp_avg > 0 and \ |
| 613 | pt_down_graph_to_ofp_avg < 1000: |
| 614 | port_down_graph_to_ofp_list.append( |
| 615 | pt_down_graph_to_ofp_avg) |
| 616 | else: |
| 617 | main.log.info("Average port down graph-to-ofp result" + |
| 618 | " exceeded the threshold: "+ |
| 619 | str(pt_down_graph_to_ofp_avg)) |
| 620 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 621 | if pt_down_device_to_ofp_avg > 0 and \ |
| 622 | pt_down_device_to_ofp_avg < 1000: |
| 623 | port_down_device_to_ofp_list.append( |
| 624 | pt_down_device_to_ofp_avg) |
| 625 | else: |
| 626 | main.log.info("Average port down device-to-ofp result" + |
| 627 | " exceeded the threshold: "+ |
| 628 | str(pt_down_device_to_ofp_avg)) |
| 629 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 630 | #TODO: Remove these logs. For test purposes only |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 631 | main.log.info("Delta1 down graph: "+str(pt_down_graph_to_ofp_1)) |
| 632 | main.log.info("Delta2 down graph: "+str(pt_down_graph_to_ofp_2)) |
| 633 | main.log.info("Delta3 down graph: "+str(pt_down_graph_to_ofp_3)) |
| 634 | |
| 635 | main.log.info("Delta1 down device: "+ |
| 636 | str(pt_down_device_to_ofp_1)) |
| 637 | main.log.info("Delta2 down device: "+ |
| 638 | str(pt_down_device_to_ofp_2)) |
| 639 | main.log.info("Delta3 down device: "+ |
| 640 | str(pt_down_device_to_ofp_3)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 641 | |
| 642 | #Port up events |
| 643 | main.step("Enable port and obtain timestamp") |
| 644 | main.step("Starting wireshark capture for port status up") |
| 645 | main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up) |
| 646 | time.sleep(10) |
| 647 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 648 | main.Mininet2.handle.sendline("sudo ifconfig "+ |
| 649 | interface_config+" up") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 650 | main.Mininet2.handle.expect("\$") |
| 651 | time.sleep(20) |
| 652 | |
| 653 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 654 | tshark_port_up+" /tmp/") |
| 655 | |
| 656 | f_port_up = open(tshark_port_up, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 657 | f_line = f_port_up.readline() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 658 | obj_up = f_line.split(" ") |
| 659 | if len(f_line) > 0: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 660 | timestamp_begin_pt_up = int(float(obj_up[1]))*1000 |
| 661 | main.log.info("Port up begin timestamp: "+ |
| 662 | str(timestamp_begin_pt_up)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 663 | else: |
| 664 | main.log.info("Tshark output file returned unexpected"+ |
| 665 | " results.") |
| 666 | timestamp_begin_pt_up = 0 |
| 667 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 668 | f_port_up.close() |
| 669 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 670 | main.step("Obtain t1 by REST call") |
| 671 | #TODO: Implement json object parsing here |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 672 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 673 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 674 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 675 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 676 | json_obj_1 = json.loads(json_str_1) |
| 677 | json_obj_2 = json.loads(json_str_2) |
| 678 | json_obj_3 = json.loads(json_str_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 679 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 680 | #Obtain graph timestamp. This timestsamp captures |
| 681 | #the epoch time at which the topology graph was updated. |
| 682 | graph_timestamp_1 = \ |
| 683 | json_obj_1[graphTimestamp]['value'] |
| 684 | graph_timestamp_2 = \ |
| 685 | json_obj_2[graphTimestamp]['value'] |
| 686 | graph_timestamp_3 = \ |
| 687 | json_obj_3[graphTimestamp]['value'] |
| 688 | |
| 689 | #Obtain device timestamp. This timestamp captures |
| 690 | #the epoch time at which the device event happened |
| 691 | device_timestamp_1 = \ |
| 692 | json_obj_1[deviceTimestamp]['value'] |
| 693 | device_timestamp_2 = \ |
| 694 | json_obj_2[deviceTimestamp]['value'] |
| 695 | device_timestamp_3 = \ |
| 696 | json_obj_3[deviceTimestamp]['value'] |
| 697 | |
| 698 | #Get delta between graph event and OFP |
| 699 | pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 700 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 701 | pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 702 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 703 | pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 704 | int(timestamp_begin_pt_up) |
| 705 | |
| 706 | #Get delta between device event and OFP |
| 707 | pt_up_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 708 | int(timestamp_begin_pt_up) |
| 709 | pt_up_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 710 | int(timestamp_begin_pt_up) |
| 711 | pt_up_device_to_ofp_3 = int(device_timestamp_3) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 712 | int(timestamp_begin_pt_up) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 713 | |
| 714 | pt_up_graph_to_ofp_avg = \ |
| 715 | (float(pt_up_graph_to_ofp_1) + |
| 716 | float(pt_up_graph_to_ofp_2) + |
| 717 | float(pt_up_graph_to_ofp_3)) / 3 |
| 718 | |
| 719 | pt_up_device_to_ofp_avg = \ |
| 720 | (float(pt_up_device_to_ofp_1) + |
| 721 | float(pt_up_device_to_ofp_2) + |
| 722 | float(pt_up_device_to_ofp_3)) / 3 |
| 723 | |
| 724 | if pt_up_graph_to_ofp_avg > 0 and \ |
| 725 | pt_up_graph_to_ofp_avg < 1000: |
| 726 | port_up_graph_to_ofp_list.append( |
| 727 | pt_up_graph_to_ofp_avg) |
| 728 | else: |
| 729 | main.log.info("Average port up graph-to-ofp result"+ |
| 730 | " exceeded the threshold: "+ |
| 731 | str(pt_up_graph_to_ofp_avg)) |
| 732 | |
| 733 | if pt_up_device_to_ofp_avg > 0 and \ |
| 734 | pt_up_device_to_ofp_avg < 1000: |
| 735 | port_up_device_to_ofp_list.append( |
| 736 | pt_up_device_to_ofp_avg) |
| 737 | else: |
| 738 | main.log.info("Average port up graph-to-ofp result"+ |
| 739 | " exceeded the threshold: "+ |
| 740 | str(pt_up_device_to_ofp_avg)) |
| 741 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 742 | #TODO: Remove these logs. For test purposes only |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 743 | main.log.info("Delta1 up graph: "+str(pt_up_graph_to_ofp_1)) |
| 744 | main.log.info("Delta2 up graph: "+str(pt_up_graph_to_ofp_2)) |
| 745 | main.log.info("Delta3 up graph: "+str(pt_up_graph_to_ofp_3)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 746 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 747 | main.log.info("Delta1 down device: "+ |
| 748 | str(pt_up_device_to_ofp_1)) |
| 749 | main.log.info("Delta2 down device: "+ |
| 750 | str(pt_up_device_to_ofp_2)) |
| 751 | main.log.info("Delta3 down device: "+ |
| 752 | str(pt_up_device_to_ofp_3)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 753 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 754 | #END ITERATION FOR LOOP |
| 755 | |
| 756 | port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list) |
| 757 | port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list) |
| 758 | port_down_graph_to_ofp_avg = \ |
| 759 | (sum(port_down_graph_to_ofp_list) / |
| 760 | len(port_down_graph_to_ofp_list)) |
| 761 | |
| 762 | main.log.report("Port up graph-to-ofp Min: ") |
| 763 | main.log.report("Port up graph-to-ofp Max: ") |
| 764 | main.log.report("Port up graph-to-ofp Avg: ") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 765 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 766 | def CASE4(self, main): |
| 767 | ''' |
| 768 | Link down event using loss rate 100% |
| 769 | ''' |
| 770 | import time |
| 771 | import subprocess |
| 772 | import os |
| 773 | import requests |
| 774 | import json |
| 775 | |
| 776 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 777 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 778 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 779 | ONOS_user = main.params['CTRL']['user'] |
| 780 | |
| 781 | default_sw_port = main.params['CTRL']['port1'] |
| 782 | |
| 783 | #Number of iterations of case |
| 784 | num_iter = main.params['TEST']['numIter'] |
| 785 | |
| 786 | #Timestamp 'keys' for json metrics output. |
| 787 | #These are subject to change, hence moved into params |
| 788 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 789 | linkTimestamp = main.params['JSON']['linkTimestamp'] |
| 790 | |
| 791 | assertion = main.TRUE |
| 792 | #Link event timestamp to system time list |
| 793 | link_down_link_to_system_list = [] |
| 794 | link_up_link_to_system_list = [] |
| 795 | #Graph event timestamp to system time list |
| 796 | link_down_graph_to_system_list = [] |
| 797 | link_up_graph_to_system_list = [] |
| 798 | |
| 799 | main.log.report("Add / remove link latency between "+ |
| 800 | "two switches") |
| 801 | |
| 802 | main.step("Assign all switches") |
| 803 | main.Mininet1.assign_sw_controller(sw="1", |
| 804 | ip1=ONOS1_ip, port1=default_sw_port) |
| 805 | main.Mininet1.assign_sw_controller(sw="2", |
| 806 | ip1=ONOS1_ip, port1=default_sw_port) |
| 807 | |
| 808 | main.step("Verifying switch assignment") |
| 809 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
| 810 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
| 811 | |
| 812 | if result_s1 == main.TRUE and result_s2 == main.TRUE: |
| 813 | main.log.report("Switches s1, s2 assigned successfully") |
| 814 | else: |
| 815 | main.log.error("Error assigning switches s1 and s2") |
| 816 | assertion = main.FALSE |
| 817 | |
| 818 | #Allow time for events to finish before taking measurements |
| 819 | time.sleep(10) |
| 820 | |
| 821 | #Start iteration of link event test |
| 822 | for i in range(0, int(num_iter)): |
| 823 | main.step("Getting initial system time as t0") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 824 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 825 | timestamp_link_down_t0 = time.time() * 1000 |
| 826 | #Link down is simulated by 100% loss rate using traffic |
| 827 | #control command |
| 828 | main.Mininet1.handle.sendline( |
| 829 | "sh tc qdisc add dev s1-eth1 root netem loss 100%") |
| 830 | |
| 831 | #TODO: Iterate through topology count to detect |
| 832 | # link down discovery. Take timestamp and |
| 833 | # gather list for num_iter |
| 834 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 835 | |
| 836 | |
| 837 | |