ANNA Suite
2020b
Multipurpose development suite for Telco applications
|
#include <Engine.hpp>
Public Member Functions | |
void | setOriginRealmName (const std::string &originRealmName) |
void | setOriginHostName (const std::string &originHostName) |
const std::string & | getOriginRealmName () const |
const std::string & | getOriginHostName () const |
void | raiseAutoRecovery (bool autoRecovery=true) noexcept(false) |
bool | getAutoBind () const |
void | setAutoBind (const bool autoBind) |
void | setMaxConnectionDelay (const anna::Millisecond &maxConnectionDelay) |
const anna::Millisecond & | getMaxConnectionDelay () |
bool | bind () noexcept(false) |
void | setClientCER (const anna::DataBlock &cer) noexcept(false) |
void | setClientCER (const std::string &cerPathFile) noexcept(false) |
void | setClientCER (const anna::U32 &applicationId) noexcept(false) |
void | setClientDWR (const anna::DataBlock &dwr) noexcept(false) |
void | setClientDWR (const std::string &dwrPathFile="") noexcept(false) |
void | setWatchdogPeriod (const anna::Millisecond &wp) noexcept(false) |
int | getNumberOfClientSessionsPerServer () const |
void | setNumberOfClientSessionsPerServer (int numberOfClientSessionsPerServer) |
ClientSession * | findClientSession (const std::string &addr, int port, int socketId, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
ClientSession * | findClientSession (const std::string &key, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
Server * | findServer (const std::string &addr, int port, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
Entity * | findEntity (const socket_v &socketList, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
Entity * | findEntity (const std::string &addr1, int port1, const std::string &addr2, int port2, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
Entity * | createEntity (const socket_v &socketList, const std::string &description="") noexcept(false) |
Entity * | createEntity (const std::string &addr1, int port1, const std::string &addr2, int port2, const std::string &description="") noexcept(false) |
LocalServer * | findLocalServer (const std::string &addr, int port, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
ServerSession * | findServerSession (int socketId, anna::Exception::Mode::_v emode=anna::Exception::Mode::Throw) noexcept(false) |
LocalServer * | createLocalServer (const std::string &addr, int port=Session::DefaultPort, int maxConnections=-1, const anna::Millisecond &allowedInactivityTime=ServerSession::DefaultAllowedInactivityTime, int category=1, const std::string &description="") noexcept(false) |
void | close (bool destroy=false) noexcept(false) |
void | closeEntities (bool destroy=false) noexcept(false) |
void | closeEntity (Entity *entity, bool destroy=false) noexcept(false) |
void | closeLocalServers (bool destroy=false) noexcept(false) |
void | closeLocalServer (LocalServer *localServer, bool destroy=false) noexcept(false) |
int | getOTARequestsForEntities () const |
int | getOTARequestsForLocalServers () const |
int | getOTARequests () const |
bool | idleForEntities () const |
bool | idleForLocalServers () const |
bool | idle () const |
bool | broadcastEntities (const Message *message) noexcept(false) |
bool | broadcastEntities (const Message &message) noexcept(false) |
bool | broadcastLocalServers (const Message *message) noexcept(false) |
bool | broadcastLocalServers (const Message &message) noexcept(false) |
virtual std::string | asString (void) const |
virtual anna::xml::Node * | asXML (anna::xml::Node *parent) const |
virtual void | bindingClientSession (const ClientSession *) const |
virtual void | readDPA (anna::DataBlock &dpa, const anna::DataBlock &dpr) const |
void | setCEA (const std::string &ceaPathfile) |
const std::string & | getCEA () const |
virtual void | readCEA (anna::DataBlock &cea, const anna::DataBlock &cer) const |
virtual void | readDWA (anna::DataBlock &dwa, const anna::DataBlock &dwr) const |
const Response * | sendRealmHost (const Message *message, const std::string &destinationRealm, const std::string &destinationHost="") noexcept(false) |
void | resetStatistics () |
void | lazyInitialize () noexcept(false) |
Public Member Functions inherited from anna::app::Component | |
virtual | ~Component () |
void | attach () noexcept(false) |
Public Member Functions inherited from anna::Component | |
const char * | getClassName () const |
Public Member Functions inherited from anna::Mutex | |
Mutex (const Mode::_v mode=Mode::Recursive) | |
virtual | ~Mutex () |
virtual void | lock () noexcept(false) |
virtual void | unlock () |
bool | trylock () noexcept(false) |
operator const pthread_mutex_t * () const | |
Protected Member Functions | |
Engine (const char *className, const stack::Dictionary *baseProtocolDictionary) | |
Server * | createServer (Entity *, const socket_t &) noexcept(false) |
void | closeServer (Server *, bool) noexcept(false) |
ClientSession * | createClientSession (Server *, int) noexcept(false) |
void | closeClientSession (ClientSession *, bool) noexcept(false) |
Server * | allocateServer () |
void | releaseServer (Server *) |
ClientSession * | allocateClientSession () |
void | releaseClientSession (ClientSession *) |
virtual Entity * | allocateEntity () |
virtual void | releaseEntity (Entity *) |
virtual LocalServer * | allocateLocalServer () |
virtual void | releaseLocalServer (LocalServer *) |
codec::Engine * | getBaseProtocolCodecEngine () const |
Protected Member Functions inherited from anna::app::Component | |
Component (const char *className) | |
State::_v | getState () const |
void | addPredecessor (const char *componentName) |
void | initialize () noexcept(false) |
void | stop () |
virtual void | kill () |
Protected Member Functions inherited from anna::Component | |
Component (const char *className) | |
Component (const Component &other) | |
Protected Member Functions inherited from anna::Safe | |
Safe () | |
Friends | |
class | Session |
class | ClientSession |
class | ServerSession |
class | ServerSocket |
class | Server |
class | Entity |
class | LocalServer |
Additional Inherited Members | |
Protected Attributes inherited from anna::Component | |
const std::string | a_className |
General manager for connections to several diameter servers and from diameter clients.
Optimizes creation, finding and releasing of established client-sessions to a certain number of diameter servers through entities. Optimizes creation, finding and releasing of established server-sessions from a certain number of diameter clients through local servers.
Implementation example:
|
protected |
Constructor.
className | Component class name |
baseProtocolDictionary | This will be used internally when calling @readCEA, @readDPA and @readDWA on servers, and also used during base protocol messages tracing (if debug traces are enabled). You could provide NULL, but you must be sure that neither of the former situations are going to happen or an exception will be thrown (using setClientCER and setClientDWR with DataBlock arguments, expects externally encoded messages and could help). It is recommended to set a base protocol dictionary loading 'source/diameter/stack/setups' dictionaries (for example 'avps_ietf.xml' plus 'commands_baseProtocol.xml'), or using the dictionary creation API. The dictionary could also be an application stack, the only condition is containing the resources to build base protocol messages. |
|
protected |
|
inlineprotectedvirtual |
Entity allocator method.
It is recommended to use anna::Recycler for entities creation/releasing.
|
inlineprotectedvirtual |
Local server allocator method.
It is recommended to use anna::Recycler for entities creation/releasing.
|
protected |
|
virtual |
Class string representation
Reimplemented from anna::app::Component.
|
virtual |
Class XML representation.
parent | XML node over which we will put instance information. |
Reimplemented from anna::app::Component.
|
noexcept |
Binds engine entities.
|
inlinevirtual |
|
noexcept |
Sent a message to all the engine entities. It is used, i.e., in Disconnect-Peer-Request procedure over the engine.
message | Message which is being sent. |
|
inlinenoexcept |
|
noexcept |
Sent a message through all the engine local servers. It is used, i.e., in Disconnect-Peer-Request procedure over the engine.
message | Message which is being sent. |
|
inlinenoexcept |
|
inlinenoexcept |
Close all the engine resources (entities and local servers) Optionally all resources may be freed passing true
destroy | Free all engine entity resources |
|
protectednoexcept |
|
noexcept |
Close all the engine entities (close servers, then close client-sessions within them). Depending on client-session configuration ('OnDisconnect' behaviour), pending answers will be wait (graceful) or ignored (immediate-abrupt close). Optionally all entities resources may be freed passing true; in this case, close is immediately performed:
destroy | Free all engine entity resources |
|
noexcept |
Close entity servers (then, client-sessions included) and optionally free resources including entity itself. If entity is null, this operation has no effect.
entity | Diameter entity to be closed. |
destroy | Deletes entity over the engine and all its resources. |
|
noexcept |
Close local server socket and its children server sessions. This is useful when detecting service lost. When service is ready to handle traffic, a new server socket would be created by mean #LocalServer::enable() and new connections could be accepted. Optionally local server resources may be freed passing true.
localServer | Local server to be closed. |
destroy | Deletes local server over engine and all its resources (server sessions within it). |
|
noexcept |
Close all the engine local server sockets including their children server sessions. Optionally all local server resources may be freed passing true.
destroy | Free all engine local servers resources and server sessions within them. |
|
protectednoexcept |
|
protectednoexcept |
|
noexcept |
Creates a diameter entity with provided parameters.
Depending on auto-bind configuration, capabilities exchange request will be or won't be performed over the entity client-sessions.
socketList | Diameter server priority list (priority-ordered) in order to define whole entity. |
description | Optional entity description (empty by default) |
|
noexcept |
Creates a standard (dual) diameter entity with provided parameters.
Depending on auto-bind configuration, capabilities exchange request will be or won't be performed over the entity client-sessions.
addr1 | Diameter primary server address (ip or hostname). |
port1 | Diameter primary server port. |
addr2 | Diameter secondary server address (ip or hostname). |
port2 | Diameter secondary server port. |
description | Optional entity description (empty by default) |
|
noexcept |
Creates a diameter local server with provided parameters.
Server socket address could be an IPv4 or hostname. Default port will be standard 3868 for diameter agents, but any other could be configured. Socket server could be created with any max accepted connections: zero value means temporarily disabled and negative values assume no limit (shared bind) for incomming connections.
addr | Diameter server socket address (ip or hostname). |
port | Diameter server socket port (standard 3868 by default). |
maxConnections | Diameter server max sessions allowed (no limit by default). |
allowedInactivityTime | Max inactivity time for server sessions over the local server before being reset. |
category | Optional socket server category (1 by default). |
description | Optional socket server description (empty by default). |
|
protectednoexcept |
|
noexcept |
Returns client-session instance identified by (address, port, socketId) provided.
addr | Diameter server address (ip or hostname). |
port | Diameter server port. |
socketId | Diameter server socket id. |
emode | Action when no client-session is found with provided parameters (Throw/Ignore). |
|
noexcept |
Same as findClientSession, but providing client session key (<address>:<port>|<socket id>="">)
|
noexcept |
Returns entity instance identified by internal index.
socketList | Diameter entity servers list. |
emode | Action when no client-session is found with provided parameters (Throw/Ignore). |
|
noexcept |
Returns entity instance identified by internal index.
addr1 | Diameter primary server address (ip or hostname). |
port1 | Diameter primary server port. |
addr2 | Diameter secondary server address (ip or hostname). |
port2 | Diameter secondary server port. |
emode | Action when no client-session is found with provided parameters (Throw/Ignore). |
|
noexcept |
Returns local server instance identified by pair (address, port) provided.
addr | Diameter server socket address (ip or hostname). |
port | Diameter server socket port. |
emode | Action when no local server is found with provided parameters (Throw/Ignore). |
|
noexcept |
Returns server instance identified by pair (address, port) provided.
addr | Diameter server address (ip or hostname). |
port | Diameter server port. |
emode | Action when no client-session is found with provided parameters (Throw/Ignore). |
|
noexcept |
Returns server-session instance identified by INetAddress serialization provided.
socketId | Hash for Client Socket INetAddress serialization |
emode | Action when no server-session is found with provided parameters (Throw/Ignore). |
|
inline |
|
inlineprotected |
|
inline |
|
inline |
Gets the milliseconds wait to achieve a client connection to server by mean connect primitive. Returns the global engine value, but it could be overwritten through each client session (#ClientSession::setMaxConnectionDelay). Default value is 'anna::comm::ClientSocket::DefaultMaxConnectionDelay'.
|
inline |
|
inline |
|
inline |
|
inline |
Gets the number of requests messages over-the-air for entities plus local servers.
int anna::diameter::comm::Engine::getOTARequestsForEntities | ( | ) | const |
Gets the number of requests messages over-the-air for entities.
int anna::diameter::comm::Engine::getOTARequestsForLocalServers | ( | ) | const |
Gets the number of requests messages over-the-air for local servers.
|
inline |
Returns idle state (no pending answers for entities or local servers).
|
inline |
Returns idle state (no pending answers) for entities.
|
inline |
Returns idle state (no pending answers).
|
noexcept |
Engine lazy initialization. Used if the engine is created when application is already running; for example on dynamic realms registration. At the moment is not actually needed (nothing is done at initialization), but it is recommended to start the component and set its state as 'running' from the point of view of the application.
|
noexcept |
Propagate auto recovery configuration to entities within engine. Recovery period is configured at anna::comm::Communicator::setRecoveryTime (5 seconds by default). All the client client-sessions created throught createEntity, will be created based on the engine auto-recovery value (enabled by default). You could access entities, servers or client-sessions independently to use this method, but recovery time should be updated through communicator and will apply for new created connections.
autoRecovery | Auto recovery indicator. True by default. |
|
virtual |
Class user should implement this method in order to define Capabilities-Exchange-Answer for received CER over server socket. Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name). Default implementation imply CEA with DIAMETER_SUCCESS Result-Code, and own domain node parameters, but application should analyze the CER message in order to accept it or not (with apropiate non-success Result-Code). If was invoked, a message from file is used instead of default implementation. Any other implementation is responsible to build a valid CEA diameter message, even ignoring a possible cea from file when is used:
If one peer sends a CER message to another Peer and receiver does not have support for
1) any common application then it must return the CEA with Result-Code Avp set to DIAMETER_NO_COMMON_APPLICATION and should disconnect the transport layer connection (automatically done by diameter::comm module). 2) no common security mechanism then it must return the CEA with Result-Code Avp set to DIAMETER_NO_COMMON_SECURITY and should disconnect the transport layer connection (automatically done by diameter::comm module). 3) if CER is received from any unknown peer then receiver should discard the message, or send the CEA with the Result-Code Avp set to DIAMETER_UNKNOWN_PEER.
If the local implementation policy permits to receive CER from unknown hosts, a successful CEA MAY be returned, and the life time of the peer entry in PEER-Table is equal to the lifetime of the transport connection. If in any case transport connection fails then all the pending transactions destined to the unknown peer can be discarded.
The CER and CEA messages MUST NOT be proxied, redirected or relayed. Since CER/CEA messages can not be proxied, but still it is possible that proxy will receive a CER message and proxy does not have any peer to handle the application requested in CER, in this case proxy set the E bit in CEA and set the Result-Code Avp to DIAMETER_UNABLE_TO_DELIVER, sends back to CER generator peer.
cea | CEA datablock passed as reference. Empty cea implies to discard CER received. |
cer | Corresponding CER received (sequence values must be taken into account in order to build CEA) |
|
virtual |
Class user should implement this method in order to define Disconnect-Peer-Answer for last received DPR. Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name). Default implementation imply DPA with DIAMETER_SUCCESS Result-Code, allowing remote disconnection. Any other implementation is responsible to build a valid DPA diameter message. DPR/DPA procedure is disabled with empty definition of this method: no DPA will be sent when DPR is received.
dpa | DPA datablock passed as reference |
dpr | Corresponding DPR received (sequence values must be taken into account in order to build DPA) |
|
virtual |
Class user should implement this method in order to define Device-Watchdog-Answer for received DWR over server socket. Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name). Default implementation imply DWA with DIAMETER_SUCCESS Result-Code, and own domain node parameters. Any other implementation is responsible to build a valid DWA diameter message.
dwa | DWA datablock passed as reference |
dwr | Corresponding DWR received (sequence values must be taken into account in order to build DWA) |
|
protected |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
protected |
void anna::diameter::comm::Engine::resetStatistics | ( | ) |
Reset engine statistics. At the moment, only diameter servers processing time is observed.
|
noexcept |
DRA basics: CER information is gathered on every server session managed by the diameter comm engine. You could send the message to a specific realm, and optionally you could restrict a host inside it. This is common for requests (answers are normally sent through the same source server session where the request was received). Exception will be thrown if not found an available server session for the Destination-Realm and/or Destination-Host provided
destinationRealm | If empty, NULL is returned, because is nonsense to specify a host out of realm context |
destinationHost | If empty, no restriction is applied within the target realm node. Random delivery is applied for the available server sessions |
|
inline |
Sets automatic connection bind indicator for client-sessions. If not asigned, it will be true.
autoBind | Value for automatic connection bind. |
In order to change bind timer, first client-session must be created without autobind, modify time parameter and then invoking bind.
|
inline |
|
noexcept |
Sets CER diameter messages to be used over created client-sessions.
cer | Capabilities-Exchange-Request message (encoded) for the client-sessions bind. |
|
noexcept |
Sets CER diameter messages to be used over created client-sessions.
cerPathFile | Capabilities-Exchange-Request xml message path file for the client-sessions bind. |
|
noexcept |
Sets DEFAULT CER diameter messages to be used over created client-sessions.
applicationId | Application-Id for the Auth-Application-Id AVP. |
|
noexcept |
Sets DWR for diameter keep-alive over client-sessions
dwr | Device-Watchdog-Request message (encoded) for the client-sessions keep-alive. |
|
noexcept |
Sets DWR for diameter keep-alive over client-sessions
cerPathFile | Device-Watchdog-Request xml message path file for the client-sessions keep-alive. If empty provided, a DEFAULT DWR will be built. |
|
inline |
Sets the milliseconds wait to achieve a client connection to server by mean connect primitive. This is a general value for born client-sessions over engine. Particular configuration could be done through #ClientSession::setMaxConnectionDelay.
maxConnectionDelay | Milliseconds wait to get connection |
|
inline |
Sets the number of client-sessions per server. Its recommended to set this global configuration although it is possible to configure each client-session separately.
numberOfClientSessionsPerServer | Number of client-sessions per server. |
void anna::diameter::comm::Engine::setOriginHostName | ( | const std::string & | originHostName | ) |
Diameter application origin host
originHostName | Used to configure the Origin-Host for outgoing messages. If not configured or empty string provided, hostname (system name) will be set. |
void anna::diameter::comm::Engine::setOriginRealmName | ( | const std::string & | originRealmName | ) |
Diameter application node origin realm
originRealmName | Used to configure the Origin-Realm for outgoing messages. If not configured or empty string provided, host domainname will be set. |
|
noexcept |
Sets the watchdog period (DWR) for client-sessions. Its recommended to set this global configuration although it is possible to configure each client-session separately.
wp | Watchdog period. |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |