@Override public Void visitUniverseIpSpace(UniverseIpSpace universeIpSpace) { _prefixes.add(IpWildcard.ANY.toPrefix()); return null; } }
@Override public Void visitIpWildcardIpSpace(IpWildcardIpSpace ipWildcardIpSpace) { IpWildcard ipWildcard = ipWildcardIpSpace.getIpWildcard(); assertIpWildcardIsPrefix(ipWildcard); _prefixes.add(ipWildcard.toPrefix()); return null; }
@JsonValue @Override public String toString() { if (_second.equals(Ip.ZERO)) { return _first.toString(); } else if (isPrefix()) { return toPrefix().toString(); } else { return _first + ":" + _second; } } }
public static boolean overlap(HeaderSpace h, Prefix p) { if (h.getDstIps() == null) { return true; } for (IpWildcard ipWildcard : asPositiveIpWildcards(h.getDstIps())) { Prefix p2 = ipWildcard.toPrefix(); if (overlap(p, p2)) { return true; } } return false; }
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()); } } }); }); }
@Override public void exitIp_nat_pool(Ip_nat_poolContext ctx) { String name = ctx.name.getText(); Ip first = toIp(ctx.first); Ip last = toIp(ctx.last); if (ctx.mask != null) { Prefix subnet = new IpWildcard(first, toIp(ctx.mask).inverted()).toPrefix(); createNatPool(name, first, last, subnet, ctx); } else if (ctx.prefix_length != null) { Prefix subnet = Prefix.create(first, Integer.parseInt(ctx.prefix_length.getText())); createNatPool(name, first, last, subnet, ctx); } else { _configuration.getNatPools().put(name, new NatPool(first, last)); } defineStructure(NAT_POOL, name, ctx); }
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; }
/** Convert a standard access list line to a route filter list line */ private static RouteFilterLine toRouteFilterLine(StandardAccessListLine fromLine) { LineAction action = fromLine.getAction(); /* * This cast is safe since the other address specifier (network object group specifier) * can be used only from extended ACLs. */ IpWildcard srcIpWildcard = ((WildcardAddressSpecifier) fromLine.getSrcAddressSpecifier()).getIpWildcard(); Prefix prefix = srcIpWildcard.toPrefix(); return new RouteFilterLine( action, new IpWildcard(prefix), new SubRange(prefix.getPrefixLength(), Prefix.MAX_PREFIX_LENGTH)); }
@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_prefixList); if (pl != null) { if (pl.getIpv6()) { return BooleanExprs.FALSE; } 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.getIpWildcard().toPrefix(); 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( DestinationNetwork.instance(), new NamedPrefixSet(orLongerListName)); } else { warnings.redFlag("Reference to undefined prefix-list: \"" + _prefixList + "\""); return BooleanExprs.FALSE; } } }
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; }
longerList = new RouteFilterList(longerListName); for (RouteFilterLine line : rf.getLines()) { Prefix prefix = line.getIpWildcard().toPrefix(); LineAction action = line.getAction(); SubRange longerLineRange =