c9c5b0dedc54f6311a86a8ba6ecd5d5ca228bb5b
[anna.git] / include / anna / diameter.comm / ApplicationMessageOamModule.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_diameter_comm_ApplicationMessageOamModule_hpp
10 #define anna_diameter_comm_ApplicationMessageOamModule_hpp
11
12
13 // Project
14 #include <anna/core/mt/Mutex.hpp>
15 #include <anna/core/Singleton.hpp>
16 #include <anna/core/define.autoenum.hpp>
17 #include <anna/core/oam/Module.hpp>
18
19 // Standard
20 #include <string>
21 #include <map>
22
23 namespace anna {
24
25 namespace diameter {
26
27 namespace comm {
28
29
30 /**
31   Special OAM module which tracks a replica for a set of counter types for each different application message managed by the
32   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,
33   then two counter scopes should be registered (one for Gx, another for Rx). Each scope will store counters sets for each diameter
34   message. Having N counters within each scope (for example N=14), the total capacity is N/(number of counter types) different
35   message codes:
36
37   <pre>
38     Scope for Gx:
39
40       Credit-Control-Request_SentOK_AsClient
41       Credit-Control-Request_SentNOK_AsClient
42       Credit-Control-Answer_SentOK_AsClient
43       Credit-Control-Answer_SentNOK_AsClient
44       Credit-Control-Request_Received_AsClient
45       Credit-Control-Answer_Received_AsClient
46       Credit-Control-Answer_UnknownReceived_AsClient
47       Credit-Control-Request_SentOK_AsServer
48       Credit-Control-Request_SentNOK_AsServer
49       Credit-Control-Answer_SentOK_AsServer
50       Credit-Control-Answer_SentNOK_AsServer
51       Credit-Control-Request_Received_AsServer
52       Credit-Control-Answer_Received_AsServer
53       Credit-Control-Answer_UnknownReceived_AsServer
54       Re-Auth-Request_SentOK_AsClient
55       Re-Auth-Request_SentNOK_AsClient
56       Re-Auth-Answer_SentOK_AsClient
57       Re-Auth-Answer_SentNOK_AsClient
58       Re-Auth-Request_Received_AsClient
59       Re-Auth-Answer_Received_AsClient
60       Re-Auth-Answer_UnknownReceived_AsClient
61       Re-Auth-Request_SentOK_AsServer
62       Re-Auth-Request_SentNOK_AsServer
63       Re-Auth-Answer_SentOK_AsServer
64       Re-Auth-Answer_SentNOK_AsServer
65       Re-Auth-Request_Received_AsServer
66       Re-Auth-Answer_Received_AsServer
67       Re-Auth-Answer_UnknownReceived_AsServer
68    
69     Scope for Rx:
70
71       AA-Request_SentOK_AsClient
72       AA-Request_SentNOK_AsClient
73       AA-Answer_SentOK_AsClient
74       AA-Answer_SentNOK_AsClient
75       AA-Request_Received_AsClient
76       AA-Answer_Received_AsClient
77       AA-Answer_UnknownReceived_AsClient
78       AA-Request_SentOK_AsServer
79       AA-Request_SentNOK_AsServer
80       AA-Answer_SentOK_AsServer
81       AA-Answer_SentNOK_AsServer
82       AA-Request_Received_AsServer
83       AA-Answer_Received_AsServer
84       AA-Answer_UnknownReceived_AsServer
85       Re-Auth-Request_SentOK_AsClient
86       Re-Auth-Request_SentNOK_AsClient
87       Re-Auth-Answer_SentOK_AsClient
88       Re-Auth-Answer_SentNOK_AsClient
89       Re-Auth-Request_Received_AsClient
90       Re-Auth-Answer_Received_AsClient
91       Re-Auth-Answer_UnknownReceived_AsClient
92       Re-Auth-Request_SentOK_AsServer
93       Re-Auth-Request_SentNOK_AsServer
94       Re-Auth-Answer_SentOK_AsServer
95       Re-Auth-Answer_SentNOK_AsServer
96       Re-Auth-Request_Received_AsServer
97       Re-Auth-Answer_Received_AsServer
98       Re-Auth-Answer_UnknownReceived_AsServer
99   </pre> 
100 */
101 class ApplicationMessageOamModule : public anna::oam::Module, public anna::Singleton <ApplicationMessageOamModule> {
102
103   std::map<int /* message code */, int /* base offset */> a_messageMap;
104   std::map<unsigned int /* stack id */, int /* scope id */> a_stackMap;
105
106   int a_counter_types;
107
108   anna::Mutex a_mutex; // counter scope switch
109
110 public:
111
112   struct Counter {
113     enum _v
114     {
115       None = -1,
116
117       Request_SentOK_AsClient,
118       Request_SentNOK_AsClient,
119       Answer_SentOK_AsClient,
120       Answer_SentNOK_AsClient,
121       Request_Received_AsClient,
122       Answer_Received_AsClient,
123       Answer_UnknownReceived_AsClient,
124
125       Request_SentOK_AsServer,
126       Request_SentNOK_AsServer,
127       Answer_SentOK_AsServer,
128       Answer_SentNOK_AsServer,
129       Request_Received_AsServer,
130       Answer_Received_AsServer,
131       Answer_UnknownReceived_AsServer
132     };
133
134     anna_declare_enum(Counter);
135   };
136
137   /* virtual */std::string getDefaultInternalCounterDescription(const int & counterType) const throw() { return Counter::asCString((Counter::_v)counterType); }
138
139   // map stack id with a scope id
140   void createStackCounterScope(int /* scope id */, unsigned int /* stack id */) throw(anna::RuntimeException);
141
142   // translate message code into offset and invoke parent class count method. The message applicationId will be used as stack id
143   void count (int messageCode, unsigned int stackId, const int & type, const int & amount = 1) throw(anna::RuntimeException);
144
145   // Number of different counter types for each message
146   int getCounterTypes() const throw() { return a_counter_types; }
147
148 private:
149
150   // private constructor
151   ApplicationMessageOamModule() : anna::oam::Module("Application Message Comm OAM Events") { a_counter_types = Counter::calculateSize(); }
152
153
154   friend class anna::Singleton <ApplicationMessageOamModule>;
155 };
156
157 }
158 }
159 }
160
161 #endif
162