use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeIpsByHostname_noIps.
/**
* Hosts that own no IPs should be assigned an empty set by computeIpsByHostname
*/
@Test
public void testComputeIpsByHostname_noIps() {
Configuration c = _cb.build();
Vrf v = _vb.setOwner(c).build();
_ib.setOwner(c).setVrf(v).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(c.getName(), c)).setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of())).build();
assertThat(inputWithDataPlane, hasIpsByHostname(equalTo(ImmutableMap.of(c.getName(), ImmutableSet.of()))));
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class SynthesizerInputImplTest method testSourceNatWithNoAcl.
/**
* Test that for a SourceNat with no ACL, the SynthesizerInput will have an "accept everything"
* ACL.
*/
@Test
public void testSourceNatWithNoAcl() {
Configuration srcNode = _cb.build();
Configuration nextHop = _cb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Vrf nextHopVrf = _vb.setOwner(nextHop).build();
Ip ip1 = new Ip("1.0.0.0");
Ip ip2 = new Ip("1.0.0.10");
SourceNat sourceNat = _snb.setPoolIpFirst(ip1).setPoolIpLast(ip2).build();
Interface srcInterfaceOneSourceNat = _ib.setOwner(srcNode).setVrf(srcVrf).setSourceNats(ImmutableList.of(sourceNat)).build();
Interface nextHopInterface = _ib.setOwner(nextHop).setVrf(nextHopVrf).setSourceNats(ImmutableList.of()).build();
Edge forwardEdge = new Edge(srcInterfaceOneSourceNat, nextHopInterface);
Edge backEdge = new Edge(nextHopInterface, srcInterfaceOneSourceNat);
SynthesizerInput inputWithDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(forwardEdge, backEdge))).build();
// Acl for the SourceNat is DefaultSourceNatAcl
assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceOneSourceNat.getName()), equalTo(ImmutableList.of(immutableEntry(new AclPermit(srcNode.getHostname(), SynthesizerInputImpl.DEFAULT_SOURCE_NAT_ACL.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip1.asLong(), ip2.asLong()))))))))));
assertThat(inputWithDataPlane, hasAclConditions(hasEntry(srcNode.getHostname(), ImmutableMap.of(SynthesizerInputImpl.DEFAULT_SOURCE_NAT_ACL.getName(), ImmutableList.of(new HeaderSpaceMatchExpr(IpAccessListLine.builder().setSrcIps(ImmutableList.of(new IpWildcard("0.0.0.0/0"))).build()))))));
assertThat(inputWithDataPlane, hasAclActions(hasEntry(srcNode.getHostname(), ImmutableMap.of(SynthesizerInputImpl.DEFAULT_SOURCE_NAT_ACL.getName(), ImmutableList.of(LineAction.ACCEPT)))));
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeAclActions.
@Test
public void testComputeAclActions() {
Configuration srcNode = _cb.build();
Configuration nextHop = _cb.build();
IpAccessList edgeInterfaceInAcl = _aclb.setOwner(srcNode).setLines(ImmutableList.of(IpAccessListLine.builder().setAction(LineAction.ACCEPT).build(), IpAccessListLine.builder().setAction(LineAction.REJECT).build())).build();
IpAccessList srcInterfaceOutAcl = _aclb.build();
IpAccessList iNoEdgeInAcl = _aclb.build();
IpAccessList iNoEdgeOutAcl = _aclb.build();
IpAccessList nextHopInterfaceInAcl = _aclb.setOwner(nextHop).build();
IpAccessList nextHopInterfaceOutAcl = _aclb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Vrf nextHopVrf = _vb.setOwner(nextHop).build();
Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).setIncomingFilter(edgeInterfaceInAcl).setOutgoingFilter(srcInterfaceOutAcl).build();
/*
* Interface without an edge: Its ACLs should be absent with data plane, but present without
* data plane.
*/
_ib.setIncomingFilter(iNoEdgeInAcl).setOutgoingFilter(iNoEdgeOutAcl).build();
Interface nextHopInterface = _ib.setIncomingFilter(nextHopInterfaceInAcl).setOutgoingFilter(nextHopInterfaceOutAcl).setOwner(nextHop).setVrf(nextHopVrf).build();
Edge forwardEdge = new Edge(srcInterface, nextHopInterface);
Edge backEdge = new Edge(nextHopInterface, srcInterface);
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(forwardEdge, backEdge))).build();
List<LineAction> expectedActions = ImmutableList.of(LineAction.ACCEPT, LineAction.REJECT);
Map<String, List<LineAction>> expectedSrcNodeWithDataPlane = ImmutableMap.of(edgeInterfaceInAcl.getName(), expectedActions, srcInterfaceOutAcl.getName(), expectedActions);
Map<String, List<LineAction>> expectedSrcNodeWithoutDataPlane = ImmutableMap.<String, List<LineAction>>builder().putAll(expectedSrcNodeWithDataPlane).put(iNoEdgeInAcl.getName(), expectedActions).put(iNoEdgeOutAcl.getName(), expectedActions).build();
Map<String, List<LineAction>> expectedNextHop = ImmutableMap.of(nextHopInterfaceInAcl.getName(), expectedActions, nextHopInterfaceOutAcl.getName(), expectedActions);
assertThat(inputWithDataPlane, hasAclActions(equalTo(ImmutableMap.of(srcNode.getName(), expectedSrcNodeWithDataPlane, nextHop.getName(), expectedNextHop))));
assertThat(inputWithoutDataPlane, hasAclActions(equalTo(ImmutableMap.of(srcNode.getName(), expectedSrcNodeWithoutDataPlane, nextHop.getName(), expectedNextHop))));
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class BatfishCompressionTest method diamondNetwork.
/**
* This network should be compressed from: A --> B --> D, A --> C --> D to A --> {B,C} --> D.
* i.e., B and C should be merged into one node.
*
* @return Configurations for the original (uncompressed) network.
*/
private SortedMap<String, Configuration> diamondNetwork() {
NetworkFactory nf = new NetworkFactory();
Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
Configuration cA = cb.setHostname("A").build();
Configuration cB = cb.setHostname("B").build();
Configuration cC = cb.setHostname("C").build();
Configuration cD = cb.setHostname("D").build();
Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);
Vrf vA = vb.setOwner(cA).build();
Vrf vB = vb.setOwner(cB).build();
Vrf vC = vb.setOwner(cC).build();
Vrf vD = vb.setOwner(cD).build();
Prefix pAB = Prefix.parse("10.12.0.0/31");
Prefix pAC = Prefix.parse("10.13.0.0/31");
Prefix pBD = Prefix.parse("10.24.0.0/31");
Prefix pCD = Prefix.parse("10.34.0.0/31");
Interface.Builder ib = nf.interfaceBuilder().setActive(true);
// Add a route from A --> B
ib.setOwner(cA).setVrf(vA).setAddress(new InterfaceAddress(pAB.getStartIp(), pAB.getPrefixLength())).build();
// Interface iBA
ib.setOwner(cB).setVrf(vA).setAddress(new InterfaceAddress(pAB.getEndIp(), pAB.getPrefixLength())).build();
// Interface iAC
ib.setOwner(cA).setVrf(vA).setAddress(new InterfaceAddress(pAC.getStartIp(), pAC.getPrefixLength())).build();
// Interface iCA
ib.setOwner(cC).setVrf(vC).setAddress(new InterfaceAddress(pAC.getEndIp(), pAC.getPrefixLength())).build();
// Interface iBD
ib.setOwner(cB).setVrf(vB).setAddress(new InterfaceAddress(pBD.getStartIp(), pBD.getPrefixLength())).build();
// Interface iDB
ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pBD.getEndIp(), pBD.getPrefixLength())).build();
// Interface iCD
ib.setOwner(cC).setVrf(vC).setAddress(new InterfaceAddress(pCD.getStartIp(), pCD.getPrefixLength())).build();
// Interface iDC
ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pCD.getEndIp(), pCD.getPrefixLength())).build();
// For the destination
Prefix pD = Prefix.parse("4.4.4.4/32");
// Interface iD
ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pD.getEndIp(), pD.getPrefixLength())).build();
StaticRoute.Builder bld = StaticRoute.builder().setNetwork(pD);
vA.getStaticRoutes().add(bld.setNextHopIp(pAB.getEndIp()).build());
vA.getStaticRoutes().add(bld.setNextHopIp(pAC.getEndIp()).build());
vB.getStaticRoutes().add(bld.setNextHopIp(pBD.getEndIp()).build());
vC.getStaticRoutes().add(bld.setNextHopIp(pCD.getEndIp()).build());
return new TreeMap<>(ImmutableSortedMap.of(cA.getName(), cA, cB.getName(), cB, cC.getName(), cC, cD.getName(), cD));
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_compressibleNetwork.
/**
* 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_compressibleNetwork() throws IOException {
DataPlane origDataPlane = getDataPlane(compressibleNetwork());
SortedMap<String, Configuration> compressedConfigs = compressNetwork(compressibleNetwork(), new HeaderSpace());
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
/* Compression removed a node */
assertThat(compressedConfigs.entrySet(), hasSize(2));
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
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));
}
}));
}
Aggregations