Search in sources :

Example 1 with AndExpr

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

the class MultipathInconsistencyQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    addOriginateRules(rules);
    ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
    rules.add(new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(Accept.INSTANCE, Drop.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Accept.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Drop.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 2 with AndExpr

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

the class BlacklistDstIpQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<BooleanExpr> queryConditionsBuilder = ImmutableList.builder();
    queryConditionsBuilder.add(SaneExpr.INSTANCE);
    for (Ip blacklistIp : _blacklistIps) {
        BooleanExpr blacklistIpCondition = new NotExpr(new EqExpr(new VarIntExpr(BasicHeaderField.DST_IP), new LitIntExpr(blacklistIp)));
        queryConditionsBuilder.add(blacklistIpCondition);
    }
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(ImmutableList.of(new BasicRuleStatement(new AndExpr(queryConditionsBuilder.build()), ImmutableSet.of(), Query.INSTANCE))).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) ImmutableList(com.google.common.collect.ImmutableList) EqExpr(org.batfish.z3.expr.EqExpr) Ip(org.batfish.datamodel.Ip) LitIntExpr(org.batfish.z3.expr.LitIntExpr) NotExpr(org.batfish.z3.expr.NotExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 3 with AndExpr

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

the class EarliestMoreGeneralReachableLineQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    int unreachableLineIndex = _unreachableLine.getLine();
    IpAccessListLine unreachableLine = _list.getLines().get(unreachableLineIndex);
    BooleanExpr matchUnreachableLineHeaderSpace = new HeaderSpaceMatchExpr(unreachableLine);
    ImmutableList.Builder<QueryStatement> queries = ImmutableList.builder();
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    for (AclLine earlierReachableLine : _earlierReachableLines) {
        int earlierLineIndex = earlierReachableLine.getLine();
        IpAccessListLine earlierLine = _list.getLines().get(earlierLineIndex);
        BooleanExpr matchEarlierLineHeaderSpace = new HeaderSpaceMatchExpr(earlierLine);
        NumberedQuery queryRel = new NumberedQuery(earlierLineIndex);
        rules.add(new BasicRuleStatement(new AndExpr(ImmutableList.of(new NotExpr(matchEarlierLineHeaderSpace), matchUnreachableLineHeaderSpace, SaneExpr.INSTANCE)), queryRel));
        QueryStatement query = new QueryStatement(queryRel);
        queries.add(query);
        _resultsByQueryIndex.add(earlierLineIndex);
    }
    return ReachabilityProgram.builder().setInput(input).setQueries(queries.build()).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) NumberedQuery(org.batfish.z3.state.NumberedQuery) ImmutableList(com.google.common.collect.ImmutableList) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 4 with AndExpr

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

the class BoolExprTransformerTest method testVisitAndExpr.

@Test
public void testVisitAndExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BooleanExpr p2Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    BoolExpr p2Z3 = toBoolExpr(p2Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new AndExpr(of(p1Batfish, p2Batfish)), _input, _nodContext), equalTo(_ctx.mkAnd(p1Z3, p2Z3)));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 5 with AndExpr

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

the class SimplifierTest method testSimplifyAndExprPreserveUnalteredInstance.

/**
 * Test that an unsimplifiable expression is unchanged by simplification.
 */
@Test
public void testSimplifyAndExprPreserveUnalteredInstance() {
    BooleanExpr p1 = newAtom();
    BooleanExpr p2 = newAtom();
    AndExpr and = new AndExpr(of(p1, p2));
    assertThat(simplifyBooleanExpr(and), sameInstance(and));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Aggregations

AndExpr (org.batfish.z3.expr.AndExpr)15 BooleanExpr (org.batfish.z3.expr.BooleanExpr)13 Test (org.junit.Test)8 NotExpr (org.batfish.z3.expr.NotExpr)6 ImmutableList (com.google.common.collect.ImmutableList)5 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 QueryStatement (org.batfish.z3.expr.QueryStatement)5 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)5 EqExpr (org.batfish.z3.expr.EqExpr)3 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)3 LitIntExpr (org.batfish.z3.expr.LitIntExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 SaneExpr (org.batfish.z3.expr.SaneExpr)3 StateExpr (org.batfish.z3.expr.StateExpr)3 VarIntExpr (org.batfish.z3.expr.VarIntExpr)3 List (java.util.List)2 BitVecExpr (org.batfish.z3.expr.BitVecExpr)2 CurrentIsOriginalExpr (org.batfish.z3.expr.CurrentIsOriginalExpr)2 Expr (org.batfish.z3.expr.Expr)2 ExtractExpr (org.batfish.z3.expr.ExtractExpr)2