@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; }
/** * 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()); } }
if (n.getLocalAs().equals(n.getRemoteAs()) && n.getLocalIp() != null) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp());
String srcNode = "as" + n.getRemoteAs(); Ip zeroIp = Ip.create(0); Ip dstIp = n.getLocalIp();
BgpActivePeerConfig src, @Nullable TracerouteEngine tracerouteEngine) { Ip srcAddress = src.getLocalIp(); Ip dstAddress = src.getPeerAddress(); if (dstAddress == null) {
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(); }
networkConfigurations.getBgpPointToPointPeerConfig(neighborId); if (neighbor == null || neighbor.getLocalIp() == null || neighbor.getLocalAs() == null || neighbor.getPeerAddress() == null
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(); }