net.floodlightcontroller.devicemanager.internal
Class DefaultEntityClassifier

java.lang.Object
  extended by net.floodlightcontroller.devicemanager.internal.DefaultEntityClassifier
All Implemented Interfaces:
IFloodlightModule, IFloodlightService, IEntityClassifierService

public class DefaultEntityClassifier
extends java.lang.Object
implements IEntityClassifierService, IFloodlightModule

This is a default entity classifier that simply classifies all entities into a fixed entity class, with key fields of MAC and VLAN.

Author:
readams

Nested Class Summary
protected static class DefaultEntityClassifier.DefaultEntityClass
          A default fixed entity class
 
Field Summary
protected static DefaultEntityClassifier.DefaultEntityClass entityClass
           
protected static java.util.EnumSet<IDeviceService.DeviceField> keyFields
           
 
Constructor Summary
DefaultEntityClassifier()
           
 
Method Summary
 void addListener(IEntityClassListener listener)
          Adds a listener to listen for IEntityClassifierServices notifications
 IEntityClass classifyEntity(Entity entity)
          Classify the given entity into an IEntityClass.
 void deviceUpdate(IDevice oldDevice, java.util.Collection<? extends IDevice> newDevices)
          Once reclassification is complete for a device, this method will be called.
 java.util.EnumSet<IDeviceService.DeviceField> getKeyFields()
          Return the most general list of fields that should be used as key fields.
 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.
 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.
 IEntityClass reclassifyEntity(IDevice curDevice, Entity entity)
          Reclassify the given entity into a class.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyFields

protected static java.util.EnumSet<IDeviceService.DeviceField> keyFields

entityClass

protected static DefaultEntityClassifier.DefaultEntityClass entityClass
Constructor Detail

DefaultEntityClassifier

public DefaultEntityClassifier()
Method Detail

classifyEntity

public IEntityClass classifyEntity(Entity entity)
Description copied from interface: IEntityClassifierService
Classify the given entity into an IEntityClass. It is important that the key fields returned by IEntityClassifierService.getKeyFields() be sufficient for classifying entities. That is, if two entities are identical except for a field that is not a key field, they must be assigned the same class. Furthermore, entity classification must be transitive: For all entities x, y, z, if x and y belong to a class c, and y and z belong class c, then x and z must belong to class c.

Specified by:
classifyEntity in interface IEntityClassifierService
Parameters:
entity - the entity to classify
Returns:
the IEntityClass resulting from the classification.
See Also:
IEntityClassifierService.getKeyFields()

reclassifyEntity

public IEntityClass reclassifyEntity(IDevice curDevice,
                                     Entity entity)
Description copied from interface: IEntityClassifierService
Reclassify the given entity into a class. When reclassifying entities, it can be helpful to take into account the current classification either as an optimization or to allow flushing any cached state tied to the key for that device. The entity will be assigned to a new device with a new object if the entity class returned is different from the entity class for curDevice.

Note that you must take steps to ensure you always return classes in some consistent ordering.

Specified by:
reclassifyEntity in interface IEntityClassifierService
Parameters:
curDevice - the device currently associated with the entity
entity - the entity to reclassify
Returns:
the IEntityClass resulting from the classification

deviceUpdate

public void deviceUpdate(IDevice oldDevice,
                         java.util.Collection<? extends IDevice> newDevices)
Description copied from interface: IEntityClassifierService
Once reclassification is complete for a device, this method will be called. If any entities within the device changed their classification, it will split into one or more new devices for each of the entities. If two devices are merged because of a reclassification, then this will be called on each of the devices, with the same device in the newDevices collection.

Specified by:
deviceUpdate in interface IEntityClassifierService
Parameters:
oldDevice - the original device object
newDevices - all the new devices derived from the entities of the old device. If null, the old device was unchanged.

getKeyFields

public java.util.EnumSet<IDeviceService.DeviceField> getKeyFields()
Description copied from interface: IEntityClassifierService
Return the most general list of fields that should be used as key fields. If devices differ in any fields not listed here, they can never be considered a different device by any IEntityClass returned by IEntityClassifierService.classifyEntity(net.floodlightcontroller.devicemanager.internal.Entity). The key fields for an entity classifier must not change unless associated with a flush of all entity state. The list of key fields must be the union of all key fields that could be returned by IEntityClass.getKeyFields().

Specified by:
getKeyFields in interface IEntityClassifierService
Returns:
a set containing the fields that should not be wildcarded. May be null to indicate that all fields are key fields.
See Also:
IEntityClass#getKeyFields()}, IEntityClassifierService#classifyEntity}

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

addListener

public void addListener(IEntityClassListener listener)
Description copied from interface: IEntityClassifierService
Adds a listener to listen for IEntityClassifierServices notifications

Specified by:
addListener in interface IEntityClassifierService
Parameters:
listener - The listener that wants the notifications