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