from helper import *
parser = argparse.ArgumentParser()
parser.add_argument('--files', '-f',
help="Rate timeseries output to one plot",
required=True,
action="store",
nargs='+',
dest="files")
#parser.add_argument('--files_dcell', '-d',
# help="Rate timeseries output to one plot",
# required=True,
# action="store",
# nargs='+',
# dest="files_dcell")
parser.add_argument('--legend', '-l',
help="Legend to use if there are multiple plots. File names used as default.",
action="store",
nargs="+",
default=None,
dest="legend")
parser.add_argument('--out', '-o',
help="Output png file for the plot.",
default=None, # Will show the plot
dest="out")
parser.add_argument('-s', '--summarise',
help="Summarise the time series plot (boxplot). First 10 and last 10 values are ignored.",
default=False,
dest="summarise",
action="store_true")
parser.add_argument('--labels',
help="Labels for x-axis if summarising; defaults to file names",
required=False,
default=[],
nargs="+",
dest="labels")
parser.add_argument('--xlabel',
help="Custom label for x-axis",
required=False,
default=None,
dest="xlabel")
parser.add_argument('--ylabel',
help="Custom label for y-axis",
required=False,
default=None,
dest="ylabel")
parser.add_argument('-i',
help="Interfaces to plot (regex)",
default=".*",
dest="pat_iface")
parser.add_argument('--rx',
help="Plot receive rates on the interfaces.",
default=False,
action="store_true",
dest="rx")
parser.add_argument('--maxy',
help="Max mbps on y-axis..",
default=400,
action="store",
dest="maxy")
parser.add_argument('--miny',
help="Min mbps on y-axis..",
default=0,
action="store",
dest="miny")
parser.add_argument('--normalize',
help="normalise y-axis",
default=False,
action="store_true",
dest="normalise")
args = parser.parse_args()
if args.labels is None:
args.labels = args.files
pat_iface = re.compile(args.pat_iface)
#print pat_iface
to_plot=[]
"""Output of bwm-ng csv has the following columns:
unix_timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in
"""
if args.normalise and args.labels == []:
raise "Labels required if summarising/normalising."
sys.exit(-1)
bw = map(lambda e: int(e.replace('M','')), args.labels)
idx = 0
#data_tree =[]
data_dcell =[]
#for f in args.files:
# data_tree = read_list(f)
#print "tree-tt"
#for f in args.files_dcell:
for f in args.files:
data_dcell = read_list(f)
rate = {}
#def isWantedTreeInterface(ifname):
# if ((ifname not in ['lo'])and (('eth3' in ifname )and (not 's0-eth3' in ifname)and (not 's1-eth3' in ifname)and (not 's2-eth3' in ifname)and (not 's3-eth3' in ifname)and (not 's4-eth3' in ifname)and (not 's5-eth3' in ifname)and (not 's6-eth3' in ifname)and (not 's7-eth3' in ifname)and (not 's8-eth3' in ifname)and (not 's9-eth3' in ifname)and (not 's10-eth3' in ifname)and (not 's11-eth3' in ifname)or( ('eth4' in ifname )and (not 's0-eth4' in ifname)and (not 's1-eth4' in ifname)and (not 's2-eth4' in ifname)and (not 's3-eth4' in ifname)and (not 's4-eth4' in ifname)and (not 's5-eth4' in ifname)and (not 's6-eth4' in ifname)and (not 's7-eth4' in ifname)and (not 's8-eth4' in ifname)and (not 's9-eth4' in ifname)and (not 's10-eth4' in ifname)and (not 's11-eth4' in ifname)))):
#or( ('eth2' in ifname )and (not 's0-eth2' in ifname)and (not 's1-eth2' in ifname)and (not 's2-eth2' in ifname)and (not 's3-eth2' in ifname)and (not 's4-eth2' in ifname)and (not 's5-eth2' in ifname)and (not 's6-eth2' in ifname)and (not 's7-eth2' in ifname)and (not 's8-eth2' in ifname)and (not 's9-eth2' in ifname)and (not 's10-eth2' in ifname)and (not 's11-eth2' in ifname))
#and ('s12-eth3' in ifname )and ('s12-eth4' in ifname )and ('s13-eth3' in ifname )and ('s13-eth4' in ifname )and ('s14-eth3' in ifname )and ('s14-eth4' in ifname )and ('s15-eth3' in ifname )and ('s15-eth4' in ifname )and ('s16-eth3' in ifname )and ('s16-eth4' in ifname )and ('s17-eth3' in ifname )and ('s17-eth4' in ifname )and ('s18-eth3' in ifname )and ('s18-eth4' in ifname )and ('s19-eth3' in ifname )and ('s19-eth4' in ifname )
# and ('eth0' in ifname )):
#and (not 's0-eth0' in ifname)and (not 's1-eth0' in ifname)and (not 's2-eth0' in ifname)and (not 's3-eth0' in ifname)):
#print "tree "
# return True
# return False
def isWantedDCellInterface(ifname):
#if ((ifname not in ['lo']) and ('eth0' in ifname ) and (not 's0-eth0' in ifname)):
if ((ifname not in ['lo']) and ('eth0' in ifname ) and (not 's0-eth0' in ifname) and (not 's1-eth0' in ifname)and (not 's2-eth0' in ifname)and (not 's3-eth0' in ifname)and (not 's4-eth0' in ifname)):
return True
return False
def populate_rate(data, ratei, ag_ifname, topo):
#xaxis = map(float, col(0, data))
#start_time = xaxis[0]
#xaxis = map(lambda x: x - start_time, xaxis)
#rate = map(float, col(2, data))
column = 2
if args.rx:
column = 3
cur_time_stamp = data[0][0]
#print cur_time_stamp
if not rate.has_key(ag_ifname):
rate[ag_ifname] = []
local_rate = 0.0
cur_rate_sum = 0.0
count = 0.0
for row in data:
try:
ifname = row[1]
except:
break
if ifname not in ['lo']:
if not rate.has_key(ifname):
rate[ifname] = []
try:
rate_l = float(row[column]) * 8.0 / (1 << 20)
rate[ifname].append(rate_l)
except:
break
for row in data:
try:
ifname = row[1]
#print ifname
except:
break
if ((topo=='dcell' and isWantedDCellInterface(ifname))):
#((topo=='tree' and isWantedTreeInterface(ifname))):
# or (topo=='dcell' and isWantedDCellInterface(ifname))):
#print ifname
#print "topo is tree"
time_stamp = row[0]
#print time_stamp
#if (ifname not in ['eth1'] and ifname not in ['eth2']):
if (time_stamp == cur_time_stamp) :
#print ifname
#print row[column]
#print "equal"
cur_rate = float(row[column])
cur_rate_sum += cur_rate
count = count +1
#print "calculate aggregate throughput1"#
#print cur_rate_sum
#print count
else:
#print "not equal"
try:
#print "_______________________________________________________________"
#print count
#print cur_rate_sum/count
#cur_rate_sum = cur_rate_sum / count
cur