use of org.batfish.datamodel.routing_policy.expr.AbstractionPrefixSet 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;
}
Aggregations