Fixed an issue that caused FlowPusher to go into an infinite loop.

FlowPusher used to use the IOFSwitch object as a key in its data structures.
When the IOFSwitchListener inteface changed to include only the DPID in its
callback methods instead of the IOFSwitch, the FlowPusher is now not able
to get a reference to the switch once it has disconnected. This means
FlowPusher can't clean out its data structures and it if messages are still
in the queue for the switch it will try and send them forever.

The fix is to change FlowPusher so its internal data structures use the DPID
as the key. While doing this I also changed most of its APIs so that they also
reference switches by DPID rather than by IOFSwitch.

Change-Id: I255d64fdac21d8b147f991ff41f6ecace310b116
diff --git a/src/main/java/net/onrc/onos/core/flowprogrammer/IFlowPusherService.java b/src/main/java/net/onrc/onos/core/flowprogrammer/IFlowPusherService.java
index 25162aa..1026855 100644
--- a/src/main/java/net/onrc/onos/core/flowprogrammer/IFlowPusherService.java
+++ b/src/main/java/net/onrc/onos/core/flowprogrammer/IFlowPusherService.java
@@ -2,10 +2,10 @@
 
 import java.util.Collection;
 
-import net.floodlightcontroller.core.IOFSwitch;
 import net.floodlightcontroller.core.internal.OFMessageFuture;
 import net.floodlightcontroller.core.module.IFloodlightService;
 import net.onrc.onos.core.intent.FlowEntry;
+import net.onrc.onos.core.util.Dpid;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.projectfloodlight.openflow.protocol.OFBarrierReply;
@@ -20,9 +20,9 @@
  */
 public interface IFlowPusherService extends IFloodlightService {
     public static enum MsgPriority {
-        HIGH,        // High priority: e.g. flow synchronization
+        HIGH,          // High priority: e.g. flow synchronization
         NORMAL,        // Normal priority
-//              LOW,            // Low priority, not needed for now
+        // LOW,        // Low priority, not needed for now
     }
 
     public static enum QueueState {
@@ -34,53 +34,53 @@
     /**
      * Create a queue correspondent to the switch.
      *
-     * @param sw Switch to which new queue is attached.
+     * @param dpid DPID of the switch to which new queue is attached.
      * @return true if new queue is successfully created.
      */
-    boolean createQueue(IOFSwitch sw);
+    boolean createQueue(Dpid dpid);
 
     /**
      * Delete a queue correspondent to the switch.
      * Messages remains in queue will be all sent before queue is deleted.
      *
-     * @param sw Switch of which queue is deleted.
+     * @param dpid DPID of the switch from which the queue is deleted.
      * @return true if queue is successfully deleted.
      */
-    boolean deleteQueue(IOFSwitch sw);
+    boolean deleteQueue(Dpid dpid);
 
     /**
      * Delete a queue correspondent to the switch.
      * By setting force flag on, queue will be deleted immediately.
      *
-     * @param sw        Switch of which queue is deleted.
+     * @param dpid      DPID of the switch from which the queue is deleted.
      * @param forceStop If this flag is set to true, queue will be deleted
      *                  immediately regardless of any messages in the queue.
      *                  If false, all messages will be sent to switch and queue will
      *                  be deleted after that.
      * @return true if queue is successfully deleted or flagged to be deleted.
      */
-    boolean deleteQueue(IOFSwitch sw, boolean forceStop);
+    boolean deleteQueue(Dpid dpid, boolean forceStop);
 
     /**
      * Add a message to the queue of the switch with normal priority.
      * <p/>
      * Note: Notification is NOT delivered for the pushed message.
      *
-     * @param sw  Switch to which message is pushed.
+     * @param dpid DPID of the switch to which the message is pushed.
      * @param msg Message object to be added.
      * @return true if message is successfully added to a queue.
      */
-    boolean add(IOFSwitch sw, OFMessage msg);
+    boolean add(Dpid dpid, OFMessage msg);
 
     /**
      * Add a message to the queue of the switch with specific priority.
      *
-     * @param sw       Switch to which message is pushed.
+     * @param dpid     DPID of the switch to which the message is pushed.
      * @param msg      Message object to be added.
      * @param priority Sending priority of the message.
      * @return true if message is successfully added to a queue.
      */
-    boolean add(IOFSwitch sw, OFMessage msg, MsgPriority priority);
+    boolean add(Dpid dpid, OFMessage msg, MsgPriority priority);
 
     /**
      * Push a collection of Flow Entries to the corresponding switches
@@ -89,10 +89,10 @@
      * Note: Notification is delivered for the Flow Entries that
      * are pushed successfully.
      *
-     * @param entries the collection of <IOFSwitch, FlowEntry> pairs
+     * @param entries the collection of <Dpid, FlowEntry> pairs
      *                to push.
      */
-    void pushFlowEntries(Collection<Pair<IOFSwitch, FlowEntry>> entries);
+    void pushFlowEntries(Collection<Pair<Dpid, FlowEntry>> entries);
 
     /**
      * Push a collection of Flow Entries to the corresponding switches
@@ -101,11 +101,11 @@
      * Note: Notification is delivered for the Flow Entries that
      * are pushed successfully.
      *
-     * @param entries  the collection of <IOFSwitch, FlowEntry> pairs
+     * @param entries  the collection of <Dpid, FlowEntry> pairs
      *                 to push.
      * @param priority Sending priority of flow entries.
      */
-    void pushFlowEntries(Collection<Pair<IOFSwitch, FlowEntry>> entries,
+    void pushFlowEntries(Collection<Pair<Dpid, FlowEntry>> entries,
                          MsgPriority priority);
 
     /**
@@ -115,10 +115,10 @@
      * Note: Notification is delivered for the Flow Entries that
      * are pushed successfully.
      *
-     * @param sw        Switch to which message is pushed.
+     * @param dpid      DPID of the switch to which the message is pushed.
      * @param flowEntry FlowEntry object used for creating message.
      */
-    void pushFlowEntry(IOFSwitch sw, FlowEntry flowEntry);
+    void pushFlowEntry(Dpid dpid, FlowEntry flowEntry);
 
     /**
      * Create a message from FlowEntry and add it to the queue of the
@@ -127,57 +127,61 @@
      * Note: Notification is delivered for the Flow Entries that
      * are pushed successfully.
      *
-     * @param sw        Switch to which message is pushed.
+     * @param dpid      DPID of the switch to which the message is pushed.
      * @param flowEntry FlowEntry object used for creating message.
+     * @param priority  Sending priority of flow entries.
      */
-    void pushFlowEntry(IOFSwitch sw, FlowEntry flowEntry,
+    void pushFlowEntry(Dpid dpid, FlowEntry flowEntry,
                        MsgPriority priority);
 
     /**
      * Set sending rate to a switch.
+     * <p/>
+     * TODO The rate limiter function currently does not work as we are unable
+     * to determine the size of the messages when using Loxi.
      *
-     * @param sw   Switch.
+     * @param dpid DPID of the switch to alter the sending rate of.
      * @param rate Rate in bytes/ms.
      */
-    public void setRate(IOFSwitch sw, long rate);
+    public void setRate(Dpid dpid, long rate);
 
     /**
      * Add BARRIER message to queue and wait for reply.
      *
-     * @param sw Switch to which barrier message is pushed.
+     * @param dpid DPID of the switch to which a barrier message is pushed.
      * @return BARRIER_REPLY message sent from switch.
      */
-    OFBarrierReply barrier(IOFSwitch sw);
+    OFBarrierReply barrier(Dpid dpid);
 
     /**
      * Add BARRIER message to queue asynchronously.
      *
-     * @param sw Switch to which barrier message is pushed.
+     * @param dpid DPID of the switch to which a barrier message is pushed.
      * @return Future object of BARRIER_REPLY message which will be sent from switch.
      */
-    OFMessageFuture<OFBarrierReply> barrierAsync(IOFSwitch sw);
+    OFMessageFuture<OFBarrierReply> barrierAsync(Dpid dpid);
 
     /**
      * Suspend pushing message to a switch.
      *
-     * @param sw Switch to be suspended pushing message.
+     * @param dpid DPID of the switch whose queue is to be suspended.
      * @return true if success
      */
-    boolean suspend(IOFSwitch sw);
+    boolean suspend(Dpid dpid);
 
     /**
      * Resume pushing message to a switch.
      *
-     * @param sw Switch to be resumed pushing message.
+     * @param dpid DPID of the switch whose queue is to be resumed.
      * @return true if success
      */
-    boolean resume(IOFSwitch sw);
+    boolean resume(Dpid dpid);
 
     /**
      * Get state of queue attached to a switch.
      *
-     * @param sw Switch to be checked.
+     * @param dpid DPID of the switch to be checked.
      * @return State of queue.
      */
-    QueueState getState(IOFSwitch sw);
+    QueueState getState(Dpid dpid);
 }