Extend host structures to store multiple locations

Also update host location format in CLI and REST API

Change-Id: I0fbd655f642627dd3eb8a2925f83a3ee016fe4aa
diff --git a/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java b/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java
index 5f9cfd8..c2531f6 100644
--- a/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java
@@ -16,6 +16,8 @@
 package org.onosproject.net.host;
 
 import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
 import java.util.Set;
 
 import org.onosproject.net.AbstractDescription;
@@ -38,7 +40,7 @@
 
     private final MacAddress mac;
     private final VlanId vlan;
-    private final HostLocation location;
+    private final Set<HostLocation> locations;
     private final Set<IpAddress> ip;
     private final boolean configured;
 
@@ -53,8 +55,7 @@
     public DefaultHostDescription(MacAddress mac, VlanId vlan,
                                   HostLocation location,
                                   SparseAnnotations... annotations) {
-        this(mac, vlan, location, Collections.emptySet(),
-             annotations);
+        this(mac, vlan, location, Collections.emptySet(), annotations);
     }
 
     /**
@@ -100,8 +101,7 @@
                                   HostLocation location,
                                   boolean configured,
                                   SparseAnnotations... annotations) {
-        this(mac, vlan, location, Collections.<IpAddress>emptySet(),
-             configured, annotations);
+        this(mac, vlan, location, Collections.emptySet(), configured, annotations);
     }
 
     /**
@@ -118,11 +118,28 @@
                                   HostLocation location, Set<IpAddress> ip,
                                   boolean configured,
                                   SparseAnnotations... annotations) {
+        this(mac, vlan, Collections.singleton(location), ip, configured, annotations);
+    }
+
+    /**
+     * Creates a host description using the supplied information.
+     *
+     * @param mac          host MAC address
+     * @param vlan         host VLAN identifier
+     * @param locations    host locations
+     * @param ip           host IP address
+     * @param configured   true if configured via NetworkConfiguration
+     * @param annotations  optional key/value annotations map
+     */
+    public DefaultHostDescription(MacAddress mac, VlanId vlan,
+                                  Set<HostLocation> locations,
+                                  Set<IpAddress> ip, boolean configured,
+                                  SparseAnnotations... annotations) {
         super(annotations);
         this.mac = mac;
         this.vlan = vlan;
-        this.location = location;
-        this.ip = ImmutableSet.copyOf(ip);
+        this.locations = new HashSet<>(locations);
+        this.ip = new HashSet<>(ip);
         this.configured = configured;
     }
 
@@ -138,7 +155,14 @@
 
     @Override
     public HostLocation location() {
-        return location;
+        return locations.stream()
+                .sorted(Comparator.comparingLong(HostLocation::time).reversed())
+                .findFirst().orElse(null);
+    }
+
+    @Override
+    public Set<HostLocation> locations() {
+        return locations;
     }
 
     @Override
@@ -156,7 +180,7 @@
         return toStringHelper(this)
                 .add("mac", mac)
                 .add("vlan", vlan)
-                .add("location", location)
+                .add("locations", locations)
                 .add("ipAddress", ip)
                 .add("configured", configured)
                 .toString();
@@ -164,7 +188,7 @@
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(super.hashCode(), mac, vlan, location, ip);
+        return Objects.hashCode(super.hashCode(), mac, vlan, locations, ip);
     }
 
     @Override
@@ -176,7 +200,7 @@
             DefaultHostDescription that = (DefaultHostDescription) object;
             return Objects.equal(this.mac, that.mac)
                     && Objects.equal(this.vlan, that.vlan)
-                    && Objects.equal(this.location, that.location)
+                    && Objects.equal(this.locations, that.locations)
                     && Objects.equal(this.ip, that.ip);
         }
         return false;