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)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 446 | latency_end_to_end_std_dev = \ |
| 447 | str(round(numpy.std(latency_end_to_end_list),1)) |
| 448 | |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 449 | latency_ofp_to_graph_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 450 | int(max(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 451 | latency_ofp_to_graph_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 452 | int(min(latency_ofp_to_graph_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 453 | latency_ofp_to_graph_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 454 | (int(sum(latency_ofp_to_graph_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 455 | len(latency_ofp_to_graph_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 456 | latency_ofp_to_graph_std_dev = \ |
| 457 | str(round(numpy.std(latency_ofp_to_graph_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 458 | |
| 459 | latency_ofp_to_device_max = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 460 | int(max(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 461 | latency_ofp_to_device_min = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 462 | int(min(latency_ofp_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 463 | latency_ofp_to_device_avg = \ |
andrewonlab | ee4efeb | 2014-10-24 16:44:51 -0400 | [diff] [blame] | 464 | (int(sum(latency_ofp_to_device_list)) / \ |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 465 | len(latency_ofp_to_device_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 466 | latency_ofp_to_device_std_dev = \ |
| 467 | str(round(numpy.std(latency_ofp_to_device_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 468 | |
| 469 | latency_t0_to_device_max = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 470 | int(max(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 471 | latency_t0_to_device_min = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 472 | int(min(latency_t0_to_device_list)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 473 | latency_t0_to_device_avg = \ |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 474 | (int(sum(latency_t0_to_device_list)) / \ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 475 | len(latency_t0_to_device_list)) |
| 476 | latency_ofp_to_device_std_dev = \ |
| 477 | str(round(numpy.std(latency_t0_to_device_list),1)) |
andrewonlab | c15c958 | 2014-10-24 16:35:52 -0400 | [diff] [blame] | 478 | |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 479 | latency_tcp_to_ofp_max = \ |
| 480 | int(max(latency_tcp_to_ofp_list)) |
| 481 | latency_tcp_to_ofp_min = \ |
| 482 | int(min(latency_tcp_to_ofp_list)) |
| 483 | latency_tcp_to_ofp_avg = \ |
| 484 | (int(sum(latency_tcp_to_ofp_list)) / \ |
| 485 | len(latency_tcp_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 486 | latency_tcp_to_ofp_std_dev = \ |
| 487 | str(round(numpy.std(latency_tcp_to_ofp_list),1)) |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 488 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 489 | main.log.report("Switch add - End-to-end latency: "+\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 490 | "Avg: "+str(latency_end_to_end_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 491 | "Std Deviation: "+latency_end_to_end_std_dev+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 492 | main.log.report("Switch add - OFP-to-Graph latency: "+\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 493 | "Avg: "+str(latency_ofp_to_graph_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 494 | "Std Deviation: "+latency_ofp_to_graph_std_dev+" ms") |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 495 | main.log.report("Switch add - TCP-to-OFP latency: "+\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 496 | "Avg: "+str(latency_tcp_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 497 | "Std Deviation: "+latency_tcp_to_ofp_std_dev+" ms") |
andrewonlab | 226024e | 2014-10-24 16:01:32 -0400 | [diff] [blame] | 498 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 499 | if debug_mode == 'on': |
| 500 | main.ONOS1.cp_logs_to_dir("/opt/onos/log/karaf.log", |
| 501 | "/tmp/", copy_file_name="sw_lat_karaf") |
| 502 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 503 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 504 | onpass="Switch latency test successful", |
| 505 | onfail="Switch latency test failed") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 506 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 507 | def CASE3(self, main): |
| 508 | ''' |
| 509 | Bring port up / down and measure latency. |
| 510 | Port enable / disable is simulated by ifconfig up / down |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 511 | |
| 512 | In ONOS-next, we must ensure that the port we are |
| 513 | manipulating is connected to another switch with a valid |
| 514 | connection. Otherwise, graph view will not be updated. |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 515 | ''' |
| 516 | import time |
| 517 | import subprocess |
| 518 | import os |
| 519 | import requests |
| 520 | import json |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 521 | import numpy |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 522 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 523 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 524 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 525 | ONOS3_ip = main.params['CTRL']['ip3'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 526 | ONOS_user = main.params['CTRL']['user'] |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 527 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 528 | default_sw_port = main.params['CTRL']['port1'] |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 529 | |
| 530 | assertion = main.TRUE |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 531 | #Number of iterations of case |
| 532 | num_iter = main.params['TEST']['numIter'] |
| 533 | |
| 534 | #Timestamp 'keys' for json metrics output. |
| 535 | #These are subject to change, hence moved into params |
| 536 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 537 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 538 | |
| 539 | debug_mode = main.params['TEST']['debugMode'] |
| 540 | |
| 541 | local_time = time.strftime('%x %X') |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 542 | local_time = local_time.replace("/","") |
| 543 | local_time = local_time.replace(" ","_") |
| 544 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 545 | if debug_mode == 'on': |
| 546 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 547 | "/tmp/port_lat_pcap_"+local_time) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 548 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 549 | #Threshold for this test case |
| 550 | up_threshold_str = main.params['TEST']['portUpThreshold'] |
| 551 | down_threshold_str = main.params['TEST']['portDownThreshold'] |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 552 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 553 | up_threshold_obj = up_threshold_str.split(",") |
| 554 | down_threshold_obj = down_threshold_str.split(",") |
| 555 | |
| 556 | up_threshold_min = int(up_threshold_obj[0]) |
| 557 | up_threshold_max = int(up_threshold_obj[1]) |
| 558 | |
| 559 | down_threshold_min = int(down_threshold_obj[0]) |
| 560 | down_threshold_max = int(down_threshold_obj[1]) |
| 561 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 562 | #NOTE: Some hardcoded variables you may need to configure |
| 563 | # besides the params |
| 564 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 565 | tshark_port_status = "OFP 130 Port Status" |
| 566 | |
| 567 | tshark_port_up = "/tmp/tshark_port_up.txt" |
| 568 | tshark_port_down = "/tmp/tshark_port_down.txt" |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 569 | interface_config = "s1-eth1" |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 570 | |
| 571 | main.log.report("Port enable / disable latency") |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 572 | main.log.report("Simulated by ifconfig up / down") |
| 573 | main.log.report("Total iterations of test: "+str(num_iter)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 574 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 575 | main.step("Assign switches s1 and s2 to controller 1") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 576 | main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip, |
| 577 | port1=default_sw_port) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 578 | main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip, |
| 579 | port1=default_sw_port) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 580 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 581 | #Give enough time for metrics to propagate the |
| 582 | #assign controller event. Otherwise, these events may |
| 583 | #carry over to our measurements |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 584 | time.sleep(15) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 585 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 586 | port_up_device_to_ofp_list = [] |
| 587 | port_up_graph_to_ofp_list = [] |
| 588 | port_down_device_to_ofp_list = [] |
| 589 | port_down_graph_to_ofp_list = [] |
| 590 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 591 | for i in range(0, int(num_iter)): |
| 592 | main.step("Starting wireshark capture for port status down") |
| 593 | main.ONOS1.tshark_grep(tshark_port_status, |
| 594 | tshark_port_down) |
| 595 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 596 | time.sleep(5) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 597 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 598 | #Disable interface that is connected to switch 2 |
| 599 | main.step("Disable port: "+interface_config) |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 600 | main.Mininet1.handle.sendline("sh ifconfig "+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 601 | interface_config+" down") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 602 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 603 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 604 | time.sleep(3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 605 | main.ONOS1.tshark_stop() |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 606 | |
| 607 | main.step("Obtain t1 by metrics call") |
| 608 | json_str_up_1 = main.ONOS1cli.topology_events_metrics() |
| 609 | json_str_up_2 = main.ONOS2cli.topology_events_metrics() |
| 610 | json_str_up_3 = main.ONOS3cli.topology_events_metrics() |
| 611 | |
| 612 | json_obj_1 = json.loads(json_str_up_1) |
| 613 | json_obj_2 = json.loads(json_str_up_2) |
| 614 | json_obj_3 = json.loads(json_str_up_3) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 615 | |
| 616 | #Copy tshark output file from ONOS to TestON instance |
| 617 | #/tmp directory |
| 618 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 619 | tshark_port_down+" /tmp/") |
| 620 | |
| 621 | f_port_down = open(tshark_port_down, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 622 | #Get first line of port down event from tshark |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 623 | f_line = f_port_down.readline() |
| 624 | obj_down = f_line.split(" ") |
| 625 | if len(f_line) > 0: |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 626 | timestamp_begin_pt_down = int(float(obj_down[1])*1000) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 627 | main.log.info("Port down begin timestamp: "+ |
| 628 | str(timestamp_begin_pt_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 629 | else: |
| 630 | main.log.info("Tshark output file returned unexpected"+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 631 | " results: "+str(obj_down)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 632 | timestamp_begin_pt_down = 0 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 633 | |
| 634 | f_port_down.close() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 635 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 636 | main.log.info("TEST tshark obj: "+str(obj_down)) |
| 637 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 638 | time.sleep(3) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 639 | |
| 640 | #Obtain graph timestamp. This timestsamp captures |
| 641 | #the epoch time at which the topology graph was updated. |
| 642 | graph_timestamp_1 = \ |
| 643 | json_obj_1[graphTimestamp]['value'] |
| 644 | graph_timestamp_2 = \ |
| 645 | json_obj_2[graphTimestamp]['value'] |
| 646 | graph_timestamp_3 = \ |
| 647 | json_obj_3[graphTimestamp]['value'] |
| 648 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 649 | main.log.info("TEST graph timestamp ONOS1: "+ |
| 650 | str(graph_timestamp_1)) |
| 651 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 652 | #Obtain device timestamp. This timestamp captures |
| 653 | #the epoch time at which the device event happened |
| 654 | device_timestamp_1 = \ |
| 655 | json_obj_1[deviceTimestamp]['value'] |
| 656 | device_timestamp_2 = \ |
| 657 | json_obj_2[deviceTimestamp]['value'] |
| 658 | device_timestamp_3 = \ |
| 659 | json_obj_3[deviceTimestamp]['value'] |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 660 | |
| 661 | #Get delta between graph event and OFP |
| 662 | pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
| 663 | int(timestamp_begin_pt_down) |
| 664 | pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
| 665 | int(timestamp_begin_pt_down) |
| 666 | pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 667 | int(timestamp_begin_pt_down) |
| 668 | |
| 669 | #Get delta between device event and OFP |
| 670 | pt_down_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 671 | int(timestamp_begin_pt_down) |
| 672 | pt_down_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 673 | int(timestamp_begin_pt_down) |
| 674 | pt_down_device_to_ofp_3 = int(device_timestamp_3) -\ |
| 675 | int(timestamp_begin_pt_down) |
| 676 | |
| 677 | #Caluclate average across clusters |
| 678 | pt_down_graph_to_ofp_avg =\ |
| 679 | (int(pt_down_graph_to_ofp_1) + |
| 680 | int(pt_down_graph_to_ofp_2) + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 681 | int(pt_down_graph_to_ofp_3)) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 682 | pt_down_device_to_ofp_avg = \ |
| 683 | (int(pt_down_device_to_ofp_1) + |
| 684 | int(pt_down_device_to_ofp_2) + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 685 | int(pt_down_device_to_ofp_3)) / 3 |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 686 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 687 | if pt_down_graph_to_ofp_avg > down_threshold_min and \ |
| 688 | pt_down_graph_to_ofp_avg < down_threshold_max: |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 689 | port_down_graph_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 690 | pt_down_graph_to_ofp_avg) |
| 691 | main.log.info("Port down: graph to ofp avg: "+ |
| 692 | str(pt_down_graph_to_ofp_avg) + " ms") |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 693 | else: |
| 694 | main.log.info("Average port down graph-to-ofp result" + |
| 695 | " exceeded the threshold: "+ |
| 696 | str(pt_down_graph_to_ofp_avg)) |
| 697 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 698 | if pt_down_device_to_ofp_avg > 0 and \ |
| 699 | pt_down_device_to_ofp_avg < 1000: |
| 700 | port_down_device_to_ofp_list.append( |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 701 | pt_down_device_to_ofp_avg) |
| 702 | main.log.info("Port down: device to ofp avg: "+ |
| 703 | str(pt_down_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 704 | else: |
| 705 | main.log.info("Average port down device-to-ofp result" + |
| 706 | " exceeded the threshold: "+ |
| 707 | str(pt_down_device_to_ofp_avg)) |
| 708 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 709 | #Port up events |
| 710 | main.step("Enable port and obtain timestamp") |
| 711 | main.step("Starting wireshark capture for port status up") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 712 | main.ONOS1.tshark_grep(tshark_port_status, tshark_port_up) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 713 | time.sleep(5) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 714 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 715 | main.Mininet1.handle.sendline("sh ifconfig "+ |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 716 | interface_config+" up") |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 717 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 718 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 719 | #Allow time for tshark to capture event |
| 720 | time.sleep(3) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 721 | main.ONOS1.tshark_stop() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 722 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 723 | #Obtain metrics shortly afterwards |
| 724 | #This timestsamp captures |
| 725 | #the epoch time at which the topology graph was updated. |
| 726 | main.step("Obtain t1 by REST call") |
| 727 | json_str_up_1 = main.ONOS1cli.topology_events_metrics() |
| 728 | json_str_up_2 = main.ONOS2cli.topology_events_metrics() |
| 729 | json_str_up_3 = main.ONOS3cli.topology_events_metrics() |
| 730 | |
| 731 | json_obj_1 = json.loads(json_str_up_1) |
| 732 | json_obj_2 = json.loads(json_str_up_2) |
| 733 | json_obj_3 = json.loads(json_str_up_3) |
| 734 | |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 735 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 736 | tshark_port_up+" /tmp/") |
| 737 | |
| 738 | f_port_up = open(tshark_port_up, 'r') |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 739 | f_line = f_port_up.readline() |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 740 | obj_up = f_line.split(" ") |
| 741 | if len(f_line) > 0: |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 742 | timestamp_begin_pt_up = int(float(obj_up[1])*1000) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 743 | main.log.info("Port up begin timestamp: "+ |
| 744 | str(timestamp_begin_pt_up)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 745 | else: |
| 746 | main.log.info("Tshark output file returned unexpected"+ |
| 747 | " results.") |
| 748 | timestamp_begin_pt_up = 0 |
| 749 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 750 | f_port_up.close() |
| 751 | |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 752 | graph_timestamp_1 = \ |
| 753 | json_obj_1[graphTimestamp]['value'] |
| 754 | graph_timestamp_2 = \ |
| 755 | json_obj_2[graphTimestamp]['value'] |
| 756 | graph_timestamp_3 = \ |
| 757 | json_obj_3[graphTimestamp]['value'] |
| 758 | |
| 759 | #Obtain device timestamp. This timestamp captures |
| 760 | #the epoch time at which the device event happened |
| 761 | device_timestamp_1 = \ |
| 762 | json_obj_1[deviceTimestamp]['value'] |
| 763 | device_timestamp_2 = \ |
| 764 | json_obj_2[deviceTimestamp]['value'] |
| 765 | device_timestamp_3 = \ |
| 766 | json_obj_3[deviceTimestamp]['value'] |
| 767 | |
| 768 | #Get delta between graph event and OFP |
| 769 | pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 770 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 771 | pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 772 | int(timestamp_begin_pt_up) |
andrewonlab | 393531a | 2014-10-27 18:36:26 -0400 | [diff] [blame] | 773 | pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\ |
| 774 | int(timestamp_begin_pt_up) |
| 775 | |
| 776 | #Get delta between device event and OFP |
| 777 | pt_up_device_to_ofp_1 = int(device_timestamp_1) -\ |
| 778 | int(timestamp_begin_pt_up) |
| 779 | pt_up_device_to_ofp_2 = int(device_timestamp_2) -\ |
| 780 | int(timestamp_begin_pt_up) |
| 781 | pt_up_device_to_ofp_3 = int(device_timestamp_3) -\ |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 782 | int(timestamp_begin_pt_up) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 783 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 784 | main.log.info("ONOS1 delta G2O: "+str(pt_up_graph_to_ofp_1)) |
| 785 | main.log.info("ONOS2 delta G2O: "+str(pt_up_graph_to_ofp_2)) |
| 786 | main.log.info("ONOS3 delta G2O: "+str(pt_up_graph_to_ofp_3)) |
| 787 | |
| 788 | main.log.info("ONOS1 delta D2O: "+str(pt_up_device_to_ofp_1)) |
| 789 | main.log.info("ONOS2 delta D2O: "+str(pt_up_device_to_ofp_2)) |
| 790 | main.log.info("ONOS3 delta D2O: "+str(pt_up_device_to_ofp_3)) |
| 791 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 792 | pt_up_graph_to_ofp_avg = \ |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 793 | (int(pt_up_graph_to_ofp_1) + |
| 794 | int(pt_up_graph_to_ofp_2) + |
| 795 | int(pt_up_graph_to_ofp_3)) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 796 | |
| 797 | pt_up_device_to_ofp_avg = \ |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 798 | (int(pt_up_device_to_ofp_1) + |
| 799 | int(pt_up_device_to_ofp_2) + |
| 800 | int(pt_up_device_to_ofp_3)) / 3 |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 801 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 802 | if pt_up_graph_to_ofp_avg > up_threshold_min and \ |
| 803 | pt_up_graph_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 804 | port_up_graph_to_ofp_list.append( |
| 805 | pt_up_graph_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 806 | main.log.info("Port down: graph to ofp avg: "+ |
| 807 | str(pt_up_graph_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 808 | else: |
| 809 | main.log.info("Average port up graph-to-ofp result"+ |
| 810 | " exceeded the threshold: "+ |
| 811 | str(pt_up_graph_to_ofp_avg)) |
| 812 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 813 | if pt_up_device_to_ofp_avg > up_threshold_min and \ |
| 814 | pt_up_device_to_ofp_avg < up_threshold_max: |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 815 | port_up_device_to_ofp_list.append( |
| 816 | pt_up_device_to_ofp_avg) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 817 | main.log.info("Port up: device to ofp avg: "+ |
| 818 | str(pt_up_device_to_ofp_avg) + " ms") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 819 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 820 | main.log.info("Average port up device-to-ofp result"+ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 821 | " exceeded the threshold: "+ |
| 822 | str(pt_up_device_to_ofp_avg)) |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 823 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 824 | #END ITERATION FOR LOOP |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 825 | |
| 826 | #Check all list for latency existence and set assertion |
| 827 | if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\ |
| 828 | and port_up_graph_to_ofp_list and port_up_device_to_ofp_list): |
| 829 | assertion = main.TRUE |
| 830 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 831 | #Calculate and report latency measurements |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 832 | port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list) |
| 833 | port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list) |
| 834 | port_down_graph_to_ofp_avg = \ |
| 835 | (sum(port_down_graph_to_ofp_list) / |
| 836 | len(port_down_graph_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 837 | port_down_graph_to_ofp_std_dev = \ |
| 838 | str(round(numpy.std(port_down_graph_to_ofp_list),1)) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 839 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 840 | main.log.report("Port down graph-to-ofp "+ |
| 841 | "Avg: "+str(port_down_graph_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 842 | "Std Deviation: "+port_down_graph_to_ofp_std_dev+" ms") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 843 | |
| 844 | port_down_device_to_ofp_min = min(port_down_device_to_ofp_list) |
| 845 | port_down_device_to_ofp_max = max(port_down_device_to_ofp_list) |
| 846 | port_down_device_to_ofp_avg = \ |
| 847 | (sum(port_down_device_to_ofp_list) /\ |
| 848 | len(port_down_device_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 849 | port_down_device_to_ofp_std_dev = \ |
| 850 | str(round(numpy.std(port_down_device_to_ofp_list),1)) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 851 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 852 | main.log.report("Port down device-to-ofp "+ |
| 853 | "Avg: "+str(port_down_device_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 854 | "Std Deviation: "+port_down_device_to_ofp_std_dev+" ms") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 855 | |
| 856 | port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list) |
| 857 | port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list) |
| 858 | port_up_graph_to_ofp_avg = \ |
| 859 | (sum(port_up_graph_to_ofp_list) /\ |
| 860 | len(port_up_graph_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 861 | port_up_graph_to_ofp_std_dev = \ |
| 862 | str(round(numpy.std(port_up_graph_to_ofp_list),1)) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 863 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 864 | main.log.report("Port up graph-to-ofp "+ |
| 865 | "Avg: "+str(port_up_graph_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 866 | "Std Deviation: "+port_up_graph_to_ofp_std_dev+" ms") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 867 | |
| 868 | port_up_device_to_ofp_min = min(port_up_device_to_ofp_list) |
| 869 | port_up_device_to_ofp_max = max(port_up_device_to_ofp_list) |
| 870 | port_up_device_to_ofp_avg = \ |
| 871 | (sum(port_up_device_to_ofp_list) /\ |
| 872 | len(port_up_device_to_ofp_list)) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 873 | port_up_device_to_ofp_std_dev = \ |
| 874 | str(round(numpy.std(port_up_device_to_ofp_list),1)) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 875 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 876 | main.log.report("Port up device-to-ofp "+ |
| 877 | "Avg: "+str(port_up_device_to_ofp_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 878 | "Std Deviation: "+port_up_device_to_ofp_std_dev+" ms") |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 879 | |
| 880 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 881 | onpass="Port discovery latency calculation successful", |
| 882 | onfail="Port discovery test failed") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 883 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 884 | def CASE4(self, main): |
| 885 | ''' |
| 886 | Link down event using loss rate 100% |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 887 | |
| 888 | Important: |
| 889 | Use a simple 2 switch topology with 1 link between |
| 890 | the two switches. Ensure that mac addresses of the |
| 891 | switches are 1 / 2 respectively |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 892 | ''' |
| 893 | import time |
| 894 | import subprocess |
| 895 | import os |
| 896 | import requests |
| 897 | import json |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 898 | import numpy |
| 899 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 900 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 901 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 902 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 903 | ONOS_user = main.params['CTRL']['user'] |
| 904 | |
| 905 | default_sw_port = main.params['CTRL']['port1'] |
| 906 | |
| 907 | #Number of iterations of case |
| 908 | num_iter = main.params['TEST']['numIter'] |
| 909 | |
| 910 | #Timestamp 'keys' for json metrics output. |
| 911 | #These are subject to change, hence moved into params |
| 912 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
| 913 | linkTimestamp = main.params['JSON']['linkTimestamp'] |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 914 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 915 | |
| 916 | debug_mode = main.params['TEST']['debugMode'] |
| 917 | |
| 918 | local_time = time.strftime('%x %X') |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 919 | local_time = local_time.replace("/","") |
| 920 | local_time = local_time.replace(" ","_") |
| 921 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 922 | if debug_mode == 'on': |
| 923 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 924 | "/tmp/link_lat_pcap_"+local_time) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 925 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 926 | #Threshold for this test case |
| 927 | up_threshold_str = main.params['TEST']['linkUpThreshold'] |
| 928 | down_threshold_str = main.params['TEST']['linkDownThreshold'] |
| 929 | |
| 930 | up_threshold_obj = up_threshold_str.split(",") |
| 931 | down_threshold_obj = down_threshold_str.split(",") |
| 932 | |
| 933 | up_threshold_min = int(up_threshold_obj[0]) |
| 934 | up_threshold_max = int(up_threshold_obj[1]) |
| 935 | |
| 936 | down_threshold_min = int(down_threshold_obj[0]) |
| 937 | down_threshold_max = int(down_threshold_obj[1]) |
| 938 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 939 | assertion = main.TRUE |
| 940 | #Link event timestamp to system time list |
| 941 | link_down_link_to_system_list = [] |
| 942 | link_up_link_to_system_list = [] |
| 943 | #Graph event timestamp to system time list |
| 944 | link_down_graph_to_system_list = [] |
| 945 | link_up_graph_to_system_list = [] |
| 946 | |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 947 | main.log.report("Link up / down discovery latency between "+ |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 948 | "two switches") |
andrewonlab | 4b5c8b9 | 2014-11-10 16:04:33 -0500 | [diff] [blame] | 949 | main.log.report("Simulated by setting loss-rate 100%") |
| 950 | main.log.report("'tc qdisc add dev <intfs> root netem loss 100%'") |
| 951 | main.log.report("Total iterations of test: "+str(num_iter)) |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 952 | |
| 953 | main.step("Assign all switches") |
| 954 | main.Mininet1.assign_sw_controller(sw="1", |
| 955 | ip1=ONOS1_ip, port1=default_sw_port) |
| 956 | main.Mininet1.assign_sw_controller(sw="2", |
| 957 | ip1=ONOS1_ip, port1=default_sw_port) |
| 958 | |
| 959 | main.step("Verifying switch assignment") |
| 960 | result_s1 = main.Mininet1.get_sw_controller(sw="s1") |
| 961 | result_s2 = main.Mininet1.get_sw_controller(sw="s2") |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 962 | |
| 963 | #Allow time for events to finish before taking measurements |
| 964 | time.sleep(10) |
| 965 | |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 966 | link_down1 = False |
| 967 | link_down2 = False |
| 968 | link_down3 = False |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 969 | #Start iteration of link event test |
| 970 | for i in range(0, int(num_iter)): |
| 971 | main.step("Getting initial system time as t0") |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 972 | |
andrewonlab | 3622beb | 2014-10-28 16:07:56 -0400 | [diff] [blame] | 973 | timestamp_link_down_t0 = time.time() * 1000 |
| 974 | #Link down is simulated by 100% loss rate using traffic |
| 975 | #control command |
| 976 | main.Mininet1.handle.sendline( |
| 977 | "sh tc qdisc add dev s1-eth1 root netem loss 100%") |
| 978 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 979 | #TODO: Iterate through 'links' command to verify that |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 980 | # link s1 -> s2 went down (loop timeout 30 seconds) |
| 981 | # on all 3 ONOS instances |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 982 | main.log.info("Checking ONOS for link update") |
| 983 | loop_count = 0 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 984 | while( not (link_down1 and link_down2 and link_down3)\ |
| 985 | and loop_count < 30 ): |
| 986 | json_str1 = main.ONOS1cli.links() |
| 987 | json_str2 = main.ONOS2cli.links() |
| 988 | json_str3 = main.ONOS3cli.links() |
| 989 | |
| 990 | if not (json_str1 and json_str2 and json_str3): |
| 991 | main.log.error("CLI command returned error ") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 992 | break |
| 993 | else: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 994 | json_obj1 = json.loads(json_str1) |
| 995 | json_obj2 = json.loads(json_str2) |
| 996 | json_obj3 = json.loads(json_str3) |
| 997 | for obj1 in json_obj1: |
| 998 | if '01' not in obj1['src']['device']: |
| 999 | link_down1 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1000 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1001 | "s1 -> s2 on ONOS1 detected") |
| 1002 | for obj2 in json_obj2: |
| 1003 | if '01' not in obj2['src']['device']: |
| 1004 | link_down2 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1005 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1006 | "s1 -> s2 on ONOS2 detected") |
| 1007 | for obj3 in json_obj3: |
| 1008 | if '01' not in obj3['src']['device']: |
| 1009 | link_down3 = True |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1010 | main.log.info("Link down from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1011 | "s1 -> s2 on ONOS3 detected") |
| 1012 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1013 | loop_count += 1 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1014 | #If CLI doesn't like the continuous requests |
| 1015 | #and exits in this loop, increase the sleep here. |
| 1016 | #Consequently, while loop timeout will increase |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1017 | time.sleep(1) |
| 1018 | |
| 1019 | #Give time for metrics measurement to catch up |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1020 | #NOTE: May need to be configured more accurately |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1021 | time.sleep(10) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1022 | #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] | 1023 | #false, then ONOS has failed to discover link down event |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1024 | if not (link_down1 and link_down2 and link_down3): |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1025 | main.log.info("Link down discovery failed") |
| 1026 | |
| 1027 | link_down_lat_graph1 = 0 |
| 1028 | link_down_lat_graph2 = 0 |
| 1029 | link_down_lat_graph3 = 0 |
| 1030 | link_down_lat_device1 = 0 |
| 1031 | link_down_lat_device2 = 0 |
| 1032 | link_down_lat_device3 = 0 |
| 1033 | |
| 1034 | assertion = main.FALSE |
| 1035 | else: |
| 1036 | json_topo_metrics_1 =\ |
| 1037 | main.ONOS1cli.topology_events_metrics() |
| 1038 | json_topo_metrics_2 =\ |
| 1039 | main.ONOS2cli.topology_events_metrics() |
| 1040 | json_topo_metrics_3 =\ |
| 1041 | main.ONOS3cli.topology_events_metrics() |
| 1042 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 1043 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 1044 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 1045 | |
| 1046 | main.log.info("Obtaining graph and device timestamp") |
| 1047 | graph_timestamp_1 = \ |
| 1048 | json_topo_metrics_1[graphTimestamp]['value'] |
| 1049 | graph_timestamp_2 = \ |
| 1050 | json_topo_metrics_2[graphTimestamp]['value'] |
| 1051 | graph_timestamp_3 = \ |
| 1052 | json_topo_metrics_3[graphTimestamp]['value'] |
| 1053 | |
| 1054 | link_timestamp_1 = \ |
| 1055 | json_topo_metrics_1[linkTimestamp]['value'] |
| 1056 | link_timestamp_2 = \ |
| 1057 | json_topo_metrics_2[linkTimestamp]['value'] |
| 1058 | link_timestamp_3 = \ |
| 1059 | json_topo_metrics_3[linkTimestamp]['value'] |
| 1060 | |
| 1061 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 1062 | graph_timestamp_3 and link_timestamp_1 and\ |
| 1063 | link_timestamp_2 and link_timestamp_3: |
| 1064 | link_down_lat_graph1 = int(graph_timestamp_1) -\ |
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 | link_down_lat_graph2 = int(graph_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1067 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1068 | link_down_lat_graph3 = int(graph_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1069 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1070 | |
| 1071 | link_down_lat_link1 = int(link_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1072 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1073 | link_down_lat_link2 = int(link_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1074 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1075 | link_down_lat_link3 = int(link_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1076 | int(timestamp_link_down_t0) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1077 | else: |
| 1078 | main.log.error("There was an error calculating"+ |
| 1079 | " the delta for link down event") |
| 1080 | link_down_lat_graph1 = 0 |
| 1081 | link_down_lat_graph2 = 0 |
| 1082 | link_down_lat_graph3 = 0 |
| 1083 | |
| 1084 | link_down_lat_device1 = 0 |
| 1085 | link_down_lat_device2 = 0 |
| 1086 | link_down_lat_device3 = 0 |
| 1087 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1088 | main.log.info("Link down latency ONOS1 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1089 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1090 | str(link_down_lat_graph1)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1091 | main.log.info("Link down latency ONOS2 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1092 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1093 | str(link_down_lat_graph2)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1094 | main.log.info("Link down latency ONOS3 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1095 | str(i)+" (end-to-end): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1096 | str(link_down_lat_graph3)+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1097 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1098 | main.log.info("Link down latency ONOS1 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1099 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1100 | str(link_down_lat_link1)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1101 | main.log.info("Link down latency ONOS2 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1102 | str(i)+" (link-event-to-system-timestamp): "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1103 | str(link_down_lat_link2)+" ms") |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1104 | main.log.info("Link down latency ONOS3 iteration "+ |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1105 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1106 | str(link_down_lat_link3)) |
| 1107 | |
| 1108 | #Calculate avg of node calculations |
| 1109 | link_down_lat_graph_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1110 | (link_down_lat_graph1 + |
| 1111 | link_down_lat_graph2 + |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 1112 | link_down_lat_graph3) / 3 |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1113 | link_down_lat_link_avg =\ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1114 | (link_down_lat_link1 + |
| 1115 | link_down_lat_link2 + |
andrewonlab | 65d7389 | 2014-11-10 17:36:00 -0500 | [diff] [blame] | 1116 | link_down_lat_link3) / 3 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1117 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1118 | #Set threshold and append latency to list |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1119 | if link_down_lat_graph_avg > down_threshold_min and\ |
| 1120 | link_down_lat_graph_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1121 | link_down_graph_to_system_list.append( |
| 1122 | link_down_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1123 | else: |
| 1124 | main.log.info("Link down latency exceeded threshold") |
| 1125 | main.log.info("Results for iteration "+str(i)+ |
| 1126 | "have been omitted") |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1127 | if link_down_lat_link_avg > down_threshold_min and\ |
| 1128 | link_down_lat_link_avg < down_threshold_max: |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1129 | link_down_link_to_system_list.append( |
| 1130 | link_down_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1131 | else: |
| 1132 | main.log.info("Link down latency exceeded threshold") |
| 1133 | main.log.info("Results for iteration "+str(i)+ |
| 1134 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1135 | |
| 1136 | #NOTE: To remove loss rate and measure latency: |
| 1137 | # 'sh tc qdisc del dev s1-eth1 root' |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1138 | timestamp_link_up_t0 = time.time() * 1000 |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1139 | main.Mininet1.handle.sendline("sh tc qdisc del dev "+ |
| 1140 | "s1-eth1 root") |
| 1141 | main.Mininet1.handle.expect("mininet>") |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1142 | |
| 1143 | main.log.info("Checking ONOS for link update") |
| 1144 | |
| 1145 | link_down1 = True |
| 1146 | link_down2 = True |
| 1147 | link_down3 = True |
| 1148 | loop_count = 0 |
| 1149 | while( (link_down1 and link_down2 and link_down3)\ |
| 1150 | and loop_count < 30 ): |
| 1151 | json_str1 = main.ONOS1cli.links() |
| 1152 | json_str2 = main.ONOS2cli.links() |
| 1153 | json_str3 = main.ONOS3cli.links() |
| 1154 | if not (json_str1 and json_str2 and json_str3): |
| 1155 | main.log.error("CLI command returned error ") |
| 1156 | break |
| 1157 | else: |
| 1158 | json_obj1 = json.loads(json_str1) |
| 1159 | json_obj2 = json.loads(json_str2) |
| 1160 | json_obj3 = json.loads(json_str3) |
| 1161 | |
| 1162 | for obj1 in json_obj1: |
| 1163 | if '01' in obj1['src']['device']: |
| 1164 | link_down1 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1165 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1166 | "s1 -> s2 on ONOS1 detected") |
| 1167 | for obj2 in json_obj2: |
| 1168 | if '01' in obj2['src']['device']: |
| 1169 | link_down2 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1170 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1171 | "s1 -> s2 on ONOS2 detected") |
| 1172 | for obj3 in json_obj3: |
| 1173 | if '01' in obj3['src']['device']: |
| 1174 | link_down3 = False |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1175 | main.log.info("Link up from "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1176 | "s1 -> s2 on ONOS3 detected") |
| 1177 | |
| 1178 | loop_count += 1 |
| 1179 | time.sleep(1) |
| 1180 | |
| 1181 | if (link_down1 and link_down2 and link_down3): |
| 1182 | main.log.info("Link up discovery failed") |
| 1183 | |
| 1184 | link_up_lat_graph1 = 0 |
| 1185 | link_up_lat_graph2 = 0 |
| 1186 | link_up_lat_graph3 = 0 |
| 1187 | link_up_lat_device1 = 0 |
| 1188 | link_up_lat_device2 = 0 |
| 1189 | link_up_lat_device3 = 0 |
| 1190 | |
| 1191 | assertion = main.FALSE |
| 1192 | else: |
| 1193 | json_topo_metrics_1 =\ |
| 1194 | main.ONOS1cli.topology_events_metrics() |
| 1195 | json_topo_metrics_2 =\ |
| 1196 | main.ONOS2cli.topology_events_metrics() |
| 1197 | json_topo_metrics_3 =\ |
| 1198 | main.ONOS3cli.topology_events_metrics() |
| 1199 | json_topo_metrics_1 = json.loads(json_topo_metrics_1) |
| 1200 | json_topo_metrics_2 = json.loads(json_topo_metrics_2) |
| 1201 | json_topo_metrics_3 = json.loads(json_topo_metrics_3) |
| 1202 | |
| 1203 | main.log.info("Obtaining graph and device timestamp") |
| 1204 | graph_timestamp_1 = \ |
| 1205 | json_topo_metrics_1[graphTimestamp]['value'] |
| 1206 | graph_timestamp_2 = \ |
| 1207 | json_topo_metrics_2[graphTimestamp]['value'] |
| 1208 | graph_timestamp_3 = \ |
| 1209 | json_topo_metrics_3[graphTimestamp]['value'] |
| 1210 | |
| 1211 | link_timestamp_1 = \ |
| 1212 | json_topo_metrics_1[linkTimestamp]['value'] |
| 1213 | link_timestamp_2 = \ |
| 1214 | json_topo_metrics_2[linkTimestamp]['value'] |
| 1215 | link_timestamp_3 = \ |
| 1216 | json_topo_metrics_3[linkTimestamp]['value'] |
| 1217 | |
| 1218 | if graph_timestamp_1 and graph_timestamp_2 and\ |
| 1219 | graph_timestamp_3 and link_timestamp_1 and\ |
| 1220 | link_timestamp_2 and link_timestamp_3: |
| 1221 | link_up_lat_graph1 = int(graph_timestamp_1) -\ |
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 | link_up_lat_graph2 = int(graph_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1224 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1225 | link_up_lat_graph3 = int(graph_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1226 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1227 | |
| 1228 | link_up_lat_link1 = int(link_timestamp_1) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1229 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1230 | link_up_lat_link2 = int(link_timestamp_2) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1231 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1232 | link_up_lat_link3 = int(link_timestamp_3) -\ |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1233 | int(timestamp_link_up_t0) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1234 | else: |
| 1235 | main.log.error("There was an error calculating"+ |
| 1236 | " the delta for link down event") |
| 1237 | link_up_lat_graph1 = 0 |
| 1238 | link_up_lat_graph2 = 0 |
| 1239 | link_up_lat_graph3 = 0 |
| 1240 | |
| 1241 | link_up_lat_device1 = 0 |
| 1242 | link_up_lat_device2 = 0 |
| 1243 | link_up_lat_device3 = 0 |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1244 | |
| 1245 | if debug_mode == 'on': |
| 1246 | main.log.info("Link up latency ONOS1 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1247 | str(i)+" (end-to-end): "+ |
| 1248 | str(link_up_lat_graph1)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1249 | main.log.info("Link up latency ONOS2 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1250 | str(i)+" (end-to-end): "+ |
| 1251 | str(link_up_lat_graph2)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1252 | main.log.info("Link up latency ONOS3 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1253 | str(i)+" (end-to-end): "+ |
| 1254 | str(link_up_lat_graph3)+" ms") |
| 1255 | |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1256 | main.log.info("Link up latency ONOS1 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1257 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1258 | str(link_up_lat_link1)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1259 | main.log.info("Link up latency ONOS2 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1260 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1261 | str(link_up_lat_link2)+" ms") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1262 | main.log.info("Link up latency ONOS3 iteration "+ |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1263 | str(i)+" (link-event-to-system-timestamp): "+ |
| 1264 | str(link_up_lat_link3)) |
| 1265 | |
| 1266 | #Calculate avg of node calculations |
| 1267 | link_up_lat_graph_avg =\ |
| 1268 | (link_up_lat_graph1 + |
| 1269 | link_up_lat_graph2 + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1270 | link_up_lat_graph3) / 3 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1271 | link_up_lat_link_avg =\ |
| 1272 | (link_up_lat_link1 + |
| 1273 | link_up_lat_link2 + |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1274 | link_up_lat_link3) / 3 |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1275 | |
| 1276 | #Set threshold and append latency to list |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1277 | if link_up_lat_graph_avg > up_threshold_min and\ |
| 1278 | link_up_lat_graph_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1279 | link_up_graph_to_system_list.append( |
| 1280 | link_up_lat_graph_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1281 | else: |
| 1282 | main.log.info("Link up latency exceeded threshold") |
| 1283 | main.log.info("Results for iteration "+str(i)+ |
| 1284 | "have been omitted") |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1285 | if link_up_lat_link_avg > up_threshold_min and\ |
| 1286 | link_up_lat_link_avg < up_threshold_max: |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1287 | link_up_link_to_system_list.append( |
| 1288 | link_up_lat_link_avg) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1289 | else: |
| 1290 | main.log.info("Link up latency exceeded threshold") |
| 1291 | main.log.info("Results for iteration "+str(i)+ |
| 1292 | "have been omitted") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1293 | |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1294 | #Calculate min, max, avg of list and report |
| 1295 | link_down_min = min(link_down_graph_to_system_list) |
| 1296 | link_down_max = max(link_down_graph_to_system_list) |
| 1297 | link_down_avg = sum(link_down_graph_to_system_list) / \ |
| 1298 | len(link_down_graph_to_system_list) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1299 | link_up_min = min(link_up_graph_to_system_list) |
| 1300 | link_up_max = max(link_up_graph_to_system_list) |
| 1301 | link_up_avg = sum(link_up_graph_to_system_list) / \ |
| 1302 | len(link_up_graph_to_system_list) |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1303 | link_down_std_dev = \ |
| 1304 | str(round(numpy.std(link_down_graph_to_system_list),1)) |
| 1305 | link_up_std_dev = \ |
| 1306 | str(round(numpy.std(link_up_graph_to_system_list),1)) |
andrewonlab | abb11c3 | 2014-11-04 15:03:24 -0500 | [diff] [blame] | 1307 | |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1308 | main.log.report("Link down latency " + |
| 1309 | "Avg: "+str(link_down_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1310 | "Std Deviation: "+link_down_std_dev+" ms") |
andrewonlab | 4f50ec9 | 2014-11-11 14:24:45 -0500 | [diff] [blame] | 1311 | main.log.report("Link up latency "+ |
| 1312 | "Avg: "+str(link_up_avg)+" ms "+ |
andrewonlab | 6986416 | 2014-11-11 16:28:48 -0500 | [diff] [blame] | 1313 | "Std Deviation: "+link_up_std_dev+" ms") |
andrewonlab | 4e12448 | 2014-11-04 13:37:25 -0500 | [diff] [blame] | 1314 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1315 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 1316 | onpass="Link discovery latency calculation successful", |
| 1317 | onfail="Link discovery latency case failed") |
| 1318 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1319 | def CASE5(self, main): |
| 1320 | ''' |
| 1321 | 100 Switch discovery latency |
| 1322 | |
| 1323 | Important: |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1324 | This test case can be potentially dangerous if |
| 1325 | your machine has previously set iptables rules. |
| 1326 | One of the steps of the test case will flush |
| 1327 | all existing iptables rules. |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1328 | Note: |
| 1329 | You can specify the number of switches in the |
| 1330 | params file to adjust the switch discovery size |
| 1331 | (and specify the corresponding topology in Mininet1 |
| 1332 | .topo file) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1333 | ''' |
| 1334 | import time |
| 1335 | import subprocess |
| 1336 | import os |
| 1337 | import requests |
| 1338 | import json |
| 1339 | |
| 1340 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 1341 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 1342 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 1343 | MN1_ip = main.params['MN']['ip1'] |
| 1344 | ONOS_user = main.params['CTRL']['user'] |
| 1345 | |
| 1346 | default_sw_port = main.params['CTRL']['port1'] |
| 1347 | |
| 1348 | #Number of iterations of case |
| 1349 | num_iter = main.params['TEST']['numIter'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1350 | num_sw = main.params['TEST']['numSwitch'] |
| 1351 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1352 | #Timestamp 'keys' for json metrics output. |
| 1353 | #These are subject to change, hence moved into params |
| 1354 | deviceTimestamp = main.params['JSON']['deviceTimestamp'] |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1355 | graphTimestamp = main.params['JSON']['graphTimestamp'] |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1356 | |
| 1357 | debug_mode = main.params['TEST']['debugMode'] |
| 1358 | |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 1359 | local_time = time.strftime('%X') |
| 1360 | local_time = local_time.replace("/","") |
| 1361 | local_time = local_time.replace(" ","_") |
| 1362 | local_time = local_time.replace(":","") |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1363 | if debug_mode == 'on': |
| 1364 | main.ONOS1.tshark_pcap("eth0", |
andrewonlab | b1998c5 | 2014-11-10 13:31:43 -0500 | [diff] [blame] | 1365 | "/tmp/100_sw_lat_pcap_"+local_time) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1366 | |
| 1367 | #Threshold for this test case |
| 1368 | sw_disc_threshold_str = main.params['TEST']['swDisc100Threshold'] |
| 1369 | sw_disc_threshold_obj = sw_disc_threshold_str.split(",") |
| 1370 | sw_disc_threshold_min = int(sw_disc_threshold_obj[0]) |
| 1371 | sw_disc_threshold_max = int(sw_disc_threshold_obj[1]) |
| 1372 | |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1373 | tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt" |
| 1374 | tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt" |
| 1375 | |
| 1376 | tshark_ofp_result_list = [] |
| 1377 | tshark_tcp_result_list = [] |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1378 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1379 | sw_discovery_lat_list = [] |
| 1380 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1381 | main.case(num_sw+" Switch discovery latency") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1382 | main.step("Assigning all switches to ONOS1") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1383 | for i in range(1, int(num_sw)+1): |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1384 | main.Mininet1.assign_sw_controller( |
| 1385 | sw=str(i), |
| 1386 | ip1=ONOS1_ip, |
| 1387 | port1=default_sw_port) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1388 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1389 | #Ensure that nodes are configured with ptpd |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1390 | #Just a warning message |
| 1391 | main.log.info("Please check ptpd configuration to ensure"+\ |
| 1392 | " All nodes' system times are in sync") |
| 1393 | time.sleep(5) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1394 | |
| 1395 | for i in range(0, int(num_iter)): |
andrewonlab | 8d29f12 | 2014-10-22 17:15:04 -0400 | [diff] [blame] | 1396 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1397 | main.step("Set iptables rule to block incoming sw connections") |
| 1398 | #Set iptables rule to block incoming switch connections |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1399 | #The rule description is as follows: |
| 1400 | # Append to INPUT rule, |
| 1401 | # behavior DROP that matches following: |
| 1402 | # * packet type: tcp |
| 1403 | # * source IP: MN1_ip |
| 1404 | # * destination PORT: 6633 |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1405 | main.ONOS1.handle.sendline( |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1406 | "sudo iptables -A INPUT -p tcp -s "+MN1_ip+ |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1407 | " --dport "+default_sw_port+" -j DROP") |
| 1408 | main.ONOS1.handle.expect("\$") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1409 | # Append to OUTPUT rule, |
| 1410 | # behavior DROP that matches following: |
| 1411 | # * packet type: tcp |
| 1412 | # * source IP: MN1_ip |
| 1413 | # * destination PORT: 6633 |
| 1414 | main.ONOS1.handle.sendline( |
| 1415 | "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+ |
| 1416 | " --dport "+default_sw_port+" -j DROP") |
| 1417 | main.ONOS1.handle.expect("\$") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1418 | #Give time to allow rule to take effect |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 1419 | #NOTE: Sleep period may need to be configured |
| 1420 | # based on the number of switches in the topology |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1421 | main.log.info("Please wait for switch connection to "+ |
| 1422 | "time out") |
| 1423 | time.sleep(60) |
| 1424 | |
| 1425 | #Gather vendor OFP with tshark |
| 1426 | main.ONOS1.tshark_grep("OFP 86 Vendor", |
| 1427 | tshark_ofp_output) |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1428 | main.ONOS1.tshark_grep("TCP 74 ", |
| 1429 | tshark_tcp_output) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1430 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1431 | #NOTE: Remove all iptables rule quickly (flush) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1432 | # Before removal, obtain TestON timestamp at which |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1433 | # removal took place |
| 1434 | # (ensuring nodes are configured via ptp) |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1435 | # sudo iptables -F |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1436 | |
| 1437 | t0_system = time.time() * 1000 |
| 1438 | main.ONOS1.handle.sendline( |
| 1439 | "sudo iptables -F") |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1440 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1441 | #Counter to track loop count |
| 1442 | counter_loop = 0 |
| 1443 | counter_avail1 = 0 |
| 1444 | counter_avail2 = 0 |
| 1445 | counter_avail3 = 0 |
| 1446 | onos1_dev = False |
| 1447 | onos2_dev = False |
| 1448 | onos3_dev = False |
| 1449 | while counter_loop < 60: |
| 1450 | #Continue to check devices for all device |
| 1451 | #availability. When all devices in all 3 |
| 1452 | #ONOS instances indicate that devices are available |
| 1453 | #obtain graph event timestamp for t1. |
| 1454 | device_str_obj1 = main.ONOS1cli.devices() |
| 1455 | device_str_obj2 = main.ONOS2cli.devices() |
| 1456 | device_str_obj3 = main.ONOS3cli.devices() |
| 1457 | |
| 1458 | device_json1 = json.loads(device_str_obj1) |
| 1459 | device_json2 = json.loads(device_str_obj2) |
| 1460 | device_json3 = json.loads(device_str_obj3) |
| 1461 | |
| 1462 | for device1 in device_json1: |
| 1463 | if device1['available'] == True: |
| 1464 | counter_avail1 += 1 |
| 1465 | if counter_avail1 == int(num_sw): |
| 1466 | onos1_dev = True |
| 1467 | main.log.info("All devices have been "+ |
| 1468 | "discovered on ONOS1") |
| 1469 | else: |
| 1470 | counter_avail1 = 0 |
| 1471 | for device2 in device_json2: |
| 1472 | if device2['available'] == True: |
| 1473 | counter_avail2 += 1 |
| 1474 | if counter_avail2 == int(num_sw): |
| 1475 | onos2_dev = True |
| 1476 | main.log.info("All devices have been "+ |
| 1477 | "discovered on ONOS2") |
| 1478 | else: |
| 1479 | counter_avail2 = 0 |
| 1480 | for device3 in device_json3: |
| 1481 | if device3['available'] == True: |
| 1482 | counter_avail3 += 1 |
| 1483 | if counter_avail3 == int(num_sw): |
| 1484 | onos3_dev = True |
| 1485 | main.log.info("All devices have been "+ |
| 1486 | "discovered on ONOS3") |
| 1487 | else: |
| 1488 | counter_avail3 = 0 |
| 1489 | |
| 1490 | if onos1_dev and onos2_dev and onos3_dev: |
| 1491 | main.log.info("All devices have been discovered "+ |
| 1492 | "on all ONOS instances") |
| 1493 | json_str_topology_metrics_1 =\ |
| 1494 | main.ONOS1cli.topology_events_metrics() |
| 1495 | json_str_topology_metrics_2 =\ |
| 1496 | main.ONOS2cli.topology_events_metrics() |
| 1497 | json_str_topology_metrics_3 =\ |
| 1498 | main.ONOS3cli.topology_events_metrics() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1499 | |
| 1500 | #Exit while loop if all devices discovered |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1501 | break |
| 1502 | |
| 1503 | counter_loop += 1 |
| 1504 | #Give some time in between CLI calls |
| 1505 | #(will not affect measurement) |
| 1506 | time.sleep(3) |
| 1507 | |
| 1508 | main.ONOS1.tshark_stop() |
| 1509 | |
| 1510 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1511 | tshark_ofp_output+" /tmp/") |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1512 | os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+ |
| 1513 | tshark_tcp_output+" /tmp/") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1514 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1515 | #TODO: Automate OFP output analysis |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1516 | #Debug mode - print out packets captured at runtime |
| 1517 | if debug_mode == 'on': |
| 1518 | ofp_file = open(tshark_ofp_output, 'r') |
| 1519 | main.log.info("Tshark OFP Vendor output: ") |
| 1520 | for line in ofp_file: |
| 1521 | tshark_ofp_result_list.append(line) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1522 | main.log.info(line) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1523 | ofp_file.close() |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1524 | |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1525 | tcp_file = open(tshark_tcp_output, 'r') |
| 1526 | main.log.info("Tshark TCP 74 output: ") |
| 1527 | for line in tcp_file: |
| 1528 | tshark_tcp_result_list.append(line) |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1529 | main.log.info(line) |
andrewonlab | 58f7d70 | 2014-11-07 13:21:19 -0500 | [diff] [blame] | 1530 | tcp_file.close() |
andrewonlab | 53b641c | 2014-10-31 19:44:44 -0400 | [diff] [blame] | 1531 | |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1532 | json_obj_1 = json.loads(json_str_topology_metrics_1) |
| 1533 | json_obj_2 = json.loads(json_str_topology_metrics_2) |
| 1534 | json_obj_3 = json.loads(json_str_topology_metrics_3) |
| 1535 | |
| 1536 | graph_timestamp_1 = \ |
| 1537 | json_obj_1[graphTimestamp]['value'] |
| 1538 | graph_timestamp_2 = \ |
| 1539 | json_obj_2[graphTimestamp]['value'] |
| 1540 | graph_timestamp_3 = \ |
| 1541 | json_obj_3[graphTimestamp]['value'] |
| 1542 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1543 | graph_lat_1 = int(graph_timestamp_1) - int(t0_system) |
| 1544 | graph_lat_2 = int(graph_timestamp_2) - int(t0_system) |
| 1545 | graph_lat_3 = int(graph_timestamp_3) - int(t0_system) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1546 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1547 | avg_graph_lat = \ |
| 1548 | (int(graph_lat_1) +\ |
| 1549 | int(graph_lat_2) +\ |
| 1550 | int(graph_lat_3)) / 3 |
| 1551 | |
| 1552 | if avg_graph_lat > sw_disc_threshold_min \ |
| 1553 | and avg_graph_lat < sw_disc_threshold_max: |
| 1554 | sw_discovery_lat_list.append( |
| 1555 | avg_graph_lat) |
| 1556 | else: |
| 1557 | main.log.info("100 Switch discovery latency "+ |
| 1558 | "exceeded the threshold.") |
| 1559 | |
| 1560 | #END ITERATION FOR LOOP |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1561 | |
andrewonlab | e5bcef9 | 2014-11-06 17:53:20 -0500 | [diff] [blame] | 1562 | sw_lat_min = min(sw_discovery_lat_list) |
| 1563 | sw_lat_max = max(sw_discovery_lat_list) |
| 1564 | sw_lat_avg = sum(sw_discovery_lat_list) /\ |
| 1565 | len(sw_discovery_lat_list) |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1566 | |
andrewonlab | f9828f0 | 2014-11-10 14:50:27 -0500 | [diff] [blame] | 1567 | main.log.report("100 Switch discovery lat "+\ |
| 1568 | "Min: "+str(sw_lat_min)+" ms"+\ |
| 1569 | "Max: "+str(sw_lat_max)+" ms"+\ |
| 1570 | "Avg: "+str(sw_lat_avg)+" ms") |
andrewonlab | 16ce485 | 2014-10-30 13:41:09 -0400 | [diff] [blame] | 1571 | |
andrewonlab | b54b85b | 2014-10-28 18:43:57 -0400 | [diff] [blame] | 1572 | |