Add string attributes to self-containd objects.
- Add common super class to *Event classes, which handles attributes.
- Add string attributes to *Event classes (ONOS-1564)
- Populate string attributes.
Picked random attribute obtained from OF, just to initially populate attrs.
Attributes to be used for each elements should be revisited later.
- *Impl class to use/reference self-contained objects
prep-work for snapshot in mind.
- unified equals implementations
- Add unfrozen Copy constructor.
- Add freeze check to fixed attributes.
- Remove get*Impl which was not really adding value.
Change-Id: I10f9538f87d133a22237bd8ab97b8de421d3930b
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index 140e4c7..d73f80f 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -1,34 +1,65 @@
package net.onrc.onos.core.topology;
import java.nio.ByteBuffer;
+import java.util.Objects;
import net.onrc.onos.core.topology.web.serializers.LinkEventSerializer;
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.PortNumber;
import net.onrc.onos.core.util.SwitchPort;
+import org.apache.commons.lang.Validate;
import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
* Self-contained Link event Object.
* <p/>
- * TODO: We probably want common base class/interface for Self-Contained Event Object.
+ * TODO: Rename to match what it is. (Switch/Port/Link/Device)Snapshot?
+ * FIXME: Current implementation directly use this object as
+ * Replication message, but should be sending update operation info.
*/
@JsonSerialize(using = LinkEventSerializer.class)
-public class LinkEvent {
- protected final SwitchPort src;
- protected final SwitchPort dst;
+public class LinkEvent extends TopologyElement<LinkEvent> {
+
+ private final SwitchPort src;
+ private final SwitchPort dst;
+ // TODO add LastSeenTime, Capacity if appropriate
/**
* Default constructor for Serializer to use.
*/
@Deprecated
- public LinkEvent() {
+ protected LinkEvent() {
src = null;
dst = null;
}
+ /**
+ * Creates the Link object.
+ *
+ * @param src source SwitchPort
+ * @param dst destination SwitchPort
+ */
+ public LinkEvent(SwitchPort src, SwitchPort dst) {
+ Validate.notNull(src);
+ Validate.notNull(dst);
+
+ this.src = src;
+ this.dst = dst;
+ }
+
+ /**
+ * Create an unfrozen copy of given Object.
+ *
+ * @param original to make copy of.
+ */
+ public LinkEvent(LinkEvent original) {
+ super(original);
+ this.src = original.src;
+ this.dst = original.dst;
+ }
+
public LinkEvent(Long srcDpid, Long srcPortNo, Long dstDpid,
Long dstPortNo) {
src = new SwitchPort(srcDpid, srcPortNo);
@@ -42,16 +73,34 @@
link.getDstPort().getNumber());
}
+ /**
+ * Creates the Link object.
+ *
+ * @param srcDpid source switch DPID
+ * @param srcPortNo source port number
+ * @param dstDpid destination switch DPID
+ * @param dstPortNo destination port number
+ */
public LinkEvent(Dpid srcDpid, PortNumber srcPortNo,
Dpid dstDpid, PortNumber dstPortNo) {
src = new SwitchPort(srcDpid, srcPortNo);
dst = new SwitchPort(dstDpid, dstPortNo);
}
+ /**
+ * Gets the source SwitchPort.
+ *
+ * @return source SwitchPort.
+ */
public SwitchPort getSrc() {
return src;
}
+ /**
+ * Gets the destination SwitchPort.
+ *
+ * @return destination SwitchPort.
+ */
public SwitchPort getDst() {
return dst;
}
@@ -71,7 +120,8 @@
public static ByteBuffer getLinkID(Long srcDpid, Long srcPortNo,
Long dstDpid, Long dstPortNo) {
- return (ByteBuffer) ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
+ return (ByteBuffer) ByteBuffer.allocate(LinkEvent.LINKID_BYTES)
+ .putChar('L')
.put(PortEvent.getPortID(srcDpid, srcPortNo))
.put(PortEvent.getPortID(dstDpid, dstPortNo)).flip();
}
@@ -88,7 +138,7 @@
@Override
public int hashCode() {
final int prime = 31;
- int result = 1;
+ int result = super.hashCode();
result = prime * result + ((dst == null) ? 0 : dst.hashCode());
result = prime * result + ((src == null) ? 0 : src.hashCode());
return result;
@@ -99,27 +149,22 @@
if (this == obj) {
return true;
}
+
if (obj == null) {
return false;
}
+
if (getClass() != obj.getClass()) {
return false;
}
LinkEvent other = (LinkEvent) obj;
- if (dst == null) {
- if (other.dst != null) {
- return false;
- }
- } else if (!dst.equals(other.dst)) {
+
+ // compare attributes
+ if (!super.equals(obj)) {
return false;
}
- if (src == null) {
- if (other.src != null) {
- return false;
- }
- } else if (!src.equals(other.src)) {
- return false;
- }
- return true;
+
+ return Objects.equals(this.src, other.src) &&
+ Objects.equals(this.dst, other.dst);
}
}