X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fmain.cpp;h=3b1b75438a636359f7653cffd4e6e28ffd5f2a21;hb=3e258840b15577cb8bda3cdedd0b9b88e16404b3;hp=90f40ba2fe2c2380f9fbcea17e7329321600e604;hpb=4e12ac57e93c052f716a6305ad8fc099c45899d1;p=anna.git diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 90f40ba..3b1b754 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -1,4 +1,4 @@ -// ANNA - Anna is Not 'N' Anymore +// ANNA - Anna is Not Nothingness Anymore // // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo // @@ -34,12 +34,8 @@ // cisco.tierra@gmail.com -/* - Establece un manejador externo para controlar el teclado, recoge los parametros de la operacion - por este y envia la peticion al servidor. -*/ -#include #include +#include #include #include @@ -57,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -86,17 +83,20 @@ namespace diameter { namespace comm { class Entity; class Response; +class LocalServer; } } } +#define SIGUSR2_TASKS_INPUT_FILENAME "./sigusr2.tasks.input" +#define SIGUSR2_TASKS_OUTPUT_FILENAME "./sigusr2.tasks.output" + // Auxiliary message for sendings anna::diameter::comm::Message G_commMsgSent2c, G_commMsgSent2e, G_commMsgFwd2c, G_commMsgFwd2e; anna::diameter::comm::Message G_commMsg; anna::diameter::codec::Message G_codecMsg, G_codecAnsMsg; -anna::Recycler G_commMessages; // create en el forward de requets sin answer programada -// realease en el forward de answers +anna::Recycler G_commMessages; // create on requests forwards without programmed answer / release in answers forward // Auxiliary resources for answers programming @@ -107,6 +107,32 @@ reacting_answers_container G_reactingAnswers2C, G_reactingAnswers2E; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// COUNTERS RECORD PROCEDURE ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class MyCounterRecorderClock : public anna::timex::Clock { + public: + MyCounterRecorderClock(const char *clockName, const anna::Millisecond & timeout) : + anna::timex::Clock(clockName, timeout) {;} + //virtual ~MyCounterRecorderClock(); + + virtual bool tick() throw (RuntimeException) { + anna::diameter::comm::OamModule::instantiate().recordCounters(); + anna::diameter::codec::OamModule::instantiate().recordCounters(); + return true; + } +}; + +class MyCounterRecorder : public anna::oam::CounterRecorder { + + // pure virtual definitions: + void open() throw(anna::RuntimeException) {;} + void apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) {;} + void close() throw() {;} + std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 )"; } +}; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + class MyDiameterEntity : public anna::diameter::comm::Entity { void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); @@ -166,7 +192,6 @@ private: void evRequest(anna::comm::ClientSocket&, const anna::http::Request& request) throw(anna::RuntimeException); void evResponse(anna::comm::ClientSocket&, const anna::http::Response&) throw(anna::RuntimeException) {;} - void sendOperation(const std::string &, std::string &) throw(anna::RuntimeException); }; class MyCommunicator : public anna::comm::Communicator { @@ -184,17 +209,6 @@ private: void eventBreakConnection(Server* server) throw(); }; - -class MyCounterRecorder : public anna::oam::CounterRecorder { - - // pure virtual definitions: - void open() throw(anna::RuntimeException) {;} - void apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) {;} - void close() throw() {;} - std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 )"; } -}; - - class Launcher : public anna::comm::Application { MyCommunicator *a_communicator; @@ -206,6 +220,7 @@ class Launcher : public anna::comm::Application { anna::time::Date a_start_time; anna::timex::Engine* a_timeEngine; MyCounterRecorder *a_counterRecorder; + MyCounterRecorderClock *a_counterRecorderClock; std::string a_cerPathfile; std::string a_dwrPathfile; @@ -233,6 +248,7 @@ public: void baseProtocolSetupAsClient(void) throw(anna::RuntimeException); anna::diameter::comm::Entity *getEntity() throw() { return a_entity; } anna::diameter::comm::LocalServer* getDiameterLocalServer() throw() { return a_diameterLocalServer; } + void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException); bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); } void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw(); void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw(); @@ -243,6 +259,7 @@ public: 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(); @@ -494,104 +511,178 @@ void Launcher::resetCounters() throw() { oamDiameterComm.resetCounters(); } +void Launcher::signalUSR2() throw(anna::RuntimeException) { + + LOGNOTICE( + std::string msg = "Captured signal SIGUSR2. Reading tasks at '"; + msg += SIGUSR2_TASKS_INPUT_FILENAME; + msg += "' (results will be written at '"; + msg += SIGUSR2_TASKS_OUTPUT_FILENAME; + msg += "')"; + anna::Logger::notice(msg, ANNA_FILE_LOCATION); + ); + + // Operation: + std::string line; + std::string response_content; + + std::ifstream in_file (SIGUSR2_TASKS_INPUT_FILENAME); + std::ofstream out_file (SIGUSR2_TASKS_OUTPUT_FILENAME); + + if (!in_file.is_open()) throw RuntimeException("Unable to read tasks", ANNA_FILE_LOCATION); + if (!out_file.is_open()) throw RuntimeException("Unable to write tasks", ANNA_FILE_LOCATION); + + while (getline (in_file, line)) + { + LOGDEBUG( + std::string msg = "Processing line: "; + msg += line; + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); + + try { + eventOperation(line, response_content); + } catch (RuntimeException &ex) { + ex.trace(); + } + out_file << response_content; + } + in_file.close(); + out_file.close(); +} + + std::string Launcher::help() const throw() { std::string result = "\n"; result += "\n ------------- HELP -------------\n"; - result += "\nThe Diameter Launcher process is a complete diameter agent with client and server"; - result += "\ncapabilities as well as balancer (proxy) features. It could be used as diameter server"; - result += "\n(i.e. to simulate PCRF nodes, OCS systems, etc.), as diameter client (GGSNs, DPIs, etc.)"; - result += "\nand balancer systems to provide failover to external round-robin launchers). Also, auxiliary"; - result += "\nencoder/decoder/loader function could be deployed to reinterpret certain external flow and"; - result += "\nsend it to another process."; result += "\n"; - result += "\nAs any other ANNA process, context dump could be retrieved sending -10 signal:"; - result += "\n kill -10 ; vi /var/tmp/anna.context."; + result += "\nOVERVIEW"; + result += "\n--------"; + result += "\n"; + result += "\nThe ADL (ANNA Diameter Launcher) process is a complete diameter agent with client and server"; + result += "\n capabilities as well as balancer (proxy) features. It could be used as diameter server"; + result += "\n (i.e. to simulate PCRF nodes, OCS systems, etc.), as diameter client (GGSNs, DPIs, etc.),"; + result += "\n and balancer systems to provide failover to external round-robin launchers. Also, auxiliary"; + result += "\n encoder/decoder/loader function could be deployed to reinterpret certain external flow and"; + result += "\n send it to another process."; + result += "\n"; + result += "\nThe ANNA::diameter_comm built-in module provides a great set of characteristics as multiple connections"; + result += "\n on both server and client side, definition for multiple-server entities (and not only two as standard"; + 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 += "\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:"; + result += "\n kill -10 "; + result += "\n or"; + result += "\n kill -s SIGUSR1 "; + result += "\n and then"; + result += "\n vi /var/tmp/anna.context."; result += "\n"; result += "\nA complete xml report will show all the context information (counters, alarms, statistics,"; - result += "\nhandlers, diameter dictionary, etc.), and a powerful log module could dump all the events"; - result += "\nprocessed and flow information. Statistics could be analized at context dump and optionally"; - result += "\nwritten to disk as sample files with all the events measurements."; + result += "\n handlers, diameter dictionary, etc.), and a powerful log module could dump all the events"; + result += "\n processed and flow information. Statistics could be analized at context dump and optionally"; + result += "\n written to disk as sample files (useful for graphs and spreadsheet reports) with all the"; + result += "\n measurements."; result += "\n"; - result += "\nProcess traces are dump on \"launcher.traces\" and could have any trace level (POSIX levels):"; - result += "\nusually 'debug' or 'warning'. See ANNA documentation."; + result += "\nAlso SIGUSR2 is handled for management purposes. We will talk later about this."; result += "\n"; - result += "\nThe ANNA::diameter built-in module provide a great set of characteristics as multiple connections"; - result += "\non both server and client side, definition for multiple-server entities (and not only two as standard"; - result += "\nestablish as minimum), separate statistics analyzer per each resource, automatic CER/CEA and DWR/DWA"; - result += "\ngeneration, expiration control and many more features"; result += "\n"; - result += "\nOPERATIONS INTERFACE"; + result += "\nCOMMAND LINE"; + result += "\n------------"; result += "\n"; - result += "\nNDL supports several operations via HTTP interface. The HTTP request body content will"; - result += "\nbe an string with a command:"; + result += "\nStart the launcher process without arguments in order to see all the startup configuration"; + result += "\n posibilities, many of which could be modified on the air through the management interface"; + result += "\n (we will talk later about this great feature). Some of the more common parameters are:"; result += "\n"; - result += "\nFor example, we could launch an operation via curl:"; + result += "\nAs mandatory, the stack definition given through the xml dictionary:"; + result += "\n -dictionary "; + result += "\n"; + result += "\nActing as a diameter server (accepting i.e. 10 connections), you would have:"; + result += "\n -diameterServer localhost:3868 -diameterServerSessions 10 -entityServerSessions 0"; + result += "\n"; + result += "\nActing as a diameter client (launching i.e. 10 connections to each entity server), you would have:"; + result += "\n -entity 192.168.12.11:3868,192.168.12.21:3868 -entityServerSessions 10 -diameterServerSessions 0"; + result += "\n"; + result += "\nIf you act as a proxy or a translation agent, you need to combine both former setups, and probably"; + result += "\n will need to program the answers to be replied through the operations interface. To balance the"; + result += "\n traffic at your client side you shall use '-balance' and '-sessionBasedModelsClientSocketSelection'"; + result += "\n arguments in order to define the balancing behaviour."; + result += "\n"; + result += "\nThe process builds automatically CER and DWR messages as a client, but you could specify your own"; + result += "\n customized ones using '-cer ' and '-dwr '."; + result += "\nThe process builds automatically CEA and DWA messages as a server, but you could program your own"; + result += "\n customized ones using operations interface."; result += "\n"; - result += "\n curl -m 1 --data \"diameterServerSessions|4\" localhost:9000"; - result += "\n curl -m 1 --data \"code|ccr.xml\" localhost:9000"; - result += "\n curl -m 1 --data \"decode|ccr.hex\" localhost:9000"; - result += "\n curl -m 1 --data \"sendxml2e|ccr.xml\" localhost:9000"; - result += "\n etc."; result += "\n"; - result += "\nThese are the available commands:"; + result += "\nDYNAMIC OPERATIONS"; + result += "\n------------------"; result += "\n"; + result += "\nADL supports several operations which could be reconized via HTTP interface or SIGUSR2 caugh."; + result += "\nAn operation is specified by mean a string containing the operation name and needed arguments"; + result += "\n separated by pipes. These are the available commands:"; result += "\n"; - result += "\nGeneral -----------------------------"; + result += "\n--------------------------------------------------------------------------------------- General purpose"; result += "\n"; result += "\nhelp This help. Startup information-level traces also dump this help."; result += "\n"; - result += "\nParsing operations ------------------"; + result += "\n------------------------------------------------------------------------------------ Parsing operations"; result += "\n"; result += "\ncode|| Encodes source file (pathfile) into target file (pathfile)."; result += "\ndecode|| Decodes source file (pathfile) into target file (pathfile)."; result += "\nloadxml| Reinterpret xml source file (pathfile)."; result += "\n"; - result += "\nHot changes -------------------------"; + result += "\n------------------------------------------------------------------------------------------- Hot changes"; result += "\n"; - result += "\ndiameterServerSessions| Updates the maximum number of accepted connections to diameter server socket."; - result += "\ncollect Reset statistics and counters to start a new test stage of performance measurement."; - result += "\n Context data is written at '/var/tmp/anna.context.' by mean 'kill -10 '."; + result += "\ndiameterServerSessions| Updates the maximum number of accepted connections to diameter"; + result += "\n server socket."; + 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 += "\n"; result += "\n|[
:]|[socket id]"; result += "\n"; - result += "\n Actions: hide, show (update state) and hidden, shown (query state)."; - result += "\n Acts over a client session for messages delivery (except CER/A, DWR/A, DPR/A)."; - result += "\n If missing server (first parameter) all applications sockets will be affected."; - result += "\n If missing socket (second parameter) for specific server, all its sockets will be affected."; + result += "\n Actions: hide, show (update state) and hidden, shown (query state)."; + result += "\n Acts over a client session for messages delivery (except CER/A, DWR/A, DPR/A)."; + result += "\n If missing server (first parameter) all applications sockets will be affected."; + result += "\n If missing socket (second parameter) for specific server, all its sockets will be affected."; result += "\n"; - result += "\n All application client sessions are shown on startup, but standard delivery only use primary server ones except if fails."; - result += "\n Balance configuration use all the allowed sockets. You could also use command line 'sessionBasedModelsClientSocketSelection'"; - result += "\n to force traffic flow over certain client sessions, but for this, hide/show feature seems easier."; + result += "\n All application client sessions are shown on startup, but standard delivery only use primary"; + result += "\n server ones except if fails. Balance configuration use all the allowed sockets. You could also"; + result += "\n use command line 'sessionBasedModelsClientSocketSelection' to force traffic flow over certain"; + result += "\n client sessions, but for this, hide/show feature seems easier."; result += "\n"; - result += "\nFlow operations ---------------------"; + result += "\n--------------------------------------------------------------------------------------- Flow operations"; result += "\n"; - result += "\nsendxml2e| Sends xml source file (pathfile) through configured diameter entity."; - result += "\nsendxml2c| Sends xml source file (pathfile) to diameter client."; - result += "\nsendxml| Same as 'sendxml2e'."; - result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for corresponding request from diameter entity."; - result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for corresponding request from diameter client."; - result += "\nanswerxml|[source_file] Same as 'answerxml2c'."; - result += "\n List programmed answers if no parameter provided."; + 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 += "\nanswerxml|[source_file] Same as 'answerxml2c'."; + result += "\n List programmed answers if no parameter provided."; result += "\n"; - result += "\nIf a request is received, answer map (built with 'answerxml<[2c] or 2e>' operations) will be checked to find"; - result += "\na corresponding programmed answer to be replied(*). If no ocurrence is found, or answer message was received,"; - result += "\nthe message is forwarded to the other side (entity or client), or nothing but trace when no peer at that side"; - result += "\nis configured. Answer to client have sense when diameter server socket is configured, answer to entity have"; - result += "\nsense when entity does."; + 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,"; + result += "\n or answer message was received, the message is forwarded to the other side (entity or client),"; + 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 += "\n(*) sequence values (hop-by-hop and end-to-end), Session-Id and Subscription-Id avps, are mirrored to the"; - result += "\n peer which sent the request. If user wants to test a specific answer without changing it, use sendxml"; - result += "\n operations better than programming."; + 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 operations better than programming."; result += "\n"; - result += "\nBalance ('-balance' command line parameter) could be used to forward server socket receptions through entity servers"; - result += "\nby mean a round-robin algorithm. Both diameter server socket and entity targets should have been configured, that is"; - result += "\nto say: launcher acts as client and server. If no balance is used, an standard delivery is performed: first primary"; - result += "\nentity server, secondary when fails, etc."; + result += "\nBalance ('-balance' command line parameter) could be used to forward server socket receptions through"; + result += "\n entity servers by mean a round-robin algorithm. Both diameter server socket and entity targets should"; + result += "\n have been configured, that is to say: launcher acts as client and server. If no balance is used, an"; + result += "\n standard delivery is performed: first primary entity server, secondary when fails, etc."; result += "\n"; - result += "\nProcessing types --------------------"; + result += "\n--------------------------------------------------------------------------- Processing types (log tags)"; result += "\n"; - result += "\nUsed as log file extensions (when '-splitLog' is provided on command line) and context preffixes on log details when"; - result += "\nunique log file is dumped:"; + result += "\nUsed as log file extensions (when '-splitLog' is provided on command line) and context preffixes on log"; + result += "\n details when unique log file is dumped:"; result += "\n"; result += "\n [sent2e/send2eError] Send to entity (success/error)"; result += "\n [sent2c/send2cError] Send to client (success/error)"; @@ -601,35 +692,76 @@ std::string Launcher::help() const throw() { result += "\n [recvfe] Reception from entity"; result += "\n [req2c-expired] A request sent to client has been expired"; result += "\n [req2e-expired] A request sent to entity has been expired"; - result += "\n [recvfc-ans-unknown] Reception from client of an unknown answer (probably former [req2c-expired] has been logged)"; - result += "\n [recvfe-ans-unknown] Reception from entity of an unknown answer (probably former [req2e-expired] has been logged)"; + result += "\n [recvfc-ans-unknown] Reception from client of an unknown answer (probably former [req2c-expired]"; + result += "\n has been logged)"; + result += "\n [recvfe-ans-unknown] Reception from entity of an unknown answer (probably former [req2e-expired]"; + result += "\n has been logged)"; result += "\n"; - result += "\nLoad tests --------------------------"; + result += "\n-------------------------------------------------------------------------------------------- Load tests"; result += "\n"; - result += "\nburst||[parameter] Used for performance testing, we first program diameter requests messages in order"; - result += "\n to launch them from client side to the configured diameter entity. We could start"; - result += "\n the burst with an initial load (non-asynchronous sending), after this, a new request"; - result += "\n will be sent per answer received or expired context. There are 10 actions: clear, load"; - result += "\n start, push, pop, stop, repeat, send, goto and look."; + result += "\nburst||[parameter] Used for performance testing, we first program diameter requests"; + result += "\n messages in order to launch them from client side to the configured"; + result += "\n diameter entity. We could start the burst with an initial load"; + result += "\n (non-asynchronous sending), after this, a new request will be sent"; + result += "\n per answer received or expired context. There are 10 actions: clear,"; + result += "\n load, start, push, pop, stop, repeat, send, goto and look."; result += "\n"; - result += "\n burst|clear clears all loaded burst messages."; - result += "\n burst|load| loads the next diameter message into launcher burst."; - result += "\n burst|start| starts (or restarts if already in progress) the message sending with a certain initial load."; - result += "\n burst|push| sends specific non-aynchronous load."; - result += "\n burst|pop| skip send burst messages in order to reduce over-the-air requests. Popping all OTA requests"; - result += "\n implies burst stop because no more answer will arrive to the process. Burst output file"; - result += "\n (-burstLog command line parameter) shows popped messages with crosses (x). Each cross"; - result += "\n represents one received answer for which no new request is sent."; - result += "\n burst|stop stops the burst cycle. You can resume pushing 1 load amount."; - result += "\n burst|repeat|[[yes]|no] restarts the burst launch when finish. If initial load or push load amount is"; - result += "\n greater than burst list size, they will be limited when the list is processed"; - result += "\n except when repeat mode is enabled."; - result += "\n burst|send| send messages from burst list. The main difference with start/push operations is that burst"; - result += "\n won't be awaken. Externally we could control sending time (no request will be sent for answers)."; - result += "\n burst|goto| Updates current burst pointer position."; - result += "\n burst|look| Show programmed burst message for order provided."; + result += "\n burst|clear Clears all loaded burst messages."; + result += "\n burst|load| Loads the next diameter message into launcher burst."; + result += "\n burst|start| Starts (or restarts if already in progress) the message sending with"; + result += "\n a certain initial load."; + result += "\n burst|push| Sends specific non-aynchronous load."; + result += "\n burst|pop| Skip send burst messages in order to reduce over-the-air requests."; + result += "\n Popping all OTA requests implies burst stop because no more answer"; + result += "\n will arrive to the process. Burst output file (-burstLog command"; + result += "\n line parameter) shows popped messages with crosses (x). Each cross"; + result += "\n represents one received answer for which no new request is sent."; + result += "\n burst|stop Stops the burst cycle. You can resume pushing 1 load amount."; + result += "\n burst|repeat|[[yes]|no] Restarts the burst launch when finish. If initial load or push load"; + result += "\n amount is greater than burst list size, they will be limited when"; + result += "\n the list is processed except when repeat mode is enabled."; + result += "\n burst|send| Sends messages from burst list. The main difference with start/push"; + result += "\n operations is that burst won't be awaken. Externally we could control"; + result += "\n sending time (no request will be sent for answers)."; + result += "\n burst|goto| Updates current burst pointer position."; + result += "\n burst|look| Show programmed burst message for order provided."; + result += "\n"; + result += "\n"; + result += "\nUSING OPERATIONS INTERFACE"; + result += "\n--------------------------"; + result += "\n"; + result += "\n------------------------------------------------------------------------- Operations via HTTP interface"; + result += "\n"; + result += "\nAll the operations described above can be used through the optional HTTP interface. You only have"; + result += "\n to define the http server at the command line with something like: '-httpServer localhost:9000'."; + result += "\nTo send the task, we shall build the http request body with the operation string. Some examples"; + result += "\n using curl client could be:"; + result += "\n"; + result += "\n curl -m 1 --data \"diameterServerSessions|4\" localhost:9000"; + result += "\n curl -m 1 --data \"code|ccr.xml\" localhost:9000"; + result += "\n curl -m 1 --data \"decode|ccr.hex\" localhost:9000"; + result += "\n curl -m 1 --data \"sendxml2e|ccr.xml\" localhost:9000"; + result += "\n etc."; result += "\n"; + result += "\n------------------------------------------------------------------------- Operations via SIGUSR2 signal"; result += "\n"; + result += "\nThe alternative using SIGUSR2 signal requires the creation of the task(s) file which will be read at"; + result += "\n signal event:"; + result += "\n echo \"<\" > "; result += SIGUSR2_TASKS_INPUT_FILENAME; + result += "\n then"; + result += "\n kill -12 "; + result += "\n or"; + result += "\n kill -s SIGUSR2 "; + result += "\n and then see the results:"; + result += "\n cat "; result += SIGUSR2_TASKS_OUTPUT_FILENAME; + result += "\n"; + result += "\nYou could place more than one line (task) in the input file. Output reports will be appended in that"; + result += "\n case over the output file. Take into account that all the content of the task file will be executed"; + result += "\n sinchronously by the process. If you are planning traffic load, better use the asynchronous http"; + result += "\n interface."; + result += "\n"; + result += "\n"; + return result; } @@ -745,7 +877,7 @@ int main(int argc, const char** argv) { 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."); // Communications - commandLine.add("httpServer", anna::CommandLine::Argument::Mandatory, "HTTP Management interface address (using i.e. curl tool) in '
:' format. For example: 10.20.30.40:8080"); + commandLine.add("httpServer", anna::CommandLine::Argument::Optional, "HTTP Management interface address (using i.e. curl tool) in '
:' format. For example: 10.20.30.40:8080"); commandLine.add("httpServerShared", anna::CommandLine::Argument::Optional, "Enables shared bind for HTTP Management interface address. It would be useful i.e. to allow a great amount of curl operations per second", false); commandLine.add("diameterServer", anna::CommandLine::Argument::Optional, "Diameter own server address in '
:' format. For example: 10.20.30.40:3868"); commandLine.add("diameterServerSessions", anna::CommandLine::Argument::Optional, "Diameter own server available connections (0: diameter server disabled). Default value of 1"); @@ -781,7 +913,7 @@ int main(int argc, const char** argv) { Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", "1.1"), a_communicator(NULL) { a_myDiameterEngine = new MyDiameterEngine(); - a_myDiameterEngine->setRealm("NDL.ericsson.com"); + a_myDiameterEngine->setRealm("ADL.ericsson.com"); a_myDiameterEngine->setAutoBind(false); // allow to create client-sessions without binding them, in order to set timeouts. //a_myDiameterEngine->setFreezeEndToEndOnSending(); a_logFile = "launcher.log"; @@ -790,6 +922,7 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " a_detailedLog = false; a_timeEngine = NULL; a_counterRecorder = NULL; + a_counterRecorderClock = NULL; a_entity = NULL; a_diameterLocalServer = NULL; a_cerPathfile = "cer.xml"; @@ -1064,6 +1197,8 @@ throw(anna::RuntimeException) { a_communicator = new MyCommunicator(workMode); a_timeEngine = new anna::timex::Engine((anna::Millisecond)300000, (anna::Millisecond)150); a_counterRecorder = new MyCounterRecorder(); + a_counterRecorderClock = new MyCounterRecorderClock("Counters record procedure clock", Millisecond(10000)); + //a_counterRecorderClock = new MyCounterRecorderClock("Counters record procedure clock", Millisecond(300000)); } void Launcher::run() @@ -1081,6 +1216,7 @@ throw(anna::RuntimeException) { oamDiameterComm.initializeCounterScope(1); // 1000 - 1999 anna::diameter::codec::OamModule & oamDiameterCodec = anna::diameter::codec::OamModule::instantiate(); oamDiameterCodec.initializeCounterScope(2); // 2000 - 2999 + ///////////////// // COMM MODULE // ///////////////// @@ -1178,10 +1314,13 @@ throw(anna::RuntimeException) { oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedRuleForCardinalityMoreThanNeeded, "", 17 /*2017*/); oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedGenericAvpRuleForCardinalityFoundDisregardedItem, "", 18 /*2018*/); oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FoundDisregardedItemsAndGenericAVPWasNotSpecified, "", 19 /*2019*/); - anna::oam::CounterManager& cm = anna::oam::CounterManager::instantiate(); - cm.setEngine(a_timeEngine); - cm.setRecordPeriod(Millisecond(300000)); - cm.setCounterRecorder(static_cast(a_counterRecorder)); + + ///////////////////////////////// + // Counter recorder associated // + ///////////////////////////////// + oamDiameterComm.setCounterRecorder(a_counterRecorder); + oamDiameterCodec.setCounterRecorder(a_counterRecorder); + a_timeEngine->activate(a_counterRecorderClock); // start clock // Checking command line parameters if (cl.exists("sessionBasedModelsClientSocketSelection")) { @@ -1205,13 +1344,16 @@ throw(anna::RuntimeException) { anna::Logger::information(msg, ANNA_FILE_LOCATION); ); // HTTP Server: - anna::comm::Network& network = anna::comm::Network::instantiate(); - std::string address; - int port; - anna::functions::getAddressAndPortFromSocketLiteral(cl.getValue("httpServer"), address, port); -// const anna::comm::Device* device = network.find(Device::asAddress(address)); // aqui hay que proporcionar una IP ! - const anna::comm::Device* device = *((network.resolve(address)->device_begin())); // ArtimaƱa para resolver (IP o hostname) - a_httpServerSocket = new anna::comm::ServerSocket(anna::comm::INetAddress(device, port), cl.exists("httpServerShared") /* shared bind */, &anna::http::Transport::getFactory()); + if (cl.exists("httpServer")) { + anna::comm::Network& network = anna::comm::Network::instantiate(); + std::string address; + int port; + anna::functions::getAddressAndPortFromSocketLiteral(cl.getValue("httpServer"), address, port); + //const anna::comm::Device* device = network.find(Device::asAddress(address)); // aqui hay que proporcionar una IP ! + const anna::comm::Device* device = *((network.resolve(address)->device_begin())); // ArtimaƱa para resolver (IP o hostname) + a_httpServerSocket = new anna::comm::ServerSocket(anna::comm::INetAddress(device, port), cl.exists("httpServerShared") /* shared bind */, &anna::http::Transport::getFactory()); + } + // Stack: anna::diameter::codec::Engine *codecEngine = new anna::diameter::codec::Engine(); anna::diameter::stack::Engine &stackEngine = anna::diameter::stack::Engine::instantiate(); @@ -1348,7 +1490,7 @@ throw(anna::RuntimeException) { } a_communicator->setRecoveryTime((const anna::Millisecond)reconnectionPeriod); - a_communicator->attach(a_httpServerSocket); // HTTP + if (cl.exists("httpServer")) a_communicator->attach(a_httpServerSocket); // HTTP a_communicator->accept(); } @@ -1385,7 +1527,8 @@ throw(anna::RuntimeException) { std::string response_content; try { - sendOperation(body_content, response_content); + Launcher& my_app = static_cast (anna::app::functions::getApp()); + my_app.eventOperation(body_content, response_content); } catch (RuntimeException &ex) { ex.trace(); } @@ -1410,9 +1553,8 @@ throw(anna::RuntimeException) { } } -void MyHandler::sendOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { - LOGMETHOD(anna::TraceMethod tm("MyHandler", "sendOperation", ANNA_FILE_LOCATION)); - Launcher& my_app = static_cast (anna::app::functions::getApp()); +void Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("Launcher", "eventOperation", ANNA_FILE_LOCATION)); CommandLine& cl(anna::CommandLine::instantiate()); LOGDEBUG(anna::Logger::debug(operation, ANNA_FILE_LOCATION)); response_content = "Operation processed with exception. See traces\n"; // supposed @@ -1420,15 +1562,17 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons // Help: if (operation == "help") { - std::cout << my_app.help() << std::endl; + 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"; return; } // Reset performance data: if (operation == "collect") { - my_app.resetCounters(); - my_app.resetStatistics(); + resetCounters(); + resetStatistics(); response_content = "All process counters & statistic information have been reset\n"; return; } @@ -1440,7 +1584,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons //LOGDEBUG(anna::Logger::debug(anna::functions::asString("Number of operation parameters: %d", numParams), ANNA_FILE_LOCATION)); if (numParams > 2) { - LOGWARNING(anna::Logger::warning(my_app.help(), ANNA_FILE_LOCATION)); + LOGWARNING(anna::Logger::warning(help(), ANNA_FILE_LOCATION)); throw anna::RuntimeException("Wrong body content format on HTTP Request", ANNA_FILE_LOCATION); } @@ -1483,7 +1627,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons outfile.close(); infile.close(); } else if ((opType == "hide") || (opType == "show") || (opType == "hidden") || (opType == "shown")) { - anna::diameter::comm::Entity *entity = my_app.getEntity(); + anna::diameter::comm::Entity *entity = getEntity(); if (!entity) throw anna::RuntimeException("No entity configured to send messages", ANNA_FILE_LOCATION); @@ -1493,25 +1637,25 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons key += "|"; key += param2; - if (opType == "hide") my_app.getMyDiameterEngine()->findClientSession(key)->hide(); + if (opType == "hide") getMyDiameterEngine()->findClientSession(key)->hide(); - if (opType == "show") my_app.getMyDiameterEngine()->findClientSession(key)->show(); + if (opType == "show") getMyDiameterEngine()->findClientSession(key)->show(); - if (opType == "hidden") result = my_app.getMyDiameterEngine()->findClientSession(key)->hidden() ? "true" : "false"; + if (opType == "hidden") result = getMyDiameterEngine()->findClientSession(key)->hidden() ? "true" : "false"; - if (opType == "shown") result = my_app.getMyDiameterEngine()->findClientSession(key)->shown() ? "true" : "false"; + if (opType == "shown") result = getMyDiameterEngine()->findClientSession(key)->shown() ? "true" : "false"; } else { std::string address; int port; anna::functions::getAddressAndPortFromSocketLiteral(param1, address, port); - if (opType == "hide") my_app.getMyDiameterEngine()->findServer(address, port)->hide(); + if (opType == "hide") getMyDiameterEngine()->findServer(address, port)->hide(); - if (opType == "show") my_app.getMyDiameterEngine()->findServer(address, port)->show(); + if (opType == "show") getMyDiameterEngine()->findServer(address, port)->show(); - if (opType == "hidden") result = my_app.getMyDiameterEngine()->findServer(address, port)->hidden() ? "true" : "false"; + if (opType == "hidden") result = getMyDiameterEngine()->findServer(address, port)->hidden() ? "true" : "false"; - if (opType == "shown") result = my_app.getMyDiameterEngine()->findServer(address, port)->shown() ? "true" : "false"; + if (opType == "shown") result = getMyDiameterEngine()->findServer(address, port)->shown() ? "true" : "false"; } } else { if (opType == "hide") entity->hide(); @@ -1526,7 +1670,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (numParams != 1) throw anna::RuntimeException("Wrong body content format on HTTP Request for 'sendxml/sendxml2e' operation (missing parameter)", ANNA_FILE_LOCATION); - anna::diameter::comm::Entity *entity = my_app.getEntity(); + anna::diameter::comm::Entity *entity = getEntity(); if (!entity) throw anna::RuntimeException("No entity configured to send the message", ANNA_FILE_LOCATION); @@ -1538,17 +1682,17 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons bool success = entity->send(G_commMsgSent2e, cl.exists("balance")); // Detailed log: - if (my_app.logEnabled()) { + if (logEnabled()) { anna::diameter::comm::Server *usedServer = entity->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; std::string detail = usedClientSession ? usedClientSession->asString() : ""; // esto no deberia ocurrir - my_app.writeLogFile(G_codecMsg, (success ? "sent2e" : "send2eError"), detail); + writeLogFile(G_codecMsg, (success ? "sent2e" : "send2eError"), detail); } } else if ((opType == "burst")) { if (numParams < 1) throw anna::RuntimeException("Wrong body content format on HTTP Request for 'burst' operation (missing action parameter)", ANNA_FILE_LOCATION); - anna::diameter::comm::Entity *entity = my_app.getEntity(); + anna::diameter::comm::Entity *entity = getEntity(); if (!entity) throw anna::RuntimeException("No entity configured to use burst feature", ANNA_FILE_LOCATION); @@ -1567,7 +1711,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (param1 == "clear") { result = "Removed "; - result += anna::functions::asString(my_app.clearBurst()); + result += anna::functions::asString(clearBurst()); result += " elements."; } else if (param1 == "load") { if (param2 == "") throw anna::RuntimeException("Missing xml path file for burst load operation", ANNA_FILE_LOCATION); @@ -1577,7 +1721,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (G_codecMsg.isAnswer()) throw anna::RuntimeException("Cannot load diameter answers for burst feature", ANNA_FILE_LOCATION); try { G_codecMsg.valid(); } catch (anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue loading (see validation mode configured in launcher) - int position = my_app.loadBurstMessage(G_codecMsg.code()); + int position = loadBurstMessage(G_codecMsg.code()); result = "Loaded '"; result += param2; result += "' file into burst list position "; @@ -1586,7 +1730,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (param2 == "") throw anna::RuntimeException("Missing initial load for burst start operation", ANNA_FILE_LOCATION); int initialLoad = atoi(param2.c_str()); - int processed = my_app.startBurst(initialLoad); + int processed = startBurst(initialLoad); if (processed > 0) { result = "Initial load completed for "; @@ -1596,7 +1740,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons } else if (param1 == "push") { if (param2 == "") throw anna::RuntimeException("Missing load amount for burst push operation", ANNA_FILE_LOCATION); - int pushed = my_app.pushBurst(atoi(param2.c_str())); + int pushed = pushBurst(atoi(param2.c_str())); if (pushed > 0) { result = "Pushed "; @@ -1607,7 +1751,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (param2 == "") throw anna::RuntimeException("Missing amount for burst pop operation", ANNA_FILE_LOCATION); int releaseLoad = atoi(param2.c_str()); - int popped = my_app.popBurst(releaseLoad); + int popped = popBurst(releaseLoad); if (popped > 0) { result = "Burst popped for "; @@ -1615,7 +1759,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons result += "."; } } else if (param1 == "stop") { - int left = my_app.stopBurst(); + int left = stopBurst(); if (left != -1) { result += anna::functions::entriesAsString(left, "message"); @@ -1625,12 +1769,12 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (param2 == "") param2 = "yes"; bool repeat = (param2 == "yes"); - my_app.repeatBurst(repeat); + repeatBurst(repeat); result += (repeat ? "Mode on." : "Mode off."); } else if (param1 == "send") { if (param2 == "") throw anna::RuntimeException("Missing amount for burst send operation", ANNA_FILE_LOCATION); - int sent = my_app.sendBurst(atoi(param2.c_str())); + int sent = sendBurst(atoi(param2.c_str())); if (sent > 0) { result = "Sent "; @@ -1640,13 +1784,13 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons } else if (param1 == "goto") { if (param2 == "") throw anna::RuntimeException("Missing order position for burst goto operation", ANNA_FILE_LOCATION); - result = my_app.gotoBurst(atoi(param2.c_str())); + result = gotoBurst(atoi(param2.c_str())); result += "."; } else if (param1 == "look") { if (param2 == "") throw anna::RuntimeException("Missing order position for burst look operation", ANNA_FILE_LOCATION); result = "\n\n"; - result += my_app.lookBurst(atoi(param2.c_str())); + result += lookBurst(atoi(param2.c_str())); result += "\n\n"; } else { throw anna::RuntimeException("Wrong body content format on HTTP Request for 'burst' operation (unexpected action parameter). See help", ANNA_FILE_LOCATION); @@ -1655,7 +1799,7 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons if (numParams != 1) throw anna::RuntimeException("Wrong body content format on HTTP Request for 'sendxml2c' operation (missing parameter)", ANNA_FILE_LOCATION); - anna::diameter::comm::LocalServer *localServer = my_app.getDiameterLocalServer(); + anna::diameter::comm::LocalServer *localServer = getDiameterLocalServer(); if (!localServer) throw anna::RuntimeException("No local server configured to send the message", ANNA_FILE_LOCATION); @@ -1667,10 +1811,10 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons bool success = localServer->send(G_commMsgSent2c); // Detailed log: - if (my_app.logEnabled()) { + if (logEnabled()) { anna::diameter::comm::ServerSession *usedServerSession = localServer->getLastUsedResource(); std::string detail = usedServerSession ? usedServerSession->asString() : ""; // esto no deberia ocurrir - my_app.writeLogFile(G_codecMsg, (success ? "sent2c" : "send2cError"), detail); + writeLogFile(G_codecMsg, (success ? "sent2c" : "send2cError"), detail); } } else if (opType == "loadxml") { if (numParams != 1) @@ -1685,12 +1829,12 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons int diameterServerSessions = atoi(param1.c_str()); - if (!my_app.getDiameterLocalServer()) - my_app.startDiameterServer(diameterServerSessions); + if (!getDiameterLocalServer()) + startDiameterServer(diameterServerSessions); else - my_app.getDiameterLocalServer()->setMaxConnections(diameterServerSessions); + getDiameterLocalServer()->setMaxConnections(diameterServerSessions); } else if ((opType == "answerxml") || (opType == "answerxml2c")) { - anna::diameter::comm::LocalServer *localServer = my_app.getDiameterLocalServer(); + anna::diameter::comm::LocalServer *localServer = getDiameterLocalServer(); if (!localServer) throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION); @@ -1716,12 +1860,12 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons G_reactingAnswers2C[code] = message; } else { // answers query on stdout - std::cout << my_app.programmedAnswers2c() << std::endl; + std::cout << programmedAnswers2c() << std::endl; response_content = "Programmed answers dumped on stdout\n"; return; } } else if ((opType == "answerxml2e")) { - anna::diameter::comm::Entity *entity = my_app.getEntity(); + anna::diameter::comm::Entity *entity = getEntity(); if (!entity) throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION); @@ -1747,12 +1891,12 @@ void MyHandler::sendOperation(const std::string &operation, std::string &respons G_reactingAnswers2E[code] = message; } else { // answers query on stdout - std::cout << my_app.programmedAnswers2e() << std::endl; + std::cout << programmedAnswers2e() << std::endl; response_content = "Programmed answers dumped on stdout\n"; return; } } else { - LOGWARNING(anna::Logger::warning(my_app.help(), ANNA_FILE_LOCATION)); + LOGWARNING(anna::Logger::warning(help(), ANNA_FILE_LOCATION)); throw anna::RuntimeException("Wrong body content format on HTTP Request. Unsupported/unrecognized operation type", ANNA_FILE_LOCATION); }