def isFailedLocal(self, path): #Analagous to isFailed path class function #Takes a path object as input and checks locally if the path is failed and return True, else false for component in path.getComponents(): if self.localPathComponentStatus[component.getID()] == Status.FAIL: return True return False
def _setTrafficLocalComponentStatus(self, traffic, paths): #set initial traffic local component status information for path in paths: for component in path.getComponents(): componentID = component.getID() if componentID not in traffic.localPathComponentStatus: traffic.localPathComponentStatus[ componentID] = component.getStatus()
def __getHoplengthFromSourceByComponentID(self,componentID): for path in self.paths: hoplength = 0 for component in path.getComponents(): #asssuming that the first item in the path components list is always the source if(component.getID() == componentID): return hoplength hoplength+=1 assert(False) #the componentID supplied was not found in the paths list
def _unreservePath(self, path, bw, trafficID, duplex=True): assert path for component in path.getComponents(): component.removeTrafficID(trafficID) if isinstance(component, Link): if (duplex): component.unReserveBandwidth(bw) else: raise NotImplementedError( "Uni directional path reservation has not been implemented" )
def test_localRouting(self): cfg.k_FatTree = 48 fattree = FatTree() fattree.generate() #fattree.printTopology() source = 'h_1_1_1' dest = 'h_3_2_2' bandwidth = 10 path = fattree.findPath(source, dest, bandwidth) #fattree._reservePath(path,bandwidth,1,False) backupPaths = [] components = path.getComponents() for compNO in [3, 5, 7, 9]: remBW = components[compNO].getAvailableBWFromDevice( components[compNO - 1]) components[compNO].reserveBWFromDevice( remBW, components[compNO - 1]) #reserve all to simulate a failure tempPath = fattree.findPath(components[compNO - 1].getID(), dest, bandwidth) if tempPath is None: print("Couldnt find a backup for" + str(components[compNO - 1].getID()) + " to %s failure" + str(components[compNO].getID())) return False #fattree._reservePath(tempPath,bandwidth,compNO,False) backupPaths.append(tempPath) components[compNO].unReserveBWFromDevice(remBW, components[compNO - 1]) fattree._reservePath(path, bandwidth, 0, False) #removeComponent i = 0 for backupPath in backupPaths: i = i + 1 print("FatTree hop length: %.2f " % (backupPath.getHopLength() + i)) print backupPath linksToRemove = path.getOverlappingLinks(backupPath) backupPath.removeComponents(linksToRemove) fattree._reservePath(backupPath, bandwidth, i, False) #pathIDs = [] #for component in path.getComponents(): # pathIDs.append(str(component.id)) #assert (pathIDs == firstShortestPathIDs) #print("FatTree hop length: %.2f " % (path.getHopLength())) return True
def _reservePath(self, path, bw, trafficID, duplex=True): assert path components = path.getComponents() for compNumber in range(len(components)): component = components[compNumber] if ( component.addTrafficID(trafficID) ): # this fails if trafficID already present, so we dont double reserve links if isinstance(component, Link): if (duplex): component.reserveBandwidth(bw) else: component.reserveBWFromDevice( bw, components[compNumber - 1] ) #it is assumed that for each link both of its devices are given in path
def allocateLocalRoutes(self, traffic): #finds all local routes by failing links along the primary path and then calculating new paths from each point of failure. #reserves and returns all these paths #TODO: does not deal with device failures primaryPath = self.findPath(traffic.sourceID, traffic.destinationID, traffic.getBandwidth()) if primaryPath is None: return [] paths = [primaryPath] devices = (x for x in primaryPath.getComponents() if isinstance(x, Device)) previousDevice = None originalBw = None for device in devices: if previousDevice: originalBw = self.graph[previousDevice.getID()][device.getID()] self.updateGraphLinkBw( previousDevice.getID(), device.getID(), 0) #set the bandwidth to zero to mark as failed localPath = self.findPath(previousDevice.getID(), traffic.destinationID, traffic.getBandwidth()) if localPath: paths.append(localPath) self.updateGraphLinkBw( previousDevice.getID(), device.getID(), originalBw) #set the original bandwidth back previousDevice = device completePaths = [primaryPath] for path in paths: # reserve paths self._reservePath( path, traffic.getBandwidth(), traffic.getID(), cfg.duplexReservation) #this fcn takes care of overreservation #complete the partial paths #TODO: refactor the code below if path is not primaryPath: completeComps = [] pathComps = path.getComponents() for comp in primaryPath.getComponents(): if comp in pathComps: break completeComps.append(comp) completeComps = completeComps + pathComps completePaths.append(Path(completeComps)) self.populateGraph( ) #update the entire graph TODO: make a more optimized funciton return completePaths
def test_simplePath(self): cfg.k_FatTree = 4 fattree = FatTree() fattree.generate() #fattree.printTopology() source = 'h_1_1_1' dest = 'h_3_2_2' firstShortestPathIDs = [ 'h_1_1_1', 'h_1_1_1+t_1_1', 't_1_1', 't_1_1+a_1_1', 'a_1_1', 'a_1_1+c_1', 'c_1', 'a_3_1+c_1', 'a_3_1', 't_3_2+a_3_1', 't_3_2', 'h_3_2_2+t_3_2', 'h_3_2_2' ] path = fattree.findPath(source, dest) pathIDs = [] for component in path.getComponents(): pathIDs.append(str(component.id)) assert (pathIDs == firstShortestPathIDs) print("FatTree hop length: %.2f " % (path.getHopLength())) return True