Revert "Restruct launcher source code. Separate classes in different files to improve...
[anna.git] / example / diameter / launcher / main.cpp
index 92dd89b..dde2f7c 100644 (file)
@@ -1,37 +1,9 @@
-// ANNA - Anna is Not Nothingness Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// http://redmine.teslayout.com/projects/anna-suite
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     *  Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-//          cisco.tierra@gmail.com
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
 
 
 #include <fstream>
@@ -436,6 +408,7 @@ public:
   void writeBurstLogFile(const std::string &buffer) throw();
   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
   void startDiameterServer(int) throw(anna::RuntimeException);
+  void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
 
   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
   void resetStatistics() throw() { a_myDiameterEngine->resetStatistics(); }
@@ -846,6 +819,7 @@ std::string Launcher::help() const throw() {
   result += "\ncollect                              Reset statistics and counters to start a new test stage of";
   result += "\n                                      performance measurement. Context data is written at";
   result += "\n                                      '/var/tmp/anna.context.<pid>' by mean 'kill -10 <pid>'.";
+  result += "\nforceCountersRecord                  Forces dump to file the current counters of the process.";
   result += "\n";
   result += "\n<visibility action>|[<address>:<port>]|[socket id]";
   result += "\n";
@@ -1835,6 +1809,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     return;
   }
 
+  // Counters dump on demand:
+  if(operation == "forceCountersRecord") {
+    forceCountersRecord();
+    response_content = "Current counters have been dump to disk\n";
+    return;
+  }
+
   ///////////////////////////////////////////////////////////////////
   // Tokenize operation
   Tokenizer params;
@@ -2228,14 +2209,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     response_content += "' loaded.";
     response_content += "\n";
   } else if((opType == "answerxml") || (opType == "answerxml2c")) {
-    response_content += "Answer to client '";
+    response_content += "'";
     response_content += param1;
-    response_content += "' programmed.";
+    response_content += "' applied on server FIFO queue";
     response_content += "\n";
   } else if(opType == "answerxml2e") {
-    response_content += "Answer to entity '";
+    response_content += "'";
     response_content += param1;
-    response_content += "' programmed.";
+    response_content += "' applied on client FIFO queue";
     response_content += "\n";
   } else if(opType == "diameterServerSessions") {
     response_content += "Maximum server socket connections updated to '";
@@ -2349,6 +2330,7 @@ throw(anna::RuntimeException) {
   if(localServer && (cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) /* don't forward CER */) {
     try {
       anna::diameter::comm::Message *msg = G_commMessages.create();
+      msg->updateEndToEnd(false); // end-to-end will be kept
       msg->setBody(message);
       msg->setRequestClientSessionKey(clientSession->getKey());
       bool success = localServer->send(msg);
@@ -2431,6 +2413,7 @@ throw(anna::RuntimeException) {
 
     if(localServer && (request_cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) /* don't forward CEA */) {
       try {
+        G_commMsgFwd2c.updateEndToEnd(false); // end-to-end will be kept
         G_commMsgFwd2c.setBody(*message);
         bool success = localServer->send(&G_commMsgFwd2c, request->getRequestServerSessionKey());
         G_commMessages.release(request);
@@ -2529,6 +2512,7 @@ throw(anna::RuntimeException) {
   anna::diameter::comm::Entity *entity = my_app.getEntity();
   if(!programmed && entity) {  // forward condition (no programmed answer + entity available)
     anna::diameter::comm::Message *msg = G_commMessages.create();
+    msg->updateEndToEnd(false); // end-to-end will be kept
     msg->setBody(message);
     msg->setRequestServerSessionKey(serverSession->getKey());
     bool success = entity->send(msg, cl.exists("balance"));
@@ -2656,6 +2640,7 @@ throw(anna::RuntimeException) {
       if(my_app.logEnabled()) detail = usedClientSession ? usedClientSession->asString() : "<null client session>";  // esto no deberia ocurrir
 
       try {
+        G_commMsgFwd2e.updateEndToEnd(false); // end-to-end will be kept
         G_commMsgFwd2e.setBody(*message);
 
         // Metodo 1: