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;
}
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);
}
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));
}
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));
}
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())));
}
Aggregations