Search in sources :

Example 1 with AclLineMatch

use of org.batfish.z3.state.AclLineMatch 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 AclLineMatch

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

the class DefaultTransitionGeneratorTest method testVisitAclPermit.

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

Example 3 with AclLineMatch

use of org.batfish.z3.state.AclLineMatch 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 AclLineMatch

use of org.batfish.z3.state.AclLineMatch 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)

Example 5 with AclLineMatch

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

the class AclReachabilityQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ReachabilityProgram.Builder builder = ReachabilityProgram.builder().setInput(input);
    ImmutableList.Builder<QueryStatement> queries = ImmutableList.builder();
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    for (int line = 0; line < _numLines; line++) {
        NumberedQuery query = new NumberedQuery(line);
        rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(new AclLineMatch(_hostname, _aclName, line)), new NumberedQuery(line)));
        queries.add(new QueryStatement(query));
        _keys.add(new AclLine(_hostname, _aclName, line));
    }
    return builder.setInput(input).setQueries(queries.build()).setRules(rules.build()).build();
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) NumberedQuery(org.batfish.z3.state.NumberedQuery) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Aggregations

BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 RuleStatement (org.batfish.z3.expr.RuleStatement)5 AclLineMatch (org.batfish.z3.state.AclLineMatch)5 SynthesizerInput (org.batfish.z3.SynthesizerInput)4 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)4 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)3 AclLineNoMatch (org.batfish.z3.state.AclLineNoMatch)3 ImmutableList (com.google.common.collect.ImmutableList)2 AclDeny (org.batfish.z3.state.AclDeny)2 AclPermit (org.batfish.z3.state.AclPermit)2 NumberedQuery (org.batfish.z3.state.NumberedQuery)2 Test (org.junit.Test)2 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