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. |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 329 | latency_ofp_to_device_list.append(avg_delta_ofp_device) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 330 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 331 | #TODO: |
| 332 | #Fetch logs upon threshold excess |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 333 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 334 | main.log.info("ONOS1 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 335 | str(delta_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 336 | main.log.info("ONOS2 delta end-to-end: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 337 | str(delta_graph_2) + " ms") |
| 338 | main.log.info("ONOS3 delta end-to-end: "+ |
| 339 | str(delta_graph_3) + " ms") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 340 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 341 | main.log.info("ONOS1 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 342 | str(delta_ofp_graph_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 343 | main.log.info("ONOS2 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 344 | str(delta_ofp_graph_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 345 | main.log.info("ONOS3 delta OFP - graph: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 346 | str(delta_ofp_graph_3) + " ms") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 347 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 348 | main.log.info("ONOS1 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 349 | str(delta_device_1) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 350 | main.log.info("ONOS2 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 351 | str(delta_device_2) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 352 | main.log.info("ONOS3 delta device - t0: "+ |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 353 | str(delta_device_3) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 354 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 355 | #main.log.info("ONOS1 delta OFP - device: "+ |
| 356 | # str(delta_ofp_device_1) + " ms") |
| 357 | #main.log.info("ONOS2 delta OFP - device: "+ |
| 358 | # str(delta_ofp_device_2) + " ms") |
| 359 | #main.log.info("ONOS3 delta OFP - device: "+ |
| 360 | # str(delta_ofp_device_3) + " ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 361 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 362 | main.step("Remove switch from controller") |
| 363 | main.Mininet1.delete_sw_controller("s1") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 364 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 365 | time.sleep(5) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 366 | |
andrewonlab | 09d973e | 2014-10-24 18:56:58 -0400 | [diff] [blame] | 367 | #END of for loop iteration |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 368 | |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 369 | #If there is at least 1 element in each list, |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 370 | #pass the test case |
| 371 | if len(latency_end_to_end_list) > 0 and\ |
| 372 | len(latency_ofp_to_graph_list) > 0 and\ |
| 373 | len(latency_ofp_to_device_list) > 0 and\ |
| 374 | len(latency_t0_to_device_list) > 0: |
| 375 | assertion = main.TRUE |
andrewonlab | f47993a | 2014-10-24 17:56:01 -0400 | [diff] [blame] | 376 | elif len(latency_end_to_end_list) == 0: |
| 377 | #The appending of 0 here is to prevent |
| 378 | #the min,max,sum functions from failing |
| 379 | #below |
| 380 | latency_end_to_end_list.append(0) |
| 381 | assertion = main.FALSE |
| 382 | elif len(latency_ofp_to_graph_list) == 0: |
| 383 | latency_ofp_to_graph_list.append(0) |
| 384 | assertion = main.FALSE |
| 385 | elif len(latency_ofp_to_device_list) == 0: |
| 386 | latency_ofp_to_device_list.append(0) |
| 387 | assertion = main.FALSE |
| 388 | elif len(latency_t0_to_device_list) == 0: |
| 389 | latency_t0_to_device_list.append(0) |
| 390 | assertion = main.FALSE |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 391 | |
| 392 | #Calculate min, max, avg of latency lists |
| 393 | latency_end_to_end_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 394 | int(max(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 395 | latency_end_to_end_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 396 | int(min(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 397 | latency_end_to_end_avg = \ |
andrewonlab | c90667c | 2014-10-24 16:48:28 -0400 | [diff] [blame] | 398 | (int(sum(latency_end_to_end_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 399 | len(latency_end_to_end_list)) |
| 400 | |
| 401 | latency_ofp_to_graph_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 402 | int(max(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 403 | latency_ofp_to_graph_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 404 | int(min(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 405 | latency_ofp_to_graph_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 406 | (int(sum(latency_ofp_to_graph_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 407 | len(latency_ofp_to_graph_list)) |
| 408 | |
| 409 | latency_ofp_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 410 | int(max(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 411 | latency_ofp_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 412 | int(min(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 413 | latency_ofp_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 414 | (int(sum(latency_ofp_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 415 | len(latency_ofp_to_device_list)) |
| 416 | |
| 417 | latency_t0_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 418 | float(max(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 419 | latency_t0_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 420 | float(min(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 421 | latency_t0_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 422 | (float(sum(latency_t0_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 423 | len(latency_ofp_to_device_list)) |
| 424 | |
| 425 | main.log.report("Switch add - End-to-end latency: \n"+\ |
| 426 | "Min: "+str(latency_end_to_end_min)+"\n"+\ |
| 427 | "Max: "+str(latency_end_to_end_max)+"\n"+\ |
| 428 | "Avg: "+str(latency_end_to_end_avg)) |
| 429 | main.log.report("Switch add - OFP-to-Graph latency: \n"+\ |
| 430 | "Min: "+str(latency_ofp_to_graph_min)+"\n"+\ |
| 431 | "Max: "+str(latency_ofp_to_graph_max)+"\n"+\ |
| 432 | "Avg: "+str(latency_ofp_to_graph_avg)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 433 | main.log.report("Switch add - t0-to-Device latency: \n"+\ |
| 434 | "Min: "+str(latency_t0_to_device_min)+"\n"+\ |
| 435 | "Max: "+str(latency_t0_to_device_max)+"\n"+\ |
| 436 | "Avg: "+str(latency_t0_to_device_avg)) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 437 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 438 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 439 | onpass="Switch latency test successful", |
| 440 | onfail="Switch latency test failed") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 441 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 442 | def CASE3(self, main): |
| 443 | ''' |
| 444 | Bring port up / down and measure latency. |
| 445 | Port enable / disable is simulated by ifconfig up / down |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 446 | |
| 447 | In ONOS-next, we must ensure that the port we are |
| 448 | manipulating is connected to another switch with a valid |
| 449 | connection. Otherwise, graph view will not be updated. |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 450 | ''' |
| 451 | import time |
| 452 | import subprocess |
| 453 | import os |
| 454 | import requests |
| 455 | import json |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 456 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 457 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 458 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 459 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 460 | ONOS_user = main.params['CTRL']['user'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 461 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 462 | default_sw_port = main.params['CTRL']['port1'] |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 463 | |
| 464 | assertion = main.TRUE |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 465 | #Number of iterations of case |
| 466 | num_iter = main.params['TEST']['numIter'] |
| 467 | |
| 468 | #Timestamp 'keys' for json metrics output. |
| 469 | #These are subject to change, hence moved into params |
| 470 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 471 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 472 | |
| 473 | #NOTE: Some hardcoded variables you may need to configure |
| 474 | # besides the params |
| 475 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 476 | tshark_port_status = "OFP 130 Port Status" |
| 477 | |
| 478 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 479 | tshark_port_down = "/tmp/tshark_port_down.txt" |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 480 | interface_config = "s1-eth1" |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 481 | |
| 482 | main.log.report("Port enable / disable latency") |
| 483 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 484 | main.step("Assign switches s1 and s2 to controller 1") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 485 | main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip, |
| 486 | port1=default_sw_port) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 487 | main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip, |
| 488 | port1=default_sw_port) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 489 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 490 | #Give enough time for metrics to propagate the |
| 491 | #assign controller event. Otherwise, these events may |
| 492 | #carry over to our measurements |
| 493 | time.sleep(10) |
| 494 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 495 | main.step("Verify switch is assigned correctly") |
| 496 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 497 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
| 498 | if result_s1 == main.FALSE or result_s2 == main.FALSE: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 499 | main.log.info("Switch s1 was not assigned correctly") |
| 500 | assertion = main.FALSE |
| 501 | else: |
| 502 | main.log.info("Switch s1 was assigned correctly") |
| 503 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 504 | port_up_device_to_ofp_list = [] |
| 505 | port_up_graph_to_ofp_list = [] |
| 506 | port_down_device_to_ofp_list = [] |
| 507 | port_down_graph_to_ofp_list = [] |
| 508 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 509 | for i in range(0, int(num_iter)): |
| 510 | main.step("Starting wireshark capture for port status down") |
| 511 | main.ONOS1.tshark_grep(tshark_port_status, |
| 512 | tshark_port_down) |
| 513 | |
| 514 | time.sleep(10) |
| 515 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 516 | #Disable interface that is connected to switch 2 |
| 517 | main.step("Disable port: "+interface_config) |
| 518 | main.Mininet2.handle.sendline("sudo ifconfig "+ |
| 519 | interface_config+" down") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 520 | main.Mininet2.handle.expect("\$") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 521 | time.sleep(10) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 522 | |
| 523 | main.ONOS1.tshark_stop() |
| 524 | time.sleep(5) |
| 525 | |
| 526 | #Copy tshark output file from ONOS to TestON instance |
| 527 | #/tmp directory |
| 528 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 529 | tshark_port_down+" /tmp/") |
| 530 | |
| 531 | f_port_down = open(tshark_port_down, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 532 | #Get first line of port down event from tshark |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 533 | f_line = f_port_down.readline() |
| 534 | obj_down = f_line.split(" ") |
| 535 | if len(f_line) > 0: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 536 | timestamp_begin_pt_down = int(float(obj_down[1]))*1000 |
| 537 | main.log.info("Port down begin timestamp: "+ |
| 538 | str(timestamp_begin_pt_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 539 | else: |
| 540 | main.log.info("Tshark output file returned unexpected"+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 541 | " results: "+str(obj_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 542 | timestamp_begin_pt_down = 0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 543 | |
| 544 | f_port_down.close() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 545 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 546 | main.log.info("TEST tshark obj: "+str(obj_down)) |
| 547 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 548 | main.step("Obtain t1 by REST call") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 549 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 550 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 551 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 552 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 553 | main.log.info("TEST json_str 1: "+str(json_str_1)) |
| 554 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 555 | json_obj_1 = json.loads(json_str_1) |
| 556 | json_obj_2 = json.loads(json_str_2) |
| 557 | json_obj_3 = json.loads(json_str_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 558 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 559 | time.sleep(5) |
| 560 | |
| 561 | #Obtain graph timestamp. This timestsamp captures |
| 562 | #the epoch time at which the topology graph was updated. |
| 563 | graph_timestamp_1 = \ |
| 564 | json_obj_1[graphTimestamp]['value'] |
| 565 | graph_timestamp_2 = \ |
| 566 | json_obj_2[graphTimestamp]['value'] |
| 567 | graph_timestamp_3 = \ |
| 568 | json_obj_3[graphTimestamp]['value'] |
| 569 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 570 | #Obtain device timestamp. This timestamp captures |
| 571 | #the epoch time at which the device event happened |
| 572 | device_timestamp_1 = \ |
| 573 | json_obj_1[deviceTimestamp]['value'] |
| 574 | device_timestamp_2 = \ |
| 575 | json_obj_2[deviceTimestamp]['value'] |
| 576 | device_timestamp_3 = \ |
| 577 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 578 | |
| 579 | #Get delta between graph event and OFP |
| 580 | pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
| 581 | int(timestamp_begin_pt_down) |
| 582 | pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
| 583 | int(timestamp_begin_pt_down) |
| 584 | pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 585 | int(timestamp_begin_pt_down) |
| 586 | |
| 587 | #Get delta between device event and OFP |
| 588 | pt_down_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 589 | int(timestamp_begin_pt_down) |
| 590 | pt_down_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 591 | int(timestamp_begin_pt_down) |
| 592 | pt_down_device_to_ofp_3 = int(device_timestamp_3) -\ |
| 593 | int(timestamp_begin_pt_down) |
| 594 | |
| 595 | #Caluclate average across clusters |
| 596 | pt_down_graph_to_ofp_avg =\ |
| 597 | (int(pt_down_graph_to_ofp_1) + |
| 598 | int(pt_down_graph_to_ofp_2) + |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 599 | int(pt_down_graph_to_ofp_3)) / 3.0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 600 | pt_down_device_to_ofp_avg = \ |
| 601 | (int(pt_down_device_to_ofp_1) + |
| 602 | int(pt_down_device_to_ofp_2) + |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 603 | int(pt_down_device_to_ofp_3)) / 3.0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 604 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 605 | if pt_down_graph_to_ofp_avg > 0.0 and \ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 606 | pt_down_graph_to_ofp_avg < 1000: |
| 607 | port_down_graph_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 608 | pt_down_graph_to_ofp_avg) |
| 609 | main.log.info("Port down: graph to ofp avg: "+ |
| 610 | str(pt_down_graph_to_ofp_avg) + " ms") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 611 | else: |
| 612 | main.log.info("Average port down graph-to-ofp result" + |
| 613 | " exceeded the threshold: "+ |
| 614 | str(pt_down_graph_to_ofp_avg)) |
| 615 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 616 | if pt_down_device_to_ofp_avg > 0 and \ |
| 617 | pt_down_device_to_ofp_avg < 1000: |
| 618 | port_down_device_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 619 | pt_down_device_to_ofp_avg) |
| 620 | main.log.info("Port down: device to ofp avg: "+ |
| 621 | str(pt_down_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 622 | else: |
| 623 | main.log.info("Average port down device-to-ofp result" + |
| 624 | " exceeded the threshold: "+ |
| 625 | str(pt_down_device_to_ofp_avg)) |
| 626 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 627 | #Port up events |
| 628 | main.step("Enable port and obtain timestamp") |
| 629 | main.step("Starting wireshark capture for port status up") |
| 630 | main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 631 | time.sleep(5) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 632 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 633 | main.Mininet2.handle.sendline("sudo ifconfig "+ |
| 634 | interface_config+" up") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 635 | main.Mininet2.handle.expect("\$") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 636 | time.sleep(10) |
| 637 | |
| 638 | main.ONOS1.tshark_stop() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 639 | |
| 640 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 641 | tshark_port_up+" /tmp/") |
| 642 | |
| 643 | f_port_up = open(tshark_port_up, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 644 | f_line = f_port_up.readline() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 645 | obj_up = f_line.split(" ") |
| 646 | if len(f_line) > 0: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 647 | timestamp_begin_pt_up = int(float(obj_up[1]))*1000 |
| 648 | main.log.info("Port up begin timestamp: "+ |
| 649 | str(timestamp_begin_pt_up)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 650 | else: |
| 651 | main.log.info("Tshark output file returned unexpected"+ |
| 652 | " results.") |
| 653 | timestamp_begin_pt_up = 0 |
| 654 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 655 | f_port_up.close() |
| 656 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 657 | main.step("Obtain t1 by REST call") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 658 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 659 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 660 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 661 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 662 | json_obj_1 = json.loads(json_str_1) |
| 663 | json_obj_2 = json.loads(json_str_2) |
| 664 | json_obj_3 = json.loads(json_str_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 665 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 666 | #Obtain graph timestamp. This timestsamp captures |
| 667 | #the epoch time at which the topology graph was updated. |
| 668 | graph_timestamp_1 = \ |
| 669 | json_obj_1[graphTimestamp]['value'] |
| 670 | graph_timestamp_2 = \ |
| 671 | json_obj_2[graphTimestamp]['value'] |
| 672 | graph_timestamp_3 = \ |
| 673 | json_obj_3[graphTimestamp]['value'] |
| 674 | |
| 675 | #Obtain device timestamp. This timestamp captures |
| 676 | #the epoch time at which the device event happened |
| 677 | device_timestamp_1 = \ |
| 678 | json_obj_1[deviceTimestamp]['value'] |
| 679 | device_timestamp_2 = \ |
| 680 | json_obj_2[deviceTimestamp]['value'] |
| 681 | device_timestamp_3 = \ |
| 682 | json_obj_3[deviceTimestamp]['value'] |
| 683 | |
| 684 | #Get delta between graph event and OFP |
| 685 | pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 686 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 687 | pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 688 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 689 | pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 690 | int(timestamp_begin_pt_up) |
| 691 | |
| 692 | #Get delta between device event and OFP |
| 693 | pt_up_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 694 | int(timestamp_begin_pt_up) |
| 695 | pt_up_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 696 | int(timestamp_begin_pt_up) |
| 697 | pt_up_device_to_ofp_3 = int(device_timestamp_3) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 698 | int(timestamp_begin_pt_up) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 699 | |
| 700 | pt_up_graph_to_ofp_avg = \ |
| 701 | (float(pt_up_graph_to_ofp_1) + |
| 702 | float(pt_up_graph_to_ofp_2) + |
| 703 | float(pt_up_graph_to_ofp_3)) / 3 |
| 704 | |
| 705 | pt_up_device_to_ofp_avg = \ |
| 706 | (float(pt_up_device_to_ofp_1) + |
| 707 | float(pt_up_device_to_ofp_2) + |
| 708 | float(pt_up_device_to_ofp_3)) / 3 |
| 709 | |
| 710 | if pt_up_graph_to_ofp_avg > 0 and \ |
| 711 | pt_up_graph_to_ofp_avg < 1000: |
| 712 | port_up_graph_to_ofp_list.append( |
| 713 | pt_up_graph_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 714 | main.log.info("Port down: graph to ofp avg: "+ |
| 715 | str(pt_up_graph_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 716 | else: |
| 717 | main.log.info("Average port up graph-to-ofp result"+ |
| 718 | " exceeded the threshold: "+ |
| 719 | str(pt_up_graph_to_ofp_avg)) |
| 720 | |
| 721 | if pt_up_device_to_ofp_avg > 0 and \ |
| 722 | pt_up_device_to_ofp_avg < 1000: |
| 723 | port_up_device_to_ofp_list.append( |
| 724 | pt_up_device_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 725 | main.log.info("Port up: device to ofp avg: "+ |
| 726 | str(pt_up_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 727 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 728 | main.log.info("Average port up device-to-ofp result"+ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 729 | " exceeded the threshold: "+ |
| 730 | str(pt_up_device_to_ofp_avg)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 731 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 732 | #END ITERATION FOR LOOP |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 733 | |
| 734 | #Check all list for latency existence and set assertion |
| 735 | if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\ |
| 736 | and port_up_graph_to_ofp_list and port_up_device_to_ofp_list): |
| 737 | assertion = main.TRUE |
| 738 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 739 | #Calculate and report latency measurements |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 740 | port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list) |
| 741 | port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list) |
| 742 | port_down_graph_to_ofp_avg = \ |
| 743 | (sum(port_down_graph_to_ofp_list) / |
| 744 | len(port_down_graph_to_ofp_list)) |
| 745 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 746 | main.log.report("Port down graph-to-ofp Min: "+ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 747 | str(port_down_graph_to_ofp_min)+" ms Max: "+ |
| 748 | str(port_down_graph_to_ofp_max)+" ms Avg: "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 749 | str(port_down_graph_to_ofp_avg)) |
| 750 | |
| 751 | port_down_device_to_ofp_min = min(port_down_device_to_ofp_list) |
| 752 | port_down_device_to_ofp_max = max(port_down_device_to_ofp_list) |
| 753 | port_down_device_to_ofp_avg = \ |
| 754 | (sum(port_down_device_to_ofp_list) /\ |
| 755 | len(port_down_device_to_ofp_list)) |
| 756 | |
| 757 | main.log.report("Port down device-to-ofp Min: "+ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 758 | str(port_down_device_to_ofp_min)+" ms Max: "+ |
| 759 | str(port_down_device_to_ofp_max)+" ms Avg: "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 760 | str(port_down_device_to_ofp_avg)) |
| 761 | |
| 762 | port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list) |
| 763 | port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list) |
| 764 | port_up_graph_to_ofp_avg = \ |
| 765 | (sum(port_up_graph_to_ofp_list) /\ |
| 766 | len(port_up_graph_to_ofp_list)) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 767 | |
| 768 | main.log.report("Port up graph-to-ofp Min: "+ |
| 769 | str(port_up_graph_to_ofp_min)+" ms Max: "+ |
| 770 | str(port_up_graph_to_ofp_max)+" ms Avg: "+ |
| 771 | str(port_up_graph_to_ofp_avg)) |
| 772 | |
| 773 | port_up_device_to_ofp_min = min(port_up_device_to_ofp_list) |
| 774 | port_up_device_to_ofp_max = max(port_up_device_to_ofp_list) |
| 775 | port_up_device_to_ofp_avg = \ |
| 776 | (sum(port_up_device_to_ofp_list) /\ |
| 777 | len(port_up_device_to_ofp_list)) |
| 778 | |
| 779 | main.log.report("Port up device-to-ofp Min: "+ |
| 780 | str(port_up_device_to_ofp_min)+" ms Max: "+ |
| 781 | str(port_up_device_to_ofp_max)+" ms Avg: "+ |
| 782 | str(port_up_device_to_ofp_avg)) |
| 783 | |
| 784 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 785 | onpass="Port discovery latency calculation successful", |
| 786 | onfail="Port discovery test failed") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 787 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 788 | def CASE4(self, main): |
| 789 | ''' |
| 790 | Link down event using loss rate 100% |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 791 | |
| 792 | Important: |
| 793 | Use a simple 2 switch topology with 1 link between |
| 794 | the two switches. Ensure that mac addresses of the |
| 795 | switches are 1 / 2 respectively |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 796 | ''' |
| 797 | import time |
| 798 | import subprocess |
| 799 | import os |
| 800 | import requests |
| 801 | import json |
| 802 | |
| 803 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 804 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 805 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 806 | ONOS_user = main.params['CTRL']['user'] |
| 807 | |
| 808 | default_sw_port = main.params['CTRL']['port1'] |
| 809 | |
| 810 | #Number of iterations of case |
| 811 | num_iter = main.params['TEST']['numIter'] |
| 812 | |
| 813 | #Timestamp 'keys' for json metrics output. |
| 814 | #These are subject to change, hence moved into params |
| 815 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 816 | linkTimestamp = main.params['JSON']['linkTimestamp'] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 817 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 818 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 819 | assertion = main.TRUE |
| 820 | #Link event timestamp to system time list |
| 821 | link_down_link_to_system_list = [] |
| 822 | link_up_link_to_system_list = [] |
| 823 | #Graph event timestamp to system time list |
| 824 | link_down_graph_to_system_list = [] |
| 825 | link_up_graph_to_system_list = [] |
| 826 | |
| 827 | main.log.report("Add / remove link latency between "+ |
| 828 | "two switches") |
| 829 | |
| 830 | main.step("Assign all switches") |
| 831 | main.Mininet1.assign_sw_controller(sw="1", |
| 832 | ip1=ONOS1_ip, port1=default_sw_port) |
| 833 | main.Mininet1.assign_sw_controller(sw="2", |
| 834 | ip1=ONOS1_ip, port1=default_sw_port) |
| 835 | |
| 836 | main.step("Verifying switch assignment") |
| 837 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
| 838 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 839 | |
| 840 | #Allow time for events to finish before taking measurements |
| 841 | time.sleep(10) |
| 842 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 843 | link_down1 = False |
| 844 | link_down2 = False |
| 845 | link_down3 = False |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 846 | #Start iteration of link event test |
| 847 | for i in range(0, int(num_iter)): |
| 848 | main.step("Getting initial system time as t0") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 849 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 850 | timestamp_link_down_t0 = time.time() * 1000 |
| 851 | #Link down is simulated by 100% loss rate using traffic |
| 852 | #control command |
| 853 | main.Mininet1.handle.sendline( |
| 854 | "sh tc qdisc add dev s1-eth1 root netem loss 100%") |
| 855 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 856 | #TODO: Iterate through 'links' command to verify that |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 857 | # link s1 -> s2 went down (loop timeout 30 seconds) |
| 858 | # on all 3 ONOS instances |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 859 | main.log.info("Checking ONOS for link update") |
| 860 | loop_count = 0 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 861 | while( not (link_down1 and link_down2 and link_down3)\ |
| 862 | and loop_count < 30 ): |
| 863 | json_str1 = main.ONOS1cli.links() |
| 864 | json_str2 = main.ONOS2cli.links() |
| 865 | json_str3 = main.ONOS3cli.links() |
| 866 | |
| 867 | if not (json_str1 and json_str2 and json_str3): |
| 868 | main.log.error("CLI command returned error ") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 869 | break |
| 870 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 871 | json_obj1 = json.loads(json_str1) |
| 872 | json_obj2 = json.loads(json_str2) |
| 873 | json_obj3 = json.loads(json_str3) |
| 874 | for obj1 in json_obj1: |
| 875 | if '01' not in obj1['src']['device']: |
| 876 | link_down1 = True |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 877 | main.log.report("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 878 | "s1 -> s2 on ONOS1 detected") |
| 879 | for obj2 in json_obj2: |
| 880 | if '01' not in obj2['src']['device']: |
| 881 | link_down2 = True |
| 882 | main.log.report("Link down from "+ |
| 883 | "s1 -> s2 on ONOS2 detected") |
| 884 | for obj3 in json_obj3: |
| 885 | if '01' not in obj3['src']['device']: |
| 886 | link_down3 = True |
| 887 | main.log.report("Link down from "+ |
| 888 | "s1 -> s2 on ONOS3 detected") |
| 889 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 890 | loop_count += 1 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 891 | #If CLI doesn't like the continuous requests |
| 892 | #and exits in this loop, increase the sleep here. |
| 893 | #Consequently, while loop timeout will increase |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 894 | time.sleep(1) |
| 895 | |
| 896 | #Give time for metrics measurement to catch up |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 897 | #NOTE: May need to be configured more accurately |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 898 | time.sleep(10) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 899 | #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] | 900 | #false, then ONOS has failed to discover link down event |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 901 | if not (link_down1 and link_down2 and link_down3): |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 902 | main.log.info("Link down discovery failed") |
| 903 | |
| 904 | link_down_lat_graph1 = 0 |
| 905 | link_down_lat_graph2 = 0 |
| 906 | link_down_lat_graph3 = 0 |
| 907 | link_down_lat_device1 = 0 |
| 908 | link_down_lat_device2 = 0 |
| 909 | link_down_lat_device3 = 0 |
| 910 | |
| 911 | assertion = main.FALSE |
| 912 | else: |
| 913 | json_topo_metrics_1 =\ |
| 914 | main.ONOS1cli.topology_events_metrics() |
| 915 | json_topo_metrics_2 =\ |
| 916 | main.ONOS2cli.topology_events_metrics() |
| 917 | json_topo_metrics_3 =\ |
| 918 | main.ONOS3cli.topology_events_metrics() |
| 919 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 920 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 921 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 922 | |
| 923 | main.log.info("Obtaining graph and device timestamp") |
| 924 | graph_timestamp_1 = \ |
| 925 | json_topo_metrics_1[graphTimestamp]['value'] |
| 926 | graph_timestamp_2 = \ |
| 927 | json_topo_metrics_2[graphTimestamp]['value'] |
| 928 | graph_timestamp_3 = \ |
| 929 | json_topo_metrics_3[graphTimestamp]['value'] |
| 930 | |
| 931 | link_timestamp_1 = \ |
| 932 | json_topo_metrics_1[linkTimestamp]['value'] |
| 933 | link_timestamp_2 = \ |
| 934 | json_topo_metrics_2[linkTimestamp]['value'] |
| 935 | link_timestamp_3 = \ |
| 936 | json_topo_metrics_3[linkTimestamp]['value'] |
| 937 | |
| 938 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 939 | graph_timestamp_3 and link_timestamp_1 and\ |
| 940 | link_timestamp_2 and link_timestamp_3: |
| 941 | link_down_lat_graph1 = int(graph_timestamp_1) -\ |
| 942 | timestamp_link_down_t0 |
| 943 | link_down_lat_graph2 = int(graph_timestamp_2) -\ |
| 944 | timestamp_link_down_t0 |
| 945 | link_down_lat_graph3 = int(graph_timestamp_3) -\ |
| 946 | timestamp_link_down_t0 |
| 947 | |
| 948 | link_down_lat_link1 = int(link_timestamp_1) -\ |
| 949 | timestamp_link_down_t0 |
| 950 | link_down_lat_link2 = int(link_timestamp_2) -\ |
| 951 | timestamp_link_down_t0 |
| 952 | link_down_lat_link3 = int(link_timestamp_3) -\ |
| 953 | timestamp_link_down_t0 |
| 954 | else: |
| 955 | main.log.error("There was an error calculating"+ |
| 956 | " the delta for link down event") |
| 957 | link_down_lat_graph1 = 0 |
| 958 | link_down_lat_graph2 = 0 |
| 959 | link_down_lat_graph3 = 0 |
| 960 | |
| 961 | link_down_lat_device1 = 0 |
| 962 | link_down_lat_device2 = 0 |
| 963 | link_down_lat_device3 = 0 |
| 964 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 965 | main.log.report("Link down latency ONOS1 iteration "+ |
| 966 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 967 | str(link_down_lat_graph1)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 968 | main.log.report("Link down latency ONOS2 iteration "+ |
| 969 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 970 | str(link_down_lat_graph2)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 971 | main.log.report("Link down latency ONOS3 iteration "+ |
| 972 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 973 | str(link_down_lat_graph3)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 974 | |
| 975 | main.log.report("Link down latency ONOS1 iteration "+ |
| 976 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 977 | str(link_down_lat_link1)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 978 | main.log.report("Link down latency ONOS2 iteration "+ |
| 979 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 980 | str(link_down_lat_link2)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 981 | main.log.report("Link down latency ONOS3 iteration "+ |
| 982 | str(i)+" (link-event-to-system-timestamp): "+ |
| 983 | str(link_down_lat_link3)) |
| 984 | |
| 985 | #Calculate avg of node calculations |
| 986 | link_down_lat_graph_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 987 | (link_down_lat_graph1 + |
| 988 | link_down_lat_graph2 + |
| 989 | link_down_lat_graph3) / 3.0 |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 990 | link_down_lat_link_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 991 | (link_down_lat_link1 + |
| 992 | link_down_lat_link2 + |
| 993 | link_down_lat_link3) / 3.0 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 994 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 995 | #Set threshold and append latency to list |
| 996 | if link_down_lat_graph_avg > 0.0 and\ |
| 997 | link_down_lat_graph_avg < 30000: |
| 998 | link_down_graph_to_system_list.append( |
| 999 | link_down_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1000 | else: |
| 1001 | main.log.info("Link down latency exceeded threshold") |
| 1002 | main.log.info("Results for iteration "+str(i)+ |
| 1003 | "have been omitted") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1004 | if link_down_lat_link_avg > 0.0 and\ |
| 1005 | link_down_lat_link_avg < 30000: |
| 1006 | link_down_link_to_system_list.append( |
| 1007 | link_down_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1008 | else: |
| 1009 | main.log.info("Link down latency exceeded threshold") |
| 1010 | main.log.info("Results for iteration "+str(i)+ |
| 1011 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1012 | |
| 1013 | #NOTE: To remove loss rate and measure latency: |
| 1014 | # 'sh tc qdisc del dev s1-eth1 root' |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1015 | timestamp_link_up_t0 = time.time() * 1000 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1016 | main.Mininet1.handle.sendline("sh tc qdisc del dev "+ |
| 1017 | "s1-eth1 root") |
| 1018 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1019 | |
| 1020 | main.log.info("Checking ONOS for link update") |
| 1021 | |
| 1022 | link_down1 = True |
| 1023 | link_down2 = True |
| 1024 | link_down3 = True |
| 1025 | loop_count = 0 |
| 1026 | while( (link_down1 and link_down2 and link_down3)\ |
| 1027 | and loop_count < 30 ): |
| 1028 | json_str1 = main.ONOS1cli.links() |
| 1029 | json_str2 = main.ONOS2cli.links() |
| 1030 | json_str3 = main.ONOS3cli.links() |
| 1031 | if not (json_str1 and json_str2 and json_str3): |
| 1032 | main.log.error("CLI command returned error ") |
| 1033 | break |
| 1034 | else: |
| 1035 | json_obj1 = json.loads(json_str1) |
| 1036 | json_obj2 = json.loads(json_str2) |
| 1037 | json_obj3 = json.loads(json_str3) |
| 1038 | |
| 1039 | for obj1 in json_obj1: |
| 1040 | if '01' in obj1['src']['device']: |
| 1041 | link_down1 = False |
| 1042 | main.log.report("Link up from "+ |
| 1043 | "s1 -> s2 on ONOS1 detected") |
| 1044 | for obj2 in json_obj2: |
| 1045 | if '01' in obj2['src']['device']: |
| 1046 | link_down2 = False |
| 1047 | main.log.report("Link up from "+ |
| 1048 | "s1 -> s2 on ONOS2 detected") |
| 1049 | for obj3 in json_obj3: |
| 1050 | if '01' in obj3['src']['device']: |
| 1051 | link_down3 = False |
| 1052 | main.log.report("Link up from "+ |
| 1053 | "s1 -> s2 on ONOS3 detected") |
| 1054 | |
| 1055 | loop_count += 1 |
| 1056 | time.sleep(1) |
| 1057 | |
| 1058 | if (link_down1 and link_down2 and link_down3): |
| 1059 | main.log.info("Link up discovery failed") |
| 1060 | |
| 1061 | link_up_lat_graph1 = 0 |
| 1062 | link_up_lat_graph2 = 0 |
| 1063 | link_up_lat_graph3 = 0 |
| 1064 | link_up_lat_device1 = 0 |
| 1065 | link_up_lat_device2 = 0 |
| 1066 | link_up_lat_device3 = 0 |
| 1067 | |
| 1068 | assertion = main.FALSE |
| 1069 | else: |
| 1070 | json_topo_metrics_1 =\ |
| 1071 | main.ONOS1cli.topology_events_metrics() |
| 1072 | json_topo_metrics_2 =\ |
| 1073 | main.ONOS2cli.topology_events_metrics() |
| 1074 | json_topo_metrics_3 =\ |
| 1075 | main.ONOS3cli.topology_events_metrics() |
| 1076 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 1077 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 1078 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 1079 | |
| 1080 | main.log.info("Obtaining graph and device timestamp") |
| 1081 | graph_timestamp_1 = \ |
| 1082 | json_topo_metrics_1[graphTimestamp]['value'] |
| 1083 | graph_timestamp_2 = \ |
| 1084 | json_topo_metrics_2[graphTimestamp]['value'] |
| 1085 | graph_timestamp_3 = \ |
| 1086 | json_topo_metrics_3[graphTimestamp]['value'] |
| 1087 | |
| 1088 | link_timestamp_1 = \ |
| 1089 | json_topo_metrics_1[linkTimestamp]['value'] |
| 1090 | link_timestamp_2 = \ |
| 1091 | json_topo_metrics_2[linkTimestamp]['value'] |
| 1092 | link_timestamp_3 = \ |
| 1093 | json_topo_metrics_3[linkTimestamp]['value'] |
| 1094 | |
| 1095 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 1096 | graph_timestamp_3 and link_timestamp_1 and\ |
| 1097 | link_timestamp_2 and link_timestamp_3: |
| 1098 | link_up_lat_graph1 = int(graph_timestamp_1) -\ |
| 1099 | timestamp_link_up_t0 |
| 1100 | link_up_lat_graph2 = int(graph_timestamp_2) -\ |
| 1101 | timestamp_link_up_t0 |
| 1102 | link_up_lat_graph3 = int(graph_timestamp_3) -\ |
| 1103 | timestamp_link_up_t0 |
| 1104 | |
| 1105 | link_up_lat_link1 = int(link_timestamp_1) -\ |
| 1106 | timestamp_link_up_t0 |
| 1107 | link_up_lat_link2 = int(link_timestamp_2) -\ |
| 1108 | timestamp_link_up_t0 |
| 1109 | link_up_lat_link3 = int(link_timestamp_3) -\ |
| 1110 | timestamp_link_up_t0 |
| 1111 | else: |
| 1112 | main.log.error("There was an error calculating"+ |
| 1113 | " the delta for link down event") |
| 1114 | link_up_lat_graph1 = 0 |
| 1115 | link_up_lat_graph2 = 0 |
| 1116 | link_up_lat_graph3 = 0 |
| 1117 | |
| 1118 | link_up_lat_device1 = 0 |
| 1119 | link_up_lat_device2 = 0 |
| 1120 | link_up_lat_device3 = 0 |
| 1121 | |
| 1122 | main.log.info("Link up latency ONOS1 iteration "+ |
| 1123 | str(i)+" (end-to-end): "+ |
| 1124 | str(link_up_lat_graph1)+" ms") |
| 1125 | main.log.info("Link up latency ONOS2 iteration "+ |
| 1126 | str(i)+" (end-to-end): "+ |
| 1127 | str(link_up_lat_graph2)+" ms") |
| 1128 | main.log.info("Link up latency ONOS3 iteration "+ |
| 1129 | str(i)+" (end-to-end): "+ |
| 1130 | str(link_up_lat_graph3)+" ms") |
| 1131 | |
| 1132 | main.log.info("Link up latency ONOS1 iteration "+ |
| 1133 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1134 | str(link_up_lat_link1)+" ms") |
| 1135 | main.log.info("Link up latency ONOS2 iteration "+ |
| 1136 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1137 | str(link_up_lat_link2)+" ms") |
| 1138 | main.log.info("Link up latency ONOS3 iteration "+ |
| 1139 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1140 | str(link_up_lat_link3)) |
| 1141 | |
| 1142 | #Calculate avg of node calculations |
| 1143 | link_up_lat_graph_avg =\ |
| 1144 | (link_up_lat_graph1 + |
| 1145 | link_up_lat_graph2 + |
| 1146 | link_up_lat_graph3) / 3.0 |
| 1147 | link_up_lat_link_avg =\ |
| 1148 | (link_up_lat_link1 + |
| 1149 | link_up_lat_link2 + |
| 1150 | link_up_lat_link3) / 3.0 |
| 1151 | |
| 1152 | #Set threshold and append latency to list |
| 1153 | if link_up_lat_graph_avg > 0.0 and\ |
| 1154 | link_up_lat_graph_avg < 30000: |
| 1155 | link_up_graph_to_system_list.append( |
| 1156 | link_up_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1157 | else: |
| 1158 | main.log.info("Link up latency exceeded threshold") |
| 1159 | main.log.info("Results for iteration "+str(i)+ |
| 1160 | "have been omitted") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1161 | if link_up_lat_link_avg > 0.0 and\ |
| 1162 | link_up_lat_link_avg < 30000: |
| 1163 | link_up_link_to_system_list.append( |
| 1164 | link_up_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1165 | else: |
| 1166 | main.log.info("Link up latency exceeded threshold") |
| 1167 | main.log.info("Results for iteration "+str(i)+ |
| 1168 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1169 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1170 | #Calculate min, max, avg of list and report |
| 1171 | link_down_min = min(link_down_graph_to_system_list) |
| 1172 | link_down_max = max(link_down_graph_to_system_list) |
| 1173 | link_down_avg = sum(link_down_graph_to_system_list) / \ |
| 1174 | len(link_down_graph_to_system_list) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1175 | link_up_min = min(link_up_graph_to_system_list) |
| 1176 | link_up_max = max(link_up_graph_to_system_list) |
| 1177 | link_up_avg = sum(link_up_graph_to_system_list) / \ |
| 1178 | len(link_up_graph_to_system_list) |
| 1179 | |
| 1180 | main.log.report("Link down latency - Min: "+ |
| 1181 | str(link_down_min)+"ms Max: "+ |
| 1182 | str(link_down_max)+"ms Avg: "+ |
| 1183 | str(link_down_avg)+"ms") |
| 1184 | main.log.report("Link up latency - Min: "+ |
| 1185 | str(link_up_min)+"ms Max: "+ |
| 1186 | str(link_up_max)+"ms Avg: "+ |
| 1187 | str(link_up_avg)+"ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1188 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1189 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 1190 | onpass="Link discovery latency calculation successful", |
| 1191 | onfail="Link discovery latency case failed") |
| 1192 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1193 | def CASE5(self, main): |
| 1194 | ''' |
| 1195 | 100 Switch discovery latency |
| 1196 | |
| 1197 | Important: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1198 | This test case can be potentially dangerous if |
| 1199 | your machine has previously set iptables rules. |
| 1200 | One of the steps of the test case will flush |
| 1201 | all existing iptables rules. |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1202 | Note: |
| 1203 | You can specify the number of switches in the |
| 1204 | params file to adjust the switch discovery size |
| 1205 | (and specify the corresponding topology in Mininet1 |
| 1206 | .topo file) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1207 | ''' |
| 1208 | import time |
| 1209 | import subprocess |
| 1210 | import os |
| 1211 | import requests |
| 1212 | import json |
| 1213 | |
| 1214 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 1215 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 1216 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 1217 | MN1_ip = main.params['MN']['ip1'] |
| 1218 | ONOS_user = main.params['CTRL']['user'] |
| 1219 | |
| 1220 | default_sw_port = main.params['CTRL']['port1'] |
| 1221 | |
| 1222 | #Number of iterations of case |
| 1223 | num_iter = main.params['TEST']['numIter'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1224 | num_sw = main.params['TEST']['numSwitch'] |
| 1225 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1226 | #Timestamp 'keys' for json metrics output. |
| 1227 | #These are subject to change, hence moved into params |
| 1228 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1229 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 1230 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1231 | tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt" |
| 1232 | tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt" |
| 1233 | |
| 1234 | tshark_ofp_result_list = [] |
| 1235 | tshark_tcp_result_list = [] |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1236 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1237 | main.case(num_sw+" Switch discovery latency") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1238 | main.step("Assigning all switches to ONOS1") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1239 | for i in range(1, int(num_sw)+1): |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1240 | main.Mininet1.assign_sw_controller( |
| 1241 | sw=str(i), |
| 1242 | ip1=ONOS1_ip, |
| 1243 | port1=default_sw_port) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1244 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1245 | #Ensure that nodes are configured with ptpd |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1246 | #Just a warning message |
| 1247 | main.log.info("Please check ptpd configuration to ensure"+\ |
| 1248 | " All nodes' system times are in sync") |
| 1249 | time.sleep(5) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1250 | |
| 1251 | for i in range(0, int(num_iter)): |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 1252 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1253 | main.step("Set iptables rule to block incoming sw connections") |
| 1254 | #Set iptables rule to block incoming switch connections |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1255 | #The rule description is as follows: |
| 1256 | # Append to INPUT rule, |
| 1257 | # behavior DROP that matches following: |
| 1258 | # * packet type: tcp |
| 1259 | # * source IP: MN1_ip |
| 1260 | # * destination PORT: 6633 |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1261 | main.ONOS1.handle.sendline( |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1262 | "sudo iptables -A INPUT -p tcp -s "+MN1_ip+ |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1263 | " --dport "+default_sw_port+" -j DROP") |
| 1264 | main.ONOS1.handle.expect("\$") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1265 | # Append to OUTPUT rule, |
| 1266 | # behavior DROP that matches following: |
| 1267 | # * packet type: tcp |
| 1268 | # * source IP: MN1_ip |
| 1269 | # * destination PORT: 6633 |
| 1270 | main.ONOS1.handle.sendline( |
| 1271 | "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+ |
| 1272 | " --dport "+default_sw_port+" -j DROP") |
| 1273 | main.ONOS1.handle.expect("\$") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1274 | #Give time to allow rule to take effect |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1275 | #NOTE: Sleep period may need to be configured |
| 1276 | # based on the number of switches in the topology |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1277 | main.log.info("Please wait for switch connection to "+ |
| 1278 | "time out") |
| 1279 | time.sleep(60) |
| 1280 | |
| 1281 | #Gather vendor OFP with tshark |
| 1282 | main.ONOS1.tshark_grep("OFP 86 Vendor", |
| 1283 | tshark_ofp_output) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1284 | main.ONOS1.tshark_grep("TCP 74 ", |
| 1285 | tshark_tcp_output) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1286 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1287 | #NOTE: Remove all iptables rule quickly (flush) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1288 | # Before removal, obtain TestON timestamp at which |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1289 | # removal took place |
| 1290 | # (ensuring nodes are configured via ptp) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1291 | # sudo iptables -F |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1292 | |
| 1293 | t0_system = time.time() * 1000 |
| 1294 | main.ONOS1.handle.sendline( |
| 1295 | "sudo iptables -F") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1296 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1297 | #Counter to track loop count |
| 1298 | counter_loop = 0 |
| 1299 | counter_avail1 = 0 |
| 1300 | counter_avail2 = 0 |
| 1301 | counter_avail3 = 0 |
| 1302 | onos1_dev = False |
| 1303 | onos2_dev = False |
| 1304 | onos3_dev = False |
| 1305 | while counter_loop < 60: |
| 1306 | #Continue to check devices for all device |
| 1307 | #availability. When all devices in all 3 |
| 1308 | #ONOS instances indicate that devices are available |
| 1309 | #obtain graph event timestamp for t1. |
| 1310 | device_str_obj1 = main.ONOS1cli.devices() |
| 1311 | device_str_obj2 = main.ONOS2cli.devices() |
| 1312 | device_str_obj3 = main.ONOS3cli.devices() |
| 1313 | |
| 1314 | device_json1 = json.loads(device_str_obj1) |
| 1315 | device_json2 = json.loads(device_str_obj2) |
| 1316 | device_json3 = json.loads(device_str_obj3) |
| 1317 | |
| 1318 | for device1 in device_json1: |
| 1319 | if device1['available'] == True: |
| 1320 | counter_avail1 += 1 |
| 1321 | if counter_avail1 == int(num_sw): |
| 1322 | onos1_dev = True |
| 1323 | main.log.info("All devices have been "+ |
| 1324 | "discovered on ONOS1") |
| 1325 | else: |
| 1326 | counter_avail1 = 0 |
| 1327 | for device2 in device_json2: |
| 1328 | if device2['available'] == True: |
| 1329 | counter_avail2 += 1 |
| 1330 | if counter_avail2 == int(num_sw): |
| 1331 | onos2_dev = True |
| 1332 | main.log.info("All devices have been "+ |
| 1333 | "discovered on ONOS2") |
| 1334 | else: |
| 1335 | counter_avail2 = 0 |
| 1336 | for device3 in device_json3: |
| 1337 | if device3['available'] == True: |
| 1338 | counter_avail3 += 1 |
| 1339 | if counter_avail3 == int(num_sw): |
| 1340 | onos3_dev = True |
| 1341 | main.log.info("All devices have been "+ |
| 1342 | "discovered on ONOS3") |
| 1343 | else: |
| 1344 | counter_avail3 = 0 |
| 1345 | |
| 1346 | if onos1_dev and onos2_dev and onos3_dev: |
| 1347 | main.log.info("All devices have been discovered "+ |
| 1348 | "on all ONOS instances") |
| 1349 | json_str_topology_metrics_1 =\ |
| 1350 | main.ONOS1cli.topology_events_metrics() |
| 1351 | json_str_topology_metrics_2 =\ |
| 1352 | main.ONOS2cli.topology_events_metrics() |
| 1353 | json_str_topology_metrics_3 =\ |
| 1354 | main.ONOS3cli.topology_events_metrics() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1355 | |
| 1356 | #Exit while loop if all devices discovered |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1357 | break |
| 1358 | |
| 1359 | counter_loop += 1 |
| 1360 | #Give some time in between CLI calls |
| 1361 | #(will not affect measurement) |
| 1362 | time.sleep(3) |
| 1363 | |
| 1364 | main.ONOS1.tshark_stop() |
| 1365 | |
| 1366 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1367 | tshark_ofp_output+" /tmp/") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1368 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1369 | tshark_tcp_output+" /tmp/") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1370 | ofp_file = open(tshark_ofp_output, 'r') |
| 1371 | |
| 1372 | #The following is for information purpose only. |
| 1373 | #TODO: Automate OFP output analysis |
| 1374 | main.log.info("Tshark OFP Vendor output: ") |
| 1375 | for line in ofp_file: |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1376 | tshark_ofp_result_list.append(line) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1377 | main.log.info(line) |
| 1378 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1379 | ofp_file.close() |
| 1380 | |
| 1381 | tcp_file = open(tshark_tcp_output, 'r') |
| 1382 | main.log.info("Tshark TCP 74 output: ") |
| 1383 | for line in tcp_file: |
| 1384 | tshark_tcp_result_list.append(line) |
| 1385 | main.log.info(line) |
| 1386 | |
| 1387 | tcp_file.close() |
| 1388 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1389 | json_obj_1 = json.loads(json_str_topology_metrics_1) |
| 1390 | json_obj_2 = json.loads(json_str_topology_metrics_2) |
| 1391 | json_obj_3 = json.loads(json_str_topology_metrics_3) |
| 1392 | |
| 1393 | graph_timestamp_1 = \ |
| 1394 | json_obj_1[graphTimestamp]['value'] |
| 1395 | graph_timestamp_2 = \ |
| 1396 | json_obj_2[graphTimestamp]['value'] |
| 1397 | graph_timestamp_3 = \ |
| 1398 | json_obj_3[graphTimestamp]['value'] |
| 1399 | |
| 1400 | main.log.info( |
| 1401 | int(graph_timestamp_1) - int(t0_system)) |
| 1402 | main.log.info( |
| 1403 | int(graph_timestamp_2) - int(t0_system)) |
| 1404 | main.log.info( |
| 1405 | int(graph_timestamp_3) - int(t0_system)) |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1412 | |