Search in sources :

Example 1 with StaticBooleanExpr

use of org.batfish.datamodel.routing_policy.expr.BooleanExprs.StaticBooleanExpr in project batfish by batfish.

the class BatfishCompressor method applyFilters.

/**
 * Update a list of RoutingPolicy statements by filtering traffic according to the input filter.
 *
 * @param statements The list of RoutingPolicy statements.
 * @param filter The filter used to restrict traffic
 * @return A new list of RoutingPolicy statements
 */
// PrefixTrie: capture the prefixes you are installing to allow traffic through. Restrict
// to those prefixes
// Boolean: are the prefixes for the default equivalence class?
private List<Statement> applyFilters(List<Statement> statements, @Nullable EquivalenceClassFilter filter) {
    If i = new If();
    List<Statement> newStatements = new ArrayList<>();
    List<Statement> falseStatements = new ArrayList<>();
    Statement reject = new StaticStatement(Statements.ExitReject);
    falseStatements.add(reject);
    if (filter == null) {
        StaticBooleanExpr sbe = new StaticBooleanExpr(BooleanExprs.False);
        i.setGuard(sbe);
    } else {
        AbstractionPrefixSet eps = new AbstractionPrefixSet(filter._prefixTrie);
        MatchPrefixSet match = new MatchPrefixSet(new DestinationNetwork(), eps);
        if (filter._isForDefaultSlice) {
            // Let traffic through if it passes the filter or was advertised from outside the network.
            Disjunction pfxOrExternal = new Disjunction();
            pfxOrExternal.setDisjuncts(ImmutableList.of(match, matchExternalTraffic()));
            i.setGuard(pfxOrExternal);
        } else {
            // Not default equivalence class, so just let traffic through if dest matches the filter
            i.setGuard(match);
        }
    }
    i.setFalseStatements(falseStatements);
    i.setTrueStatements(statements);
    newStatements.add(i);
    return newStatements;
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) AbstractionPrefixSet(org.batfish.datamodel.routing_policy.expr.AbstractionPrefixSet) StaticStatement(org.batfish.datamodel.routing_policy.statement.Statements.StaticStatement) Statement(org.batfish.datamodel.routing_policy.statement.Statement) StaticStatement(org.batfish.datamodel.routing_policy.statement.Statements.StaticStatement) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) ArrayList(java.util.ArrayList) If(org.batfish.datamodel.routing_policy.statement.If) StaticBooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExprs.StaticBooleanExpr)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractionPrefixSet (org.batfish.datamodel.routing_policy.expr.AbstractionPrefixSet)1 StaticBooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExprs.StaticBooleanExpr)1 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)1 Disjunction (org.batfish.datamodel.routing_policy.expr.Disjunction)1 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)1 If (org.batfish.datamodel.routing_policy.statement.If)1 Statement (org.batfish.datamodel.routing_policy.statement.Statement)1 StaticStatement (org.batfish.datamodel.routing_policy.statement.Statements.StaticStatement)1