Added IPv6Address.ofCidrMaskLength() and the corresponding unit tests

Reference:
IPv6AddressWithMask.of(String)
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 dbf5a90..8a3a60a 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
@@ -1,5 +1,6 @@
 package org.projectfloodlight.openflow.types;
 
+import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.regex.Pattern;
 
@@ -252,6 +253,36 @@
         return new IPv6Address(raw1, raw2);
     }
 
+    public static IPv6Address ofCidrMaskLength(int cidrMaskLength) {
+        Preconditions.checkArgument(
+                cidrMaskLength >= 0 && cidrMaskLength <= 128,
+                "Invalid IPv6 CIDR mask length: %s", cidrMaskLength);
+
+        if (cidrMaskLength == 128) {
+            return IPv6Address.NO_MASK;
+        } else if (cidrMaskLength == 0) {
+            return IPv6Address.FULL_MASK;
+        } else {
+            BigInteger mask
+                    = BigInteger.ONE.negate().shiftLeft(128 - cidrMaskLength);
+            byte[] maskBytesTemp = mask.toByteArray();
+            byte[] maskBytes;
+            if (maskBytesTemp.length < 16) {
+                maskBytes = new byte[16];
+                System.arraycopy(maskBytesTemp, 0,
+                        maskBytes, 16 - maskBytesTemp.length,
+                        maskBytesTemp.length);
+                Arrays.fill(maskBytes, 0, 16 - maskBytesTemp.length, (byte)(0xFF));
+            } else if (maskBytesTemp.length > 16) {
+                maskBytes = new byte[16];
+                System.arraycopy(maskBytesTemp, 0, maskBytes, 0, maskBytes.length);
+            } else {
+                maskBytes = maskBytesTemp;
+            }
+            return IPv6Address.of(maskBytes);
+        }
+    }
+
     private volatile byte[] bytesCache = null;
 
     public byte[] getBytes() {
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 6963c21..394a39b 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
@@ -198,6 +198,44 @@
         }
     }
 
+    private static void testOfCidrMaskLengthHelper(
+            int cidrMaskLength, String ipStr) throws UnknownHostException {
+        byte[] ba0 = IPv6Address.ofCidrMaskLength(cidrMaskLength).getBytes();
+        byte[] ba1 = Inet6Address.getByName(ipStr).getAddress();
+        assertArrayEquals(ba0, ba1);
+    }
+
+    @Test
+    public void testOfCidrMaskLength() throws UnknownHostException {
+        for (int i = 0; i <= 128; i++) {
+            assertTrue(IPv6Address.ofCidrMaskLength(i).isCidrMask());
+            assertEquals(IPv6Address.ofCidrMaskLength(i).asCidrMaskLength(), i);
+        }
+        testOfCidrMaskLengthHelper(0, "::");
+        testOfCidrMaskLengthHelper(1, "8000::");
+        testOfCidrMaskLengthHelper(2, "c000::");
+        testOfCidrMaskLengthHelper(8, "ff00::");
+        testOfCidrMaskLengthHelper(16, "ffff::");
+        testOfCidrMaskLengthHelper(17, "ffff:8000::");
+        testOfCidrMaskLengthHelper(31, "ffff:fffe::");
+        testOfCidrMaskLengthHelper(32, "ffff:ffff::");
+        testOfCidrMaskLengthHelper(33, "ffff:ffff:8000::");
+        testOfCidrMaskLengthHelper(46, "ffff:ffff:fffc::");
+        testOfCidrMaskLengthHelper(48, "ffff:ffff:ffff::");
+        testOfCidrMaskLengthHelper(55, "ffff:ffff:ffff:fe00::");
+        testOfCidrMaskLengthHelper(56, "ffff:ffff:ffff:ff00::");
+        testOfCidrMaskLengthHelper(59, "ffff:ffff:ffff:ffe0::");
+        testOfCidrMaskLengthHelper(63, "ffff:ffff:ffff:fffe::");
+        testOfCidrMaskLengthHelper(64, "ffff:ffff:ffff:ffff::");
+        testOfCidrMaskLengthHelper(65, "ffff:ffff:ffff:ffff:8000::");
+        testOfCidrMaskLengthHelper(67, "ffff:ffff:ffff:ffff:e000::");
+        testOfCidrMaskLengthHelper(100, "ffff:ffff:ffff:ffff:ffff:ffff:f000::");
+        testOfCidrMaskLengthHelper(101, "ffff:ffff:ffff:ffff:ffff:ffff:f800::");
+        testOfCidrMaskLengthHelper(126, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc");
+        testOfCidrMaskLengthHelper(127, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe");
+        testOfCidrMaskLengthHelper(128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
+    }
+
     @Test
     public void testReadFrom() throws OFParseError, UnknownHostException {
         for(int i=0; i < testStrings.length; i++ ) {
@@ -313,5 +351,17 @@
         } catch (IllegalArgumentException e) {
             assertNotNull(e.getMessage());
         }
+        try {
+            IPv6Address.ofCidrMaskLength(-1);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            assertNotNull(e.getMessage());
+        }
+        try {
+            IPv6Address.ofCidrMaskLength(129);
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            assertNotNull(e.getMessage());
+        }
     }
 }