@VisibleForTesting static SelfDescribingObject getRemoteIp(@Nonnull BgpPeerConfig peer) { if (peer instanceof BgpActivePeerConfig) { return new SelfDescribingObject(Schema.IP, ((BgpActivePeerConfig) peer).getPeerAddress()); } if (peer instanceof BgpPassivePeerConfig) { return new SelfDescribingObject(Schema.PREFIX, ((BgpPassivePeerConfig) peer).getPeerPrefix()); } throw new IllegalArgumentException( String.format("Peer is neither Active nor Passive: %s", peer)); }
@Nullable @VisibleForTesting static ConfiguredSessionStatus getLocallyBrokenStatus( BgpActivePeerConfig neighbor, SessionType sessionType) { if (neighbor.getLocalIp() == null) { if (sessionType == BgpSessionProperties.SessionType.EBGP_MULTIHOP || sessionType == BgpSessionProperties.SessionType.IBGP) { return ConfiguredSessionStatus.LOCAL_IP_UNKNOWN_STATICALLY; } else { return ConfiguredSessionStatus.NO_LOCAL_IP; } } else if (neighbor.getLocalAs() == null) { return ConfiguredSessionStatus.NO_LOCAL_AS; } else if (neighbor.getPeerAddress() == null) { return ConfiguredSessionStatus.NO_REMOTE_IP; } else if (neighbor.getRemoteAs() == null) { return ConfiguredSessionStatus.NO_REMOTE_AS; } return null; }
static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId bgpPeerConfigId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Set<Ip> allInterfaceIps, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } // Nothing blatantly broken so far on the local side, keep checking. Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!allInterfaceIps.contains(localIp)) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!allInterfaceIps.contains(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(bgpPeerConfigId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(bgpPeerConfigId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; }
(ge, n) -> { sb.append(n); sb.append("Edge: ").append(ge).append(" (").append(n.getPeerAddress()).append(")\n"); }); _ibgpNeighbors.forEach( (ge, n) -> sb.append("Edge: ").append(ge).append(" (").append(n.getPeerAddress()).append(")\n"));
BgpProcess bgp = conf.getDefaultVrf().getBgpProcess(); for (BgpActivePeerConfig neighbor : bgp.getActiveNeighbors().values()) { ipList.add(neighbor.getPeerAddress()); ns.add(neighbor);
public long findRouterId(GraphEdge ge, Protocol proto) { GraphEdge eOther = _otherEnd.get(ge); if (proto.isOspf() || proto.isConnected() || proto.isStatic()) { return 0L; } if (eOther != null) { String peer = eOther.getRouter(); Configuration peerConf = getConfigurations().get(peer); return routerId(peerConf, proto); } BgpActivePeerConfig n = findBgpNeighbor(ge); if (n != null && n.getPeerAddress() != null) { return n.getPeerAddress().asLong(); } throw new BatfishException("Unable to find router id for " + ge + "," + proto.name()); }
/** * Check if the given combo of BGP peer configs can agree on their respective BGP local/remote AS * number configurations. */ private static boolean bgpCandidatePassesSanityChecks( @Nonnull BgpActivePeerConfig neighbor, @Nonnull BgpPeerConfigId candidateId, @Nonnull Set<String> possibleHostnames, @Nonnull NetworkConfigurations nc) { if (candidateId.isDynamic()) { BgpPassivePeerConfig candidate = nc.getBgpDynamicPeerConfig(candidateId); return candidate != null && candidate.canConnect(neighbor.getLocalAs()) && Objects.equals(neighbor.getRemoteAs(), candidate.getLocalAs()) && candidate.canConnect(neighbor.getLocalIp()) && possibleHostnames.contains(candidateId.getHostname()); } else { BgpActivePeerConfig candidate = nc.getBgpPointToPointPeerConfig(candidateId); return candidate != null && Objects.equals(neighbor.getPeerAddress(), candidate.getLocalIp()) && Objects.equals(neighbor.getLocalIp(), candidate.getPeerAddress()) && Objects.equals(neighbor.getRemoteAs(), candidate.getLocalAs()) && Objects.equals(neighbor.getLocalAs(), candidate.getRemoteAs()); } }
private Interface createIbgpInterface(BgpActivePeerConfig n, String peer) { Interface iface = new Interface("iBGP-" + peer); iface.setActive(true); // TODO is this valid. iface.setAddress(new InterfaceAddress(n.getPeerAddress(), Prefix.MAX_PREFIX_LENGTH)); iface.setBandwidth(0.); return iface; }
|| neighbor.getLocalIp() == null || neighbor.getLocalAs() == null || neighbor.getPeerAddress() == null || neighbor.getRemoteAs() == null) { continue; Set<String> possibleHostnames = ipOwners.get(neighbor.getPeerAddress()); if (possibleHostnames == null) { continue; Set<BgpPeerConfigId> candidates = localAddresses.get(neighbor.getPeerAddress()); if (candidates == null) {
@Nullable TracerouteEngine tracerouteEngine) { Ip srcAddress = src.getLocalIp(); Ip dstAddress = src.getPeerAddress(); if (dstAddress == null) { return false;
} else { String address; if (n.getPeerAddress() == null) { address = "null"; } else { address = n.getPeerAddress().toString();
bgpSessionInfo._localIp = localIp; bgpSessionInfo._onLoopback = loopbackIps.contains(localIp); Ip remoteIp = ((BgpActivePeerConfig) bgpPeerConfig).getPeerAddress();
private static @Nonnull Row buildActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, SessionType type, ConfiguredSessionStatus status, Map<String, ColumnMetadata> metadataMap, ValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology, Map<String, Configuration> configurations) { Node remoteNode = null; if (status == UNIQUE_MATCH) { String remoteNodeName = bgpTopology.adjacentNodes(activeId).iterator().next().getHostname(); remoteNode = new Node(remoteNodeName); } Ip localIp = activePeer.getLocalIp(); NodeInterfacePair localInterface = getInterface(configurations.get(activeId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_CONFIGURED_STATUS, status) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, activePeer.getLocalAs()) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getRemoteAs())) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, activeId.getVrfName()) .build(); }
private static @Nonnull Row buildActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, SessionType type, SessionStatus status, Map<String, ColumnMetadata> metadataMap, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology, Map<String, Configuration> configurations) { Node remoteNode = null; if (status != NOT_COMPATIBLE) { String remoteNodeName = configuredBgpTopology.adjacentNodes(activeId).iterator().next().getHostname(); remoteNode = new Node(remoteNodeName); } Ip localIp = activePeer.getLocalIp(); NodeInterfacePair localInterface = getInterface(configurations.get(activeId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_ESTABLISHED_STATUS, status) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, activePeer.getLocalAs()) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getRemoteAs())) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, activeId.getVrfName()) .build(); }
private static @Nonnull Row buildDynamicMatchRow( Map<String, ColumnMetadata> metadataMap, BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<String, Configuration> configurations) { SessionType type = BgpSessionProperties.getSessionType(activePeer); Ip localIp = activePeer.getPeerAddress(); NodeInterfacePair localInterface = getInterface(configurations.get(passiveId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, localIp) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getLocalAs())) .put(COL_REMOTE_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getLocalIp())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, passiveId.getVrfName()) .build(); }
private static @Nonnull Row buildDynamicMatchRow( Map<String, ColumnMetadata> metadataMap, BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, boolean established, Map<String, Configuration> configurations) { SessionType type = BgpSessionProperties.getSessionType(activePeer); SessionStatus status = established ? ESTABLISHED : NOT_ESTABLISHED; Ip localIp = activePeer.getPeerAddress(); NodeInterfacePair localInterface = getInterface(configurations.get(passiveId.getHostname()), localIp); return Row.builder(metadataMap) .put(COL_ESTABLISHED_STATUS, status) .put(COL_LOCAL_INTERFACE, localInterface) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, localIp) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, new SelfDescribingObject(Schema.LONG, activePeer.getLocalAs())) .put(COL_REMOTE_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getLocalIp())) .put(COL_SESSION_TYPE, type) .put(COL_VRF, passiveId.getVrfName()) .build(); }
nextHopIp = ((BgpActivePeerConfig) toNeighbor).getPeerAddress(); } else { String nextHopInterface = route.getNextHopInterface();