Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/core/api/src/main/java/org/onlab/onos/net/DefaultHost.java b/core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
index e5d641f..f1ec27e 100644
--- a/core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
+++ b/core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
@@ -8,23 +8,27 @@
 import java.util.Set;
 
 import org.onlab.onos.net.provider.ProviderId;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
+/**
+ * A basic implementation of a Host.
+ */
 public class DefaultHost extends AbstractElement implements Host {
 
     private final MACAddress mac;
-    private final short vlan;
+    private final VLANID vlan;
     private final HostLocation location;
-    private final Set<IPv4> ips;
+    private final Set<IPAddress> ips;
 
-    public DefaultHost(ProviderId providerId, ElementId id, MACAddress mac,
-            short vlan, HostLocation loc, Set<IPv4> ips) {
+    public DefaultHost(ProviderId providerId, HostId id, MACAddress mac,
+            VLANID vlan, HostLocation loc, Set<IPAddress> ips) {
         super(providerId, id);
         this.mac = mac;
         this.vlan = vlan;
         this.location = loc;
-        this.ips = new HashSet<IPv4>(ips);
+        this.ips = new HashSet<IPAddress>(ips);
     }
 
     @Override
@@ -38,7 +42,7 @@
     }
 
     @Override
-    public Set<IPv4> ipAddresses() {
+    public Set<IPAddress> ipAddresses() {
         return Collections.unmodifiableSet(ips);
     }
 
@@ -48,7 +52,7 @@
     }
 
     @Override
-    public short vlan() {
+    public VLANID vlan() {
         return vlan;
     }
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/Host.java b/core/api/src/main/java/org/onlab/onos/net/Host.java
index 667bb88..b56c2f9 100644
--- a/core/api/src/main/java/org/onlab/onos/net/Host.java
+++ b/core/api/src/main/java/org/onlab/onos/net/Host.java
@@ -1,7 +1,8 @@
 package org.onlab.onos.net;
 
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
 import java.util.Set;
 
@@ -15,6 +16,7 @@
      *
      * @return host id
      */
+    @Override
     HostId id();
 
     /**
@@ -29,14 +31,14 @@
      *
      * @return VLAN ID value
      */
-    short vlan();
+    VLANID vlan();
 
     /**
      * Returns set of IP addresses currently bound to the host MAC address.
      *
      * @return set of IP addresses; empty if no IP address is bound
      */
-    Set<IPv4> ipAddresses();
+    Set<IPAddress> ipAddresses();
 
     /**
      * Returns the most recent host location where the host attaches to the
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java b/core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java
index c3653e6..ea68b53 100644
--- a/core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java
+++ b/core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java
@@ -6,24 +6,25 @@
 import java.util.Set;
 
 import org.onlab.onos.net.HostLocation;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
 import com.google.common.collect.ImmutableSet;
 
 public class DefaultHostDescription implements HostDescription {
 
     private final MACAddress mac;
-    private final short vlan;
+    private final VLANID vlan;
     private final HostLocation location;
-    private final Set<IPv4> ips;
+    private final Set<IPAddress> ips;
 
-    public DefaultHostDescription(MACAddress mac, short vlan,
-            HostLocation loc, Set<IPv4> ips) {
+    public DefaultHostDescription(MACAddress mac, VLANID vlan,
+            HostLocation loc, Set<IPAddress> ips) {
         this.mac = mac;
         this.vlan = vlan;
         this.location = loc;
-        this.ips = new HashSet<IPv4>(ips);
+        this.ips = new HashSet<IPAddress>(ips);
     }
 
     @Override
@@ -32,7 +33,7 @@
     }
 
     @Override
-    public short vlan() {
+    public VLANID vlan() {
         return vlan;
     }
 
@@ -42,7 +43,7 @@
     }
 
     @Override
-    public Set<IPv4> ipAddresses() {
+    public Set<IPAddress> ipAddresses() {
         return ImmutableSet.copyOf(ips);
     }
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java b/core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java
index 62a4c9a..313a403 100644
--- a/core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java
@@ -4,8 +4,9 @@
 
 import org.onlab.onos.net.Description;
 import org.onlab.onos.net.HostLocation;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
 /**
  * Information describing host and its location.
@@ -24,7 +25,7 @@
      *
      * @return the VLAN ID value
      */
-    short vlan();
+    VLANID vlan();
 
     /**
      * Returns the location of the host on the network edge.
@@ -38,6 +39,6 @@
      *
      * @return a set of IP addresses.
      */
-    Set<IPv4> ipAddresses();
+    Set<IPAddress> ipAddresses();
 
 }
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostService.java b/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
index 9ffa58a..1a94471 100644
--- a/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
@@ -4,8 +4,9 @@
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.Host;
 import org.onlab.onos.net.HostId;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
 import java.util.Set;
 
@@ -43,7 +44,7 @@
      * @return set of hosts in the given vlan id
      */
     // FIXME: change long to VLanId
-    Set<Host> getHostsByVlan(long vlanId);
+    Set<Host> getHostsByVlan(VLANID vlanId);
 
     /**
      * Returns the set of hosts that have the specified MAC address.
@@ -59,7 +60,7 @@
      * @param ip ip address
      * @return set of hosts with the given IP
      */
-    Set<Host> getHostsByIp(IPv4 ip);
+    Set<Host> getHostsByIp(IPAddress ip);
 
     /**
      * Returns the set of hosts whose most recent location is the specified
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
index daa3ddf..3032ac9 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
@@ -21,8 +21,9 @@
 import org.onlab.onos.net.host.HostService;
 import org.onlab.onos.net.provider.AbstractProviderRegistry;
 import org.onlab.onos.net.provider.AbstractProviderService;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 import org.slf4j.Logger;
 
 import java.util.Set;
@@ -85,7 +86,7 @@
     }
 
     @Override
-    public Set<Host> getHostsByVlan(long vlanId) {
+    public Set<Host> getHostsByVlan(VLANID vlanId) {
         return store.getHosts(vlanId);
     }
 
@@ -96,7 +97,7 @@
     }
 
     @Override
-    public Set<Host> getHostsByIp(IPv4 ip) {
+    public Set<Host> getHostsByIp(IPAddress ip) {
         checkNotNull(ip, "IP address cannot be null");
         return store.getHosts(ip);
     }
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
index a26107d..2f9eb29 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
@@ -19,8 +19,9 @@
 import org.onlab.onos.net.host.HostDescription;
 import org.onlab.onos.net.host.HostEvent;
 import org.onlab.onos.net.provider.ProviderId;
-import org.onlab.packet.IPv4;
+import org.onlab.packet.IPAddress;
 import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableSet;
@@ -149,10 +150,10 @@
      * @param vlanId vlan id
      * @return set of hosts in the vlan
      */
-    Set<Host> getHosts(long vlanId) {
+    Set<Host> getHosts(VLANID vlanId) {
         Set<Host> vlanset = new HashSet<Host>();
         for (Host h : hosts.values()) {
-            if (h.vlan() == vlanId) {
+            if (h.vlan().equals(vlanId)) {
                 vlanset.add(h);
             }
         }
@@ -181,7 +182,7 @@
      * @param ip ip address
      * @return set of hosts with the given IP
      */
-    Set<Host> getHosts(IPv4 ip) {
+    Set<Host> getHosts(IPAddress ip) {
         Set<Host> ipset = new HashSet<>();
         for (Host h : hosts.values()) {
             if (h.ipAddresses().contains(ip)) {
diff --git a/utils/misc/src/main/java/org/onlab/packet/IPAddress.java b/utils/misc/src/main/java/org/onlab/packet/IPAddress.java
new file mode 100644
index 0000000..f7b19dc
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/IPAddress.java
@@ -0,0 +1,132 @@
+package org.onlab.packet;
+
+import java.util.Arrays;
+
+/**
+ * A class representing an IPv4 address.
+ */
+public class IPAddress {
+
+    //IP Versions
+    public enum Version { INET, INET6 };
+
+    //lengths of address, in bytes
+    public static final int INET_LEN = 4;
+    public static final int INET6_LEN = 6;
+
+    protected Version version;
+    //does it make more sense to have a integral address?
+    protected byte[] octets;
+
+    protected IPAddress(Version ver, byte[] octets) {
+        this.version = ver;
+        this.octets = Arrays.copyOf(octets, INET_LEN);
+    }
+
+    /**
+     * Converts a byte array into an IP address.
+     *
+     * @param address a byte array
+     * @return an IP address
+     */
+    public static IPAddress valueOf(byte [] address) {
+        return new IPAddress(Version.INET, address);
+    }
+
+    /**
+     * Converts an integer into an IPv4 address.
+     *
+     * @param address an integer representing an IP value
+     * @return an IP address
+     */
+    public static IPAddress valueOf(int address) {
+        byte [] bytes = new byte [] {
+                (byte) ((address >> 24) & 0xff),
+                (byte) ((address >> 16) & 0xff),
+                (byte) ((address >> 8) & 0xff),
+                (byte) ((address >> 0) & 0xff)
+        };
+        return new IPAddress(Version.INET, bytes);
+    }
+
+    /**
+     * Converts a string in dotted-decimal notation (x.x.x.x) into
+     * an IPv4 address.
+     *
+     * @param address a string representing an IP address, e.g. "10.0.0.1"
+     * @return an IP address
+     */
+    public static IPAddress valueOf(String address) {
+        final String [] parts = address.split(".");
+        if (parts.length != INET_LEN) {
+            throw new IllegalArgumentException("Malformed IP address string; "
+                    + "Addres must have four decimal values separated by dots (.)");
+        }
+        final byte [] bytes = new byte[INET_LEN];
+        for (int i = 0; i < INET_LEN; i++) {
+            bytes[i] = Byte.parseByte(parts[i], 10);
+        }
+        return new IPAddress(Version.INET, bytes);
+    }
+
+    /**
+     * Returns the IP version of this address.
+     *
+     * @return the version
+     */
+    public Version version() {
+        return this.version;
+    }
+
+    /**
+     * Returns the IP address as a byte array.
+     *
+     * @return a byte array
+     */
+    public byte [] toOctets() {
+        return Arrays.copyOf(this.octets, INET_LEN);
+    }
+
+    public int toInt() {
+        int address =
+                ((octets[0] << 24) |
+                (octets[1] << 16) |
+                (octets[2] << 8) |
+                (octets[3] << 0));
+        return address;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder();
+        for (final byte b : this.octets) {
+            if (builder.length() > 0) {
+                builder.append(".");
+            }
+            builder.append(String.format("%02d", b));
+        }
+        return builder.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        return octets.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof IPAddress) {
+            IPAddress other = (IPAddress) obj;
+            if (!(this.version.equals(other.version))) {
+                return false;
+            }
+            if (!(Arrays.equals(this.octets, other.octets))) {
+                return false;
+            }
+        }
+        return true;
+    }
+}
diff --git a/utils/misc/src/main/java/org/onlab/packet/VLANID.java b/utils/misc/src/main/java/org/onlab/packet/VLANID.java
new file mode 100644
index 0000000..68774e3
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/VLANID.java
@@ -0,0 +1,41 @@
+package org.onlab.packet;
+
+/**
+ * Representation of a VLAN ID.
+ */
+public class VLANID {
+    // A VLAN ID is 12 bits, short is close
+    private final short value;
+
+    public VLANID(short value) {
+        this.value = value;
+    }
+
+    public short toShort() {
+        return this.value;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof VLANID) {
+            return true;
+        }
+
+        VLANID other = (VLANID) obj;
+        if (this.value == other.value) {
+            return true;
+        }
+
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return this.value;
+    }
+}
+