blob: 67298f546ab452484aadeba8052f662dd442650d [file] [log] [blame]
andrewonlab2a6c9342014-10-16 13:40:15 -04001#TopoPerfNext
2#
3#Topology Performance test for ONOS-next
4#
5#andrew@onlab.us
6
7import time
8import sys
9import os
10import re
11
12class TopoPerfNext:
13 def __init__(self):
14 self.default = ''
15
16 def CASE1(self, main):
17 '''
18 ONOS startup sequence
19 '''
andrewonlabe9fb6722014-10-24 12:20:35 -040020 import time
21
andrewonlab2a6c9342014-10-16 13:40:15 -040022 cell_name = main.params['ENV']['cellName']
23
24 git_pull = main.params['GIT']['autoPull']
25 checkout_branch = main.params['GIT']['checkout']
26
27 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040028 ONOS2_ip = main.params['CTRL']['ip2']
29 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab2a6c9342014-10-16 13:40:15 -040030 MN1_ip = main.params['MN']['ip1']
31 BENCH_ip = main.params['BENCH']['ip']
32
33 main.case("Setting up test environment")
34
35 main.step("Creating cell file")
36 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040037 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040038 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040039
40 main.step("Applying cell file to environment")
41 cell_apply_result = main.ONOSbench.set_cell(cell_name)
42 verify_cell_result = main.ONOSbench.verify_cell()
43
44 main.step("Git checkout and pull "+checkout_branch)
45 if git_pull == 'on':
46 checkout_result = \
47 main.ONOSbench.git_checkout(checkout_branch)
48 pull_result = main.ONOSbench.git_pull()
49 else:
50 checkout_result = main.TRUE
51 pull_result = main.TRUE
52 main.log.info("Skipped git checkout and pull")
53
54 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040055 #mvn_result = main.ONOSbench.clean_install()
56 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040057
58 main.step("Creating ONOS package")
59 package_result = main.ONOSbench.onos_package()
60
61 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040062 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
63 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
64 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlabe9fb6722014-10-24 12:20:35 -040066 #NOTE: This step may be unnecessary
67 #main.step("Starting ONOS service")
68 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040069
andrewonlab867212a2014-10-22 20:13:38 -040070 main.step("Set cell for ONOS cli env")
71 main.ONOS1cli.set_cell(cell_name)
72 main.ONOS2cli.set_cell(cell_name)
73 main.ONOS3cli.set_cell(cell_name)
74
andrewonlabe9fb6722014-10-24 12:20:35 -040075 time.sleep(10)
76
andrewonlab867212a2014-10-22 20:13:38 -040077 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -040078 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
79 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
80 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
81
82 if not (cli1 and cli2 and cli3):
83 main.log.info("Attempting to start cli again")
84 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
85 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
86 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
andrewonlab867212a2014-10-22 20:13:38 -040087
88 main.step("Enable metrics feature")
89 main.ONOS1cli.feature_install("onos-app-metrics-topology")
90 main.ONOS2cli.feature_install("onos-app-metrics-topology")
91 main.ONOS3cli.feature_install("onos-app-metrics-topology")
92
andrewonlab2a6c9342014-10-16 13:40:15 -040093 utilities.assert_equals(expect=main.TRUE,
94 actual= cell_file_result and cell_apply_result and\
95 verify_cell_result and checkout_result and\
96 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -040097 install1_result and install2_result and\
98 install3_result,
andrewonlab8d29f122014-10-22 17:15:04 -040099 onpass="ONOS started successfully",
100 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -0400101
andrewonlabba44bcf2014-10-16 16:54:41 -0400102 def CASE2(self, main):
103 '''
104 Assign s1 to ONOS1 and measure latency
105 '''
106 import time
andrewonlabe6745342014-10-17 14:29:13 -0400107 import subprocess
108 import json
109 import requests
110 import os
andrewonlabba44bcf2014-10-16 16:54:41 -0400111
112 ONOS1_ip = main.params['CTRL']['ip1']
113 ONOS2_ip = main.params['CTRL']['ip2']
114 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400115 ONOS_user = main.params['CTRL']['user']
116
andrewonlabba44bcf2014-10-16 16:54:41 -0400117 default_sw_port = main.params['CTRL']['port1']
118
119 #Number of iterations of case
120 num_iter = main.params['TEST']['numIter']
121
andrewonlab226024e2014-10-24 16:01:32 -0400122 #Timestamp 'keys' for json metrics output.
123 #These are subject to change, hence moved into params
124 deviceTimestamp = main.params['JSON']['deviceTimestamp']
125 graphTimestamp = main.params['JSON']['graphTimestamp']
126
127 #List of switch add latency collected from
128 #all iterations
129 latency_end_to_end_list = []
130 latency_ofp_to_graph_list = []
131 latency_ofp_to_device_list = []
132 latency_t0_to_device_list = []
133
andrewonlabba44bcf2014-10-16 16:54:41 -0400134 #Directory/file to store tshark results
135 tshark_of_output = "/tmp/tshark_of_topo.txt"
136 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
137
138 #String to grep in tshark output
139 tshark_tcp_string = "TCP 74 "+default_sw_port
140 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400141
142 #Initialize assertion to TRUE
143 assertion = main.TRUE
144
andrewonlabba44bcf2014-10-16 16:54:41 -0400145 main.log.report("Latency of adding one switch")
146
147 for i in range(0, int(num_iter)):
148 main.log.info("Starting tshark capture")
149
150 #* TCP [ACK, SYN] is used as t0_a, the
151 # very first "exchange" between ONOS and
152 # the switch for end-to-end measurement
153 #* OFP [Stats Reply] is used for t0_b
154 # the very last OFP message between ONOS
155 # and the switch for ONOS measurement
156 main.ONOS1.tshark_grep(tshark_tcp_string,
157 tshark_tcp_output)
158 main.ONOS1.tshark_grep(tshark_of_string,
159 tshark_of_output)
160
161 #Wait and ensure tshark is started and
162 #capturing
163 time.sleep(10)
164
165 main.log.info("Assigning s1 to controller")
166
167 main.Mininet1.assign_sw_controller(sw="1",
168 ip1=ONOS1_ip, port1=default_sw_port)
169
170 #Wait and ensure switch is assigned
171 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400172 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400173
174 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400175 main.ONOS1.stop_tshark()
176
andrewonlabe6745342014-10-17 14:29:13 -0400177 #tshark output is saved in ONOS. Use subprocess
178 #to copy over files to TestON for parsing
179 main.log.info("Copying over tshark files")
180
181 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400182 #Copy the tshark output from ONOS machine to
183 #TestON machine in tshark_tcp_output directory>file
184 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
185 tshark_tcp_output+" /tmp/")
186 tcp_file = open(tshark_tcp_output, 'r')
187 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400188 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400189
andrewonlabe6745342014-10-17 14:29:13 -0400190 main.log.info("Object read in from TCP capture: "+
191 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400192 if len(temp_text) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400193 t0_tcp = int(float(temp_text[1])*1000)
194 else:
195 main.log.error("Tshark output file for TCP"+
196 " returned unexpected results")
197 t0_tcp = 0
198 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400199
200 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400201 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400202
andrewonlabe6745342014-10-17 14:29:13 -0400203 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400204 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
205 tshark_of_output+" /tmp/")
206 of_file = open(tshark_of_output, 'r')
207
208 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400209 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400210 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400211 temp_text = of_file.readline()
212 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400213 line_ofp = temp_text
214 else:
215 break
216 obj = line_ofp.split(" ")
217
218 main.log.info("Object read in from OFP capture: "+
219 str(line_ofp))
220
andrewonlab867212a2014-10-22 20:13:38 -0400221 if len(line_ofp) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400222 t0_ofp = int(float(obj[1])*1000)
223 else:
224 main.log.error("Tshark output file for OFP"+
225 " returned unexpected results")
226 t0_ofp = 0
227 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400228
229 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400230 #****************
231
232 #TODO:
233 #Get json object from all 3 ONOS instances
andrewonlab867212a2014-10-22 20:13:38 -0400234 json_str_1 = main.ONOS1cli.topology_events_metrics()
235 json_str_2 = main.ONOS2cli.topology_events_metrics()
236 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400237
238 json_obj_1 = json.loads(json_str_1)
239 json_obj_2 = json.loads(json_str_2)
240 json_obj_3 = json.loads(json_str_3)
241
andrewonlab226024e2014-10-24 16:01:32 -0400242 #Obtain graph timestamp. This timestsamp captures
243 #the epoch time at which the topology graph was updated.
244 graph_timestamp_1 = \
245 json_obj_1[graphTimestamp]['value']
246 graph_timestamp_2 = \
247 json_obj_2[graphTimestamp]['value']
248 graph_timestamp_3 = \
249 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400250
andrewonlab226024e2014-10-24 16:01:32 -0400251 #Obtain device timestamp. This timestamp captures
252 #the epoch time at which the device event happened
253 device_timestamp_1 = \
254 json_obj_1[deviceTimestamp]['value']
255 device_timestamp_2 = \
256 json_obj_2[deviceTimestamp]['value']
257 device_timestamp_3 = \
258 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400259
andrewonlab226024e2014-10-24 16:01:32 -0400260 #t0 to device processing latency
261 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
262 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
263 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
264
265 #Get average of delta from all instances
266 avg_delta_device = \
267 (int(delta_device_1)+\
268 int(delta_device_2)+\
269 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400270
andrewonlab226024e2014-10-24 16:01:32 -0400271 #Ensure avg delta meets the threshold before appending
272 if avg_delta_device > 0.0 and avg_delta_device < 10000:
273 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400274 else:
275 main.log.info("Results ignored due to excess in "+\
276 "threshold")
277
andrewonlab226024e2014-10-24 16:01:32 -0400278 #t0 to graph processing latency (end-to-end)
279 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
280 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
281 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
282
283 #Get average of delta from all instances
284 avg_delta_graph = \
285 (int(delta_graph_1)+\
286 int(delta_graph_2)+\
287 int(delta_graph_3)) / 3
288
289 latency_end_to_end_list.append(avg_delta_graph)
290
291 #Ensure avg delta meets the threshold before appending
292 if avg_delta_graph > 0.0 and avg_delta_graph < 10000:
293 latency_t0_to_device_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400294 else:
295 main.log.info("Results ignored due to excess in "+\
296 "threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400297
298 #ofp to graph processing latency (ONOS processing)
299 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
300 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
301 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
302
303 avg_delta_ofp_graph = \
304 (int(delta_ofp_graph_1)+\
305 int(delta_ofp_graph_2)+\
306 int(delta_ofp_graph_3)) / 3
307
308 if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000:
309 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400310 else:
311 main.log.info("Results ignored due to excess in "+\
312 "threshold")
313
andrewonlab226024e2014-10-24 16:01:32 -0400314 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400315 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
316 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
317 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400318
319 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400320 (float(delta_ofp_device_1)+\
321 float(delta_ofp_device_2)+\
322 float(delta_ofp_device_3)) / 3.0
andrewonlab226024e2014-10-24 16:01:32 -0400323
324 if avg_delta_ofp_device > 0.0 and avg_delta_ofp_device < 10000:
325 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400326 else:
327 main.log.info("Results ignored due to excess in "+\
328 "threshold")
andrewonlabba44bcf2014-10-16 16:54:41 -0400329
andrewonlabe6745342014-10-17 14:29:13 -0400330 #TODO:
331 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400332
andrewonlab226024e2014-10-24 16:01:32 -0400333 main.log.info("ONOS1 delta end-to-end: "+
334 str(delta_graph_1))
335 main.log.info("ONOS2 delta end-to-end: "+
336 str(delta_graph_2))
337 main.log.info("ONSO3 delta end-to-end: "+
338 str(delta_graph_3))
andrewonlabba44bcf2014-10-16 16:54:41 -0400339
andrewonlab226024e2014-10-24 16:01:32 -0400340 main.log.info("ONOS1 delta OFP - graph: "+
341 str(delta_ofp_graph_1))
342 main.log.info("ONOS2 delta OFP - graph: "+
343 str(delta_ofp_graph_2))
344 main.log.info("ONOS3 delta OFP - graph: "+
345 str(delta_ofp_graph_3))
andrewonlabe6745342014-10-17 14:29:13 -0400346
andrewonlab226024e2014-10-24 16:01:32 -0400347 main.log.info("ONOS1 delta device - t0: "+
348 str(delta_device_1))
349 main.log.info("ONOS2 delta device - t0: "+
350 str(delta_device_2))
351 main.log.info("ONOS3 delta device - t0: "+
352 str(delta_device_3))
353
354 main.log.info("ONOS1 delta OFP - device: "+
355 str(delta_ofp_device_1))
356 main.log.info("ONOS2 delta OFP - device: "+
357 str(delta_ofp_device_2))
358 main.log.info("ONOS3 delta OFP - device: "+
359 str(delta_ofp_device_3))
360
andrewonlab8d29f122014-10-22 17:15:04 -0400361 main.step("Remove switch from controller")
362 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400363
andrewonlab8d29f122014-10-22 17:15:04 -0400364 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400365
andrewonlabee4efeb2014-10-24 16:44:51 -0400366 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400367 #pass the test case
368 if len(latency_end_to_end_list) > 0 and\
369 len(latency_ofp_to_graph_list) > 0 and\
370 len(latency_ofp_to_device_list) > 0 and\
371 len(latency_t0_to_device_list) > 0:
372 assertion = main.TRUE
373
374 #Calculate min, max, avg of latency lists
375 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400376 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400377 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400378 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400379 latency_end_to_end_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400380 (int(sum(latency_end_to_end_list) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400381 len(latency_end_to_end_list))
382
383 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400384 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400385 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400386 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400387 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400388 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400389 len(latency_ofp_to_graph_list))
390
391 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400392 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400393 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400394 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400395 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400396 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400397 len(latency_ofp_to_device_list))
398
399 latency_t0_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400400 float(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400401 latency_t0_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400402 float(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400403 latency_t0_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400404 (float(sum(latency_t0_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400405 len(latency_ofp_to_device_list))
406
407 main.log.report("Switch add - End-to-end latency: \n"+\
408 "Min: "+str(latency_end_to_end_min)+"\n"+\
409 "Max: "+str(latency_end_to_end_max)+"\n"+\
410 "Avg: "+str(latency_end_to_end_avg))
411 main.log.report("Switch add - OFP-to-Graph latency: \n"+\
412 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
413 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
414 "Avg: "+str(latency_ofp_to_graph_avg))
415 main.log.report("Switch add - OFP-to-Device latency: \n"+\
416 "Min: "+str(latency_ofp_to_device_min)+"\n"+\
417 "Max: "+str(latency_ofp_to_device_max)+"\n"+\
418 "Avg: "+str(latency_ofp_to_device_avg))
419 main.log.report("Switch add - t0-to-Device latency: \n"+\
420 "Min: "+str(latency_t0_to_device_min)+"\n"+\
421 "Max: "+str(latency_t0_to_device_max)+"\n"+\
422 "Avg: "+str(latency_t0_to_device_avg))
andrewonlab226024e2014-10-24 16:01:32 -0400423
andrewonlab8d29f122014-10-22 17:15:04 -0400424 utilities.assert_equals(expect=main.TRUE, actual=assertion,
425 onpass="Switch latency test successful",
426 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400427
andrewonlab8d29f122014-10-22 17:15:04 -0400428 def CASE3(self, main):
429 '''
430 Bring port up / down and measure latency.
431 Port enable / disable is simulated by ifconfig up / down
432 '''
433 import time
434 import subprocess
435 import os
436 import requests
437 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400438
andrewonlab8d29f122014-10-22 17:15:04 -0400439 ONOS1_ip = main.params['CTRL']['ip1']
440 default_sw_port = main.params['CTRL']['port1']
441 ONOS_user = main.params['CTRL']['user']
442 num_iter = main.params['TEST']['numIter']
443
444 tshark_port_status = "OFP 130 Port Status"
445
446 tshark_port_up = "/tmp/tshark_port_up.txt"
447 tshark_port_down = "/tmp/tshark_port_down.txt"
448
449 main.log.report("Port enable / disable latency")
450
451 main.step("Assign switch to controller")
452 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
453 port1=default_sw_port)
454
455 main.step("Verify switch is assigned correctly")
456 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
457 if result_s1 == main.FALSE:
458 main.log.info("Switch s1 was not assigned correctly")
459 assertion = main.FALSE
460 else:
461 main.log.info("Switch s1 was assigned correctly")
462
463 for i in range(0, int(num_iter)):
464 main.step("Starting wireshark capture for port status down")
465 main.ONOS1.tshark_grep(tshark_port_status,
466 tshark_port_down)
467
468 time.sleep(10)
469
470 main.step("Disable port (interface s1-eth2)")
471 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down")
472 main.Mininet2.handle.expect("\$")
473 time.sleep(20)
474
475 main.ONOS1.tshark_stop()
476 time.sleep(5)
477
478 #Copy tshark output file from ONOS to TestON instance
479 #/tmp directory
480 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
481 tshark_port_down+" /tmp/")
482
483 f_port_down = open(tshark_port_down, 'r')
484 f_line = f_port_down.readline()
485 obj_down = f_line.split(" ")
486 if len(f_line) > 0:
487 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
488 else:
489 main.log.info("Tshark output file returned unexpected"+
490 " results")
491 timestamp_begin_pt_down = 0
492
493 main.step("Obtain t1 by REST call")
494 #TODO: Implement json object parsing here
495
496 timestamp_end_pt_down_1 = 0
497 timestamp_end_pt_down_2 = 0
498 timestamp_end_pt_down_3 = 0
499
500 delta_pt_down_1 = int(timestamp_end_pt_down_1) - \
501 int(timestamp_begin_pt_down)
502 delta_pt_down_2 = int(timestamp_end_pt_down_2) - \
503 int(timestamp_begin_pt_down)
504 delta_pt_down_3 = int(timestamp_end_pt_down_3) - \
505 int(timestamp_begin_pt_down)
506
507 #TODO: Remove these logs. For test purposes only
508 main.log.info("Delta1: "+str(delta_pt_down_1))
509 main.log.info("Delta2: "+str(delta_pt_down_2))
510 main.log.info("Delta3: "+str(delta_pt_down_3))
511
512 #Port up events
513 main.step("Enable port and obtain timestamp")
514 main.step("Starting wireshark capture for port status up")
515 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
516 time.sleep(10)
517
518 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up")
519 main.Mininet2.handle.expect("\$")
520 time.sleep(20)
521
522 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
523 tshark_port_up+" /tmp/")
524
525 f_port_up = open(tshark_port_up, 'r')
526 f_line = f_port_down.readline()
527 obj_up = f_line.split(" ")
528 if len(f_line) > 0:
529 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
530 else:
531 main.log.info("Tshark output file returned unexpected"+
532 " results.")
533 timestamp_begin_pt_up = 0
534
535 main.step("Obtain t1 by REST call")
536 #TODO: Implement json object parsing here
537
538 timestamp_end_pt_up_1 = 0
539 timestamp_end_pt_up_2 = 0
540 timestamp_end_pt_up_3 = 0
541
542 delta_pt_up_1 = int(timestamp_end_pt_up_1) - \
543 int(timestamp_begin_pt_up)
544 delta_pt_up_2 = int(timestamp_end_pt_up_2) - \
545 int(timestamp_begin_pt_up)
546 delta_pt_up_3 = int(timestamp_end_pt_up_3) - \
547 int(timestamp_begin_pt_up)
548
549 #TODO: Remove these logs. For test purposes only
550 main.log.info("Delta1: "+str(delta_pt_up_1))
551 main.log.info("Delta2: "+str(delta_pt_up_2))
552 main.log.info("Delta3: "+str(delta_pt_up_3))
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567