use of org.batfish.grammar.flatjuniper.FlatJuniperParser.Policy_expressionContext 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");
}
}
use of org.batfish.grammar.flatjuniper.FlatJuniperParser.Policy_expressionContext in project batfish by batfish.
the class ConfigurationBuilder method exitB_export.
@Override
public void exitB_export(B_exportContext ctx) {
Policy_expressionContext expr = ctx.expr;
String name;
int line;
if (expr.variable() != null) {
name = expr.variable().getText();
line = expr.variable().getStart().getLine();
} else {
name = toComplexPolicyStatement(expr);
line = expr.getStart().getLine();
}
_currentBgpGroup.getExportPolicies().put(name, line);
}
use of org.batfish.grammar.flatjuniper.FlatJuniperParser.Policy_expressionContext in project batfish by batfish.
the class ConfigurationBuilder method exitB_import.
@Override
public void exitB_import(B_importContext ctx) {
Policy_expressionContext expr = ctx.expr;
String name;
int line;
if (expr.variable() != null) {
name = expr.variable().getText();
line = expr.variable().getStart().getLine();
} else {
name = toComplexPolicyStatement(expr);
line = expr.getStart().getLine();
}
_currentBgpGroup.getImportPolicies().put(name, line);
}
Aggregations