Renamed devicemanager, flowprogrammer, linkdiscovery and util packages
net.onrc.onos.ofcontroller.devicemanager.* => net.onrc.onos.core.devicemanager.*
net.onrc.onos.ofcontroller.flowprogrammer.* => net.onrc.onos.core.flowprogrammer.*
net.onrc.onos.ofcontroller.linkdiscovery.* => net.onrc.onos.core.linkdiscovery.*
net.onrc.onos.ofcontroller.util.* => net.onrc.onos.core.util.*
Change-Id: Iaa865af552e8fb3a589e73d006569ac79f5a0f08
diff --git a/src/main/java/net/onrc/onos/core/util/IPv4.java b/src/main/java/net/onrc/onos/core/util/IPv4.java
new file mode 100644
index 0000000..86795aa
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/IPv4.java
@@ -0,0 +1,88 @@
+package net.onrc.onos.core.util;
+
+import net.onrc.onos.core.util.serializers.IPv4Deserializer;
+import net.onrc.onos.core.util.serializers.IPv4Serializer;
+
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+/**
+ * The class representing an IPv4 address.
+ */
+@JsonDeserialize(using=IPv4Deserializer.class)
+@JsonSerialize(using=IPv4Serializer.class)
+public class IPv4 {
+ private int value;
+
+ /**
+ * Default constructor.
+ */
+ public IPv4() {
+ this.value = 0;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to copy from.
+ */
+ public IPv4(IPv4 other) {
+ this.value = other.value;
+ }
+
+ /**
+ * Constructor from an integer value.
+ *
+ * @param value the value to use.
+ */
+ public IPv4(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Constructor from a string.
+ *
+ * @param value the value to use.
+ */
+ public IPv4(String value) {
+ String[] splits = value.split("\\.");
+ if (splits.length != 4)
+ throw new IllegalArgumentException("Specified IPv4 address must contain four " +
+ "numerical digits separated by '.'");
+
+ int result = 0;
+ for (int i = 0; i < 4; ++i) {
+ result |= Integer.valueOf(splits[i]) << ((3-i)*8);
+ }
+ this.value = result;
+ }
+
+ /**
+ * Get the value of the IPv4 address.
+ *
+ * @return the value of the IPv4 address.
+ */
+ public int value() { return value; }
+
+ /**
+ * Set the value of the IPv4 address.
+ *
+ * @param value the value to set.
+ */
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Convert the IPv4 value to a '.' separated string.
+ *
+ * @return the IPv4 value as a '.' separated string.
+ */
+ @Override
+ public String toString() {
+ return ((this.value >> 24) & 0xFF) + "." +
+ ((this.value >> 16) & 0xFF) + "." +
+ ((this.value >> 8) & 0xFF) + "." +
+ (this.value & 0xFF);
+ }
+}