New ApplicationMessageOamModule in diameter::comm, to dynamically manage application...
[anna.git] / source / diameter.comm / ServerSession.cpp
index 1be1470..3c493d0 100644 (file)
@@ -22,6 +22,7 @@
 #include <anna/diameter.comm/Response.hpp>
 #include <anna/diameter.comm/Message.hpp>
 #include <anna/diameter.comm/OamModule.hpp>
+#include <anna/diameter.comm/ApplicationMessageOamModule.hpp>
 #include <anna/diameter.comm/TimerManager.hpp>
 #include <anna/diameter.comm/Timer.hpp>
 #include <anna/diameter.comm/LocalServer.hpp>
@@ -90,6 +91,8 @@ const Response* ServerSession::send(const Message* message) throw(anna::RuntimeE
   // Command id:
   bool isRequest;
   diameter::CommandId cid = message->getCommandId(isRequest);
+  diameter::ApplicationId aid = message->getApplicationId();
+
   LOGDEBUG(
     std::string msg = "Sending diameter message: ";
     msg += anna::diameter::functions::commandIdAsPairString(cid);
@@ -208,7 +211,7 @@ const Response* ServerSession::send(const Message* message) throw(anna::RuntimeE
     //
     updateOutgoingActivityTime();
     // OAM
-    countSendings(cid, true /* send ok */);
+    countSendings(cid, aid, true /* send ok */);
     // Trace non-application messages:
     LOGDEBUG(
 
@@ -225,7 +228,7 @@ const Response* ServerSession::send(const Message* message) throw(anna::RuntimeE
     if(fixed) message_nc->restoreSequencesAfterFix();  // restore to application sequences after fix
 
     // OAM
-    countSendings(cid, false /* send no ok */);
+    countSendings(cid, aid, false /* send no ok */);
     throw;
   }
 
@@ -395,6 +398,9 @@ throw(anna::RuntimeException) {
     }
 
     try {
+      // application message counters
+      ApplicationMessageOamModule::instantiate().count(cid.first, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Request_Received_AsServer);
+
       eventRequest(db);
     } catch(anna::RuntimeException& ex) {
       ex.trace();
@@ -444,7 +450,12 @@ throw(anna::RuntimeException) {
     oamModule.count(OamModule::Counter::AnswerReceivedUnknown);
     oamModule.count(OamModule::Counter::AnswerReceivedOnServerSessionUnknown);
     oamModule.activateAlarm(OamModule::Alarm::AnswerReceivedOnServerSessionUnknown);
+
+    // application message counters
+    ApplicationMessageOamModule::instantiate().count(cid.first, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Answer_UnknownReceived_AsServer);
+
     eventUnknownResponse(db);
+
     string msg(asString());
     msg += anna::functions::asString(" | Response received from client, for non registered context (HopByHop: %u)", hopByHop);
     throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
@@ -490,7 +501,12 @@ throw(anna::RuntimeException) {
       );
       diameter::codec::functions::setHopByHop((anna::DataBlock&)db, response->getRequest()->getRequestHopByHop());
       diameter::codec::functions::setEndToEnd((anna::DataBlock&)db, response->getRequest()->getRequestEndToEnd());
+
+      // application message counters
+      ApplicationMessageOamModule::instantiate().count(cid.first, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Answer_Received_AsServer);
+
       eventResponse(*response);
+
     } catch(anna::RuntimeException& ex) {
       ex.trace();
     }
@@ -696,8 +712,10 @@ void ServerSession::updateOutgoingActivityTime(void) throw() {
 //------------------------------------------------------------------------------
 //----------------------------------------------- ServerSession::countSendings()
 //------------------------------------------------------------------------------
-void ServerSession::countSendings(const diameter::CommandId & cid, bool ok)throw() {
+void ServerSession::countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok)throw() {
   OamModule &oamModule = OamModule::instantiate();
+  ApplicationMessageOamModule &appMsgOamModule = ApplicationMessageOamModule::instantiate();
+
   bool isRequest = cid.second;
 
   if(ok) {
@@ -710,6 +728,10 @@ void ServerSession::countSendings(const diameter::CommandId & cid, bool ok)throw
     else if(cid == helpers::base::COMMANDID__Device_Watchdog_Request) oamModule.count(OamModule::Counter::DWRSentOK);  // not usual
     else if(cid == helpers::base::COMMANDID__Disconnect_Peer_Answer) oamModule.count(OamModule::Counter::DPASentOK);
     else if(cid == helpers::base::COMMANDID__Disconnect_Peer_Request) oamModule.count(OamModule::Counter::DPRSentOK);
+    // Application messages:
+    else {
+      appMsgOamModule.count(cid.first, aid, isRequest ? ApplicationMessageOamModule::Counter::Request_SentOK_AsServer : ApplicationMessageOamModule::Counter::Answer_SentOK_AsServer);
+    }
   } else {
     // Main counters:
     oamModule.count(isRequest ? OamModule::Counter::RequestSentNOK : OamModule::Counter::AnswerSentNOK);
@@ -720,6 +742,10 @@ void ServerSession::countSendings(const diameter::CommandId & cid, bool ok)throw
     else if(cid == helpers::base::COMMANDID__Device_Watchdog_Request) oamModule.count(OamModule::Counter::DWRSentNOK);  // not usual
     else if(cid == helpers::base::COMMANDID__Disconnect_Peer_Answer) oamModule.count(OamModule::Counter::DPASentNOK);
     else if(cid == helpers::base::COMMANDID__Disconnect_Peer_Request) oamModule.count(OamModule::Counter::DPRSentNOK);
+    // Application messages:
+    else {
+      appMsgOamModule.count(cid.first, aid, isRequest ? ApplicationMessageOamModule::Counter::Request_SentNOK_AsServer : ApplicationMessageOamModule::Counter::Answer_SentNOK_AsServer);
+    }
   }
 }