Fix for IOFSwitch/OFSwitchImpl leak
- Fix for ONOS-1765
- OFSwitchImpl.java
Changes TLS bufffer map to WeakHashMap to eliminate buffer for
eliminated switches.
- OFMessageDamper.java
Added a hack to remove cached entries related to disconnected switch
- TimedCache.java
Backdoor acccess to manually invalidate cached entries
- FlowProgrammer.java
Propagate removeSwitch event
FlowPusher -> OFMessageDamper to invalidate cache.
- FlowPusher.java
Switched `assignedQueues` to concurrent version of WeakHashMap
- PlanInstallRuntime.java
Changed FlowModCount map to WeakHashMap and removed
strong reference to IOFSwitch
Change-Id: Idb5014379ebc5658d0ae58ebcdbb2bf03e981df7
diff --git a/src/main/java/net/onrc/onos/core/flowprogrammer/FlowPusher.java b/src/main/java/net/onrc/onos/core/flowprogrammer/FlowPusher.java
index 98c2f97..37e1b44 100644
--- a/src/main/java/net/onrc/onos/core/flowprogrammer/FlowPusher.java
+++ b/src/main/java/net/onrc/onos/core/flowprogrammer/FlowPusher.java
@@ -70,6 +70,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.cache.CacheBuilder;
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
@@ -299,8 +301,11 @@
* Main thread that reads messages from queues and sends them to switches.
*/
private class FlowPusherThread extends Thread {
+ // Weak ConncurrentHashMap
private Map<IOFSwitch, SwitchQueue> assignedQueues
- = new ConcurrentHashMap<IOFSwitch, SwitchQueue>();
+ = CacheBuilder.newBuilder()
+ .weakKeys()
+ .<IOFSwitch, SwitchQueue>build().asMap();
final Lock queuingLock = new ReentrantLock();
final Condition messagePushed = queuingLock.newCondition();
@@ -612,6 +617,17 @@
}
}
+ /**
+ * Invalidate.
+ *
+ * @param sw switch
+ *
+ * @see OFMessageDamper#invalidate(IOFSwitch)
+ */
+ public void invalidate(IOFSwitch sw) {
+ messageDamper.invalidate(sw);
+ }
+
@Override
public boolean add(IOFSwitch sw, OFMessage msg) {
return add(sw, msg, MsgPriority.NORMAL);