Commit f39c69a7 authored by Deathcrow's avatar Deathcrow

Different method for bandwidth aggregation

parent 45a09f69
#!/usr/bin/env python3
# vim: expandtab shiftwidth=4 softtabstop=4
#iperf -V -Z cubic -t 30 -c fdb2:f689:4248:2bc8::3 -p 12345
import argparse
import copy
import math
import os
import re
import signal
import subprocess
import tempfile
#import threading
import time
def signal_handler(signum, frame):
clean_up()
raise SystemExit
def testy(a,b):
print(a)
print(b)
print(sender)
return 0
def clean_up():
# Clean up
if args.legacy:
tcpprobe.terminate()
if args.tcpdump == "1":
tcpdump.terminate()
if args.cpunetlog != "":
cpunetlog.terminate()
for i in sender:
# if i['utility'].returncode == None:
try:
i['utility'].kill()
except ProcessLookupError:
pass
# i['utility_file'].close()
time.sleep(1)
#def parse_dir(directory):
def qsort1(list):
"""Quicksort using list comprehensions"""
if list == []:
return []
else:
pivot = list[0]
lesser = qsort1([x for x in list[1:] if x < pivot])
greater = qsort1([x for x in list[1:] if x >= pivot])
return lesser + [pivot] + greater
def quantil(list,p):
length = len(list)
len_p = (length * p)-1
if math.ceil(len_p) == len_p:
return ((list[int(len_p)] + list[int(len_p + 1)]) / 2)
else:
return list[math.ceil(len_p)]
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
parser = argparse.ArgumentParser(description='Configure test environment.')
parser.add_argument('folders', nargs="*", default="./", help="Folder to search for files")
parser.add_argument('-m', '--mask', default="")
args = parser.parse_args()
mypid = os.getpid()
#print(args.folders)
#for key, folder in enumerate(args.folders):
# args.folders[key] = os.path.abspath(folder)
args.folders = [os.path.abspath(folder) for folder in args.folders]
print(args.folders)
rtt_values_file = tempfile.TemporaryFile(mode='r+')
bw_values_file = tempfile.TemporaryFile(mode='r+')
netperf_throughput_file = tempfile.TemporaryFile(mode='r+')
netperf_retrans_file = tempfile.TemporaryFile(mode='r+')
rtt_file_lines = 0
bw_file_lines = 0
for folder in args.folders:
for path, dirs, files in os.walk(folder):
for file in files:
if file[:9+len(args.mask)] == "tcpprobe_"+args.mask:
tcpprobe_file = open(path + "/" + file)
for line in tcpprobe_file:
line = line.split(" ")
#print(line[9])
rtt_values_file.write(line[9]+'\n')
rtt_file_lines += 1
tcpprobe_file.close()
elif file[:3+len(args.mask)] == "bw_"+args.mask:
bw_file = open(path + "/" + file)
sum_b = 0
last_bw = (0, 0)
for line in bw_file:
line = line.split(" ")
this_bw = (float(line[0]), float(line[3]))
if this_bw[0] < math.ceil(last_bw[0]):
sum_b+= (this_bw[0] - last_bw[0])*this_bw[1]
elif math.floor(this_bw[0]) - math.ceil(last_bw[0]) >= 1:
for i in range(math.floor(this_bw[0]) - math.ceil(last_bw[0])):
bw_values_file.write("0"+"\n")
#print(math.floor(last_bw[0])+i,0)
sum_b = (this_bw[0] - math.floor(this_bw[0]))*this_bw[1]
else:
sum_b += (math.ceil(last_bw[0]) - last_bw[0]) * float(line[3])
bw_values_file.write(str(sum_b)+"\n")
#print(math.floor(last_bw[0]), sum_b)
sum_b = (this_bw[0] - math.floor(this_bw[0]))*this_bw[1]
last_bw = this_bw
#bw_values_file.write(line[3])
#bw_file_lines += 1
bw_file.close()
elif file[:8+len(args.mask)] == "netperf_"+args.mask:
netperf_file = open(path + "/" + file)
count = 0
for line in netperf_file:
count+=1
if count == 6:
netperf_throughput_file.write(line[11:])
elif count == 42:
netperf_retrans_file.write(line[24:])
netperf_file.close()
bw_values_file.seek(0)
rtt_values_file.seek(0)
netperf_throughput_file.seek(0)
netperf_retrans_file.seek(0)
def statify_list(sorted_list, n):
avg = sum( sorted_list ) / n
std_deviation = math.sqrt((1/(n - 1)) * sum( [ (value-avg)**2 for value in sorted_list ] ))
q_25 = quantil(sorted_list, 0.25)
q_75 = quantil(sorted_list, 0.75)
iqr = q_75 - q_25
bot = sorted_list[0]
top = sorted_list[len(sorted_list) - 1]
whisker_bot = bot
for value in sorted_list:
if value >= (q_25 - iqr*1.5):
whisker_bot = value
break
whisker_top = top
for value in reversed(sorted_list):
if value <= (q_75 + iqr*1.5):
whisker_top = value
break
percent_under_whisker = 0
count = 0
for value in sorted_list:
if value < whisker_bot:
count += 1
else:
percent_under_whisker = (count / n) * 100
break
count = 0
for value in reversed(sorted_list):
if value > whisker_top:
count += 1
else:
percent_over_whisker = (count / n) * 100
break
print("Average:\t"+str(avg))
print("Std. deviation:\t"+str(std_deviation))
print("0.25 Quantil:\t"+str(q_25))
print("0.75 Quantil:\t"+str(q_75))
print("IQR:\t\t"+str(iqr))
print("bot. whisker:\t"+str(whisker_bot))
print("top whisker:\t"+str(whisker_top))
print("% < whisker:\t"+str(percent_under_whisker))
print("% > whisker:\t"+str(percent_over_whisker))
#return list with extreme outliers removed
for value in sorted_list:
if value < (q_25 - iqr*3.0):
del sorted_list[0]
else:
break
for value in reversed(sorted_list):
if value > (q_75 + iqr*3.0):
del sorted_list[len(sorted_list)-1]
else:
break
print("min. without outliers: "+str(sorted_list[0]))
print("max. without outliers: "+str(sorted_list[len(sorted_list)-1]))
print("Std. deviation without outliers: "+str(math.sqrt((1/(n - 1)) * sum( [ (value-avg)**2 for value in sorted_list ] ))))
return sorted_list
sorted_bw = sorted([ float(line) for line in bw_values_file ])
sorted_rtt = sorted([ float(line) for line in rtt_values_file ])
sorted_netperf_throughput = sorted([ float(line) for line in netperf_throughput_file ])
sorted_netperf_retrans = sorted([ float(line) for line in netperf_retrans_file ])
print("Bandwidth: ")
print("=============================")
sorted_bw = statify_list(sorted_bw, len(sorted_bw))
print("")
print("Round Trip Time: ")
print("=============================")
sorted_rtt = statify_list(sorted_rtt, len(sorted_rtt))
print("")
print("Netperf Throughput: ")
print("=============================")
if len(sorted_netperf_throughput) == 1:
sorted_netperf_throughput += sorted_netperf_throughput
sorted_netperf_throughput = statify_list(sorted_netperf_throughput, len(sorted_netperf_throughput))
print("")
print("Netperf Retransmissions: ")
print("=============================")
if len(sorted_netperf_retrans) == 1:
sorted_netperf_retrans += sorted_netperf_retrans
sorted_netperf_retrans = statify_list(sorted_netperf_retrans, len(sorted_netperf_retrans))
#from pylab import *
#boxplot(sorted_bw)
#show()
#boxplot(sorted_rtt)
#show()
#rtt_q_25 = quantil(sorted_rtt, 0.25)
#rtt_q_75 = quantil(sorted_rtt, 0.75)
#rtt_iqr = rtt_q_75 - rtt_q_25
#print(bw_values_file.read())
#print(bw_file_lines)
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