BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / hosttracker_new / api / src / main / java / org / opendaylight / controller / hosttracker / Entity.java
index 7c98e9505b28b1b51098a9d9c9c3e29ab9af6a2c..64f4c7ef1e1d65bddcafd7310dccfe6b44278741 100644 (file)
 
 package org.opendaylight.controller.hosttracker;
 
+import java.net.InetAddress;
 import java.util.Date;
 
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.utils.NetUtils;
 
 /**
  * An entity on the network is a visible trace of a device that corresponds to a
@@ -218,6 +221,19 @@ public class Entity implements Comparable<Entity> {
         return true;
     }
 
+    public HostNodeConnector toHostNodeConnector() {
+        try {
+            NodeConnector n = this.getPort();
+            InetAddress ip = InetAddress.getByAddress(NetUtils.intToByteArray4(this.getIpv4Address()));
+            byte[] macAddr = NetUtils.longToByteArray6(this.getMacAddress());
+            HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n,
+                    (short) 0);
+            return nc;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
     @Override
     public String toString() {
         return "Entity [macAddress=" + macAddress + ", ipv4Address="
@@ -228,10 +244,12 @@ public class Entity implements Comparable<Entity> {
     @Override
     public int compareTo(Entity o) {
         int r;
-        if (port == null)
+        if (port == null) {
             r = o.port == null ? 0 : -1;
-        else if (o.port == null)
+        }
+        else if (o.port == null) {
             r = 1;
+        }
         else {
             // XXX - the node id is only defined as an object rather
             // than something useful. We're just going to have to