Search in sources :

Example 61 with Interface

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()));
}
Also used : Configuration(org.batfish.datamodel.Configuration) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 62 with Interface

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)))));
}
Also used : SourceNat(org.batfish.datamodel.SourceNat) IpWildcard(org.batfish.datamodel.IpWildcard) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) AclPermit(org.batfish.z3.state.AclPermit) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 63 with Interface

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))));
}
Also used : LineAction(org.batfish.datamodel.LineAction) Configuration(org.batfish.datamodel.Configuration) List(java.util.List) IpAccessList(org.batfish.datamodel.IpAccessList) ImmutableList(com.google.common.collect.ImmutableList) IpAccessList(org.batfish.datamodel.IpAccessList) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 64 with Interface

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));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) NetworkFactory(org.batfish.datamodel.NetworkFactory) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) TreeMap(java.util.TreeMap) Interface(org.batfish.datamodel.Interface)

Example 65 with Interface

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));
        }));
    }
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) CommonUtil.toImmutableMap(org.batfish.common.util.CommonUtil.toImmutableMap) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) Function(java.util.function.Function) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) EmptyIpSpace(org.batfish.datamodel.EmptyIpSpace) Configuration(org.batfish.datamodel.Configuration) LineAction(org.batfish.datamodel.LineAction) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Pair(org.batfish.common.Pair) Nullable(javax.annotation.Nullable) BooleanExpr(org.batfish.z3.expr.BooleanExpr) ImmutableSet(com.google.common.collect.ImmutableSet) NetworkFactory(org.batfish.datamodel.NetworkFactory) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) CommonUtil.computeIpOwners(org.batfish.common.util.CommonUtil.computeIpOwners) Range(com.google.common.collect.Range) Set(java.util.Set) IpSpace(org.batfish.datamodel.IpSpace) AclPermit(org.batfish.z3.state.AclPermit) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) List(java.util.List) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) Entry(java.util.Map.Entry) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) Ip(org.batfish.datamodel.Ip) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) IpAccessList(org.batfish.datamodel.IpAccessList) Interface(org.batfish.datamodel.Interface) Pair(org.batfish.common.Pair)

Aggregations

Interface (org.batfish.datamodel.Interface)68 Configuration (org.batfish.datamodel.Configuration)42 Ip (org.batfish.datamodel.Ip)26 Edge (org.batfish.datamodel.Edge)21 Prefix (org.batfish.datamodel.Prefix)20 Test (org.junit.Test)19 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)18 Vrf (org.batfish.datamodel.Vrf)18 HashMap (java.util.HashMap)17 IpAccessList (org.batfish.datamodel.IpAccessList)16 Topology (org.batfish.datamodel.Topology)14 ArrayList (java.util.ArrayList)13 List (java.util.List)13 StaticRoute (org.batfish.datamodel.StaticRoute)13 HashSet (java.util.HashSet)12 Set (java.util.Set)12 BatfishException (org.batfish.common.BatfishException)12 Map (java.util.Map)11 TreeSet (java.util.TreeSet)10 SortedSet (java.util.SortedSet)9