Bug 1029: Remove dead code: samples/clustersession
[controller.git] / opendaylight / hosttracker_new / implementation / src / main / java / org / opendaylight / controller / hosttracker / internal / Device.java
index 90911fe152f13e8f0c820a00a495dc838da6afdc..8fcb988b6cd43a63530873c025a23d92cd2f067b 100755 (executable)
@@ -33,6 +33,7 @@
 
 package org.opendaylight.controller.hosttracker.internal;
 
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -51,6 +52,7 @@ import org.opendaylight.controller.hosttracker.IDeviceService.DeviceField;
 import org.opendaylight.controller.hosttracker.IEntityClass;
 import org.opendaylight.controller.hosttracker.SwitchPort;
 import org.opendaylight.controller.hosttracker.SwitchPort.ErrorStatus;
+import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.slf4j.Logger;
@@ -76,6 +78,8 @@ public class Device implements IDevice {
     protected final Short[] vlanIds;
     protected volatile String dhcpClientName;
 
+    private boolean staticHost;
+
     /**
      * These are the old attachment points for the device that were valid no
      * more than INACTIVITY_TIME ago.
@@ -177,7 +181,8 @@ public class Device implements IDevice {
      * @param newEntity
      *            the entity to add. newEntity must be have the same entity
      *            class as device
-     * @param if positive indicates the index in the entities array were the new
+     * @param insertionpoint
+     *        if positive indicates the index in the entities array were the new
      *        entity should be inserted. If negative we will compute the correct
      *        insertion point
      */
@@ -236,10 +241,11 @@ public class Device implements IDevice {
 
         TreeSet<Short> vals = new TreeSet<Short>();
         for (Entity e : entities) {
-            if (e.getVlan() == null)
+            if (e.getVlan() == null) {
                 vals.add((short) -1);
-            else
+            } else {
                 vals.add(e.getVlan());
+            }
         }
         return vals.toArray(new Short[vals.size()]);
     }
@@ -309,15 +315,16 @@ public class Device implements IDevice {
             return false;
 
         for (AttachmentPoint ap : apList) {
-            if (ap.getLastSeen() + AttachmentPoint.INACTIVITY_INTERVAL < System
-                    .currentTimeMillis())
-                expiredAPs.add(ap);
+            if (ap.getLastSeen() + AttachmentPoint.INACTIVITY_INTERVAL < System.currentTimeMillis()) {
+               expiredAPs.add(ap);
+            }
         }
         if (expiredAPs.size() > 0) {
             apList.removeAll(expiredAPs);
             return true;
-        } else
+        } else {
             return false;
+        }
     }
 
     /**
@@ -334,7 +341,6 @@ public class Device implements IDevice {
      */
     List<AttachmentPoint> getDuplicateAttachmentPoints(
             List<AttachmentPoint> oldAPList, Map<Long, AttachmentPoint> apMap) {
-        // ITopologyService topology = deviceManager.topology;
         List<AttachmentPoint> dupAPs = new ArrayList<AttachmentPoint>();
         long timeThreshold = System.currentTimeMillis()
                 - AttachmentPoint.INACTIVITY_INTERVAL;
@@ -343,17 +349,11 @@ public class Device implements IDevice {
             return dupAPs;
 
         for (AttachmentPoint ap : oldAPList) {
-            // XXX - Missing functionality
-            // long id = topology.getL2DomainId(ap.getSw());
             long id = 0;
             AttachmentPoint trueAP = apMap.get(id);
 
             if (trueAP == null)
                 continue;
-            // XXX - Missing functionality
-            // boolean c = (topology.isConsistent(trueAP.getSw(),
-            // trueAP.getPort(),
-            // ap.getSw(), ap.getPort()));
             boolean c = true;
             boolean active = (ap.getActiveSince() > trueAP.getActiveSince());
             boolean last = ap.getLastSeen() > timeThreshold;
@@ -406,7 +406,6 @@ public class Device implements IDevice {
      * any change to the list of attachment points for the device -- which
      * indicates a device move.
      *
-     * @param sw
      * @param port
      * @param lastSeen
      * @return
@@ -456,7 +455,6 @@ public class Device implements IDevice {
         }
 
         // XXX - Missing functionality
-        // long id = topology.getL2DomainId(sw);
         long id = 0;
         AttachmentPoint oldAP = apMap.get(id);
 
@@ -493,11 +491,6 @@ public class Device implements IDevice {
                 oldAPList.addAll(oldAPs);
             oldAPList.add(oldAP);
             this.oldAPs = oldAPList;
-            // XXX - Missing functionality
-            // if (!topology.isInSameBroadcastDomain(oldAP.getSw(),
-            // oldAP.getPort(),
-            // newAP.getSw(), newAP.getPort()))
-            // return true; // attachment point changed.
             return true;
         } else if (oldAPFlag) {
             // retain oldAP as is. Put the newAP in oldAPs for flagging
@@ -508,11 +501,6 @@ public class Device implements IDevice {
             // Add to oldAPList only if it was picked up from the oldAPList
             oldAPList.add(newAP);
             this.oldAPs = oldAPList;
-            // XXX - Missing functionality
-            // if (!topology.isInSameBroadcastDomain(oldAP.getSw(),
-            // oldAP.getPort(),
-            // newAP.getSw(), newAP.getPort()))
-            // return true; // attachment point changed.
             return true;
         }
         return false;
@@ -521,7 +509,6 @@ public class Device implements IDevice {
     /**
      * Delete (sw,port) from the list of list of attachment points and oldAPs.
      *
-     * @param sw
      * @param port
      * @return
      */
@@ -699,10 +686,12 @@ public class Device implements IDevice {
         TreeSet<Short> vals = new TreeSet<Short>();
         for (Entity e : entities) {
             if (e.getPort().equals(swp.getPort())) {
-                if (e.getVlan() == null)
+                if (e.getVlan() == null) {
                     vals.add(VLAN_UNTAGGED);
-                else
+                }
+                else  {
                     vals.add(e.getVlan());
+                }
             }
         }
         return vals.toArray(new Short[vals.size()]);
@@ -779,6 +768,41 @@ public class Device implements IDevice {
         return true;
     }
 
+    public HostNodeConnector toHostNodeConnector() {
+        Integer[] ipv4s = this.getIPv4Addresses();
+        try {
+            Entity e = this.entities[this.entities.length-1];
+            NodeConnector n = null;
+            if(e!=null)
+                 n = e.getPort();
+            InetAddress ip = InetAddress.getByName(ipv4s[ipv4s.length - 1]
+                    .toString());
+            byte[] macAddr = macLongToByte(this.getMACAddress());
+            HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n,
+                    (short) 0);
+            nc.setStaticHost(this.isStaticHost());
+            return nc;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private byte[] macLongToByte(long mac) {
+        byte[] macAddr = new byte[6];
+        for (int i = 0; i < 6; i++) {
+            macAddr[5 - i] = (byte) (mac >> (8 * i));
+        }
+        return macAddr;
+    }
+
+    public boolean isStaticHost(){
+        return this.staticHost;
+    }
+
+    public void setStaticHost(boolean isStatic){
+        this.staticHost = isStatic;
+    }
+
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
@@ -794,7 +818,6 @@ public class Device implements IDevice {
             if (!isFirst)
                 builder.append(", ");
             isFirst = false;
-            // builder.append(IPv4.fromIPv4Address(ip));
             builder.append(ip);
         }
         builder.append("], APs=");