def geninput(self): # Return a list of flows flowlist = [] # print 'Generating input' if not self.hasInput: for fid in range(self.MAXNUMFLOW): flow = Flow.Flow() flow.flowId = fid flow.SetFlowSize(round(random.expovariate(1 / self.FLOWSIZEMEAN))) # deadline is in number of RTTs ddlinsteps = int(round(random.expovariate(1 / self.FLOWDDLMEAN) / self.RTT)) while ddlinsteps >= self.Steps - 1: ddlinsteps = int(round(random.expovariate(1 / self.FLOWDDLMEAN) / self.RTT)) flow.SetFlowDeadline(ddlinsteps) # print 'flow {} time for choice: {}'.format(fid, (Steps - flow.deadline)) flow.startTime = random.choice(range(self.Steps - flow.deadline)) # initial window flow.bw = 10 * PKTSIZE / self.RTT flow.residualRate = 0 flowlist.append(flow) else: with open(self.inputf) as inputf: tempflows = json.load(inputf) for i in range(len(tempflows)): flow = Flow.Flow() flow.flowId = i flow.SetFlowSize(tempflows['{}'.format(i)]['flowSize']) flow.SetFlowDeadline(tempflows['{}'.format(i)]['deadline']) flow.startTime = tempflows['{}'.format(i)]['startTime'] flow.bw = 10 * PKTSIZE / self.RTT flow.residualRate = 0 flowlist.append(flow) return flowlist
def AssignFlowsCSV(self, filename="Input/trace.csv"): f = open(filename, "r") for line in f.readlines(): l = line.rstrip('\r\n').split(',') print l flow = Flow() flow.startId = int(l[0]) flow.endId = int(l[2]) flow.SetFlowSize(float(l[6])) flow.startTime = float(l[4]) flow.coflowId = int(l[5]) flow.flowId = len(self.flows) + 1 self.flows.append(flow) FlowScheduler.AssignFlows(self) f.close()
def AssignFlows(self, args): """ The args is a tuple containing: K, S, L, a, which are following the parameters in GenFlowInput.py """ self.K = int(args[0]) self.flowSize = float(args[1]) self.mean = int(args[2]) self.avgFlowNums = int(args[3]) self.alpha = float(args[4]) f_name = inDir + "K%d_S%0.0f_L%d_a%d_flows.txt" \ % (self.K, self.flowSize, self.mean, self.avgFlowNums) f = open(f_name, "r") for line in f.readlines(): l = line.split() flow = Flow() flow.startId = int(l[0]) flow.endId = int(l[1]) flow.SetFlowSize(float(l[2])) flow.startTime = float(l[3]) flow.flowId = len(self.flows) + 1 self.flows.append(flow) FlowScheduler.AssignFlows(self) f.close()
def AssignFlows(self, args): """ The args is a tuple containing: K, S, L, a, which are following the parameters in GenFlowInput.py """ self.flowSize = float(args[0]) self.mean = int(args[1]) self.avgFlowNums = int(args[2]) self.alpha = float(args[3]) f_name = inDir + "S%0.0f_L%d_a%d_flows.txt" \ % (self.flowSize, self.mean, self.avgFlowNums) f = open(f_name, "r") for line in f.readlines(): l = line.split() flow = Flow() flow.startId = int(l[0]) flow.endId = int(l[1]) flow.SetFlowSize(float(l[2])) flow.startTime = float(l[3]) flow.flowId = len(self.flows) + 1 self.flows.append(flow) FlowScheduler.AssignFlows(self) f.close()
def AssignFlows(self, filename="Input/trace.csv"): print sum(1 for li in open(filename,'r')) f = open(filename, "r") coflowsize = {} coflowwidth = {} line_count = 0 for line in f.readlines(): l = line.rstrip('\r\n').split(',') line_count += 1 if line_count ==500: break for i in range(1): # print l flow = Flow() flow.startId = choice(range(180)) + int(l[0]) flow.endId = choice(range(180)) + int(l[2]) flow.SetFlowSize(float(l[6])*100) flow.startTime = float(l[4]) flow.coflowId = int(l[5]) if flow.coflowId not in coflowsize: coflowsize[flow.coflowId] = flow.flowSize coflowwidth[flow.coflowId] = 1 else: coflowsize[flow.coflowId] += flow.flowSize coflowwidth[flow.coflowId] += 1 flow.flowId = len(self.flows) self.flows.append(flow) FlowScheduler.AssignFlows(self) print len(self.flows) f.close() f = open("Input/coflow_in.csv","w") writer = csv.writer(f) writer.writerow(['id', 'volume', 'count']) for k in coflowsize: writer.writerow([k, coflowsize[k], coflowwidth[k]]) f.close()
def AssignFlows(self, topo, filename="Input/load20host32MR.txt"): # print sum(1 for li in open(filename,'r')) f = open(filename, "r") # skip first line # next(f) coflowsize = {} coflowwidth = {} line_count = 0 for line in f.readlines(): l = line.rstrip('\n').split(',') # print l # skip title line if line_count == 0: line_count += 1 continue line_count += 1 flow = Flow() flow.startId = int(l[4]) flow.endId = int(l[5]) flow.SetFlowSize(float(l[1])) flow.startTime = float(l[2]) flow.coflowId = int(l[3]) if flow.coflowId not in coflowsize: coflowsize[flow.coflowId] = flow.flowSize coflowwidth[flow.coflowId] = 1 else: coflowsize[flow.coflowId] += flow.flowSize coflowwidth[flow.coflowId] += 1 flow.flowId = len(self.flows) self.flows.append(flow) # if line_count >= 10: # break # for line in f.readlines(): # l = line.rstrip('\r\n').split(',') # line_count += 1 # for i in range(1): # # print l # flow = Flow() # flow.startId = int(l[0]) # flow.endId = int(l[2]) # # flow.startId = choice(range(topo.numOfServers-20)) + int(l[0]) # # flow.endId = choice(range(topo.numOfServers-20)) + int(l[2]) # # if flow.startId/topo.serverPerRack == flow.endId/topo.serverPerRack: # # flow.endId = (flow.endId + topo.serverPerRack)%topo.numOfServers # # flow.SetFlowSize(float(l[6])*1024*1024) # flow.SetFlowSize(float(l[6])) # flow.startTime = float(l[4]) # flow.coflowId = int(l[5]) # if flow.coflowId not in coflowsize: # coflowsize[flow.coflowId] = flow.flowSize # coflowwidth[flow.coflowId] = 1 # else: # coflowsize[flow.coflowId] += flow.flowSize # coflowwidth[flow.coflowId] += 1 # flow.flowId = len(self.flows) # self.flows.append(flow) # # if line_count == 100: # # break FlowScheduler.AssignFlows(self) # print "number of input flows = ",len(self.flows) f.close() f = open("Input/coflow_in.csv", "w") writer = csv.writer(f) writer.writerow(['id', 'volume', 'count']) for k in coflowsize: writer.writerow([k, coflowsize[k], coflowwidth[k]]) f.close()