Commit 622afe96 authored by Deathcrow's avatar Deathcrow

small improvements and fixes

parent 72462ba6
......@@ -62,7 +62,8 @@ def process_raw_tcpprobe_file(tcpprobe_file, sender):
bandwith_interval = float(args.samplerate)
line_split = line.split()
for key, i in enumerate(sender):
if line_split[1] == r"["+i['src']+r"]:"+i['src_port']:
if (args.utility == "netperf" and line_split[1] == r"["+i['src']+r"]:"+i['src_port']) \
or (args.utility == "iperf3" and line_split[2] == r"["+i['dst']+r"]:"+i['port']):
# and line_split[2][:-5] == r"["+i['dst']+r"]:":
i['tcpprobe_file'].write(line)
# i['tcpprobe_file'].close()
......@@ -79,8 +80,7 @@ def process_raw_tcpprobe_file(tcpprobe_file, sender):
# i['tcpprobe_seq'] = int(line_split[4], 0)
tcpprobe_file.close()
def process_proc_tcpprobe(sender): #sampling
starty = time.perf_counter()
def process_proc_tcpprobe(sender, while_start): #sampling
tcpprobe_proc = open("/proc/net/tcpprobe", "r")
unprocessed_senders = sender.copy()
......@@ -107,8 +107,7 @@ def process_proc_tcpprobe(sender): #sampling
def process_proc_tcpprobe_optimized(sender): #sampling
starty = time.perf_counter()
def process_proc_tcpprobe_optimized(sender, while_start): #sampling
unprocessed_senders = set([key for key in range(len(sender))])
tcpprobe_proc = open("/proc/net/tcpprobe", "r")
tcpprobe_poll = select.poll()
......@@ -116,12 +115,12 @@ def process_proc_tcpprobe_optimized(sender): #sampling
# collect line from tcpprobe and write to file if it belongs to a
# unprocessed (one that didn't have a line written yet) sender
while (len(unprocessed_senders) > 0) and (time.perf_counter() - starty < float(args.samplerate)) and tcpprobe_poll.poll(int(float(args.samplerate) * 1000)): # find line matching all senders && TIMEOUT
while (len(unprocessed_senders) > 0) and (time.perf_counter() - while_start < float(args.samplerate)) and tcpprobe_poll.poll(int(float(args.samplerate) * 1000)): # find line matching all senders && TIMEOUT
line_split = tcpprobe_proc.readline().split(" ")
# try to match current tcpprobe line against all unprocessed senders
for key in unprocessed_senders:
if (line_split[1] == r"["+sender[key]['src']+r"]:"+sender[key]['src_port']):
# or (args.utility == "iperf3" and line_split[2] == r"["+sender[key]['dst']+r"]:"+sender[key]['port']): #<=== use if src_port doesn't work with iperf3
if (args.utility == "netperf" and line_split[1] == r"["+sender[key]['src']+r"]:"+sender[key]['src_port']) \
or (args.utility == "iperf3" and line_split[2] == r"["+sender[key]['dst']+r"]:"+sender[key]['port']): #<=== use if src_port doesn't work with iperf3
# write time + current tcpprobe line to file for this sender
unprocessed_senders.discard(key)
time_dif = time.perf_counter() - start_time
......@@ -185,7 +184,8 @@ parser.add_argument('-u', '--utility', default="netperf", \
help="For iperf3 support run multiple iperf3 servers and specify ports per sender") ## XXX Note: iperf3 support is not tested extensively!!
parser.add_argument('-t', '--time', default="60")
parser.add_argument('-s', '--sender', action='append', nargs='+', required=True, \
help="Specify senders: <src ip>#<dst ip>#<port>#<congestion>#<number>#<interface> -- individual specifications overwrite globals")
help="Specify senders: <src ip>#<dst ip>#<port>#<congestion>#<number>#<interface> -- individual specifications overwrite globals. "+\
"Example: -s 10.0.0.1#10.0.0.2##yeah#2 -- Creates 2 senders using yeah, without changing the global port (-p)")
## "--receiver" sets the receiver if there was no receiver was specified
# (XXX same for --port, etc)
parser.add_argument('-r', '--receiver', default="localhost")
......@@ -195,7 +195,7 @@ parser.add_argument('-Z', '--congestion', default="cubic")
parser.add_argument('-N', '--no-delay', action='store_true')
parser.add_argument('-4', '--use-ipv4', action='store_true')
parser.add_argument('-n', '--number-senders', default="1", \
help="Amount of clones per specified sender")
help="Amount of clones per sender")
parser.add_argument('-C', '--comment', default="", \
help="Path to a (txt) file to be included in the final Tarball")
parser.add_argument('-P', '--cpunetlog' , default="", \
......@@ -205,7 +205,7 @@ parser.add_argument("--netperf-dataport", default=str(random.randint(15000,65000
parser.add_argument('-D', '--tcpdump', default="0", \
help="Enable/Disable tcpdump (Default: disabled")
parser.add_argument('-S', '--samplerate', default="0.1", \
help="Samplerate for measurements: Sleeptime between samples (in seconds)")
help="Samplerate for measurements: Defines amount of seconds between samples")
parser.add_argument('--legacy', action='store_true', \
help="Record entire tcp_probe output instead of samples by samplerate. \
Can be less CPU intensive for certain samplerates. \
......@@ -334,8 +334,9 @@ with multiprocessing.Pool(len(sender)) as pool:
## Find out which src_port belongs to which sender (not necessary for netperf) ##
# TODO: FIXME, SLEEP AS A WORKAROUND IS UNRELIABLE AND DIRTY.
# Disabled, we can use port for iperf because we have multiple servers anyway
if args.utility != "netperf":
if 0 and args.utility != "netperf":
time.sleep(0.1) # sacrifice first-born to satan
ss_file = tempfile.TemporaryFile(mode='r+')
subprocess.call(["ss", "-t", "-i", "-p", "-n"],stdout=ss_file)
......@@ -381,11 +382,11 @@ if args.utility != "netperf":
######## MAIN LOOP ########
if not args.legacy:
while (time.perf_counter() - start_time) < (float(args.time)-float(args.samplerate)):
while (time.perf_counter() - start_time) < (float(args.time)-2*float(args.samplerate)):
# print("begin while")
while_start = time.perf_counter() # remember beginning of this loop
process_proc_tcpprobe_optimized(sender) # <-- heavy lifting here
process_proc_tcpprobe_optimized(sender, while_start) # <-- heavy lifting here
try:
# sleep samplerate minus time spent in loop
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment