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