X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestStep.cpp;h=fdbd7989fc8a3374e52dc728919f3028913cb7b8;hb=61f1340da3cae5159d2e3bc14fc47c6d4bf9453e;hp=018dfcd72d14bf5006b30f6383b9339aabe7c938;hpb=a06169181968130467d2e54ac91676aecd14bcea;p=anna.git diff --git a/example/diameter/launcher/testing/TestStep.cpp b/example/diameter/launcher/testing/TestStep.cpp index 018dfcd..fdbd798 100644 --- a/example/diameter/launcher/testing/TestStep.cpp +++ b/example/diameter/launcher/testing/TestStep.cpp @@ -33,7 +33,7 @@ #include // Process -#include +#include #include #include #include @@ -152,7 +152,7 @@ namespace { bool result = true; try { - messageCodec.setEngine(NULL); // perhaps we will need another codec engine ... + messageCodec.clear(); messageCodec.decode(message); } catch (anna::RuntimeException &ex) { @@ -177,10 +177,14 @@ void TestStep::initialize(TestCase *testCase) { a_number = testCase->steps() + 1; // testCase is not NULL } -bool TestStep::decodeMessage() throw() { +bool TestStep::decodeMessage(bool trust) throw() { if (a_messageCodec) return true; a_messageCodec = new anna::diameter::codec::Message; if (::decodeMessage(a_message, *a_messageCodec)) return true; + if (trust) { + LOGDEBUG(anna::Logger::debug("Error DECODING, but trusting it ...", ANNA_FILE_LOCATION)); + return true; + } delete a_messageCodec; a_messageCodec = NULL; @@ -334,6 +338,9 @@ throw() { xmlmsg += a_messageCodec->asXMLString(); xmlmsg += "\n"; } + else { + xmlmsg = ""; + } if (msg != "") result->createAttribute("Message", msg); if (xmlmsg != "") result->createAttribute("XMLMessage", xmlmsg); @@ -346,41 +353,49 @@ throw() { bool TestStepSendxml::do_execute() throw() { bool success = false; - std::string failReason, s_warn; - MyDiameterEntity *entity = a_realmNode->getEntity(); // by default - MyLocalServer *localServer = a_realmNode->getDiameterServer(); // by default + std::string failReason; + MyDiameterEntity *entity = a_originHost->getEntity(); // by default + MyLocalServer *localServer = a_originHost->getDiameterServer(); // by default const TestStepWait *tsw = NULL; - - // Create comm message: - anna::diameter::comm::Message *msg = a_realmNode->createCommMessage(); - //msg->clearBody(); - msg->setBody(a_message); + anna::diameter::comm::Message *msg = a_originHost->createCommMessage(); try { - // Update sequence for answers: - if (a_waitForRequestStepNumber != -1) { // is an answer: try to copy sequence information; alert about Session-Id discrepance - // Request which was received: - tsw = static_cast(a_testCase->getStep(a_waitForRequestStepNumber)); - const anna::DataBlock &request = tsw->getMsgDataBlock(); - anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(request); - anna::diameter::EndToEnd ete = anna::diameter::codec::functions::getEndToEnd(request); + if (a_waitForRequestStepNumber != -1) { - // Update sequence: - anna::diameter::codec::functions::setHopByHop(a_message, hbh); - anna::diameter::codec::functions::setEndToEnd(a_message, ete); + // Referenced request in the 'wait for request step': + tsw = static_cast(a_testCase->getStep(a_waitForRequestStepNumber)); + const anna::DataBlock &referenceRequest = tsw->getMsgDataBlock(); + std::string sessionIdReferenceRequest = anna::diameter::helpers::base::functions::getSessionId(referenceRequest); + bool thisIsAnswer = anna::diameter::codec::functions::isRequest(getMsgDataBlock()); - // Check Session-Id for warning ... - std::string sessionIdAnswer = anna::diameter::helpers::base::functions::getSessionId(a_message); - std::string sessionIdRequest = anna::diameter::helpers::base::functions::getSessionId(request); + if (thisIsAnswer) { // is an answer: try to copy sequence information; alert about Session-Id discrepance + anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(referenceRequest); + anna::diameter::EndToEnd ete = anna::diameter::codec::functions::getEndToEnd(referenceRequest); - if (sessionIdRequest != sessionIdAnswer) { - s_warn = anna::functions::asString("Sending an answer which Session-Id (%s) is different than supposed corresponding request (%s)", sessionIdAnswer.c_str(), sessionIdRequest.c_str()); - LOGWARNING(anna::Logger::warning(s_warn, ANNA_FILE_LOCATION)); - a_testCase->addDebugSummaryHint(s_warn); + // Update sequence: + anna::diameter::codec::functions::setHopByHop(a_message, hbh); + anna::diameter::codec::functions::setEndToEnd(a_message, ete); + } + + // Session-Id substitution: + std::string thisSessionId = anna::diameter::helpers::base::functions::getSessionId(getMsgDataBlock()); + if (thisSessionId != sessionIdReferenceRequest) { + static anna::diameter::codec::Message codecMsg; + codecMsg.decode(getMsgDataBlock()); + codecMsg.getAvp("Session-Id")->getUTF8String()->setValue(sessionIdReferenceRequest); + a_message = codecMsg.code(); + std::string trace = anna::functions::asString("Replacing %s Session-Id (%s) to set the corresponding request one (%s)", (thisIsAnswer ? "answer":"request"), thisSessionId.c_str(), sessionIdReferenceRequest.c_str()); + LOGDEBUG(anna::Logger::debug(trace, ANNA_FILE_LOCATION)); + a_testCase->addDebugSummaryHint(trace); } } + // Create comm message: + //msg->clearBody(); + msg->setBody(a_message); + + if (getType() == Type::Sendxml2e) { anna::diameter::comm::ClientSession *usedClientSession = NULL; @@ -409,10 +424,10 @@ bool TestStepSendxml::do_execute() throw() { } // else (normal sending) // Detailed log: - if(a_realmNode->logEnabled()) { - if (decodeMessage()) { + if(a_originHost->logEnabled()) { + if (decodeMessage(true /* trust */)) { std::string detail = usedClientSession ? usedClientSession->asString() : ""; // shouldn't happen - a_realmNode->writeLogFile(*a_messageCodec, (success ? "sent2e" : "send2eError"), detail); + a_originHost->writeLogFile(*a_messageCodec, (success ? "sent2e" : "send2eError"), detail); } } } @@ -443,10 +458,10 @@ bool TestStepSendxml::do_execute() throw() { } // else (normal sending) // Detailed log: - if(a_realmNode->logEnabled()) { - if (decodeMessage()) { + if(a_originHost->logEnabled()) { + if (decodeMessage(true /* trust */)) { std::string detail = usedServerSession ? usedServerSession->asString() : ""; // shouldn't happen - a_realmNode->writeLogFile(*a_messageCodec, (success ? "sent2c" : "send2cError"), detail); + a_originHost->writeLogFile(*a_messageCodec, (success ? "sent2c" : "send2cError"), detail); } } } @@ -456,7 +471,7 @@ bool TestStepSendxml::do_execute() throw() { } // release msg - a_realmNode->releaseCommMessage(msg); + a_originHost->releaseCommMessage(msg); if (!success) { a_testCase->addDebugSummaryHint(failReason); // before report (when set Failed state); @@ -483,12 +498,13 @@ throw() { anna::xml::Node* result = TestStep::asXML(parent); //parent->createChild("TestStepDelay"); - result->createAttribute("Delay", a_delay.asString()); + result->createAttribute("Delay", ((a_delay == 0) ? "dummy step, no delay" : a_delay.asString())); return result; } bool TestStepDelay::do_execute() throw() { + if (a_delay == 0) { complete(); return true; } // special case try { a_timer = TestManager::instantiate().createTimer((TestCaseStep*)this, a_delay, TestTimer::Type::Delay); } @@ -502,12 +518,14 @@ bool TestStepDelay::do_execute() throw() { } void TestStepDelay::do_complete() throw() { + if (a_delay == 0) return; // special case a_timer = NULL; next(); // next() invoked here because execute() is always false for delay and never advance the iterator // TODO, avoid this recursion } void TestStepDelay::do_reset() throw() { + if (a_delay == 0) return; // special case try { TestManager::instantiate().cancelTimer(a_timer); } @@ -567,6 +585,9 @@ throw() { xmlmsg += a_messageCodec->asXMLString(); xmlmsg += "\n"; } + else { + xmlmsg = ""; + } if (msg != "") result->createAttribute("MatchedMessage", msg); if (xmlmsg != "") result->createAttribute("MatchedXMLMessage", xmlmsg);