X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fmain.cpp;h=6d95e9a1031c7cac20e37340b0679f3542fb82d9;hb=93366a0bda79e6fd6e7dad6316bfcf8cc82f5731;hp=301ab349ec0c91c3c734f362ff0bb82df2935681;hpb=4a6b159e05fed37e40d586b938c31a22fe82d3d0;p=anna.git diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 301ab34..6d95e9a 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -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 @@ -42,6 +14,7 @@ #include #include +#include #include @@ -101,12 +74,121 @@ anna::diameter::comm::Message G_commMsg; anna::diameter::codec::Message G_codecMsg, G_codecAnsMsg; anna::Recycler G_commMessages; // create on requests forwards without programmed answer / release in answers forward - // Auxiliary resources for answers programming -typedef std::map < int /* message code */, anna::diameter::codec::Message* > reacting_answers_container; -typedef std::map < int /* message code */, anna::diameter::codec::Message* >::iterator reacting_answers_iterator; -typedef std::map < int /* message code */, anna::diameter::codec::Message* >::const_iterator reacting_answers_const_iterator; -reacting_answers_container G_reactingAnswers2C, G_reactingAnswers2E; +class ProgrammedAnswers { + +typedef std::deque codec_messages_deque; +typedef std::deque::iterator codec_messages_deque_iterator; +typedef std::deque::const_iterator codec_messages_deque_const_iterator; +typedef std::map < int /* message code */, codec_messages_deque* > reacting_answers_container; +typedef std::map < int /* message code */, codec_messages_deque* >::iterator reacting_answers_iterator; +typedef std::map < int /* message code */, codec_messages_deque* >::const_iterator reacting_answers_const_iterator; + + reacting_answers_container a_deques; + bool a_rotate; + + public: + ProgrammedAnswers() { a_rotate = false; } + ~ProgrammedAnswers() { clear(); } + + bool rotate() const throw() { return a_rotate; } + void rotate(bool r) throw() { a_rotate = r; } + + void clear () throw() { + for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { + anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); + engine->releaseMessage(*(it->second->begin())); + delete(it->second); + } + a_deques.clear(); + } + + void dump () throw() { + std::string outfilename, xmlString; + for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { + int sequence = 1; + for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { + // programmed_answer.. + outfilename = "programmed_answer."; + outfilename += anna::functions::asString(it->first); + outfilename += "."; + outfilename += anna::functions::asString(sequence++); + outfilename += ".xml"; + std::ofstream outfile(outfilename.c_str(), std::ifstream::out); + xmlString = (*itm)->asXMLString(); + outfile.write(xmlString.c_str(), xmlString.size()); + outfile.close(); + } + } + } + + void addMessage(int code, anna::diameter::codec::Message *message) throw() { + reacting_answers_const_iterator it = a_deques.find(code); + if (it != a_deques.end()) { + it->second->push_back(message); + } + else { + codec_messages_deque *deque = new codec_messages_deque; + a_deques[code] = deque; + deque->push_back(message); + } + } + + anna::diameter::codec::Message* getMessage(int code) const throw() { //get the front message (begin()), returns NULL if deque is empty + anna::diameter::codec::Message *result = NULL; + reacting_answers_const_iterator it = a_deques.find(code); + if (it != a_deques.end()) { + if (!it->second->empty()) result = *(it->second->begin()); + } + return result; + } + + void nextMessage(int code) throw() { //pops the deque and release the message (when deque is not empty: deque::empty) + reacting_answers_const_iterator it = a_deques.find(code); + if (it != a_deques.end()) { + if (!it->second->empty()) { + anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); + if (a_rotate) { + addMessage(code, *(it->second->begin())); + } + else { + engine->releaseMessage(*(it->second->begin())); + } + it->second->pop_front(); + } + } + } + + std::string asString(const char *queueName) const throw() { + std::string result = ""; + std::string aux = "FIFO QUEUE '"; + aux += queueName; + aux += "', Rotation "; + aux += a_rotate ? "enabled":"disabled"; + result += anna::functions::highlightJustify(aux); + if(a_deques.size() != 0) { + for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { + if (it->second->size() != 0) { + aux = "Answer code "; + aux += anna::functions::asString(it->first); + result += anna::functions::highlightJustify(aux, anna::functions::TextHighlightMode::OverAndUnderline, + anna::functions::TextJustifyMode::Left, '-'); + for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { + result += (*itm)->asXMLString(); + result += "\n"; + } + result += "\n"; + } + } + } + else { + result = "No ocurrences found\n\n"; + } + return result; + } +}; + +ProgrammedAnswers G_reactingAnswers2C, G_reactingAnswers2E; @@ -207,6 +289,7 @@ class MyDiameterEntity : public anna::diameter::comm::Entity { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); + void eventDPA(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); // Reimplementation int readSocketId(const anna::diameter::comm::Message* message, int maxClientSessions) const throw(); @@ -217,6 +300,7 @@ class MyLocalServer : public anna::diameter::comm::LocalServer { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); + void eventDPA(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); }; class MyDiameterEngine : public anna::diameter::comm::Engine { @@ -285,7 +369,7 @@ class Launcher : public anna::comm::Application { anna::diameter::comm::Entity *a_entity; std::string a_logFile, a_burstLogFile; std::ofstream a_burstLogStream; - bool a_splitLog, a_detailedLog; + bool a_splitLog, a_detailedLog, a_dumpLog; anna::time::Date a_start_time; anna::timex::Engine* a_timeEngine; MyCounterRecorder *a_counterRecorder; @@ -324,14 +408,13 @@ 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(); } void resetCounters() throw(); void signalUSR2() throw(anna::RuntimeException); std::string help() const throw(); - std::string programmedAnswers2e() const throw(); - std::string programmedAnswers2c() const throw(); // helpers bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw(); @@ -666,7 +749,7 @@ std::string Launcher::help() const throw() { result += "\n establish as minimum), separate statistics analyzer per each resource, automatic CER/CEA and DWR/DWA"; result += "\n generation, expiration control and many more features."; result += "\n"; - result += "\nProcess traces are dump on \"launcher.traces\" and could have any trace level (POSIX levels), usually"; + result += "\nProcess traces are dump on \"launcher.trace\" and could have any trace level (POSIX levels), usually"; result += "\n 'debug' or 'warning'. See ANNA documentation for more details."; result += "\n"; result += "\nAs any other ANNA process, context dump could be retrieved sending SIGUSR1 signal:"; @@ -736,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.' by mean 'kill -10 '."; + result += "\nforceCountersRecord Forces dump to file the current counters of the process."; result += "\n"; result += "\n|[
:]|[socket id]"; result += "\n"; @@ -754,10 +838,20 @@ std::string Launcher::help() const throw() { result += "\nsendxml2e| Sends xml source file (pathfile) through configured entity."; result += "\nsendxml2c| Sends xml source file (pathfile) to client."; result += "\nsendxml| Same as 'sendxml2e'."; - result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for corresponding request from entity."; - result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for corresponding request from client."; + result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for incoming request with same code from entity."; + result += "\n The answer is stored in a FIFO queue for a specific message code, then there are"; + result += "\n as many queues as different message codes have been programmed."; + result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for incoming request with same code from client."; + result += "\n The answer is stored in a FIFO queue for a specific message code, then there are"; + result += "\n as many queues as different message codes have been programmed."; result += "\nanswerxml|[source_file] Same as 'answerxml2c'."; - result += "\n List programmed answers if no parameter provided."; + result += "\nanswerxml(2e/2c) List programmed answers (to entity/client) if no parameter provided."; + result += "\nanswerxml(2e/2c)|dump Write programmed answers (to entity/client) to file 'programmed_answer..',"; + result += "\n where 'sequence' is the order of the answer in each FIFO code-queue of programmed answers."; + result += "\nanswerxml(2e/2c)|clear Clear programmed answers (to entity/client)."; + result += "\nanswerxml(2e/2c)|exhaust Disable the corresponding queue rotation, which is the default behaviour."; + result += "\nanswerxml(2e/2c)|rotate Enable the corresponding queue rotation, useful in performance tests."; + result += "\n Rotation consists in add again to the queue, each element retrieved for answering."; result += "\n"; result += "\nSend operations are available using hexadecimal content (hex formatted files) which also allow to test"; result += "\nspecial scenarios (protocol errors):"; @@ -767,8 +861,8 @@ std::string Launcher::help() const throw() { result += "\nsendhex| Same as 'sendhex2e'."; result += "\n"; result += "\nAnswer programming in hexadecimal is not really neccessary (you could use send primitives) and also"; - result += "\nis intended to be used with decoded messages in order to replace things like hop by hop, end to end,"; - result += "\nsubscriber id, session id, etc. Anyway you could use 'decode' operation and then program the xml created."; + result += "\n is intended to be used with decoded messages in order to replace things like hop by hop, end to end,"; + result += "\n subscriber id, session id, etc. Anyway you could use 'decode' operation and then program the xml created."; result += "\n"; result += "\nIf a request is received, answer map (built with 'answerxml<[2c] or 2e>' operations) will be"; result += "\n checked to find a corresponding programmed answer to be replied(*). If no ocurrence is found,"; @@ -776,6 +870,11 @@ std::string Launcher::help() const throw() { result += "\n or nothing but trace when no peer at that side is configured. Answer to client have sense when"; result += "\n diameter server socket is configured, answer to entity have sense when entity does."; result += "\n"; + result += "\nIn the most complete situation (process with both client and server side) there are internally"; + result += "\n two maps with N FIFO queues, one for each different message code within programmed answers."; + result += "\nOne map is for answers towards the client, and the other is to react entity requests. Then in"; + result += "\n each one we could program different answers corresponding to different request codes received."; + result += "\n"; result += "\n(*) sequence values (hop-by-hop and end-to-end), Session-Id and Subscription-Id avps, are mirrored"; result += "\n to the peer which sent the request. If user wants to test a specific answer without changing it,"; result += "\n use sendxml/sendhex operations better than programming."; @@ -871,39 +970,6 @@ std::string Launcher::help() const throw() { } -std::string Launcher::programmedAnswers2c() const throw() { - std::string result = "\n"; - result += "\n ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n"; - - if(G_reactingAnswers2C.size() == 0) { - result += "No ocurrences found\n\n"; - } else { - for(reacting_answers_const_iterator it = G_reactingAnswers2C.begin(); it != G_reactingAnswers2C.end(); it++) { - result += (*it).second->asXMLString(); - result += "\n\n"; - } - } - - return result; -} - - -std::string Launcher::programmedAnswers2e() const throw() { - std::string result = "\n"; - result += "\n\n ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n"; - - if(G_reactingAnswers2E.size() == 0) { - result += "No ocurrences found\n\n"; - } else { - for(reacting_answers_const_iterator it = G_reactingAnswers2E.begin(); it != G_reactingAnswers2E.end(); it++) { - result += (*it).second->asXMLString(); - result += "\n\n"; - } - } - - return result; -} - void MyCommunicator::prepareAnswer(anna::diameter::codec::Message *answer, const anna::DataBlock &request) const throw() { // Sequence values (hop-by-hop and end-to-end), session-id and subscription-id avps, are mirrored to the peer which sent the request. // If user wants to test a specific answer without changing it, use send operations better than programming. @@ -966,7 +1032,7 @@ using namespace anna::diameter; int main(int argc, const char** argv) { anna::Logger::setLevel(anna::Logger::Warning); - anna::Logger::initialize("launcher", new TraceWriter("launcher.traces", 2048000)); + anna::Logger::initialize("launcher", new TraceWriter("launcher.trace", 2048000)); anna::time::functions::initialize(); // before application instantiation (it have a anna::time object) anna::time::functions::setControlPoint(); // start control point (application lifetime) Launcher app; @@ -979,6 +1045,7 @@ int main(int argc, const char** argv) { commandLine.add("log", anna::CommandLine::Argument::Optional, "Process log file (operations result, traffic log, etc.). By default 'launcher.log'. Empty string or \"null\" name, to disable. Warning: there is no rotation for log files (use logrotate or whatever)"); commandLine.add("splitLog", anna::CommandLine::Argument::Optional, "Splits log file (appends to log filename, extensions with the type of event: see help on startup information-level traces). No log files for code/decode and load operations are created", false); commandLine.add("detailedLog", anna::CommandLine::Argument::Optional, "Insert detailed information at log files. Should be disabled on automatic tests. Useful on '-balance' mode to know messages flow along the sockets", false); + commandLine.add("dumpLog", anna::CommandLine::Argument::Optional, "Write to disk every incoming/outcoming message named as '.....xml'", false); commandLine.add("logStatisticSamples", anna::CommandLine::Argument::Optional, "Log statistics samples for the provided concept id list, over './sample..csv' files. For example: \"1,2\" will log concepts 1 and 2. Reserved word \"all\" activates all registered statistics concept identifiers. That ids are shown at context dump (see help to get it)."); commandLine.add("burstLog", anna::CommandLine::Argument::Optional, "Burst operations log file. By default 'launcher.burst'. Empty string or \"null\" name, to disable. Warning: there is no rotation for log files (use logrotate or whatever). Output: dot (.) for each burst message sent/pushed, cross (x) for popped ones, and order number when multiple of 1% of burst list size, plus OTA requests when changed."); commandLine.add("cntDir", anna::CommandLine::Argument::Optional, "Counters directory. By default is the current execution directory. Warning: a counter file will be dump per record period; take care about the possible accumulation of files"); @@ -1006,7 +1073,8 @@ int main(int argc, const char** argv) { commandLine.add("originHost", anna::CommandLine::Argument::Optional, "Diameter application host name (system name). If missing, process sets o.s. hostname"); commandLine.add("originRealm", anna::CommandLine::Argument::Optional, "Diameter application node realm name. If missing, process sets domain name"); commandLine.add("integrationAndDebugging", anna::CommandLine::Argument::Optional, "Sets validation mode to 'Always' (default validates only after decoding), and validation depth to 'Complete' (default validates until 'FirstError')", false); -// commandLine.add("clone", anna::CommandLine::Argument::Optional, "Enables fork mode for request processing", false); + commandLine.add("fixMode", anna::CommandLine::Argument::Optional, "Sets message fix mode (unreconized values will assume default 'BeforeEncoding'). Allowed: 'BeforeEncoding', 'AfterDecoding', 'Always', 'Never'"); + commandLine.initialize(argv, argc); commandLine.verify(); std::cout << commandLine.asString() << std::endl; @@ -1027,6 +1095,7 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " a_burstLogFile = "launcher.burst"; a_splitLog = false; a_detailedLog = false; + a_dumpLog = false; a_timeEngine = NULL; a_counterRecorder = NULL; a_counterRecorderClock = NULL; @@ -1203,6 +1272,8 @@ void Launcher::writeLogFile(const anna::diameter::codec::Message & decodedMessag title += "]"; // Build complete log: std::string log = "\n"; + std::string xml = decodedMessage.asXMLString(); + if(a_detailedLog) { anna::time::Date now; @@ -1210,7 +1281,7 @@ void Launcher::writeLogFile(const anna::diameter::codec::Message & decodedMessag title += " "; title += now.asString(); log += anna::functions::highlight(title, anna::functions::TextHighlightMode::OverAndUnderline); - log += decodedMessage.asXMLString(); + log += xml; log += "\n"; log += anna::functions::highlight("Used resource"); log += detail; @@ -1218,10 +1289,25 @@ void Launcher::writeLogFile(const anna::diameter::codec::Message & decodedMessag } else { log += title; log += "\n"; - log += decodedMessage.asXMLString(); + log += xml; log += "\n"; } + if(a_dumpLog) { + std::string name = anna::functions::asString(decodedMessage.getHopByHop()); + name += "."; + name += anna::functions::asString(decodedMessage.getEndToEnd()); + name += "."; + name += anna::functions::asString(decodedMessage.getId().first); + name += "."; + name += ((decodedMessage.getId().second) ? "request.":"answer."); + name += logExtension; + name += ".xml"; + ofstream outMsg(name.c_str(), ifstream::out | ifstream::app); + outMsg.write(xml.c_str(), xml.size()); + outMsg.close(); + } + // Write and close out.write(log.c_str(), log.size()); out.close(); @@ -1517,6 +1603,18 @@ throw(anna::RuntimeException) { codecEngine->setValidationDepth(anna::diameter::codec::Engine::ValidationDepth::Complete); } + // Fix mode + if(cl.exists("fixMode")) { // BeforeEncoding(default), AfterDecoding, Always, Never + std::string fixMode = cl.getValue("fixMode"); + anna::diameter::codec::Engine::FixMode::_v fm; + if (fixMode == "BeforeEncoding") fm = anna::diameter::codec::Engine::FixMode::BeforeEncoding; + else if (fixMode == "AfterDecoding") fm = anna::diameter::codec::Engine::FixMode::AfterDecoding; + else if (fixMode == "Always") fm = anna::diameter::codec::Engine::FixMode::Always; + else if (fixMode == "Never") fm = anna::diameter::codec::Engine::FixMode::Never; + else LOGINFORMATION(anna::Logger::information("Unreconized command-line fix mode. Assumed default 'BeforeEncoding'", ANNA_FILE_LOCATION)); + codecEngine->setFixMode(fm); + } + codecEngine->ignoreFlagsOnValidation(cl.exists("ignoreFlags")); // Diameter Server: @@ -1585,6 +1683,8 @@ throw(anna::RuntimeException) { if(cl.exists("detailedLog")) a_detailedLog = true; + if(cl.exists("dumpLog")) a_dumpLog = true; + if(cl.exists("burstLog")) a_burstLogFile = cl.getValue("burstLog"); // Log statistics concepts @@ -1697,7 +1797,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons std::string s_help = help(); std::cout << s_help << std::endl; LOGINFORMATION(anna::Logger::information(s_help, ANNA_FILE_LOCATION)); - response_content = "Help dumped on stdout and information-level traces (launcher.traces file)\n"; + response_content = "Help dumped on stdout and information-level traces (launcher.trace file)\n"; return; } @@ -1709,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; @@ -1987,7 +2094,19 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(!localServer) throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION); - if(param1 != "") { + if(param1 == "") { // programmed answers FIFO's to stdout + std::cout << G_reactingAnswers2C.asString("ANSWERS TO CLIENT") << std::endl; + response_content = "Programmed answers dumped on stdout\n"; + return; + } else if (param1 == "rotate") { + G_reactingAnswers2C.rotate(true); + } else if (param1 == "exhaust") { + G_reactingAnswers2C.rotate(false); + } else if (param1 == "clear") { + G_reactingAnswers2C.clear(); + } else if (param1 == "dump") { + G_reactingAnswers2C.dump(); + } else { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); anna::diameter::codec::Message *message = engine->createMessage(param1); LOGDEBUG @@ -1999,18 +2118,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION); int code = message->getId().first; - reacting_answers_const_iterator it = G_reactingAnswers2C.find(code); - - if(it != G_reactingAnswers2C.end()) { // found: replace - LOGDEBUG(anna::Logger::debug("Replacing formerly programed answer...", ANNA_FILE_LOCATION)); - engine->releaseMessage((*it).second); - } - - G_reactingAnswers2C[code] = message; - } else { // answers query on stdout - std::cout << programmedAnswers2c() << std::endl; - response_content = "Programmed answers dumped on stdout\n"; - return; + LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION)); + G_reactingAnswers2C.addMessage(code, message); } } else if(opType == "answerxml2e") { anna::diameter::comm::Entity *entity = getEntity(); @@ -2018,7 +2127,19 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(!entity) throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION); - if(param1 != "") { + if(param1 == "") { // programmed answers FIFO's to stdout + std::cout << G_reactingAnswers2E.asString("ANSWERS TO ENTITY") << std::endl; + response_content = "Programmed answers dumped on stdout\n"; + return; + } else if (param1 == "rotate") { + G_reactingAnswers2C.rotate(true); + } else if (param1 == "exhaust") { + G_reactingAnswers2C.rotate(false); + } else if (param1 == "clear") { + G_reactingAnswers2E.clear(); + } else if (param1 == "dump") { + G_reactingAnswers2E.dump(); + } else { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); anna::diameter::codec::Message *message = engine->createMessage(param1); LOGDEBUG @@ -2030,18 +2151,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION); int code = message->getId().first; - reacting_answers_const_iterator it = G_reactingAnswers2E.find(code); - - if(it != G_reactingAnswers2E.end()) { // found: replace - LOGDEBUG(anna::Logger::debug("Replacing formerly programed answer...", ANNA_FILE_LOCATION)); - engine->releaseMessage((*it).second); - } - - G_reactingAnswers2E[code] = message; - } else { // answers query on stdout - std::cout << programmedAnswers2e() << std::endl; - response_content = "Programmed answers dumped on stdout\n"; - return; + LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION)); + G_reactingAnswers2E.addMessage(code, message); } } else { LOGWARNING(anna::Logger::warning(help(), ANNA_FILE_LOCATION)); @@ -2098,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 '"; @@ -2184,10 +2295,8 @@ throw(anna::RuntimeException) { // Lookup reacting answers list: int code = cid.first; - reacting_answers_const_iterator it = G_reactingAnswers2E.find(code); - - if(it != G_reactingAnswers2E.end()) { - anna::diameter::codec::Message *answer_message = (*it).second; + anna::diameter::codec::Message *answer_message = G_reactingAnswers2E.getMessage(code); + if (answer_message) { // Prepare answer: my_app.getCommunicator()->prepareAnswer(answer_message, message); @@ -2201,26 +2310,38 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(*answer_message, "send2eError", clientSession->asString()); } - } else { // not found: forward to client (if exists) - // Forward to client: - anna::diameter::comm::LocalServer *localServer = my_app.getDiameterLocalServer(); - 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->setBody(message); - msg->setRequestClientSessionKey(clientSession->getKey()); - bool success = localServer->send(msg); + // Pop front the reacting answer: + G_reactingAnswers2E.nextMessage(code); + return; + } - // Detailed log: - if(my_app.logEnabled()) { - anna::diameter::comm::ServerSession *usedServerSession = localServer->getLastUsedResource(); - std::string detail = usedServerSession ? usedServerSession->asString() : ""; // esto no deberia ocurrir - my_app.writeLogFile(message, (success ? "fwd2c" : "fwd2cError"), detail); - } - } catch(anna::RuntimeException &ex) { - ex.trace(); + LOGDEBUG + ( + std::string msg = "No answers programmed (maybe sold out) for request coming from entity: "; + msg += anna::diameter::functions::commandIdAsPairString(cid); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); + + // not found: forward to client (if exists) + // Forward to client: + anna::diameter::comm::LocalServer *localServer = my_app.getDiameterLocalServer(); + + 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->setBody(message); + msg->setRequestClientSessionKey(clientSession->getKey()); + bool success = localServer->send(msg); + + // Detailed log: + if(my_app.logEnabled()) { + anna::diameter::comm::ServerSession *usedServerSession = localServer->getLastUsedResource(); + std::string detail = usedServerSession ? usedServerSession->asString() : ""; // esto no deberia ocurrir + my_app.writeLogFile(message, (success ? "fwd2c" : "fwd2cError"), detail); } + } catch(anna::RuntimeException &ex) { + ex.trace(); } } } @@ -2337,8 +2458,27 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe-ans-unknown", clientSession->asString()); } +void MyDiameterEntity::eventDPA(anna::diameter::comm::ClientSession *clientSession, const anna::DataBlock &message) +throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("launcher::MyDiameterEntity", "eventDPA", ANNA_FILE_LOCATION)); + // Performance stats: + Launcher& my_app = static_cast (anna::app::functions::getApp()); + // CommandId: + anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); + LOGDEBUG + ( + std::string msg = "Disconnect-Peer-Answer received from entity: "; + msg += anna::diameter::functions::commandIdAsPairString(cid); + msg += " | DiameterServer: "; + msg += anna::functions::socketLiteralAsString(clientSession->getAddress(), clientSession->getPort()); + msg += " | EventTime: "; + msg += anna::time::functions::currentTimeAsString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); - + // Write reception + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString()); +} void MyLocalServer::eventRequest(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) throw(anna::RuntimeException) { @@ -2364,10 +2504,10 @@ throw(anna::RuntimeException) { // If no answer is programmed and entity is configured, the failed request would be forwarded even being wrong (delegates at the end point) int code = cid.first; - reacting_answers_const_iterator it = G_reactingAnswers2C.find(code); - bool programmed = (it != G_reactingAnswers2C.end()); - anna::diameter::comm::Entity *entity = my_app.getEntity(); + anna::diameter::codec::Message *programmed_answer = G_reactingAnswers2C.getMessage(code); + bool programmed = (programmed_answer != NULL); + 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->setBody(message); @@ -2403,7 +2543,7 @@ throw(anna::RuntimeException) { // Programmed answer only when all is ok if(analysisOK) { if(programmed) { - answer_message = (*it).second; + answer_message = programmed_answer; // Prepare answer: my_app.getCommunicator()->prepareAnswer(answer_message, message); } else return; // nothing done @@ -2428,6 +2568,9 @@ throw(anna::RuntimeException) { // Restore validation mode codecEngine->setValidationMode(backupVM); + + // Pop front the reacting answer: + if(analysisOK && programmed) G_reactingAnswers2C.nextMessage(code); } void MyLocalServer::eventResponse(const anna::diameter::comm::Response &response) @@ -2535,6 +2678,26 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc-ans-unknown", serverSession->asString()); } +void MyLocalServer::eventDPA(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) +throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventDPA", ANNA_FILE_LOCATION)); + // Performance stats: + Launcher& my_app = static_cast (anna::app::functions::getApp()); + // CommandId: + anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); + LOGDEBUG + ( + std::string msg = "Disconnect-Peer-Answer response received from client: "; + msg += anna::diameter::functions::commandIdAsPairString(cid); + msg += " | DiameterServer: "; + msg += anna::functions::socketLiteralAsString(serverSession->getAddress(), serverSession->getPort()); + msg += " | EventTime: "; + msg += anna::time::functions::currentTimeAsString(); + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); + + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString()); +} anna::xml::Node* Launcher::asXML(anna::xml::Node* parent) const throw() {