/** * Returns a new {@link PrefixSpace} containing all {@link Prefix}es shared between this {@link * PrefixSpace} and the one given. * * @param intersectSpace {@link PrefixSpace} with which to find intersecting {@link Prefix}es * @return A new {@link PrefixSpace} containing all shared {@link Prefix}es */ public PrefixSpace intersection(PrefixSpace intersectSpace) { PrefixSpace newSpace = new PrefixSpace(); Set<PrefixRange> intersectRanges = intersectSpace.getPrefixRanges(); for (PrefixRange intersectRange : intersectRanges) { if (containsPrefixRange(intersectRange)) { newSpace.addPrefixRange(intersectRange); } } return newSpace; }
/** * Expand the origination space for this prefix * * @param space {@link PrefixSpace} to add */ public void addToOriginationSpace(PrefixSpace space) { _originationSpace.addSpace(space); }
/** * Returns whether the given {@link PrefixSpace} has any {@link Prefix}es in common with this one. * * @param intersectSpace {@link PrefixSpace} in which to check for overlap * @return {@code true} if the given {@link PrefixSpace} has any {@link Prefix}es in common with * this one */ public boolean overlaps(PrefixSpace intersectSpace) { PrefixSpace intersection = intersection(intersectSpace); return !intersection.isEmpty(); }
@Test public void intersectionAndOverlapsTest() { PrefixSpace other = new PrefixSpace(); assertThat("empty spaces don't intersect", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap for empty spaces", _ps.overlaps(other), equalTo(false)); _ps.addPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-21")); assertThat("no intersection for one empty", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap for one empty", _ps.overlaps(other), equalTo(false)); other.addPrefixRange(PrefixRange.fromString("10.10.10.0/16:14-16")); assertThat("no intersection", _ps.intersection(other).isEmpty(), equalTo(true)); assertThat("no overlap", _ps.overlaps(other), equalTo(false)); other.addPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-20")); PrefixSpace intersection = _ps.intersection(other); assertThat( "now intersect for length 18", intersection.containsPrefix(Prefix.parse("10.10.0.0/18")), equalTo(true)); assertThat( "now intersect for length 19", intersection.containsPrefix(Prefix.parse("10.10.0.0/19")), equalTo(true)); assertThat( "now intersect for range 18-20", intersection.containsPrefixRange(PrefixRange.fromString("10.10.0.0/20:18-20")), equalTo(true)); assertThat("don't intersect anywhere else", intersection.getPrefixRanges().size(), equalTo(3)); assertThat("has overlap", _ps.overlaps(other), equalTo(true)); }
PrefixSpace space1 = new PrefixSpace(); boolean empty1 = true; for (Vrf v1 : c1.getVrfs().values()) { if (proc1 != null) { empty1 = false; space1.addSpace(proc1.getOriginationSpace()); PrefixSpace space2 = new PrefixSpace(); boolean empty2 = true; for (Vrf v2 : c2.getVrfs().values()) { if (proc2 != null) { empty2 = false; space2.addSpace(proc2.getOriginationSpace()); if (!empty2 && space1.overlaps(space2)) { PrefixSpace intersection = space1.intersection(space2); answerElement.addIntersection(node1, node2, intersection);
@Test public void addSpaceTest() { PrefixRange range = PrefixRange.fromString("100.0.0.0/32"); _ps.addSpace(new PrefixSpace(range)); assertThat(_ps.isEmpty(), equalTo(false)); assertThat(_ps.containsPrefixRange(range), equalTo(true)); }
PrefixRange all = PrefixRange.fromString("0.0.0.0/0:0-32"); PrefixSpace space = new PrefixSpace(); space.addPrefixRange(ten8to15); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(ten8to15))); space.addPrefixRange(ten8to16); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(ten8to16))); space.addPrefixRange(ten8to16); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(ten8to16))); space.addPrefixRange(ten9to17); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(ten8to16, ten9to17))); space.addPrefixRange(one9to9); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(one9to9, ten8to16, ten9to17))); space.addPrefixRange(eleven9to9); assertThat( space.getPrefixRanges(), equalTo(ImmutableSet.of(one9to9, ten8to16, ten9to17, eleven9to9))); space.addPrefixRange(all); assertThat(space.getPrefixRanges(), equalTo(ImmutableSet.of(all)));
/** Constructs a BgpProcess */ public BgpProcess() { _activeNeighbors = new TreeMap<>(); _generatedRoutes = new TreeSet<>(); _tieBreaker = BgpTieBreaker.ARRIVAL_ORDER; _clusterIds = new ClusterIdsSupplier(); _originationSpace = new PrefixSpace(); _activeNeighbors = new TreeMap<>(); _passiveNeighbors = new TreeMap<>(); }
@Test public void constructPrefixSpaceTest() { _ps = new PrefixSpace(PrefixRange.fromString("100.0.0.0/32")); assertThat(_ps.isEmpty(), equalTo(false)); assertThat(_ps.containsPrefixRange(PrefixRange.fromString("100.0.0.0/32")), equalTo(true)); }
@Test public void addPrefixRangeTest() { PrefixRange range = PrefixRange.fromString("10.10.10.0/32:16-24"); _ps = new PrefixSpace(range); assertThat(_ps.containsPrefixRange(range), equalTo(true)); assertThat( "Shorter prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/15")), equalTo(false)); assertThat( "Shortest prefix is included", _ps.containsPrefix(Prefix.parse("10.10.10.0/16")), equalTo(true)); assertThat( "Longest prefix is included", _ps.containsPrefix(Prefix.parse("10.10.10.0/24")), equalTo(true)); assertThat( "Longer prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/25")), equalTo(false)); assertThat( "Prefixes with mismatch in masked bits not included", _ps.containsPrefix(Prefix.parse("10.10.11.0/24")), equalTo(false)); assertThat( "Prefixes with mismatch in unmasked bits included", _ps.containsPrefix(Prefix.parse("10.10.10.255/24")), equalTo(true)); }
@Test public void addPrefixTest() { Prefix prefix = Prefix.parse("100.0.0.0/32"); _ps.addPrefix(prefix); assertThat(_ps.getPrefixRanges().size(), equalTo(1)); assertThat(_ps.containsPrefix(prefix), equalTo(true)); }
/** * Returns a {@code String} listing the {@link PrefixRange}s contained in this {@link * PrefixSpace}. * * @return {@code String} representation of this {@link PrefixSpace} */ @Override public String toString() { return getPrefixRanges().toString(); } }
} else { PrefixSpace prefixSpace = new PrefixSpace(); Prefix6Space prefix6Space = new Prefix6Space(); boolean ipv6 = false; prefixSpace.addPrefixRange(new PrefixRange(prefix, new SubRange(lower, upper))); } else { prefix6Space.addPrefix6Range(new Prefix6Range(prefix6, new SubRange(lower, upper)));
@Test public void getPrefixRangesTest() { assertThat("No ranges yet", _ps.getPrefixRanges().isEmpty(), equalTo(true)); _ps.addPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-21")); Set<PrefixRange> ranges = _ps.getPrefixRanges(); assertThat(ranges.contains(PrefixRange.fromString("10.10.0.0/18")), equalTo(true)); assertThat(ranges.contains(PrefixRange.fromString("10.10.0.0/19")), equalTo(true)); assertThat(ranges.contains(PrefixRange.fromString("10.10.10.0/20:18-21")), equalTo(true)); assertThat(ranges.size(), equalTo(3)); _ps.addPrefixRange((PrefixRange.fromString("10.10.10.0/20:20-22"))); ranges = _ps.getPrefixRanges(); assertThat(ranges.contains(PrefixRange.fromString("10.10.10.0/20:20-22")), equalTo(true)); }
new MatchPrefixSet( DestinationNetwork.instance(), new ExplicitPrefixSet(new PrefixSpace(PrefixRange.fromPrefix(prefix))))); generateAggregateConditions.add(new MatchProtocol(RoutingProtocol.AGGREGATE)); PrefixSpace space = new PrefixSpace(); space.addPrefix(prefix); newBgpProcess.addToOriginationSpace(space); exportNetworkConditions
@Test public void containsPrefixRangeTest() { PrefixRange range = PrefixRange.fromString("10.10.10.0/20:16-24"); _ps.addPrefixRange(range); assertThat( "Ranges earlier than this range not included", _ps.containsPrefixRange(PrefixRange.fromString("10.10.10.0/20:15-24")), equalTo(false)); assertThat( "Ranges later than this range not included", _ps.containsPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-26")), equalTo(false)); assertThat( "Ranges contained in this range included", _ps.containsPrefixRange(PrefixRange.fromString("10.10.10.0/20:18-20")), equalTo(true)); assertThat( "Range not included if prefix is shorter", _ps.containsPrefixRange(PrefixRange.fromString("10.10.10.0/8:16-24")), equalTo(false)); assertThat( "Range included if prefix is longer", _ps.containsPrefixRange(PrefixRange.fromString("10.10.10.0/28:16-24")), equalTo(true)); }
@Test public void containsPrefixTest() { Prefix prefix = Prefix.parse("10.10.10.0/24"); _ps.addPrefix(prefix); assertThat( "Shorter prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/20")), equalTo(false)); assertThat( "Exact given prefix is included", _ps.containsPrefix(Prefix.parse("10.10.10.0/24")), equalTo(true)); assertThat( "Longer prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/26")), equalTo(false)); assertThat( "Prefixes with mismatch in masked bits not included", _ps.containsPrefix(Prefix.parse("10.10.11.0/24")), equalTo(false)); assertThat( "Prefixes with mismatch in unmasked bits included", _ps.containsPrefix(Prefix.parse("10.10.10.255/24")), equalTo(true)); }
/** * Adds the given {@link Prefix} to this {@link PrefixSpace}. * * @param prefix Prefix to add */ public void addPrefix(Prefix prefix) { addPrefixRange(PrefixRange.fromPrefix(prefix)); }
@JsonIgnore public boolean isEmpty() { return _trie._root.isEmpty(); }
@Override public boolean matches(Prefix prefix, Environment environment) { boolean value = _prefixSpace.containsPrefix(prefix); return value; }