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);
}
}
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();
}
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;
}
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");
}
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");
}
Aggregations