-#include <anna/time/Date.hpp>
-#include <anna/diameter/helpers/base/defines.hpp>
-#include <anna/diameter/helpers/base/functions.hpp>
-#include <anna/diameter/helpers/dcca/defines.hpp>
-#include <anna/diameter/helpers/dcca/functions.hpp>
-#include <anna/statistics/Engine.hpp>
-#include <anna/core/functions.hpp>
-
-namespace anna {
-class DataBlock;
-}
-
-namespace anna {
-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<anna::diameter::comm::Message> 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;
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// 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 {
-
- // attributes
- int a_stream;
- std::string a_fileNamePrefix;
- std::string a_fileName;
- time_t a_previousTime;
- std::string a_fixedLine;
-
- // pure virtual definitions:
- void open() throw(anna::RuntimeException) {
- static char str [256];
-
- const time_t now = ::time (NULL);
- struct tm tmNow;
- struct tm tmPrevious;
-
- anna_memcpy (&tmNow, localtime (&now), sizeof (tmNow));
- anna_memcpy (&tmPrevious, localtime (&a_previousTime), sizeof (tmPrevious));
-
- sprintf (
- str,".Date%04d%02d%02d.Time%02d%02d%02d",
- 1900 + (tmNow.tm_year), (tmNow.tm_mon) + 1,
- tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec);
-
- a_fileName = a_fileNamePrefix;
- a_fileName += str;
-
- LOGDEBUG (
- std::string msg ("Flush counters | ");
- msg += a_fileName;
- anna::Logger::debug(msg, ANNA_FILE_LOCATION);
- );
-
- if ((a_stream = ::open (a_fileName.c_str (), O_WRONLY | O_CREAT, S_IWUSR)) == -1)
- throw RuntimeException (anna::functions::asString("Error opening file '%s'; errno = %d", a_fileName.c_str(), errno), ANNA_FILE_LOCATION);
-
- sprintf (str, "%04d-%02d-%02d %02d:%02d|%04d-%02d-%02d %02d:%02d",
- 1900 + (tmPrevious.tm_year), (tmPrevious.tm_mon) + 1,
- tmPrevious.tm_mday, tmPrevious.tm_hour, tmPrevious.tm_min,
- 1900 + (tmNow.tm_year), (tmNow.tm_mon) + 1,
- tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min
- );
-
- a_fixedLine = str;
- }
-
-
- void apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) {
- static char line [356];
- anna::oam::Counter::type_t value = counter;
- sprintf (line, "%s|%06d|%07u|%s\n", a_fixedLine.c_str (), counter.getReference(), value, counter.getName ().c_str ());
- if (write (a_stream, line, anna_strlen (line)) == -1)
- throw RuntimeException (anna::functions::asString("Error writting to file '%s'; errno = %d", a_fileName.c_str(), errno), ANNA_FILE_LOCATION);
- }
-
- void close() throw() {
- if (a_stream != -1) {
- ::close (a_stream);
- a_stream = -1;
- }
- chmod (a_fileName.c_str (), S_IWUSR | S_IRUSR);
- a_previousTime = ::time (NULL);
- }
-
- std::string asString() const throw() {
- std::string result = "Physical counters dump at file '";
- result += a_fileName;
- result += "'. Another way to see counters: context dump (kill -10 <pid>";
- return result;
- }
-
- public:
- MyCounterRecorder(const std::string &fnp) : a_stream(-1), a_fileNamePrefix(fnp) {
- a_previousTime = ::time (NULL);
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-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);
-
- // Reimplementation
- int readSocketId(const anna::diameter::comm::Message* message, int maxClientSessions) const throw();
-};
-
-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);
-};
-
-class MyDiameterEngine : public anna::diameter::comm::Engine {
-public:
-
- static const char* getClassName() throw() { return "launcher::MyDiameterEngine"; }
- MyDiameterEngine() {;}
-
-// Default implementation is enough
-// void readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) throw() {;} // DPA is not replied
-// void readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) throw() {;} // CEA is not replied
-// void readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) throw() {;} // DWA is not replied
-
-private:
- anna::Recycler<MyDiameterEntity> a_entitiesRecycler;
-
- anna::diameter::comm::Entity* allocateEntity() throw() { return a_entitiesRecycler.create(); }
-
- void releaseEntity(anna::diameter::comm::Entity* entity) throw() {
- MyDiameterEntity* aux = static_cast <MyDiameterEntity*>(entity);
- a_entitiesRecycler.release(aux);
- }
-
- anna::Recycler<MyLocalServer> a_localServersRecycler;
-
- anna::diameter::comm::LocalServer* allocateLocalServer() throw() { return a_localServersRecycler.create(); }
-
- void releaseLocalServer(anna::diameter::comm::LocalServer* localServer) throw() {
- MyLocalServer* aux = static_cast <MyLocalServer*>(localServer);
- a_localServersRecycler.release(aux);
- }
-};
-
-
-class MyHandler : public anna::http::Handler {
-public:
- MyHandler() : anna::http::Handler("http_converter::MyHandler") {
- allocateResponse()->createHeader(anna::http::Header::Type::Date);
- }
-
-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) {;}
-};
-
-class MyCommunicator : public anna::comm::Communicator {
-public:
- MyCommunicator(const anna::comm::Communicator::WorkMode::_v acceptMode = anna::comm::Communicator::WorkMode::Single) : anna::comm::Communicator(acceptMode),
- a_contexts("Contexts")
- {;}
-
- void prepareAnswer(anna::diameter::codec::Message *answer, const anna::DataBlock &request) const throw();
- void terminate() throw();
-
-private:
- anna::ThreadData <MyHandler> a_contexts;
- void eventReceiveMessage(anna::comm::ClientSocket&, const anna::comm::Message&) throw(anna::RuntimeException);
- void eventBreakConnection(Server* server) throw();
-};
-
-class Launcher : public anna::comm::Application {
-
- MyCommunicator *a_communicator;
- MyDiameterEngine *a_myDiameterEngine;
- anna::diameter::comm::Entity *a_entity;
- std::string a_logFile, a_burstLogFile;
- std::ofstream a_burstLogStream;
- bool a_splitLog, a_detailedLog;
- 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;
-
- // Burst feature
- int a_burstCycle;
- bool a_burstRepeat;
- bool a_burstActive;
- std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
- int a_burstLoadIndx;
- std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
- int a_otaRequest;
- int a_burstPopCounter;
-
- anna::comm::ServerSocket* a_httpServerSocket; // HTTP
- anna::diameter::comm::LocalServer* a_diameterLocalServer; // DIAMETER
- void checkTimeMeasure(const char * commandLineParameter, bool optional = true) throw(anna::RuntimeException);
- void initialize() throw(anna::RuntimeException); // HTTP
- void run() throw(anna::RuntimeException);
-
-public:
- Launcher();
-
- MyCommunicator *getCommunicator() throw() { return a_communicator; }
- MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); }
- 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();
- 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);
-
- 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();
-
- // Burst feature
- int clearBurst() throw(); // returns removed
- int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
- void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
- int startBurst(int initialLoad) throw(); // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
- int pushBurst(int loadAmount) throw(); // returns pushed (perhaps is less than provided because of no repeat mode and burst list exhausted), or -1 if burst list is empty, -2 if invalid load (0 or negative)
- int sendBurst(int loadAmount) throw(); // returns sent (burst always cycled using send), returns -1 if burst list is empty, -2 if invalid load (0 or negative)
- int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
- int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
- bool burstActive() const throw() { return a_burstActive; }
- bool sendBurstMessage(bool anyway = false) throw();
- std::string lookBurst(int order) const throw();
- std::string gotoBurst(int order) throw();
-};
-
-int Launcher::clearBurst() throw() {
- int size = a_burstMessages.size();
-
- if (size) {
- std::map<int, anna::diameter::comm::Message*>::const_iterator it;
- std::map<int, anna::diameter::comm::Message*>::const_iterator it_min(a_burstMessages.begin());
- std::map<int, anna::diameter::comm::Message*>::const_iterator it_max(a_burstMessages.end());
-
- for (it = it_min; it != it_max; it++) G_commMessages.release((*it).second);
-
- a_burstMessages.clear();
- } else {
- std::string msg = "Burst list already empty. Nothing done";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- }
-
- a_burstActive = false;
- a_burstLoadIndx = 0;
- a_burstDeliveryIt = a_burstMessages.begin();
- return size;
-}
-
-
-int Launcher::loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException) {
- anna::diameter::comm::Message *msg = G_commMessages.create();
- msg->setBody(db);
- a_burstMessages[a_burstLoadIndx++] = msg;
- return (a_burstLoadIndx - 1);
-}
-
-int Launcher::stopBurst() throw() {
- if (!a_burstActive) {
- std::string msg = "Burst launch is already stopped. Nothing done";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -1;
- }
-
- a_burstActive = false;
- // Remaining on cycle:
- return (a_burstMessages.size() - (*a_burstDeliveryIt).first);
-}
-
-int Launcher::popBurst(int releaseAmount) throw() {
- if (!a_burstActive) {
- std::string msg = "Burst launch is stopped. Nothing done";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -1;
- }
-
- if (releaseAmount < 1) {
- std::string msg = "No valid release amount is specified. Ignoring burst pop";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -2;
- }
-
- int currentOTArequests = a_entity->getOTARequests();
- a_burstPopCounter = (releaseAmount > currentOTArequests) ? currentOTArequests : releaseAmount;
- return a_burstPopCounter;
-}
-
-int Launcher::pushBurst(int loadAmount) throw() {
- if (a_burstMessages.size() == 0) {
- std::string msg = "Burst data not found (empty list). Ignoring burst launch";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -1;
- }
-
- if (loadAmount < 1) {
- std::string msg = "No valid load amount is specified. Ignoring burst push";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -2;
- }
-
- a_burstActive = true;
- register int count;
-
- for (count = 0; count < loadAmount; count++)
- if (!sendBurstMessage()) break;
-
- return count;
-}
-
-
-int Launcher::sendBurst(int loadAmount) throw() {
- if (a_burstMessages.size() == 0) {
- std::string msg = "Burst data not found (empty list). Ignoring burst launch";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -1;
- }
-
- if (loadAmount < 1) {
- std::string msg = "No valid load amount is specified. Ignoring burst send";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -2;
- }
-
- register int count;
-
- for (count = 0; count < loadAmount; count++)
- if (!sendBurstMessage(true /* anyway */)) break;
-
- return count;
-}
-
-
-
-int Launcher::startBurst(int initialLoad) throw() {
- if (initialLoad < 1) {
- std::string msg = "No initial load is specified. Ignoring burst start";
- std::cout << msg << std::endl;
- LOGWARNING(anna::Logger::warning(msg, ANNA_FILE_LOCATION));
- return -2;
- }
-
- a_burstActive = true;
- a_burstCycle = 1;
- a_burstDeliveryIt = a_burstMessages.begin();
- return (pushBurst(initialLoad));
-}
-
-bool Launcher::sendBurstMessage(bool anyway) throw() {
- if (!anyway && !burstActive()) return false;
-
- if (a_burstPopCounter > 0) {
- if (burstLogEnabled()) writeBurstLogFile("x");
-
- a_burstPopCounter--;
- return false;
- }
-
- if (a_burstDeliveryIt == a_burstMessages.end()) {
- a_burstDeliveryIt = a_burstMessages.begin();
-
- if (!anyway) {
- if (a_burstRepeat) {
- a_burstCycle++;
-
- if (burstLogEnabled()) writeBurstLogFile(anna::functions::asString(("\nCompleted burst cycle. Starting again (repeat mode) on cycle %d.\n", a_burstCycle)));
- } else {
- if (burstLogEnabled()) writeBurstLogFile("\nCompleted burst cycle. Burst finished (repeat mode disabled).\n");
-
- stopBurst();
- return false;
- }
- }
- }
-
- anna::diameter::comm::Message *msg = (*a_burstDeliveryIt).second;
- int order = (*a_burstDeliveryIt).first + 1;
- a_burstDeliveryIt++;
- bool dot = true;
- // sending
- bool result = a_entity->send(msg, anna::CommandLine::instantiate().exists("balance"));
-
- if (burstLogEnabled()) {
- if (a_burstMessages.size() >= 100)
- dot = (order % (a_burstMessages.size() / 100));
-
- if (dot) {
- writeBurstLogFile(".");
- } else {
- writeBurstLogFile(anna::functions::asString(" %d", order));
- int otaReqs = a_entity->getOTARequests();
-
- if (result && (otaReqs != a_otaRequest)) {
- // false if was a sending after an answer received (no OTA change in this case)
- // true after push and pop operations
- a_otaRequest = otaReqs;
- writeBurstLogFile(anna::functions::asString("[OTA %d]", a_otaRequest));
- }
- }
- }
-
- // Detailed log:
- if (logEnabled()) {
- anna::diameter::comm::Server *usedServer = a_entity->getLastUsedResource();
- anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL;
- std::string detail = usedClientSession ? usedClientSession->asString() : "<null client session>"; // esto no deberia ocurrir
- writeLogFile(msg->getBody(), (result ? "sent2e" : "send2eError"), detail);
- }
-
- return result;
-}
-
-
-std::string Launcher::lookBurst(int order) const throw() {
- std::string result = "No message found for order provided (";
- result += anna::functions::asString(order);
- result += ")";
- std::map<int, anna::diameter::comm::Message*>::const_iterator it = a_burstMessages.find(order - 1);
-
- if (it != a_burstMessages.end()) {
- // Decode
- try { G_codecMsg.decode((*it).second->getBody()); } catch (anna::RuntimeException &ex) { ex.trace(); }
-
- result = G_codecMsg.asXMLString();
- }
-
- return result;
-}
-
-std::string Launcher::gotoBurst(int order) throw() {
- std::string result = "Position not found for order provided (";
- std::map<int, anna::diameter::comm::Message*>::iterator it = a_burstMessages.find(order - 1);
-
- if (it != a_burstMessages.end()) {
- a_burstDeliveryIt = it;
- result = "Position updated for order provided (";
- }
-
- result += anna::functions::asString(order);
- result += ")";
- return result;
-}
-
-////////////////////////////////////////////////////
-
-
-void Launcher::resetCounters() throw() {
- // Diameter::comm module:
- anna::diameter::comm::OamModule & oamDiameterComm = anna::diameter::comm::OamModule::instantiate();
- 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 += "\n";
- 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 <pid>";
- result += "\n or";
- result += "\n kill -s SIGUSR1 <pid>";
- result += "\n and then";
- result += "\n vi /var/tmp/anna.context.<pid>";
- result += "\n";
- result += "\nA complete xml report will show all the context information (counters, alarms, statistics,";
- 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 += "\nAlso SIGUSR2 is handled for management purposes. We will talk later about this.";
- result += "\n";
- result += "\n";
- result += "\nCOMMAND LINE";
- result += "\n------------";
- result += "\n";
- 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 += "\nAs mandatory, the stack definition given through the xml dictionary:";
- result += "\n -dictionary <path to dictionary file>";
- 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 <xml message file>' and '-dwr <xml message file>'.";
- 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";
- 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 += "\n--------------------------------------------------------------------------------------- General purpose";
- result += "\n";
- result += "\nhelp This help. Startup information-level traces also dump this help.";
- result += "\n";
- result += "\n------------------------------------------------------------------------------------ Parsing operations";
- result += "\n";
- result += "\ncode|<source_file>|<target_file> Encodes source file (pathfile) into target file (pathfile).";
- result += "\ndecode|<source_file>|<target_file> Decodes source file (pathfile) into target file (pathfile).";
- result += "\nloadxml|<source_file> Reinterpret xml source file (pathfile).";
- result += "\n";
- result += "\n------------------------------------------------------------------------------------------- Hot changes";
- result += "\n";
- result += "\ndiameterServerSessions|<integer> 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.<pid>' by mean 'kill -10 <pid>'.";
- result += "\n";
- result += "\n<visibility action>|[<address>:<port>]|[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";
- 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 += "\n--------------------------------------------------------------------------------------- Flow operations";
- result += "\n";
- result += "\nsendxml2e|<source_file> Sends xml source file (pathfile) through configured entity.";
- result += "\nsendxml2c|<source_file> Sends xml source file (pathfile) to client.";
- result += "\nsendxml|<source_file> 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";
- 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";
- 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";
- 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 += "\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";
- 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)";
- result += "\n [fwd2e/fwd2eError] Forward to entity a reception from client (success/error)";
- result += "\n [fwd2c/fwd2cError] Forward to client a reception from entity (success/error)";
- result += "\n [recvfc] Reception from client";
- 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]";
- 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 += "\n-------------------------------------------------------------------------------------------- Load tests";
- result += "\n";
- result += "\nburst|<action>|[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|<source_file> Loads the next diameter message into launcher burst.";
- result += "\n burst|start|<initial load> Starts (or restarts if already in progress) the message sending with";
- result += "\n a certain initial load.";
- result += "\n burst|push|<load amount> Sends specific non-aynchronous load.";
- result += "\n burst|pop|<release amount> 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|<amount> 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|<order> Updates current burst pointer position.";
- result += "\n burst|look|<order> 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 \"<<operation>\" > "; result += SIGUSR2_TASKS_INPUT_FILENAME;
- result += "\n then";
- result += "\n kill -12 <pid>";
- result += "\n or";
- result += "\n kill -s SIGUSR2 <pid>";
- 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;
-}
-
-
-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.
- // Sequence substitution:
- answer->setHopByHop(anna::diameter::codec::functions::getHopByHop(request));
- answer->setEndToEnd(anna::diameter::codec::functions::getEndToEnd(request));
-
- // Session-Id substitution:
- try {
- std::string sessionId = anna::diameter::helpers::base::functions::getSessionId(request);
- LOGDEBUG(
- std::string msg = "Extracted Session-Id: ";
- msg += sessionId;
- anna::Logger::debug(msg, ANNA_FILE_LOCATION);
- );
- answer->getAvp("Session-Id")->getUTF8String()->setValue(sessionId);
- } catch (anna::RuntimeException &ex) {
- ex.trace();
- }
-
- // Subscription-Id substitution: is not usual to carry Subscription-Id on answer messages, but if programmed answer have this information,
- // then it will be adapted with the received data at request.
- if (answer->countAvp("Subscription-Id") > 0) {
- std::string msisdn = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(request, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164);
- std::string imsi = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(request, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI);
-
- if ((msisdn != "") || (imsi != "")) { // Both request & answer have SID: replace answer one with the request information:
- answer->removeAvp("Subscription-Id", 0 /* remove all */);
- }
-
- // Replacements:
- if (msisdn != "") {
- anna::diameter::codec::Avp *sid = answer->addAvp("Subscription-Id");
- sid->addAvp("Subscription-Id-Type")->getEnumerated()->setValue(anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164);
- sid->addAvp("Subscription-Id-Data")->getUTF8String()->setValue(msisdn);
- }
-
- if (imsi != "") {
- anna::diameter::codec::Avp *sid = answer->addAvp("Subscription-Id"); // another
- sid->addAvp("Subscription-Id-Type")->getEnumerated()->setValue(anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI);
- sid->addAvp("Subscription-Id-Data")->getUTF8String()->setValue(imsi);
- }
- }
-}
-
-// HTTP
-void MyCommunicator::eventReceiveMessage(anna::comm::ClientSocket& clientSocket, const anna::comm::Message& message)
-throw(anna::RuntimeException) {
- LOGMETHOD(anna::TraceMethod tm("MyCommunicator", "eventReceiveMessage", ANNA_FILE_LOCATION));