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