New ApplicationMessageOamModule in diameter::comm, to dynamically manage application...
[anna.git] / include / anna / diameter.comm / ApplicationMessageOamModule.hpp
diff --git a/include/anna/diameter.comm/ApplicationMessageOamModule.hpp b/include/anna/diameter.comm/ApplicationMessageOamModule.hpp
new file mode 100644 (file)
index 0000000..c9c5b0d
--- /dev/null
@@ -0,0 +1,162 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#ifndef anna_diameter_comm_ApplicationMessageOamModule_hpp
+#define anna_diameter_comm_ApplicationMessageOamModule_hpp
+
+
+// Project
+#include <anna/core/mt/Mutex.hpp>
+#include <anna/core/Singleton.hpp>
+#include <anna/core/define.autoenum.hpp>
+#include <anna/core/oam/Module.hpp>
+
+// Standard
+#include <string>
+#include <map>
+
+namespace anna {
+
+namespace diameter {
+
+namespace comm {
+
+
+/**
+  Special OAM module which tracks a replica for a set of counter types for each different application message managed by the
+  communication layer in a specific stack id. For example, if one process is managing CCR/A, RAR/A for Gx and AAR/A, RAR/A for Rx,
+  then two counter scopes should be registered (one for Gx, another for Rx). Each scope will store counters sets for each diameter
+  message. Having N counters within each scope (for example N=14), the total capacity is N/(number of counter types) different
+  message codes:
+
+  <pre>
+    Scope for Gx:
+
+      Credit-Control-Request_SentOK_AsClient
+      Credit-Control-Request_SentNOK_AsClient
+      Credit-Control-Answer_SentOK_AsClient
+      Credit-Control-Answer_SentNOK_AsClient
+      Credit-Control-Request_Received_AsClient
+      Credit-Control-Answer_Received_AsClient
+      Credit-Control-Answer_UnknownReceived_AsClient
+      Credit-Control-Request_SentOK_AsServer
+      Credit-Control-Request_SentNOK_AsServer
+      Credit-Control-Answer_SentOK_AsServer
+      Credit-Control-Answer_SentNOK_AsServer
+      Credit-Control-Request_Received_AsServer
+      Credit-Control-Answer_Received_AsServer
+      Credit-Control-Answer_UnknownReceived_AsServer
+      Re-Auth-Request_SentOK_AsClient
+      Re-Auth-Request_SentNOK_AsClient
+      Re-Auth-Answer_SentOK_AsClient
+      Re-Auth-Answer_SentNOK_AsClient
+      Re-Auth-Request_Received_AsClient
+      Re-Auth-Answer_Received_AsClient
+      Re-Auth-Answer_UnknownReceived_AsClient
+      Re-Auth-Request_SentOK_AsServer
+      Re-Auth-Request_SentNOK_AsServer
+      Re-Auth-Answer_SentOK_AsServer
+      Re-Auth-Answer_SentNOK_AsServer
+      Re-Auth-Request_Received_AsServer
+      Re-Auth-Answer_Received_AsServer
+      Re-Auth-Answer_UnknownReceived_AsServer
+   
+    Scope for Rx:
+
+      AA-Request_SentOK_AsClient
+      AA-Request_SentNOK_AsClient
+      AA-Answer_SentOK_AsClient
+      AA-Answer_SentNOK_AsClient
+      AA-Request_Received_AsClient
+      AA-Answer_Received_AsClient
+      AA-Answer_UnknownReceived_AsClient
+      AA-Request_SentOK_AsServer
+      AA-Request_SentNOK_AsServer
+      AA-Answer_SentOK_AsServer
+      AA-Answer_SentNOK_AsServer
+      AA-Request_Received_AsServer
+      AA-Answer_Received_AsServer
+      AA-Answer_UnknownReceived_AsServer
+      Re-Auth-Request_SentOK_AsClient
+      Re-Auth-Request_SentNOK_AsClient
+      Re-Auth-Answer_SentOK_AsClient
+      Re-Auth-Answer_SentNOK_AsClient
+      Re-Auth-Request_Received_AsClient
+      Re-Auth-Answer_Received_AsClient
+      Re-Auth-Answer_UnknownReceived_AsClient
+      Re-Auth-Request_SentOK_AsServer
+      Re-Auth-Request_SentNOK_AsServer
+      Re-Auth-Answer_SentOK_AsServer
+      Re-Auth-Answer_SentNOK_AsServer
+      Re-Auth-Request_Received_AsServer
+      Re-Auth-Answer_Received_AsServer
+      Re-Auth-Answer_UnknownReceived_AsServer
+  </pre> 
+*/
+class ApplicationMessageOamModule : public anna::oam::Module, public anna::Singleton <ApplicationMessageOamModule> {
+
+  std::map<int /* message code */, int /* base offset */> a_messageMap;
+  std::map<unsigned int /* stack id */, int /* scope id */> a_stackMap;
+
+  int a_counter_types;
+
+  anna::Mutex a_mutex; // counter scope switch
+
+public:
+
+  struct Counter {
+    enum _v
+    {
+      None = -1,
+
+      Request_SentOK_AsClient,
+      Request_SentNOK_AsClient,
+      Answer_SentOK_AsClient,
+      Answer_SentNOK_AsClient,
+      Request_Received_AsClient,
+      Answer_Received_AsClient,
+      Answer_UnknownReceived_AsClient,
+
+      Request_SentOK_AsServer,
+      Request_SentNOK_AsServer,
+      Answer_SentOK_AsServer,
+      Answer_SentNOK_AsServer,
+      Request_Received_AsServer,
+      Answer_Received_AsServer,
+      Answer_UnknownReceived_AsServer
+    };
+
+    anna_declare_enum(Counter);
+  };
+
+  /* virtual */std::string getDefaultInternalCounterDescription(const int & counterType) const throw() { return Counter::asCString((Counter::_v)counterType); }
+
+  // map stack id with a scope id
+  void createStackCounterScope(int /* scope id */, unsigned int /* stack id */) throw(anna::RuntimeException);
+
+  // translate message code into offset and invoke parent class count method. The message applicationId will be used as stack id
+  void count (int messageCode, unsigned int stackId, const int & type, const int & amount = 1) throw(anna::RuntimeException);
+
+  // Number of different counter types for each message
+  int getCounterTypes() const throw() { return a_counter_types; }
+
+private:
+
+  // private constructor
+  ApplicationMessageOamModule() : anna::oam::Module("Application Message Comm OAM Events") { a_counter_types = Counter::calculateSize(); }
+
+
+  friend class anna::Singleton <ApplicationMessageOamModule>;
+};
+
+}
+}
+}
+
+#endif
+