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