Skip to content
Snippets Groups Projects
Commit 8a912034 authored by Kanzhe Jiang's avatar Kanzhe Jiang
Browse files

Add per-port broadcast cache hit counter

parent 3268d90f
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment