Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / source / diameter.comm / LocalServer.cpp
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 #include <anna/diameter.comm/OamModule.hpp>
10 #include <anna/diameter.comm/Engine.hpp>
11 #include <anna/diameter.comm/LocalServer.hpp>
12 #include <anna/diameter.comm/ServerSession.hpp>
13 #include <anna/diameter.comm/ServerSocket.hpp>
14 #include <anna/core/functions.hpp>
15 #include <anna/statistics/Engine.hpp>
16 #include <anna/diameter.comm/TimerManager.hpp>
17
18 #include <anna/core/tracing/Logger.hpp>
19 #include <anna/core/tracing/TraceMethod.hpp>
20 #include <anna/core/functions.hpp>
21 #include <anna/app/functions.hpp>
22 #include <anna/xml/Node.hpp>
23 #include <anna/comm/Communicator.hpp>
24 #include <anna/comm/Network.hpp>
25 #include <anna/comm/Host.hpp>
26 #include <anna/comm/ClientSocket.hpp>
27
28 // STL
29 #include <string>
30
31
32
33 using namespace anna::diameter::comm;
34
35 LocalServer::LocalServer() :
36   //a_key(key),
37   a_description(""),
38   a_maxConnections(-1),
39   a_currentConnections(0),
40   a_allowedInactivityTime(ServerSession::DefaultAllowedInactivityTime),
41   a_engine(NULL),
42   a_serverSocket(NULL),
43   a_category(0),
44   a_lock(false),
45   a_available(false),
46   a_lastUsedResource(NULL) {
47   a_statisticsAccumulator.reset();
48 }
49
50
51 void LocalServer::initializeStatisticConcepts() throw() {
52   // Statistics:
53   anna::statistics::Engine& statsEngine = anna::statistics::Engine::instantiate();
54   // Concepts descriptions:
55   std::string serverAsString = anna::functions::socketLiteralAsString(a_key.first, a_key.second);
56   std::string c1desc = "Diameter processing time (for requests) at clients connected to "; c1desc += serverAsString;
57   std::string c2desc = "Diameter message sizes received from clients connected to "; c2desc += serverAsString;
58   // Registering
59   a_processing_time__StatisticConceptId = statsEngine.addConcept(c1desc.c_str(), "ms", true/* integer values */);
60   a_received_message_size__StatisticConceptId = statsEngine.addConcept(c2desc.c_str(), "bytes", true/* integer values */);
61 }
62
63 void LocalServer::resetStatistics() throw() {
64   a_statisticsAccumulator.reset();
65 }
66
67 void LocalServer::updateProcessingTimeStatisticConcept(const double &value) throw() {
68   a_statisticsAccumulator.process(a_processing_time__StatisticConceptId, value);
69   LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
70 }
71
72 void LocalServer::updateReceivedMessageSizeStatisticConcept(const double &value) throw() {
73   a_statisticsAccumulator.process(a_received_message_size__StatisticConceptId, value);
74   //LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
75 }
76
77
78 ServerSession* LocalServer::allocateServerSession() throw() { return a_serverSessionsRecycler.create(); }
79 void LocalServer::releaseServerSession(ServerSession *serverSession) throw() { a_serverSessionsRecycler.release(serverSession); }
80
81
82 LocalServer::serverSession_iterator LocalServer::serverSession_find(const serverSession_key &key) throw() {
83   return a_serverSessions.find(key);
84 }
85
86
87 LocalServer::serverSession_key LocalServer::getServerSessionKey(const anna::comm::ClientSocket &clientSocket) const throw() {
88   return (anna::functions::exclusiveHash(clientSocket.getRemoteAccessPoint().getINetAddress().serialize()));
89 }
90
91
92 void LocalServer::availabilityLost() throw() {
93   a_available = false;
94   std::string socket = anna::functions::socketLiteralAsString(a_key.first, a_key.second);
95   LOGDEBUG(
96     std::string msg = "diameter::comm::LocalServer { Socket: ";
97     msg += socket;
98     msg += " } has lost its availability";
99     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
100   );
101   // OAM
102   OamModule &oamModule = OamModule::instantiate();
103   oamModule.activateAlarm(OamModule::Alarm::c_LostAvailabilityOverLocalServerDefinedAs__s__, socket.c_str());
104   oamModule.count(OamModule::Counter::LostAvailabilityOverLocalServer);
105   a_engine->availabilityLost(this);
106   a_engine->refreshAvailabilityForLocalServers();
107 }
108
109
110 void LocalServer::availabilityRecovered() throw() {
111   a_available = true;
112   std::string socket = anna::functions::socketLiteralAsString(a_key.first, a_key.second);
113   LOGDEBUG(
114     std::string msg = "diameter::comm::LocalServer { Socket: ";
115     msg += socket;
116     msg += " } has recovered its availability";
117     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
118   );
119   // OAM
120   OamModule &oamModule = OamModule::instantiate();
121   oamModule.cancelAlarm(OamModule::Alarm::c_LostAvailabilityOverLocalServerDefinedAs__s__, socket.c_str());
122   oamModule.count(OamModule::Counter::RecoveredAvailabilityOverLocalServer);
123   a_engine->availabilityRecovered(this);
124   a_engine->refreshAvailabilityForLocalServers();
125 }
126
127
128
129 bool LocalServer::refreshAvailability() throw() {
130   // Here available
131   if(a_available) {  // check not-bound state for all server-sessions:
132 //      bool isolate = true;
133 //
134 //      for (const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
135 //         if (serverSession(it)->getState() != ServerSession::State::Closed) { isolate = false; break; }
136 //
137 //      if (isolate) {
138 // El problema de lo anterior, es que cuando se acepta una conexion, aun no ha llegado el CER (receive). Un server session
139 // esta en estado "Bound" cuando llega dicho CER y consecuentemente envio un CEA. Nos basaremos en 'a_currentConnections':
140     if(a_currentConnections == 0) {
141       availabilityLost();
142       return true;
143     }
144
145     return false;
146   }
147
148   // Here not available
149 //   for (const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
150 //      if (serverSession(it)->getState() == ServerSession::State::Bound) {
151   if(a_currentConnections > 0) {  // really == 0
152     availabilityRecovered();
153     return true;
154   }
155
156   return false;
157 }
158
159
160 void LocalServer::enable(bool unlock) throw(anna::RuntimeException) {
161   // Unlock ?
162   if(unlock) a_lock = false;
163
164   if(a_lock) return;
165
166   if(a_serverSocket && a_serverSocket->isOpened()) return;  // communicator attach twice gets poll bad file descriptor and application stops !
167
168   // Resolve local address:
169   anna::comm::Network& network = anna::comm::Network::instantiate();
170   // Little tricky:
171   anna::comm::Host *host = network.resolve(a_key.first /* addr */);
172   const anna::comm::Device *device = *(host->device_begin());
173   anna::comm::INetAddress localAddress(device, a_key.second /* port */);
174   // Create server socket and assign receiver factory
175   a_serverSocket = new ServerSocket(localAddress, this);
176   a_serverSocket->setCategory(a_category);
177   attach();
178 }
179
180 void LocalServer::attach() throw() {
181   try {
182     // Attach to communicator
183     anna::comm::Communicator * communicator = anna::app::functions::component <anna::comm::Communicator> (ANNA_FILE_LOCATION);
184     communicator->attach((anna::comm::ServerSocket*)a_serverSocket); // invokes handler insert and then initialize -> server socket bind (*)
185     // OAM
186     OamModule &oamModule = OamModule::instantiate();
187     oamModule.count(OamModule::Counter::ServerSocketsOpened);
188   } catch(anna::RuntimeException& ex) {
189     ex.trace(); // fails on (*) (i.e. Address already in use), within communicator attach
190     attachPlanning();
191     a_serverSocket->close();
192   }
193 }
194
195 void LocalServer::attachPlanning() throw() {
196   LOGMETHOD(anna::TraceMethod tttm("diameter::comm::LocalServer", "attachPlanning", ANNA_FILE_LOCATION));
197
198   try {
199     TimerManager::instantiate().createTimer(this);
200   } catch(anna::RuntimeException& ex) {
201     ex.trace();
202     anna::Logger::error("CAPTURED EXCEPTION activating attachPlanning timer", ANNA_FILE_LOCATION);
203   }
204 }
205
206
207 void LocalServer::disable(bool lock) throw(anna::RuntimeException) {
208   // Permanent ?
209   a_lock = lock;
210   anna::comm::Communicator * communicator = anna::app::functions::component <anna::comm::Communicator> (ANNA_FILE_LOCATION);
211   communicator->detach((anna::comm::ServerSocket*)a_serverSocket);
212   //delete(a_serverSocket);
213   // OAM
214   OamModule &oamModule = OamModule::instantiate();
215   oamModule.count(OamModule::Counter::ServerSocketsClosed);
216 }
217
218
219 void LocalServer::lostConnection() throw() {
220   a_currentConnections--;
221   enable();
222 }
223
224
225 void LocalServer::newConnection() throw(anna::RuntimeException) {
226   a_currentConnections++;
227
228   // Check capacity
229   if(a_currentConnections == a_maxConnections) {
230     LOGWARNING(anna::Logger::warning("The maximum number of connections allowed over diameter server socket have already been served", ANNA_FILE_LOCATION));
231     disable();
232   }
233
234   // Inform local server (availability changes):
235   bool changes = refreshAvailability();
236   // OAM
237   OamModule &oamModule = OamModule::instantiate();
238   oamModule.count(OamModule::Counter::CreatedConnectionForServerSession);
239 }
240
241
242
243 ServerSession *LocalServer::createServerSession(const anna::comm::ClientSocket &clientSocket) throw(anna::RuntimeException) {
244   LOGMETHOD(anna::TraceMethod tttm("diameter::comm::LocalServer", "createServerSession", ANNA_FILE_LOCATION));
245   ServerSession* result(NULL);
246   // First erase deprecated ones:
247   std::vector<const ServerSession*> deprecated_server_sessions;
248   const ServerSession* ss;
249
250   for(const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++) {
251     ss = serverSession(it);
252
253     if(ss->a_deprecated)
254       deprecated_server_sessions.push_back(ss);
255   }
256
257   std::vector<const ServerSession*>::iterator dc_ncit;
258   std::vector<const ServerSession*>::iterator dc_min(deprecated_server_sessions.begin());
259   std::vector<const ServerSession*>::iterator dc_max(deprecated_server_sessions.end());
260   serverSession_iterator ii;
261
262   for(dc_ncit = dc_min; dc_ncit != dc_max; dc_ncit++) {
263     ii = serverSession_find((*dc_ncit)->getSocketId());
264     a_serverSessions.erase(ii);
265   }
266
267   // End erase deprecated server sessions
268
269   if((result = allocateServerSession()) == NULL)
270     throw anna::RuntimeException("diameter::comm::LocalServer::allocateServerSession returns NULL", ANNA_FILE_LOCATION);
271
272   // Initialize:
273   result->initialize(); // warning: recycler does not initialize its objects and at least...
274   // Assignments (it could be done at allocate):
275   serverSession_key key = getServerSessionKey(clientSocket);
276   result->setAllowedInactivityTime(getAllowedInactivityTime());
277   result->setClientSocket((anna::comm::ClientSocket*)(&clientSocket));
278   result->a_parent = this;
279   result->a_socketId = key; // de momento...
280   result->initializeSequences(); // después de asignar el LocalServer y el socketId (*)
281   // (*) Las secuencias se basan en la semilla:    srand(::time(NULL) + anna::functions::exclusiveHash(anna::functions::asString("%s:%d|%d", getAddress().c_str(), getPort(), a_socketId)));
282   result->a_engine = a_engine;
283   a_serverSessions.insert(serverSession_value_type(key, result));
284   newConnection();
285   a_deliveryIterator = serverSession_begin();
286   return result;
287 }
288
289
290
291 void LocalServer::closeServerSession(ServerSession* serverSession)
292 throw(anna::RuntimeException) {
293   if(serverSession == NULL)
294     return;
295
296   LOGDEBUG(
297     std::string msg("diameter::comm::LocalServer::closeServerSession | ");
298     msg += serverSession->asString();
299 //      msg += " | Destroy: ";
300 //      msg += (destroy ? "yes" : "no");
301     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
302   );
303   serverSession_iterator ii = serverSession_find(serverSession->getSocketId());
304
305   if(ii == serverSession_end())
306     return;
307
308   try {
309     //serverSession->setState(ServerSession::State::Closing); NOT MANAGED WITH SERVER SESSIONS
310     serverSession->unbind(true /* always forceDisconnect on server sessions ... */);
311     releaseServerSession(serverSession);
312   } catch(anna::RuntimeException& ex) {
313     ex.trace();
314   }
315
316   //a_serverSessions.erase(ii); // IMPORTANTE: posible fuente de cores de este tipo, en relacion con ServerSession::finalize() => delete(this)
317   //   #0  0x0000003ca1c2e26d in raise () from /lib64/tls/libc.so.6
318   //   (gdb) bt
319   //   #0  0x0000003ca1c2e26d in raise () from /lib64/tls/libc.so.6
320   //   #1  0x0000003ca1c2fa6e in abort () from /lib64/tls/libc.so.6
321   //   #2  0x0000003ca8cb1148 in __gnu_cxx::__verbose_terminate_handler () from /usr/lib64/libstdc++.so.6
322   //   #3  0x0000003ca8caf176 in __cxa_call_unexpected () from /usr/lib64/libstdc++.so.6
323   //   #4  0x0000003ca8caf1a3 in std::terminate () from /usr/lib64/libstdc++.so.6
324   //   #5  0x0000003ca8caf1b6 in std::terminate () from /usr/lib64/libstdc++.so.6
325   //   #6  0x0000003ca8caf0c8 in __cxa_call_unexpected () from /usr/lib64/libstdc++.so.6
326   //   #7  0x000000000047a4a7 in anna::diameter::comm::LocalServer::lostConnection (this=0x8aeb10) at comm.db/diameter.comm.LocalServer.cc:200
327   //   #8  0x000000000047a9e6 in anna::diameter::comm::LocalServer::closeServerSession (this=0x8aeb10, serverSession=0xc37a00)
328   //       at comm.db/diameter.comm.LocalServer.cc:275
329   //   #9  0x000000000048d288 in anna::diameter::comm::ServerSession::finalize (this=0xc37a00) at comm.db/diameter.comm.ServerSession.cc:510
330   //   #10 0x0000000000494e4f in anna::diameter::comm::ServerSessionReceiver::eventBreakLocalConnection (this=0xc119c0, clientSocket=@0xb0ea00)
331   // SOLUCION: no borrar aqui, marcar como "deprecated". Este estado no se necesita realmente puesto que nadie volvera a usar este recurso.
332   // Pero simplemente se podria usar para purgar mediante temporizacion (entonces sí se haría el erase)
333   serverSession->a_deprecated = true;
334   // WE WILL ERASE AT createServerSession
335   a_deliveryIterator = serverSession_begin();
336   lostConnection();
337 }
338
339
340 ServerSession* LocalServer::findServerSession(int socketId, anna::Exception::Mode::_v emode)
341 throw(anna::RuntimeException) {
342   serverSession_iterator ii = serverSession_find(socketId);
343
344   if(ii != serverSession_end())
345     return serverSession(ii);
346
347   if(emode != anna::Exception::Mode::Ignore) {
348     std::string msg("diameter::comm::LocalServer::findServerSession | SocketId: ");
349     msg += anna::functions::asString(socketId);
350     msg += " | ServerSession not found";
351     anna::RuntimeException ex(msg, ANNA_FILE_LOCATION);
352
353     if(emode == anna::Exception::Mode::Throw)
354       throw ex;
355
356     ex.trace();
357   }
358
359   return NULL;
360 }
361
362 ServerSession* LocalServer::findServerSession(const anna::comm::ClientSocket &clientSocket, anna::Exception::Mode::_v emode)
363 throw(anna::RuntimeException) {
364   return findServerSession(getServerSessionKey(clientSocket), emode);
365 }
366
367
368 int LocalServer::getOTARequests() const throw() {
369   int result = 0;
370
371   for(const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
372     result += serverSession(it)->getOTARequests();
373
374   return result;
375 }
376
377 void LocalServer::close() throw(anna::RuntimeException) {
378   LOGMETHOD(anna::TraceMethod tttm("diameter::comm::LocalServer", "close", ANNA_FILE_LOCATION));
379   // Close listener (permanently to avoid reopening when local connections are being deleted):
380   disable(true /* lock */);
381
382   for(serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
383     closeServerSession(serverSession(it));
384 }
385
386
387 void LocalServer::setMaxConnections(int maxConnections) throw(anna::RuntimeException) {
388   LOGMETHOD(anna::TraceMethod tttm("anna::diameter::comm::LocalServer", "setMaxConnections", ANNA_FILE_LOCATION));
389
390   // Negative & initial
391   if(maxConnections < 0) {
392     LOGDEBUG(anna::Logger::debug("Provided negative value means no limit accepting connections over server socket. Opening listen port (if closed)...", ANNA_FILE_LOCATION));
393     a_maxConnections = -1;
394     enable();
395     return;
396   }
397
398   // No changes
399   if(maxConnections == a_maxConnections) {
400     LOGDEBUG(anna::Logger::debug("Provided equal to current. Ignore operation", ANNA_FILE_LOCATION));
401     return;
402   }
403
404   // No margin
405   if(maxConnections < a_currentConnections) {
406     std::string msg = "There are more current connections (";
407     msg += anna::functions::entriesAsString(a_currentConnections);
408     msg += ") than provided maximum (";
409     msg += anna::functions::entriesAsString(maxConnections);
410     msg += "). Command rejected (you should release connections before logical limitation)";
411     throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
412   }
413
414   // Updating
415   if(maxConnections > a_currentConnections) {
416     LOGDEBUG(anna::Logger::debug("Increasing connection margin (new limit is greater than current connections). Opening listen port (if closed)...", ANNA_FILE_LOCATION));
417     enable();
418   } else { // maxConnections == a_currentConnections: listen port must be closed if it is opened
419     LOGDEBUG(
420
421       if(maxConnections == 0)
422       anna::Logger::debug("Provided zero value means disabling diameter server", ANNA_FILE_LOCATION);
423       anna::Logger::debug("Zeroing connections margin (new limit is equal to current connections). Closing listen port (if opened)...", ANNA_FILE_LOCATION);
424     );
425
426     disable();
427   }
428
429   // Trace
430   LOGDEBUG(
431     std::string msg("Updating max connections from ");
432     msg += (a_maxConnections == -1) ? "'no limit'" : anna::functions::asString(a_maxConnections);
433     msg += " to ";
434     msg += (maxConnections == -1) ? "'no limit'" : anna::functions::asString(maxConnections);
435     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
436   );
437   // Assignment
438   a_maxConnections = maxConnections;
439 }
440
441
442 bool LocalServer::send(const Message* message, int socketId) throw(anna::RuntimeException) {
443   LOGMETHOD(anna::TraceMethod tttm("diameter::comm::LocalServer", "send", ANNA_FILE_LOCATION));
444
445   if(!isAvailable()) {
446     LOGWARNING(
447       std::string msg = "The local server ";
448
449     if(a_description != "") {
450     msg += "'";
451     msg += a_description;
452     msg += "' ";
453   }
454   msg += "is currently unavailable (no server sessions to send the message)";
455   anna::Logger::warning(msg, ANNA_FILE_LOCATION);
456   );
457     return false;
458   }
459
460   if(socketId != -1) {  // socket id provided
461     // Send (it was a request because of key (socketId) != -1, we forward the answer):
462     try {
463       ServerSession * fixedServerSession = a_engine->findServerSession(socketId); // exception if not found
464       fixedServerSession->send(message);
465       return true;
466     } catch(anna::RuntimeException &ex) {
467       std::string msg = "Cannot deliver answer through a fixed server session (socket id ";
468       msg += anna::functions::asString(socketId);
469       msg += "). Perhaps it existed but not now. Ignore";
470       anna::Logger::error(msg, ANNA_FILE_LOCATION);
471       ex.trace();
472       return false;
473     }
474   }
475
476   // Socket is not provided: use readSocketId
477   socketId = (a_currentConnections > 1) ? readSocketId(message) : -1; // optimization
478
479   if(a_deliveryIterator == serverSession_end()) a_deliveryIterator = serverSession_begin();
480
481   a_lastUsedResource = (*a_deliveryIterator).second;
482
483   if(socketId != -1) {
484     a_lastUsedResource = findServerSession(socketId); // exception if not found
485   } else { // Round Robin delivery between client-sessions
486     if(getCurrentConnections() != 1) {  // optimize
487       // Next server-session:
488       a_deliveryIterator++;
489     }
490   }
491
492   // Send:
493   try {
494     const Response* response = a_lastUsedResource->send(message);
495     return true; // no matter if response is NULL (answers, i.e.) or not.
496   } catch(anna::RuntimeException &ex) {
497     ex.trace();
498   }
499
500   // Here, sent has failed:
501   // OAM
502   OamModule &oamModule = OamModule::instantiate();
503   std::string socket = anna::functions::socketLiteralAsString(getKey().first, getKey().second);
504   oamModule.activateAlarm(OamModule::Alarm::UnableToDeliverDiameterMessageToClientFromLocalServer__s__, socket.c_str());
505   oamModule.count(OamModule::Counter::UnableToDeliverToClient);
506   return false;
507 }
508
509
510 bool LocalServer::broadcast(const Message* message) throw(anna::RuntimeException) {
511   LOGMETHOD(anna::TraceMethod tttm("diameter::comm::LocalServer", "broadcast", ANNA_FILE_LOCATION));
512   const Response* response;
513   bool allok = true;
514
515   for(serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++) {
516     try {
517       response = serverSession(it)->send(message);
518     } catch(anna::RuntimeException &ex) {
519       ex.trace();
520       allok = false;
521     }
522   }
523
524   return allok;
525 }
526
527 void LocalServer::eventPeerShutdown(const ServerSession* serverSession) throw() {
528   LOGWARNING(
529     std::string msg(serverSession->asString());
530     msg += " | eventPeerShutdown";
531     anna::Logger::warning(msg, ANNA_FILE_LOCATION);
532   );
533 }
534
535 std::string LocalServer::asString() const throw() {
536   std::string result("diameter::comm::LocalServer { ");
537   result += "Description: ";
538   result += (a_description != "") ? a_description : "undefined";
539   result += " | Available (any server session bound): ";
540   result += a_available ? "yes" : "no";
541   result += " | Max Connections: ";
542   result += anna::functions::asString(a_maxConnections);
543   result += " | Current Connections: ";
544   result += anna::functions::asString(a_currentConnections);
545   // Current connections ??
546   result += " | Allowed inactivity time for server sessions: ";
547   result += a_allowedInactivityTime.asString();
548   result += " | Server socket: ";
549   result += a_serverSocket ? a_serverSocket->asString() : "closed";
550   result += anna::functions::asString(" | OTA requests: %d%s", getOTARequests(), idle() ? " (idle)" : "");
551   result += " | Last Incoming Activity Time: ";
552   result += a_lastIncomingActivityTime.asString();
553   result += " | Last Outgoing Activity Time: ";
554   result += a_lastOutgoingActivityTime.asString();
555 //   result += "\n";
556 //   result += a_statisticsAccumulator.asString();
557   // ServerSessions only in xml
558   return result += " }";
559 }
560
561
562 anna::xml::Node* LocalServer::asXML(anna::xml::Node* parent) const throw() {
563   anna::xml::Node* result = parent->createChild("diameter.LocalServer");
564   result->createAttribute("Description", (a_description != "") ? a_description : "undefined");
565   result->createAttribute("Available", a_available ? "yes" : "no");
566   result->createAttribute("MaxConnections", a_maxConnections);
567   result->createAttribute("CurrentConnections", a_currentConnections);
568   // Current connections ??
569   result->createAttribute("AllowedInactivityTimeForServerSessions", a_allowedInactivityTime.asString());
570
571   if(a_serverSocket)
572     a_serverSocket->asXML(result);
573   else
574     result->createAttribute("ServerSocket", "closed");
575
576   result->createAttribute("OTArequests", anna::functions::asString("%d%s", getOTARequests(), idle() ? " (idle)" : ""));
577   result->createAttribute("LastIncomingActivityTime", a_lastIncomingActivityTime.asString());
578   result->createAttribute("LastOutgoingActivityTime", a_lastOutgoingActivityTime.asString());
579   // Statistics
580   anna::xml::Node* stats = result->createChild("Statistics");
581   a_statisticsAccumulator.asXML(stats);
582   anna::xml::Node* serverSessions = result->createChild("ServerSessions"); // LocalServer.ServerSessions
583
584   for(const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
585     serverSession(it)->asXML(serverSessions);
586
587   return result;
588 }
589
590 //------------------------------------------------------------------------------
591 //------------------------------------ LocalServer::updateIncomingActivityTime()
592 //------------------------------------------------------------------------------
593 void LocalServer::updateIncomingActivityTime() throw() {
594   a_lastIncomingActivityTime = anna::functions::millisecond();
595   LOGDEBUG
596   (
597     std::string msg = "Updated INCOMING activity on local server (milliseconds unix): ";
598     msg += anna::functions::asString(a_lastIncomingActivityTime.getValue());
599     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
600   );
601 }
602
603
604 //------------------------------------------------------------------------------
605 //------------------------------------ LocalServer::updateOutgoingActivityTime()
606 //------------------------------------------------------------------------------
607 void LocalServer::updateOutgoingActivityTime(void) throw() {
608   a_lastOutgoingActivityTime = anna::functions::millisecond();
609   LOGDEBUG
610   (
611     std::string msg = "Updated OUTGOING activity on local server (milliseconds unix): ";
612     msg += anna::functions::asString(a_lastOutgoingActivityTime.getValue());
613     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
614   );
615 }
616