use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.
the class Graph method initNamedCommunities.
/*
* Map named community sets that contain a single match
* back to the community/regex value. This makes it
* easier to provide intuitive counter examples.
*/
private void initNamedCommunities() {
_namedCommunities = 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);
_namedCommunities.put(line.getRegex(), name);
}
}
}
}
use of org.batfish.datamodel.CommunityListLine 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.CommunityListLine in project batfish by batfish.
the class TransferBDD method matchCommunityList.
/*
* Converts a community list to a boolean expression.
*/
private BDD matchCommunityList(TransferParam<BDDRoute> p, CommunityList cl, BDDRoute other) {
List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
Collections.reverse(lines);
BDD acc = factory.zero();
for (CommunityListLine line : lines) {
boolean action = (line.getAction() == LineAction.ACCEPT);
CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
p.debug("Match Line: " + cvar);
p.debug("Action: " + line.getAction());
// Skip this match if it is irrelevant
if (_policyQuotient.getCommsMatchedButNotAssigned().contains(cvar)) {
continue;
}
List<CommunityVar> deps = _commDeps.get(cvar);
for (CommunityVar dep : deps) {
p.debug("Test for: " + dep);
BDD c = other.getCommunities().get(dep);
acc = ite(c, mkBDD(action), acc);
}
}
return acc;
}
use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.
the class TransferSSA method matchCommunityList.
/*
* Converts a community list to a boolean expression.
*/
private BoolExpr matchCommunityList(CommunityList cl, SymbolicRoute other) {
List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
Collections.reverse(lines);
BoolExpr acc = _enc.mkFalse();
for (CommunityListLine line : lines) {
boolean action = (line.getAction() == LineAction.ACCEPT);
CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
BoolExpr c = other.getCommunities().get(cvar);
acc = _enc.mkIf(c, _enc.mkBool(action), acc);
}
return acc;
}
use of org.batfish.datamodel.CommunityListLine 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;
}
Aggregations