/** * @param other another IpWildcard * @return whether the set of IPs matched by this is a subset of those matched by other. */ public boolean subsetOf(IpWildcard other) { return other.supersetOf(this); }
/** * Returns true if this {@link Keyring} can be used with the given localInterface and * matchIdentity * * @param localAddress {@link org.batfish.datamodel.Interface} {@link Ip} on which this {@link * Keyring} is intended to be used * @param matchIdentity {@link IpWildcard} for the remote peers with which this {@link Keyring} is * intended to be used * @return true if this {@link Keyring} can be used with the given localAddress and matchIdentity */ public boolean match(Ip localAddress, IpWildcard matchIdentity) { return _remoteIdentity.supersetOf(matchIdentity) && (_localAddress == null || Objects.equals(localAddress, _localAddress)); }
@Override public Boolean visitIpWildcardIpSpace(IpWildcardIpSpace ipWildcardIpSpace) { return !ipWildcardIpSpace.getIpWildcard().supersetOf(_ipWildcard); }
@Override public Boolean visitIpWildcardIpSpace(IpWildcardIpSpace ipWildcardIpSpace) { return _ipWildcard.supersetOf(ipWildcardIpSpace.getIpWildcard()); }
@Override protected boolean matchesSafely(IpWildcard ipWildcard, Description mismatchDescription) { boolean matches = ipWildcard.supersetOf(_ipWildcard); if (!matches) { mismatchDescription.appendText(String.format("was %s", ipWildcard)); } return matches; }
@Override public Boolean visitPrefixIpSpace(PrefixIpSpace prefixIpSpace) { return _ipWildcard.supersetOf(new IpWildcard(prefixIpSpace.getPrefix())); }
@Override public Boolean visitPrefixIpSpace(PrefixIpSpace prefixIpSpace) { return !new IpWildcard(prefixIpSpace.getPrefix()).supersetOf(_ipWildcard); }
@Test public void testSuperset_ANY() { assertThat("ANY should be a superset of itself", IpWildcard.ANY.supersetOf(IpWildcard.ANY)); } }
@Test public void testSupersetOf() { IpWildcard wc1 = new IpWildcard("1.2.0.0/16"); IpWildcard wc2 = new IpWildcard("1.2.3.0/24"); assertThat("IpWildcard.supersetOf should not be strict", wc1.supersetOf(wc1)); assertThat("wc1 should be a superset of wc2", wc1.supersetOf(wc2)); assertThat("wc2 should not be a superset of wc1", !wc2.supersetOf(wc1)); wc1 = new IpWildcard(Ip.create(0x12005600L), Ip.create(0xFF00FF00L).inverted()); wc2 = new IpWildcard(Ip.create(0x12345600L), Ip.create(0xFFFFFF00L).inverted()); assertThat("wc1 should be a superset of wc2", wc1.supersetOf(wc2)); assertThat("wc2 should not be a superset of wc1", !wc2.supersetOf(wc1)); }