Search in sources :

Example 1 with NamedCommunitySet

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

the class RouteMapSetDeleteCommunityLine method applyTo.

@Override
public void applyTo(List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) {
    CommunityList list = c.getCommunityLists().get(_listName);
    if (list != null) {
        String msg = "match community line";
        StandardCommunityList standardCommunityList = cc.getStandardCommunityLists().get(_listName);
        if (standardCommunityList != null) {
            standardCommunityList.getReferers().put(this, msg);
        }
        ExpandedCommunityList expandedCommunityList = cc.getExpandedCommunityLists().get(_listName);
        if (expandedCommunityList != null) {
            expandedCommunityList.getReferers().put(this, msg);
        }
        statements.add(new DeleteCommunity(new NamedCommunitySet(_listName)));
    } else {
        cc.undefined(CiscoStructureType.COMMUNITY_LIST, _listName, CiscoStructureUsage.ROUTE_MAP_DELETE_COMMUNITY, _statementLine);
    }
}
Also used : NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) DeleteCommunity(org.batfish.datamodel.routing_policy.statement.DeleteCommunity) CommunityList(org.batfish.datamodel.CommunityList)

Example 2 with NamedCommunitySet

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

the class RouteMapMatchCommunityListLine method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) {
    Disjunction d = new Disjunction();
    List<BooleanExpr> disjuncts = d.getDisjuncts();
    for (String listName : _listNames) {
        CommunityList list = c.getCommunityLists().get(listName);
        if (list != null) {
            String msg = "match community line";
            StandardCommunityList standardCommunityList = cc.getStandardCommunityLists().get(listName);
            if (standardCommunityList != null) {
                standardCommunityList.getReferers().put(this, msg);
            }
            ExpandedCommunityList expandedCommunityList = cc.getExpandedCommunityLists().get(listName);
            if (expandedCommunityList != null) {
                expandedCommunityList.getReferers().put(this, msg);
            }
            disjuncts.add(new MatchCommunitySet(new NamedCommunitySet(listName)));
        } else {
            cc.undefined(CiscoStructureType.COMMUNITY_LIST, listName, CiscoStructureUsage.ROUTE_MAP_MATCH_COMMUNITY_LIST, _statementLine);
        }
    }
    return d.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) MatchCommunitySet(org.batfish.datamodel.routing_policy.expr.MatchCommunitySet) CommunityList(org.batfish.datamodel.CommunityList) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 3 with NamedCommunitySet

use of org.batfish.datamodel.routing_policy.expr.NamedCommunitySet 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 4 with NamedCommunitySet

use of org.batfish.datamodel.routing_policy.expr.NamedCommunitySet 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)

Example 5 with NamedCommunitySet

use of org.batfish.datamodel.routing_policy.expr.NamedCommunitySet 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)

Aggregations

NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)6 CommunityList (org.batfish.datamodel.CommunityList)5 BatfishException (org.batfish.common.BatfishException)3 InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)3 DeleteCommunity (org.batfish.datamodel.routing_policy.statement.DeleteCommunity)2 CommunityVar (org.batfish.symbolic.CommunityVar)2 BoolExpr (com.microsoft.z3.BoolExpr)1 HashSet (java.util.HashSet)1 BDD (net.sf.javabdd.BDD)1 VendorConversionException (org.batfish.common.VendorConversionException)1 CommunityListLine (org.batfish.datamodel.CommunityListLine)1 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)1 CommunitySetElem (org.batfish.datamodel.routing_policy.expr.CommunitySetElem)1 Disjunction (org.batfish.datamodel.routing_policy.expr.Disjunction)1 LiteralCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf)1 MatchCommunitySet (org.batfish.datamodel.routing_policy.expr.MatchCommunitySet)1