net.floodlightcontroller.counter
Class CounterStore

java.lang.Object
  extended by net.floodlightcontroller.counter.CounterStore
All Implemented Interfaces:
IFloodlightModule, IFloodlightService, ICounterStoreService

public class CounterStore
extends java.lang.Object
implements IFloodlightModule, ICounterStoreService

Implements a central store for system counters. These counters include overall packet-in, packet-out, and flow-mod counters. Additional packet-in counters are maintained for bcast/unicast/multicast traffic, as well as counters for traffic types based on ethertype and ip-proto (maintained on a per switch and controller level). These counters are maintained without the involvement of any other module in the system. For per-module counters and other detailed debug services, consider IDebugCounterService.


Nested Class Summary
protected  class CounterStore.CounterEntry
           
protected  class CounterStore.CounterKeyTuple
           
protected  class CounterStore.MutableInt
           
static class CounterStore.NetworkLayer
           
 
Field Summary
protected static java.util.Map<CounterStore.NetworkLayer,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> layeredCategories
          Counter Categories grouped by network layers NetworkLayer -> CounterToCategories
protected static org.slf4j.Logger log
           
protected  java.util.concurrent.ConcurrentHashMap<java.lang.String,CounterStore.CounterEntry> nameToCEIndex
          A cache of counterName --> Counter used to retrieve counters quickly via string-counter-keys
protected  java.lang.ThreadLocal<java.util.Map<CounterStore.CounterKeyTuple,CounterStore.MutableInt>> pktin_local_buffer
          Thread local counter stores
protected  java.util.concurrent.ConcurrentHashMap<CounterStore.CounterKeyTuple,java.util.List<ICounter>> pktinCounters
          Counter storage across all threads.
protected  java.lang.ThreadLocal<java.util.Map<CounterStore.CounterKeyTuple,CounterStore.MutableInt>> pktout_local_buffer
           
protected  java.util.concurrent.ConcurrentHashMap<CounterStore.CounterKeyTuple,java.util.List<ICounter>> pktoutCounters
           
 
Fields inherited from interface net.floodlightcontroller.counter.ICounterStoreService
BROADCAST, CONTROLLER_NAME, L3ET_IPV4, MULTICAST, TitleDelimitor, UNICAST
 
Constructor Summary
CounterStore()
           
 
Method Summary
 ICounter createCounter(java.lang.String key, CounterValue.CounterType type)
          Create a new ICounter and set the title.
static java.lang.String createCounterName(java.lang.String switchID, int portID, java.lang.String counterName)
          Create a title based on switch ID, portID, vlanID, and counterName If portID is -1, the title represents the given switch only If portID is a non-negative number, the title represents the port on the given switch
protected static java.lang.String createCounterName(java.lang.String switchID, int portID, java.lang.String counterName, java.lang.String subCategory, CounterStore.NetworkLayer layer)
          Create a title based on switch ID, portID, vlanID, counterName, and subCategory If portID is -1, the title represents the given switch only If portID is a non-negative number, the title represents the port on the given switch For example: PacketIns can be further categorized based on L2 etherType or L3 protocol
protected  java.util.List<ICounter> createPacketInCounters(IOFSwitch sw, OFMessage m, Ethernet eth)
           
 java.util.Map<java.lang.String,ICounter> getAll()
          Returns an immutable map of title:counter with all of the counters in the store.
 java.util.List<java.lang.String> getAllCategories(java.lang.String counterName, CounterStore.NetworkLayer layer)
          Retrieve a list of subCategories by counterName.
 ICounter getCounter(java.lang.String key)
          Retrieves a counter with the given title, or null if none can be found.
protected  CounterStore.CounterKeyTuple getCountersKey(IOFSwitch sw, OFMessage m, Ethernet eth)
           
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
          Get a list of Modules that this module depends on.
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
          Return the list of interfaces that this module implements.
protected  java.util.List<ICounter> getPktOutFMCounters(IOFSwitch sw, OFMessage m)
           
 java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
          Instantiate (as needed) and return objects that implement each of the services exported by this module.
 void init(FloodlightModuleContext context)
          This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.
 void startUp(FloodlightModuleContext context)
          This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.
 void updateFlush()
          Flush Local Counter Updates
 void updatePacketInCountersLocal(IOFSwitch sw, OFMessage m, Ethernet eth)
          Update packetIn counters
 void updatePktOutFMCounterStoreLocal(IOFSwitch sw, OFMessage m)
          This method can only be used to update packetOut and flowmod counters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.slf4j.Logger log

pktinCounters

protected java.util.concurrent.ConcurrentHashMap<CounterStore.CounterKeyTuple,java.util.List<ICounter>> pktinCounters
Counter storage across all threads. These are periodically updated from the local per thread counters by the updateFlush method.


pktoutCounters

protected java.util.concurrent.ConcurrentHashMap<CounterStore.CounterKeyTuple,java.util.List<ICounter>> pktoutCounters

pktin_local_buffer

protected final java.lang.ThreadLocal<java.util.Map<CounterStore.CounterKeyTuple,CounterStore.MutableInt>> pktin_local_buffer
Thread local counter stores


pktout_local_buffer

protected final java.lang.ThreadLocal<java.util.Map<CounterStore.CounterKeyTuple,CounterStore.MutableInt>> pktout_local_buffer

nameToCEIndex

protected java.util.concurrent.ConcurrentHashMap<java.lang.String,CounterStore.CounterEntry> nameToCEIndex
A cache of counterName --> Counter used to retrieve counters quickly via string-counter-keys


layeredCategories

protected static java.util.Map<CounterStore.NetworkLayer,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> layeredCategories
Counter Categories grouped by network layers NetworkLayer -> CounterToCategories

Constructor Detail

CounterStore

public CounterStore()
Method Detail

updatePacketInCountersLocal

public void updatePacketInCountersLocal(IOFSwitch sw,
                                        OFMessage m,
                                        Ethernet eth)
Description copied from interface: ICounterStoreService
Update packetIn counters

Specified by:
updatePacketInCountersLocal in interface ICounterStoreService

updatePktOutFMCounterStoreLocal

public void updatePktOutFMCounterStoreLocal(IOFSwitch sw,
                                            OFMessage m)
Description copied from interface: ICounterStoreService
This method can only be used to update packetOut and flowmod counters

Specified by:
updatePktOutFMCounterStoreLocal in interface ICounterStoreService

updateFlush

public void updateFlush()
Description copied from interface: ICounterStoreService
Flush Local Counter Updates

Specified by:
updateFlush in interface ICounterStoreService

createCounter

public ICounter createCounter(java.lang.String key,
                              CounterValue.CounterType type)
Description copied from interface: ICounterStoreService
Create a new ICounter and set the title. Note that the title must be unique, otherwise this will throw an IllegalArgumentException.

Specified by:
createCounter in interface ICounterStoreService
Returns:

getCounter

public ICounter getCounter(java.lang.String key)
Description copied from interface: ICounterStoreService
Retrieves a counter with the given title, or null if none can be found.

Specified by:
getCounter in interface ICounterStoreService

getAll

public java.util.Map<java.lang.String,ICounter> getAll()
Description copied from interface: ICounterStoreService
Returns an immutable map of title:counter with all of the counters in the store. (Note - this method may be slow - primarily for debugging/UI)

Specified by:
getAll in interface ICounterStoreService

getAllCategories

public java.util.List<java.lang.String> getAllCategories(java.lang.String counterName,
                                                         CounterStore.NetworkLayer layer)
Description copied from interface: ICounterStoreService
Retrieve a list of subCategories by counterName. null if nothing.

Specified by:
getAllCategories in interface ICounterStoreService

createCounterName

public static java.lang.String createCounterName(java.lang.String switchID,
                                                 int portID,
                                                 java.lang.String counterName)
Create a title based on switch ID, portID, vlanID, and counterName If portID is -1, the title represents the given switch only If portID is a non-negative number, the title represents the port on the given switch


getCountersKey

protected CounterStore.CounterKeyTuple getCountersKey(IOFSwitch sw,
                                                      OFMessage m,
                                                      Ethernet eth)

createPacketInCounters

protected java.util.List<ICounter> createPacketInCounters(IOFSwitch sw,
                                                          OFMessage m,
                                                          Ethernet eth)

getPktOutFMCounters

protected java.util.List<ICounter> getPktOutFMCounters(IOFSwitch sw,
                                                       OFMessage m)

createCounterName

protected static java.lang.String createCounterName(java.lang.String switchID,
                                                    int portID,
                                                    java.lang.String counterName,
                                                    java.lang.String subCategory,
                                                    CounterStore.NetworkLayer layer)
Create a title based on switch ID, portID, vlanID, counterName, and subCategory If portID is -1, the title represents the given switch only If portID is a non-negative number, the title represents the port on the given switch For example: PacketIns can be further categorized based on L2 etherType or L3 protocol


getModuleServices

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
Description copied from interface: IFloodlightModule
Return the list of interfaces that this module implements. All interfaces must inherit IFloodlightService

Specified by:
getModuleServices in interface IFloodlightModule
Returns:

getServiceImpls

public java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
Description copied from interface: IFloodlightModule
Instantiate (as needed) and return objects that implement each of the services exported by this module. The map returned maps the implemented service to the object. The object could be the same object or different objects for different exported services.

Specified by:
getServiceImpls in interface IFloodlightModule
Returns:
The map from service interface class to service implementation

getModuleDependencies

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
Description copied from interface: IFloodlightModule
Get a list of Modules that this module depends on. The module system will ensure that each these dependencies is resolved before the subsequent calls to init().

Specified by:
getModuleDependencies in interface IFloodlightModule
Returns:
The Collection of IFloodlightServices that this module depends on.

init

public void init(FloodlightModuleContext context)
          throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.

Specified by:
init in interface IFloodlightModule
Throws:
FloodlightModuleException

startUp

public void startUp(FloodlightModuleContext context)
Description copied from interface: IFloodlightModule
This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.

Specified by:
startUp in interface IFloodlightModule