@Override protected Long featureValueOf(BgpActivePeerConfig actual) { return actual.getRemoteAs(); } }
@VisibleForTesting static SelfDescribingObject getRemoteAs(@Nonnull BgpPeerConfig peer) { if (peer instanceof BgpActivePeerConfig) { return new SelfDescribingObject(Schema.LONG, ((BgpActivePeerConfig) peer).getRemoteAs()); } if (peer instanceof BgpPassivePeerConfig) { return new SelfDescribingObject( Schema.list(Schema.LONG), ((BgpPassivePeerConfig) peer).getRemoteAs()); } throw new IllegalArgumentException( String.format("Peer is neither Active nor Passive: %s", peer)); }
/** * Determine what type of session the peer is configured to establish. * * @param initiator the configuration of connection initiator. * @return a {@link SessionType} the initiator is configured to establish. */ public static @Nonnull SessionType getSessionType(BgpActivePeerConfig initiator) { SessionType sessionType = SessionType.UNSET; if (initiator.getLocalAs() != null && initiator.getRemoteAs() != null) { if (initiator.getLocalAs().equals(initiator.getRemoteAs())) { sessionType = SessionType.IBGP; } else if (initiator.getEbgpMultihop()) { sessionType = SessionType.EBGP_MULTIHOP; } else { sessionType = SessionType.EBGP_SINGLEHOP; } } return sessionType; }
@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; }
/** * 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() == null || n.getRemoteAs() == null) { if (n.getLocalAs().equals(n.getRemoteAs()) && n.getLocalIp() != null) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAs() == null) { if (!localBgpConfig.getLocalAs().equals(localBgpConfig.getRemoteAs())) {
String srcNode = "as" + n.getRemoteAs(); Ip zeroIp = Ip.create(0); Ip dstIp = n.getLocalIp();
BgpActivePeerConfig n = e.getValue(); if (n.getLocalAs().equals(n.getRemoteAs())) { acc = false; break;
|| neighbor.getLocalAs() == null || neighbor.getPeerAddress() == null || neighbor.getRemoteAs() == null) { continue;
Long remoteAs = ((BgpActivePeerConfig) bgpPeerConfig).getRemoteAs(); if (remoteAs != null && !remoteAs.equals(bgpPeerConfig.getLocalAs())) { bgpSessionInfo._sessionType =
@Override public long evaluate(Environment environment) { BgpProcess proc = environment.getVrf().getBgpProcess(); if (proc == null) { throw new BatfishException("Expected BGP process"); } Direction direction = environment.getDirection(); long as; Ip peerAddress = environment.getPeerAddress(); if (peerAddress == null) { throw new BatfishException("Expected a peer address"); } Prefix peerPrefix = Prefix.create(peerAddress, Prefix.MAX_PREFIX_LENGTH); // TODO: what not sure what happens with dynamic neighbors here BgpActivePeerConfig neighbor = proc.getActiveNeighbors().get(peerPrefix); if (neighbor == null) { throw new BatfishException("Expected a peer with address: " + peerAddress); } if (direction == Direction.IN) { as = neighbor.getRemoteAs(); } else if (direction == Direction.OUT) { as = neighbor.getLocalAs(); } else { throw new BatfishException("Expected to be applied in a direction"); } return as; }
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(); }