def getNextHopByNetSegment(self, netSegment, nextHops): print "dstSegment:{}".format(netSegment.strNormal()) prefixLength = netSegment.prefixlen() ns = netSegment.int() while prefixLength>0: prefix = plugins.getPrefixByIpMask(ns, prefixLength) bgp_list = self.mapPrefixBgp.get(prefix) print "### prefix:{}".format(plugins.getIpById(prefix)) # if bgp_list: # for bgp in bgp_list: # print "### {}".format(bgp) # if bgp_list: # for bgp in bgp_list: # nextHop = plugins.getNetSegmentByIpMask(bgp.nextHop) # if nextHop in nextHops: # return nextHop if bgp_list: bgp = reduce(self.bgpRouteSelect, bgp_list) curPrefix = plugins.getPrefixByIpMask(bgp.nextHop, prefixLength) if curPrefix==prefix: return netSegment print "@@@@@@@@@@ {}".format(bgp) nextHop = plugins.getNetSegmentByIpMask(bgp.nextHop) #nextHop = self.getRouterIdByNetSegment(bgp.nextHop) return nextHop # print "###prefix:{}, BGP:{}".format(prefixLength, bgp) # if bgp and bgp.prefixLength==prefixLength: # nextHop = plugins.getNetSegmentByIpMask(bgp.nextHop) # if nextHop in nextHops: # return nextHop prefixLength -= 1 else: return netSegment
def getAsbrLinkByNextHop(nextHop): for link in self.asbrLinks: p1 = plugins.getPrefixByIpMask(link.srcIp, link.mask) p2 = plugins.getPrefixByIpMask(nextHop, link.mask) if p1==p2: return link return
def getRouterIdByIpMask(self, ip, mask): prefixLength = plugins.getPrefixlenByIpMask(ip, mask) while prefixLength>0: prefix = plugins.getPrefixByIpMask(ip, prefixLength) routerId = self.getRouterIdByPrefix(prefix) if routerId: return routerId externalLsa = self.mapPrefixExternallsa.get(prefix) if externalLsa and plugins.getIdByIp(externalLsa.networkMask)==plugins.getIdByIp(mask): advRouter = externalLsa.getAdvRouter() routerId = plugins.getIdByIp(advRouter) return routerId prefixLength -= 1 else: return # def getRouterIdFromStub(self, ip, mask): # prefix = plugins.getPrefixByIpMask(ip, mask) # routerId = self.mapPrefixRouterid.get(prefix) # return routerId if routerId else 0 # def getRouterIdFromExternalLsa(self, ip, mask): # prefix = plugins.getPrefixByIpMask(ip, mask) # lsa = self.mapPrefixExternallsa.get(prefix) # return lsa.getAdvRouter() if lsa else 0 '''
def getAsbrIdByInterfaceIp(self, interfaceIp): if interfaceIp<=0: return asbrId = self.mapInterfaceipRouterid.get(interfaceIp) if asbrId: return asbrId prefix = plugins.getPrefixByIpMask(ip, 32) if prefix: return self.getRouterIdByPrefix(prefix)
def getAsbrSegsByDstSegment(self, dstSegment): asbrSegs = [] prefixLength = dstSegment.prefixlen() ds = dstSegment.int() while prefixLength>0: prefix = plugins.getPrefixByIpMask(ds, prefixLength) lsa_list = self.mapPrefixExternallsa.get(prefix) if lsa_list: for lsa in lsa_list: print lsa asbrSegs = self.asbrRouteSelect(lsa_list) print "asbrSegs:{}".format(asbrSegs) return asbrSegs prefixLength -=1 else: return "Oh, No, Couldn't find the asbrSegment!"
def getAsbrSegByDstSegment(self, netSegment): try: prefixLength = netSegment.prefixlen() ns = netSegment.int() print "PrefixLength:{}\tNetSegment:{}".format(prefixLength, ns) for p,lsa in self.mapPrefixExternallsa.items(): print "Prefix:{}, Lsa:{}".format(p, lsa) while prefixLength>0: prefix = plugins.getPrefixByIpMask(ns, prefixLength) externalLsa = self.mapPrefixExternallsa.get(prefix) #print "***Lsa:{}".format(externalLsa) if externalLsa and externalLsa.getPrefixLength()==prefixLength: #print "Lsa's prefixLengt:{}".format(externalLsa.getPrefixLength()) asbrId = externalLsa.getAdvRouter() print "SelectLsa:{}".format(plugins.getNetSegmentByIpMask(asbrId)) asbrSeg = plugins.getNetSegmentByIpMask(asbrId) return asbrSeg prefixLength -= 1 except Exception,e: print "@@@ AsbrSeg Find Error:{}-{}".format(Exception, e)
def getPrefix(self): # srcIp = plugins.getIpById(self.srcIp) # mask = plugins.getIpById(self.mask) return plugins.getPrefixByIpMask(self.srcIp, self.mask)
def getPrefix(self): return plugins.getPrefixByIpMask(self.srcIp, self.mask)