def run(self): Debug.debug('mdp run') self.prepair() lst = [] for i,j in self.flowMap.table.iteritems(): for k, flow in j.iteritems(): path,dis = self.singleMDP(flow, set([])) """ data center change here, from dis to dis*flow.lat """ lst.append([flow, path, dis*flow.lat]) lst.sort(key = lambda ele: ele[2], reverse = True) retLst = [] for flow,path,dis in lst: mask,tp = self.checkMask() retPath, retDis = self.singleMDP(flow, mask) #no path in this mask while retDis >= Defines.INF: Debug.debug('!!!!!!!!!!!!!!!!!!!cannot found path in mask!!!!!!!!!!!') tPath, tDis = self.singleMDP(flow, set([])) minIdx = -1 minVal = Defines.INF for mb in tPath[1:-1]: if mb in mask: if minVal > self.cnt[tp[mb]][mb]: minVal = self.cnt[tp[mb]][mb] minIdx = mb mask.remove(minIdx) retPath, retDis = self.singleMDP(flow, mask) self.incCnt(retPath, flow.proc) retLst.append([flow, retPath, retDis]) return retLst
def run(self): Debug.debug('mdp run') self.prepair() lst = [] for i, j in self.flowMap.table.iteritems(): for k, flow in j.iteritems(): path, dis = self.singleMDP(flow, set([])) """ data center change here, from dis to dis*flow.lat """ lst.append([flow, path, dis * flow.lat]) lst.sort(key=lambda ele: ele[2], reverse=True) retLst = [] for flow, path, dis in lst: mask, tp = self.checkMask() retPath, retDis = self.singleMDP(flow, mask) #no path in this mask while retDis >= Defines.INF: Debug.debug( '!!!!!!!!!!!!!!!!!!!cannot found path in mask!!!!!!!!!!!') tPath, tDis = self.singleMDP(flow, set([])) minIdx = -1 minVal = Defines.INF for mb in tPath[1:-1]: if mb in mask: if minVal > self.cnt[tp[mb]][mb]: minVal = self.cnt[tp[mb]][mb] minIdx = mb mask.remove(minIdx) retPath, retDis = self.singleMDP(flow, mask) self.incCnt(retPath, flow.proc) retLst.append([flow, retPath, retDis]) return retLst
def run(self): Debug.debug('k level run') self.prepair() for i in range(self.level): self.vote(i) self.select() return self.finalSelect()
def singleMDP(self, flow, mask=set([])): #self.singleTable = make2dList(mbCnt, Defines.mb_max_num, [-1, Defines.INF]) #mask = set([]) Debug.debug('mdp set', mask) self.singleTable = TwoDMap() proc = flow.proc if len(proc) <= 0: return [flow.src, flow.dst], self.topo.getDis(flow.src, flow.dst) for idx, mb in enumerate(proc): if idx == 0: for idx2, candi in enumerate(self.candi[mb]): if candi in mask: continue self.singleTable[mb][candi] = [ flow.src, self.topo.getDis(flow.src, candi) ] else: for idx2, candi in enumerate(self.candi[mb]): if candi in mask: continue premb = proc[idx - 1] self.singleTable[mb][candi] = [-1, Defines.INF] for idx3, pre in enumerate(self.candi[premb]): if pre in mask: continue if self.singleTable[mb][candi][1] > self.singleTable[ premb][pre][1] + self.topo.getDis(candi, pre): self.singleTable[mb][candi] = [ pre, self.singleTable[premb][pre][1] + self.topo.getDis(candi, pre) ] lastmb = proc[-1] finalDis = Defines.INF finalmbidx = -1 finalmb = -1 for idx, candi in enumerate(self.candi[lastmb]): if candi in mask: continue if not self.singleTable.has_key(lastmb, candi): continue if finalDis > self.singleTable[lastmb][candi][ 1] + self.topo.getDis(candi, flow.dst): finalDis = self.singleTable[lastmb][candi][ 1] + self.topo.getDis(candi, flow.dst) #finalmbidx = idx finalmb = candi path = [] #stidx = finalmbidx if finalmb == -1: return [], Defines.INF st = finalmb path.append(flow.dst) path.append(st) for i in range(len(proc)): mbidx = len(proc) - i - 1 mb = proc[mbidx] st = self.singleTable[mb][st][0] path.append(st) path.reverse() return path, finalDis
def finalSelect(self): ret = self.make2dList(self.mbCnt, 1) mask = set([]) for j in range(self.mbCnt): ret[j] = self.getNPool(j, self.numLst[j], mask) for item in ret[j]: mask.add(item) Debug.debug('final selected ret', ret) return ret
def getSwitchDis(self, nd1, nd2): if not self.minDis: self.calcShortestPath() self.minDis = True if self.switchDis.has_key(nd1, nd2): return self.switchDis[nd1][nd2] else: Debug.debug('switch dis not found', nd1, nd2) return self.INF
def getSwitchDis(self, nd1, nd2): if not self.minDis: self.calcShortestPath() self.minDis = True if self.switchDis.has_key(nd1 , nd2): return self.switchDis[nd1][nd2] else: Debug.debug('switch dis not found', nd1, nd2) return self.INF
def calcMinReq(self): for i,j in self.flowMap.table.iteritems(): for k,flow in j.iteritems(): for mb in flow.proc: self.minReq[mb] += flow.size for mb in range(Defines.mb_type): Debug.debug('raw req', self.minReq[mb]) self.minReq[mb] /= Defines.general_max self.minReq[mb] += 1 if self.minReq[mb] > Defines.mb_max_num: raise AlgException('need more mb instances')
def calcMinReq(self): for i, j in self.flowMap.table.iteritems(): for k, flow in j.iteritems(): for mb in flow.proc: self.minReq[mb] += flow.size for mb in range(Defines.mb_type): Debug.debug('raw req', self.minReq[mb]) self.minReq[mb] /= Defines.general_max self.minReq[mb] += 1 if self.minReq[mb] > Defines.mb_max_num: raise AlgException('need more mb instances')
def run(self): Debug.debug('FLBAlg run') self.prepair() lst = [] for i,j in self.flowMap.table.iteritems(): for k, flow in j.iteritems(): path,dis = self.randPath(flow) lst.append([flow, path, dis]) self.incCnt(path, flow.proc) self.checkOverDelay(lst) self.checkOverflow() return lst
def run(self): Debug.debug('FFAlg run') self.prepair() lst = [] for i, j in self.flowMap.table.iteritems(): for k, flow in j.iteritems(): path, dis = self.singleMDP(flow, set([])) lst.append([flow, path, dis]) self.incCnt(path, flow.proc) self.checkOverDelay(lst) self.checkOverflow() return lst
def singleMDP(self, flow, mask = set([])): #self.singleTable = make2dList(mbCnt, Defines.mb_max_num, [-1, Defines.INF]) #mask = set([]) Debug.debug('mdp set', mask) self.singleTable = TwoDMap() proc = flow.proc if len(proc) <= 0: return [flow.src, flow.dst], self.topo.getDis(flow.src, flow.dst) for idx,mb in enumerate(proc): if idx == 0: for idx2,candi in enumerate(self.candi[mb]): if candi in mask: continue self.singleTable[mb][candi] = [flow.src, self.topo.getDis(flow.src, candi)] else: for idx2,candi in enumerate(self.candi[mb]): if candi in mask: continue premb = proc[idx-1] self.singleTable[mb][candi] = [-1 , Defines.INF] for idx3, pre in enumerate(self.candi[premb]): if pre in mask: continue if self.singleTable[mb][candi][1] > self.singleTable[premb][pre][1] + self.topo.getDis(candi, pre): self.singleTable[mb][candi] = [pre , self.singleTable[premb][pre][1] + self.topo.getDis(candi, pre)] lastmb = proc[-1] finalDis = Defines.INF finalmbidx = -1 finalmb = -1 for idx, candi in enumerate(self.candi[lastmb]): if candi in mask: continue if not self.singleTable.has_key(lastmb, candi): continue if finalDis > self.singleTable[lastmb][candi][1] + self.topo.getDis(candi, flow.dst): finalDis = self.singleTable[lastmb][candi][1] + self.topo.getDis(candi , flow.dst) #finalmbidx = idx finalmb = candi path = [] #stidx = finalmbidx if finalmb == -1: return [], Defines.INF st = finalmb path.append(flow.dst) path.append(st) for i in range(len(proc)): mbidx = len(proc) - i - 1 mb = proc[mbidx] st = self.singleTable[mb][st][0] path.append(st) path.reverse() return path, finalDis
def generateCandi(self): poolLen = len(self.pool) self.candi = [0] * self.mbCnt mask = set([]) random.seed() Debug.debug('numLst', self.numLst) for mb, cnt in enumerate(self.numLst): self.candi[mb] = [] for i in range(cnt): while True: idx = random.randint(0, poolLen - 1) if idx not in mask: mask.add(idx) self.candi[mb].append(self.pool[idx]) break
def checkOverflow(self): f = open('ffflownum' + str(self.seq), 'w') mbLst = [] for i, j in self.cnt.iteritems(): overflow = False for k, cnt in j.iteritems(): Debug.debug('type %d pool %d cnt %d' % (i, k, cnt)) f.write('%d %d %d\n' % (i, k, cnt)) if cnt > Defines.general_busy * 2: overflow = True if overflow: Debug.debug('mb type %d overflow' % i) mbLst.append(i) f.close() return mbLst
def generateCandi(self): poolLen = len(self.pool) self.candi = [0]*self.mbCnt mask = set([]) random.seed() Debug.debug('numLst', self.numLst) for mb, cnt in enumerate(self.numLst): self.candi[mb] = [] for i in range(cnt): while True: idx = random.randint(0, poolLen -1 ) if idx not in mask: mask.add(idx) self.candi[mb].append(self.pool[idx]) break
def checkOverflow(self): f = open('flbflownum' + str(self.seq), 'w') mbLst = [] for i,j in self.cnt.iteritems(): overflow = False for k,cnt in j.iteritems(): Debug.debug('type %d pool %d cnt %d' %(i, k, cnt)) f.write('%d %d %d\n' % (i, k, cnt)) if cnt > Defines.general_busy*2: overflow = True if overflow: Debug.debug('mb type %d overflow' % i) mbLst.append(i) f.close() return mbLst
def run(self): # calc min request mb number list self.calcMinReq() while True: Debug.debug('min req', self.minReq) self.klevel.setPara(self.minReq) pla = self.klevel.run() self.mdp.setPara(pla) retLst = self.mdp.run() self.mdp.checkOverflow() if self.mdp.checkOverDelay(retLst) > Defines.max_delay_ratio: addLst = self.mdp.checkOverflowByDelay(retLst) for addItem in addLst: self.minReq[addItem] += Defines.mb_add_step else: return pla, retLst
def calcShortestPath(self): Debug.debug('calc shortest path') self.switchDis = TwoDMap() #Floyd-Warshall Algorithm for switchID in self.switch: self.switchDis[switchID][switchID] = 0 for src,j in self.table.iteritems(): for dst,delay in j.iteritems(): if self.nd[src].ndType == 'switch' and self.nd[dst].ndType == 'switch': self.switchDis[src][dst] = delay for switchID in self.switch: for src in self.switch: if self.switchDis.has_key(src, switchID): for dst in self.switch: if self.switchDis.has_key(dst, switchID): if self.switchDis[src][dst] > self.switchDis[src][switchID] + self.switchDis[switchID][dst]: self.switchDis[src][dst] = self.switchDis[src][switchID] + self.switchDis[switchID][dst]
def checkOverDelay(self, retLst): self.seq += 1 self.getCandi() f = open('delay'+str(self.seq), 'w') totalCnt = len(retLst)*1.0 overCnt = 0.0 for flow, retPath, retDis in retLst: dis = retDis for i,mbID in enumerate(retPath[1:-1]): dis += self.topo.nd[mbID].getMBDelay(flow.proc[i], self.cnt[flow.proc[i]][mbID]) f.write('%d %d %d %d\n' % ( flow.src, flow.dst, dis, flow.lat)) #if dis > Defines.max_delay: if dis > flow.lat: overCnt += 1 Debug.debug('over delay ratio:',overCnt/totalCnt) f.close() return overCnt/totalCnt
def checkOverDelay(self, retLst): self.seq += 1 self.getCandi() f = open('ffdelay' + str(self.seq), 'w') totalCnt = len(retLst) * 1.0 overCnt = 0.0 for flow, retPath, retDis in retLst: dis = retDis for i, mbID in enumerate(retPath[1:-1]): dis += self.topo.nd[mbID].getMBDelay( flow.proc[i], self.cnt[flow.proc[i]][mbID]) f.write('%d %d %d %d\n' % (flow.src, flow.dst, dis, flow.lat)) #if dis > Defines.max_delay: if dis > flow.lat: overCnt += 1 Debug.debug('over delay ratio:', overCnt / totalCnt) f.close() return overCnt / totalCnt
def calcShortestPath(self): Debug.debug('calc shortest path') self.switchDis = TwoDMap() #Floyd-Warshall Algorithm for switchID in self.switch: self.switchDis[switchID][switchID] = 0 for src, j in self.table.iteritems(): for dst, delay in j.iteritems(): if self.nd[src].ndType == 'switch' and self.nd[ dst].ndType == 'switch': self.switchDis[src][dst] = delay for switchID in self.switch: for src in self.switch: if self.switchDis.has_key(src, switchID): for dst in self.switch: if self.switchDis.has_key(dst, switchID): if self.switchDis[src][dst] > self.switchDis[src][ switchID] + self.switchDis[switchID][dst]: self.switchDis[src][dst] = self.switchDis[src][ switchID] + self.switchDis[switchID][dst]