Gives application control over event DPA received for both client and entity
authorEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Fri, 17 Apr 2015 23:58:22 +0000 (01:58 +0200)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Fri, 17 Apr 2015 23:58:22 +0000 (01:58 +0200)
example/diameter/launcher/main.cpp
include/anna/diameter.comm/ClientSession.hpp
include/anna/diameter.comm/Entity.hpp
include/anna/diameter.comm/LocalServer.hpp
include/anna/diameter.comm/Server.hpp
include/anna/diameter.comm/ServerSession.hpp
include/anna/diameter.comm/Session.hpp
source/diameter.comm/ClientSession.cpp
source/diameter.comm/Server.cpp
source/diameter.comm/ServerSession.cpp

index 35b283c..4b36441 100644 (file)
@@ -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 <Launcher&>(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 <Launcher&>(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() {
index 805b8d7..a949b56 100644 (file)
@@ -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
index 65f45dc..d732ef8 100644 (file)
@@ -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;
index fff7912..0fe05af 100644 (file)
@@ -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;
index aaadbf8..f7c623d 100644 (file)
@@ -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;
index 10bf001..048701e 100644 (file)
@@ -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
index fa4a81c..f171eff 100644 (file)
@@ -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;
+
 
 
   /**
index d521b60..8adb77b 100644 (file)
@@ -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);
 
index 43a3b28..c34fd73 100644 (file)
@@ -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);
index ce4f3ce..90da697 100644 (file)
@@ -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);
   }