Merge into master from pull request #74:
LOXI-45 Create common base interface for IPv[46]Address and IPv[46]Address with Mask (https://github.com/floodlight/loxigen/pull/74)
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/Prerequisite.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/Prerequisite.java
index 96cf8e9..03d5e79 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/Prerequisite.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/match/Prerequisite.java
@@ -10,7 +10,8 @@
private final Set<OFValueType<T>> values;
private boolean any;
- public Prerequisite(MatchField<T> field, @SuppressWarnings("unchecked") OFValueType<T>... values) {
+ @SafeVarargs
+ public Prerequisite(MatchField<T> field, OFValueType<T>... values) {
this.values = new HashSet<OFValueType<T>>();
this.field = field;
if (values == null || values.length == 0) {
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
new file mode 100644
index 0000000..7c50aed
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
@@ -0,0 +1,16 @@
+package org.projectfloodlight.openflow.types;
+
+public abstract class IPAddress<F extends IPAddress<F>> implements OFValueType<F> {
+
+ public abstract IPVersion getIpVersion();
+
+ public static IPAddress<?> of(String ip) {
+ if (ip.indexOf('.') != -1)
+ return IPv4Address.of(ip);
+ else if (ip.indexOf(':') != -1)
+ return IPv6Address.of(ip);
+ else
+ throw new IllegalArgumentException("IP Address not well formed: " + ip);
+ }
+
+}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java
new file mode 100644
index 0000000..11ef103
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java
@@ -0,0 +1,21 @@
+package org.projectfloodlight.openflow.types;
+
+
+public abstract class IPAddressWithMask<F extends IPAddress<F>> extends Masked<F> {
+
+ protected IPAddressWithMask(F value, F mask) {
+ super(value, mask);
+ }
+
+ public abstract IPVersion getIpVersion();
+
+ public static IPAddressWithMask<?> of(String ip) {
+ if (ip.indexOf('.') != -1)
+ return IPv4AddressWithMask.of(ip);
+ else if (ip.indexOf(':') != -1)
+ return IPv6AddressWithMask.of(ip);
+ else
+ throw new IllegalArgumentException("IP Address not well formed: " + ip);
+ }
+
+}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPVersion.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPVersion.java
new file mode 100644
index 0000000..5bfc6d8
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPVersion.java
@@ -0,0 +1,6 @@
+package org.projectfloodlight.openflow.types;
+
+public enum IPVersion {
+ IPv4,
+ IPv6
+}
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 0a8994a..3b07c17 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
@@ -9,7 +9,7 @@
*
* @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
*/
-public class IPv4Address implements OFValueType<IPv4Address> {
+public class IPv4Address extends IPAddress<IPv4Address> {
static final int LENGTH = 4;
private final int rawValue;
@@ -23,6 +23,11 @@
this.rawValue = rawValue;
}
+ @Override
+ public IPVersion getIpVersion() {
+ return IPVersion.IPv4;
+ }
+
public static IPv4Address of(final byte[] address) {
if (address.length != LENGTH) {
throw new IllegalArgumentException(
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 45f10d1..67bbce4 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
@@ -1,6 +1,7 @@
package org.projectfloodlight.openflow.types;
-public class IPv4AddressWithMask extends Masked<IPv4Address> {
+
+public class IPv4AddressWithMask extends IPAddressWithMask<IPv4Address> {
public final static IPv4AddressWithMask NONE = of(IPv4Address.NONE, IPv4Address.NONE);
private IPv4AddressWithMask(int rawValue, int rawMask) {
@@ -11,6 +12,11 @@
super(value, mask);
}
+ @Override
+ public IPVersion getIpVersion() {
+ return IPVersion.IPv4;
+ }
+
public static IPv4AddressWithMask of(int rawValue, int rawMask) {
return new IPv4AddressWithMask(rawValue, rawMask);
}
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 8afdaba..eb52f67 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
@@ -11,7 +11,7 @@
*
* @author Andreas Wundsam <andreas.wundsam@teleteach.de>
*/
-public class IPv6Address implements OFValueType<IPv6Address> {
+public class IPv6Address extends IPAddress<IPv6Address> {
static final int LENGTH = 16;
private final long raw1;
private final long raw2;
@@ -28,6 +28,11 @@
this.raw2 = raw2;
}
+ @Override
+ public IPVersion getIpVersion() {
+ return IPVersion.IPv6;
+ }
+
public static IPv6Address of(final byte[] address) {
if (address.length != LENGTH) {
throw new IllegalArgumentException(
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
index dcaa0b6..727daf6 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
@@ -3,13 +3,18 @@
import java.math.BigInteger;
import java.util.Arrays;
-public class IPv6AddressWithMask extends Masked<IPv6Address> {
+public class IPv6AddressWithMask extends IPAddressWithMask<IPv6Address> {
public final static IPv6AddressWithMask NONE = of(IPv6Address.NONE, IPv6Address.NONE);
private IPv6AddressWithMask(IPv6Address value, IPv6Address mask) {
super(value, mask);
}
+ @Override
+ public IPVersion getIpVersion() {
+ return IPVersion.IPv6;
+ }
+
public static IPv6AddressWithMask of(IPv6Address value, IPv6Address mask) {
return new IPv6AddressWithMask(value, mask);
}