Search in sources :

Example 1 with AclLineNoMatch

use of org.batfish.z3.state.AclLineNoMatch in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitAclDeny.

@Test
public void testVisitAclDeny() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclActions(aclActions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclDeny.State.INSTANCE)));
    // MatchDenyLine
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 1), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 3), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 0), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 2), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 1), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 3), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 0), new AclDeny(NODE2, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 2), new AclDeny(NODE2, ACL2))));
    // MatchNoLines
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE1, ACL1, 3), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE1, ACL2, 3), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclDeny(NODE1, ACL3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE2, ACL1, 3), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE2, ACL2, 3), new AclDeny(NODE2, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclDeny(NODE1, ACL3))));
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) AclDeny(org.batfish.z3.state.AclDeny) 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) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 2 with AclLineNoMatch

use of org.batfish.z3.state.AclLineNoMatch in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitAclLineNoMatch.

@Test
public void testVisitAclLineNoMatch() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclConditions(aclConditions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclLineNoMatch.State.INSTANCE)));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 0)), new AclLineNoMatch(NODE1, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 1)), new AclLineNoMatch(NODE1, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 2)), new AclLineNoMatch(NODE1, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 0)), new AclLineNoMatch(NODE1, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 1)), new AclLineNoMatch(NODE1, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 2)), new AclLineNoMatch(NODE1, ACL2, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 0)), new AclLineNoMatch(NODE2, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 1)), new AclLineNoMatch(NODE2, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 2)), new AclLineNoMatch(NODE2, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 0)), new AclLineNoMatch(NODE2, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 1)), new AclLineNoMatch(NODE2, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 2)), new AclLineNoMatch(NODE2, ACL2, 3))));
}
Also used : 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) NotExpr(org.batfish.z3.expr.NotExpr) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 3 with AclLineNoMatch

use of org.batfish.z3.state.AclLineNoMatch in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitAclLineMatch.

@Test
public void testVisitAclLineMatch() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclConditions(aclConditions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclLineMatch.State.INSTANCE)));
    // MatchCurrentAndDontMatchPrevious
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, new AclLineMatch(NODE1, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 0)), new AclLineMatch(NODE1, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 1)), new AclLineMatch(NODE1, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 2)), new AclLineMatch(NODE1, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, new AclLineMatch(NODE1, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 0)), new AclLineMatch(NODE1, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 1)), new AclLineMatch(NODE1, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 2)), new AclLineMatch(NODE1, ACL2, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, new AclLineMatch(NODE2, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 0)), new AclLineMatch(NODE2, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 1)), new AclLineMatch(NODE2, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 2)), new AclLineMatch(NODE2, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, new AclLineMatch(NODE2, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 0)), new AclLineMatch(NODE2, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(FalseExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 1)), new AclLineMatch(NODE2, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 2)), new AclLineMatch(NODE2, ACL2, 3))));
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) 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) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 4 with AclLineNoMatch

use of org.batfish.z3.state.AclLineNoMatch in project batfish by batfish.

the class DefaultTransitionGenerator method visitAclDeny.

@Override
public void visitAclDeny(AclDeny.State aclDeny) {
    // MatchDenyLine
    _input.getAclActions().forEach((node, nodeAcls) -> nodeAcls.forEach((acl, linesActions) -> {
        int lineNumber = 0;
        for (LineAction linesAction : linesActions) {
            if (linesAction == LineAction.REJECT) {
                _rules.add(new BasicRuleStatement(new AclLineMatch(node, acl, lineNumber), new AclDeny(node, acl)));
            }
            lineNumber++;
        }
    }));
    // MatchNoLines
    _input.getAclActions().entrySet().stream().flatMap(aclActionsEntryByNode -> {
        String hostname = aclActionsEntryByNode.getKey();
        return aclActionsEntryByNode.getValue().entrySet().stream().map(aclActionsEntryByAclName -> {
            String acl = aclActionsEntryByAclName.getKey();
            List<LineAction> lineActions = aclActionsEntryByAclName.getValue();
            AclDeny deny = new AclDeny(hostname, acl);
            if (lineActions.isEmpty()) {
                return new BasicRuleStatement(deny);
            } else {
                int lastLine = lineActions.size() - 1;
                return new BasicRuleStatement(new AclLineNoMatch(hostname, acl, lastLine), deny);
            }
        });
    }).forEach(_rules::add);
}
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) LineAction(org.batfish.datamodel.LineAction) AclLineMatch(org.batfish.z3.state.AclLineMatch) AclDeny(org.batfish.z3.state.AclDeny) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Aggregations

SynthesizerInput (org.batfish.z3.SynthesizerInput)4 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)4 RuleStatement (org.batfish.z3.expr.RuleStatement)4 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)4 AclLineNoMatch (org.batfish.z3.state.AclLineNoMatch)4 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)3 AclLineMatch (org.batfish.z3.state.AclLineMatch)3 NotExpr (org.batfish.z3.expr.NotExpr)2 AclDeny (org.batfish.z3.state.AclDeny)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IpWildcard (org.batfish.datamodel.IpWildcard)1 LineAction (org.batfish.datamodel.LineAction)1