use of org.batfish.representation.juniper.PsFromPolicyStatementConjunction in project batfish by batfish.
the class ConfigurationBuilder method toComplexPolicyStatement.
private String toComplexPolicyStatement(Policy_expressionContext expr) {
if (expr.pe_nested() != null) {
return toComplexPolicyStatement(expr.pe_nested().policy_expression());
} else if (expr.variable() != null) {
String name = expr.variable().getText();
return name;
} else if (expr.pe_conjunction() != null) {
Set<String> conjuncts = new LinkedHashSet<>();
for (Policy_expressionContext conjunctCtx : expr.pe_conjunction().policy_expression()) {
String conjunctName = toComplexPolicyStatement(conjunctCtx);
conjuncts.add(conjunctName);
}
String conjunctionPolicyName = "~CONJUNCTION_POLICY_" + _conjunctionPolicyIndex + "~";
_conjunctionPolicyIndex++;
PolicyStatement conjunctionPolicy = new PolicyStatement(conjunctionPolicyName, -1);
PsTerm conjunctionPolicyTerm = conjunctionPolicy.getDefaultTerm();
PsFromPolicyStatementConjunction from = new PsFromPolicyStatementConjunction(conjuncts);
conjunctionPolicyTerm.getFroms().add(from);
conjunctionPolicyTerm.getThens().add(PsThenAccept.INSTANCE);
_configuration.getPolicyStatements().put(conjunctionPolicyName, conjunctionPolicy);
return conjunctionPolicyName;
} else if (expr.pe_disjunction() != null) {
Set<String> disjuncts = new LinkedHashSet<>();
for (Policy_expressionContext disjunctCtx : expr.pe_disjunction().policy_expression()) {
String disjunctName = toComplexPolicyStatement(disjunctCtx);
disjuncts.add(disjunctName);
}
String disjunctionPolicyName = "~DISJUNCTION_POLICY_" + _disjunctionPolicyIndex + "~";
_disjunctionPolicyIndex++;
PolicyStatement disjunctionPolicy = new PolicyStatement(disjunctionPolicyName, -1);
PsTerm disjunctionPolicyTerm = disjunctionPolicy.getDefaultTerm();
for (String disjunct : disjuncts) {
PsFromPolicyStatement from = new PsFromPolicyStatement(disjunct);
disjunctionPolicyTerm.getFroms().add(from);
}
disjunctionPolicyTerm.getThens().add(PsThenAccept.INSTANCE);
_configuration.getPolicyStatements().put(disjunctionPolicyName, disjunctionPolicy);
return disjunctionPolicyName;
} else {
throw new BatfishException("Invalid policy expression");
}
}
Aggregations