Search in sources :

Example 6 with InlineCommunitySet

use of org.batfish.datamodel.routing_policy.expr.InlineCommunitySet in project batfish by batfish.

the class TransferBDD method matchCommunitySet.

/*
   * Converts a community set to a boolean expression
   */
private BDD matchCommunitySet(TransferParam<BDDRoute> p, Configuration conf, CommunitySetExpr e, BDDRoute other) {
    if (e instanceof InlineCommunitySet) {
        Set<CommunityVar> comms = _graph.findAllCommunities(conf, e);
        BDD acc = factory.one();
        for (CommunityVar comm : comms) {
            p.debug("Inline Community Set: " + comm);
            BDD c = other.getCommunities().get(comm);
            if (c == null) {
                throw new BatfishException("matchCommunitySet: should not be null");
            }
            acc = acc.and(c);
        }
        return acc;
    }
    if (e instanceof NamedCommunitySet) {
        p.debug("Named");
        NamedCommunitySet x = (NamedCommunitySet) e;
        CommunityList cl = conf.getCommunityLists().get(x.getName());
        p.debug("Named Community Set: " + cl.getName());
        return matchCommunityList(p, cl, other);
    }
    throw new BatfishException("TODO: match community set");
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) BDD(net.sf.javabdd.BDD) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 7 with InlineCommunitySet

use of org.batfish.datamodel.routing_policy.expr.InlineCommunitySet in project batfish by batfish.

the class PsThenCommunitySet method applyTo.

@Override
public void applyTo(List<Statement> statements, JuniperConfiguration juniperVendorConfiguration, Configuration c, Warnings warnings) {
    CommunityList namedList = _configuration.getCommunityLists().get(_name);
    if (namedList == null) {
        warnings.redFlag("Reference to undefined community: \"" + _name + "\"");
    } else {
        org.batfish.datamodel.CommunityList list = c.getCommunityLists().get(_name);
        String regex = list.getLines().get(0).getRegex();
        // assuming this is a valid community list for setting, the regex value
        // just retrieved should just be an explicit community
        long community = CommonUtil.communityStringToLong(regex);
        statements.add(new SetCommunity(new InlineCommunitySet(Collections.singleton(community))));
    }
}
Also used : SetCommunity(org.batfish.datamodel.routing_policy.statement.SetCommunity) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Aggregations

InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)7 CommunityList (org.batfish.datamodel.CommunityList)5 BatfishException (org.batfish.common.BatfishException)3 NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)3 TreeSet (java.util.TreeSet)2 AddCommunity (org.batfish.datamodel.routing_policy.statement.AddCommunity)2 SetCommunity (org.batfish.datamodel.routing_policy.statement.SetCommunity)2 CommunityVar (org.batfish.symbolic.CommunityVar)2 BoolExpr (com.microsoft.z3.BoolExpr)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BDD (net.sf.javabdd.BDD)1 CommunityListLine (org.batfish.datamodel.CommunityListLine)1 CommunitySetElem (org.batfish.datamodel.routing_policy.expr.CommunitySetElem)1 LiteralCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf)1