use of org.batfish.datamodel.CommunityList 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.CommunityList in project batfish by batfish.
the class CiscoConfiguration method toCommunityList.
private CommunityList toCommunityList(ExpandedCommunityList ecList) {
List<CommunityListLine> cllList = new ArrayList<>();
for (ExpandedCommunityListLine ecll : ecList.getLines()) {
cllList.add(toCommunityListLine(ecll));
}
CommunityList cList = new CommunityList(ecList.getName(), cllList);
return cList;
}
use of org.batfish.datamodel.CommunityList 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.CommunityList 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.CommunityList in project batfish by batfish.
the class Graph method findNamedCommunities.
/*
* Map named community sets that contain a single match
* back to the community/regex value. This makes it
* easier to provide intuitive counter examples.
*/
public Map<String, String> findNamedCommunities() {
Map<String, String> comms = new HashMap<>();
for (Configuration conf : getConfigurations().values()) {
for (Entry<String, CommunityList> entry : conf.getCommunityLists().entrySet()) {
String name = entry.getKey();
CommunityList cl = entry.getValue();
if (cl != null && cl.getLines().size() == 1) {
CommunityListLine line = cl.getLines().get(0);
comms.put(line.getRegex(), name);
}
}
}
return comms;
}
Aggregations