Work toward ONOS-1451: Separate Event Key space per instance

Final step in the implementation:
Implement the Topology Event filtering and processing logic
inside class TopologyEventPreprocessor:
  - The topology events from each ONOS instance are kept separately
    within class OnosInstanceLastAddEvents
  - We keep only the last copy of the ADD events (not removed yet
    by REMOVE events).
  - If ADD MastershipEvent is received, all previously
    stored ADD Topology events for the corresponding Switch DPID are
    applied to the Topology
  - If there were previously reordered events, we attempt to
    add them again along with the other events.
  - Before adding the events to the Topology, the events are
    aggregated (squashed), and reordered in their natural order to
    build a Topology. E.g., the ADD events order is:
    MastershipEvent, SwitchEvent, PortEvent, LinkEvent, HostEvent.
    The REMOVE events are in the reverse order.
    Also, the REMOVE events are processed before the ADD events.
  - If an event cannot be added to the topology, it is added
    back to the collection of reordered events.

Also, replaced some of the Collection<> with List<> in some of the
event-related API to indicate that there is a semantic ordering
of the events.

NOTE: Some of the internals of TopologyEventPreprocessor should be optimized
for speed. E.g., we should create an additional lookup map:
    Dpid -> Collection<TopologyEvent>
and then method getPostponedEvents() doesn't need to traverse all
topologyEvents entries.

Change-Id: Ic0d9ebf242f015adb60817921b239bb65dd560e2
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
index 4ea9e31..23471ff 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
@@ -4,6 +4,7 @@
 import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 
+import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.OnosInstanceId;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -169,6 +170,40 @@
     }
 
     /**
+     * Gets the event origin DPID.
+     *
+     * @return the event origin DPID.
+     */
+    public Dpid getOriginDpid() {
+        if (mastershipEvent != null) {
+            return mastershipEvent.getOriginDpid();
+        }
+        if (switchEvent != null) {
+            return switchEvent.getOriginDpid();
+        }
+        if (portEvent != null) {
+            return portEvent.getOriginDpid();
+        }
+        if (linkEvent != null) {
+            return linkEvent.getOriginDpid();
+        }
+        if (hostEvent != null) {
+            return hostEvent.getOriginDpid();
+        }
+        return null;
+    }
+
+    /**
+     * Tests whether the event origin DPID equals the specified DPID.
+     *
+     * @param dpid the DPID to compare against.
+     * @return true if the event origin Dpid equals the specified DPID.
+     */
+    public boolean equalsOriginDpid(Dpid dpid) {
+        return dpid.equals(getOriginDpid());
+    }
+
+    /**
      * Checks if all events contained are equal.
      *
      * @param obj TopologyEvent to compare against