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 | |
| 82 | if not (cli1 and cli2 and cli3): |
| 83 | main.log.info("Attempting to start cli again") |
| 84 | cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip) |
| 85 | cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip) |
| 86 | cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 87 | |
| 88 | main.step("Enable metrics feature") |
| 89 | main.ONOS1cli.feature_install("onos-app-metrics-topology") |
| 90 | main.ONOS2cli.feature_install("onos-app-metrics-topology") |
| 91 | main.ONOS3cli.feature_install("onos-app-metrics-topology") |
| 92 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 93 | utilities.assert_equals(expect=main.TRUE, |
| 94 | actual= cell_file_result and cell_apply_result and\ |
| 95 | verify_cell_result and checkout_result and\ |
| 96 | pull_result and mvn_result and\ |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 97 | install1_result and install2_result and\ |
| 98 | install3_result, |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 99 | onpass="ONOS started successfully", |
| 100 | onfail="Failed to start ONOS") |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 101 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 102 | def CASE2(self, main): |
| 103 | ''' |
| 104 | Assign s1 to ONOS1 and measure latency |
| 105 | ''' |
| 106 | import time |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 107 | import subprocess |
| 108 | import json |
| 109 | import requests |
| 110 | import os |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 111 | |
| 112 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 113 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 114 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 115 | ONOS_user = main.params['CTRL']['user'] |
| 116 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 117 | default_sw_port = main.params['CTRL']['port1'] |
| 118 | |
| 119 | #Number of iterations of case |
| 120 | num_iter = main.params['TEST']['numIter'] |
| 121 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 122 | #Timestamp 'keys' for json metrics output. |
| 123 | #These are subject to change, hence moved into params |
| 124 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 125 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
| 126 | |
| 127 | #List of switch add latency collected from |
| 128 | #all iterations |
| 129 | latency_end_to_end_list = [] |
| 130 | latency_ofp_to_graph_list = [] |
| 131 | latency_ofp_to_device_list = [] |
| 132 | latency_t0_to_device_list = [] |
| 133 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 134 | #Directory/file to store tshark results |
| 135 | tshark_of_output = "/tmp/tshark_of_topo.txt" |
| 136 | tshark_tcp_output = "/tmp/tshark_tcp_topo.txt" |
| 137 | |
| 138 | #String to grep in tshark output |
| 139 | tshark_tcp_string = "TCP 74 "+default_sw_port |
| 140 | tshark_of_string = "OFP 86 Vendor" |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 141 | |
| 142 | #Initialize assertion to TRUE |
| 143 | assertion = main.TRUE |
| 144 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 145 | main.log.report("Latency of adding one switch") |
| 146 | |
| 147 | for i in range(0, int(num_iter)): |
| 148 | main.log.info("Starting tshark capture") |
| 149 | |
| 150 | #* TCP [ACK, SYN] is used as t0_a, the |
| 151 | # very first "exchange" between ONOS and |
| 152 | # the switch for end-to-end measurement |
| 153 | #* OFP [Stats Reply] is used for t0_b |
| 154 | # the very last OFP message between ONOS |
| 155 | # and the switch for ONOS measurement |
| 156 | main.ONOS1.tshark_grep(tshark_tcp_string, |
| 157 | tshark_tcp_output) |
| 158 | main.ONOS1.tshark_grep(tshark_of_string, |
| 159 | tshark_of_output) |
| 160 | |
| 161 | #Wait and ensure tshark is started and |
| 162 | #capturing |
| 163 | time.sleep(10) |
| 164 | |
| 165 | main.log.info("Assigning s1 to controller") |
| 166 | |
| 167 | main.Mininet1.assign_sw_controller(sw="1", |
| 168 | ip1=ONOS1_ip, port1=default_sw_port) |
| 169 | |
| 170 | #Wait and ensure switch is assigned |
| 171 | #before stopping tshark |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 172 | time.sleep(30) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 173 | |
| 174 | main.log.info("Stopping all Tshark processes") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 175 | main.ONOS1.stop_tshark() |
| 176 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 177 | #tshark output is saved in ONOS. Use subprocess |
| 178 | #to copy over files to TestON for parsing |
| 179 | main.log.info("Copying over tshark files") |
| 180 | |
| 181 | #TCP CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 182 | #Copy the tshark output from ONOS machine to |
| 183 | #TestON machine in tshark_tcp_output directory>file |
| 184 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 185 | tshark_tcp_output+" /tmp/") |
| 186 | tcp_file = open(tshark_tcp_output, 'r') |
| 187 | temp_text = tcp_file.readline() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 188 | temp_text = temp_text.split(" ") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 189 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 190 | main.log.info("Object read in from TCP capture: "+ |
| 191 | str(temp_text)) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 192 | if len(temp_text) > 1: |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 193 | t0_tcp = int(float(temp_text[1])*1000) |
| 194 | else: |
| 195 | main.log.error("Tshark output file for TCP"+ |
| 196 | " returned unexpected results") |
| 197 | t0_tcp = 0 |
| 198 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 199 | |
| 200 | tcp_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 201 | #**************** |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 202 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 203 | #OF CAPTURE **** |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 204 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 205 | tshark_of_output+" /tmp/") |
| 206 | of_file = open(tshark_of_output, 'r') |
| 207 | |
| 208 | line_ofp = "" |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 209 | #Read until last line of file |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 210 | while True: |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 211 | temp_text = of_file.readline() |
| 212 | if temp_text !='': |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 213 | line_ofp = temp_text |
| 214 | else: |
| 215 | break |
| 216 | obj = line_ofp.split(" ") |
| 217 | |
| 218 | main.log.info("Object read in from OFP capture: "+ |
| 219 | str(line_ofp)) |
| 220 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 221 | if len(line_ofp) > 1: |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 222 | t0_ofp = int(float(obj[1])*1000) |
| 223 | else: |
| 224 | main.log.error("Tshark output file for OFP"+ |
| 225 | " returned unexpected results") |
| 226 | t0_ofp = 0 |
| 227 | assertion = main.FALSE |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 228 | |
| 229 | of_file.close() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 230 | #**************** |
| 231 | |
| 232 | #TODO: |
| 233 | #Get json object from all 3 ONOS instances |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 234 | json_str_1 = main.ONOS1cli.topology_events_metrics() |
| 235 | json_str_2 = main.ONOS2cli.topology_events_metrics() |
| 236 | json_str_3 = main.ONOS3cli.topology_events_metrics() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 237 | |
| 238 | json_obj_1 = json.loads(json_str_1) |
| 239 | json_obj_2 = json.loads(json_str_2) |
| 240 | json_obj_3 = json.loads(json_str_3) |
| 241 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 242 | #Obtain graph timestamp. This timestsamp captures |
| 243 | #the epoch time at which the topology graph was updated. |
| 244 | graph_timestamp_1 = \ |
| 245 | json_obj_1[graphTimestamp]['value'] |
| 246 | graph_timestamp_2 = \ |
| 247 | json_obj_2[graphTimestamp]['value'] |
| 248 | graph_timestamp_3 = \ |
| 249 | json_obj_3[graphTimestamp]['value'] |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 250 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 251 | #Obtain device timestamp. This timestamp captures |
| 252 | #the epoch time at which the device event happened |
| 253 | device_timestamp_1 = \ |
| 254 | json_obj_1[deviceTimestamp]['value'] |
| 255 | device_timestamp_2 = \ |
| 256 | json_obj_2[deviceTimestamp]['value'] |
| 257 | device_timestamp_3 = \ |
| 258 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | e9fb672 | 2014-10-24 12:20:35 -0400 | [diff] [blame] | 259 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 260 | #t0 to device processing latency |
| 261 | delta_device_1 = int(device_timestamp_1) - int(t0_tcp) |
| 262 | delta_device_2 = int(device_timestamp_2) - int(t0_tcp) |
| 263 | delta_device_3 = int(device_timestamp_3) - int(t0_tcp) |
| 264 | |
| 265 | #Get average of delta from all instances |
| 266 | avg_delta_device = \ |
| 267 | (int(delta_device_1)+\ |
| 268 | int(delta_device_2)+\ |
| 269 | int(delta_device_3)) / 3 |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 270 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 271 | #Ensure avg delta meets the threshold before appending |
| 272 | if avg_delta_device > 0.0 and avg_delta_device < 10000: |
| 273 | latency_t0_to_device_list.append(avg_delta_device) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 274 | else: |
| 275 | main.log.info("Results ignored due to excess in "+\ |
| 276 | "threshold") |
| 277 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 278 | #t0 to graph processing latency (end-to-end) |
| 279 | delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp) |
| 280 | delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp) |
| 281 | delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp) |
| 282 | |
| 283 | #Get average of delta from all instances |
| 284 | avg_delta_graph = \ |
| 285 | (int(delta_graph_1)+\ |
| 286 | int(delta_graph_2)+\ |
| 287 | int(delta_graph_3)) / 3 |
| 288 | |
| 289 | latency_end_to_end_list.append(avg_delta_graph) |
| 290 | |
| 291 | #Ensure avg delta meets the threshold before appending |
| 292 | if avg_delta_graph > 0.0 and avg_delta_graph < 10000: |
| 293 | latency_t0_to_device_list.append(avg_delta_graph) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 294 | else: |
| 295 | main.log.info("Results ignored due to excess in "+\ |
| 296 | "threshold") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 297 | |
| 298 | #ofp to graph processing latency (ONOS processing) |
| 299 | delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp) |
| 300 | delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp) |
| 301 | delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp) |
| 302 | |
| 303 | avg_delta_ofp_graph = \ |
| 304 | (int(delta_ofp_graph_1)+\ |
| 305 | int(delta_ofp_graph_2)+\ |
| 306 | int(delta_ofp_graph_3)) / 3 |
| 307 | |
| 308 | if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000: |
| 309 | latency_ofp_to_graph_list.append(avg_delta_ofp_graph) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 310 | else: |
| 311 | main.log.info("Results ignored due to excess in "+\ |
| 312 | "threshold") |
| 313 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 314 | #ofp to device processing latency (ONOS processing) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 315 | delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp) |
| 316 | delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp) |
| 317 | delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 318 | |
| 319 | avg_delta_ofp_device = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 320 | (float(delta_ofp_device_1)+\ |
| 321 | float(delta_ofp_device_2)+\ |
| 322 | float(delta_ofp_device_3)) / 3.0 |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 323 | |
| 324 | if avg_delta_ofp_device > 0.0 and avg_delta_ofp_device < 10000: |
| 325 | latency_ofp_to_device_list.append(avg_delta_ofp_device) |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 326 | else: |
| 327 | main.log.info("Results ignored due to excess in "+\ |
| 328 | "threshold") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 329 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 330 | #TODO: |
| 331 | #Fetch logs upon threshold excess |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 332 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 333 | main.log.info("ONOS1 delta end-to-end: "+ |
| 334 | str(delta_graph_1)) |
| 335 | main.log.info("ONOS2 delta end-to-end: "+ |
| 336 | str(delta_graph_2)) |
| 337 | main.log.info("ONSO3 delta end-to-end: "+ |
| 338 | str(delta_graph_3)) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 339 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 340 | main.log.info("ONOS1 delta OFP - graph: "+ |
| 341 | str(delta_ofp_graph_1)) |
| 342 | main.log.info("ONOS2 delta OFP - graph: "+ |
| 343 | str(delta_ofp_graph_2)) |
| 344 | main.log.info("ONOS3 delta OFP - graph: "+ |
| 345 | str(delta_ofp_graph_3)) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 346 | |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 347 | main.log.info("ONOS1 delta device - t0: "+ |
| 348 | str(delta_device_1)) |
| 349 | main.log.info("ONOS2 delta device - t0: "+ |
| 350 | str(delta_device_2)) |
| 351 | main.log.info("ONOS3 delta device - t0: "+ |
| 352 | str(delta_device_3)) |
| 353 | |
| 354 | main.log.info("ONOS1 delta OFP - device: "+ |
| 355 | str(delta_ofp_device_1)) |
| 356 | main.log.info("ONOS2 delta OFP - device: "+ |
| 357 | str(delta_ofp_device_2)) |
| 358 | main.log.info("ONOS3 delta OFP - device: "+ |
| 359 | str(delta_ofp_device_3)) |
| 360 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 361 | main.step("Remove switch from controller") |
| 362 | main.Mininet1.delete_sw_controller("s1") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 363 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 364 | time.sleep(5) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 365 | |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 366 | #If there is at least 1 element in each list, |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 367 | #pass the test case |
| 368 | if len(latency_end_to_end_list) > 0 and\ |
| 369 | len(latency_ofp_to_graph_list) > 0 and\ |
| 370 | len(latency_ofp_to_device_list) > 0 and\ |
| 371 | len(latency_t0_to_device_list) > 0: |
| 372 | assertion = main.TRUE |
| 373 | |
| 374 | #Calculate min, max, avg of latency lists |
| 375 | latency_end_to_end_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 376 | int(max(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 377 | latency_end_to_end_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 378 | int(min(latency_end_to_end_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 379 | latency_end_to_end_avg = \ |
andrewonlab | c90667c | 2014-10-24 16:48:28 -0400 | [diff] [blame^] | 380 | (int(sum(latency_end_to_end_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 381 | len(latency_end_to_end_list)) |
| 382 | |
| 383 | latency_ofp_to_graph_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 384 | int(max(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 385 | latency_ofp_to_graph_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 386 | int(min(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 387 | latency_ofp_to_graph_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 388 | (int(sum(latency_ofp_to_graph_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 389 | len(latency_ofp_to_graph_list)) |
| 390 | |
| 391 | latency_ofp_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 392 | int(max(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 393 | latency_ofp_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 394 | int(min(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 395 | latency_ofp_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 396 | (int(sum(latency_ofp_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 397 | len(latency_ofp_to_device_list)) |
| 398 | |
| 399 | latency_t0_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 400 | float(max(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 401 | latency_t0_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 402 | float(min(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 403 | latency_t0_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 404 | (float(sum(latency_t0_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 405 | len(latency_ofp_to_device_list)) |
| 406 | |
| 407 | main.log.report("Switch add - End-to-end latency: \n"+\ |
| 408 | "Min: "+str(latency_end_to_end_min)+"\n"+\ |
| 409 | "Max: "+str(latency_end_to_end_max)+"\n"+\ |
| 410 | "Avg: "+str(latency_end_to_end_avg)) |
| 411 | main.log.report("Switch add - OFP-to-Graph latency: \n"+\ |
| 412 | "Min: "+str(latency_ofp_to_graph_min)+"\n"+\ |
| 413 | "Max: "+str(latency_ofp_to_graph_max)+"\n"+\ |
| 414 | "Avg: "+str(latency_ofp_to_graph_avg)) |
| 415 | main.log.report("Switch add - OFP-to-Device latency: \n"+\ |
| 416 | "Min: "+str(latency_ofp_to_device_min)+"\n"+\ |
| 417 | "Max: "+str(latency_ofp_to_device_max)+"\n"+\ |
| 418 | "Avg: "+str(latency_ofp_to_device_avg)) |
| 419 | main.log.report("Switch add - t0-to-Device latency: \n"+\ |
| 420 | "Min: "+str(latency_t0_to_device_min)+"\n"+\ |
| 421 | "Max: "+str(latency_t0_to_device_max)+"\n"+\ |
| 422 | "Avg: "+str(latency_t0_to_device_avg)) |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 423 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 424 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 425 | onpass="Switch latency test successful", |
| 426 | onfail="Switch latency test failed") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 427 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 428 | def CASE3(self, main): |
| 429 | ''' |
| 430 | Bring port up / down and measure latency. |
| 431 | Port enable / disable is simulated by ifconfig up / down |
| 432 | ''' |
| 433 | import time |
| 434 | import subprocess |
| 435 | import os |
| 436 | import requests |
| 437 | import json |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 438 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 439 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 440 | default_sw_port = main.params['CTRL']['port1'] |
| 441 | ONOS_user = main.params['CTRL']['user'] |
| 442 | num_iter = main.params['TEST']['numIter'] |
| 443 | |
| 444 | tshark_port_status = "OFP 130 Port Status" |
| 445 | |
| 446 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 447 | tshark_port_down = "/tmp/tshark_port_down.txt" |
| 448 | |
| 449 | main.log.report("Port enable / disable latency") |
| 450 | |
| 451 | main.step("Assign switch to controller") |
| 452 | main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip, |
| 453 | port1=default_sw_port) |
| 454 | |
| 455 | main.step("Verify switch is assigned correctly") |
| 456 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
| 457 | if result_s1 == main.FALSE: |
| 458 | main.log.info("Switch s1 was not assigned correctly") |
| 459 | assertion = main.FALSE |
| 460 | else: |
| 461 | main.log.info("Switch s1 was assigned correctly") |
| 462 | |
| 463 | for i in range(0, int(num_iter)): |
| 464 | main.step("Starting wireshark capture for port status down") |
| 465 | main.ONOS1.tshark_grep(tshark_port_status, |
| 466 | tshark_port_down) |
| 467 | |
| 468 | time.sleep(10) |
| 469 | |
| 470 | main.step("Disable port (interface s1-eth2)") |
| 471 | main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down") |
| 472 | main.Mininet2.handle.expect("\$") |
| 473 | time.sleep(20) |
| 474 | |
| 475 | main.ONOS1.tshark_stop() |
| 476 | time.sleep(5) |
| 477 | |
| 478 | #Copy tshark output file from ONOS to TestON instance |
| 479 | #/tmp directory |
| 480 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 481 | tshark_port_down+" /tmp/") |
| 482 | |
| 483 | f_port_down = open(tshark_port_down, 'r') |
| 484 | f_line = f_port_down.readline() |
| 485 | obj_down = f_line.split(" ") |
| 486 | if len(f_line) > 0: |
| 487 | timestamp_begin_pt_down = int(float(obj_down[1])*1000) |
| 488 | else: |
| 489 | main.log.info("Tshark output file returned unexpected"+ |
| 490 | " results") |
| 491 | timestamp_begin_pt_down = 0 |
| 492 | |
| 493 | main.step("Obtain t1 by REST call") |
| 494 | #TODO: Implement json object parsing here |
| 495 | |
| 496 | timestamp_end_pt_down_1 = 0 |
| 497 | timestamp_end_pt_down_2 = 0 |
| 498 | timestamp_end_pt_down_3 = 0 |
| 499 | |
| 500 | delta_pt_down_1 = int(timestamp_end_pt_down_1) - \ |
| 501 | int(timestamp_begin_pt_down) |
| 502 | delta_pt_down_2 = int(timestamp_end_pt_down_2) - \ |
| 503 | int(timestamp_begin_pt_down) |
| 504 | delta_pt_down_3 = int(timestamp_end_pt_down_3) - \ |
| 505 | int(timestamp_begin_pt_down) |
| 506 | |
| 507 | #TODO: Remove these logs. For test purposes only |
| 508 | main.log.info("Delta1: "+str(delta_pt_down_1)) |
| 509 | main.log.info("Delta2: "+str(delta_pt_down_2)) |
| 510 | main.log.info("Delta3: "+str(delta_pt_down_3)) |
| 511 | |
| 512 | #Port up events |
| 513 | main.step("Enable port and obtain timestamp") |
| 514 | main.step("Starting wireshark capture for port status up") |
| 515 | main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up) |
| 516 | time.sleep(10) |
| 517 | |
| 518 | main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up") |
| 519 | main.Mininet2.handle.expect("\$") |
| 520 | time.sleep(20) |
| 521 | |
| 522 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 523 | tshark_port_up+" /tmp/") |
| 524 | |
| 525 | f_port_up = open(tshark_port_up, 'r') |
| 526 | f_line = f_port_down.readline() |
| 527 | obj_up = f_line.split(" ") |
| 528 | if len(f_line) > 0: |
| 529 | timestamp_begin_pt_up = int(float(obj_up[1])*1000) |
| 530 | else: |
| 531 | main.log.info("Tshark output file returned unexpected"+ |
| 532 | " results.") |
| 533 | timestamp_begin_pt_up = 0 |
| 534 | |
| 535 | main.step("Obtain t1 by REST call") |
| 536 | #TODO: Implement json object parsing here |
| 537 | |
| 538 | timestamp_end_pt_up_1 = 0 |
| 539 | timestamp_end_pt_up_2 = 0 |
| 540 | timestamp_end_pt_up_3 = 0 |
| 541 | |
| 542 | delta_pt_up_1 = int(timestamp_end_pt_up_1) - \ |
| 543 | int(timestamp_begin_pt_up) |
| 544 | delta_pt_up_2 = int(timestamp_end_pt_up_2) - \ |
| 545 | int(timestamp_begin_pt_up) |
| 546 | delta_pt_up_3 = int(timestamp_end_pt_up_3) - \ |
| 547 | int(timestamp_begin_pt_up) |
| 548 | |
| 549 | #TODO: Remove these logs. For test purposes only |
| 550 | main.log.info("Delta1: "+str(delta_pt_up_1)) |
| 551 | main.log.info("Delta2: "+str(delta_pt_up_2)) |
| 552 | main.log.info("Delta3: "+str(delta_pt_up_3)) |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |