Gather topology element info to TopologyImpl
- Moved all the self-contained topology elements (*Event) to
TopologyImpl. (ONOS-1651)
Now {Switch, Port, Link, Host}Impl is just a handler attached to
TopologyImpl.
- BugFix: TopologyManager.addHost(HostEvent)
HostEvent could be pushed to reorder queue multiple times,
if multiple attachment point was given.
- BugFix: TopologyManager.{addLink, removePort}
Properly handle if Host attachment point was removed as side-effect.
- BugFix: Copy HostEvent#lastSeenTime
- BugFix: Event instance notified to listeners (api*Events) should be
the event which was/will be in the replica. (TopologyManager)
- Added/Modified debug log in TopologyManager so that log will be in
same format for each event type.
"{Added, Update, Removed} <Self-contained>"
- Removed backdoor method and use TestUtils instead.
Change-Id: If053d6f11f39574a188e7a52cb6194114f8afe5d
diff --git a/src/main/java/net/onrc/onos/core/topology/HostImpl.java b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
index 469d335..d0964a1 100644
--- a/src/main/java/net/onrc/onos/core/topology/HostImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
@@ -9,50 +9,29 @@
import net.onrc.onos.core.util.SwitchPort;
/**
- * Host Object stored in In-memory Topology.
+ * Handler to Host object stored in In-memory Topology snapshot.
+ * <p/>
*/
public class HostImpl extends TopologyObject implements Host {
- //////////////////////////////////////////////////////
- /// Topology element attributes
- /// - any changes made here needs to be replicated.
- //////////////////////////////////////////////////////
- private HostEvent deviceObj;
+ private final MACAddress id;
/**
- * Creates a Host object based on {@link HostEvent}.
- *
- * @param topology Topology instance this object belongs to
- * @param scHost self contained {@link HostEvent}
- */
- public HostImpl(Topology topology, HostEvent scHost) {
- super(topology);
- Validate.notNull(scHost);
-
- // TODO should we assume deviceObj is already frozen before this call
- // or expect attribute update will happen after .
- if (scHost.isFrozen()) {
- this.deviceObj = scHost;
- } else {
- this.deviceObj = new HostEvent(scHost);
- this.deviceObj.freeze();
- }
- }
-
- /**
- * Creates a Host object with empty attributes.
+ * Creates a Host handler object.
*
* @param topology Topology instance this object belongs to
* @param mac MAC address of the host
*/
- public HostImpl(Topology topology, MACAddress mac) {
- this(topology, new HostEvent(mac).freeze());
+ HostImpl(TopologyInternal topology, MACAddress mac) {
+ super(topology);
+ Validate.notNull(mac);
+ this.id = mac;
}
@Override
public MACAddress getMacAddress() {
- return this.deviceObj.getMac();
+ return id;
}
@Override
@@ -60,7 +39,7 @@
List<Port> ports = new ArrayList<>();
topology.acquireReadLock();
try {
- for (SwitchPort swp : this.deviceObj.getAttachmentPoints()) {
+ for (SwitchPort swp : getHostEvent().getAttachmentPoints()) {
Port p = this.topology.getPort(swp);
if (p != null) {
ports.add(p);
@@ -74,7 +53,7 @@
@Override
public long getLastSeenTime() {
- return deviceObj.getLastSeenTime();
+ return this.topology.getHostEvent(id).getLastSeenTime();
}
@Override
@@ -82,45 +61,16 @@
return getMacAddress().toString();
}
- // TODO we may no longer need this. confirm and delete later.
- void setLastSeenTime(long lastSeenTime) {
- // XXX Following will make this instance thread unsafe. Need to use AtomicRef.
- HostEvent updated = new HostEvent(this.deviceObj);
- updated.setLastSeenTime(lastSeenTime);
- updated.freeze();
- this.deviceObj = updated;
- }
-
/**
- * Only {@link TopologyManager} should use this method.
+ * Gets the current HostEvent.
*
- * @param port the port that the device is attached to
+ * @return HostEvent
*/
- void addAttachmentPoint(Port port) {
- // XXX Following will make this instance thread unsafe. Need to use AtomicRef.
- HostEvent updated = new HostEvent(this.deviceObj);
- updated.removeAttachmentPoint(port.asSwitchPort());
- updated.addAttachmentPoint(port.asSwitchPort());
- updated.freeze();
- this.deviceObj = updated;
+ private HostEvent getHostEvent() {
+ return this.topology.getHostEvent(id);
}
/**
- * Only {@link TopologyManager} should use this method.
- *
- * @param port the port that the device is attached to
- */
- boolean removeAttachmentPoint(Port port) {
- // XXX Following will make this instance thread unsafe. Need to use AtomicRef.
- HostEvent updated = new HostEvent(this.deviceObj);
- final boolean result = updated.removeAttachmentPoint(port.asSwitchPort());
- updated.freeze();
- this.deviceObj = updated;
- return result;
- }
-
-
- /**
* Returns the type of topology object.
*
* @return the type of the topology object