1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
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
17 // * Neither the name of the copyright holder 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.
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.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_diameter_comm_Message_hpp
38 #define anna_diameter_comm_Message_hpp
41 #include <anna/diameter/defines.hpp>
42 #include <anna/diameter.comm/ClassCode.hpp>
44 #include <anna/core/RuntimeException.hpp>
45 #include <anna/comm/Message.hpp>
46 #include <anna/core/util/Millisecond.hpp>
47 #include <anna/core/functions.hpp>
70 Messages launched to diameter servers
72 class Message : public anna::comm::Message {
76 * Define las acciones a realizar en caso de que el temporizador de la petición expire.
78 struct OnExpiry { enum _v { Abandon, Ignore }; };
82 \param onExpiry Indica la acción a realizar si el temporizador de esta transación expira.
84 Message(const OnExpiry::_v onExpiry = OnExpiry::Ignore) : anna::comm::Message(StatusCodeBuffer::Reserve),
85 a_classCode(ClassCode::ApplicationMessage),
86 a_onExpiry(onExpiry) { initialize(); }
89 Devuelve el tipo de la clase de esta peticion indicada en el contructor.
90 \return El tipo de la clase de esta peticion indicada en el contructor.
92 const ClassCode::_v & getClassCode() const throw() { return a_classCode; }
95 * Devuelve la acción a realizar en caso de que el temporizador asociado a esta petición expire.
96 * \return la acción a realizar en caso de que el temporizador asociado a esta petición expire.
98 OnExpiry::_v getOnExpiry() const throw() { return a_onExpiry; }
101 * Establece la acción a realizar en caso de que el temporizador asociado a esta petición expire.
102 * \param onExpiry Indica la acción a realizar en caso de que el temporizador asociado a esta petición expire.
104 * \warning Establecer el valor OnExpiry::Ignore podría causar pérdida de memoria y uso innecesario de recursos.
106 void setOnExpiry(const OnExpiry::_v onExpiry) throw() { a_onExpiry = onExpiry; }
108 // Internal use (CER message)
109 void setClassCode(const ClassCode::_v & classCode) throw() { a_classCode = classCode; }
113 Class string representation
114 \return String with relevant information for this instance.
116 virtual std::string asString() const throw();
119 Class xml representation
120 \param parent Parent XML node on which hold this instance information.
121 \return XML document with relevant information for this instance.
123 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
127 HopByHop getHopByHop() const throw();
128 EndToEnd getEndToEnd() const throw();
129 HopByHop getRequestHopByHop() const throw() { return a_requestHopByHop; }
130 EndToEnd getRequestEndToEnd() const throw() { return a_requestEndToEnd; }
131 void setRequestHopByHop(HopByHop hbh) throw() { a_requestHopByHop = hbh; }
132 void setRequestEndToEnd(EndToEnd ete) throw() { a_requestEndToEnd = ete; }
133 CommandId getCommandId(bool &isRequest) const throw();
134 CommandId getCommandId() const throw() { bool dummy; return getCommandId(dummy); }
136 bool fixRequestSequence(HopByHop hbh, EndToEnd ete, bool freezeEndToEnd) throw();
139 void updateRequestTimestampMs(void) throw() { a_request_timestamp_ms = anna::functions::millisecond(); }
140 const anna::Millisecond & getRequestTimestampMs() const throw() { return (a_request_timestamp_ms); }
142 int getRetries() const throw() { return a_retries; }
143 void setRetries(int value) throw() { a_retries = value; }
146 int getRequestServerSessionKey() const throw() { return a_requestServerSessionKey; }
148 /** Application specific socket id to keep origin track for request which came from a specific client, at asyncronous contexts (process with both diameter interfaces: client & entities) */
149 void setRequestServerSessionKey(int value) throw() { a_requestServerSessionKey = value; }
151 const std::string & getRequestClientSessionKey() const throw() { return a_requestClientSessionKey; }
153 /** Application specific socket id to keep origin track for request which came from a specific server (entity), at asyncronous contexts (process with both diameter interfaces: client & entities) */
154 void setRequestClientSessionKey(const std::string & value) throw() { a_requestClientSessionKey = value; }
156 /** Initializes class information */
157 void initialize() throw() {
159 a_requestServerSessionKey = -1; // means unknown/unset
160 a_requestClientSessionKey = ""; // means unknown/unset
161 a_requestHopByHop = 0;
162 a_requestEndToEnd = 0;
169 \param classCode Tipo de clase de esta peticion.
170 \param onExpiry Indica la acción a realizar si el temporizador de esta transación expira.
172 Message(const ClassCode::_v & classCode, const OnExpiry::_v onExpiry = OnExpiry::Ignore) : anna::comm::Message(StatusCodeBuffer::Reserve),
173 a_classCode(classCode),
174 a_onExpiry(onExpiry) { initialize(); }
178 ClassCode::_v a_classCode;
179 OnExpiry::_v a_onExpiry;
180 anna::Millisecond a_request_timestamp_ms; // Lapsed timestamp milliseconds at request event. Used for statistic purposes.
182 int a_requestServerSessionKey; // useful to resolve origin of messages when diameter sessions are involved in the other side (if another interface, inherit from this Message class and put/carry context information)
183 std::string a_requestClientSessionKey; // idem for request which was received from servers
184 HopByHop a_requestHopByHop; // application backup for hop-by-hop in order to restore on answer receive
185 EndToEnd a_requestEndToEnd; // application backup for end-to-end in order to restore on answer receive
187 void send(ClientSession&) const throw(anna::RuntimeException);
188 void send(ServerSession&) const throw(anna::RuntimeException);
189 void restoreSequencesAfterFix() throw();
191 static const char* asText(const OnExpiry::_v) throw();
193 friend class Session;
194 friend class ClientSession;
195 friend class ServerSession;