Search in sources :

Example 11 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class RelationCollectorTest method testVisitQueryStatement.

/**
 * Test that collectRelations traverses the child of a QueryStatement.
 */
@Test
public void testVisitQueryStatement() {
    StateExpr p1 = newStateExpr();
    QueryStatement expr = new QueryStatement(p1);
    Set<String> expectedRelations = ImmutableSet.of(getNodName(_input, p1));
    assertThat(collectRelations(_input, expr), equalTo(expectedRelations));
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) Test(org.junit.Test)

Example 12 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class RelationCollectorTest method testVisitBasicRuleStatement.

/**
 * Test that collectRelations traverses the child of a BasicRuleStatement.
 */
@Test
public void testVisitBasicRuleStatement() {
    StateExpr p1 = newStateExpr();
    StateExpr p2 = newStateExpr();
    BasicRuleStatement expr1 = new BasicRuleStatement(p1);
    Set<String> expectedRelations1 = ImmutableSet.of(getNodName(_input, p1));
    BasicRuleStatement expr2 = new BasicRuleStatement(p1, p2);
    Set<String> expectedRelations2 = ImmutableSet.of(getNodName(_input, p1), getNodName(_input, p2));
    assertThat(collectRelations(_input, expr1), equalTo(expectedRelations1));
    assertThat(collectRelations(_input, expr2), equalTo(expectedRelations2));
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 13 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class DefaultTransitionGenerator method visitNodeDropAclOut.

@Override
public void visitNodeDropAclOut(NodeDropAclOut.State nodeDropAclOut) {
    _input.getEnabledEdges().forEach(edge -> {
        String node1 = edge.getNode1();
        String iface1 = edge.getInt1();
        String node2 = edge.getNode2();
        String iface2 = edge.getInt2();
        String outAcl = _input.getOutgoingAcls().get(node1).get(iface1);
        // There has to be an ACL -- no ACL is an implicit Permit.
        if (outAcl != null) {
            Set<StateExpr> postTransformationPreStates = ImmutableSet.of(new AclDeny(node1, outAcl), new PreOutEdgePostNat(node1, iface1, node2, iface2));
            _rules.add(new BasicRuleStatement(TrueExpr.INSTANCE, postTransformationPreStates, new NodeDropAclOut(node1)));
        }
    });
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) AclDeny(org.batfish.z3.state.AclDeny) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut)

Example 14 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateMatchSourceNatRules.

private void visitPreOutEdgePostNat_generateMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
    List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().get(node1).get(iface1);
    for (int natNumber = 0; natNumber < sourceNats.size(); natNumber++) {
        ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
        preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
        // does not match any previous source NAT.
        sourceNats.subList(0, natNumber).stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
        // does match the current source NAT.
        preStates.add(sourceNats.get(natNumber).getKey());
        BooleanExpr transformationExpr = sourceNats.get(natNumber).getValue();
        _rules.add(new TransformationRuleStatement(transformationExpr, preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
    }
}
Also used : DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) AclLineMatch(org.batfish.z3.state.AclLineMatch) Drop(org.batfish.z3.state.Drop) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) NumberedQuery(org.batfish.z3.state.NumberedQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PostIn(org.batfish.z3.state.PostIn) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) State(org.batfish.z3.expr.StateExpr.State) Originate(org.batfish.z3.state.Originate) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Query(org.batfish.z3.state.Query) PostOutEdge(org.batfish.z3.state.PostOutEdge) List(java.util.List) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) OriginateVrf(org.batfish.z3.state.OriginateVrf) PreOutEdge(org.batfish.z3.state.PreOutEdge) Entry(java.util.Map.Entry) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) IpWildcard(org.batfish.datamodel.IpWildcard) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) TrueExpr(org.batfish.z3.expr.TrueExpr) DropAcl(org.batfish.z3.state.DropAcl) DropNullRoute(org.batfish.z3.state.DropNullRoute) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) NodeAccept(org.batfish.z3.state.NodeAccept) ImmutableList(com.google.common.collect.ImmutableList) StateExpr(org.batfish.z3.expr.StateExpr) LineAction(org.batfish.datamodel.LineAction) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) PreOut(org.batfish.z3.state.PreOut) AclDeny(org.batfish.z3.state.AclDeny) NotExpr(org.batfish.z3.expr.NotExpr) AclPermit(org.batfish.z3.state.AclPermit) VarIntExpr(org.batfish.z3.expr.VarIntExpr) PreInInterface(org.batfish.z3.state.PreInInterface) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) EqExpr(org.batfish.z3.expr.EqExpr) PostInInterface(org.batfish.z3.state.PostInInterface) AclDeny(org.batfish.z3.state.AclDeny) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) StateExpr(org.batfish.z3.expr.StateExpr) Entry(java.util.Map.Entry) PreOutEdge(org.batfish.z3.state.PreOutEdge) ImmutableSet(com.google.common.collect.ImmutableSet) BooleanExpr(org.batfish.z3.expr.BooleanExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat)

Example 15 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class StandardReachabilityQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    List<StateExpr> finalActions = computeFinalActions();
    ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
    finalActions.stream().map(finalAction -> new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(finalAction), Query.INSTANCE)).forEach(rules::add);
    addOriginateRules(rules);
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAction(org.batfish.datamodel.ForwardingAction) DropAcl(org.batfish.z3.state.DropAcl) DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) BatfishException(org.batfish.common.BatfishException) Drop(org.batfish.z3.state.Drop) DropNullRoute(org.batfish.z3.state.DropNullRoute) NodeAccept(org.batfish.z3.state.NodeAccept) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) StateExpr(org.batfish.z3.expr.StateExpr) Nonnull(javax.annotation.Nonnull) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) ImmutableSet(com.google.common.collect.ImmutableSet) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) Set(java.util.Set) Query(org.batfish.z3.state.Query) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) List(java.util.List) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) QueryStatement(org.batfish.z3.expr.QueryStatement) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) AndExpr(org.batfish.z3.expr.AndExpr) StateExpr(org.batfish.z3.expr.StateExpr) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Aggregations

Test (org.junit.Test)10 StateExpr (org.batfish.z3.expr.StateExpr)9 TestStateExpr (org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)7 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 ImmutableList (com.google.common.collect.ImmutableList)4 NodeAccept (org.batfish.z3.state.NodeAccept)4 NodeDrop (org.batfish.z3.state.NodeDrop)4 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 BooleanExpr (org.batfish.z3.expr.BooleanExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 Accept (org.batfish.z3.state.Accept)3 AclDeny (org.batfish.z3.state.AclDeny)3 Debug (org.batfish.z3.state.Debug)3 Drop (org.batfish.z3.state.Drop)3 DropAcl (org.batfish.z3.state.DropAcl)3 DropAclIn (org.batfish.z3.state.DropAclIn)3