private void assertIpWildcardIsPrefix(IpWildcard ipWildcard) { if (!ipWildcard.isPrefix()) { throw new BatfishException("non-prefix IpWildcards are unsupported"); } }
public Prefix toPrefix() { if (isPrefix()) { return Prefix.create(_first, _second.inverted()); } else { throw new BatfishException("Invalid wildcard format for conversion to prefix: " + _second); } }
@JsonValue @Override public String toString() { if (_second.equals(Ip.ZERO)) { return _first.toString(); } else if (isPrefix()) { return toPrefix().toString(); } else { return _first + ":" + _second; } } }
private void computeSuppressedAggregates() { _encoderSlice .getGraph() .getConfigurations() .forEach( (router, conf) -> { Set<Prefix> prefixes = new HashSet<>(); _suppressedAggregates.put(router, prefixes); conf.getRouteFilterLists() .forEach( (name, filter) -> { if (name.contains(AGGREGATION_SUPPRESS_NAME)) { for (RouteFilterLine line : filter.getLines()) { if (!line.getIpWildcard().isPrefix()) { throw new BatfishException("non-prefix IpWildcards are unsupported"); } prefixes.add(line.getIpWildcard().toPrefix()); } } }); }); }
public static BooleanExpr matchIpWildcard(IpWildcard ipWildcard, IntExpr ipField) { if (ipWildcard.isPrefix()) { return matchPrefix(ipWildcard.toPrefix(), ipField); } long ip = ipWildcard.getIp().asLong(); long wildcard = ipWildcard.getWildcard().asLong(); ImmutableList.Builder<BooleanExpr> matchIp = ImmutableList.builder(); for (int currentBitIndex = 0; currentBitIndex < Prefix.MAX_PREFIX_LENGTH; currentBitIndex++) { long mask = 1L << currentBitIndex; long currentWildcardBit = mask & wildcard; boolean useBit = currentWildcardBit == 0; if (useBit) { IntExpr extractIp = ExtractExpr.newExtractExpr(ipField, currentBitIndex, currentBitIndex); LitIntExpr srcIpMatchLit = new LitIntExpr(ip, currentBitIndex, currentBitIndex); EqExpr matchIpBit = new EqExpr(extractIp, srcIpMatchLit); matchIp.add(matchIpBit); } } return new AndExpr(matchIp.build()); }
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) { if (!line.getIpWildcard().isPrefix()) { throw new BatfishException("non-prefix IpWildcards are unsupported"); } Prefix p = line.getIpWildcard().toPrefix(); SubRange r = line.getLengthRange(); PrefixRange range = new PrefixRange(p, r); BoolExpr matches = _enc.isRelevantFor(other.getPrefixLength(), range); BoolExpr action = _enc.mkBool(line.getAction() == LineAction.PERMIT); acc = _enc.mkIf(matches, action, acc); } return acc; }
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) { if (!line.getIpWildcard().isPrefix()) { throw new BatfishException("non-prefix IpWildcards are unsupported"); } Prefix pfx = line.getIpWildcard().toPrefix(); 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.PERMIT); acc = ite(matches, action, acc); } } return acc; }