net.floodlightcontroller.learningswitch
Class LearningSwitch

java.lang.Object
  extended by net.floodlightcontroller.learningswitch.LearningSwitch
All Implemented Interfaces:
IListener<OFType>, IOFMessageListener, IFloodlightModule, IFloodlightService, ILearningSwitchService

public class LearningSwitch
extends java.lang.Object
implements IFloodlightModule, ILearningSwitchService, IOFMessageListener


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.core.IListener
IListener.Command
 
Field Summary
static int APP_ID_BITS
           
static int APP_ID_SHIFT
           
protected  ICounterStoreService counterStore
           
protected  IFloodlightProviderService floodlightProvider
           
protected static short FLOWMOD_DEFAULT_HARD_TIMEOUT
           
protected static short FLOWMOD_DEFAULT_IDLE_TIMEOUT
           
protected static short FLOWMOD_PRIORITY
           
static int LEARNING_SWITCH_APP_ID
           
static long LEARNING_SWITCH_COOKIE
           
protected static boolean LEARNING_SWITCH_REVERSE_FLOW
           
protected static org.slf4j.Logger log
           
protected  java.util.Map<IOFSwitch,java.util.Map<MacVlanPair,java.lang.Integer>> macVlanToSwitchPortMap
           
protected static int MAX_MACS_PER_SWITCH
           
protected  IRestApiService restApi
           
 
Constructor Summary
LearningSwitch()
           
 
Method Summary
protected  void addToPortMap(IOFSwitch sw, long mac, short vlan, int portVal)
          Adds a host to the MAC/VLAN->SwitchPort mapping
 void clearLearnedTable()
          Clears the MAC/VLAN -> SwitchPort map for all switches
 void clearLearnedTable(IOFSwitch sw)
          Clears the MAC/VLAN -> SwitchPort map for a single switch
 java.lang.Integer getFromPortMap(IOFSwitch sw, long mac, short vlan)
          Get the port that a MAC/VLAN pair is associated with
 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.lang.String getName()
          The name assigned to this listener
 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.
 java.util.Map<IOFSwitch,java.util.Map<MacVlanPair,java.lang.Integer>> getTable()
          Returns the LearningSwitch's learned host table
 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.
 boolean isCallbackOrderingPostreq(OFType type, java.lang.String name)
          Check if the module called name is a callback ordering post-requisite for this module.
 boolean isCallbackOrderingPrereq(OFType type, java.lang.String name)
          Check if the module called name is a callback ordering prerequisite for this module.
 IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx)
          This is the method Floodlight uses to call listeners with OpenFlow messages
protected  void removeFromPortMap(IOFSwitch sw, long mac, short vlan)
          Removes a host from the MAC/VLAN->SwitchPort mapping
 void setFloodlightProvider(IFloodlightProviderService floodlightProvider)
           
 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

log

protected static org.slf4j.Logger log

floodlightProvider

protected IFloodlightProviderService floodlightProvider

counterStore

protected ICounterStoreService counterStore

restApi

protected IRestApiService restApi

macVlanToSwitchPortMap

protected java.util.Map<IOFSwitch,java.util.Map<MacVlanPair,java.lang.Integer>> macVlanToSwitchPortMap

LEARNING_SWITCH_APP_ID

public static final int LEARNING_SWITCH_APP_ID
See Also:
Constant Field Values

APP_ID_BITS

public static final int APP_ID_BITS
See Also:
Constant Field Values

APP_ID_SHIFT

public static final int APP_ID_SHIFT
See Also:
Constant Field Values

LEARNING_SWITCH_COOKIE

public static final long LEARNING_SWITCH_COOKIE
See Also:
Constant Field Values

FLOWMOD_DEFAULT_IDLE_TIMEOUT

protected static short FLOWMOD_DEFAULT_IDLE_TIMEOUT

FLOWMOD_DEFAULT_HARD_TIMEOUT

protected static short FLOWMOD_DEFAULT_HARD_TIMEOUT

FLOWMOD_PRIORITY

protected static short FLOWMOD_PRIORITY

MAX_MACS_PER_SWITCH

protected static final int MAX_MACS_PER_SWITCH
See Also:
Constant Field Values

LEARNING_SWITCH_REVERSE_FLOW

protected static final boolean LEARNING_SWITCH_REVERSE_FLOW
See Also:
Constant Field Values
Constructor Detail

LearningSwitch

public LearningSwitch()
Method Detail

setFloodlightProvider

public void setFloodlightProvider(IFloodlightProviderService floodlightProvider)
Parameters:
floodlightProvider - the floodlightProvider to set

getName

public java.lang.String getName()
Description copied from interface: IListener
The name assigned to this listener

Specified by:
getName in interface IListener<OFType>
Returns:

addToPortMap

protected void addToPortMap(IOFSwitch sw,
                            long mac,
                            short vlan,
                            int portVal)
Adds a host to the MAC/VLAN->SwitchPort mapping

Parameters:
sw - The switch to add the mapping to
mac - The MAC address of the host to add
vlan - The VLAN that the host is on
portVal - The switchport that the host is on

removeFromPortMap

protected void removeFromPortMap(IOFSwitch sw,
                                 long mac,
                                 short vlan)
Removes a host from the MAC/VLAN->SwitchPort mapping

Parameters:
sw - The switch to remove the mapping from
mac - The MAC address of the host to remove
vlan - The VLAN that the host is on

getFromPortMap

public java.lang.Integer getFromPortMap(IOFSwitch sw,
                                        long mac,
                                        short vlan)
Get the port that a MAC/VLAN pair is associated with

Parameters:
sw - The switch to get the mapping from
mac - The MAC address to get
vlan - The VLAN number to get
Returns:
The port the host is on

clearLearnedTable

public void clearLearnedTable()
Clears the MAC/VLAN -> SwitchPort map for all switches


clearLearnedTable

public void clearLearnedTable(IOFSwitch sw)
Clears the MAC/VLAN -> SwitchPort map for a single switch

Parameters:
sw - The switch to clear the mapping for

getTable

public java.util.Map<IOFSwitch,java.util.Map<MacVlanPair,java.lang.Integer>> getTable()
Description copied from interface: ILearningSwitchService
Returns the LearningSwitch's learned host table

Specified by:
getTable in interface ILearningSwitchService
Returns:
The learned host table

receive

public IListener.Command receive(IOFSwitch sw,
                                 OFMessage msg,
                                 FloodlightContext cntx)
Description copied from interface: IOFMessageListener
This is the method Floodlight uses to call listeners with OpenFlow messages

Specified by:
receive in interface IOFMessageListener
Parameters:
sw - the OpenFlow switch that sent this message
msg - the message
cntx - a Floodlight message context object you can use to pass information between listeners
Returns:
the command to continue or stop the execution

isCallbackOrderingPrereq

public boolean isCallbackOrderingPrereq(OFType type,
                                        java.lang.String name)
Description copied from interface: IListener
Check if the module called name is a callback ordering prerequisite for this module. In other words, if this function returns true for the given name, then this listener will be called after that message listener.

Specified by:
isCallbackOrderingPrereq in interface IListener<OFType>
Parameters:
type - the object type to which this applies
name - the name of the module
Returns:
whether name is a prerequisite.

isCallbackOrderingPostreq

public boolean isCallbackOrderingPostreq(OFType type,
                                         java.lang.String name)
Description copied from interface: IListener
Check if the module called name is a callback ordering post-requisite for this module. In other words, if this function returns true for the given name, then this listener will be called before that message listener.

Specified by:
isCallbackOrderingPostreq in interface IListener<OFType>
Parameters:
type - the object type to which this applies
name - the name of the module
Returns:
whether name is a post-requisite.

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