def get_moving_avg(fptr,idir,odir,nfiles): ''' Fn to plot max link utilizations ''' window = 20 transdur= int(gen.get_param(fptr,"TRANS_DUR")) numslices = int(gen.get_param(fptr,"numslices")) init_pert = int(gen.get_param(fptr,"Range for Initial Random Wt")) iter_dur = int(gen.get_param(fptr,"ITER_DUR")) max = [] for i in range(1,nfiles): try: fp = gz.open(idir + str(i)) except: break util = 0 lines = fp.readlines() for line in lines: line = line.split() if float(line[5]) > util: util = float(line[5]) max.append(util) fp.close() avgarr = [] for i in range(window,len(max)): tmp = max[i-window:i+1] avg = np.average(tmp) avgarr.append(avg) fp = open(odir+"avgmax"+".txt","w") for i in range(1,window): fp.write("%s %.2f 0\n"%(i,max[i])) for i in range(window,len(max)): fp.write("%s %.2f %.2f\n"%(i,max[i-1],avgarr[i-window])) fp.close()
def plot(fptr,rid = None): ''' Fn to plot output. Get output dir from input config, call appropriate plotting fn ''' output_dir = gen.get_param(fptr,"outdir") + "/" topo = gen.get_param(fptr,"topo_name") + "/" max = 0 if rid == None: idir = output_dir + topo dir = os.listdir(idir) for d in dir: if "run" not in d: continue cid = int(d.split("run")[1]) if cid > max: max = cid rid = max idir = output_dir + topo + "run"+str(rid) + "/" odir = idir.replace("output","plots") os.system("mkdir -p " + odir) simdur = int(gen.get_param(fptr,"SIM_DUR")) iter_dur = int(gen.get_param(fptr,"ITER_DUR")) nfiles = simdur/iter_dur plot_utils(fptr,idir,odir,nfiles) get_moving_avg(fptr,idir,odir,nfiles) plot_cmp(fptr,idir,odir,nfiles)
def get_moving_avg(fptr, idir, odir, nfiles): ''' Fn to plot max link utilizations ''' window = 20 transdur = int(gen.get_param(fptr, "TRANS_DUR")) numslices = int(gen.get_param(fptr, "numslices")) init_pert = int(gen.get_param(fptr, "Range for Initial Random Wt")) iter_dur = int(gen.get_param(fptr, "ITER_DUR")) max = [] for i in range(1, nfiles): try: fp = gz.open(idir + str(i)) except: break util = 0 lines = fp.readlines() for line in lines: line = line.split() if float(line[5]) > util: util = float(line[5]) max.append(util) fp.close() avgarr = [] for i in range(window, len(max)): tmp = max[i - window:i + 1] avg = np.average(tmp) avgarr.append(avg) fp = open(odir + "avgmax" + ".txt", "w") for i in range(1, window): fp.write("%s %.2f 0\n" % (i, max[i])) for i in range(window, len(max)): fp.write("%s %.2f %.2f\n" % (i, max[i - 1], avgarr[i - window])) fp.close()
def plot(fptr, rid=None): ''' Fn to plot output. Get output dir from input config, call appropriate plotting fn ''' output_dir = gen.get_param(fptr, "outdir") + "/" topo = gen.get_param(fptr, "topo_name") + "/" max = 0 if rid == None: idir = output_dir + topo dir = os.listdir(idir) for d in dir: if "run" not in d: continue cid = int(d.split("run")[1]) if cid > max: max = cid rid = max idir = output_dir + topo + "run" + str(rid) + "/" odir = idir.replace("output", "plots") os.system("mkdir -p " + odir) simdur = int(gen.get_param(fptr, "SIM_DUR")) iter_dur = int(gen.get_param(fptr, "ITER_DUR")) nfiles = simdur / iter_dur plot_utils(fptr, idir, odir, nfiles) get_moving_avg(fptr, idir, odir, nfiles) plot_cmp(fptr, idir, odir, nfiles)
def __init__(self,fptr,topo,tmtype): self.tmtype = tmtype self.gen_flag = int(gen.get_param(fptr,'TMgenerate')) self.FRAC_UTIL= float(gen.get_param(fptr,'FRAC_UTIL')) self.tm = {} self.topo_name = gen.get_param(fptr,'topo_name') #self.base_dir = 'data/traffic/matrices/' self.base_dir = gen.get_param(fptr,"tm_dir") self.tm_name = gen.get_param(fptr,"tm_name") for s in topo: self.tm[s] = {} for d in topo: self.tm[s][d] = 0.0
def plot_utils(fptr,idir,odir,nfiles): ''' Fn to plot all link utilizations ''' transdur= int(gen.get_param(fptr,"TRANS_DUR")) numslices = int(gen.get_param(fptr,"numslices")) init_pert = int(gen.get_param(fptr,"Range for Initial Random Wt")) iter_dur = int(gen.get_param(fptr,"ITER_DUR")) out = {} for i in range(1,nfiles): try: fp = gz.open(idir + str(i)) except: break lines = fp.readlines() #print idir+str(i) for line in lines: #print line line = line.split() link = line[0] + "-" + line[1] try: out[link].append(line[5]) except: out[link] = [] fp.close() #outlink = ["4-7","5-8","6-9"] outlink = out #cr = 'Static Traffic on ' #leg = [cr + "Link 1", cr + "Link 2", cr + 'Link 3'] #fig = plt.figure(num=None, figsize=(8,3.5)) #fig.subplots_adjust(bottom=0.15) p = [] for link in outlink: x = range(0,len(out[link])) x = (np.array(x) - 200)*5 p.append(plt.plot(x,out[link])[0]) plt.ylim(ymin=0,ymax=1.5) #plt.title("#of topos:" + str(numslices) + \ #" Iter duration:" + str(iter_dur)) #plt.xlim(xmin=1000/iter_dur) #plt.xlim(xmin=0) plt.xlabel("Iterations",fontsize=18) plt.xlabel("Time",fontsize=18) plt.ylabel("Offered Load",fontsize=18) #plt.legend(p,leg,loc=0) plt.savefig(odir+"utilization-" + str(link) + ".eps") plt.clf()
def __init__(self,fptr,otopo,otm): self.total_agg_arr = 0 # Accounting flows # self.total_agg_dep = 0 # '' # self.agg_arr = {} self.agg_dep = {} self.inst_load = {} self.routed_flows = 0 self.queue = [] # the event queue. Contains time of next flow arrival - # - departure, and all iterations. # for s in otm.tm: self.agg_arr[s] = {} # Accounting flows # self.agg_dep[s] = {} self.inst_load[s] = {} for d in otm.tm[s]: self.agg_arr[s][d] = 0 self.agg_dep[s][d] = 0 self.inst_load[s][d] = 0 #event = {"type":"","time":-1} self.numslices = int(gen.get_param(fptr,"numslices")) self.sim_dur = int(gen.get_param(fptr,"SIM_DUR")) self.iter_dur = int(gen.get_param(fptr,"ITER_DUR")) self.trans_dur = int(gen.get_param(fptr,"TRANS_DUR")) self.static_load = gen.get_param(fptr,"STATIC_LOAD") for iter in range(self.iter_dur,self.sim_dur,self.iter_dur): #iter events # event = {"type":"iter","time":iter} self.insert(event) self.add_static_load_events(otopo) updatetype = gen.get_param(fptr,"Link Weight Update") # link update algo # if updatetype.lower() == "keymetric_std": self.olinkupdate = update.keymetric_std(fptr,otopo) # link update obj # if updatetype.lower() == "keymetric_ecmp": self.olinkupdate = update.keymetric_ecmp(fptr,otopo) # link update obj # if updatetype.lower() == "static": self.trans_dur = self.sim_dur self.outfile = gen.get_param(fptr,"outdir") # output directory # topo_name = gen.get_param(fptr,"topo_name") self.outfile += "/" + topo_name + "/" try: # check and prepare output dir # dir = os.listdir(self.outfile) except: print self.outfile os.system("mkdir -p " + self.outfile) dir = [] fn = -1 for i in dir: if "run" not in i: continue i = i.split("run")[1] if int(i) > fn: fn = int(i) fn += 1 self.outfile += ("run" + str(fn) + "/") os.system("mkdir " + self.outfile) #print "cp input " + self.outfile # store input params assoc with this run #os.system("cp input " + self.outfile) gen.cp_file(fptr,self.outfile,"input")
def plot_utils(fptr, idir, odir, nfiles): ''' Fn to plot all link utilizations ''' transdur = int(gen.get_param(fptr, "TRANS_DUR")) numslices = int(gen.get_param(fptr, "numslices")) init_pert = int(gen.get_param(fptr, "Range for Initial Random Wt")) iter_dur = int(gen.get_param(fptr, "ITER_DUR")) out = {} for i in range(1, nfiles): try: fp = gz.open(idir + str(i)) except: break lines = fp.readlines() #print idir+str(i) for line in lines: #print line line = line.split() link = line[0] + "-" + line[1] try: out[link].append(line[5]) except: out[link] = [] fp.close() #outlink = ["4-7","5-8","6-9"] outlink = out #cr = 'Static Traffic on ' #leg = [cr + "Link 1", cr + "Link 2", cr + 'Link 3'] #fig = plt.figure(num=None, figsize=(8,3.5)) #fig.subplots_adjust(bottom=0.15) p = [] for link in outlink: x = range(0, len(out[link])) x = (np.array(x) - 200) * 5 p.append(plt.plot(x, out[link])[0]) plt.ylim(ymin=0, ymax=1.5) #plt.title("#of topos:" + str(numslices) + \ #" Iter duration:" + str(iter_dur)) #plt.xlim(xmin=1000/iter_dur) #plt.xlim(xmin=0) plt.xlabel("Iterations", fontsize=18) plt.xlabel("Time", fontsize=18) plt.ylabel("Offered Load", fontsize=18) #plt.legend(p,leg,loc=0) plt.savefig(odir + "utilization-" + str(link) + ".eps") plt.clf()
def initialize(fptr): otopo = topo.Topology(fptr) # create topo object # otm = tmc.get_TMgen(fptr, otopo.L) # create traffic matrix (TM) object # # We just created the structure of TM # instantiated with all 0's traffic volumes. # Now we fill these or read from file # (depends on 'TMgenerate' in the config file). otm.generate(otopo.L) # generate the TM # print("TM after generation:", otm.tm) oflowgen = flow.flowgen(fptr, otm.tm) # create flow generator object # oevent = event.event(fptr, otopo, otm) # create event simulator object # sim_dur = int(gen.get_param(fptr, "SIM_DUR")) # duration of simulation # oevent.insert(oflowgen.next(otm.tm)) # insert first event # #loadev = {"type":"load-surge","time":1000,"surgetype":"random","num":5} #oevent.insert(loadev) while True: currev = oevent.pop() # pop event from queue # if currev["time"] > sim_dur: # time # break oevent.handler(currev, otopo, otm) # handle current event # if currev[ "type"] == "flow-arr": # if event is flow arrival, inseert next - oevent.insert(oflowgen.next(otm.tm)) # - arrival in event queue
def __init__(self,fptr,G): short_paths = gen.get_param(fptr,"Short Paths") if short_paths.upper() == 'SP': self.oshort_paths = noecmproute(G) if short_paths.upper() == 'ECMPSP': self.oshort_paths = ecmproute(G) if short_paths.upper() == 'FLUIDECMPSP': self.oshort_paths = fluidecmproute(G)
def __init__(self, fptr, G): short_paths = gen.get_param(fptr, "Short Paths") if short_paths.upper() == 'SP': self.oshort_paths = noecmproute(G) if short_paths.upper() == 'ECMPSP': self.oshort_paths = ecmproute(G) if short_paths.upper() == 'FLUIDECMPSP': self.oshort_paths = fluidecmproute(G)
def plot_cmp(fptr,idir,odir,nfiles): odatdir = odir.replace("plots","output") print odatdir fip = gen.get_input(odatdir+"/input") topo_name = gen.get_param(fip,"topo_name") init_wt = gen.get_param(fip,"Initial Wt setting") algo = gen.get_param(fip,"link weight update") tm_name = gen.get_param(fip,"tm_name") fo = open("tmp","a") if algo.lower() == 'keymetric_ecmp': fo.write(" km %s\n"%(tm_name)) if algo.lower() == 'static' and init_wt.lower() == 'inv_cap': fo.write(" inv_cap %s\n"%(tm_name)) if algo.lower() == 'static' and init_wt.lower() == 'base_rand': fo.write(" thorup %s\n"%(tm_name)) fo.close()
def get_TMgen(fptr,topo): ''' Fn to instantiate object depending on specified TM model ''' tmtype = gen.get_param(fptr,"tmtype") if tmtype == 'GRAVITY': tm = gravityTMgen(fptr,topo,tmtype) if tmtype == 'BIMODAL': tm = bimodalTMgen(fptr,topo,tmtype) return tm
def plot_cmp(fptr, idir, odir, nfiles): odatdir = odir.replace("plots", "output") print odatdir fip = gen.get_input(odatdir + "/input") topo_name = gen.get_param(fip, "topo_name") init_wt = gen.get_param(fip, "Initial Wt setting") algo = gen.get_param(fip, "link weight update") tm_name = gen.get_param(fip, "tm_name") fo = open("tmp", "a") if algo.lower() == 'keymetric_ecmp': fo.write(" km %s\n" % (tm_name)) if algo.lower() == 'static' and init_wt.lower() == 'inv_cap': fo.write(" inv_cap %s\n" % (tm_name)) if algo.lower() == 'static' and init_wt.lower() == 'base_rand': fo.write(" thorup %s\n" % (tm_name)) fo.close()
def __init__(self,fptr,tm): self.time = 0 self.flowid = 0 fsize = gen.get_param(fptr,"Flow Size") if fsize.lower() == 'exponential': self.sizegen = size_exp(fptr) # object for flow size generation if fsize.lower() == 'pareto': self.sizegen = size_pareto(fptr) # object for flow size generation arrprocess = gen.get_param(fptr,"Flow Arrival") if arrprocess.lower() == 'poisson': # object for flow arrival self.arrival = arr_poisson(fptr,tm,self.sizegen.avgflowsize()) tput = gen.get_param(fptr,"Flow Tput") if tput.lower() == 'standard': self.tput = tput_std() # object for throughput assignment self.numslices = int(gen.get_param(fptr,"numslices")) self.routing = gen.get_param(fptr,"routing")
def __init__(self,fptr): topo_dir = gen.get_param(fptr,"topo_dir") IP_FILE = topo_dir + gen.get_param(fptr,"ip_file") TOPO_FILE = topo_dir + gen.get_param(fptr,"topo_file") numslices = int(gen.get_param(fptr,"numslices")) self.init_wt_rnd_range = int(gen.get_param(fptr,"Range for initial Random Wt")) self.initwttype = gen.get_param(fptr,"Initial Wt setting") self.duplex = gen.get_param(fptr,"duplex") routing = gen.get_param(fptr,"Routing") self.numslices = numslices self.get_node_ips(IP_FILE) self.create_full_topo(TOPO_FILE) self.get_routing_scheme(fptr,routing)
def __init__(self, fptr): topo_dir = gen.get_param(fptr, "topo_dir") IP_FILE = topo_dir + gen.get_param(fptr, "ip_file") TOPO_FILE = topo_dir + gen.get_param(fptr, "topo_file") numslices = int(gen.get_param(fptr, "numslices")) self.init_wt_rnd_range = int( gen.get_param(fptr, "Range for initial Random Wt")) self.initwttype = gen.get_param(fptr, "Initial Wt setting") self.duplex = gen.get_param(fptr, "duplex") routing = gen.get_param(fptr, "Routing") self.numslices = numslices self.get_node_ips(IP_FILE) self.create_full_topo(TOPO_FILE) self.get_routing_scheme(fptr, routing)
def algo_setting(fptr, algo): if algo == 'pste': fptr = gen.modify_param(fptr, 'initial wt setting', 'base_rand') #Mohammed - it was inv_cap! fptr = gen.modify_param(fptr, 'link weight update', 'KeyMetric_ecmp') #fptr = gen.modify_param(fptr,'numslices',3) if algo == 'thorup': fptr = gen.modify_param(fptr, 'initial wt setting', 'base_rand') fptr = gen.modify_param(fptr, 'link weight update', 'static') fptr = gen.modify_param(fptr, 'numslices', 1) if algo == 'inv_cap': fptr = gen.modify_param(fptr, 'initial wt setting', 'inv_cap') fptr = gen.modify_param(fptr, 'link weight update', 'static') fptr = gen.modify_param(fptr, 'numslices', 1) out = gen.get_param(fptr, "outdir") fptr = gen.modify_param(fptr, 'outdir', out + algo + "/") return fptr
def __init__(self,fptr,otopo): self.oroute = route.fluidecmproute(otopo.G) # obj oroute uses fluid ecmp # - model this ensures we get all paths that pass through a (s,d) pair # self.nkeymetric = int(gen.get_param(fptr,"Number of Key metrics")) self.links_to_avoid = gen.get_param(fptr,"Links to avoid criterion") #if self.links_to_avoid.lower() == 'topn': self.perc_nlinks_to_avoid = float(gen.get_param(fptr,"Maximum percentage of links to avoid")) if self.links_to_avoid.lower() in ['skew','combo','rescap','rescapnorm'] : self.skew_threshold = float(gen.get_param(fptr,"Skew threshold")) self.maxrescap = float(gen.get_param(fptr,"Max residual capacity")) #max_nlinks_to_avoid = int(gen.get_param(fptr,"Maximum number of links to avoid")) totnlinks = otopo.count_nlinks() max_nlinks_to_avoid = self.perc_nlinks_to_avoid * totnlinks nperclinks = int(np.ceil(self.perc_nlinks_to_avoid*totnlinks)) self.max_nlinks_to_avoid = max(nperclinks,max_nlinks_to_avoid) print 'Max nlinks to avoid %s'%(self.max_nlinks_to_avoid) self.thres_theta = float(gen.get_param(fptr,"Threshold theta"))
def __init__(self, fptr, otopo): self.oroute = route.fluidecmproute( otopo.G) # obj oroute uses fluid ecmp # - model this ensures we get all paths that pass through a (s,d) pair # self.nkeymetric = int(gen.get_param(fptr, "Number of Key metrics")) self.links_to_avoid = gen.get_param(fptr, "Links to avoid criterion") #if self.links_to_avoid.lower() == 'topn': self.perc_nlinks_to_avoid = float( gen.get_param(fptr, "Maximum percentage of links to avoid")) if self.links_to_avoid.lower() in [ 'skew', 'combo', 'rescap', 'rescapnorm' ]: self.skew_threshold = float(gen.get_param(fptr, "Skew threshold")) self.maxrescap = float(gen.get_param(fptr, "Max residual capacity")) #max_nlinks_to_avoid = int(gen.get_param(fptr,"Maximum number of links to avoid")) totnlinks = otopo.count_nlinks() max_nlinks_to_avoid = self.perc_nlinks_to_avoid * totnlinks nperclinks = int(np.ceil(self.perc_nlinks_to_avoid * totnlinks)) self.max_nlinks_to_avoid = max(nperclinks, max_nlinks_to_avoid) print 'Max nlinks to avoid %s' % (self.max_nlinks_to_avoid) self.thres_theta = float(gen.get_param(fptr, "Threshold theta"))
def __init__(self, fptr, otopo, otm): self.total_agg_arr = 0 # Accounting flows # self.total_agg_dep = 0 # '' # self.agg_arr = {} self.agg_dep = {} self.inst_load = {} self.routed_flows = 0 self.queue = [ ] # the event queue. Contains time of next flow arrival - # - departure, and all iterations. # for s in otm.tm: self.agg_arr[s] = {} # Accounting flows # self.agg_dep[s] = {} self.inst_load[s] = {} for d in otm.tm[s]: self.agg_arr[s][d] = 0 self.agg_dep[s][d] = 0 self.inst_load[s][d] = 0 #event = {"type":"","time":-1} self.numslices = int(gen.get_param(fptr, "numslices")) self.sim_dur = int(gen.get_param(fptr, "SIM_DUR")) self.iter_dur = int(gen.get_param(fptr, "ITER_DUR")) self.trans_dur = int(gen.get_param(fptr, "TRANS_DUR")) self.static_load = gen.get_param(fptr, "STATIC_LOAD") for iter in range(self.iter_dur, self.sim_dur, self.iter_dur): #iter events # event = {"type": "iter", "time": iter} self.insert(event) self.add_static_load_events(otopo) updatetype = gen.get_param(fptr, "Link Weight Update") # link update algo # if updatetype.lower() == "keymetric_std": self.olinkupdate = update.keymetric_std(fptr, otopo) # link update obj # if updatetype.lower() == "keymetric_ecmp": self.olinkupdate = update.keymetric_ecmp( fptr, otopo) # link update obj # if updatetype.lower() == "static": self.trans_dur = self.sim_dur self.outfile = gen.get_param(fptr, "outdir") # output directory # topo_name = gen.get_param(fptr, "topo_name") self.outfile += "/" + topo_name + "/" try: # check and prepare output dir # dir = os.listdir(self.outfile) except: print self.outfile os.system("mkdir -p " + self.outfile) dir = [] fn = -1 for i in dir: if "run" not in i: continue i = i.split("run")[1] if int(i) > fn: fn = int(i) fn += 1 self.outfile += ("run" + str(fn) + "/") #os.system("mkdir " + self.outfile) if not os.path.exists(self.outfile): os.makedirs(self.outfile) #print "cp input " + self.outfile # store input params assoc with this run #os.system("cp input " + self.outfile) gen.cp_file(fptr, self.outfile, "input")
def __init__(self,fptr): self.param = float(gen.get_param(fptr,"Lambda"))
def __init__(self,fptr,tm,flowsize): self.simdur = float(gen.get_param(fptr,"SIM_DUR")) self.flowsize = flowsize self.allnextarr = [] self.initarrivals(tm)
def __init__(self,fptr): self.alpha = 1.3 self.param = float(gen.get_param(fptr,"Lambda")) self.U = 8000 #self.L = self.param*(self.alpha-1)/self.alpha self.L = float(gen.get_param(fptr,"Pareto L"))