net.floodlightcontroller.core.internal
Class Controller

java.lang.Object
  extended by net.floodlightcontroller.core.internal.Controller
All Implemented Interfaces:
java.lang.Runnable, IFloodlightProviderService, IInfoProvider, IFloodlightService, IStorageSourceListener

public class Controller
extends java.lang.Object
implements IFloodlightProviderService, IStorageSourceListener, IInfoProvider

The main controller class. Handles all setup and network listeners


Nested Class Summary
static class Controller.Counters
           
 class Controller.SwitchEvent
           
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.core.IFloodlightProviderService
IFloodlightProviderService.Role
 
Field Summary
protected static boolean ALWAYS_DECODE_ETH
           
static int BATCH_MAX_SIZE
           
protected static java.lang.String CONTROLLER_ID
           
protected static java.lang.String CONTROLLER_INTERFACE_CONTROLLER_ID
           
protected static java.lang.String CONTROLLER_INTERFACE_DISCOVERED_IP
           
protected static java.lang.String CONTROLLER_INTERFACE_ID
           
protected static java.lang.String CONTROLLER_INTERFACE_NUMBER
           
protected static java.lang.String CONTROLLER_INTERFACE_TABLE_NAME
           
protected static java.lang.String CONTROLLER_INTERFACE_TYPE
           
protected static java.lang.String CONTROLLER_TABLE_NAME
           
protected  java.util.HashMap<java.lang.String,java.lang.String> controllerNodeIPsCache
           
protected  IDebugEventService debugEvents
           
protected  IEventUpdater<Controller.SwitchEvent> evSwitch
           
protected  FloodlightFactory factory
           
protected static java.lang.ThreadLocal<java.util.Stack<FloodlightContext>> flcontext_cache
          flcontext_cache - Keep a thread local stack of contexts
protected  ListenerDispatcher<HAListenerTypeMarker,IHAListener> haListeners
           
protected  LoadMonitor loadmonitor
           
protected static org.slf4j.Logger log
           
protected  java.util.concurrent.ConcurrentMap<OFType,ListenerDispatcher<OFType,IOFMessageListener>> messageListeners
           
protected  IFloodlightProviderService.Role notifiedRole
           
protected static INotificationManager notifier
           
protected  java.lang.String openFlowHost
           
protected  int openFlowPort
           
protected  boolean overload_drop
           
protected  java.util.Map<java.lang.String,java.util.List<IInfoProvider>> providerMap
           
protected  java.util.Set<IReadyForReconcileListener> readyForReconcileListeners
           
protected static int SEND_BUFFER_SIZE
           
protected static java.lang.String SWITCH_CONFIG_CORE_SWITCH
           
protected static java.lang.String SWITCH_CONFIG_TABLE_NAME
           
protected  java.util.Set<IOFSwitchListener> switchListeners
           
protected  java.util.concurrent.BlockingQueue<net.floodlightcontroller.core.internal.Controller.IUpdate> updates
           
protected  int workerThreads
           
 
Fields inherited from interface net.floodlightcontroller.core.IFloodlightProviderService
bcStore, CONTEXT_PI_PAYLOAD
 
Constructor Summary
Controller()
           
 
Method Summary
 void addHAListener(IHAListener listener)
          Adds a listener for HA role events
 void addInfoProvider(java.lang.String type, IInfoProvider provider)
          Add an info provider of a particular type
 void addOFMessageListener(OFType type, IOFMessageListener listener)
          Adds an OpenFlow message listener
 void addOFSwitchDriver(java.lang.String manufacturerDescriptionPrefix, IOFSwitchDriver driver)
          Adds an OFSwitch driver
 void addOFSwitchListener(IOFSwitchListener listener)
          Add a switch listener
 void addReadyForReconcileListener(IReadyForReconcileListener l)
          Add a listener for ready-for-flow-reconcile events
 void addSwitchEvent(long switchDPID, java.lang.String reason, boolean flushNow)
          Switch Added/Deleted Events
protected static FloodlightContext flcontext_alloc()
          flcontext_alloc - pop a context off the stack, if required create a new one
protected  void flcontext_free(FloodlightContext flcontext)
          flcontext_free - Free the context to the current thread
 java.util.Set<java.lang.Long> getAllSwitchDpids()
          Returns a snapshot of the set DPIDs for all known switches.
 java.util.Map<java.lang.Long,IOFSwitch> getAllSwitchMap()
          Return a snapshot FIXME: asdf
 java.util.Map<java.lang.String,java.lang.Object> getControllerInfo(java.lang.String type)
          Return information of a particular type (for rest services)
 java.util.Map<java.lang.String,java.lang.String> getControllerNodeIPs()
          Get the current mapping of controller IDs to their IP addresses Returns a copy of the current mapping.
 java.util.Map<java.lang.String,java.lang.Object> getInfo(java.lang.String type)
          Called when rest API requests information of a particular type
protected  IFloodlightProviderService.Role getInitialRole(java.util.Map<java.lang.String,java.lang.String> configParams)
          Sets the initial role based on properties in the config params.
 java.util.Map<OFType,java.util.List<IOFMessageListener>> getListeners()
          Return a non-modifiable list of all current listeners
 java.util.Map<java.lang.String,java.lang.Long> getMemory()
          Get controller memory information
 FloodlightFactory getOFMessageFactory()
          Gets the FloodlightFactory
 IFloodlightProviderService.Role getRole()
          Get the current role of the controller
 RoleInfo getRoleInfo()
          Get the current role of the controller
 IOFSwitch getSwitch(long dpid)
          If the switch with the given DPID is known to any controller in the cluster, this method returns the associated IOFSwitch instance.
 long getSystemStartTime()
          Return the controller start time in milliseconds
 java.util.Set<java.lang.String> getUplinkPortPrefixSet()
          Get the set of port prefixes that will define an UPLINK port.
 java.lang.Long getUptime()
          returns the uptime of this controller.
protected  void handleControllerNodeIPChanges()
          Handle changes to the controller nodes IPs and dispatch update.
protected  void handleMessage(IOFSwitch sw, OFMessage m, FloodlightContext bContext)
          Handle and dispatch a message to IOFMessageListeners.
 void handleOutgoingMessage(IOFSwitch sw, OFMessage m, FloodlightContext bc)
          Process written messages through the message listeners for the controller
 void init(java.util.Map<java.lang.String,java.lang.String> configParams)
          Initialize internal data structures
 boolean injectOfMessage(IOFSwitch sw, OFMessage msg)
          Re-injects an OFMessage back into the packet processing chain
 boolean injectOfMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc)
          Re-injects an OFMessage back into the packet processing chain
 void removeHAListener(IHAListener listener)
          Removes a listener for HA role events
 void removeInfoProvider(java.lang.String type, IInfoProvider provider)
          Remove an info provider of a particular type
 void removeOFMessageListener(OFType type, IOFMessageListener listener)
          Removes an OpenFlow message listener
 void removeOFMessageListeners(OFType type)
           
 void removeOFSwitchListener(IOFSwitchListener listener)
          Remove a switch listener
 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.
 void run()
          Tell controller that we're ready to accept switches loop
 void setAlwaysClearFlowsOnSwActivate(boolean value)
          Configure controller to always clear the flow table on the switch, when it connects to controller.
 void setDebugEvent(IDebugEventService debugEvent)
           
 void setRole(IFloodlightProviderService.Role role, java.lang.String roleChangeDescription)
          Set the role of the controller
 void setUplinkPortPrefixSet(java.util.Set<java.lang.String> prefixSet)
           
 void startupComponents()
          Startup all of the controller's components
 void terminate()
          Terminate the process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log

notifier

protected static final INotificationManager notifier

factory

protected FloodlightFactory factory

messageListeners

protected java.util.concurrent.ConcurrentMap<OFType,ListenerDispatcher<OFType,IOFMessageListener>> messageListeners

controllerNodeIPsCache

protected java.util.HashMap<java.lang.String,java.lang.String> controllerNodeIPsCache

switchListeners

protected java.util.Set<IOFSwitchListener> switchListeners

haListeners

protected ListenerDispatcher<HAListenerTypeMarker,IHAListener> haListeners

readyForReconcileListeners

protected java.util.Set<IReadyForReconcileListener> readyForReconcileListeners

providerMap

protected java.util.Map<java.lang.String,java.util.List<IInfoProvider>> providerMap

updates

protected java.util.concurrent.BlockingQueue<net.floodlightcontroller.core.internal.Controller.IUpdate> updates

debugEvents

protected IDebugEventService debugEvents

openFlowHost

protected java.lang.String openFlowHost

openFlowPort

protected int openFlowPort

workerThreads

protected int workerThreads

notifiedRole

protected volatile IFloodlightProviderService.Role notifiedRole

CONTROLLER_TABLE_NAME

protected static final java.lang.String CONTROLLER_TABLE_NAME
See Also:
Constant Field Values

CONTROLLER_ID

protected static final java.lang.String CONTROLLER_ID
See Also:
Constant Field Values

SWITCH_CONFIG_TABLE_NAME

protected static final java.lang.String SWITCH_CONFIG_TABLE_NAME
See Also:
Constant Field Values

SWITCH_CONFIG_CORE_SWITCH

protected static final java.lang.String SWITCH_CONFIG_CORE_SWITCH
See Also:
Constant Field Values

CONTROLLER_INTERFACE_TABLE_NAME

protected static final java.lang.String CONTROLLER_INTERFACE_TABLE_NAME
See Also:
Constant Field Values

CONTROLLER_INTERFACE_ID

protected static final java.lang.String CONTROLLER_INTERFACE_ID
See Also:
Constant Field Values

CONTROLLER_INTERFACE_CONTROLLER_ID

protected static final java.lang.String CONTROLLER_INTERFACE_CONTROLLER_ID
See Also:
Constant Field Values

CONTROLLER_INTERFACE_TYPE

protected static final java.lang.String CONTROLLER_INTERFACE_TYPE
See Also:
Constant Field Values

CONTROLLER_INTERFACE_NUMBER

protected static final java.lang.String CONTROLLER_INTERFACE_NUMBER
See Also:
Constant Field Values

CONTROLLER_INTERFACE_DISCOVERED_IP

protected static final java.lang.String CONTROLLER_INTERFACE_DISCOVERED_IP
See Also:
Constant Field Values

SEND_BUFFER_SIZE

protected static final int SEND_BUFFER_SIZE
See Also:
Constant Field Values

BATCH_MAX_SIZE

public static final int BATCH_MAX_SIZE
See Also:
Constant Field Values

ALWAYS_DECODE_ETH

protected static final boolean ALWAYS_DECODE_ETH
See Also:
Constant Field Values

evSwitch

protected IEventUpdater<Controller.SwitchEvent> evSwitch

overload_drop

protected final boolean overload_drop

loadmonitor

protected final LoadMonitor loadmonitor

flcontext_cache

protected static final java.lang.ThreadLocal<java.util.Stack<FloodlightContext>> flcontext_cache
flcontext_cache - Keep a thread local stack of contexts

Constructor Detail

Controller

public Controller()
Method Detail

getUplinkPortPrefixSet

public java.util.Set<java.lang.String> getUplinkPortPrefixSet()
Description copied from interface: IFloodlightProviderService
Get the set of port prefixes that will define an UPLINK port.

Specified by:
getUplinkPortPrefixSet in interface IFloodlightProviderService
Returns:
The set of prefixes

setUplinkPortPrefixSet

public void setUplinkPortPrefixSet(java.util.Set<java.lang.String> prefixSet)

setDebugEvent

public void setDebugEvent(IDebugEventService debugEvent)

getRole

public IFloodlightProviderService.Role getRole()
Description copied from interface: IFloodlightProviderService
Get the current role of the controller

Specified by:
getRole in interface IFloodlightProviderService

getRoleInfo

public RoleInfo getRoleInfo()
Description copied from interface: IFloodlightProviderService
Get the current role of the controller

Specified by:
getRoleInfo in interface IFloodlightProviderService

setRole

public void setRole(IFloodlightProviderService.Role role,
                    java.lang.String roleChangeDescription)
Description copied from interface: IFloodlightProviderService
Set the role of the controller

Specified by:
setRole in interface IFloodlightProviderService
Parameters:
role - The new role for the controller node
roleChangeDescription - The reason or other information for this role change

flcontext_alloc

protected static FloodlightContext flcontext_alloc()
flcontext_alloc - pop a context off the stack, if required create a new one

Returns:
FloodlightContext

flcontext_free

protected void flcontext_free(FloodlightContext flcontext)
flcontext_free - Free the context to the current thread

Parameters:
flcontext -

handleMessage

protected void handleMessage(IOFSwitch sw,
                             OFMessage m,
                             FloodlightContext bContext)
                      throws java.io.IOException
Handle and dispatch a message to IOFMessageListeners. We only dispatch messages to listeners if the controller's role is MASTER.

Parameters:
sw - The switch sending the message
m - The message the switch sent
flContext - The floodlight context to use for this message. If null, a new context will be allocated.
Throws:
java.io.IOException - FIXME: this method and the ChannelHandler disagree on which messages should be dispatched and which shouldn't

getAllSwitchMap

public java.util.Map<java.lang.Long,IOFSwitch> getAllSwitchMap()
Description copied from interface: IFloodlightProviderService
Return a snapshot FIXME: asdf

Specified by:
getAllSwitchMap in interface IFloodlightProviderService
Returns:

getAllSwitchDpids

public java.util.Set<java.lang.Long> getAllSwitchDpids()
Description copied from interface: IFloodlightProviderService
Returns a snapshot of the set DPIDs for all known switches. The returned set is owned by the caller: the caller can modify it at will and changes to the known switches are not reflected in the returned set. The caller needs to call getAllSwitchDpids() if an updated version is needed. See IFloodlightProviderService.getSwitch(long) for what "known" switch is.

Specified by:
getAllSwitchDpids in interface IFloodlightProviderService
Returns:
the set of DPIDs of all known switches

getSwitch

public IOFSwitch getSwitch(long dpid)
Description copied from interface: IFloodlightProviderService
If the switch with the given DPID is known to any controller in the cluster, this method returns the associated IOFSwitch instance. As such the returned switches not necessarily connected or in master role for the local controller. Multiple calls to this method with the same DPID may return different IOFSwitch references. A caller must not store or otherwise rely on IOFSwitch references to be constant over the lifecycle of a switch.

Specified by:
getSwitch in interface IFloodlightProviderService
Parameters:
dpid - the dpid of the switch to query
Returns:
the IOFSwitch instance associated with the dpid, null if no switch with the dpid is known to the cluster

addOFSwitchListener

public void addOFSwitchListener(IOFSwitchListener listener)
Description copied from interface: IFloodlightProviderService
Add a switch listener

Specified by:
addOFSwitchListener in interface IFloodlightProviderService
Parameters:
listener - The module that wants to listen for events

removeOFSwitchListener

public void removeOFSwitchListener(IOFSwitchListener listener)
Description copied from interface: IFloodlightProviderService
Remove a switch listener

Specified by:
removeOFSwitchListener in interface IFloodlightProviderService
Parameters:
listener - The The module that no longer wants to listen for events

addOFMessageListener

public void addOFMessageListener(OFType type,
                                 IOFMessageListener listener)
Description copied from interface: IFloodlightProviderService
Adds an OpenFlow message listener

Specified by:
addOFMessageListener in interface IFloodlightProviderService
Parameters:
type - The OFType the component wants to listen for
listener - The component that wants to listen for the message

removeOFMessageListener

public void removeOFMessageListener(OFType type,
                                    IOFMessageListener listener)
Description copied from interface: IFloodlightProviderService
Removes an OpenFlow message listener

Specified by:
removeOFMessageListener in interface IFloodlightProviderService
Parameters:
type - The OFType the component no long wants to listen for
listener - The component that no longer wants to receive the message

removeOFMessageListeners

public void removeOFMessageListeners(OFType type)

getListeners

public java.util.Map<OFType,java.util.List<IOFMessageListener>> getListeners()
Description copied from interface: IFloodlightProviderService
Return a non-modifiable list of all current listeners

Specified by:
getListeners in interface IFloodlightProviderService
Returns:
listeners

injectOfMessage

public boolean injectOfMessage(IOFSwitch sw,
                               OFMessage msg,
                               FloodlightContext bc)
Description copied from interface: IFloodlightProviderService
Re-injects an OFMessage back into the packet processing chain

Specified by:
injectOfMessage in interface IFloodlightProviderService
Parameters:
sw - The switch to use for the message
msg - the message to inject
bc - a floodlight context to use if required. Can be null
Returns:
True if successfully re-injected, false otherwise

terminate

public void terminate()
Description copied from interface: IFloodlightProviderService
Terminate the process

Specified by:
terminate in interface IFloodlightProviderService

injectOfMessage

public boolean injectOfMessage(IOFSwitch sw,
                               OFMessage msg)
Description copied from interface: IFloodlightProviderService
Re-injects an OFMessage back into the packet processing chain

Specified by:
injectOfMessage in interface IFloodlightProviderService
Parameters:
sw - The switch to use for the message
msg - the message to inject
Returns:
True if successfully re-injected, false otherwise

handleOutgoingMessage

public void handleOutgoingMessage(IOFSwitch sw,
                                  OFMessage m,
                                  FloodlightContext bc)
Description copied from interface: IFloodlightProviderService
Process written messages through the message listeners for the controller

Specified by:
handleOutgoingMessage in interface IFloodlightProviderService
Parameters:
sw - The switch being written to
m - the message
bc - any accompanying context object. Can be null in which case a new context will be allocated and passed to listeners

getOFMessageFactory

public FloodlightFactory getOFMessageFactory()
Description copied from interface: IFloodlightProviderService
Gets the FloodlightFactory

Specified by:
getOFMessageFactory in interface IFloodlightProviderService
Returns:
an OpenFlow message factory

getInitialRole

protected IFloodlightProviderService.Role getInitialRole(java.util.Map<java.lang.String,java.lang.String> configParams)
Sets the initial role based on properties in the config params. It looks for two different properties. If the "role" property is specified then the value should be either "EQUAL", "MASTER", or "SLAVE" and the role of the controller is set to the specified value. If the "role" property is not specified then it looks next for the "role.path" property. In this case the value should be the path to a property file in the file system that contains a property called "floodlight.role" which can be one of the values listed above for the "role" property. The idea behind the "role.path" mechanism is that you have some separate heartbeat and master controller election algorithm that determines the role of the controller. When a role transition happens, it updates the current role in the file specified by the "role.path" file. Then if floodlight restarts for some reason it can get the correct current role of the controller from the file.

Parameters:
configParams - The config params for the FloodlightProvider service
Returns:
A valid role if role information is specified in the config params, otherwise null

run

public void run()
Tell controller that we're ready to accept switches loop

Specified by:
run in interface java.lang.Runnable
Specified by:
run in interface IFloodlightProviderService
Throws:
java.io.IOException

init

public void init(java.util.Map<java.lang.String,java.lang.String> configParams)
Initialize internal data structures


startupComponents

public void startupComponents()
                       throws FloodlightModuleException
Startup all of the controller's components

Throws:
FloodlightModuleException

addInfoProvider

public void addInfoProvider(java.lang.String type,
                            IInfoProvider provider)
Description copied from interface: IFloodlightProviderService
Add an info provider of a particular type

Specified by:
addInfoProvider in interface IFloodlightProviderService

removeInfoProvider

public void removeInfoProvider(java.lang.String type,
                               IInfoProvider provider)
Description copied from interface: IFloodlightProviderService
Remove an info provider of a particular type

Specified by:
removeInfoProvider in interface IFloodlightProviderService

getControllerInfo

public java.util.Map<java.lang.String,java.lang.Object> getControllerInfo(java.lang.String type)
Description copied from interface: IFloodlightProviderService
Return information of a particular type (for rest services)

Specified by:
getControllerInfo in interface IFloodlightProviderService
Returns:

addHAListener

public void addHAListener(IHAListener listener)
Description copied from interface: IFloodlightProviderService
Adds a listener for HA role events

Specified by:
addHAListener in interface IFloodlightProviderService
Parameters:
listener - The module that wants to listen for events

removeHAListener

public void removeHAListener(IHAListener listener)
Description copied from interface: IFloodlightProviderService
Removes a listener for HA role events

Specified by:
removeHAListener in interface IFloodlightProviderService
Parameters:
listener - The module that no longer wants to listen for events

addReadyForReconcileListener

public void addReadyForReconcileListener(IReadyForReconcileListener l)
Description copied from interface: IFloodlightProviderService
Add a listener for ready-for-flow-reconcile events

Specified by:
addReadyForReconcileListener in interface IFloodlightProviderService

handleControllerNodeIPChanges

protected void handleControllerNodeIPChanges()
Handle changes to the controller nodes IPs and dispatch update.


getControllerNodeIPs

public java.util.Map<java.lang.String,java.lang.String> getControllerNodeIPs()
Description copied from interface: IFloodlightProviderService
Get the current mapping of controller IDs to their IP addresses Returns a copy of the current mapping.

Specified by:
getControllerNodeIPs in interface IFloodlightProviderService
See Also:
IHAListener

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

getSystemStartTime

public long getSystemStartTime()
Description copied from interface: IFloodlightProviderService
Return the controller start time in milliseconds

Specified by:
getSystemStartTime in interface IFloodlightProviderService
Returns:

setAlwaysClearFlowsOnSwActivate

public void setAlwaysClearFlowsOnSwActivate(boolean value)
Description copied from interface: IFloodlightProviderService
Configure controller to always clear the flow table on the switch, when it connects to controller. This will be true for first time switch reconnect, as well as a switch re-attaching to Controller after HA switch over to ACTIVE role

Specified by:
setAlwaysClearFlowsOnSwActivate in interface IFloodlightProviderService

getMemory

public java.util.Map<java.lang.String,java.lang.Long> getMemory()
Description copied from interface: IFloodlightProviderService
Get controller memory information

Specified by:
getMemory in interface IFloodlightProviderService

getUptime

public java.lang.Long getUptime()
Description copied from interface: IFloodlightProviderService
returns the uptime of this controller.

Specified by:
getUptime in interface IFloodlightProviderService
Returns:

addOFSwitchDriver

public void addOFSwitchDriver(java.lang.String manufacturerDescriptionPrefix,
                              IOFSwitchDriver driver)
Description copied from interface: IFloodlightProviderService
Adds an OFSwitch driver

Specified by:
addOFSwitchDriver in interface IFloodlightProviderService
driver - A IOFSwitchDriver instance to handle IOFSwitch instaniation for the given manufacturer description prefix

addSwitchEvent

public void addSwitchEvent(long switchDPID,
                           java.lang.String reason,
                           boolean flushNow)
Switch Added/Deleted Events

Specified by:
addSwitchEvent in interface IFloodlightProviderService
reason - Reason for this event
flushNow - see debug-event flushing in IDebugEventService

getInfo

public java.util.Map<java.lang.String,java.lang.Object> getInfo(java.lang.String type)
Description copied from interface: IInfoProvider
Called when rest API requests information of a particular type

Specified by:
getInfo in interface IInfoProvider
Returns: