Search in sources :

Example 1 with QueryStatement

use of org.batfish.z3.expr.QueryStatement 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 QueryStatement

use of org.batfish.z3.expr.QueryStatement 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 QueryStatement

use of org.batfish.z3.expr.QueryStatement 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 QueryStatement

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

the class ReachabilityProgramOptimizerTest method freshQueryStateExpr.

private StateExpr freshQueryStateExpr() {
    StateExpr stateExpr = freshStateExpr();
    _queries.add(new QueryStatement(stateExpr));
    return stateExpr;
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)

Example 5 with QueryStatement

use of org.batfish.z3.expr.QueryStatement 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)

Aggregations

QueryStatement (org.batfish.z3.expr.QueryStatement)6 ImmutableList (com.google.common.collect.ImmutableList)5 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 AndExpr (org.batfish.z3.expr.AndExpr)4 BooleanExpr (org.batfish.z3.expr.BooleanExpr)4 RuleStatement (org.batfish.z3.expr.RuleStatement)4 NotExpr (org.batfish.z3.expr.NotExpr)2 StateExpr (org.batfish.z3.expr.StateExpr)2 NumberedQuery (org.batfish.z3.state.NumberedQuery)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 BatfishException (org.batfish.common.BatfishException)1 ForwardingAction (org.batfish.datamodel.ForwardingAction)1 HeaderSpace (org.batfish.datamodel.HeaderSpace)1 Ip (org.batfish.datamodel.Ip)1 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)1 EqExpr (org.batfish.z3.expr.EqExpr)1