d8f6fa66d82c6eebb7755de84c1c3faf84e23b4a
[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 and result code in case of answer, in a specific stack id. For example, if one process is managing CCR/A,
33   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
34   will store counters sets for each diameter event (message and optionally result code description). Having N counters within
35   each scope (for example N=14), the total capacity is N/(number of counter types) different events:
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
100     Note: all other combinations including the result code for answers
101           may be dynamically created.
102
103   </pre> 
104 */
105 class ApplicationMessageOamModule : public anna::oam::Module, public anna::Singleton <ApplicationMessageOamModule> {
106
107   std::map<std::string /* event id */, int /* base offset */> a_eventMap;
108   std::map<unsigned int /* stack id */, int /* scope id */> a_stackMap;
109
110   int a_counter_types;
111
112   anna::Mutex a_mutex; // counter scope switch
113
114 public:
115
116   struct Counter {
117     enum _v
118     {
119       None = -1,
120
121       Request_SentOK_AsClient,
122       Request_SentNOK_AsClient,
123       Answer_SentOK_AsClient,
124       Answer_SentNOK_AsClient,
125       Request_Received_AsClient,
126       Answer_Received_AsClient,
127       Answer_UnknownReceived_AsClient,
128
129       Request_SentOK_AsServer,
130       Request_SentNOK_AsServer,
131       Answer_SentOK_AsServer,
132       Answer_SentNOK_AsServer,
133       Request_Received_AsServer,
134       Answer_Received_AsServer,
135       Answer_UnknownReceived_AsServer
136     };
137
138     anna_declare_enum(Counter);
139   };
140
141   /* virtual */std::string getDefaultInternalCounterDescription(const int & counterType) const throw() { return Counter::asCString((Counter::_v)counterType); }
142
143   // map stack id with a scope id
144   void createStackCounterScope(int /* scope id */, unsigned int /* stack id */) throw(anna::RuntimeException);
145
146   // translate message code into offset and invoke parent class count method. The message applicationId will be used as stack id
147   // resultCode shall be -1 for non-answers
148   void count (int messageCode, int resultCode, unsigned int stackId, const int & type, const int & amount = 1) throw(anna::RuntimeException);
149
150   // Number of different counter types for each message
151   int getCounterTypes() const throw() { return a_counter_types; }
152
153   // -1 if multistack 
154   int monoStackScopeId() const throw() {
155     return ((a_stackMap.size() != 1) ? -1 : a_stackMap.begin()->second);
156   }
157
158 private:
159
160   // private constructor
161   ApplicationMessageOamModule() : anna::oam::Module("Application Message Comm OAM Events") { a_counter_types = Counter::calculateSize(); }
162
163
164   friend class anna::Singleton <ApplicationMessageOamModule>;
165 };
166
167 }
168 }
169 }
170
171 #endif
172