use of org.batfish.datamodel.Interface in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeTopologyInterfaces.
@Test
public void testComputeTopologyInterfaces() {
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 iNoEdge = _ib.build();
Interface nextHopInterface = _ib.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();
assertThat(inputWithDataPlane, hasTopologyInterfaces(hasEntry(equalTo(srcNode.getName()), hasItem(srcInterface.getName()))));
assertThat(inputWithDataPlane, hasTopologyInterfaces(hasEntry(equalTo(srcNode.getName()), not(hasItem(iNoEdge.getName())))));
assertThat(inputWithDataPlane, hasTopologyInterfaces(hasEntry(equalTo(nextHop.getName()), hasItem(nextHopInterface.getName()))));
assertThat(inputWithoutDataPlane, hasTopologyInterfaces(nullValue()));
}
use of org.batfish.datamodel.Interface 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.Interface 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.Interface 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.Interface in project batfish by batfish.
the class SynthesizerInputImpl method computeEnabledAcls.
private Map<String, Map<String, IpAccessList>> computeEnabledAcls() {
if (_topologyInterfaces != null) {
return toImmutableMap(_topologyInterfaces, Entry::getKey, /* node */
topologyInterfacesEntry -> {
String hostname = topologyInterfacesEntry.getKey();
Configuration c = _configurations.get(hostname);
return topologyInterfacesEntry.getValue().stream().flatMap(ifaceName -> {
Interface i = c.getInterfaces().get(ifaceName);
ImmutableList.Builder<Pair<String, IpAccessList>> interfaceAcls = ImmutableList.builder();
IpAccessList aclIn = i.getIncomingFilter();
IpAccessList aclOut = i.getOutgoingFilter();
if (aclIn != null) {
aclIn = _ipAclListSpecializer.specialize(aclIn);
interfaceAcls.add(new Pair<>(aclIn.getName(), aclIn));
}
if (aclOut != null) {
aclOut = _ipAclListSpecializer.specialize(aclOut);
interfaceAcls.add(new Pair<>(aclOut.getName(), aclOut));
}
i.getSourceNats().forEach(sourceNat -> {
IpAccessList sourceNatAcl = sourceNat.getAcl();
if (sourceNatAcl != null) {
interfaceAcls.add(new Pair<>(sourceNatAcl.getName(), sourceNatAcl));
} else {
interfaceAcls.add(new Pair<>(DEFAULT_SOURCE_NAT_ACL.getName(), DEFAULT_SOURCE_NAT_ACL));
}
});
return interfaceAcls.build().stream();
}).collect(ImmutableSet.toImmutableSet()).stream().collect(ImmutableMap.toImmutableMap(Pair::getFirst, Pair::getSecond));
});
} else {
return _configurations.entrySet().stream().filter(e -> !_disabledNodes.contains(e.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> {
String hostname = e.getKey();
Set<String> disabledAcls = _disabledAcls.get(hostname);
return e.getValue().getIpAccessLists().entrySet().stream().filter(e2 -> disabledAcls == null || !disabledAcls.contains(e2.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
}));
}
}
Aggregations