use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyOrFalse.
/**
* Test that any FALSE children of an OR node are removed.
*/
@Test
public void testSimplifyOrFalse() {
BooleanExpr p1 = newAtom();
BooleanExpr p2 = newAtom();
OrExpr and = new OrExpr(of(FalseExpr.INSTANCE, p1, FalseExpr.INSTANCE, p2));
assertThat(simplifyBooleanExpr(and), equalTo(new OrExpr(of(p1, p2))));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplfyNotDoubleNegation.
/**
* Test that NOT NOT P == P.
*/
@Test
public void testSimplfyNotDoubleNegation() {
BooleanExpr p1 = newAtom();
assertThat(simplifyBooleanExpr(new NotExpr(new NotExpr(p1))), equalTo(p1));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyWrappers.
/**
* Test that wrapper expressions are changed by simplification
*/
@Test
public void testSimplifyWrappers() {
BooleanExpr headerSpaceMatchExpr = new HeaderSpaceMatchExpr(IpAccessListLine.builder().build());
BooleanExpr prefixMatchExpr = new PrefixMatchExpr(BasicHeaderField.DST_IP, Prefix.ZERO);
BooleanExpr rangeMatchExpr = RangeMatchExpr.greaterThanOrEqualTo(BasicHeaderField.DST_IP, 123456L, 10);
assertThat(simplifyBooleanExpr(CurrentIsOriginalExpr.INSTANCE), not(equalTo(CurrentIsOriginalExpr.INSTANCE)));
assertThat(simplifyBooleanExpr(headerSpaceMatchExpr), not(equalTo(headerSpaceMatchExpr)));
assertThat(simplifyBooleanExpr(prefixMatchExpr), not(equalTo(prefixMatchExpr)));
assertThat(simplifyBooleanExpr(rangeMatchExpr), not(equalTo(rangeMatchExpr)));
assertThat(simplifyBooleanExpr(SaneExpr.INSTANCE), not(equalTo(SaneExpr.INSTANCE)));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateNoMatchSourceNatRules.
private void visitPreOutEdgePostNat_generateNoMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().getOrDefault(node1, ImmutableMap.of()).getOrDefault(iface1, ImmutableList.of());
ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
sourceNats.stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
_rules.add(new TransformationRuleStatement(new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent())), preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class Simplifier method visitAndExpr.
@Override
public BooleanExpr visitAndExpr(AndExpr andExpr) {
boolean changed = false;
List<BooleanExpr> oldConjuncts = andExpr.getConjuncts();
ImmutableList.Builder<BooleanExpr> newConjunctsBuilder = ImmutableList.builder();
// first check for nested ANDs
if (oldConjuncts.stream().anyMatch(Predicates.instanceOf(AndExpr.class))) {
return simplifyBooleanExpr(new AndExpr(oldConjuncts.stream().flatMap(conjunct -> conjunct instanceof AndExpr ? ((AndExpr) conjunct).getConjuncts().stream() : Stream.of(conjunct)).collect(ImmutableList.toImmutableList())));
}
// no nested ANDs, so just simplify all conjuncts
for (BooleanExpr conjunct : oldConjuncts) {
BooleanExpr simplifiedConjunct = simplifyBooleanExpr(conjunct);
if (conjunct != simplifiedConjunct) {
changed = true;
}
if (simplifiedConjunct == FalseExpr.INSTANCE) {
return FalseExpr.INSTANCE;
} else if (simplifiedConjunct != TrueExpr.INSTANCE) {
newConjunctsBuilder.add(simplifiedConjunct);
} else {
changed = true;
}
}
List<BooleanExpr> newConjuncts = newConjunctsBuilder.build();
if (newConjuncts.size() == 0) {
return TrueExpr.INSTANCE;
} else if (newConjuncts.size() == 1) {
return newConjuncts.get(0);
} else if (!changed) {
return andExpr;
} else {
return new AndExpr(newConjuncts);
}
}
Aggregations