public FwFromDestinationPort(int port) { _portRange = new SubRange(port, port); }
@Test public void testEmptyRange() { SubRange range = new SubRange(3, 1); assertThat(range.isEmpty(), equalTo(true)); assertThat(range.getStart(), equalTo(3)); assertThat(range.getEnd(), equalTo(1)); assertThat(range.includes(1), equalTo(false)); assertThat(range.includes(2), equalTo(false)); assertThat(range.includes(3), equalTo(false)); }
/** * Returns true if the {@code other} subrange is <b>fully</b> contained within this subrange. An * empty {@code other} is trivially considered to be contained within any subrange. */ public boolean contains(@Nonnull SubRange other) { return other.isEmpty() || (_start <= other.getStart() && _end >= other.getEnd()); }
@Test public void isSingleValue() { SubRange empty = new SubRange(2, 1); SubRange base = new SubRange(0, 10); SubRange singleton = new SubRange(5, 5); assertThat(empty.isSingleValue(), equalTo(false)); assertThat(base.isSingleValue(), equalTo(false)); assertThat(singleton.isSingleValue(), equalTo(true)); } }
public PrefixRange(Prefix prefix, SubRange lengthRange) { // Canonicalize the prefix by dropping extra bits in the address that are longer than any // relevant length. int realPrefixLength = Math.min(prefix.getPrefixLength(), lengthRange.getEnd()); Ip realPrefixAddress = prefix.getStartIp().getNetworkAddress(realPrefixLength); this._prefix = Prefix.create(realPrefixAddress, prefix.getPrefixLength()); this._lengthRange = lengthRange; }
@Override public boolean matches(int communityHalf) { return _range.includes(communityHalf); }
@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; } } }
public static boolean rangesContain(Collection<SubRange> ranges, int num) { return ranges.stream().anyMatch(sr -> sr.includes(num)); }
/** Returns a {@link PrefixRange} that represents all more specific prefixes. */ public static PrefixRange moreSpecificThan(Prefix prefix) { return new PrefixRange( prefix, new SubRange(prefix.getPrefixLength() + 1, Prefix.MAX_PREFIX_LENGTH)); }
@Override public Result evaluate(Environment environment) { LocalRoute localRoute = (LocalRoute) environment.getOriginalRoute(); Result result = new Result(); result.setBooleanValue(_matchLength.includes(localRoute.getSourcePrefixLength())); return result; }
/** Returns a {@link PrefixRange} that contains exactly the specified {@link Prefix}. */ public static PrefixRange fromPrefix(Prefix prefix) { int prefixLength = prefix.getPrefixLength(); return new PrefixRange(prefix, new SubRange(prefixLength, prefixLength)); }
@Override public void applyTo(RouteFilterList rfl) { org.batfish.datamodel.RouteFilterLine line = new org.batfish.datamodel.RouteFilterLine( LineAction.PERMIT, _prefix, new SubRange(_minPrefixLength, _maxPrefixLength)); rfl.addLine(line); }