diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index 5c6b7b62d111069d8e2c7653a310b60f45ad25e5..d3781cb584116745ac33a16592df14108cb1c433 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -300,10 +300,16 @@ public interface IOFSwitch { public void clearAllFlowMods(); /** - * Return a TimedHashMap associated with the switch + * Update broadcast cache * @param data + * @return true if there is a cache hit + * false if there is no cache hit. + */ + public boolean updateBroadcastCache(Long entry, Short port); + + /** + * Get the portBroadcastCacheHits * @return */ - public TimedCache<Long> getTimedCache(); - + public Map<Short, Long> getPortBroadcastHits(); } diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index f623b2b21b4d499028a5013de22f16ccc37f1d73..96016b09dbab1e668d7c4c06de08d28424a78591 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -74,6 +74,7 @@ public class OFSwitchImpl implements IOFSwitch { protected Map<Integer,OFStatisticsFuture> statsFutureMap; protected boolean connected; protected TimedCache<Long> timedCache; + protected ConcurrentMap<Short, Long> portBroadcastCacheHitMap; protected ReentrantReadWriteLock lock; public static IOFSwitchFeatures switchFeatures; @@ -90,6 +91,7 @@ public class OFSwitchImpl implements IOFSwitch { this.connected = true; this.statsFutureMap = new ConcurrentHashMap<Integer,OFStatisticsFuture>(); this.timedCache = new TimedCache<Long>(100, 5*1000 ); // 5 seconds interval + this.portBroadcastCacheHitMap = new ConcurrentHashMap<Short, Long>(); this.lock = new ReentrantReadWriteLock(); // Defaults properties for an ideal switch @@ -361,10 +363,23 @@ public class OFSwitchImpl implements IOFSwitch { } @Override - public TimedCache<Long> getTimedCache() { - return timedCache; + public boolean updateBroadcastCache(Long entry, Short port) { + if (timedCache.update(entry)) { + Long count = portBroadcastCacheHitMap.putIfAbsent(port, new Long(1)); + if (count != null) { + count++; + } + return true; + } else { + return false; + } } + @Override + public Map<Short, Long> getPortBroadcastHits() { + return this.portBroadcastCacheHitMap; + } + /** * Return a lock that need to be held while processing a message. Multiple threads * can hold this lock.