use of org.batfish.datamodel.RouteFilterLine in project batfish by batfish.
the class PsFromPrefixListFilterLonger method toBooleanExpr.
@Override
public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) {
PrefixList pl = jc.getPrefixLists().get(_prefixList);
if (pl != null) {
pl.getReferers().put(this, "from prefix-list-filter longer");
if (pl.getIpv6()) {
return BooleanExprs.False.toStaticBooleanExpr();
}
RouteFilterList rf = c.getRouteFilterLists().get(_prefixList);
String longerListName = "~" + _prefixList + "~LONGER~";
RouteFilterList longerList = c.getRouteFilterLists().get(longerListName);
if (longerList == null) {
longerList = new RouteFilterList(longerListName);
for (RouteFilterLine line : rf.getLines()) {
Prefix prefix = line.getPrefix();
LineAction action = line.getAction();
SubRange longerLineRange = new SubRange(line.getLengthRange().getStart() + 1, Prefix.MAX_PREFIX_LENGTH);
if (longerLineRange.getStart() > Prefix.MAX_PREFIX_LENGTH) {
warnings.redFlag("'prefix-list-filter " + _prefixList + " longer' cannot match more specific prefix than " + prefix);
continue;
}
RouteFilterLine orLongerLine = new RouteFilterLine(action, prefix, longerLineRange);
longerList.addLine(orLongerLine);
c.getRouteFilterLists().put(longerListName, longerList);
}
}
return new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(longerListName));
} else {
warnings.redFlag("Reference to undefined prefix-list: \"" + _prefixList + "\"");
return BooleanExprs.False.toStaticBooleanExpr();
}
}
use of org.batfish.datamodel.RouteFilterLine in project batfish by batfish.
the class PsFromPrefixListFilterOrLonger method toBooleanExpr.
@Override
public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) {
PrefixList pl = jc.getPrefixLists().get(_prefixList);
if (pl != null) {
pl.getReferers().put(this, "from prefix-list-filter or-longer");
if (pl.getIpv6()) {
return BooleanExprs.False.toStaticBooleanExpr();
}
RouteFilterList rf = c.getRouteFilterLists().get(_prefixList);
String orLongerListName = "~" + _prefixList + "~ORLONGER~";
RouteFilterList orLongerList = c.getRouteFilterLists().get(orLongerListName);
if (orLongerList == null) {
orLongerList = new RouteFilterList(orLongerListName);
for (RouteFilterLine line : rf.getLines()) {
Prefix prefix = line.getPrefix();
LineAction action = line.getAction();
SubRange orLongerLineRange = new SubRange(line.getLengthRange().getStart(), Prefix.MAX_PREFIX_LENGTH);
RouteFilterLine orLongerLine = new RouteFilterLine(action, prefix, orLongerLineRange);
orLongerList.addLine(orLongerLine);
c.getRouteFilterLists().put(orLongerListName, orLongerList);
}
}
return new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(orLongerListName));
} else {
warnings.redFlag("Reference to undefined prefix-list: \"" + _prefixList + "\"");
return BooleanExprs.False.toStaticBooleanExpr();
}
}
use of org.batfish.datamodel.RouteFilterLine in project batfish by batfish.
the class TransferBDD method matchFilterList.
/*
* Converts a route filter list to a boolean expression.
*/
private BDD matchFilterList(TransferParam<BDDRoute> p, RouteFilterList x, BDDRoute other) {
BDD acc = factory.zero();
List<RouteFilterLine> lines = new ArrayList<>(x.getLines());
Collections.reverse(lines);
for (RouteFilterLine line : lines) {
Prefix pfx = line.getPrefix();
if (!PrefixUtils.isContainedBy(pfx, _ignoredNetworks)) {
SubRange r = line.getLengthRange();
PrefixRange range = new PrefixRange(pfx, r);
p.debug("Prefix Range: " + range);
p.debug("Action: " + line.getAction());
BDD matches = isRelevantFor(other, range);
BDD action = mkBDD(line.getAction() == LineAction.ACCEPT);
acc = ite(matches, action, acc);
}
}
return acc;
}
use of org.batfish.datamodel.RouteFilterLine in project batfish by batfish.
the class TransferSSA method matchFilterList.
/*
* Converts a route filter list to a boolean expression.
*/
private BoolExpr matchFilterList(RouteFilterList x, SymbolicRoute other) {
BoolExpr acc = _enc.mkFalse();
List<RouteFilterLine> lines = new ArrayList<>(x.getLines());
Collections.reverse(lines);
for (RouteFilterLine line : lines) {
Prefix p = line.getPrefix();
SubRange r = line.getLengthRange();
PrefixRange range = new PrefixRange(p, r);
BoolExpr matches = _enc.isRelevantFor(other.getPrefixLength(), range);
BoolExpr action = _enc.mkBool(line.getAction() == LineAction.ACCEPT);
acc = _enc.mkIf(matches, action, acc);
}
return acc;
}
use of org.batfish.datamodel.RouteFilterLine in project batfish by batfish.
the class CiscoConfiguration method toRouteFilterLine.
private RouteFilterLine toRouteFilterLine(ExtendedAccessListLine fromLine) {
LineAction action = fromLine.getAction();
Ip ip = fromLine.getSourceIpWildcard().getIp();
long minSubnet = fromLine.getDestinationIpWildcard().getIp().asLong();
long maxSubnet = minSubnet | fromLine.getDestinationIpWildcard().getWildcard().asLong();
int minPrefixLength = fromLine.getDestinationIpWildcard().getIp().numSubnetBits();
int maxPrefixLength = new Ip(maxSubnet).numSubnetBits();
int statedPrefixLength = fromLine.getSourceIpWildcard().getWildcard().inverted().numSubnetBits();
int prefixLength = Math.min(statedPrefixLength, minPrefixLength);
Prefix prefix = new Prefix(ip, prefixLength);
return new RouteFilterLine(action, prefix, new SubRange(minPrefixLength, maxPrefixLength));
}
Aggregations