From: Eduardo Ramos Testillano Date: Fri, 17 Apr 2015 23:58:22 +0000 (+0200) Subject: Gives application control over event DPA received for both client and entity X-Git-Tag: REFACTORING_TESTING_LIBRARY~157 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=6c4aae8b2e861a6cbca6962611624a5aadadd6ad;p=anna.git Gives application control over event DPA received for both client and entity --- diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 35b283c..4b36441 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -300,6 +300,7 @@ class MyDiameterEntity : public anna::diameter::comm::Entity { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); + void eventDPA(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); // Reimplementation int readSocketId(const anna::diameter::comm::Message* message, int maxClientSessions) const throw(); @@ -310,6 +311,7 @@ class MyLocalServer : public anna::diameter::comm::LocalServer { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); + void eventDPA(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); }; class MyDiameterEngine : public anna::diameter::comm::Engine { @@ -2417,8 +2419,27 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe-ans-unknown", clientSession->asString()); } +void MyDiameterEntity::eventDPA(anna::diameter::comm::ClientSession *clientSession, const anna::DataBlock &message) +throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("launcher::MyDiameterEntity", "eventDPA", ANNA_FILE_LOCATION)); + // Performance stats: + Launcher& my_app = static_cast (anna::app::functions::getApp()); + // CommandId: + anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); + LOGDEBUG + ( + std::string msg = "Disconnect-Peer-Answer received from entity: "; + msg += anna::diameter::functions::commandIdAsPairString(cid); + msg += " | DiameterServer: "; + msg += anna::functions::socketLiteralAsString(clientSession->getAddress(), clientSession->getPort()); + msg += " | EventTime: "; + msg += anna::time::functions::currentTimeAsString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); - + // Write reception + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString()); +} void MyLocalServer::eventRequest(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) throw(anna::RuntimeException) { @@ -2618,6 +2639,26 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc-ans-unknown", serverSession->asString()); } +void MyLocalServer::eventDPA(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) +throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventDPA", ANNA_FILE_LOCATION)); + // Performance stats: + Launcher& my_app = static_cast (anna::app::functions::getApp()); + // CommandId: + anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); + LOGDEBUG + ( + std::string msg = "Disconnect-Peer-Answer response received from client: "; + msg += anna::diameter::functions::commandIdAsPairString(cid); + msg += " | DiameterServer: "; + msg += anna::functions::socketLiteralAsString(serverSession->getAddress(), serverSession->getPort()); + msg += " | EventTime: "; + msg += anna::time::functions::currentTimeAsString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); + + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString()); +} anna::xml::Node* Launcher::asXML(anna::xml::Node* parent) const throw() { diff --git a/include/anna/diameter.comm/ClientSession.hpp b/include/anna/diameter.comm/ClientSession.hpp index 805b8d7..a949b56 100644 --- a/include/anna/diameter.comm/ClientSession.hpp +++ b/include/anna/diameter.comm/ClientSession.hpp @@ -282,6 +282,14 @@ private: */ void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException); + /** + Handler for diameter server (client-session) Disconnect-Peer-Answer messages + + \param response Answer data block object without context match + */ + void eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException); + + /** * Handlers for receptions diff --git a/include/anna/diameter.comm/Entity.hpp b/include/anna/diameter.comm/Entity.hpp index 65f45dc..d732ef8 100644 --- a/include/anna/diameter.comm/Entity.hpp +++ b/include/anna/diameter.comm/Entity.hpp @@ -465,6 +465,16 @@ protected: */ virtual void eventUnknownResponse(ClientSession *clientSession, const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + /** + Handler for diameter session Disconnect-Peer-Answer messages + + \param clientSession ClientSession from which request has been received + \param response Answer data block object without context match + */ + virtual void eventDPA(ClientSession *clientSession, const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + + + friend class Engine; friend class Server; diff --git a/include/anna/diameter.comm/LocalServer.hpp b/include/anna/diameter.comm/LocalServer.hpp index fff7912..0fe05af 100644 --- a/include/anna/diameter.comm/LocalServer.hpp +++ b/include/anna/diameter.comm/LocalServer.hpp @@ -406,6 +406,14 @@ protected: */ virtual void eventUnknownResponse(ServerSession* serverSession, const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + /** + Handler for diameter client Disconnect-Peer-Answer messages + + \param serverSession ServerSession from which request has been received + \param response Answer data block object without context match + */ + virtual void eventDPA(ServerSession* serverSession, const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + friend class anna::diameter::comm::Timer; friend class Engine; diff --git a/include/anna/diameter.comm/Server.hpp b/include/anna/diameter.comm/Server.hpp index aaadbf8..f7c623d 100644 --- a/include/anna/diameter.comm/Server.hpp +++ b/include/anna/diameter.comm/Server.hpp @@ -333,6 +333,15 @@ protected: */ virtual void eventUnknownResponse(ClientSession *clientSession, const anna::DataBlock& response) throw(anna::RuntimeException); + /** + Handler for diameter server (client-session) Disconnect-Peer-Answer messages + + \param clientSession ClientSession from which request has been received + \param response Answer data block object without context match + */ + virtual void eventDPA(ClientSession *clientSession, const anna::DataBlock& response) throw(anna::RuntimeException); + + friend class Engine; friend class ClientSession; diff --git a/include/anna/diameter.comm/ServerSession.hpp b/include/anna/diameter.comm/ServerSession.hpp index 10bf001..048701e 100644 --- a/include/anna/diameter.comm/ServerSession.hpp +++ b/include/anna/diameter.comm/ServerSession.hpp @@ -219,6 +219,14 @@ private: */ void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException); + /** + Handler for diameter client Disconnect-Peer-Answer messages + + \param response Answer data block object without context match + */ + void eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException); + + /** * Handlers for receptions diff --git a/include/anna/diameter.comm/Session.hpp b/include/anna/diameter.comm/Session.hpp index fa4a81c..f171eff 100644 --- a/include/anna/diameter.comm/Session.hpp +++ b/include/anna/diameter.comm/Session.hpp @@ -379,6 +379,13 @@ protected: */ virtual void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + /** + Handler for diameter session Disconnect-Peer-Answer messages + + \param response Answer data block object without context match + */ + virtual void eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException) = 0; + /** diff --git a/source/diameter.comm/ClientSession.cpp b/source/diameter.comm/ClientSession.cpp index d521b60..8adb77b 100644 --- a/source/diameter.comm/ClientSession.cpp +++ b/source/diameter.comm/ClientSession.cpp @@ -482,6 +482,11 @@ void ClientSession::eventUnknownResponse(const anna::DataBlock& response) throw( a_parent->eventUnknownResponse(this, response); } +void ClientSession::eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException) { + // Inform father server: + a_parent->eventDPA(this, response); +} + //------------------------------------------------------------------------------------------ @@ -679,7 +684,6 @@ throw(anna::RuntimeException) { requestMessage->setRequestServerSessionKey(response->getRequest()->getRequestServerSessionKey()); // -1 means unkown/unset if(cid != helpers::base::COMMANDID__Disconnect_Peer_Answer) { - // don't progress DPA: unbind is automatically performed and not open to any application decision try { response->setMessage(&db); // Restore received datablock @@ -698,6 +702,11 @@ throw(anna::RuntimeException) { ex.trace(); } } + else { // DPA + // unbind is automatically performed, anyway we can inform to the application just in case some additional + // procedure could be issued: + eventDPA(db); + } response_erase(response); diff --git a/source/diameter.comm/Server.cpp b/source/diameter.comm/Server.cpp index 43a3b28..c34fd73 100644 --- a/source/diameter.comm/Server.cpp +++ b/source/diameter.comm/Server.cpp @@ -362,6 +362,12 @@ void Server::eventUnknownResponse(ClientSession *clientSession, const anna::Data a_parent->eventUnknownResponse(clientSession, response); } +void Server::eventDPA(ClientSession *clientSession, const anna::DataBlock & response) throw(anna::RuntimeException) { + // Inform father server: + a_parent->eventDPA(clientSession, response); +} + + void Server::availabilityLost() throw() { a_available = false; std::string socket = anna::functions::socketLiteralAsString(a_socket.first, a_socket.second); diff --git a/source/diameter.comm/ServerSession.cpp b/source/diameter.comm/ServerSession.cpp index ce4f3ce..90da697 100644 --- a/source/diameter.comm/ServerSession.cpp +++ b/source/diameter.comm/ServerSession.cpp @@ -346,6 +346,10 @@ void ServerSession::eventUnknownResponse(const anna::DataBlock& response) throw( a_parent->eventUnknownResponse(this, response); } +void ServerSession::eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException) { + // Inform father server: + a_parent->eventDPA(this, response); +} //------------------------------------------------------------------------------------------ // Se invoca desde el diameter::comm::Receiver @@ -452,6 +456,9 @@ throw(anna::RuntimeException) { doUnbind = true; } } + + eventDPA(db); + } else if(cid == helpers::base::COMMANDID__Device_Watchdog_Answer) { // non usual (server should not send DWR's) oamModule.count(OamModule::Counter::DWAReceived); }