libfluid
The ONF OpenFlow driver
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
fluid_base::OFServer Class Reference

#include <OFServer.hh>

Inheritance diagram for fluid_base::OFServer:
fluid_base::BaseOFServer fluid_base::OFHandler

Public Member Functions

 OFServer (const char *address, const int port, const int nthreads=4, const bool secure=false, const struct OFServerSettings ofsc=OFServerSettings())
 
virtual bool start (bool block=false)
 
virtual void stop ()
 
OFConnectionget_ofconnection (int id)
 
void set_config (OFServerSettings ofsc)
 
virtual void connection_callback (OFConnection *conn, OFConnection::Event event_type)
 
virtual void message_callback (OFConnection *conn, uint8_t type, void *data, size_t len)
 
virtual void free_data (void *data)
 

Protected Member Functions

void lock_ofconnections ()
 
void unlock_ofconnections ()
 
void base_message_callback (BaseOFConnection *c, void *data, size_t len)
 
void base_connection_callback (BaseOFConnection *c, BaseOFConnection::Event event_type)
 

Static Protected Member Functions

static void * send_echo (void *arg)
 

Protected Attributes

OFServerSettings ofsc
 
std::map< int, OFConnection * > ofconnections
 
pthread_mutex_t ofconnections_lock
 

Additional Inherited Members

- Private Member Functions inherited from fluid_base::BaseOFServer
 BaseOFServer (const char *address, const int port, const int nevloops=1, const bool secure=false)
 

Detailed Description

An OFServer manages OpenFlow connections and abstracts their events through callbacks. It provides some of the basic functionalities: OpenFlow connection setup and liveness check.

Tipically a controller or low-level controller base class will inherit from OFServer and implement the message_callback and connection_callback methods to implement further functionality.

Constructor & Destructor Documentation

fluid_base::OFServer::OFServer ( const char *  address,
const int  port,
const int  nthreads = 4,
const bool  secure = false,
const struct OFServerSettings  ofsc = OFServerSettings() 
)

Create an OFServer.

Parameters
addressaddress to bind the server
portTCP port on which the server will listen
nthreadsnumber of threads to run. Connections will be attributed to event loops running on threads on a round-robin fashion. The first event loop will also listen for new connections.
securewhether the connections should use TLS. TLS support must compiled into the library and you need to call libfluid_ssl_init before you can use this feature.
ofscthe optional server configuration parameters. If no value is provided, default settings will be used. See OFServerSettings.

Member Function Documentation

virtual bool fluid_base::OFServer::start ( bool  block = false)
virtual

Start the server. It will listen at the port declared in the constructor, handling connections in different threads and optionally blocking the calling thread until OFServer::stop is called.

Parameters
blockblock the calling thread while the server is running

Reimplemented from fluid_base::BaseOFServer.

virtual void fluid_base::OFServer::stop ( )
virtual

Stop the server. It will close all connections, ask the theads handling connections to finish.

It will eventually unblock OFServer::start if it is blocking.

Reimplemented from fluid_base::BaseOFServer.

OFConnection* fluid_base::OFServer::get_ofconnection ( int  id)

Retrieve an OFConnection object associated with this OFServer with a given id.

Parameters
idOFConnection id
void fluid_base::OFServer::set_config ( OFServerSettings  ofsc)

Set configuration parameters for this OFServer.

This method should be called before OFServer::start is called. Doing otherwise will result in undefined settings behavior. In theory, it will work fine, but unpredictable behavior can happen, and some settings will only apply to new connections.

You will usually initialize the settings in the constructor. This method is provided to give more flexibility to implementations.

Parameters
ofscan OFServerSettings object with the desired settings
virtual void fluid_base::OFServer::connection_callback ( OFConnection conn,
OFConnection::Event  event_type 
)
inlinevirtual

Callback for connection events.

This method blocks the event loop on which the connection is running, preventing other connection's events from being handled. If you want to perform a very long operation, try to queue it and return.

The implementation must be thread-safe, because it will possibly be called from several threads (on which connection events are being created).

Parameters
connthe OFConnection on which the message was received
event_typethe event type (see #Event)

Implements fluid_base::OFHandler.

virtual void fluid_base::OFServer::message_callback ( OFConnection conn,
uint8_t  type,
void *  data,
size_t  len 
)
inlinevirtual

Callback for new messages.

This method blocks the event loop on which the connection is running, preventing other connection's events from being handled. If you want to perform a very long operation, try to queue it and return.

The implementation must be thread-safe, because it will possibly be called from several threads (on which message events are being created).

By default, the message data will managed (freed) for you. If you want a zero-copy behavior, see OFServerSettings::keep_data_ownership.

Parameters
connthe OFConnection on which the message was received
typeOpenFlow message type
databinary message data
lenmessage length

Implements fluid_base::OFHandler.

virtual void fluid_base::OFServer::free_data ( void *  data)
virtual

Free the data passed to BaseOFHandler::base_message_callback.

Reimplemented from fluid_base::BaseOFServer.

void fluid_base::OFServer::base_message_callback ( BaseOFConnection conn,
void *  data,
size_t  len 
)
protectedvirtual

Callback for new messages.

This method blocks the event loop on which the connection is running, preventing other connection's events from being handled. If you want to perform a very long operation, try to queue it and return.

The implementation must be thread-safe, because it may be called by several EventLoop instances, each running in a thread.

The message data will not be freed. To free it, you should call BaseOFConnection::free_data when you are done with it.

Parameters
connthe BaseOFConnection on which the message was received
databinary message data
lenmessage length

Reimplemented from fluid_base::BaseOFServer.

void fluid_base::OFServer::base_connection_callback ( BaseOFConnection conn,
BaseOFConnection::Event  event_type 
)
protectedvirtual

Callback for connection events.

This method blocks the event loop on which the connection is running, preventing other connection's events from being handled. If you want to perform a very long operation, try to queue it and return.

The implementation must be thread-safe, because it may be called by several EventLoop instances, each running in a thread.

Parameters
connthe BaseOFConnection on which the message was received
event_typethe event type (see #BaseOFConnectionEvent)

Reimplemented from fluid_base::BaseOFServer.


The documentation for this class was generated from the following file: