First commit
[anna.git] / include / anna / diameter / app / dcca / Message.hpp
1 // ANNA - Anna is Not 'N' Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef anna_diameter_app_dcca_Message_hpp
38 #define anna_diameter_app_dcca_Message_hpp
39
40
41 // Local
42 #include <anna/diameter/app/base/Message.hpp>
43
44 // AVPID's
45 #include <anna/diameter/helpers/base/defines.hpp>
46 #include <anna/diameter/helpers/tgpp/defines.hpp>
47 #include <anna/diameter/helpers/dcca/defines.hpp>
48
49 #include <anna/core/RuntimeException.hpp>
50
51 // STL
52 #include <string>
53
54
55 //------------------------------------------------------------------------------
56 //---------------------------------------------------------------------- #define
57 //------------------------------------------------------------------------------
58
59
60
61 namespace anna {
62
63 namespace diameter {
64
65 namespace codec {
66 using namespace basetypes;
67 }
68
69 namespace app {
70
71 namespace dcca {
72
73
74
75 typedef struct {
76
77   std::string qosProfile;
78   int Release;
79   int TrafficClass;
80   int HandlingPriority;
81   int MaximumBitrateForUplink;
82   int MaximumBitrateForDownlink;
83
84
85   void reset() throw() {
86     qosProfile = "";
87     Release = TrafficClass = HandlingPriority = MaximumBitrateForUplink = MaximumBitrateForDownlink = 0;
88   }
89
90 } qosProfile_t;
91
92
93
94
95 /**
96 * Diameter message for DCCA (diameter credit control application)
97 */
98 class Message : public anna::diameter::app::base::Message {
99
100   qosProfile_t a_qosProfile;
101
102 public:
103
104   /**
105      Avp Subscription-Id-Data data-part pointer reference.
106
107      @param Subscription-Id-Type value to filter the search. END_USER_E164 by default.
108      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
109   */
110   const UTF8String * getSubscriptionIdData(int subscriptionIdType = helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
111     ASSERT_APP_GETAVP(
112       const anna::diameter::codec::Avp * sid;
113       int pos = 1;
114
115       while(sid = getAvp(helpers::dcca::AVPID__Subscription_Id, pos++))
116       if(subscriptionIdType == sid->getAvp(helpers::dcca::AVPID__Subscription_Id_Type)->getEnumerated()->getValue())
117         return sid->getAvp(helpers::dcca::AVPID__Subscription_Id_Data)->getUTF8String();
118         return NULL;
119       );
120   }
121
122   /**
123      Avp Multiple-Services-Credit-Control pointer reference
124      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
125   */
126   const anna::diameter::codec::Avp * getMultipleServicesCreditControl(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
127     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control));
128   }
129
130   /**
131      Avp Service-Identifier data-part pointer reference
132      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
133   */
134   const Unsigned32 * getServiceIdentifier(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
135     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Service_Identifier)->getUnsigned32());
136   }
137
138   /**
139      Avp Rating-Group data-part pointer reference
140      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
141   */
142   const Unsigned32 * getRatingGroup(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
143     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Rating_Group)->getUnsigned32());
144   }
145
146   /**
147      Avp Tariff-Change-Usage data-part pointer reference
148      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
149   */
150   const Enumerated * getTariffChangeUsage(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
151     ASSERT_APP_GETAVP(
152       return   getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->
153                getAvp(helpers::dcca::AVPID__Used_Service_Unit)->
154                getAvp(helpers::dcca::AVPID__Tariff_Change_Usage)->getEnumerated();
155     );
156   }
157
158   /**
159      Avp Validity-Time data-part pointer reference
160      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
161   */
162   const Unsigned32 * getValidityTime(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
163     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Validity_Time)->getUnsigned32());
164   }
165
166   /**
167      Avp Requested-Service-Unit pointer reference
168      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
169   */
170   const anna::diameter::codec::Avp * getRequestedServiceUnit(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
171     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Requested_Service_Unit));
172   }
173
174   /**
175      Avp n-th Used-Service-Unit pointer reference
176      @param ocurrence Select the n-th USU within the MSCC. First by default.
177      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
178   */
179   const anna::diameter::codec::Avp * getUsedServiceUnit(int ocurrence = 1, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
180     ASSERT_APP_GETAVP(
181       return   getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->
182                getAvp(helpers::dcca::AVPID__Used_Service_Unit, ocurrence);
183     );
184   }
185
186   /**
187      Avp CC_Request_Type data-part pointer reference
188      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
189   */
190   const Enumerated * getCCRequestType(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
191     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__CC_Request_Type)->getEnumerated());
192   }
193
194   /**
195      Avp CC_Request_Number data-part pointer reference
196      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
197   */
198   const Unsigned32 * getCCRequestNumber(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
199     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__CC_Request_Number)->getUnsigned32());
200   }
201
202   /**
203      Avp Multiple-Services-Indicator data-part pointer reference
204      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
205   */
206   const Enumerated * getMultipleServicesIndicator(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
207     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Indicator)->getEnumerated());
208   }
209
210   /**
211      Avp Service-Context-Id data-part pointer reference
212      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
213   */
214   const UTF8String * getServiceContextId(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
215     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Service_Context_Id)->getUTF8String());
216   }
217
218   /**
219      Avp 3GPP-NSAPI data-part pointer reference
220      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
221   */
222   const UTF8String * get3GPPNSAPI(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
223     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_NSAPI)->getUTF8String());
224   }
225
226   /**
227      Avp 3GPP-Selection-Mode data-part pointer reference
228      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
229   */
230   const UTF8String * get3GPPSelectionMode(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
231     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_Selection_Mode)->getUTF8String());
232   }
233
234   /**
235      Avp 3GPP-Session-Stop-Indicator data-part pointer reference
236      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
237   */
238   const OctetString * get3GPPSessionStopIndicator(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
239     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_Session_Stop_Indicator)->getOctetString());
240   }
241
242   /**
243      Avp User-Equipment-Info pointer reference
244      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
245   */
246   const anna::diameter::codec::Avp * getUserEquipmentInfo(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
247     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__User_Equipment_Info));
248   }
249
250   /**
251      Avp User-Equipment-Info-Value data-part pointer reference.
252
253      @param User-Equipment-Info-Type value to filter the search. IMEISV by default.
254      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
255   */
256   const OctetString * getUserEquipmentInfoValue(int userEquipmentInfoType = helpers::dcca::AVPVALUES__User_Equipment_Info_Type::IMEISV, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) {
257     ASSERT_APP_GETAVP(
258       const anna::diameter::codec::Avp * uei;
259       int pos = 1;
260
261       while(uei = getAvp(helpers::dcca::AVPID__User_Equipment_Info, pos++))
262       if(userEquipmentInfoType == uei->getAvp(helpers::dcca::AVPID__User_Equipment_Info_Type)->getEnumerated()->getValue())
263         return uei->getAvp(helpers::dcca::AVPID__User_Equipment_Info_Value)->getOctetString();
264         return NULL;
265       );
266   }
267
268   // there has to be at least one out-of-line definition of a non-pure-virtual function (http://www.daniweb.com/software-development/cpp/threads/114299/undefined-reference-to-vtable-for-)
269   // Lo que dice es que las virtuales no puras de una clase deben tener al menos una definicion en el .cc (lo contrario de in-line). Parece una limitaciĆ³n del compilador.
270   // Podemos hacer una definicion por defecto (return NULL), o mejor, hacerla virtual pura (porque se necesitara por parte del decodificador de QoS):
271   virtual const UTF8String * get3GPPGPRSNegQoSProfile(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException) = 0;
272
273
274   /**
275      Decodes 3GPP-GPRS-Neg-QoS-Profile (as described in 3GPP TS 24.008)
276
277      @return 3GPP-GPRS-Neg-QoS-Profile decoded on struct
278   */
279   const qosProfile_t & decode3GPPGPRSNegQoSProfile() throw(anna::RuntimeException);
280
281
282
283 //   static bool dameTiempoConsumido(const InfoDIAMETER & mensaje,long &tiempoConsumidoAntesConmutacion,long &tiempoConsumidoDespuesConmutacion,long &tiempoConsumidoSinConmutacion);
284 //   static bool dameTiempoConsumido(const InfoDIAMETER & mensaje,long &tiempoConsumidoAntesConmutacion,long &tiempoConsumidoDespuesConmutacion,long &tiempoConsumidoSinConmutacion,bool &hayUSUantes, bool &hayUSUdespues);
285 //
286 //   // nos devuelve el volumen que viene en el mensaje diameter (antes, despues de la conmutacion y el valor cuando no ha  habido conmutacion)
287 //   // Le pasamos el tipo volumen que queremos  ( ambos,downlink,uplink)
288 //   // en tipoVol, se indica de que   AVP leemos las unidades ( Input_Octets, Output-Octets o TotalOctets )
289 //   //static void dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volAntesConmutacion,long &volDespuesConmutacion,long &volConsumidoSinConmutacion);
290 //   // Devuelve FALSE si ha habido algun error
291 //   static bool dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volUpAntesConmutacion,long &volUpDespuesConmutacion,
292 //                  long &volDownAntesConmutacion,long &volDownDespuesConmutacion,long &volUp,long &volDown,bool &errorTariffChange);
293 //   static bool dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volUpAntesConmutacion,long &volUpDespuesConmutacion,
294 //                  long &volDownAntesConmutacion,long &volDownDespuesConmutacion,long &volUp,long &volDown,bool &errorTariffChange,
295 //                  bool &hayUSUantes, bool &hayUSUdespues);
296 //
297 //
298 //   bool getConsumedTime(int &beforeSwitch, int &afterSwitch, int &withoutSwitch) const throw();
299 //   bool getConsumedVolume(int volumeType, int &upBeforeSwitch, int &upAfterSwitch, int &downBeforeSwitch, int &downAfterSwitch, int &upWithoutSwitch, int &downWithoutSwitch, bool &tariffChangeError) const throw();
300 //
301
302
303
304
305
306 };
307
308 }
309 }
310 }
311 }
312
313 #endif