From 6e1b37527452c6e59433144d6770db26253862eb Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Sun, 26 Apr 2015 17:00:34 +0200 Subject: [PATCH] Add proxied attribute to diameter::comm::Message in order to automate end-to-end generation or respect value. --- example/diameter/launcher/DEPLOY.sh | 2 +- .../launcher/deployments/ft-client/args.txt | 8 +++--- example/diameter/launcher/main.cpp | 4 +++ include/anna/diameter.comm/Engine.hpp | 13 --------- include/anna/diameter.comm/Message.hpp | 28 +++++++++++++------ source/diameter.comm/ClientSession.cpp | 4 +-- source/diameter.comm/Engine.cpp | 5 ++-- source/diameter.comm/Message.cpp | 6 ++-- source/diameter.comm/ServerSession.cpp | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/example/diameter/launcher/DEPLOY.sh b/example/diameter/launcher/DEPLOY.sh index 98392ad..ceb04b1 100755 --- a/example/diameter/launcher/DEPLOY.sh +++ b/example/diameter/launcher/DEPLOY.sh @@ -118,7 +118,7 @@ then echo echo " (a)dvanced version: includes burst management script and templates for different scenarios. Automatic configuration during start." echo " (b)asic version: 4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method." - echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs." + echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests." echo echo "Input option [b]:" read option diff --git a/example/diameter/launcher/deployments/ft-client/args.txt b/example/diameter/launcher/deployments/ft-client/args.txt index 2ee9a85..12bffbb 100755 --- a/example/diameter/launcher/deployments/ft-client/args.txt +++ b/example/diameter/launcher/deployments/ft-client/args.txt @@ -1,4 +1,4 @@ --dictionary `grep -v ^# .dictionary` --entity `grep -v ^# .entity` --entityServerSessions `grep -v ^# .entityServerSessions` --splitLog +--dictionary `grep -v ^# .dictionary` +--entity `grep -v ^# .entity` +--entityServerSessions `grep -v ^# .entityServerSessions` +--splitLog diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 6d95e9a..7907a47 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -2330,6 +2330,7 @@ throw(anna::RuntimeException) { if(localServer && (cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) /* don't forward CER */) { try { anna::diameter::comm::Message *msg = G_commMessages.create(); + msg->setProxied(); // end-to-end will be kept msg->setBody(message); msg->setRequestClientSessionKey(clientSession->getKey()); bool success = localServer->send(msg); @@ -2412,6 +2413,7 @@ throw(anna::RuntimeException) { if(localServer && (request_cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) /* don't forward CEA */) { try { + G_commMsgFwd2c.setProxied(); // end-to-end will be kept G_commMsgFwd2c.setBody(*message); bool success = localServer->send(&G_commMsgFwd2c, request->getRequestServerSessionKey()); G_commMessages.release(request); @@ -2510,6 +2512,7 @@ throw(anna::RuntimeException) { anna::diameter::comm::Entity *entity = my_app.getEntity(); if(!programmed && entity) { // forward condition (no programmed answer + entity available) anna::diameter::comm::Message *msg = G_commMessages.create(); + msg->setProxied(); // end-to-end will be kept msg->setBody(message); msg->setRequestServerSessionKey(serverSession->getKey()); bool success = entity->send(msg, cl.exists("balance")); @@ -2637,6 +2640,7 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) detail = usedClientSession ? usedClientSession->asString() : ""; // esto no deberia ocurrir try { + G_commMsgFwd2e.setProxied(); // end-to-end will be kept G_commMsgFwd2e.setBody(*message); // Metodo 1: diff --git a/include/anna/diameter.comm/Engine.hpp b/include/anna/diameter.comm/Engine.hpp index 0a65b24..1c1a12e 100644 --- a/include/anna/diameter.comm/Engine.hpp +++ b/include/anna/diameter.comm/Engine.hpp @@ -215,18 +215,6 @@ public: */ void setNumberOfClientSessionsPerServer(int numberOfClientSessionsPerServer) throw() { a_numberOfClientSessionsPerServer = numberOfClientSessionsPerServer; } - /** - * Gets true when end-to-end sequence is freezed on requests sendings. - * Engine starts with false value, sequencing end-to-end as hop-by-hop does. - * \return Freeze end-to-end indicator. - */ - bool getFreezeEndToEndOnSending() const throw() { return a_freezeEndToEndOnSending; } - - /** - * Freeze end-to-end indicator on requests sendings. - * \param freezeEndToEndOnSending Freeze end-to-end indicator. - */ - void setFreezeEndToEndOnSending(bool freezeEndToEndOnSending = true) throw() { a_freezeEndToEndOnSending = freezeEndToEndOnSending; } /** * Returns client-session instance identified by (address, port, socketId) provided. @@ -689,7 +677,6 @@ private: std::string a_host; bool a_autoBind; int a_numberOfClientSessionsPerServer; - bool a_freezeEndToEndOnSending; // ClientSessions messages: diff --git a/include/anna/diameter.comm/Message.hpp b/include/anna/diameter.comm/Message.hpp index 031391c..7e007ca 100644 --- a/include/anna/diameter.comm/Message.hpp +++ b/include/anna/diameter.comm/Message.hpp @@ -40,18 +40,19 @@ class ServerSession; /** Messages launched to diameter servers + Could be proxied (end-to-end kept) or not (by default). */ class Message : public anna::comm::Message { public: /** - * Define las acciones a realizar en caso de que el temporizador de la petición expire. + * Define las acciones a realizar en caso de que el temporizador de la petici�n expire. */ struct OnExpiry { enum _v { Abandon, Ignore }; }; /** Constructor. - \param onExpiry Indica la acción a realizar si el temporizador de esta transación expira. + \param onExpiry Indica la acci�n a realizar si el temporizador de esta transaci�n expira. */ Message(const OnExpiry::_v onExpiry = OnExpiry::Ignore) : anna::comm::Message(StatusCodeBuffer::Reserve), a_classCode(ClassCode::ApplicationMessage), @@ -64,16 +65,16 @@ public: const ClassCode::_v & getClassCode() const throw() { return a_classCode; } /** - * Devuelve la acción a realizar en caso de que el temporizador asociado a esta petición expire. - * \return la acción a realizar en caso de que el temporizador asociado a esta petición expire. + * Devuelve la acci�n a realizar en caso de que el temporizador asociado a esta petici�n expire. + * \return la acci�n a realizar en caso de que el temporizador asociado a esta petici�n expire. */ OnExpiry::_v getOnExpiry() const throw() { return a_onExpiry; } /** - * Establece la acción a realizar en caso de que el temporizador asociado a esta petición expire. - * \param onExpiry Indica la acción a realizar en caso de que el temporizador asociado a esta petición expire. + * Establece la acci�n a realizar en caso de que el temporizador asociado a esta petici�n expire. + * \param onExpiry Indica la acci�n a realizar en caso de que el temporizador asociado a esta petici�n expire. * - * \warning Establecer el valor OnExpiry::Ignore podría causar pérdida de memoria y uso innecesario de recursos. + * \warning Establecer el valor OnExpiry::Ignore podr�a causar p�rdida de memoria y uso innecesario de recursos. */ void setOnExpiry(const OnExpiry::_v onExpiry) throw() { a_onExpiry = onExpiry; } @@ -105,7 +106,14 @@ public: CommandId getCommandId(bool &isRequest) const throw(); CommandId getCommandId() const throw() { bool dummy; return getCommandId(dummy); } - bool fixRequestSequence(HopByHop hbh, EndToEnd ete, bool freezeEndToEnd) throw(); + bool fixRequestSequence(HopByHop hbh, EndToEnd ete) throw(); + + /** Diameter agents CANNOT modify the end-to-end. True value stands for intermediate agents, false for request originators */ + bool isProxied() const throw() { return a_proxied; } + + /** Diameter agents CANNOT modify the end-to-end. True value stands for intermediate agents, false for request originators */ + void setProxied(bool proxied = true) throw() { a_proxied = proxied; } + // Statistics void updateRequestTimestampMs(void) throw() { a_request_timestamp_ms = anna::functions::millisecond(); } @@ -132,6 +140,7 @@ public: a_requestClientSessionKey = ""; // means unknown/unset a_requestHopByHop = 0; a_requestEndToEnd = 0; + a_proxied = false; } @@ -139,7 +148,7 @@ protected: /** Constructor. \param classCode Tipo de clase de esta peticion. - \param onExpiry Indica la acción a realizar si el temporizador de esta transación expira. + \param onExpiry Indica la acci�n a realizar si el temporizador de esta transaci�n expira. */ Message(const ClassCode::_v & classCode, const OnExpiry::_v onExpiry = OnExpiry::Ignore) : anna::comm::Message(StatusCodeBuffer::Reserve), a_classCode(classCode), @@ -155,6 +164,7 @@ private: std::string a_requestClientSessionKey; // idem for request which was received from servers HopByHop a_requestHopByHop; // application backup for hop-by-hop in order to restore on answer receive EndToEnd a_requestEndToEnd; // application backup for end-to-end in order to restore on answer receive + bool a_proxied; // end-to-end will be kept void send(ClientSession&) const throw(anna::RuntimeException); void send(ServerSession&) const throw(anna::RuntimeException); diff --git a/source/diameter.comm/ClientSession.cpp b/source/diameter.comm/ClientSession.cpp index 87a2f60..91aa8cf 100644 --- a/source/diameter.comm/ClientSession.cpp +++ b/source/diameter.comm/ClientSession.cpp @@ -116,7 +116,7 @@ void ClientSession::bind() throw(anna::RuntimeException) { // Tekelec PCRF a_engine->bindingClientSession(this); - // OAM Lo comento, porque no se contabilizan los reintentos y por lo tanto no son muy útiles. + // OAM Lo comento, porque no se contabilizan los reintentos y por lo tanto no son muy �tiles. // OamModule &oamModule = OamModule::instantiate(); // oamModule.count(a_server->isAvailable() ? OamModule::Counter::TCPConnectOK:OamModule::Counter::TCPConnectNOK); // Application bind @@ -273,7 +273,7 @@ const Response* ClientSession::send(const Message* message) throw(anna::RuntimeE } // Fixing indicator: - fixed = message_nc->fixRequestSequence(a_nextHopByHop, a_nextEndToEnd, a_engine->getFreezeEndToEndOnSending()); + fixed = message_nc->fixRequestSequence(a_nextHopByHop, a_nextEndToEnd); message_nc->updateRequestTimestampMs(); // statistics purposes (processing time for request type) } diff --git a/source/diameter.comm/Engine.cpp b/source/diameter.comm/Engine.cpp index fd5f8c8..fa13a37 100644 --- a/source/diameter.comm/Engine.cpp +++ b/source/diameter.comm/Engine.cpp @@ -48,8 +48,7 @@ Engine::Engine() : // a_dwa(true), a_watchdogPeriod(ClientSession::DefaultWatchdogPeriod), a_maxConnectionDelay(anna::comm::ClientSocket::DefaultMaxConnectionDelay /* 200 ms*/), - a_numberOfClientSessionsPerServer(1), - a_freezeEndToEndOnSending(false) { + a_numberOfClientSessionsPerServer(1) { anna::diameter::sccs::activate(); a_realm = anna::functions::getDomainname(); a_host = anna::functions::getHostname(); @@ -261,7 +260,7 @@ throw(anna::RuntimeException) { result->setWatchdogPeriod(a_watchdogPeriod); result->a_parent = server; result->a_socketId = socketId; - result->initializeSequences(); // después de asignar el server y el socketId (*) + result->initializeSequences(); // despu�s de asignar el server y el socketId (*) // (*) Las secuencias se basan en la semilla: srand(::time(NULL) + anna::functions::exclusiveHash(anna::functions::asString("%s:%d|%d", getAddress().c_str(), getPort(), a_socketId))); result->a_engine = this; clientSession_key key = ClientSession::getKey(server->getAddress(), server->getPort(), socketId); diff --git a/source/diameter.comm/Message.cpp b/source/diameter.comm/Message.cpp index b8ae723..2b6331c 100644 --- a/source/diameter.comm/Message.cpp +++ b/source/diameter.comm/Message.cpp @@ -61,7 +61,7 @@ throw() { //// a_onExpiry = OnExpiry::Ignore; //} -bool Message::fixRequestSequence(HopByHop hbh, EndToEnd ete, bool freezeEndToEnd) throw() { +bool Message::fixRequestSequence(HopByHop hbh, EndToEnd ete) throw() { setRequestHopByHop(getHopByHop()); // original request hop-by-hop (backup) setRequestEndToEnd(getEndToEnd()); // original request end-to-end (backup) bool result = false; @@ -71,7 +71,7 @@ bool Message::fixRequestSequence(HopByHop hbh, EndToEnd ete, bool freezeEndToEnd result = true; } - if(!freezeEndToEnd) { + if(!a_proxied) { if(ete != getRequestEndToEnd()) { codec::functions::setEndToEnd((anna::DataBlock&)getBody(), ete); result = true; @@ -85,7 +85,7 @@ bool Message::fixRequestSequence(HopByHop hbh, EndToEnd ete, bool freezeEndToEnd msg += " (original) -> "; msg += anna::functions::asString(hbh); msg += " (session)"; - msg += freezeEndToEnd ? " | End to end [freezed]: " : " | End to end: "; + msg += a_proxied ? " | End to end [proxied]: " : " | End to end: "; msg += anna::functions::asString(getRequestEndToEnd()); msg += " (original) -> "; msg += anna::functions::asString(ete); diff --git a/source/diameter.comm/ServerSession.cpp b/source/diameter.comm/ServerSession.cpp index 76add9f..1be1470 100644 --- a/source/diameter.comm/ServerSession.cpp +++ b/source/diameter.comm/ServerSession.cpp @@ -185,7 +185,7 @@ const Response* ServerSession::send(const Message* message) throw(anna::RuntimeE if(isRequest) { // Fixing indicator: - fixed = message_nc->fixRequestSequence(a_nextHopByHop, a_nextEndToEnd, a_engine->getFreezeEndToEndOnSending()); + fixed = message_nc->fixRequestSequence(a_nextHopByHop, a_nextEndToEnd); message_nc->updateRequestTimestampMs(); // statistics purposes (processing time for request type) } -- 2.20.1