package org.opendaylight.controller.hosttracker.internal;
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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;
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.
* @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
*/
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()]);
}
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;
+ }
}
/**
*/
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;
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;
* any change to the list of attachment points for the device -- which
* indicates a device move.
*
- * @param sw
* @param port
* @param lastSeen
* @return
}
// XXX - Missing functionality
- // long id = topology.getL2DomainId(sw);
long id = 0;
AttachmentPoint oldAP = apMap.get(id);
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
// 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;
/**
* Delete (sw,port) from the list of list of attachment points and oldAPs.
*
- * @param sw
* @param port
* @return
*/
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()]);
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();
if (!isFirst)
builder.append(", ");
isFirst = false;
- // builder.append(IPv4.fromIPv4Address(ip));
builder.append(ip);
}
builder.append("], APs=");