Search in sources :

Example 21 with SynthesizerInput

use of org.batfish.z3.SynthesizerInput in project batfish by batfish.

the class SynthesizerInputImplTest method testComputeNeighborUnreachable.

@Test
public void testComputeNeighborUnreachable() {
    Configuration node = _cb.build();
    Vrf vrf = _vb.setOwner(node).build();
    Interface iface1 = _ib.setOwner(node).setVrf(vrf).build();
    Interface iface2 = _ib.build();
    IpSpace ipSpace1 = Ip.ZERO;
    IpSpace ipSpace2 = Ip.MAX;
    IpSpaceMatchExpr m1 = new IpSpaceMatchExpr(ipSpace1, false, true);
    IpSpaceMatchExpr m2 = new IpSpaceMatchExpr(ipSpace2, false, true);
    SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(node.getName(), node)).build();
    SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().setNeighborUnreachable(ImmutableMap.of(node.getName(), ImmutableMap.of(vrf.getName(), ImmutableMap.of(iface1.getName(), ipSpace1, iface2.getName(), ipSpace2)))).build()).setTopology(new Topology(ImmutableSortedSet.of())).build();
    assertThat(inputWithoutDataPlane, hasNeighborUnreachable(nullValue()));
    assertThat(inputWithDataPlane, hasNeighborUnreachable(equalTo(ImmutableMap.of(node.getHostname(), ImmutableMap.of(vrf.getName(), ImmutableMap.of(iface1.getName(), m1, iface2.getName(), m2))))));
}
Also used : Configuration(org.batfish.datamodel.Configuration) IpSpace(org.batfish.datamodel.IpSpace) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 22 with SynthesizerInput

use of org.batfish.z3.SynthesizerInput 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()));
}
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 23 with SynthesizerInput

use of org.batfish.z3.SynthesizerInput 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))))))));
}
Also used : Configuration(org.batfish.datamodel.Configuration) IpSpace(org.batfish.datamodel.IpSpace) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) 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 24 with SynthesizerInput

use of org.batfish.z3.SynthesizerInput 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()));
}
Also used : SourceNat(org.batfish.datamodel.SourceNat) 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) IpAccessList(org.batfish.datamodel.IpAccessList) 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 25 with SynthesizerInput

use of org.batfish.z3.SynthesizerInput in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testPreOutEdgePostNat.

@Test
public void testPreOutEdgePostNat() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE1, NODE2, INTERFACE2), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE2), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE2), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdgePostNat.State.INSTANCE)));
    BooleanExpr newSrcIpEqualsCurrentSrcIp = new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent()));
    // PreOutEdgePostNatForTopologyEdges
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE2))));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) PreOutEdge(org.batfish.z3.state.PreOutEdge) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) EqExpr(org.batfish.z3.expr.EqExpr) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) Edge(org.batfish.datamodel.Edge) PostOutEdge(org.batfish.z3.state.PostOutEdge) PreOutEdge(org.batfish.z3.state.PreOutEdge) BooleanExpr(org.batfish.z3.expr.BooleanExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)38 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)35 RuleStatement (org.batfish.z3.expr.RuleStatement)34 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)30 SynthesizerInput (org.batfish.z3.SynthesizerInput)30 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)30 Edge (org.batfish.datamodel.Edge)12 Configuration (org.batfish.datamodel.Configuration)8 Interface (org.batfish.datamodel.Interface)8 Topology (org.batfish.datamodel.Topology)8 Vrf (org.batfish.datamodel.Vrf)8 ImmutableList (com.google.common.collect.ImmutableList)7 SynthesizerInputMatchers.hasArpTrueEdge (org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge)7 AclPermit (org.batfish.z3.state.AclPermit)7 BooleanExpr (org.batfish.z3.expr.BooleanExpr)6 PreOut (org.batfish.z3.state.PreOut)6 PreOutEdge (org.batfish.z3.state.PreOutEdge)6 Ip (org.batfish.datamodel.Ip)5 IpWildcard (org.batfish.datamodel.IpWildcard)5 AclLineMatch (org.batfish.z3.state.AclLineMatch)5