1. Removed type serializers, added (write|read)[0-9]*Byte[s]?(ChannelBuffer) method to value types instead.
2. Updated Masked fields for IPv4, IPv6 with specific string methods.
3. Added value types for other fields from the spec
4. Updated unit tests accordingly
5. Changed java_type.py to support multiple read/write operations per type, per OF version.
diff --git a/java_gen/pre-written/src/test/java/org/openflow/types/IPv6Test.java b/java_gen/pre-written/src/test/java/org/openflow/types/IPv6Test.java
index 9782429..f2f6fe8 100644
--- a/java_gen/pre-written/src/test/java/org/openflow/types/IPv6Test.java
+++ b/java_gen/pre-written/src/test/java/org/openflow/types/IPv6Test.java
@@ -21,6 +21,72 @@
"ffe0::",
"1:2:3:4:5:6:7:8"
};
+
+ String[] ipsWithMask = {
+ "1::1/80",
+ "1:2:3:4::/ffff:ffff:ffff:ff00::",
+ "ffff:ffee:1::/ff00:ff00:ff00:ff00::",
+ "8:8:8:8:8:8:8:8",
+ };
+
+ byte[][] masks = {
+ new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
+ (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
+ (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
+ new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
+ (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
+ new byte[] { (byte)0xff, (byte)0x00, (byte)0xff, (byte)0x00,
+ (byte)0xff, (byte)0x00, (byte)0xff, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
+ new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
+ };
+
+ boolean[] hasMask = {
+ true,
+ true,
+ true,
+ false
+ };
+
+ @Test
+ public void testMasked() throws UnknownHostException {
+ for(int i=0; i < ipsWithMask.length; i++ ) {
+ OFValueType value = IPv6WithMask.ofPossiblyMasked(ipsWithMask[i]);
+ if (value instanceof IPv6 && !hasMask[i]) {
+ // Types OK, check values
+ IPv6 ip = (IPv6)value;
+ InetAddress inetAddress = InetAddress.getByName(ipsWithMask[i]);
+
+ assertArrayEquals(ip.getBytes(), inetAddress.getAddress());
+ assertEquals(ipsWithMask[i], ip.toString());
+ } else if (value instanceof IPv6WithMask && hasMask[i]) {
+ IPv6WithMask ip = null;
+ try {
+ ip = (IPv6WithMask)value;
+ } catch (ClassCastException e) {
+ fail("Invalid Masked<T> type.");
+ }
+ // Types OK, check values
+ InetAddress inetAddress = InetAddress.getByName(ipsWithMask[i].substring(0, ipsWithMask[i].indexOf('/')));
+
+ assertArrayEquals(ip.value.getBytes(), inetAddress.getAddress());
+ assertEquals(ipsWithMask[i].substring(0, ipsWithMask[i].indexOf('/')), ip.value.toString());
+ assertArrayEquals(masks[i], ip.mask.getBytes());
+ } else if (value instanceof IPv6) {
+ fail("Expected masked IPv6, got unmasked IPv6.");
+ } else {
+ fail("Expected unmasked IPv6, got masked IPv6.");
+ }
+ }
+ }
+
@Test
public void testOfString() throws UnknownHostException {
@@ -47,7 +113,7 @@
public void testReadFrom() throws OFParseError, OFShortRead, UnknownHostException {
for(int i=0; i < testStrings.length; i++ ) {
byte[] bytes = Inet6Address.getByName(testStrings[i]).getAddress();
- IPv6 ip = IPv6.SERIALIZER_V12.readFrom(ChannelBuffers.copiedBuffer(bytes));
+ IPv6 ip = IPv6.read16Bytes(ChannelBuffers.copiedBuffer(bytes));
assertEquals(testStrings[i], ip.toString());
assertArrayEquals(bytes, ip.getBytes());
}