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 setTopoStubInfo(self, stubInfo): for stub in stubInfo: routerId = plugins.getIdByIp(stub.get("routerId")) prefix = stub.get("prefix") mask = plugins.getIdByIp(stub.get("mask")) if all([routerId, prefix, mask]): self.addMapPrefixRouterid(prefix, routerId)
def setOuterExternallasInfo(self, lsaInfo): for lsa in lsaInfo: metric = lsa.get("metric") networkMask = plugins.getIdByIp(lsa.get("networkMask")) advRouter = plugins.getIdByIp(lsa.get("advRouter")) linkStateId = plugins.getIdByIp(lsa.get("linkStateId")) externalType = lsa.get("externalType") forwardingAddress = plugins.getIdByIp(lsa.get("forwardingAddress")) if all([networkMask, advRouter, linkStateId, externalType]): l = ExternalLsa() l.setLsaInfo(metric, advRouter, linkStateId, networkMask, externalType, forwardingAddress) #self.addMapPrefixExternallsa(linkStateId, l) self.addMapPrefixExternallsaItem(l)
def setTopoAsbrInfo(self, asbrInfo): for asbr in asbrInfo: linkId = asbr.get("linkId") metric = asbr.get("metric") mask = plugins.getIdByIp(asbr.get("mask")) srcId = plugins.getIdByIp(asbr.get("routerId")) dstId = plugins.getIdByIp(asbr.get("nRouterId")) srcIp = plugins.getIdByIp(asbr.get("interfaceIP")) dstAs = asbr.get("nAsNumber") if all([linkId, srcId, srcIp, mask, dstId, dstAs]): asbrLink = AsbrLink() asbrLink.setLinkInfo(linkId, metric, mask, \ srcId, dstId, srcIp, dstAs) self.addMapInterfaceipRouterid(srcIp, srcId) self.addAsbrLink(asbrLink)
def setOuterBgpInfo(self, bgpInfo): for bgp in bgpInfo: nextHop = plugins.getIdByIp(bgp.get("nexthop")) if nextHop==0: continue prefix = plugins.getIdByIp(bgp.get("prefix")) length = bgp.get("length") weight = bgp.get("weight") origin = bgp.get("origin") localPreference = bgp.get("localPreference") metric = bgp.get("med") asPath = bgp.get("aspath") asSize = len(asPath) if all([nextHop, prefix, length>=0, weight>=0, origin>=0, \ localPreference>=0, metric>=0, asSize>=0]): b = Bgp() b.setBgpInfo(origin, weight, length, metric, prefix, \ nextHop, localPreference, asPath) self.addMapPrefixBgpItem(b)
def setTopoNodeInfo(self, nodeInfo): for node in nodeInfo: router = Router() routerId = plugins.getIdByIp(node.get("routerId")) router.setRouterId(routerId) neighbors = node.get("neighbors") for neighbor in neighbors: srcId = routerId linkId = neighbor.get("id") area = neighbor.get("area") srcIp = plugins.getIdByIp(neighbor.get("interfaceIP")) mask = plugins.getIdByIp(neighbor.get("mask")) dstId = plugins.getIdByIp(neighbor.get("nRouterId")) metric = neighbor.get("metric") if all([linkId, srcId, dstId, srcIp, mask]): link = NormalLink() link.setLinkInfo(linkId, metric, area, srcId, dstId, srcIp, mask) router.addArea(area) router.addLink(link) self.normalLinks.append(link) self.addLinkId(linkId) self.addMapInterfaceipRouterid(srcIp, srcId) self.addRouterId(routerId) self.addMapRouteridRouter(routerId, router)