net.floodlightcontroller.staticflowentry
Class StaticFlowEntryPusher

java.lang.Object
  extended by net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher
All Implemented Interfaces:
IListener<OFType>, IOFMessageListener, IOFSwitchListener, IFloodlightModule, IFloodlightService, IStaticFlowEntryPusherService, IStorageSourceListener

public class StaticFlowEntryPusher
extends java.lang.Object
implements IOFSwitchListener, IFloodlightModule, IStaticFlowEntryPusherService, IStorageSourceListener, IOFMessageListener


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.core.IListener
IListener.Command
 
Field Summary
static java.lang.String COLUMN_ACTIONS
           
static java.lang.String COLUMN_ACTIVE
           
static java.lang.String COLUMN_COOKIE
           
static java.lang.String COLUMN_DL_DST
           
static java.lang.String COLUMN_DL_SRC
           
static java.lang.String COLUMN_DL_TYPE
           
static java.lang.String COLUMN_DL_VLAN
           
static java.lang.String COLUMN_DL_VLAN_PCP
           
static java.lang.String COLUMN_HARD_TIMEOUT
           
static java.lang.String COLUMN_IDLE_TIMEOUT
           
static java.lang.String COLUMN_IN_PORT
           
static java.lang.String COLUMN_NAME
           
static java.lang.String COLUMN_NW_DST
           
static java.lang.String COLUMN_NW_PROTO
           
static java.lang.String COLUMN_NW_SRC
           
static java.lang.String COLUMN_NW_TOS
           
static java.lang.String COLUMN_PRIORITY
           
static java.lang.String COLUMN_SWITCH
           
static java.lang.String COLUMN_TP_DST
           
static java.lang.String COLUMN_TP_SRC
           
static java.lang.String COLUMN_WILDCARD
           
static java.lang.String[] ColumnNames
           
protected  java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> entriesFromStorage
           
protected  java.util.Map<java.lang.String,java.lang.String> entry2dpid
           
protected  IFloodlightProviderService floodlightProvider
           
protected static org.slf4j.Logger log
           
protected  IRestApiService restApi
           
static int STATIC_FLOW_APP_ID
           
static java.lang.String StaticFlowName
           
protected  IStorageSourceService storageSource
           
static java.lang.String TABLE_NAME
           
 
Constructor Summary
StaticFlowEntryPusher()
           
 
Method Summary
 void addFlow(java.lang.String name, OFFlowMod fm, java.lang.String swDpid)
          Adds a static flow.
protected  java.util.Map<java.lang.String,java.lang.String> computeEntry2DpidMap(java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> map)
          Used only for bundle-local indexing
 int countEntries()
          used for debugging and unittests
 void deleteAllFlows()
          Deletes all flows.
 void deleteFlow(java.lang.String name)
          Deletes a static flow
 void deleteFlowsForSwitch(long dpid)
          Deletes all static flows for a practicular switch
 IFloodlightProviderService getFloodlightProvider()
           
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> getFlows()
          Deletes all flows installed by static flow pusher on a given switch.
 java.util.Map<java.lang.String,OFFlowMod> getFlows(java.lang.String dpid)
          Gets a list of flows by switch
 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.
 IListener.Command handleFlowRemoved(IOFSwitch sw, OFFlowRemoved msg, FloodlightContext cntx)
          Handles a flow removed message from a switch.
 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
 void rowsDeleted(java.lang.String tableName, java.util.Set<java.lang.Object> rowKeys)
          Called when a new row is deleted from the table.
 void rowsModified(java.lang.String tableName, java.util.Set<java.lang.Object> rowKeys)
          Called when rows are inserted or updated in the table.
protected  void sendEntriesToSwitch(long switchId)
          Reads from our entriesFromStorage for the specified switch and sends the FlowMods down to the controller in sorted order.
 void setFloodlightProvider(IFloodlightProviderService floodlightProvider)
           
 void setStorageSource(IStorageSourceService storageSource)
           
 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 switchActivated(long switchId)
          Fired when a switch becomes active *on the local controller*, I.e., the switch is connected to the local controller and is in MASTER mode
 void switchAdded(long switchId)
          Fired when switch becomes known to the controller cluster.
 void switchChanged(long switchId)
          Fired when any non-port related information (e.g., attributes, features) change after a switchAdded TODO: currently unused
 void switchPortChanged(long switchId, ImmutablePort port, IOFSwitch.PortChangeType type)
          Fired when a port on a known switch changes.
 void switchRemoved(long switchId)
          Fired when a switch disconnects from the cluster ,
 
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

StaticFlowName

public static final java.lang.String StaticFlowName
See Also:
Constant Field Values

STATIC_FLOW_APP_ID

public static final int STATIC_FLOW_APP_ID
See Also:
Constant Field Values

TABLE_NAME

public static final java.lang.String TABLE_NAME
See Also:
Constant Field Values

COLUMN_NAME

public static final java.lang.String COLUMN_NAME
See Also:
Constant Field Values

COLUMN_SWITCH

public static final java.lang.String COLUMN_SWITCH
See Also:
Constant Field Values

COLUMN_ACTIVE

public static final java.lang.String COLUMN_ACTIVE
See Also:
Constant Field Values

COLUMN_IDLE_TIMEOUT

public static final java.lang.String COLUMN_IDLE_TIMEOUT
See Also:
Constant Field Values

COLUMN_HARD_TIMEOUT

public static final java.lang.String COLUMN_HARD_TIMEOUT
See Also:
Constant Field Values

COLUMN_PRIORITY

public static final java.lang.String COLUMN_PRIORITY
See Also:
Constant Field Values

COLUMN_COOKIE

public static final java.lang.String COLUMN_COOKIE
See Also:
Constant Field Values

COLUMN_WILDCARD

public static final java.lang.String COLUMN_WILDCARD
See Also:
Constant Field Values

COLUMN_IN_PORT

public static final java.lang.String COLUMN_IN_PORT
See Also:
Constant Field Values

COLUMN_DL_SRC

public static final java.lang.String COLUMN_DL_SRC
See Also:
Constant Field Values

COLUMN_DL_DST

public static final java.lang.String COLUMN_DL_DST
See Also:
Constant Field Values

COLUMN_DL_VLAN

public static final java.lang.String COLUMN_DL_VLAN
See Also:
Constant Field Values

COLUMN_DL_VLAN_PCP

public static final java.lang.String COLUMN_DL_VLAN_PCP
See Also:
Constant Field Values

COLUMN_DL_TYPE

public static final java.lang.String COLUMN_DL_TYPE
See Also:
Constant Field Values

COLUMN_NW_TOS

public static final java.lang.String COLUMN_NW_TOS
See Also:
Constant Field Values

COLUMN_NW_PROTO

public static final java.lang.String COLUMN_NW_PROTO
See Also:
Constant Field Values

COLUMN_NW_SRC

public static final java.lang.String COLUMN_NW_SRC
See Also:
Constant Field Values

COLUMN_NW_DST

public static final java.lang.String COLUMN_NW_DST
See Also:
Constant Field Values

COLUMN_TP_DST

public static final java.lang.String COLUMN_TP_DST
See Also:
Constant Field Values

COLUMN_TP_SRC

public static final java.lang.String COLUMN_TP_SRC
See Also:
Constant Field Values

COLUMN_ACTIONS

public static final java.lang.String COLUMN_ACTIONS
See Also:
Constant Field Values

ColumnNames

public static java.lang.String[] ColumnNames

floodlightProvider

protected IFloodlightProviderService floodlightProvider

storageSource

protected IStorageSourceService storageSource

restApi

protected IRestApiService restApi

entriesFromStorage

protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> entriesFromStorage

entry2dpid

protected java.util.Map<java.lang.String,java.lang.String> entry2dpid
Constructor Detail

StaticFlowEntryPusher

public StaticFlowEntryPusher()
Method Detail

countEntries

public int countEntries()
used for debugging and unittests

Returns:
the number of static flow entries as cached from storage

getFloodlightProvider

public IFloodlightProviderService getFloodlightProvider()

setFloodlightProvider

public void setFloodlightProvider(IFloodlightProviderService floodlightProvider)

setStorageSource

public void setStorageSource(IStorageSourceService storageSource)

sendEntriesToSwitch

protected void sendEntriesToSwitch(long switchId)
Reads from our entriesFromStorage for the specified switch and sends the FlowMods down to the controller in sorted order. Sorted is important to maintain correctness of the switch: if a packet would match both a lower and a higher priority rule, then we want it to match the higher priority or nothing, but never just the lower priority one. Inserting from high to low priority fixes this. TODO consider adding a "block all" flow mod and then removing it while starting up.

Parameters:
sw - The switch to send entries to

computeEntry2DpidMap

protected java.util.Map<java.lang.String,java.lang.String> computeEntry2DpidMap(java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> map)
Used only for bundle-local indexing

Parameters:
map -
Returns:

switchAdded

public void switchAdded(long switchId)
Description copied from interface: IOFSwitchListener
Fired when switch becomes known to the controller cluster. I.e., the switch is connected at some controller in the cluster

Specified by:
switchAdded in interface IOFSwitchListener
Parameters:
switchId - the datapath Id of the new switch

switchRemoved

public void switchRemoved(long switchId)
Description copied from interface: IOFSwitchListener
Fired when a switch disconnects from the cluster ,

Specified by:
switchRemoved in interface IOFSwitchListener
Parameters:
switchId - the datapath Id of the switch

switchActivated

public void switchActivated(long switchId)
Description copied from interface: IOFSwitchListener
Fired when a switch becomes active *on the local controller*, I.e., the switch is connected to the local controller and is in MASTER mode

Specified by:
switchActivated in interface IOFSwitchListener
Parameters:
switchId - the datapath Id of the switch

switchChanged

public void switchChanged(long switchId)
Description copied from interface: IOFSwitchListener
Fired when any non-port related information (e.g., attributes, features) change after a switchAdded TODO: currently unused

Specified by:
switchChanged in interface IOFSwitchListener

switchPortChanged

public void switchPortChanged(long switchId,
                              ImmutablePort port,
                              IOFSwitch.PortChangeType type)
Description copied from interface: IOFSwitchListener
Fired when a port on a known switch changes. A user of this notification needs to take care if the port and type information is used directly and if the collection of ports has been queried as well. This notification will only be dispatched after the the port changes have been committed to the IOFSwitch instance. However, if a user has previously called IOFSwitch.getPorts() or related method a subsequent update might already be present in the information returned by getPorts.

Specified by:
switchPortChanged in interface IOFSwitchListener

rowsModified

public void rowsModified(java.lang.String tableName,
                         java.util.Set<java.lang.Object> rowKeys)
Description copied from interface: IStorageSourceListener
Called when rows are inserted or updated in the table.

Specified by:
rowsModified in interface IStorageSourceListener
Parameters:
tableName - The table where the rows were inserted
rowKeys - The keys of the rows that were inserted

rowsDeleted

public void rowsDeleted(java.lang.String tableName,
                        java.util.Set<java.lang.Object> rowKeys)
Description copied from interface: IStorageSourceListener
Called when a new row is deleted from the table.

Specified by:
rowsDeleted in interface IStorageSourceListener
Parameters:
tableName - The table where the rows were deleted
rowKeys - The keys of the rows that were deleted

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:

handleFlowRemoved

public IListener.Command handleFlowRemoved(IOFSwitch sw,
                                           OFFlowRemoved msg,
                                           FloodlightContext cntx)
Handles a flow removed message from a switch. If the flow was removed and we did not explicitly delete it we re-install it. If we explicitly removed the flow we stop the processing of the flow removed message.

Parameters:
sw - The switch that sent the flow removed message.
msg - The flow removed message.
cntx - The associated context.
Returns:
Whether to continue processing this message.

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

addFlow

public void addFlow(java.lang.String name,
                    OFFlowMod fm,
                    java.lang.String swDpid)
Description copied from interface: IStaticFlowEntryPusherService
Adds a static flow.

Specified by:
addFlow in interface IStaticFlowEntryPusherService
Parameters:
name - Name of the flow mod. Must be unique.
fm - The flow to push.
swDpid - The switch DPID to push it to, in 00:00:00:00:00:00:00:01 notation.

deleteFlow

public void deleteFlow(java.lang.String name)
Description copied from interface: IStaticFlowEntryPusherService
Deletes a static flow

Specified by:
deleteFlow in interface IStaticFlowEntryPusherService
Parameters:
name - The name of the static flow to delete.

deleteAllFlows

public void deleteAllFlows()
Description copied from interface: IStaticFlowEntryPusherService
Deletes all flows.

Specified by:
deleteAllFlows in interface IStaticFlowEntryPusherService

deleteFlowsForSwitch

public void deleteFlowsForSwitch(long dpid)
Description copied from interface: IStaticFlowEntryPusherService
Deletes all static flows for a practicular switch

Specified by:
deleteFlowsForSwitch in interface IStaticFlowEntryPusherService
Parameters:
dpid - The DPID of the switch to delete flows for.

getFlows

public java.util.Map<java.lang.String,java.util.Map<java.lang.String,OFFlowMod>> getFlows()
Deletes all flows installed by static flow pusher on a given switch. We send a delete flow mod with the static flow pusher app ID in the cookie. Since OF1.0 doesn't support masking based on the cookie we have to disable having flow specific cookies.

Specified by:
getFlows in interface IStaticFlowEntryPusherService
Parameters:
dpid - The DPID of the switch to clear all it's flows.

getFlows

public java.util.Map<java.lang.String,OFFlowMod> getFlows(java.lang.String dpid)
Description copied from interface: IStaticFlowEntryPusherService
Gets a list of flows by switch

Specified by:
getFlows in interface IStaticFlowEntryPusherService