X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdiameter.comm%2FEngine.cpp;h=f860a15e5a1597a0b59cc5468fbf42f61ade68db;hb=refs%2Fheads%2Fmaster;hp=489a093c148880813088ddb595254022ad34aa61;hpb=e80e62a5cf9aacad1a9551c68c432147ef98cd29;p=anna.git diff --git a/source/diameter.comm/Engine.cpp b/source/diameter.comm/Engine.cpp index 489a093..f860a15 100644 --- a/source/diameter.comm/Engine.cpp +++ b/source/diameter.comm/Engine.cpp @@ -16,7 +16,6 @@ #include #include #include - #include #include #include @@ -53,8 +52,8 @@ comm::Engine::Engine(const char *className, const stack::Dictionary *baseProtoco a_autoBind(true), a_availableForEntities(false), a_availableForLocalServers(false), - a_cer(true), - a_dwr(true), + a_client_cer(true), + a_client_dwr(true), // a_cea(true), // a_dwa(true), a_watchdogPeriod(ClientSession::DefaultWatchdogPeriod), @@ -63,15 +62,16 @@ comm::Engine::Engine(const char *className, const stack::Dictionary *baseProtoco a_baseProtocolCodecEngine((std::string("baseProtocolCodecEngine_for_") + std::string(className)).c_str(), baseProtocolDictionary) { anna::diameter::sccs::activate(); - a_realm = anna::functions::getDomainname(); - a_host = anna::functions::getHostname(); + a_originRealm = anna::functions::getDomainname(); + a_originHost = anna::functions::getHostname(); + a_ceaPathfile = ""; // Internal base protocol codec engine: a_baseProtocolCodecEngine.setValidationMode(anna::diameter::codec::Engine::ValidationMode::Always); // default was: after decoding } -void comm::Engine::assertBaseProtocolHealth() throw(anna::RuntimeException) { +void comm::Engine::assertBaseProtocolHealth() const noexcept(false) { if (!getBaseProtocolCodecEngine()->getDictionary()) throw anna::RuntimeException("Invalid diameter::comm::Engine object: base protocol dictionary provided on constructor was NULL", ANNA_FILE_LOCATION); // it would be interesting to check and identify certain base protocol elements in the dictionary ... @@ -79,26 +79,77 @@ void comm::Engine::assertBaseProtocolHealth() throw(anna::RuntimeException) { } -comm::Server* comm::Engine::allocateServer() throw() { return a_serversRecycler.create(); } -void comm::Engine::releaseServer(Server *server) throw() { a_serversRecycler.release(server); } -comm::ClientSession* comm::Engine::allocateClientSession() throw() { return a_clientSessionsRecycler.create(); } -void comm::Engine::releaseClientSession(ClientSession *clientSession) throw() { a_clientSessionsRecycler.release(clientSession); } - +comm::Server* comm::Engine::allocateServer() { return a_serversRecycler.create(); } +void comm::Engine::releaseServer(Server *server) { a_serversRecycler.release(server); } +comm::ClientSession* comm::Engine::allocateClientSession() { return a_clientSessionsRecycler.create(); } +void comm::Engine::releaseClientSession(ClientSession *clientSession) { a_clientSessionsRecycler.release(clientSession); } -void comm::Engine::setClientCERandDWR(const anna::DataBlock & cer, const anna::DataBlock & dwr) throw(anna::RuntimeException) { +void comm::Engine::setClientCER(const anna::DataBlock & cer) noexcept(false) { if(codec::functions::getCommandId(cer) != helpers::base::COMMANDID__Capabilities_Exchange_Request) { throw anna::RuntimeException("The message provided as 'CER' is not a Capabilities-Exchange-Request", ANNA_FILE_LOCATION); } + a_client_cer = cer; +} + +void comm::Engine::setClientDWR(const anna::DataBlock & dwr) noexcept(false) { if(codec::functions::getCommandId(dwr) != helpers::base::COMMANDID__Device_Watchdog_Request) { throw anna::RuntimeException("The message provided as 'DWR' is not a Device-Watchdog-Request", ANNA_FILE_LOCATION); } - a_cer = cer; - a_dwr = dwr; + a_client_dwr = dwr; +} + +void comm::Engine::setClientCER(const std::string & cerPathfile) noexcept(false) { + + // Check for base protocol codec engine health: + assertBaseProtocolHealth(); + + anna::diameter::codec::Message diameterCER(getBaseProtocolCodecEngine()); + try { + diameterCER.loadXMLFile(cerPathfile); + } catch(anna::RuntimeException &ex) { + anna::Logger::error("CER file not found or unable to parse. Nothing done !", ANNA_FILE_LOCATION); + return; + } + + // Assignment for internal encoded version: + setClientCER(diameterCER.code()); +} + +void comm::Engine::setClientDWR(const std::string & dwrPathfile) noexcept(false) { + + // Check for base protocol codec engine health: + assertBaseProtocolHealth(); + + anna::diameter::codec::Message diameterDWR(getBaseProtocolCodecEngine()); + std::string OH = getOriginHostName(); + std::string OR = getOriginRealmName(); + + if (!dwrPathfile.empty()) { + try { + diameterDWR.loadXMLFile(dwrPathfile); + } catch(anna::RuntimeException &ex) { + anna::Logger::error("DWR file not found or unable to parse. Nothing done !", ANNA_FILE_LOCATION); + return; + } + } + + // DEFAULT VERSION: + // Build DWR + // ::= < Diameter Header: 280, REQ > + // { Origin-Host } + // { Origin-Realm } + diameterDWR.setId(anna::diameter::helpers::base::COMMANDID__Device_Watchdog_Request); + diameterDWR.setApplicationId(0); // base protocol + diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); + diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); + + // Assignment for internal encoded version: + setClientDWR(diameterDWR.code()); } -void comm::Engine::setClientCERandDWR(const std::string & cer, const std::string & dwr) throw(anna::RuntimeException) { +void comm::Engine::setClientCER(const anna::U32 &applicationId) noexcept(false) { // Check for base protocol codec engine health: assertBaseProtocolHealth(); @@ -115,70 +166,26 @@ void comm::Engine::setClientCERandDWR(const std::string & cer, const std::string // * [ Auth-Application-Id ] 258 Unsigned32 // * [Acct-Application-Id] 259 Unsigned32 anna::diameter::codec::Message diameterCER(getBaseProtocolCodecEngine()); - int applicationId = 0 /*anna::diameter::helpers::APPID__3GPP_Rx*/; // Unsigned32 - std::string OH = getHost(); - std::string OR = getRealm(); + std::string OH = getOriginHostName(); + std::string OR = getOriginRealmName(); std::string hostIP = anna::functions::getHostnameIP(); // Address int vendorId = anna::diameter::helpers::VENDORID__tgpp; // Unsigned32 std::string productName = "ANNA Diameter Client"; // UTF8String - bool encodeDefault = false; - - if (cer != "") { - try { - diameterCER.loadXML(cer); - } catch(anna::RuntimeException &ex) { - //ex.trace(); - encodeDefault = true; - LOGWARNING(anna::Logger::warning("CER file not found or unable to parse. Encoding harcoded default version ...", ANNA_FILE_LOCATION)); - } - } - else { - encodeDefault = true; - } - - if(encodeDefault) { - diameterCER.setId(anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request); - diameterCER.setApplicationId(applicationId); - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Host_IP_Address)->getAddress()->fromPrintableString(hostIP.c_str()); // supported by Address class, anyway is better to provide "1|" - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Vendor_Id)->getUnsigned32()->setValue(vendorId); - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Product_Name)->getUTF8String()->setValue(productName); - diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Auth_Application_Id)->getUnsigned32()->setValue(applicationId); - } - - // Build DWR - // ::= < Diameter Header: 280, REQ > - // { Origin-Host } - // { Origin-Realm } - anna::diameter::codec::Message diameterDWR(getBaseProtocolCodecEngine()); - encodeDefault = false; - - if (dwr != "") { - try { - diameterDWR.loadXML(dwr); - } catch(anna::RuntimeException &ex) { - //ex.trace(); - encodeDefault = true; - LOGWARNING(anna::Logger::warning("DWR file not found or unable to parse. Encoding harcoded default version ...", ANNA_FILE_LOCATION)); - } - } - else { - encodeDefault = true; - } - if(encodeDefault) { - diameterDWR.setId(anna::diameter::helpers::base::COMMANDID__Device_Watchdog_Request); - diameterDWR.setApplicationId(applicationId); - diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); - diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); - } + diameterCER.setId(anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request); + diameterCER.setApplicationId(0); // base protocol + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Host_IP_Address)->getAddress()->fromPrintableString(hostIP.c_str()); // supported by Address class, anyway is better to provide "1|" + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Vendor_Id)->getUnsigned32()->setValue(vendorId); + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Product_Name)->getUTF8String()->setValue(productName); + diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Auth_Application_Id)->getUnsigned32()->setValue(applicationId); // Assignment for internal encoded versions: - setClientCERandDWR(diameterCER.code(), diameterDWR.code()); + setClientCER(diameterCER.code()); } -void comm::Engine::setWatchdogPeriod(const anna::Millisecond & wp) throw(anna::RuntimeException) { +void comm::Engine::setWatchdogPeriod(const anna::Millisecond & wp) noexcept(false) { if(wp < ClientSession::DefaultWatchdogPeriod) { throw anna::RuntimeException(anna::functions::asString("Please set watchdog period over %s", ClientSession::DefaultWatchdogPeriod.asString().c_str()), ANNA_FILE_LOCATION); } @@ -186,7 +193,7 @@ void comm::Engine::setWatchdogPeriod(const anna::Millisecond & wp) throw(anna::R a_watchdogPeriod = wp; } -void comm::Engine::checkEntityCollision(const socket_v &v) throw(anna::RuntimeException) { +void comm::Engine::checkEntityCollision(const socket_v &v) noexcept(false) { socket_v::const_iterator it; socket_v::const_iterator it_min(v.begin()); socket_v::const_iterator it_max(v.end()); @@ -208,7 +215,7 @@ void comm::Engine::checkEntityCollision(const socket_v &v) throw(anna::RuntimeEx } comm::Entity* comm::Engine::createEntity(const socket_v & socketList, const std::string &description) -throw(anna::RuntimeException) { +noexcept(false) { Entity* result(NULL); anna::Guard guard(this, "anna::diameter::comm::Engine::createEntity"); @@ -257,24 +264,25 @@ throw(anna::RuntimeException) { comm::LocalServer *comm::Engine::createLocalServer(const std::string & addr, int port, int maxConnections, const anna::Millisecond & allowedInactivityTime, int category, const std::string & description) -throw(anna::RuntimeException) { +noexcept(false) { LocalServer* result(NULL); anna::Guard guard(this, "anna::diameter::comm::Engine::createLocalServer"); // Proteccion antes de reservar memoria para un LocalServer socket_t key(addr, port); - if(a_localServers.find(key) != a_localServers.end()) + if(a_localServers.find(key) != a_localServers.end()) { throw anna::RuntimeException("LocalServer is already reserved by a former created access point. Cannot create again", ANNA_FILE_LOCATION); + } if((result = allocateLocalServer()) == NULL) throw anna::RuntimeException("diameter::comm::Engine::allocateLocalServer returns NULL (perhaps virtual method was not implemented)", ANNA_FILE_LOCATION); - result->setEngine(this); // lo podia haber asignado en el allocateLocalServer (no importa) + result->setEngine(this); // only to refresh availability result->setKey(key); result->setCategory(category); result->setDescription(description); result->setAllowedInactivityTime(allowedInactivityTime); - result->initializeStatisticConcepts(); + result->initializeStatisticResources(); // Los saco con metodos virtuales readXXX del motor: // if ((a_cea.isEmpty()) || (a_dwa.isEmpty())) // throw anna::RuntimeException("Must define valid CEA and DWA messages by mean setCEAandDWA()", ANNA_FILE_LOCATION); @@ -286,13 +294,14 @@ throw(anna::RuntimeException) { ); // // Listen: (*) // /*if (a_autoListen) */result->enable(); // creates server socket + // ENABLE THE SERVER: if already open (other comm engine for another origin host in the same address), nothing done. But the reference to the server is doubled along 2 comm engines ... result->setMaxConnections(maxConnections); // (*) this enables the listen port ... or not return result; } comm::Entity* comm::Engine::createEntity(const std::string & addr1, int port1, const std::string & addr2, int port2, const std::string &description) -throw(anna::RuntimeException) { +noexcept(false) { socket_v dualList; dualList.push_back(socket_t(addr1, port1)); dualList.push_back(socket_t(addr2, port2)); @@ -301,7 +310,7 @@ throw(anna::RuntimeException) { comm::Server* comm::Engine::createServer(Entity *entity, const socket_t & socket) -throw(anna::RuntimeException) { +noexcept(false) { Server* result(NULL); anna::Guard guard(this, "anna::diameter::comm::Engine::createServer"); @@ -314,9 +323,9 @@ throw(anna::RuntimeException) { result->a_parent = entity; result->a_socket = socket; result->setMaxClientSessions(a_numberOfClientSessionsPerServer /* engine */); - result->a_engine = this; - result->initializeStatisticConcepts(); + result->initializeStatisticResources(); + result->a_engine = this; for(int k = 0; k < a_numberOfClientSessionsPerServer; k++) result->addClientSession(k); @@ -333,7 +342,7 @@ throw(anna::RuntimeException) { // Lohacemos privado comm::ClientSession* comm::Engine::createClientSession(Server *server, int socketId) -throw(anna::RuntimeException) { +noexcept(false) { ClientSession* result(NULL); anna::Guard guard(this, "anna::diameter::comm::Engine::createClientSession"); @@ -344,16 +353,15 @@ throw(anna::RuntimeException) { result->initialize(); // warning: recycler does not initialize its objects and at least... // Assignments (it could be done at allocate): - if((a_cer.isEmpty()) || (a_dwr.isEmpty())) - throw anna::RuntimeException("Must define valid CER and DWR messages by mean setCERandDWR()", ANNA_FILE_LOCATION); + if((a_client_cer.isEmpty()) || (a_client_dwr.isEmpty())) + throw anna::RuntimeException("Must define valid CER and DWR messages by mean setClientCER and setClientDWR()", ANNA_FILE_LOCATION); - result->a_cer.setBody(a_cer); - result->a_dwr.setBody(a_dwr); + result->a_cer.setBody(a_client_cer); + result->a_dwr.setBody(a_client_dwr); result->setWatchdogPeriod(a_watchdogPeriod); result->a_parent = server; result->a_socketId = 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->initializeSequences(); // despues de asignar el server y el socketId (sequences are seed-based by mean exclusive hash) result->a_engine = this; clientSession_key key = ClientSession::getKey(server->getAddress(), server->getPort(), socketId); a_clientSessions.insert(clientSession_value_type(key, result)); @@ -378,7 +386,7 @@ throw(anna::RuntimeException) { } -bool comm::Engine::broadcastEntities(const Message* message) throw(anna::RuntimeException) { +bool comm::Engine::broadcastEntities(const Message* message) noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "broadcastEntities", ANNA_FILE_LOCATION)); bool allok = true; bool ok; @@ -397,7 +405,7 @@ bool comm::Engine::broadcastEntities(const Message* message) throw(anna::Runtime return allok; } -bool comm::Engine::broadcastLocalServers(const Message* message) throw(anna::RuntimeException) { +bool comm::Engine::broadcastLocalServers(const Message* message) noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "broadcastLocalServers", ANNA_FILE_LOCATION)); bool allok = true; bool ok; @@ -416,7 +424,7 @@ bool comm::Engine::broadcastLocalServers(const Message* message) throw(anna::Run return allok; } -bool comm::Engine::bind() throw(anna::RuntimeException) { +bool comm::Engine::bind() noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "bind", ANNA_FILE_LOCATION)); bool result = true; // all OK return @@ -433,12 +441,12 @@ bool comm::Engine::bind() throw(anna::RuntimeException) { } comm::ClientSession* comm::Engine::findClientSession(const std::string & addr, int port, int socketId, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { return findClientSession(ClientSession::getKey(addr, port, socketId), emode); } comm::ClientSession* comm::Engine::findClientSession(const std::string & key, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { anna::Guard guard(this, "anna::diameter::comm::Engine::findClientSession"); clientSession_iterator ii = clientSession_find(key); @@ -462,7 +470,7 @@ throw(anna::RuntimeException) { comm::Server* comm::Engine::findServer(const std::string & addr, int port, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { anna::Guard guard(this, "anna::diameter::comm::Engine::findServer"); server_iterator ii = server_find(server_key(addr, port)); @@ -486,7 +494,7 @@ throw(anna::RuntimeException) { } comm::Entity* comm::Engine::findEntity(const socket_v & socketList, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { anna::Guard guard(this, "anna::diameter::comm::Engine::findEntity"); entity_key key(getEntityKey(socketList)); entity_iterator ii = entity_find(key); @@ -510,7 +518,7 @@ throw(anna::RuntimeException) { } comm::Entity* comm::Engine::findEntity(const std::string & addr1, int port1, const std::string & addr2, int port2, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { socket_v dualList; dualList.push_back(socket_t(addr1, port1)); dualList.push_back(socket_t(addr2, port2)); @@ -519,7 +527,7 @@ throw(anna::RuntimeException) { //Entity* Engine::findEntity(int category, anna::Exception::Mode::_v emode) -//throw(anna::RuntimeException) { +//noexcept(false) { // // Entity *entity; // @@ -533,7 +541,7 @@ throw(anna::RuntimeException) { comm::LocalServer* comm::Engine::findLocalServer(const std::string & addr, int port, anna::Exception::Mode::_v emode) -throw(anna::RuntimeException) { +noexcept(false) { anna::Guard guard(this, "anna::diameter::comm::Engine::findLocalServer"); socket_t key(addr, port); localServer_iterator ii = localServer_find(key); @@ -558,7 +566,7 @@ throw(anna::RuntimeException) { } -comm::ServerSession* comm::Engine::findServerSession(int socketId, anna::Exception::Mode::_v emode) throw(anna::RuntimeException) { +comm::ServerSession* comm::Engine::findServerSession(int socketId, anna::Exception::Mode::_v emode) noexcept(false) { anna::Guard guard(this, "anna::diameter::comm::Engine::findServerSession"); ServerSession *result; @@ -586,7 +594,7 @@ comm::ServerSession* comm::Engine::findServerSession(int socketId, anna::Excepti void comm::Engine::closeClientSession(comm::ClientSession* clientSession, bool destroy) -throw(anna::RuntimeException) { +noexcept(false) { if(clientSession == NULL) return; @@ -624,7 +632,7 @@ throw(anna::RuntimeException) { void comm::Engine::closeServer(comm::Server* server, bool destroy) -throw(anna::RuntimeException) { +noexcept(false) { if(server == NULL) return; @@ -656,7 +664,7 @@ throw(anna::RuntimeException) { void comm::Engine::closeEntity(comm::Entity* entity, bool destroy) -throw(anna::RuntimeException) { +noexcept(false) { if(entity == NULL) return; @@ -691,7 +699,7 @@ throw(anna::RuntimeException) { void comm::Engine::closeLocalServer(comm::LocalServer* localServer, bool destroy) -throw(anna::RuntimeException) { +noexcept(false) { if(localServer == NULL) return; @@ -723,7 +731,7 @@ throw(anna::RuntimeException) { -void comm::Engine::closeEntities(bool destroy) throw(anna::RuntimeException) { +void comm::Engine::closeEntities(bool destroy) noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "closeEntities", ANNA_FILE_LOCATION)); anna::Guard guard(this, "anna::diameter::comm::Engine::closeEntities"); @@ -731,7 +739,7 @@ void comm::Engine::closeEntities(bool destroy) throw(anna::RuntimeException) { closeEntity(entity(it), destroy); } -void comm::Engine::closeLocalServers(bool destroy) throw(anna::RuntimeException) { +void comm::Engine::closeLocalServers(bool destroy) noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "closeLocalServers", ANNA_FILE_LOCATION)); anna::Guard guard(this, "anna::diameter::comm::Engine::closeLocalServers"); @@ -739,7 +747,7 @@ void comm::Engine::closeLocalServers(bool destroy) throw(anna::RuntimeException) closeLocalServer(localServer(it), destroy); } -void comm::Engine::eraseDeprecatedIdleEntities() throw() { +void comm::Engine::eraseDeprecatedIdleEntities() { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "eraseDeprecatedIdleEntities", ANNA_FILE_LOCATION)); Entity *et; @@ -750,7 +758,7 @@ void comm::Engine::eraseDeprecatedIdleEntities() throw() { } } -int comm::Engine::getOTARequestsForEntities() const throw() { +int comm::Engine::getOTARequestsForEntities() const { int result = 0; for(const_entity_iterator it = entity_begin(), maxii = entity_end(); it != maxii; it ++) @@ -759,7 +767,7 @@ int comm::Engine::getOTARequestsForEntities() const throw() { return result; } -int comm::Engine::getOTARequestsForLocalServers() const throw() { +int comm::Engine::getOTARequestsForLocalServers() const { int result = 0; for(const_localServer_iterator it = localServer_begin(), maxii = localServer_end(); it != maxii; it ++) @@ -769,18 +777,18 @@ int comm::Engine::getOTARequestsForLocalServers() const throw() { } -void comm::Engine::setRealm(const std::string & name) throw() { - a_realm = ((name != "") ? name : anna::functions::getDomainname()); +void comm::Engine::setOriginRealmName(const std::string & originRealmName) { + a_originRealm = ((originRealmName != "") ? originRealmName : anna::functions::getDomainname()); } -void comm::Engine::setHost(const std::string & name) throw() { - a_host = ((name != "") ? name : anna::functions::getHostname()); +void comm::Engine::setOriginHostName(const std::string & originHostName) { + a_originHost = ((originHostName != "") ? originHostName : anna::functions::getHostname()); } -void comm::Engine::raiseAutoRecovery(bool autoRecovery) throw(anna::RuntimeException) { +void comm::Engine::raiseAutoRecovery(bool autoRecovery) noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "raiseAutoRecovery", ANNA_FILE_LOCATION)); for(entity_iterator it = entity_begin(), maxii = entity_end(); it != maxii; it ++) @@ -788,12 +796,12 @@ void comm::Engine::raiseAutoRecovery(bool autoRecovery) throw(anna::RuntimeExcep } void comm::Engine::do_stop() -throw() { +{ LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "do_stop", ANNA_FILE_LOCATION)); close(true /* destroy */); } -std::string comm::Engine::asString(void) const throw() { +std::string comm::Engine::asString(void) const { std::string trace; trace = "\n================================"; trace += "\nDiameter comm Engine information"; @@ -835,7 +843,7 @@ std::string comm::Engine::asString(void) const throw() { anna::xml::Node* comm::Engine::asXML(anna::xml::Node* parent) const -throw() { +{ parent = anna::app::Component::asXML(parent); anna::xml::Node* result = parent->createChild("diameter.comm.Engine"); result->createAttribute("AutoBind", a_autoBind ? "yes" : "no"); @@ -884,30 +892,30 @@ throw() { return result; } -comm::Engine::clientSession_iterator comm::Engine::clientSession_find(const clientSession_key &key) throw() { +comm::Engine::clientSession_iterator comm::Engine::clientSession_find(const clientSession_key &key) { return a_clientSessions.find(key); } -comm::Engine::server_iterator comm::Engine::server_find(const server_key &key) throw() { +comm::Engine::server_iterator comm::Engine::server_find(const server_key &key) { return a_servers.find(key); } -comm::Engine::entity_iterator comm::Engine::entity_find(const entity_key &key) throw() { +comm::Engine::entity_iterator comm::Engine::entity_find(const entity_key &key) { return a_entities.find(key); } -comm::Engine::localServer_iterator comm::Engine::localServer_find(const socket_t &key) throw() { +comm::Engine::localServer_iterator comm::Engine::localServer_find(const socket_t &key) { return a_localServers.find(key); } -comm::Engine::entity_key comm::Engine::getEntityKey(const std::string & addr1, int port1, const std::string & addr2, int port2) const throw() { +comm::Engine::entity_key comm::Engine::getEntityKey(const std::string & addr1, int port1, const std::string & addr2, int port2) const { socket_v dualList; dualList.push_back(socket_t(addr1, port1)); dualList.push_back(socket_t(addr2, port2)); return (getEntityKey(dualList)); } -comm::Engine::entity_key comm::Engine::getEntityKey(const socket_v &v) const throw() { +comm::Engine::entity_key comm::Engine::getEntityKey(const socket_v &v) const { std::string result; socket_v::const_iterator it; socket_v::const_iterator it_min(v.begin()); @@ -919,16 +927,17 @@ comm::Engine::entity_key comm::Engine::getEntityKey(const socket_v &v) const thr } result.erase(result.size() - 1, 1); // remove last space - //return anna::functions::exclusiveHash(result); return result; } -void comm::Engine::availabilityLostForEntities() throw() { +void comm::Engine::availabilityLostForEntities() { a_availableForEntities = false; LOGDEBUG( - std::string msg = "diameter::comm::Engine { Realm: "; - msg += getRealm(); + std::string msg = "diameter::comm::Engine { Origin-Realm: "; + msg += getOriginRealmName(); + msg += " | Origin-Host: "; + msg += getOriginHostName(); msg += " } has lost its availability for entities"; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); @@ -936,16 +945,16 @@ void comm::Engine::availabilityLostForEntities() throw() { OamModule &oamModule = OamModule::instantiate(); oamModule.activateAlarm(OamModule::Alarm::c_LostAvailabilityOverEntitiesForEngineWithClassName__s__, getClassName()); oamModule.count(OamModule::Counter::LostAvailabilityOverEngineForEntities); - // Virtual - availabilityLostForEntities(this); } -void comm::Engine::availabilityRecoveredForEntities() throw() { +void comm::Engine::availabilityRecoveredForEntities() { a_availableForEntities = true; LOGDEBUG( - std::string msg = "diameter::comm::Engine { Realm: "; - msg += getRealm(); + std::string msg = "diameter::comm::Engine { Origin-Realm: "; + msg += getOriginRealmName(); + msg += " | Origin-Host: "; + msg += getOriginHostName(); msg += " } has recovered its availability for entities"; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); @@ -953,16 +962,16 @@ void comm::Engine::availabilityRecoveredForEntities() throw() { OamModule &oamModule = OamModule::instantiate(); oamModule.cancelAlarm(OamModule::Alarm::c_LostAvailabilityOverEntitiesForEngineWithClassName__s__, getClassName()); oamModule.count(OamModule::Counter::RecoveredAvailabilityOverEngineForEntities); - // Virtual - availabilityRecoveredForEntities(this); } -void comm::Engine::availabilityLostForLocalServers() throw() { +void comm::Engine::availabilityLostForLocalServers() { a_availableForLocalServers = false; LOGDEBUG( - std::string msg = "diameter::comm::Engine { Realm: "; - msg += getRealm(); + std::string msg = "diameter::comm::Engine { Origin-Realm: "; + msg += getOriginRealmName(); + msg += " | Origin-Host: "; + msg += getOriginHostName(); msg += " } has lost its availability for local servers"; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); @@ -970,16 +979,16 @@ void comm::Engine::availabilityLostForLocalServers() throw() { OamModule &oamModule = OamModule::instantiate(); oamModule.activateAlarm(OamModule::Alarm::c_LostAvailabilityOverLocalServersForEngineWithClassName__s__, getClassName()); oamModule.count(OamModule::Counter::LostAvailabilityOverEngineForLocalServers); - // Virtual - availabilityLostForLocalServers(this); } -void comm::Engine::availabilityRecoveredForLocalServers() throw() { +void comm::Engine::availabilityRecoveredForLocalServers() { a_availableForLocalServers = true; LOGDEBUG( - std::string msg = "diameter::comm::Engine { Realm: "; - msg += getRealm(); + std::string msg = "diameter::comm::Engine { Origin-Realm: "; + msg += getOriginRealmName(); + msg += " | Origin-Host: "; + msg += getOriginHostName(); msg += " } has recovered its availability for local servers"; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); @@ -987,12 +996,10 @@ void comm::Engine::availabilityRecoveredForLocalServers() throw() { OamModule &oamModule = OamModule::instantiate(); oamModule.cancelAlarm(OamModule::Alarm::c_LostAvailabilityOverLocalServersForEngineWithClassName__s__, getClassName()); oamModule.count(OamModule::Counter::RecoveredAvailabilityOverEngineForLocalServers); - // Virtual - availabilityRecoveredForLocalServers(this); } -bool comm::Engine::refreshAvailabilityForEntities() throw() { +bool comm::Engine::refreshAvailabilityForEntities() { // Here available if(a_availableForEntities) { // check not-bound state for all client-sessions: bool isolate = true; @@ -1018,7 +1025,7 @@ bool comm::Engine::refreshAvailabilityForEntities() throw() { return false; } -bool comm::Engine::refreshAvailabilityForLocalServers() throw() { +bool comm::Engine::refreshAvailabilityForLocalServers() { // Here available if(a_availableForLocalServers) { // check not-bound state for all client-sessions: bool isolate = true; @@ -1045,10 +1052,16 @@ bool comm::Engine::refreshAvailabilityForLocalServers() throw() { } -void comm::Engine::readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) throw() { +void comm::Engine::readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) const { // Check for base protocol codec engine health: - assertBaseProtocolHealth(); + try { + assertBaseProtocolHealth(); + } + catch(anna::RuntimeException &ex) { + ex.trace(); + return; + } // Default DPA implementation: // @@ -1076,11 +1089,11 @@ void comm::Engine::readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) th // Origin-Host avpOH.setId(anna::diameter::helpers::base::AVPID__Origin_Host); avpOH.setMandatoryBit(); - avpOH.getDiameterIdentity()->fromPrintableString(a_host.c_str()); + avpOH.getDiameterIdentity()->fromPrintableString(a_originHost.c_str()); // Origin-Realm avpOR.setId(anna::diameter::helpers::base::AVPID__Origin_Realm); avpOR.setMandatoryBit(); - avpOR.getDiameterIdentity()->fromPrintableString(a_realm.c_str()); + avpOR.getDiameterIdentity()->fromPrintableString(a_originRealm.c_str()); diameterDPA.addAvp(&avpRC); diameterDPA.addAvp(&avpOH); diameterDPA.addAvp(&avpOR); @@ -1095,11 +1108,30 @@ void comm::Engine::readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) th } -void comm::Engine::readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) throw() { +void comm::Engine::readCEA(anna::DataBlock &cea, const anna::DataBlock &cer) const { // Check for base protocol codec engine health: assertBaseProtocolHealth(); + if (getCEA() != "") { + anna::diameter::codec::Message diameterCEA(getBaseProtocolCodecEngine()); + + try { + diameterCEA.loadXMLFile(getCEA()); + diameterCEA.setHopByHop(anna::diameter::codec::functions::getHopByHop(cer)); + diameterCEA.setEndToEnd(anna::diameter::codec::functions::getEndToEnd(cer)); + cea = diameterCEA.code(); + + } catch(anna::RuntimeException &ex) { + ex.trace(); + LOGWARNING(anna::Logger::warning("CEA file not found or unable to parse. Encoding harcoded default version ...", ANNA_FILE_LOCATION)); + //return anna::diameter::comm::Engine::readCEA(cea, cer); + // will fail with empty cea + } + + return; + } + // Default CEA implementation: // // 'Capabilities-Exchange-Answer' (257,answer) @@ -1137,11 +1169,11 @@ void comm::Engine::readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) th // Origin-Host avpOH.setId(anna::diameter::helpers::base::AVPID__Origin_Host); avpOH.setMandatoryBit(); - avpOH.getDiameterIdentity()->fromPrintableString(a_host.c_str()); + avpOH.getDiameterIdentity()->fromPrintableString(a_originHost.c_str()); // Origin-Realm avpOR.setId(anna::diameter::helpers::base::AVPID__Origin_Realm); avpOR.setMandatoryBit(); - avpOR.getDiameterIdentity()->fromPrintableString(a_realm.c_str()); + avpOR.getDiameterIdentity()->fromPrintableString(a_originRealm.c_str()); diameterCEA.addAvp(&avpRC); diameterCEA.addAvp(&avpOH); diameterCEA.addAvp(&avpOR); @@ -1152,7 +1184,7 @@ void comm::Engine::readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) th int vendorId = anna::diameter::helpers::VENDORID__tgpp; // Unsigned32 diameterCEA.addAvp(anna::diameter::helpers::base::AVPID__Vendor_Id)->getUnsigned32()->setValue(vendorId); // Product-Name - std::string productName = "OCS Diameter Server"; // UTF8String + std::string productName = "Diameter Server"; // UTF8String diameterCEA.addAvp(anna::diameter::helpers::base::AVPID__Product_Name)->getUTF8String()->setValue(productName); // Encode cea = diameterCEA.code(); @@ -1164,13 +1196,13 @@ void comm::Engine::readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) th } } -void comm::Engine::manageDrDhServerSession(ServerSession *ss, bool register_or_desregister) throw() { +void comm::Engine::manageDrDhServerSession(ServerSession *ss, bool register_or_desregister) { // Decode CER (TODO: use raw buffer helpers) std::string destinationRealm, destinationHost; codec::Message codecMsg(getBaseProtocolCodecEngine()); try { - codecMsg.decode(ss->a_cer); + codecMsg.decode(a_client_cer); destinationRealm = codecMsg.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); destinationHost = codecMsg.getAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->getValue(); } @@ -1224,7 +1256,7 @@ void comm::Engine::manageDrDhServerSession(ServerSession *ss, bool register_or_d } } -void comm::Engine::readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) throw() { +void comm::Engine::readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) const { // Check for base protocol codec engine health: assertBaseProtocolHealth(); @@ -1246,9 +1278,9 @@ void comm::Engine::readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) th // Message header diameterDWA.setId(anna::diameter::helpers::base::COMMANDID__Device_Watchdog_Answer); diameterDWA.setVersion(1); - diameterDWA.setApplicationId(codec::functions::getApplicationId(dwr)); - diameterDWA.setHopByHop(codec::functions::getHopByHop(dwr)); - diameterDWA.setEndToEnd(codec::functions::getEndToEnd(dwr)); + diameterDWA.setApplicationId(anna::diameter::codec::functions::getApplicationId(dwr)); + diameterDWA.setHopByHop(anna::diameter::codec::functions::getHopByHop(dwr)); + diameterDWA.setEndToEnd(anna::diameter::codec::functions::getEndToEnd(dwr)); // Result-Code avpRC.setId(anna::diameter::helpers::base::AVPID__Result_Code); avpRC.setMandatoryBit(); @@ -1256,11 +1288,11 @@ void comm::Engine::readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) th // Origin-Host avpOH.setId(anna::diameter::helpers::base::AVPID__Origin_Host); avpOH.setMandatoryBit(); - avpOH.getDiameterIdentity()->fromPrintableString(a_host.c_str()); + avpOH.getDiameterIdentity()->fromPrintableString(a_originHost.c_str()); // Origin-Realm avpOR.setId(anna::diameter::helpers::base::AVPID__Origin_Realm); avpOR.setMandatoryBit(); - avpOR.getDiameterIdentity()->fromPrintableString(a_realm.c_str()); + avpOR.getDiameterIdentity()->fromPrintableString(a_originRealm.c_str()); diameterDWA.addAvp(&avpRC); diameterDWA.addAvp(&avpOH); diameterDWA.addAvp(&avpOR); @@ -1274,7 +1306,7 @@ void comm::Engine::readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) th } } -void comm::Engine::resetStatistics() throw() { +void comm::Engine::resetStatistics() { for(server_iterator it = server_begin(), maxii = server_end(); it != maxii; it ++) server(it)->resetStatistics(); @@ -1282,18 +1314,18 @@ void comm::Engine::resetStatistics() throw() { localServer(it)->resetStatistics(); } -void comm::Engine::do_initialize() throw(RuntimeException) { +void comm::Engine::do_initialize() noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "do_initialize", ANNA_FILE_LOCATION)); LOGDEBUG(anna::Logger::debug("Nothing special done on component initialization", ANNA_FILE_LOCATION)); } -void comm::Engine::lazyInitialize() throw(RuntimeException) { +void comm::Engine::lazyInitialize() noexcept(false) { LOGMETHOD(anna::TraceMethod tttm("diameter::comm::Engine", "lazyInitialize", ANNA_FILE_LOCATION)); anna::app::Component::initialize(); // this will invoke do_initialize } // Not tested yet -const comm::Response* comm::Engine::sendRealmHost(const Message* message, const std::string &destinationRealm, const std::string &destinationHost) throw(anna::RuntimeException) { +const comm::Response* comm::Engine::sendRealmHost(const Message* message, const std::string &destinationRealm, const std::string &destinationHost) noexcept(false) { if (destinationRealm == "") throw anna::RuntimeException("Unable to resolve the destination: empty provided Destination-Realm name", ANNA_FILE_LOCATION);