X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fmain.cpp;h=49612e9210b43d857e1ee9a9787e455f7e27a6bf;hb=2032c82d206dd40e35d118242272417431094823;hp=4b36441045ce298ab67e621aa61cde640ba0b6b5;hpb=6c4aae8b2e861a6cbca6962611624a5aadadd6ad;p=anna.git diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 4b36441..49612e9 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -113,11 +113,15 @@ typedef std::map < int /* message code */, codec_messages_deque* >::iterator re 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() {}; + 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); @@ -172,29 +176,42 @@ typedef std::map < int /* message code */, codec_messages_deque* >::const_iterat if (it != a_deques.end()) { if (!it->second->empty()) { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); - engine->releaseMessage(*(it->second->begin())); + if (a_rotate) { + addMessage(code, *(it->second->begin())); + } + else { + engine->releaseMessage(*(it->second->begin())); + } it->second->pop_front(); } } } - std::string asString() const throw() { - std::string result = "No ocurrences found\n\n"; - std::string s_code; + 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) { - result = ""; for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { - - s_code = "Answer code "; - s_code += anna::functions::asString(it->first); - result += anna::functions::highlightJustify(s_code); - for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { - result += (*itm)->asXMLString(); + 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"; } - result += "\n"; } } + else { + result = "No ocurrences found\n\n"; + } return result; } }; @@ -380,7 +397,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; @@ -849,15 +866,18 @@ std::string Launcher::help() const throw() { result += "\nsendxml| Same as 'sendxml2e'."; 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 received."; + 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 received."; + result += "\n as many queues as different message codes have been programmed."; result += "\nanswerxml|[source_file] Same as 'answerxml2c'."; 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):"; @@ -1047,10 +1067,27 @@ int main(int argc, const char** argv) { try { CommandLine& commandLine(anna::CommandLine::instantiate()); // General + commandLine.add(NULL, anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("juan,pepe,maria", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("dos,palabras", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("x,y", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("-x", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("-ooox", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("--ooox", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("--x", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("x,-y", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("x,-lly", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("bueno,a-medias", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("bueno,en-te-ro", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + commandLine.add("b,a-ho-ra-si", anna::CommandLine::Argument::Optional, "XXXXXXXXXXXXXXXXXXXXX"); + + + commandLine.add("trace", anna::CommandLine::Argument::Optional, "Trace level (emergency, alert, critical, error, warning, notice, information, debug, local0..local7)"); 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"); @@ -1099,6 +1136,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; @@ -1275,6 +1313,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; @@ -1282,7 +1322,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; @@ -1290,10 +1330,23 @@ 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.xml":"answer.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(); @@ -1657,6 +1710,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 @@ -2060,11 +2115,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION); if(param1 == "") { // programmed answers FIFO's to stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n"; - std::cout << G_reactingAnswers2C.asString() << std::endl; + 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") { @@ -2091,11 +2148,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION); if(param1 == "") { // programmed answers FIFO's to stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n"; - std::cout << G_reactingAnswers2E.asString() << std::endl; + 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") {