Search in sources :

Example 1 with InlineCommunitySet

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

the class RouteMapSetCommunityListLine method applyTo.

@Override
public void applyTo(List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) {
    List<Long> communities = new ArrayList<>();
    for (String communityListName : _communityLists) {
        CommunityList communityList = c.getCommunityLists().get(communityListName);
        if (communityList != null) {
            StandardCommunityList scl = cc.getStandardCommunityLists().get(communityListName);
            if (scl != null) {
                for (StandardCommunityListLine line : scl.getLines()) {
                    if (line.getAction() == LineAction.ACCEPT) {
                        communities.addAll(line.getCommunities());
                    } else {
                        w.redFlag("Expected only permit lines in standard community-list referred to by route-map " + "set community community-list line: \"" + communityListName + "\"");
                    }
                }
            } else {
                w.redFlag("Expected standard community list in route-map set community community-list line " + "but got expanded instead: \"" + communityListName + "\"");
            }
        } else {
            cc.undefined(CiscoStructureType.COMMUNITY_LIST, communityListName, CiscoStructureUsage.ROUTE_MAP_SET_COMMUNITY, _statementLine);
        }
    }
    statements.add(new SetCommunity(new InlineCommunitySet(new TreeSet<>(communities))));
}
Also used : SetCommunity(org.batfish.datamodel.routing_policy.statement.SetCommunity) ArrayList(java.util.ArrayList) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 2 with InlineCommunitySet

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

the class Graph method findAllCommunities.

/*
   * Final all uniquely mentioned community values for a particular
   * router configuration and community set expression.
   */
public Set<CommunityVar> findAllCommunities(Configuration conf, CommunitySetExpr ce) {
    Set<CommunityVar> comms = new HashSet<>();
    if (ce instanceof InlineCommunitySet) {
        InlineCommunitySet c = (InlineCommunitySet) ce;
        for (CommunitySetElem cse : c.getCommunities()) {
            if (cse.getPrefix() instanceof LiteralCommunitySetElemHalf && cse.getSuffix() instanceof LiteralCommunitySetElemHalf) {
                LiteralCommunitySetElemHalf x = (LiteralCommunitySetElemHalf) cse.getPrefix();
                LiteralCommunitySetElemHalf y = (LiteralCommunitySetElemHalf) cse.getSuffix();
                int prefixInt = x.getValue();
                int suffixInt = y.getValue();
                String val = prefixInt + ":" + suffixInt;
                Long l = (((long) prefixInt) << 16) | (suffixInt);
                CommunityVar var = new CommunityVar(CommunityVar.Type.EXACT, val, l);
                comms.add(var);
            } else {
                throw new BatfishException("TODO: community non literal: " + cse);
            }
        }
    }
    if (ce instanceof NamedCommunitySet) {
        NamedCommunitySet c = (NamedCommunitySet) ce;
        String cname = c.getName();
        CommunityList cl = conf.getCommunityLists().get(cname);
        if (cl != null) {
            for (CommunityListLine line : cl.getLines()) {
                CommunityVar var = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
                comms.add(var);
            }
        }
    }
    return comms;
}
Also used : BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) CommunityListLine(org.batfish.datamodel.CommunityListLine) CommunityList(org.batfish.datamodel.CommunityList) LiteralCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf) CommunitySetElem(org.batfish.datamodel.routing_policy.expr.CommunitySetElem) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet) HashSet(java.util.HashSet)

Example 3 with InlineCommunitySet

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

the class PsThenCommunityAdd 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 + "\"");
        return;
    } else {
        SortedSet<Long> communities = new TreeSet<>();
        for (CommunityListLine clLine : namedList.getLines()) {
            // assuming that regex here is actually a literal community
            String communityStr = clLine.getRegex();
            long communityLong = CommonUtil.communityStringToLong(communityStr);
            communities.add(communityLong);
        }
        statements.add(new AddCommunity(new InlineCommunitySet(communities)));
    }
}
Also used : AddCommunity(org.batfish.datamodel.routing_policy.statement.AddCommunity) TreeSet(java.util.TreeSet) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 4 with InlineCommunitySet

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

the class RouteMapSetAdditiveCommunityListLine method applyTo.

@Override
public void applyTo(List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) {
    SortedSet<Long> communities = new TreeSet<>();
    for (String communityListName : _communityLists) {
        CommunityList communityList = c.getCommunityLists().get(communityListName);
        if (communityList != null) {
            StandardCommunityList scl = cc.getStandardCommunityLists().get(communityListName);
            if (scl != null) {
                for (StandardCommunityListLine line : scl.getLines()) {
                    if (line.getAction() == LineAction.ACCEPT) {
                        communities.addAll(line.getCommunities());
                    } else {
                        w.redFlag("Expected only permit lines in standard community-list referred to by route-map " + "set community community-list line: \"" + communityListName + "\"");
                    }
                }
            } else {
                w.redFlag("Expected standard community list in route-map set community community-list line " + "but got expanded instead: \"" + communityListName + "\"");
            }
        } else {
            cc.undefined(CiscoStructureType.COMMUNITY_LIST, communityListName, CiscoStructureUsage.ROUTE_MAP_ADD_COMMUNITY, _statementLine);
        }
    }
    statements.add(new AddCommunity(new InlineCommunitySet(communities)));
}
Also used : AddCommunity(org.batfish.datamodel.routing_policy.statement.AddCommunity) TreeSet(java.util.TreeSet) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 5 with InlineCommunitySet

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

the class TransferSSA method matchCommunitySet.

/*
   * Converts a community set to a boolean expression
   */
private BoolExpr matchCommunitySet(Configuration conf, CommunitySetExpr e, SymbolicRoute other) {
    if (e instanceof InlineCommunitySet) {
        Set<CommunityVar> comms = _enc.getGraph().findAllCommunities(conf, e);
        BoolExpr acc = _enc.mkTrue();
        for (CommunityVar comm : comms) {
            BoolExpr c = other.getCommunities().get(comm);
            if (c == null) {
                throw new BatfishException("matchCommunitySet: should not be null");
            }
            acc = _enc.mkAnd(acc, c);
        }
        return acc;
    }
    if (e instanceof NamedCommunitySet) {
        NamedCommunitySet x = (NamedCommunitySet) e;
        CommunityList cl = conf.getCommunityLists().get(x.getName());
        return matchCommunityList(cl, other);
    }
    throw new BatfishException("TODO: match community set");
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) CommunityList(org.batfish.datamodel.CommunityList) 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