Address reviewer's comments floodlight/loxigen#297
Reference:
https://github.com/floodlight/loxigen/pull/297
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
index 78c568f..4cb0fa5 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
@@ -61,6 +61,37 @@
public abstract F not();
/**
+ * Returns an {@code IPAddressWithMask<F>} object that represents this
+ * IP address masked by the given IP address mask.
+ *
+ * @param mask the {@code F} object that represents the mask
+ * @return an {@code IPAddressWithMask<F>} object that represents this
+ * IP address masked by the given mask
+ * @throws NullPointerException if the given mask was {@code null}
+ */
+ @Nonnull
+ public abstract IPAddressWithMask<F> withMask(@Nonnull final F mask);
+
+ /**
+ * Returns an {@code IPAddressWithMask<F>} object that represents this
+ * IP address masked by the CIDR subnet mask of the given prefix length.
+ *
+ * @param cidrMaskLength the prefix length of the CIDR subnet mask
+ * (i.e. the number of leading one-bits),
+ * where <code>
+ * 0 <= cidrMaskLength <= (F.getLength() * 8)
+ * </code>
+ * @return an {@code IPAddressWithMask<F>} object that
+ * represents this IP address masked by the CIDR
+ * subnet mask of the given prefix length
+ * @throws IllegalArgumentException if the given prefix length was invalid
+ * @see #ofCidrMaskLength(int)
+ */
+ @Nonnull
+ public abstract IPAddressWithMask<F> withMaskOfLength(
+ final int cidrMaskLength);
+
+ /**
* Returns the raw IP address of this {@code IPAddress} object. The result
* is in network byte order: the highest order byte of the address is in
* {@code getBytes()[0]}.
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
index 74cd7b0..3a1b15e 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
@@ -239,82 +239,13 @@
* @throws NullPointerException if the given mask was {@code null}
*/
@Nonnull
+ @Override
public IPv4AddressWithMask withMask(@Nonnull final IPv4Address mask) {
return IPv4AddressWithMask.of(this, mask);
}
/**
* Returns an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask. The argument is in
- * network byte order: the highest order byte of the address is in
- * {@code mask[0]}.
- * <p>
- * The address byte array must be 4 bytes long (32 bits long).
- *
- * @param mask the raw IP address mask in network byte order
- * @return an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given raw IP address mask
- * @throws NullPointerException if the given mask was {@code null}
- * @throws IllegalArgumentException if the given mask was of an invalid
- * byte array length
- * @see #of(byte[])
- */
- @Nonnull
- public IPv4AddressWithMask withMask(@Nonnull final byte[] mask) {
- return IPv4AddressWithMask.of(this, IPv4Address.of(mask));
- }
-
- /**
- * Returns an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask.
- *
- * @param mask the raw IP address mask represented as a 32-bit integer
- * @return an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given raw IP address mask
- * @see #of(int)
- */
- @Nonnull
- public IPv4AddressWithMask withMask(final int mask) {
- return IPv4AddressWithMask.of(this, IPv4Address.of(mask));
- }
-
- /**
- * Returns an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask. The argument is in
- * the canonical quad-dotted notation. For example, {@code 255.255.255.0}.
- *
- * @param mask the IP address mask in the canonical quad-dotted notation
- * @return an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask
- * @throws NullPointerException if the given string was {@code null}
- * @throws IllegalArgumentException if the given string was not a valid
- * IPv4 address
- * @see #of(String)
- */
- @Nonnull
- public IPv4AddressWithMask withMask(@Nonnull final String mask) {
- return IPv4AddressWithMask.of(this, IPv4Address.of(mask));
- }
-
- /**
- * Returns an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask. The argument is given as
- * an {@code Inet4Address} object.
- *
- * @param mask the IP address mask as an {@code Inet4Address} object
- * @return an {@code IPv4AddressWithMask} object that represents this
- * IP address masked by the given IP address mask
- * @throws NullPointerException if the given {@code Inet4Address} was
- * {@code null}
- * @see #of(Inet4Address)
- */
- @Nonnull
- public IPv4AddressWithMask withMask(@Nonnull final Inet4Address mask) {
- return IPv4AddressWithMask.of(this, IPv4Address.of(mask));
- }
-
- /**
- * Returns an {@code IPv4AddressWithMask} object that represents this
* IP address masked by the CIDR subnet mask of the given prefix length.
*
* @param cidrMaskLength the prefix length of the CIDR subnet mask
@@ -327,9 +258,9 @@
* @see #ofCidrMaskLength(int)
*/
@Nonnull
+ @Override
public IPv4AddressWithMask withMaskOfLength(final int cidrMaskLength) {
- return IPv4AddressWithMask.of(this,
- IPv4Address.ofCidrMaskLength(cidrMaskLength));
+ return this.withMask(IPv4Address.ofCidrMaskLength(cidrMaskLength));
}
public int getInt() {
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
index 6bd5539..b6dc1b9 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
@@ -30,8 +30,10 @@
* @return an {@code IPv4AddressWithMask} object that represents
* the given raw IP address masked by the given raw IP
* address mask
- * @deprecated replaced by {@link IPv4Address#of(int)} followed by
- * {@link IPv4Address#withMask(int)}
+ * @deprecated replaced by {@link IPv4Address#of(int)} and
+ * {@link IPv4Address#withMask(IPv4Address), e.g. <code>
+ * IPv4Address.of(int).withMask(IPv4Address.of(int))
+ * </code>
*/
@Nonnull
@Deprecated
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
index 4b66a8d..dcbd4a1 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
@@ -342,6 +342,40 @@
}
}
+ /**
+ * Returns an {@code IPv6AddressWithMask} object that represents this
+ * IP address masked by the given IP address mask.
+ *
+ * @param mask the {@code IPv6Address} object that represents the mask
+ * @return an {@code IPv6AddressWithMask} object that represents this
+ * IP address masked by the given mask
+ * @throws NullPointerException if the given mask was {@code null}
+ */
+ @Nonnull
+ @Override
+ public IPv6AddressWithMask withMask(@Nonnull final IPv6Address mask) {
+ return IPv6AddressWithMask.of(this, mask);
+ }
+
+ /**
+ * Returns an {@code IPv6AddressWithMask} object that represents this
+ * IP address masked by the CIDR subnet mask of the given prefix length.
+ *
+ * @param cidrMaskLength the prefix length of the CIDR subnet mask
+ * (i.e. the number of leading one-bits),
+ * where {@code 0 <= cidrMaskLength <= 128}
+ * @return an {@code IPv6AddressWithMask} object that
+ * represents this IP address masked by the CIDR
+ * subnet mask of the given prefix length
+ * @throws IllegalArgumentException if the given prefix length was invalid
+ * @see #ofCidrMaskLength(int)
+ */
+ @Nonnull
+ @Override
+ public IPv6AddressWithMask withMaskOfLength(final int cidrMaskLength) {
+ return this.withMask(IPv6Address.ofCidrMaskLength(cidrMaskLength));
+ }
+
private volatile byte[] bytesCache = null;
public byte[] getBytes() {
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
index 2e6128e..0716b50 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
@@ -281,24 +281,20 @@
IPv4AddressWithMask v;
- v = original.withMask(expectedMask);
+ v = original.withMask(IPv4Address.of(new byte[] {-1, -1, -1, 0}));
assertEquals(v.getValue(), expectedValue);
assertEquals(v.getMask(), expectedMask);
- v = original.withMask(new byte[] {-1, -1, -1, 0});
+ v = original.withMask(IPv4Address.of(0xFFFF_FF00));
assertEquals(v.getValue(), expectedValue);
assertEquals(v.getMask(), expectedMask);
- v = original.withMask(0xFFFF_FF00);
- assertEquals(v.getValue(), expectedValue);
- assertEquals(v.getMask(), expectedMask);
-
- v = original.withMask("255.255.255.0");
+ v = original.withMask(IPv4Address.of("255.255.255.0"));
assertEquals(v.getValue(), expectedValue);
assertEquals(v.getMask(), expectedMask);
Inet4Address i4a = (Inet4Address) InetAddress.getByName("255.255.255.0");
- v = original.withMask(i4a);
+ v = original.withMask(IPv4Address.of(i4a));
assertEquals(v.getValue(), expectedValue);
assertEquals(v.getMask(), expectedMask);
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
index 394a39b..a397c2a 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
@@ -237,6 +237,41 @@
}
@Test
+ public void testWithMask() throws Exception {
+ // Sanity tests for the withMask*() syntactic sugars
+
+ IPv6Address original = IPv6Address.of("fd12:3456:ABCD:7890::1");
+ IPv6Address expectedValue = IPv6Address.of("fd12:3456:ABCD::");
+ IPv6Address expectedMask = IPv6Address.of("ffff:ffff:ffff::");
+
+ IPv6AddressWithMask v;
+
+ v = original.withMask(IPv6Address.of(new byte[] {
+ -1, -1, -1, -1, -1, -1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0 }));
+ assertEquals(v.getValue(), expectedValue);
+ assertEquals(v.getMask(), expectedMask);
+
+ v = original.withMask(IPv6Address.of(
+ 0xFFFF_FFFF_FFFF_0000L, 0x0000_0000_0000_0000L));
+ assertEquals(v.getValue(), expectedValue);
+ assertEquals(v.getMask(), expectedMask);
+
+ v = original.withMask(IPv6Address.of("ffff:ffff:ffff::"));
+ assertEquals(v.getValue(), expectedValue);
+ assertEquals(v.getMask(), expectedMask);
+
+ Inet6Address i6a = (Inet6Address) InetAddress.getByName("ffff:ffff:ffff::");
+ v = original.withMask(IPv6Address.of(i6a));
+ assertEquals(v.getValue(), expectedValue);
+ assertEquals(v.getMask(), expectedMask);
+
+ v = original.withMaskOfLength(48);
+ assertEquals(v.getValue(), expectedValue);
+ assertEquals(v.getMask(), expectedMask);
+ }
+
+ @Test
public void testReadFrom() throws OFParseError, UnknownHostException {
for(int i=0; i < testStrings.length; i++ ) {
byte[] bytes = Inet6Address.getByName(testStrings[i]).getAddress();