Search in sources :

Example 1 with LitIntExpr

use of org.batfish.z3.expr.LitIntExpr 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 2 with LitIntExpr

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

the class SimplifierTest method testSimplifyEqStaticallyFalse.

/**
 * Test that an EQ node with LHS and RHS statically determinable to be unequal simplifies to
 * FALSE.
 */
@Test
public void testSimplifyEqStaticallyFalse() {
    IntExpr i1 = new LitIntExpr(Ip.ZERO);
    IntExpr i2 = new LitIntExpr(Ip.MAX);
    EqExpr eq = new EqExpr(i1, i2);
    assertThat(simplifyBooleanExpr(eq), equalTo(FalseExpr.INSTANCE));
}
Also used : EqExpr(org.batfish.z3.expr.EqExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 3 with LitIntExpr

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

the class Simplifier method visitEqExpr.

@Override
public BooleanExpr visitEqExpr(EqExpr eqExpr) {
    IntExpr lhs = eqExpr.getLhs();
    IntExpr rhs = eqExpr.getRhs();
    if (lhs.equals(rhs)) {
        return TrueExpr.INSTANCE;
    } else if (lhs instanceof LitIntExpr && rhs instanceof LitIntExpr) {
        return FalseExpr.INSTANCE;
    } else {
        return eqExpr;
    }
}
Also used : LitIntExpr(org.batfish.z3.expr.LitIntExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr)

Aggregations

LitIntExpr (org.batfish.z3.expr.LitIntExpr)3 VarIntExpr (org.batfish.z3.expr.VarIntExpr)3 EqExpr (org.batfish.z3.expr.EqExpr)2 IntExpr (org.batfish.z3.expr.IntExpr)2 ImmutableList (com.google.common.collect.ImmutableList)1 Ip (org.batfish.datamodel.Ip)1 AndExpr (org.batfish.z3.expr.AndExpr)1 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)1 BooleanExpr (org.batfish.z3.expr.BooleanExpr)1 NotExpr (org.batfish.z3.expr.NotExpr)1 QueryStatement (org.batfish.z3.expr.QueryStatement)1 Test (org.junit.Test)1