use of org.batfish.z3.expr.TransformationRuleStatement 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.TransformationRuleStatement 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.TransformationRuleStatement in project batfish by batfish.
the class BoolExprTransformer method visitTransformationRuleStatement.
@Override
public BoolExpr visitTransformationRuleStatement(TransformationRuleStatement transformationRuleStatement) {
Context ctx = _nodContext.getContext();
ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(transformationRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
transformationRuleStatement.getPreconditionPreTransformationStates().stream().map(preconditionPreTransformationState -> toBoolExpr(preconditionPreTransformationState, _input, _nodContext)).forEach(preconditions::add);
transformationRuleStatement.getPreconditionPostTransformationStates().stream().map(preconditionPostTransformationState -> (BoolExpr) toBoolExpr(preconditionPostTransformationState, _input, _nodContext).substitute(_from, _to)).forEach(preconditions::add);
return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), (BoolExpr) toBoolExpr(transformationRuleStatement.getPostconditionTransformationState(), _input, _nodContext).substitute(_from, _to));
}
Aggregations