#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::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
-
-
Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", "1.1"), a_communicator(NULL) {
a_myDiameterEngine = new MyDiameterEngine();
a_myDiameterEngine->setRealm("ADL.ericsson.com");
a_burstPopCounter = 0;
}
+anna::diameter::comm::Message *Launcher::createCommMessage() throw(anna::RuntimeException) {
+ return a_commMessages.create();
+}
+
+void Launcher::releaseCommMessage(anna::diameter::comm::Message *msg) throw() {
+ a_commMessages.release(msg);
+}
+
+anna::diameter::codec::Message *Launcher::createCodecMessage() throw(anna::RuntimeException) {
+ return a_codecMessages.create();
+}
+
+void Launcher::releaseCodecMessage(anna::diameter::codec::Message *msg) throw() {
+ a_codecMessages.release(msg);
+}
+
+
void Launcher::baseProtocolSetupAsClient(void) throw(anna::RuntimeException) {
// Build CER
// <CER> ::= < Diameter Header: 257, REQ >
void Launcher::writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw() {
// if (!logEnabled()) return;
+ anna::diameter::codec::Message codecMsg;
+ try { codecMsg.decode(db); } catch(anna::RuntimeException &ex) { ex.trace(); }
+ writeLogFile(codecMsg, logExtension, detail);
- // Decode
- try { G_codecMsg.decode(db); } catch(anna::RuntimeException &ex) { ex.trace(); }
-
- writeLogFile(G_codecMsg, logExtension, detail);
}
// Si ya lo tengo decodificado:
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);
+ for(it = it_min; it != it_max; it++) releaseCommMessage((*it).second);
a_burstMessages.clear();
} else {
}
int Launcher::loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException) {
- anna::diameter::comm::Message *msg = G_commMessages.create();
+ anna::diameter::comm::Message *msg = createCommMessage();
msg->setBody(db);
a_burstMessages[a_burstLoadIndx++] = msg;
return (a_burstLoadIndx - 1);
if(it != a_burstMessages.end()) {
// Decode
- try { G_codecMsg.decode((*it).second->getBody()); } catch(anna::RuntimeException &ex) { ex.trace(); }
-
- result = G_codecMsg.asXMLString();
+ anna::diameter::codec::Message codecMsg;
+ try { codecMsg.decode((*it).second->getBody()); } catch(anna::RuntimeException &ex) { ex.trace(); }
+ result = codecMsg.asXMLString();
}
return result;
response_content = "Operation processed with exception. See traces\n"; // supposed
std::string result = "";
anna::DataBlock db_aux(true);
+ anna::diameter::codec::Message codecMsg;
///////////////////////////////////////////////////////////////////
// Simple operations without arguments:
// Operations:
if(opType == "code") {
- G_codecMsg.loadXML(param1);
- std::string hexString = anna::functions::asHexString(G_codecMsg.code());
+ codecMsg.loadXML(param1);
+ std::string hexString = anna::functions::asHexString(codecMsg.code());
// write to outfile
std::ofstream outfile(param2.c_str(), std::ifstream::out);
outfile.write(hexString.c_str(), hexString.size());
throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION);
// Decode
- try { G_codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); }
+ try { codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); }
- std::string xmlString = G_codecMsg.asXMLString();
+ std::string xmlString = codecMsg.asXMLString();
// write to outfile
std::ofstream outfile(param2.c_str(), std::ifstream::out);
outfile.write(xmlString.c_str(), xmlString.size());
MyDiameterEntity *entity = getEntity();
if(!entity) throw anna::RuntimeException("No entity configured to send the message", ANNA_FILE_LOCATION);
+ anna::diameter::comm::Message *msg = createCommMessage();
if((opType == "sendxml") || (opType == "sendxml2e")) {
- G_codecMsg.loadXML(param1);
- G_commMsgSent2e.clearBody();
- try { G_codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher)
+ codecMsg.loadXML(param1);
+ msg->clearBody();
+ try { codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher)
- G_commMsgSent2e.setBody(G_codecMsg.code());
+ msg->setBody(codecMsg.code());
} else {
// Get DataBlock from file with hex content:
if(!getDataBlockFromHexFile(param1, db_aux))
throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION);
- G_commMsgSent2e.setBody(db_aux);
+ msg->setBody(db_aux);
}
- bool success = entity->send(G_commMsgSent2e, cl.exists("balance"));
+ bool success = entity->send(msg, cl.exists("balance"));
+ releaseCommMessage(msg);
// Detailed log:
if(logEnabled()) {
anna::diameter::comm::Server *usedServer = 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(G_codecMsg, (success ? "sent2e" : "send2eError"), detail);
+ writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail);
}
} else if((opType == "burst")) {
anna::diameter::comm::Entity *entity = getEntity();
} else if(param1 == "load") {
if(param2 == "") throw anna::RuntimeException("Missing xml path file for burst load operation", ANNA_FILE_LOCATION);
- G_codecMsg.loadXML(param2);
+ codecMsg.loadXML(param2);
- 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)
+ if(codecMsg.isAnswer()) throw anna::RuntimeException("Cannot load diameter answers for burst feature", ANNA_FILE_LOCATION);
+ try { 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 = loadBurstMessage(G_codecMsg.code());
+ int position = loadBurstMessage(codecMsg.code());
result = "Loaded '";
result += param2;
result += "' file into burst list position ";
MyLocalServer *localServer = getDiameterLocalServer();
if(!localServer) throw anna::RuntimeException("No local server configured to send the message", ANNA_FILE_LOCATION);
+ anna::diameter::comm::Message *msg = createCommMessage();
if(opType == "sendxml2c") {
- G_codecMsg.loadXML(param1);
- G_commMsgSent2c.clearBody();
- try { G_codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher)
+ codecMsg.loadXML(param1);
+ msg->clearBody();
+ try { codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher)
- G_commMsgSent2c.setBody(G_codecMsg.code());
+ msg->setBody(codecMsg.code());
} else {
// Get DataBlock from file with hex content:
if(!getDataBlockFromHexFile(param1, db_aux))
throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION);
- G_commMsgSent2c.setBody(db_aux);
+ msg->setBody(db_aux);
}
- bool success = localServer->send(G_commMsgSent2c);
+ bool success = localServer->send(msg);
+ releaseCommMessage(msg);
// Detailed log:
if(logEnabled()) {
anna::diameter::comm::ServerSession *usedServerSession = localServer->getLastUsedResource();
std::string detail = usedServerSession ? usedServerSession->asString() : "<null server session>"; // esto no deberia ocurrir
- writeLogFile(G_codecMsg, (success ? "sent2c" : "send2cError"), detail);
+ writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail);
}
} else if(opType == "loadxml") {
- G_codecMsg.loadXML(param1);
- std::string xmlString = G_codecMsg.asXMLString();
+ codecMsg.loadXML(param1);
+ std::string xmlString = codecMsg.asXMLString();
std::cout << xmlString << std::endl;
} else if(opType == "diameterServerSessions") {
int diameterServerSessions = atoi(param1.c_str());