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