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_ServerSession_hpp
38 #define anna_diameter_comm_ServerSession_hpp
44 #include <anna/core/util/Millisecond.hpp>
45 #include <anna/core/RuntimeException.hpp>
47 #include <anna/diameter.comm/Session.hpp>
48 #include <anna/diameter/defines.hpp>
49 #include <anna/diameter.comm/Message.hpp>
50 #include <anna/diameter.comm/ServerSessionReceiver.hpp>
51 #include <anna/diameter.comm/ReceiverFactoryImpl.hpp>
77 Modela la conexion realizada contra un servidor diameter local.
79 class ServerSession : public Session {
85 /* virtual */void initialize() throw();
88 * Default max inactivity period for the diameter server-session health.
90 static const anna::Millisecond DefaultAllowedInactivityTime;
93 Sets the maximum allowed inactivity time on server session
95 @param allowedInactivityTime Inactivity time allowed
97 void setAllowedInactivityTime(const anna::Millisecond & allowedInactivityTime) throw();
100 Diameter listening address (ip or hostname).
101 \return Diameter listening address.
103 /* virtual */const std::string& getAddress() const throw();
106 Diameter listen port.
107 \return Diameter listen port.
109 /* virtual */int getPort() const throw();
112 Server session key. Same as socket id
114 int getKey() const throw() { return getSocketId(); }
118 \return Local server parent
120 LocalServer *getParent() throw() { return a_parent; }
124 Sets the diameter client socket and assign the receiver factory to it
125 \param clientSocket Diameter client socket
127 void setClientSocket(anna::comm::ClientSocket *clientSocket) throw();
130 Diameter client socket
131 \return Diameter client socket
133 anna::comm::ClientSocket *getClientSocket() throw() { return a_clientSocket; }
136 // Sets deprecated state to this server session
138 // void setDeprecated(bool deprecated = true) throw() { a_deprecated = deprecated; }
141 // * Sets CEA and DWA diameter messages to be used over created server-sessions
143 // * @param cea Capabilities-Exchange-Answer message (encoded) for the server-sessions bind.
144 // * @param dwa Device-Watchdog-Answer message (encoded) for the server-sessions keep-alive.
146 // void setCEAandDWA(const anna::DataBlock & cea, const anna::DataBlock & dwa) throw(anna::RuntimeException);
148 /* virtual */const Response* send(const Message* message) throw(anna::RuntimeException);
149 /* virtual */bool unbind(bool forceDisconnect /* se usa en timer, para el actionTimer del tipo SessionUnbind, etc. */ = false) throw(anna::RuntimeException); // returns true if done at call time (no pendings or ignore pendings, except Disconnecting state by mean DPR/DPA)
153 Class string representation
154 \return String with relevant information for this instance.
156 /* virtual */std::string asString() const throw();
160 Class xml representation
161 \param parent Parent XML node on which hold this instance information.
162 \return XML document with relevant information for this instance.
164 /* virtual */anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
174 ReceiverFactoryImpl<ServerSession, ServerSessionReceiver> a_receiverFactory;
176 // Parent information
177 LocalServer *a_parent;
180 anna::comm::ClientSocket *a_clientSocket;
182 // Auxiliary messages:
183 Message a_cer, a_dwr;
185 /* virtual */void expire(anna::timex::Engine *timeController) throw(anna::RuntimeException);
188 /* virtual */void updateIncomingActivityTime() throw();
189 /* virtual */void updateOutgoingActivityTime() throw();
190 void countSendings(const diameter::CommandId & cid, bool ok) throw();
194 Handler about event break connection from diameter client over this server-session.
196 When notified, ANNA.diameter.comm generates an diameter::comm::ServerSession::eventResponse for every request with pending answers.
198 void eventPeerShutdown() throw();
201 Handler for diameter client responses
203 \param response Answer container object for corresponding diameter request
205 void eventResponse(const Response& response) throw(anna::RuntimeException);
208 Handler for diameter client requests
210 \param request Request data block object for corresponding diameter reception
212 void eventRequest(const anna::DataBlock& request) throw(anna::RuntimeException);
213 //void eventRequest(const Message& request) throw(anna::RuntimeException);
216 Handler for diameter client responses out of context
218 \param response Answer data block object without context match
220 void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException);
224 * Handlers for receptions
226 /* virtual */void receive(const anna::comm::Message& message) throw(anna::RuntimeException);
227 /* virtual */void finalize() throw();
229 /* virtual */void expireResponse(Response*) throw();
230 void sendCEA() throw(anna::RuntimeException);
231 void sendDWA() throw(anna::RuntimeException);
234 friend class anna::diameter::comm::Timer;
235 friend class LocalServer;
237 friend class ServerSessionReceiver;