Search in sources :

Example 1 with CommunitySetExpr

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;
}
Also used : AddCommunity(org.batfish.datamodel.routing_policy.statement.AddCommunity) Configuration(org.batfish.datamodel.Configuration) SetCommunity(org.batfish.datamodel.routing_policy.statement.SetCommunity) DeleteCommunity(org.batfish.datamodel.routing_policy.statement.DeleteCommunity) MatchCommunitySet(org.batfish.datamodel.routing_policy.expr.MatchCommunitySet) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) RetainCommunity(org.batfish.datamodel.routing_policy.statement.RetainCommunity) CommunitySetExpr(org.batfish.datamodel.routing_policy.expr.CommunitySetExpr) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Configuration (org.batfish.datamodel.Configuration)1 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)1 CommunitySetExpr (org.batfish.datamodel.routing_policy.expr.CommunitySetExpr)1 MatchCommunitySet (org.batfish.datamodel.routing_policy.expr.MatchCommunitySet)1 AddCommunity (org.batfish.datamodel.routing_policy.statement.AddCommunity)1 DeleteCommunity (org.batfish.datamodel.routing_policy.statement.DeleteCommunity)1 RetainCommunity (org.batfish.datamodel.routing_policy.statement.RetainCommunity)1 SetCommunity (org.batfish.datamodel.routing_policy.statement.SetCommunity)1