use of org.batfish.datamodel.routing_policy.expr.CommunitySetExpr in project batfish by batfish.
the class Graph method findAllCommunities.
public Set<CommunityVar> findAllCommunities(String router) {
Set<CommunityVar> comms = new HashSet<>();
Configuration conf = getConfigurations().get(router);
for (RoutingPolicy pol : conf.getRoutingPolicies().values()) {
AstVisitor v = new AstVisitor();
v.visit(conf, pol.getStatements(), stmt -> {
if (stmt instanceof SetCommunity) {
SetCommunity sc = (SetCommunity) stmt;
comms.addAll(findAllCommunities(conf, sc.getExpr()));
}
if (stmt instanceof AddCommunity) {
AddCommunity ac = (AddCommunity) stmt;
comms.addAll(findAllCommunities(conf, ac.getExpr()));
}
if (stmt instanceof DeleteCommunity) {
DeleteCommunity dc = (DeleteCommunity) stmt;
comms.addAll(findAllCommunities(conf, dc.getExpr()));
}
if (stmt instanceof RetainCommunity) {
RetainCommunity rc = (RetainCommunity) stmt;
comms.addAll(findAllCommunities(conf, rc.getExpr()));
}
}, expr -> {
if (expr instanceof MatchCommunitySet) {
MatchCommunitySet m = (MatchCommunitySet) expr;
CommunitySetExpr ce = m.getExpr();
comms.addAll(findAllCommunities(conf, ce));
}
});
}
return comms;
}
Aggregations