#include <OFServer.hh>
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 () |
OFConnection * | get_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) | |
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.
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.
address | address to bind the server |
port | TCP port on which the server will listen |
nthreads | number 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. |
secure | whether 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. |
ofsc | the optional server configuration parameters. If no value is provided, default settings will be used. See OFServerSettings. |
|
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.
block | block the calling thread while the server is running |
Reimplemented from fluid_base::BaseOFServer.
|
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.
id | OFConnection 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.
ofsc | an OFServerSettings object with the desired settings |
|
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).
conn | the OFConnection on which the message was received |
event_type | the event type (see #Event) |
Implements fluid_base::OFHandler.
|
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.
conn | the OFConnection on which the message was received |
type | OpenFlow message type |
data | binary message data |
len | message length |
Implements fluid_base::OFHandler.
|
virtual |
Free the data passed to BaseOFHandler::base_message_callback.
Reimplemented from fluid_base::BaseOFServer.
|
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.
conn | the BaseOFConnection on which the message was received |
data | binary message data |
len | message length |
Reimplemented from fluid_base::BaseOFServer.
|
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.
conn | the BaseOFConnection on which the message was received |
event_type | the event type (see #BaseOFConnectionEvent) |
Reimplemented from fluid_base::BaseOFServer.