Search in sources :

Example 1 with LongSpace

use of org.batfish.datamodel.LongSpace in project batfish by batfish.

the class CiscoNxosControlPlaneExtractor method toBgpAsnRange.

@Nullable
private LongSpace toBgpAsnRange(ParserRuleContext messageCtx, Bgp_asn_rangeContext ctx) {
    String rangeText = ctx.getText();
    LongSpace value = LongSpace.parse(rangeText);
    if (!BGP_ASN_RANGE.contains(value)) {
        warn(messageCtx, String.format("Expected BGP ASNs in range %s, but got '%s'", BGP_ASN_RANGE, rangeText));
        return null;
    }
    return value;
}
Also used : LongSpace(org.batfish.datamodel.LongSpace) Nullable(javax.annotation.Nullable)

Example 2 with LongSpace

use of org.batfish.datamodel.LongSpace in project batfish by batfish.

the class BgpRouteConstraints method validate.

/**
 * Check that the constraints contain valid values.
 */
private static void validate(@Nonnull BgpRouteConstraints constraints) {
    LongSpace localPref = constraints.getLocalPreference();
    LongSpace med = constraints.getMed();
    LongSpace tag = constraints.getTag();
    Set<RoutingProtocol> protocol = constraints.getProtocol();
    checkArgument(is32BitRange(localPref), "Invalid value for local preference: %s", localPref);
    checkArgument(is32BitRange(med), "Invalid value for MED: %s", med);
    checkArgument(is32BitRange(tag), "Invalid value for tag: %s", tag);
    checkArgument(isBgpProtocol(protocol), "Invalid value for protocol: %s", protocol);
}
Also used : LongSpace(org.batfish.datamodel.LongSpace) RoutingProtocol(org.batfish.datamodel.RoutingProtocol)

Example 3 with LongSpace

use of org.batfish.datamodel.LongSpace in project batfish by batfish.

the class BgpSessionCompatibilityAnswererTest method testGetDynamicPeerRowTwoCompatiblePeers.

@Test
public void testGetDynamicPeerRowTwoCompatiblePeers() {
    Ip localIp = Ip.parse("1.1.1.1");
    Prefix localAddress = localIp.toPrefix();
    Prefix remotePrefix = Prefix.parse("2.2.2.0/24");
    LongSpace remoteAsns = LongSpace.of(Range.closed(2L, 3L));
    // Dynamic peer correctly configured, with two adjacent nodes in BGP topology
    BgpPeerConfigId peerId = new BgpPeerConfigId("c1", "vrf1", remotePrefix, true);
    BgpPassivePeerConfig peer = BgpPassivePeerConfig.builder().setLocalIp(Ip.AUTO).setPeerPrefix(remotePrefix).setLocalAs(1L).setRemoteAsns(remoteAsns).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    // Remote peers
    Ip remote1Ip = Ip.parse("2.2.2.1");
    BgpPeerConfigId remote1Id = new BgpPeerConfigId("c2", "vrf2", localAddress, false);
    BgpActivePeerConfig remote1 = BgpActivePeerConfig.builder().setLocalIp(remote1Ip).setPeerAddress(localIp).setLocalAs(2L).setRemoteAs(1L).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    Ip remote2Ip = Ip.parse("2.2.2.2");
    BgpPeerConfigId remote2Id = new BgpPeerConfigId("c3", "vrf3", localAddress, false);
    BgpActivePeerConfig remote2 = BgpActivePeerConfig.builder().setLocalIp(remote2Ip).setPeerAddress(localIp).setLocalAs(3L).setRemoteAs(1L).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build();
    bgpTopology.putEdgeValue(peerId, remote1Id, BgpSessionProperties.from(remote1, peer, true));
    bgpTopology.putEdgeValue(remote1Id, peerId, BgpSessionProperties.from(remote1, peer, false));
    bgpTopology.putEdgeValue(peerId, remote2Id, BgpSessionProperties.from(remote2, peer, true));
    bgpTopology.putEdgeValue(remote2Id, peerId, BgpSessionProperties.from(remote2, peer, false));
    // Build configs for remote peers because answerer needs to look up peers from peer IDs
    NetworkConfigurations nc = NetworkConfigurations.of(createConfigurations(ImmutableList.of(remote1Id, remote2Id), ImmutableList.of(remote1, remote2)));
    List<Row> rows = getPassivePeerRows(peerId, peer, nc, bgpTopology);
    Row.RowBuilder expectedRowBuilder = Row.builder().put(COL_LOCAL_AS, 1L).put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST)).put(COL_LOCAL_IP, localIp).put(COL_NODE, new Node("c1")).put(COL_SESSION_TYPE, SessionType.EBGP_SINGLEHOP).put(COL_VRF, "vrf1").put(COL_CONFIGURED_STATUS, ConfiguredSessionStatus.DYNAMIC_MATCH).put(COL_LOCAL_INTERFACE, null).put(COL_REMOTE_INTERFACE, null);
    Row expected1 = expectedRowBuilder.put(COL_REMOTE_AS, "2").put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, remote1Ip)).put(COL_REMOTE_NODE, new Node("c2")).build();
    Row expected2 = expectedRowBuilder.put(COL_REMOTE_AS, "3").put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, remote2Ip)).put(COL_REMOTE_NODE, new Node("c3")).build();
    assertThat(rows, containsInAnyOrder(expected1, expected2));
}
Also used : LongSpace(org.batfish.datamodel.LongSpace) Ip(org.batfish.datamodel.Ip) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Node(org.batfish.datamodel.pojo.Node) Prefix(org.batfish.datamodel.Prefix) BgpSessionProperties(org.batfish.datamodel.BgpSessionProperties) BgpPassivePeerConfig(org.batfish.datamodel.BgpPassivePeerConfig) BgpActivePeerConfig(org.batfish.datamodel.BgpActivePeerConfig) BgpSessionCompatibilityAnswerer.getUnnumberedPeerRow(org.batfish.question.bgpsessionstatus.BgpSessionCompatibilityAnswerer.getUnnumberedPeerRow) Row(org.batfish.datamodel.table.Row) BgpSessionCompatibilityAnswerer.getActivePeerRow(org.batfish.question.bgpsessionstatus.BgpSessionCompatibilityAnswerer.getActivePeerRow) SelfDescribingObject(org.batfish.datamodel.answers.SelfDescribingObject) BgpPeerConfigId(org.batfish.datamodel.BgpPeerConfigId) Test(org.junit.Test)

Example 4 with LongSpace

use of org.batfish.datamodel.LongSpace in project batfish by batfish.

the class BgpSessionStatusAnswererTest method testGetDynamicPeerRowTwoCompatiblePeers.

@Test
public void testGetDynamicPeerRowTwoCompatiblePeers() {
    Ip localIp = Ip.parse("1.1.1.1");
    Prefix localAddress = localIp.toPrefix();
    Prefix remotePrefix = Prefix.parse("2.2.2.0/24");
    LongSpace remoteAsns = LongSpace.of(Range.closed(2L, 3L));
    // Dynamic peer with two compatible remotes: one can reach the dynamic peer, one can't.
    // getPassivePeerRows() should include rows for both, one ESTABLISHED and one NOT_ESTABLISHED.
    BgpPeerConfigId peerId = new BgpPeerConfigId("c1", "vrf1", remotePrefix, true);
    BgpPassivePeerConfig peer = BgpPassivePeerConfig.builder().setLocalIp(Ip.AUTO).setPeerPrefix(remotePrefix).setLocalAs(1L).setRemoteAsns(remoteAsns).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    // Remote peers
    Ip remote1Ip = Ip.parse("2.2.2.1");
    BgpPeerConfigId remote1Id = new BgpPeerConfigId("c2", "vrf2", localAddress, false);
    BgpActivePeerConfig remote1 = BgpActivePeerConfig.builder().setLocalIp(remote1Ip).setPeerAddress(localIp).setLocalAs(2L).setRemoteAs(1L).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    Ip remote2Ip = Ip.parse("2.2.2.2");
    BgpPeerConfigId remote2Id = new BgpPeerConfigId("c3", "vrf3", localAddress, false);
    BgpActivePeerConfig remote2 = BgpActivePeerConfig.builder().setLocalIp(remote2Ip).setPeerAddress(localIp).setLocalAs(3L).setRemoteAs(1L).setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()).build();
    // Configured topology: both remote peers have edges with dynamic peer
    MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build();
    configuredTopology.putEdgeValue(peerId, remote1Id, BgpSessionProperties.from(remote1, peer, true));
    configuredTopology.putEdgeValue(remote1Id, peerId, BgpSessionProperties.from(remote1, peer, false));
    configuredTopology.putEdgeValue(peerId, remote2Id, BgpSessionProperties.from(remote2, peer, true));
    configuredTopology.putEdgeValue(remote2Id, peerId, BgpSessionProperties.from(remote2, peer, false));
    // Established topology: Only remote1 has edge with dynamic peer
    MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build();
    establishedTopology.putEdgeValue(peerId, remote1Id, BgpSessionProperties.from(remote1, peer, true));
    establishedTopology.putEdgeValue(remote1Id, peerId, BgpSessionProperties.from(remote1, peer, false));
    // Build configs for remote peers because answerer needs to look up remote peers from peer IDs
    NetworkConfigurations nc = NetworkConfigurations.of(createConfigurations(ImmutableList.of(remote1Id, remote2Id), ImmutableList.of(remote1, remote2)));
    List<Row> rows = getPassivePeerRows(peerId, peer, nc, configuredTopology, establishedTopology);
    Row.RowBuilder expectedRowBuilder = Row.builder().put(COL_LOCAL_AS, 1L).put(COL_LOCAL_IP, localIp).put(COL_NODE, new Node("c1")).put(COL_SESSION_TYPE, SessionType.EBGP_SINGLEHOP).put(COL_VRF, "vrf1").put(COL_LOCAL_INTERFACE, null).put(COL_REMOTE_INTERFACE, null).put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST));
    Row expected1 = expectedRowBuilder.put(COL_ESTABLISHED_STATUS, BgpSessionStatus.ESTABLISHED).put(COL_REMOTE_AS, "2").put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, remote1Ip)).put(COL_REMOTE_NODE, new Node("c2")).build();
    Row expected2 = expectedRowBuilder.put(COL_ESTABLISHED_STATUS, BgpSessionStatus.NOT_ESTABLISHED).put(COL_REMOTE_AS, "3").put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, remote2Ip)).put(COL_REMOTE_NODE, new Node("c3")).build();
    assertThat(rows, containsInAnyOrder(expected1, expected2));
}
Also used : LongSpace(org.batfish.datamodel.LongSpace) Ip(org.batfish.datamodel.Ip) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Node(org.batfish.datamodel.pojo.Node) Prefix(org.batfish.datamodel.Prefix) BgpSessionProperties(org.batfish.datamodel.BgpSessionProperties) BgpPassivePeerConfig(org.batfish.datamodel.BgpPassivePeerConfig) BgpActivePeerConfig(org.batfish.datamodel.BgpActivePeerConfig) Row(org.batfish.datamodel.table.Row) BgpSessionStatusAnswerer.getActivePeerRow(org.batfish.question.bgpsessionstatus.BgpSessionStatusAnswerer.getActivePeerRow) BgpSessionStatusAnswerer.getUnnumberedPeerRow(org.batfish.question.bgpsessionstatus.BgpSessionStatusAnswerer.getUnnumberedPeerRow) SelfDescribingObject(org.batfish.datamodel.answers.SelfDescribingObject) BgpPeerConfigId(org.batfish.datamodel.BgpPeerConfigId) Test(org.junit.Test)

Example 5 with LongSpace

use of org.batfish.datamodel.LongSpace in project batfish by batfish.

the class IspModelingUtils method combineBorderInterfaces.

/**
 * Combines the {@link BorderInterfaceInfo} and {@link BgpPeerInfo} objects across all {@code
 * ispConfigurations}, returning a map from ASN to the list of {@link SnapshotConnection}
 * connections that ASN should have.
 */
@VisibleForTesting
static Map<Long, List<SnapshotConnection>> combineBorderInterfaces(Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) {
    Map<Long, ImmutableList.Builder<SnapshotConnection>> asnToRemotes = new HashMap<>();
    for (IspConfiguration ispConfiguration : ispConfigurations) {
        Set<Ip> allowedIspIps = ImmutableSet.copyOf(ispConfiguration.getFilter().getOnlyRemoteIps());
        List<Long> remoteAsnsList = ispConfiguration.getFilter().getOnlyRemoteAsns();
        LongSpace allowedIspAsns = remoteAsnsList.isEmpty() ? ALL_AS_NUMBERS : LongSpace.builder().includingAll(remoteAsnsList).build();
        for (BorderInterfaceInfo borderInterfaceInfo : ispConfiguration.getBorderInterfaces()) {
            List<SnapshotConnection> snapshotConnections = getSnapshotConnectionsForBorderInterface(borderInterfaceInfo, allowedIspIps, allowedIspAsns, configurations, warnings);
            if (snapshotConnections.isEmpty()) {
                continue;
            }
            // get the ISP ASN from the first snapshot connection -- they should all be the same
            long asn = snapshotConnections.get(0).getBgpPeer().getLocalAsn();
            asnToRemotes.computeIfAbsent(asn, k -> ImmutableList.builder()).addAll(snapshotConnections);
        }
        for (BgpPeerInfo bgpPeerInfo : ispConfiguration.getBgpPeerInfos()) {
            getSnapshotConnectionForBgpPeerInfo(bgpPeerInfo, allowedIspIps, allowedIspAsns, configurations, warnings).ifPresent(sc -> asnToRemotes.computeIfAbsent(sc.getBgpPeer().getLocalAsn(), k -> ImmutableList.builder()).add(sc));
        }
    }
    return ImmutableMap.copyOf(asnToRemotes.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())));
}
Also used : LongSpace(org.batfish.datamodel.LongSpace) HIGHEST_NEXT_HOP_IP(org.batfish.datamodel.bgp.NextHopIpTieBreaker.HIGHEST_NEXT_HOP_IP) Comparator.naturalOrder(java.util.Comparator.naturalOrder) AddressFamilyCapabilities(org.batfish.datamodel.bgp.AddressFamilyCapabilities) IspAttachment(org.batfish.datamodel.isp_configuration.IspAttachment) IspConfiguration(org.batfish.datamodel.isp_configuration.IspConfiguration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Interface(org.batfish.datamodel.Interface) NULL_INTERFACE_NAME(org.batfish.datamodel.Interface.NULL_INTERFACE_NAME) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PrefixSpace(org.batfish.datamodel.PrefixSpace) LocalOriginationTypeTieBreaker(org.batfish.datamodel.bgp.LocalOriginationTypeTieBreaker) BgpSessionProperties.getSessionType(org.batfish.datamodel.BgpSessionProperties.getSessionType) Layer1Node(org.batfish.common.topology.Layer1Node) Map(java.util.Map) IspNodeInfo(org.batfish.datamodel.isp_configuration.IspNodeInfo) Vrf(org.batfish.datamodel.Vrf) Statement(org.batfish.datamodel.routing_policy.statement.Statement) Conjunction(org.batfish.datamodel.routing_policy.expr.Conjunction) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) BorderInterfaceInfo(org.batfish.datamodel.isp_configuration.BorderInterfaceInfo) ImmutableSet(com.google.common.collect.ImmutableSet) BgpPeerConfig(org.batfish.datamodel.BgpPeerConfig) LocationInfo(org.batfish.specifier.LocationInfo) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DeviceModel(org.batfish.datamodel.DeviceModel) SwitchportMode(org.batfish.datamodel.SwitchportMode) Set(java.util.Set) Collectors(java.util.stream.Collectors) OriginType(org.batfish.datamodel.OriginType) IspTrafficFiltering(org.batfish.datamodel.isp_configuration.traffic_filtering.IspTrafficFiltering) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) MultipathEquivalentAsPathMatchMode(org.batfish.datamodel.MultipathEquivalentAsPathMatchMode) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) Warnings(org.batfish.common.Warnings) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Entry(java.util.Map.Entry) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol) BatfishLogger(org.batfish.common.BatfishLogger) Ip(org.batfish.datamodel.Ip) ALL_AS_NUMBERS(org.batfish.datamodel.BgpPeerConfig.ALL_AS_NUMBERS) LongSpace(org.batfish.datamodel.LongSpace) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) If(org.batfish.datamodel.routing_policy.statement.If) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Statements(org.batfish.datamodel.routing_policy.statement.Statements) BgpActivePeerConfig(org.batfish.datamodel.BgpActivePeerConfig) HashMap(java.util.HashMap) BgpProcess(org.batfish.datamodel.BgpProcess) IpAccessList(org.batfish.datamodel.IpAccessList) Ipv4UnicastAddressFamily(org.batfish.datamodel.bgp.Ipv4UnicastAddressFamily) SetOrigin(org.batfish.datamodel.routing_policy.statement.SetOrigin) HashSet(java.util.HashSet) LiteralOrigin(org.batfish.datamodel.routing_policy.expr.LiteralOrigin) Layer1Edge(org.batfish.common.topology.Layer1Edge) DEFAULT_VRF_NAME(org.batfish.datamodel.Configuration.DEFAULT_VRF_NAME) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.batfish.datamodel.Configuration) StreamSupport(java.util.stream.StreamSupport) UniverseIpSpace(org.batfish.datamodel.UniverseIpSpace) Nonnull(javax.annotation.Nonnull) IspAnnouncement(org.batfish.datamodel.isp_configuration.IspAnnouncement) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Nullable(javax.annotation.Nullable) ConcreteInterfaceAddress(org.batfish.datamodel.ConcreteInterfaceAddress) DeviceType(org.batfish.datamodel.DeviceType) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BgpPeerInfo(org.batfish.datamodel.isp_configuration.BgpPeerInfo) ExplicitPrefixSet(org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet) PrefixRange(org.batfish.datamodel.PrefixRange) StaticRoute(org.batfish.datamodel.StaticRoute) InterfaceType(org.batfish.datamodel.InterfaceType) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) EBGP_SINGLEHOP(org.batfish.datamodel.BgpSessionProperties.SessionType.EBGP_SINGLEHOP) Location.interfaceLinkLocation(org.batfish.specifier.Location.interfaceLinkLocation) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Role(org.batfish.datamodel.isp_configuration.IspNodeInfo.Role) Collections(java.util.Collections) BgpUnnumberedPeerConfig(org.batfish.datamodel.BgpUnnumberedPeerConfig) LinkLocalAddress(org.batfish.datamodel.LinkLocalAddress) Prefix(org.batfish.datamodel.Prefix) HashMap(java.util.HashMap) BorderInterfaceInfo(org.batfish.datamodel.isp_configuration.BorderInterfaceInfo) Ip(org.batfish.datamodel.Ip) BgpPeerInfo(org.batfish.datamodel.isp_configuration.BgpPeerInfo) Entry(java.util.Map.Entry) IspConfiguration(org.batfish.datamodel.isp_configuration.IspConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

LongSpace (org.batfish.datamodel.LongSpace)21 Prefix (org.batfish.datamodel.Prefix)12 Nullable (javax.annotation.Nullable)11 BgpActivePeerConfig (org.batfish.datamodel.BgpActivePeerConfig)11 Ip (org.batfish.datamodel.Ip)10 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)10 Nonnull (javax.annotation.Nonnull)9 BgpPeerConfig (org.batfish.datamodel.BgpPeerConfig)9 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 BgpPassivePeerConfig (org.batfish.datamodel.BgpPassivePeerConfig)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)7 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 Entry (java.util.Map.Entry)7