net.floodlightcontroller.loadbalancer
Class LoadBalancer

java.lang.Object
  extended by net.floodlightcontroller.loadbalancer.LoadBalancer
All Implemented Interfaces:
IListener<OFType>, IOFMessageListener, IFloodlightModule, IFloodlightService, ILoadBalancerService

public class LoadBalancer
extends java.lang.Object
implements IFloodlightModule, ILoadBalancerService, IOFMessageListener

A simple load balancer module for ping, tcp, and udp flows. This module is accessed via a REST API defined close to the OpenStack Quantum LBaaS (Load-balancer-as-a-Service) v1.0 API proposal. Since the proposal has not been final, no efforts have yet been made to confirm compatibility at this time. Limitations: - client records and static flows not purged after use, will exhaust switch flow tables over time - round robin policy among servers based on connections, not traffic volume - health monitoring feature not implemented yet

Author:
kcwang

Nested Class Summary
 class LoadBalancer.IPClient
           
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.core.IListener
IListener.Command
 
Field Summary
protected  java.util.HashMap<LoadBalancer.IPClient,LBMember> clientToMember
           
 java.util.Comparator<SwitchPort> clusterIdComparator
           
protected  ICounterStoreService counterStore
           
protected  IDeviceService deviceManager
           
protected  IFloodlightProviderService floodlightProvider
           
protected static java.lang.String LB_ETHER_TYPE
           
protected static int LB_PRIORITY
           
protected static org.slf4j.Logger log
           
protected  java.util.HashMap<java.lang.Integer,java.lang.String> memberIpToId
           
protected  java.util.HashMap<java.lang.String,LBMember> members
           
protected  OFMessageDamper messageDamper
           
protected static int OFMESSAGE_DAMPER_CAPACITY
           
protected static int OFMESSAGE_DAMPER_TIMEOUT
           
protected  java.util.HashMap<java.lang.String,LBPool> pools
           
protected  IRestApiService restApi
           
protected  IRoutingService routingEngine
           
protected  IStaticFlowEntryPusherService sfp
           
protected  ITopologyService topology
           
protected  java.util.HashMap<java.lang.Integer,java.lang.String> vipIpToId
           
protected  java.util.HashMap<java.lang.Integer,MACAddress> vipIpToMac
           
protected  java.util.HashMap<java.lang.String,LBVip> vips
           
 
Constructor Summary
LoadBalancer()
           
 
Method Summary
 LBMember createMember(LBMember member)
          Create and return a new member.
 LBMonitor createMonitor(LBMonitor monitor)
          Create and return a new monitor.
 LBPool createPool(LBPool pool)
          Create and return a new pool.
 LBVip createVip(LBVip vip)
          Create and return a new Vip.
 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.
 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.
 java.util.Collection<LBMember> listMember(java.lang.String memberId)
          List selected member by its ID.
 java.util.Collection<LBMember> listMembers()
          List all current members.
 java.util.Collection<LBMember> listMembersByPool(java.lang.String poolId)
          List all members in a specified pool.
 java.util.Collection<LBMonitor> listMonitor(java.lang.String monitorId)
          List selected monitor by its ID.
 java.util.Collection<LBMonitor> listMonitors()
          List all current monitors.
 java.util.Collection<LBPool> listPool(java.lang.String poolId)
          List selected pool by its ID.
 java.util.Collection<LBPool> listPools()
          List all current pools.
 java.util.Collection<LBVip> listVip(java.lang.String vipId)
          List selected Vip by its ID.
 java.util.Collection<LBVip> listVips()
          List all current Vips.
static void parseActionString(OFFlowMod flowMod, java.lang.String actionstr, org.slf4j.Logger log)
          Parses OFFlowMod actions from strings.
protected  void pushBidirectionalVipRoutes(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx, LoadBalancer.IPClient client, LBMember member)
          used to find and push in-bound and out-bound routes using StaticFlowEntryPusher
 void pushPacket(IPacket packet, IOFSwitch sw, int bufferId, int inPort, int outPort, FloodlightContext cntx, boolean flush)
          used to push any packet - borrowed routine from Forwarding
 void pushStaticVipRoute(boolean inBound, Route route, LoadBalancer.IPClient client, LBMember member, long pinSwitch)
          used to push given route using static flow entry pusher
 IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx)
          This is the method Floodlight uses to call listeners with OpenFlow messages
 int removeMember(java.lang.String memberId)
          Remove an existing member.
 int removeMonitor(java.lang.String monitorId)
          Remove an existing monitor.
 int removePool(java.lang.String poolId)
          Remove an existing pool.
 int removeVip(java.lang.String vipId)
          Remove an existing Vip.
 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.
 LBMember updateMember(LBMember member)
          Update and return an existing member.
 LBMonitor updateMonitor(LBMonitor monitor)
          Update and return an existing monitor.
 LBPool updatePool(LBPool pool)
          Update and return an existing pool.
 LBVip updateVip(LBVip vip)
          Update and return an existing Vip.
protected  void vipProxyArpReply(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx, java.lang.String vipId)
          used to send proxy Arp for load balanced service requests
 
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

restApi

protected IRestApiService restApi

counterStore

protected ICounterStoreService counterStore

messageDamper

protected OFMessageDamper messageDamper

deviceManager

protected IDeviceService deviceManager

routingEngine

protected IRoutingService routingEngine

topology

protected ITopologyService topology

sfp

protected IStaticFlowEntryPusherService sfp

vips

protected java.util.HashMap<java.lang.String,LBVip> vips

pools

protected java.util.HashMap<java.lang.String,LBPool> pools

members

protected java.util.HashMap<java.lang.String,LBMember> members

vipIpToId

protected java.util.HashMap<java.lang.Integer,java.lang.String> vipIpToId

vipIpToMac

protected java.util.HashMap<java.lang.Integer,MACAddress> vipIpToMac

memberIpToId

protected java.util.HashMap<java.lang.Integer,java.lang.String> memberIpToId

clientToMember

protected java.util.HashMap<LoadBalancer.IPClient,LBMember> clientToMember

OFMESSAGE_DAMPER_CAPACITY

protected static int OFMESSAGE_DAMPER_CAPACITY

OFMESSAGE_DAMPER_TIMEOUT

protected static int OFMESSAGE_DAMPER_TIMEOUT

LB_ETHER_TYPE

protected static java.lang.String LB_ETHER_TYPE

LB_PRIORITY

protected static int LB_PRIORITY

clusterIdComparator

public java.util.Comparator<SwitchPort> clusterIdComparator
Constructor Detail

LoadBalancer

public LoadBalancer()
Method Detail

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:

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.

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

vipProxyArpReply

protected void vipProxyArpReply(IOFSwitch sw,
                                OFPacketIn pi,
                                FloodlightContext cntx,
                                java.lang.String vipId)
used to send proxy Arp for load balanced service requests

Parameters:
IOFSwitch - sw
OFPacketIn - pi
FloodlightContext - cntx
String - vipId

pushPacket

public void pushPacket(IPacket packet,
                       IOFSwitch sw,
                       int bufferId,
                       int inPort,
                       int outPort,
                       FloodlightContext cntx,
                       boolean flush)
used to push any packet - borrowed routine from Forwarding

Parameters:
OFPacketIn - pi
IOFSwitch - sw
int - bufferId
int - inPort
int - outPort
FloodlightContext - cntx
boolean - flush

pushBidirectionalVipRoutes

protected void pushBidirectionalVipRoutes(IOFSwitch sw,
                                          OFPacketIn pi,
                                          FloodlightContext cntx,
                                          LoadBalancer.IPClient client,
                                          LBMember member)
used to find and push in-bound and out-bound routes using StaticFlowEntryPusher

Parameters:
IOFSwitch - sw
OFPacketIn - pi
FloodlightContext - cntx
IPClient - client
LBMember - member

pushStaticVipRoute

public void pushStaticVipRoute(boolean inBound,
                               Route route,
                               LoadBalancer.IPClient client,
                               LBMember member,
                               long pinSwitch)
used to push given route using static flow entry pusher

Parameters:
boolean - inBound
Route - route
IPClient - client
LBMember - member
long - pinSwitch

listVips

public java.util.Collection<LBVip> listVips()
Description copied from interface: ILoadBalancerService
List all current Vips.

Specified by:
listVips in interface ILoadBalancerService

listVip

public java.util.Collection<LBVip> listVip(java.lang.String vipId)
Description copied from interface: ILoadBalancerService
List selected Vip by its ID.

Specified by:
listVip in interface ILoadBalancerService
Parameters:
vipId - Id of requested Vip

createVip

public LBVip createVip(LBVip vip)
Description copied from interface: ILoadBalancerService
Create and return a new Vip.

Specified by:
createVip in interface ILoadBalancerService
Returns:
LBVip: Created Vip

updateVip

public LBVip updateVip(LBVip vip)
Description copied from interface: ILoadBalancerService
Update and return an existing Vip.

Specified by:
updateVip in interface ILoadBalancerService
Returns:
LBVip: Updated Vip

removeVip

public int removeVip(java.lang.String vipId)
Description copied from interface: ILoadBalancerService
Remove an existing Vip.

Specified by:
removeVip in interface ILoadBalancerService
Returns:
int: removal status

listPools

public java.util.Collection<LBPool> listPools()
Description copied from interface: ILoadBalancerService
List all current pools.

Specified by:
listPools in interface ILoadBalancerService

listPool

public java.util.Collection<LBPool> listPool(java.lang.String poolId)
Description copied from interface: ILoadBalancerService
List selected pool by its ID.

Specified by:
listPool in interface ILoadBalancerService
Parameters:
poolId - Id of requested pool

createPool

public LBPool createPool(LBPool pool)
Description copied from interface: ILoadBalancerService
Create and return a new pool.

Specified by:
createPool in interface ILoadBalancerService
Returns:
LBPool: Created pool

updatePool

public LBPool updatePool(LBPool pool)
Description copied from interface: ILoadBalancerService
Update and return an existing pool.

Specified by:
updatePool in interface ILoadBalancerService
Returns:
LBPool: Updated pool

removePool

public int removePool(java.lang.String poolId)
Description copied from interface: ILoadBalancerService
Remove an existing pool.

Specified by:
removePool in interface ILoadBalancerService
Returns:
int: removal status

listMembers

public java.util.Collection<LBMember> listMembers()
Description copied from interface: ILoadBalancerService
List all current members.

Specified by:
listMembers in interface ILoadBalancerService

listMember

public java.util.Collection<LBMember> listMember(java.lang.String memberId)
Description copied from interface: ILoadBalancerService
List selected member by its ID.

Specified by:
listMember in interface ILoadBalancerService
Parameters:
memberId - Id of requested member

listMembersByPool

public java.util.Collection<LBMember> listMembersByPool(java.lang.String poolId)
Description copied from interface: ILoadBalancerService
List all members in a specified pool.

Specified by:
listMembersByPool in interface ILoadBalancerService

createMember

public LBMember createMember(LBMember member)
Description copied from interface: ILoadBalancerService
Create and return a new member.

Specified by:
createMember in interface ILoadBalancerService
Returns:
LBMember: Created member

updateMember

public LBMember updateMember(LBMember member)
Description copied from interface: ILoadBalancerService
Update and return an existing member.

Specified by:
updateMember in interface ILoadBalancerService
Returns:
LBMember: Updated member

removeMember

public int removeMember(java.lang.String memberId)
Description copied from interface: ILoadBalancerService
Remove an existing member.

Specified by:
removeMember in interface ILoadBalancerService
Returns:
int: removal status

listMonitors

public java.util.Collection<LBMonitor> listMonitors()
Description copied from interface: ILoadBalancerService
List all current monitors.

Specified by:
listMonitors in interface ILoadBalancerService

listMonitor

public java.util.Collection<LBMonitor> listMonitor(java.lang.String monitorId)
Description copied from interface: ILoadBalancerService
List selected monitor by its ID.

Specified by:
listMonitor in interface ILoadBalancerService
Parameters:
monitorId - Id of requested monitor

createMonitor

public LBMonitor createMonitor(LBMonitor monitor)
Description copied from interface: ILoadBalancerService
Create and return a new monitor.

Specified by:
createMonitor in interface ILoadBalancerService
Returns:
LBMonitor: Created monitor

updateMonitor

public LBMonitor updateMonitor(LBMonitor monitor)
Description copied from interface: ILoadBalancerService
Update and return an existing monitor.

Specified by:
updateMonitor in interface ILoadBalancerService
Returns:
LBMonitor: Updated monitor

removeMonitor

public int removeMonitor(java.lang.String monitorId)
Description copied from interface: ILoadBalancerService
Remove an existing monitor.

Specified by:
removeMonitor in interface ILoadBalancerService
Returns:
int: removal status

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

parseActionString

public static void parseActionString(OFFlowMod flowMod,
                                     java.lang.String actionstr,
                                     org.slf4j.Logger log)
Parses OFFlowMod actions from strings.

Parameters:
flowMod - The OFFlowMod to set the actions for
actionstr - The string containing all the actions
log - A logger to log for errors.