use of org.batfish.z3.expr.BooleanExpr 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;
}
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class Simplifier method visitTransformationRuleStatement.
@Override
public Statement visitTransformationRuleStatement(TransformationRuleStatement transformationRuleStatement) {
/**
* TODO: something smarter
*/
BooleanExpr originalPreconditionStateIndependentConstraints = transformationRuleStatement.getPreconditionStateIndependentConstraints();
BooleanExpr simplifiedPreconditionStateIndependentConstraints = simplifyBooleanExpr(originalPreconditionStateIndependentConstraints);
if (originalPreconditionStateIndependentConstraints != simplifiedPreconditionStateIndependentConstraints) {
return simplifyStatement(new TransformationRuleStatement(simplifiedPreconditionStateIndependentConstraints, transformationRuleStatement.getPreconditionPreTransformationStates(), transformationRuleStatement.getPreconditionPostTransformationStates(), transformationRuleStatement.getPostconditionTransformationState()));
} else if (simplifiedPreconditionStateIndependentConstraints == FalseExpr.INSTANCE) {
return VACUOUS_RULE;
} else {
return transformationRuleStatement;
}
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateMatchSourceNatRules.
private void visitPreOutEdgePostNat_generateMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().get(node1).get(iface1);
for (int natNumber = 0; natNumber < sourceNats.size(); natNumber++) {
ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
// does not match any previous source NAT.
sourceNats.subList(0, natNumber).stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
// does match the current source NAT.
preStates.add(sourceNats.get(natNumber).getKey());
BooleanExpr transformationExpr = sourceNats.get(natNumber).getValue();
_rules.add(new TransformationRuleStatement(transformationExpr, preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
}
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class StandardReachabilityQuerySynthesizer method getReachabilityProgram.
@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
List<StateExpr> finalActions = computeFinalActions();
ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
finalActions.stream().map(finalAction -> new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(finalAction), Query.INSTANCE)).forEach(rules::add);
addOriginateRules(rules);
return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Aggregations