Removed the ipAddress and activeSince fields from OnosDevice.
We decided that the Device class would be a simple mapping between attachment port and MAC address. IP information is stored separately so there is no more use for the ipAddress field.
I don't know what the activeSince field was doing. We never use it - we only use the lastSeenTimestamp timestamp.
Change-Id: I252d564358f619d7b26fcbeb2ad9c8bc274f864d
diff --git a/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java b/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
index 796129a..17ce3b9 100644
--- a/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
+++ b/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
@@ -1,5 +1,5 @@
/**
- l* Copyright 2011,2012, Big Switch Networks, Inc.
+ * Copyright 2011,2012, Big Switch Networks, Inc.
* Originally created by David Erickson, Stanford University
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -21,7 +21,6 @@
import java.util.Date;
import net.floodlightcontroller.util.MACAddress;
-import net.onrc.onos.core.packet.IPv4;
/**
* An entity on the network is a visible trace of a device that corresponds
@@ -36,9 +35,9 @@
*
* @author readams
*/
-public class OnosDevice implements Serializable { //implements Comparable<OnosDevice> {
+public class OnosDevice implements Serializable {
- private static final int ACTIVITY_TIMEOUT = 30000;
+ private static final long serialVersionUID = 1L;
/**
* The MAC address associated with this entity.
@@ -46,12 +45,6 @@
private MACAddress macAddress;
/**
- * The IP address associated with this entity, or null if no IP learned
- * from the network observation associated with this entity.
- */
- private Integer ipv4Address;
-
- /**
* The VLAN tag on this entity, or null if untagged.
*/
private Short vlan;
@@ -73,8 +66,6 @@
*/
private Date lastSeenTimestamp;
- private Date activeSince;
-
private int hashCode = 0;
// ************
@@ -93,20 +84,16 @@
* @param switchPort
* @param lastSeenTimestamp
*/
- public OnosDevice(MACAddress macAddress, Short vlan,
- Integer ipv4Address, Long switchDPID, short switchPort,
- Date lastSeenTimestamp) {
+ public OnosDevice(MACAddress macAddress, Short vlan, Long switchDPID,
+ short switchPort, Date lastSeenTimestamp) {
this.macAddress = macAddress;
- this.ipv4Address = ipv4Address;
this.vlan = vlan;
this.switchDPID = switchDPID;
this.switchPort = switchPort;
if (lastSeenTimestamp != null) {
this.lastSeenTimestamp = new Date(lastSeenTimestamp.getTime());
- this.activeSince = new Date(lastSeenTimestamp.getTime());
} else {
this.lastSeenTimestamp = null;
- this.activeSince = null;
}
}
@@ -118,14 +105,6 @@
return macAddress;
}
- public Integer getIpv4Address() {
- return ipv4Address;
- }
-
- public void setIpv4Address(Integer ipv4Address) {
- this.ipv4Address = ipv4Address;
- }
-
public Short getVlan() {
return vlan;
}
@@ -154,22 +133,9 @@
}
public void setLastSeenTimestamp(Date lastSeenTimestamp) {
- if (activeSince == null ||
- (activeSince.getTime() + ACTIVITY_TIMEOUT) <
- lastSeenTimestamp.getTime()) {
- this.activeSince = new Date(lastSeenTimestamp.getTime());
- }
this.lastSeenTimestamp = new Date(lastSeenTimestamp.getTime());
}
- public Date getActiveSince() {
- return new Date(this.activeSince.getTime());
- }
-
- public void setActiveSince(Date activeSince) {
- this.activeSince = new Date(activeSince.getTime());
- }
-
@Override
public int hashCode() {
if (hashCode != 0) {
@@ -177,8 +143,6 @@
}
final int prime = 31;
hashCode = 1;
- hashCode = prime * hashCode
- + ((ipv4Address == null) ? 0 : ipv4Address.hashCode());
hashCode = prime * hashCode + (int) (macAddress.toLong() ^ (macAddress.toLong() >>> 32));
hashCode = prime * hashCode + (int) switchDPID;
hashCode = prime * hashCode + (int) switchPort;
@@ -201,13 +165,6 @@
if (hashCode() != other.hashCode()) {
return false;
}
- if (ipv4Address == null) {
- if (other.ipv4Address != null) {
- return false;
- }
- } else if (!ipv4Address.equals(other.ipv4Address)) {
- return false;
- }
if (macAddress == null) {
if (other.macAddress != null) {
return false;
@@ -236,9 +193,6 @@
StringBuilder builder = new StringBuilder();
builder.append("Entity [macAddress=");
builder.append(macAddress.toString());
- builder.append(", ipv4Address=");
- builder.append(IPv4.fromIPv4Address(ipv4Address == null ?
- 0 : ipv4Address.intValue()));
builder.append(", vlan=");
builder.append(vlan);
builder.append(", switchDPID=");
@@ -247,52 +201,7 @@
builder.append(switchPort);
builder.append(", lastSeenTimestamp=");
builder.append(lastSeenTimestamp == null ? "null" : lastSeenTimestamp.getTime());
- builder.append(", activeSince=");
- builder.append(activeSince == null ? "null" : activeSince.getTime());
builder.append("]");
return builder.toString();
}
-
- /*
- @Override
- public int compareTo(OnosDevice o) {
- if (macAddress < o.macAddress) return -1;
- if (macAddress > o.macAddress) return 1;
-
- int r;
- if (switchDPID == null)
- r = o.switchDPID == null ? 0 : -1;
- else if (o.switchDPID == null)
- r = 1;
- else
- r = switchDPID.compareTo(o.switchDPID);
- if (r != 0) return r;
-
- if (switchPort == null)
- r = o.switchPort == null ? 0 : -1;
- else if (o.switchPort == null)
- r = 1;
- else
- r = switchPort.compareTo(o.switchPort);
- if (r != 0) return r;
-
- if (ipv4Address == null)
- r = o.ipv4Address == null ? 0 : -1;
- else if (o.ipv4Address == null)
- r = 1;
- else
- r = ipv4Address.compareTo(o.ipv4Address);
- if (r != 0) return r;
-
- if (vlan == null)
- r = o.vlan == null ? 0 : -1;
- else if (o.vlan == null)
- r = 1;
- else
- r = vlan.compareTo(o.vlan);
- if (r != 0) return r;
-
- return 0;
- }*/
-
}
diff --git a/src/main/java/net/onrc/onos/core/devicemanager/OnosDeviceManager.java b/src/main/java/net/onrc/onos/core/devicemanager/OnosDeviceManager.java
index 2f56682..e6c7d83 100644
--- a/src/main/java/net/onrc/onos/core/devicemanager/OnosDeviceManager.java
+++ b/src/main/java/net/onrc/onos/core/devicemanager/OnosDeviceManager.java
@@ -27,11 +27,7 @@
import net.onrc.onos.core.datagrid.IDatagridService;
import net.onrc.onos.core.datagrid.IEventChannel;
import net.onrc.onos.core.datagrid.IEventChannelListener;
-import net.onrc.onos.core.packet.ARP;
-import net.onrc.onos.core.packet.DHCP;
import net.onrc.onos.core.packet.Ethernet;
-import net.onrc.onos.core.packet.IPv4;
-import net.onrc.onos.core.packet.UDP;
import net.onrc.onos.core.topology.ITopologyService;
import net.onrc.onos.core.topology.Topology;
@@ -139,30 +135,15 @@
//We check if it is the same device in datagrid to suppress the device update
OnosDevice exDev = mapDevice.get(mac);
- if (exDev != null) {
- if (exDev.equals(srcDevice)) {
- //There is the same existing device. Update only ActiveSince time.
- exDev.setLastSeenTimestamp(new Date());
- if (log.isTraceEnabled()) {
- log.trace("In the local cache, there is the same device."
- + "Only update last seen time: dpid {}, port {}, mac {}, ip {}, lastSeenTime {}",
- dpid, portId, srcDevice.getMacAddress(), srcDevice.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime());
- }
- return Command.CONTINUE;
- } else if (srcDevice.getIpv4Address() == null &&
- exDev.getSwitchDPID().equals(srcDevice.getSwitchDPID()) &&
- exDev.getSwitchPort() == srcDevice.getSwitchPort()) {
- //Vlan should be handled based on the Onos spec. Until then, don't handle it.
- //Device attachment point and mac address are the same
- //but the packet does not have an ip address.
- exDev.setLastSeenTimestamp(new Date());
- if (log.isTraceEnabled()) {
- log.trace("In the local cache, there is the same mac device and got no ip addr packet-in."
- + "Only update last seen time. dpid {}, port {}, mac {}, ip {} lastSeenTime {}",
- dpid, portId, srcDevice.getMacAddress(), exDev.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime());
- }
- return Command.CONTINUE;
+ if (exDev != null && exDev.equals(srcDevice)) {
+ //There is the same existing device. Update only ActiveSince time.
+ exDev.setLastSeenTimestamp(new Date());
+ if (log.isTraceEnabled()) {
+ log.trace("In the local cache, there is the same device."
+ + "Only update last seen time: dpid {}, port {}, mac {}, lastSeenTime {}",
+ dpid, portId, srcDevice.getMacAddress(), srcDevice.getLastSeenTimestamp().getTime());
}
+ return Command.CONTINUE;
}
//If the switch port we try to attach a new device already has a link, then stop adding device
@@ -177,8 +158,8 @@
addOnosDevice(mac, srcDevice);
if (log.isTraceEnabled()) {
- log.trace("Add device info: dpid {}, port {}, mac {}, ip {}, lastSeenTime {}",
- dpid, portId, srcDevice.getMacAddress(), srcDevice.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime());
+ log.trace("Add device info: dpid {}, port {}, mac {}, lastSeenTime {}",
+ dpid, portId, srcDevice.getMacAddress(), srcDevice.getLastSeenTimestamp().getTime());
}
return Command.CONTINUE;
}
@@ -195,8 +176,8 @@
long now = new Date().getTime();
if ((now - dev.getLastSeenTimestamp().getTime() > agingMillisecConfig)) {
if (log.isTraceEnabled()) {
- log.debug("Remove device info in the datagrid: dpid {}, port {}, mac {}, ip {}, lastSeenTime {}, diff {}",
- dev.getSwitchDPID(), dev.getSwitchPort(), dev.getMacAddress(), dev.getIpv4Address(),
+ log.debug("Remove device info in the datagrid: dpid {}, port {}, mac {}, lastSeenTime {}, diff {}",
+ dev.getSwitchDPID(), dev.getSwitchPort(), dev.getMacAddress(),
dev.getLastSeenTimestamp().getTime(), now - dev.getLastSeenTimestamp().getTime());
}
deleteSet.add(dev);
@@ -213,36 +194,6 @@
}
/**
- * Get IP address from packet if the packet is either an ARP
- * or a DHCP packet.
- *
- * @param eth
- * @param dlAddr
- * @return
- */
- private int getSrcNwAddr(Ethernet eth, long dlAddr) {
- if (eth.getPayload() instanceof ARP) {
- ARP arp = (ARP) eth.getPayload();
- if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) &&
- (Ethernet.toLong(arp.getSenderHardwareAddress()) == dlAddr)) {
- return IPv4.toIPv4Address(arp.getSenderProtocolAddress());
- }
- } else if (eth.getPayload() instanceof IPv4) {
- IPv4 ipv4 = (IPv4) eth.getPayload();
- if (ipv4.getPayload() instanceof UDP) {
- UDP udp = (UDP) ipv4.getPayload();
- if (udp.getPayload() instanceof DHCP) {
- DHCP dhcp = (DHCP) udp.getPayload();
- if (dhcp.getOpCode() == DHCP.OPCODE_REPLY) {
- return ipv4.getSourceAddress();
- }
- }
- }
- }
- return 0;
- }
-
- /**
* Parse an entity from an {@link Ethernet} packet.
*
* @param eth the packet to parse
@@ -253,7 +204,6 @@
protected OnosDevice getSourceDeviceFromPacket(Ethernet eth,
long swdpid,
short port) {
- long dlAddr = Ethernet.toLong(eth.getSourceMACAddress());
MACAddress sourceMac = eth.getSourceMAC();
// Ignore broadcast/multicast source
@@ -262,10 +212,8 @@
}
short vlan = eth.getVlanID();
- int nwSrc = getSrcNwAddr(eth, dlAddr);
return new OnosDevice(sourceMac,
((vlan >= 0) ? vlan : null),
- ((nwSrc != 0) ? nwSrc : null),
swdpid,
port,
new Date());