Fix dhcp6Relay

- interfaceIdOption does not proper encode vlanId
- AddHost was not using the actual vlan of the host

Change-Id: I41a639cc4f7efc0c7159f5bab07166d4032fc60a
diff --git a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
index afe05f0..a912614 100644
--- a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
+++ b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
@@ -859,11 +859,23 @@
      * @param embeddedDhcp6 the dhcp6 payload within relay
      * @param srcMac client gw/host macAddress
      * @param clientInterface client interface
+     * @param vlanIdInUse vlanid encoded in the interface id Option
      */
     private void addHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Relay,
-                                DHCP6 embeddedDhcp6, MacAddress srcMac, Interface clientInterface) {
+                                DHCP6 embeddedDhcp6, MacAddress srcMac, Interface clientInterface,
+                                VlanId vlanIdInUse) {
         log.debug("addHostOrRoute entered.");
-        VlanId vlanId = clientInterface.vlan();
+        VlanId vlanId;
+        if (clientInterface.vlanTagged().isEmpty()) {
+            vlanId = clientInterface.vlan();
+        } else {
+            // might be multiple vlan in same interface
+            vlanId = vlanIdInUse;
+        }
+        if (vlanId == null) {
+            vlanId = VlanId.NONE;
+        }
+
         Boolean isMsgReply = Dhcp6HandlerUtil.isDhcp6Reply(dhcp6Relay);
         MacAddress leafClientMac;
         Byte leafMsgType;
@@ -1315,7 +1327,7 @@
         if (hostOrRouteAllowed) {
             // add host or route
             addHostOrRoute(directConnFlag, clientConnectionPoint, dhcp6Relay, embeddedDhcp6,
-                    clientMac, clientInterface);
+                    clientMac, clientInterface, vlanIdInUse);
         }
 
         udpPacket.setPayload(embeddedDhcp6);
diff --git a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
index 45e94c0..8936cc6 100644
--- a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
+++ b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
@@ -452,8 +452,8 @@
         byte[] clientSoureMacBytes = clientPacket.getSourceMACAddress();
         byte[] inPortStringBytes = inPortString.getBytes();
         byte[] vlanIdBytes = new byte[2];
-        vlanIdBytes[0] = (byte) (clientPacket.getVlanID() & 0xff);
-        vlanIdBytes[1] = (byte) ((clientPacket.getVlanID() >> 8) & 0xff);
+        vlanIdBytes[0] = (byte) ((clientPacket.getVlanID() >> 8) & 0xff);
+        vlanIdBytes[1] = (byte) (clientPacket.getVlanID() & 0xff);
         byte[] interfaceIdBytes = new byte[clientSoureMacBytes.length +
                 inPortStringBytes.length + vlanIdBytes.length];
         log.debug("Length: interfaceIdBytes  {} clientSoureMacBytes {} inPortStringBytes {} vlan {}",
@@ -468,8 +468,8 @@
                 vlanIdBytes.length);
         interfaceId.setData(interfaceIdBytes);
         interfaceId.setLength((short) interfaceIdBytes.length);
-        log.debug("interfaceId write srcMac {} portString {}",
-                HexString.toHexString(clientSoureMacBytes, ":"), inPortString);
+        log.debug("interfaceId write srcMac {} portString {}, vlanId {}",
+                HexString.toHexString(clientSoureMacBytes, ":"), inPortString, vlanIdBytes);
         return interfaceId;
     }