Search in sources :

Example 41 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class SynthesizerInputImplTest method testComputeAclConditions.

@Test
public void testComputeAclConditions() {
    Configuration c = _cb.build();
    IpAccessList aclWithoutLines = _aclb.setOwner(c).build();
    _acllb.setAction(LineAction.ACCEPT);
    IpAccessList aclWithLines = _aclb.setLines(ImmutableList.<IpAccessListLine>of(_acllb.setDstIps(ImmutableSet.of(new IpWildcard(new Ip("1.2.3.4")))).build(), _acllb.setDstIps(ImmutableSet.of(new IpWildcard(new Ip("5.6.7.8")))).build())).build();
    SynthesizerInput input = _inputBuilder.setConfigurations(ImmutableMap.of(c.getName(), c)).build();
    assertThat(input, hasAclConditions(equalTo(ImmutableMap.of(c.getName(), ImmutableMap.of(aclWithoutLines.getName(), ImmutableList.of(), aclWithLines.getName(), ImmutableList.of(new HeaderSpaceMatchExpr(aclWithLines.getLines().get(0)), new HeaderSpaceMatchExpr(aclWithLines.getLines().get(1))))))));
    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 inputWithDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(forwardEdge1, forwardEdge2, forwardEdge3, backEdge1, backEdge2, backEdge3))).build();
    assertThat(inputWithDataPlane, hasAclConditions(equalTo(ImmutableMap.of(srcNode.getName(), ImmutableMap.of(sourceNat1Acl.getName(), ImmutableList.of(), sourceNat2Acl.getName(), ImmutableList.of()), nextHop.getName(), ImmutableMap.of()))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) SourceNat(org.batfish.datamodel.SourceNat) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) 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 42 with Edge

use of org.batfish.datamodel.Edge 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 43 with Edge

use of org.batfish.datamodel.Edge 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 44 with Edge

use of org.batfish.datamodel.Edge 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 45 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class SynthesizerInputImpl method computeArpTrueEdge.

private Map<String, Map<String, Map<String, Map<String, Map<String, BooleanExpr>>>>> computeArpTrueEdge(Map<Edge, IpSpace> arpTrueEdge) {
    Map<String, Map<String, Map<String, Map<String, Map<String, BooleanExpr>>>>> output = new HashMap<>();
    arpTrueEdge.forEach((edge, ipSpace) -> {
        ipSpace = _ipSpaceSpecializer.specialize(ipSpace);
        if (ipSpace instanceof EmptyIpSpace) {
            return;
        }
        String hostname = edge.getNode1();
        String outInterface = edge.getInt1();
        String vrf = _configurations.get(hostname).getInterfaces().get(outInterface).getVrfName();
        String recvNode = edge.getNode2();
        String recvInterface = edge.getInt2();
        output.computeIfAbsent(hostname, n -> new HashMap<>()).computeIfAbsent(vrf, n -> new HashMap<>()).computeIfAbsent(outInterface, n -> new HashMap<>()).computeIfAbsent(recvNode, n -> new HashMap<>()).put(recvInterface, new IpSpaceMatchExpr(ipSpace, false, true));
    });
    // freeze
    return toImmutableMap(output, Entry::getKey, /* node */
    outputByHostnameEntry -> toImmutableMap(outputByHostnameEntry.getValue(), Entry::getKey, /* vrf */
    outputByVrfEntry -> toImmutableMap(outputByVrfEntry.getValue(), Entry::getKey, /* outInterface */
    outputByOutInterfaceEntry -> toImmutableMap(outputByOutInterfaceEntry.getValue(), Entry::getKey, /* recvNode */
    outputByRecvNodeEntry -> toImmutableMap(outputByRecvNodeEntry.getValue(), Entry::getKey, /* recvInterface */
    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) HashMap(java.util.HashMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) CommonUtil.toImmutableMap(org.batfish.common.util.CommonUtil.toImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EmptyIpSpace(org.batfish.datamodel.EmptyIpSpace) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Aggregations

Edge (org.batfish.datamodel.Edge)46 Configuration (org.batfish.datamodel.Configuration)23 Interface (org.batfish.datamodel.Interface)19 Topology (org.batfish.datamodel.Topology)17 Test (org.junit.Test)17 Ip (org.batfish.datamodel.Ip)12 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)12 Vrf (org.batfish.datamodel.Vrf)10 BatfishException (org.batfish.common.BatfishException)9 FlowTrace (org.batfish.datamodel.FlowTrace)8 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7 TreeSet (java.util.TreeSet)7 IpAccessList (org.batfish.datamodel.IpAccessList)7 HostConfiguration (org.batfish.representation.host.HostConfiguration)7 VendorConfiguration (org.batfish.vendor.VendorConfiguration)7 SynthesizerInputMatchers.hasArpTrueEdge (org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge)7 HashMap (java.util.HashMap)6 FlowTraceHop (org.batfish.datamodel.FlowTraceHop)6 AclPermit (org.batfish.z3.state.AclPermit)6