use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeEnabledEdges.
@Test
public void testComputeEnabledEdges() {
Configuration srcNode = _cb.build();
Configuration nextHop = _cb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Vrf nextHopVrf = _vb.setOwner(nextHop).build();
Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).build();
Interface nextHopInterface = _ib.setOwner(nextHop).setVrf(nextHopVrf).build();
Interface disabledNextHopInterface = _ib.setActive(false).build();
Edge expectedEnabledEdge = new Edge(srcInterface, nextHopInterface);
Edge expectedDisabledEdge = new Edge(srcInterface, disabledNextHopInterface);
SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(expectedEnabledEdge, expectedDisabledEdge))).build();
assertThat(inputWithDataPlane, hasEnabledEdges(hasItem(expectedEnabledEdge)));
assertThat(inputWithDataPlane, hasEnabledEdges(not(hasItem(expectedDisabledEdge))));
assertThat(inputWithDataPlane, hasEnabledEdges(not(hasItem(expectedDisabledEdge))));
assertThat(inputWithoutDataPlane, hasEnabledEdges(nullValue()));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeArpTrueEdge.
@Test
public void testComputeArpTrueEdge() {
Configuration srcNode = _cb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).build();
String nextHop1 = "nextHop1";
String nextHopInterface1 = "nextHopInterface1";
String nextHop2 = "nextHop2";
String nextHopInterface2 = "nextHopInterface2";
IpSpace ipSpace1 = Ip.ZERO;
IpSpace ipSpace2 = Ip.MAX;
IpSpaceMatchExpr m1 = new IpSpaceMatchExpr(ipSpace1, false, true);
IpSpaceMatchExpr m2 = new IpSpaceMatchExpr(ipSpace2, false, true);
Edge edge1 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop1, nextHopInterface1);
Edge edge2 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop2, nextHopInterface2);
SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode)).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().setArpTrueEdge(ImmutableMap.of(edge1, ipSpace1, edge2, ipSpace2)).build()).setTopology(new Topology(ImmutableSortedSet.of(edge1, edge2))).build();
assertThat(inputWithoutDataPlane, hasArpTrueEdge(nullValue()));
assertThat(inputWithDataPlane, hasArpTrueEdge(equalTo(ImmutableMap.of(srcNode.getHostname(), ImmutableMap.of(srcVrf.getName(), ImmutableMap.of(srcInterface.getName(), ImmutableMap.of(nextHop1, ImmutableMap.of(nextHopInterface1, m1), nextHop2, ImmutableMap.of(nextHopInterface2, m2))))))));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeEnabledVrfs.
@Test
public void testComputeEnabledVrfs() {
Configuration cEnabled = _cb.build();
Configuration cDisabled = _cb.build();
Vrf vEnabled = _vb.setOwner(cEnabled).build();
Vrf vDisabledViaVrf = _vb.build();
// disabled via disabledNodes
_vb.setOwner(cDisabled).build();
SynthesizerInput input = _inputBuilder.setConfigurations(ImmutableMap.of(cEnabled.getName(), cEnabled, cDisabled.getName(), cDisabled)).setDisabledNodes(ImmutableSet.of(cDisabled.getName())).setDisabledVrfs(ImmutableMap.of(cEnabled.getName(), ImmutableSet.of(vDisabledViaVrf.getName()))).build();
assertThat(input, hasEnabledVrfs(hasEntry(equalTo(cEnabled.getName()), hasItem(vEnabled.getName()))));
assertThat(input, hasEnabledVrfs(hasEntry(equalTo(cEnabled.getName()), not(hasItem(vDisabledViaVrf.getName())))));
assertThat(input, hasEnabledVrfs(not(hasKey(cDisabled.getName()))));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeSourceNats.
@Test
public void testComputeSourceNats() {
Configuration srcNode = _cb.build();
Configuration nextHop = _cb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Vrf nextHopVrf = _vb.setOwner(nextHop).build();
Ip ip11 = new Ip("1.0.0.0");
Ip ip12 = new Ip("1.0.0.10");
Ip ip21 = new Ip("2.0.0.0");
Ip ip22 = new Ip("2.0.0.10");
IpAccessList sourceNat1Acl = _aclb.setLines(ImmutableList.of()).setOwner(srcNode).build();
IpAccessList sourceNat2Acl = _aclb.build();
SourceNat sourceNat1 = _snb.setPoolIpFirst(ip11).setPoolIpLast(ip12).setAcl(sourceNat1Acl).build();
SourceNat sourceNat2 = _snb.setPoolIpFirst(ip21).setPoolIpLast(ip22).setAcl(sourceNat2Acl).build();
Interface srcInterfaceZeroSourceNats = _ib.setOwner(srcNode).setVrf(srcVrf).setSourceNats(ImmutableList.of()).build();
Interface srcInterfaceOneSourceNat = _ib.setSourceNats(ImmutableList.of(sourceNat1)).build();
Interface srcInterfaceTwoSourceNats = _ib.setSourceNats(ImmutableList.of(sourceNat1, sourceNat2)).build();
Interface nextHopInterface = _ib.setOwner(nextHop).setVrf(nextHopVrf).setSourceNats(ImmutableList.of()).build();
Edge forwardEdge1 = new Edge(srcInterfaceZeroSourceNats, nextHopInterface);
Edge forwardEdge2 = new Edge(srcInterfaceOneSourceNat, nextHopInterface);
Edge forwardEdge3 = new Edge(srcInterfaceTwoSourceNats, nextHopInterface);
Edge backEdge1 = new Edge(nextHopInterface, srcInterfaceZeroSourceNats);
Edge backEdge2 = new Edge(nextHopInterface, srcInterfaceOneSourceNat);
Edge backEdge3 = new Edge(nextHopInterface, srcInterfaceTwoSourceNats);
SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(forwardEdge1, forwardEdge2, forwardEdge3, backEdge1, backEdge2, backEdge3))).build();
assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceZeroSourceNats.getName()), equalTo(ImmutableList.of())))));
assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceOneSourceNat.getName()), equalTo(ImmutableList.of(immutableEntry(new AclPermit(srcNode.getName(), sourceNat1Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip11.asLong(), ip12.asLong()))))))))));
assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceTwoSourceNats.getName()), equalTo(ImmutableList.of(immutableEntry(new AclPermit(srcNode.getName(), sourceNat1Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip11.asLong(), ip12.asLong())))), immutableEntry(new AclPermit(srcNode.getName(), sourceNat2Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip21.asLong(), ip22.asLong()))))))))));
assertThat(inputWithoutDataPlane, hasSourceNats(nullValue()));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_diamondNetwork.
/**
* Test the following invariant: if a FIB appears on concrete router “r”, then a corresponding
* abstract FIB appears on one of these representatives. For example, if there is a concrete FIB
* from C to D, then there should be an abstract FIB from A to B, where A is in representatives(C)
* and B is in representatives(D).
*/
@Test
public void testCompressionFibs_diamondNetwork() throws IOException {
IpAccessListLine line = new IpAccessListLine();
line.setDstIps(ImmutableList.of(new IpWildcard(Prefix.parse("4.4.4.4/32"))));
SortedMap<String, Configuration> origConfigs = diamondNetwork();
DataPlane origDataPlane = getDataPlane(origConfigs);
Map<String, Map<String, Fib>> origFibs = origDataPlane.getFibs();
Topology origTopology = new Topology(origDataPlane.getTopologyEdges());
/* Node A should have a route with C as a next hop. */
assertThat(origFibs, hasEntry(equalTo("A"), hasEntry(equalTo(Configuration.DEFAULT_VRF_NAME), hasNextHopInterfaces(hasValue(hasKey(withNode("A", isNeighborOfNode(origTopology, "C"))))))));
// compress a new copy since it will get mutated.
SortedMap<String, Configuration> compressedConfigs = new TreeMap<>(compressNetwork(diamondNetwork(), line));
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
assertThat(compressedConfigs.values(), hasSize(3));
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
compressedRibs.forEach((hostname, compressedRibsByVrf) -> compressedRibsByVrf.forEach((vrf, compressedRib) -> {
GenericRib<AbstractRoute> origRib = origRibs.get(hostname).get(vrf);
Set<AbstractRoute> origRoutes = origRib.getRoutes();
Set<AbstractRoute> compressedRoutes = compressedRib.getRoutes();
for (AbstractRoute route : compressedRoutes) {
/* Every compressed route should appear in original RIB */
assertThat(origRoutes, hasItem(route));
}
}));
/* Compression removed B or C entirely (but not both) */
assertThat(compressedRibs, either(not(hasKey("B"))).or(not(hasKey("C"))));
assertThat(compressedRibs, either(hasKey("B")).or(hasKey("C")));
String remains = compressedConfigs.containsKey("B") ? "B" : "C";
/* The remaining node is unchanged. */
assertThat(origRibs.get(remains).get(Configuration.DEFAULT_VRF_NAME).getRoutes(), equalTo(compressedRibs.get(remains).get(Configuration.DEFAULT_VRF_NAME).getRoutes()));
}
Aggregations