Supported recently introduced fields in HostsWebResource

Change-Id: I3bc3fd272008388326041540c10e8a103b01c02c
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
index 34e13ca..6bdd483 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
@@ -18,6 +18,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.packet.EthType;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.VlanId;
@@ -69,7 +70,8 @@
     @Context
     private UriInfo uriInfo;
     private static final String HOST_NOT_FOUND = "Host is not found";
-    private static final String[] REMOVAL_KEYS = {"mac", "vlan", "locations", "ipAddresses"};
+    private static final String[] REMOVAL_KEYS = {"mac", "vlan", "locations", "ipAddresses",
+            "auxLocations", "innerVlan", "outerTpid"};
 
     /**
      * Get all end-station hosts.
@@ -222,10 +224,10 @@
             MacAddress mac = MacAddress.valueOf(node.get("mac").asText());
             VlanId vlanId = VlanId.vlanId((short) node.get("vlan").asInt(VlanId.UNTAGGED));
 
+            // Parse locations
             if (null == node.get("locations")) {
                 throw new IllegalArgumentException("location isn't specified");
             }
-
             Iterator<JsonNode> locationNodes = node.get("locations").elements();
             Set<HostLocation> locations = new HashSet<>();
             while (locationNodes.hasNext()) {
@@ -236,22 +238,49 @@
                 locations.add(hostLocation);
             }
 
+            // Parse ipAddresses
             if (null == node.get("ipAddresses")) {
                 throw new IllegalArgumentException("ipAddress isn't specified");
             }
-
             Iterator<JsonNode> ipNodes = node.get("ipAddresses").elements();
             Set<IpAddress> ips = new HashSet<>();
             while (ipNodes.hasNext()) {
                 ips.add(IpAddress.valueOf(ipNodes.next().asText()));
             }
 
+            // Parse auxLocations
+            Set<HostLocation> auxLocations;
+            JsonNode auxLocationsNode = node.get("auxLocations");
+            if (null == auxLocationsNode) {
+                auxLocations = null;
+            } else {
+                Iterator<JsonNode> auxLocationNodes = auxLocationsNode.elements();
+                auxLocations = new HashSet<>();
+                while (auxLocationNodes.hasNext()) {
+                    JsonNode auxLocationNode = auxLocationNodes.next();
+                    String deviceAndPort = auxLocationNode.get("elementId").asText() + "/" +
+                            auxLocationNode.get("port").asText();
+                    HostLocation auxLocation = new HostLocation(ConnectPoint.deviceConnectPoint(deviceAndPort), 0);
+                    auxLocations.add(auxLocation);
+                }
+            }
+
+            // Parse innerVlan
+            JsonNode innerVlanNode = node.get("innerVlan");
+            VlanId innerVlan = (null == innerVlanNode) ? VlanId.NONE : VlanId.vlanId(innerVlanNode.asText());
+
+            // Parse outerTpid
+            JsonNode outerTpidNode = node.get("outerTpid");
+            EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() :
+                    EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType();
+
             // try to remove elements from json node after reading them
             SparseAnnotations annotations = annotations(removeElements(node, REMOVAL_KEYS));
             // Update host inventory
 
             HostId hostId = HostId.hostId(mac, vlanId);
-            DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, locations, ips, true, annotations);
+            DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, locations, auxLocations,
+                    ips, innerVlan, outerTpid, true, annotations);
             hostProviderService.hostDetected(hostId, desc, false);
             return hostId;
         }
diff --git a/web/api/src/main/resources/definitions/Host.json b/web/api/src/main/resources/definitions/Host.json
index b29e828..6bf6dd8 100644
--- a/web/api/src/main/resources/definitions/Host.json
+++ b/web/api/src/main/resources/definitions/Host.json
@@ -52,6 +52,36 @@
           }
         }
       }
+    },
+    "auxLocations": {
+      "required": false,
+      "type": "array",
+      "items": {
+        "type": "object",
+        "title": "location",
+        "required": [
+          "elementId",
+          "port"
+        ],
+        "properties": {
+          "elementId": {
+            "type": "string",
+            "example": "of:0000000000000003"
+          },
+          "port": {
+            "type": "string",
+            "example": "4"
+          }
+        }
+      }
+    },
+    "innerVlan": {
+      "type": "string",
+      "example": "-1"
+    },
+    "outerTpid": {
+      "type": "string",
+      "example": "unknown"
     }
   }
 }
\ No newline at end of file
diff --git a/web/api/src/main/resources/definitions/HostPut.json b/web/api/src/main/resources/definitions/HostPut.json
index 26e1c41..99f167b 100644
--- a/web/api/src/main/resources/definitions/HostPut.json
+++ b/web/api/src/main/resources/definitions/HostPut.json
@@ -47,6 +47,38 @@
           }
         }
       }
+    },
+    "auxLocations": {
+      "required": false,
+      "type": "array",
+      "items": {
+        "type": "object",
+        "title": "location",
+        "required": [
+          "elementId",
+          "port"
+        ],
+        "properties": {
+          "elementId": {
+            "type": "string",
+            "example": "of:0000000000000003"
+          },
+          "port": {
+            "type": "string",
+            "example": "4"
+          }
+        }
+      }
+    },
+    "innerVlan": {
+      "required": false,
+      "type": "string",
+      "example": "10"
+    },
+    "outerTpid": {
+      "required": false,
+      "type": "string",
+      "example": "0x88a8"
     }
   }
 }
\ No newline at end of file
diff --git a/web/api/src/main/resources/definitions/Hosts.json b/web/api/src/main/resources/definitions/Hosts.json
index 3615ba4..3a293fa 100644
--- a/web/api/src/main/resources/definitions/Hosts.json
+++ b/web/api/src/main/resources/definitions/Hosts.json
@@ -65,6 +65,36 @@
                 }
               }
             }
+          },
+          "auxLocations": {
+            "required": false,
+            "type": "array",
+            "items": {
+              "type": "object",
+              "title": "location",
+              "required": [
+                "elementId",
+                "port"
+              ],
+              "properties": {
+                "elementId": {
+                  "type": "string",
+                  "example": "of:0000000000000003"
+                },
+                "port": {
+                  "type": "string",
+                  "example": "4"
+                }
+              }
+            }
+          },
+          "innerVlan": {
+            "type": "string",
+            "example": "-1"
+          },
+          "outerTpid": {
+            "type": "string",
+            "example": "unknown"
           }
         }
       }