blob: 80d0517538b0c223ca4e1eed51f8b6716ccc9346 [file] [log] [blame]
Pavlin Radoslavov1a39b482013-05-21 19:20:10 +00001#! /usr/bin/env python
2# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
3
4import os
5import string
6import subprocess
7import time
8
Pavlin Radoslavov7be9a392013-05-24 05:17:19 +00009# flow_n = 252
10# threads_n = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 100]
11# iterations_n = 10
12
13flow_n = 1
14threads_n = [1]
Pavlin Radoslavov1a39b482013-05-21 19:20:10 +000015iterations_n = 10
16# iterations_n = 100
17
Pavlin Radoslavov7be9a392013-05-24 05:17:19 +000018# flow_n = 42
19# flow_n = 420
20# flow_n = 1008
Pavlin Radoslavov1a39b482013-05-21 19:20:10 +000021
22def run_command(cmd):
23 """
24 - Run an external command, and return a tuple: stdout as the
25 first argument, and stderr as the second argument.
26 - Returns None if error.
27 """
28 try:
29 pr = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
30 ret_tuple = pr.communicate();
31 if pr.returncode:
32 print "%s failed with error code: %s" % (cmd, str(pr.returncode))
33 return ret_tuple
34 except OSError:
35 print "OS Error running %s" % cmd
36
37def run_install_paths(flowdef_filename):
38 # Prepare the flows to measure
39 cmd = "web/measurement_store_flow.py -f " + flowdef_filename
40 os.system(cmd)
41
42def run_measurement(thread_n):
43 # Install the Flow Paths
44 cmd = ["web/measurement_install_paths.py", str(thread_n)]
45 run_command(cmd)
46
47 # Get the measurement data and print it
48 cmd = "web/measurement_get_install_paths_time_nsec.py"
49 r = run_command(cmd) # Tuple: [<stdout>, <stderr>]
Pavlin Radoslavov7be9a392013-05-24 05:17:19 +000050 res = r[0].split() # Tuple: [<num>, nsec]
Pavlin Radoslavov1a39b482013-05-21 19:20:10 +000051 nsec_str = res[0]
52 msec = float(nsec_str) / (1000 * 1000)
53
Pavlin Radoslavov7be9a392013-05-24 05:17:19 +000054 # Get the measurement data and print it
55 cmd = "web/measurement_get_per_flow_install_time.py"
56 r = run_command(cmd) # Tuple: [<stdout>, <stderr>]
57 res = r[0]
58 print res
59
Pavlin Radoslavov1a39b482013-05-21 19:20:10 +000060 # Keep checking until all Flow Paths are installed
61 while True:
62 # time.sleep(3)
63 cmd = ["web/get_flow.py", "all"]
64 r = run_command(cmd)
65 if string.count(r[0], "FlowPath") != flow_n:
66 continue
67 if string.find(r[0], "NOT") == -1:
68 break
69
70 # Remove the installed Flow Paths
71 cmd = ["web/delete_flow.py", "all"]
72 run_command(cmd)
73
74 # Keep checking until all Flows are removed
75 while True:
76 # time.sleep(3)
77 cmd = ["web/get_flow.py", "all"]
78 r = run_command(cmd)
79 if r[0] == "":
80 break
81
82 return msec
83
84
85if __name__ == "__main__":
86
87 # Initial cleanup
88 cmd = "web/measurement_clear_all_paths.py"
89 run_command(cmd)
90
91 # Install the Flow Paths to measure
92 flowdef_filename = "web/flowdef_8node_" + str(flow_n) + ".txt"
93 run_install_paths(flowdef_filename)
94
95 # Do the work
96 for thread_n in threads_n:
97 for n in range(iterations_n):
98 msec = run_measurement(thread_n)
99 # Format: <number of threads> <time in ms>
100 print "%d %f" % (thread_n, msec / flow_n)
101
102 # Cleanup on exit
103 cmd = "web/measurement_clear_all_paths.py"
104 run_command(cmd)