private String internalRegex() { StringBuilder matchInternal = new StringBuilder("(,|\\\\{|\\\\}|^|\\$| )("); Collection<BgpActivePeerConfig> neighbors = _graph.getEbgpNeighbors().values(); Set<Long> allAsns = new HashSet<>(); for (BgpActivePeerConfig n : neighbors) { Long asn = n.getLocalAs(); allAsns.add(asn); } int i = 0; for (Long asn : allAsns) { i++; matchInternal.append(asn); if (i < allAsns.size()) { matchInternal.append("|"); } } matchInternal.append(")$"); return matchInternal.toString(); }
/** * 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())) {
BgpActivePeerConfig n = e.getValue(); if (n.getLocalAs().equals(n.getRemoteAs())) { acc = false; break;
if (neighbor == null || neighbor.getLocalIp() == null || neighbor.getLocalAs() == null || neighbor.getPeerAddress() == null || neighbor.getRemoteAs() == null) {
@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(); }
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(); }