use of org.batfish.datamodel.routing_policy.expr.InlineCommunitySet 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");
}
use of org.batfish.datamodel.routing_policy.expr.InlineCommunitySet in project batfish by batfish.
the class PsThenCommunitySet 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 + "\"");
} else {
org.batfish.datamodel.CommunityList list = c.getCommunityLists().get(_name);
String regex = list.getLines().get(0).getRegex();
// assuming this is a valid community list for setting, the regex value
// just retrieved should just be an explicit community
long community = CommonUtil.communityStringToLong(regex);
statements.add(new SetCommunity(new InlineCommunitySet(Collections.singleton(community))));
}
}
Aggregations