void AccessStrategy::beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry, const Face& inFace, const Data& data) { shared_ptr<PitInfo> pi = pitEntry->getStrategyInfo<PitInfo>(); if (pi != nullptr) { pi->rtoTimer.cancel(); } if (!pitEntry->hasInRecords()) { // already satisfied by another upstream NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() << " not-fastest"); return; } pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace); if (outRecord == pitEntry->out_end()) { // no out-record NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() << " no-out-record"); return; } time::steady_clock::Duration rtt = time::steady_clock::now() - outRecord->getLastRenewed(); NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() << " rtt=" << time::duration_cast<time::microseconds>(rtt).count()); this->updateMeasurements(inFace, data, time::duration_cast<RttEstimator::Duration>(rtt)); }
void AccessStrategy::afterReceiveNewInterest(const Face& inFace, const Interest& interest, shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry) { Name miName; shared_ptr<MtInfo> mi; std::tie(miName, mi) = this->findPrefixMeasurements(*pitEntry); // has measurements for Interest Name? if (mi != nullptr) { NFD_LOG_DEBUG(interest << " interestFrom " << inFace.getId() << " new-interest mi=" << miName); // send to last working nexthop bool isSentToLastNexthop = this->sendToLastNexthop(inFace, pitEntry, *mi, fibEntry); if (isSentToLastNexthop) { return; } } else { NFD_LOG_DEBUG(interest << " interestFrom " << inFace.getId() << " new-interest no-mi"); } // no measurements, or last working nexthop unavailable // multicast to all nexthops except incoming face this->multicast(pitEntry, fibEntry, {inFace.getId()}); }
bool FaceManager::extractLocalControlParameters(const Interest& request, ControlParameters& parameters, ControlCommand& command, shared_ptr<LocalFace>& outFace, LocalControlFeature& outFeature) { if (!validateParameters(command, parameters)) { sendResponse(request.getName(), 400, "Malformed command"); return false; } shared_ptr<Face> face = m_faceTable.get(request.getIncomingFaceId()); if (!static_cast<bool>(face)) { NFD_LOG_DEBUG("command result: faceid " << request.getIncomingFaceId() << " not found"); sendResponse(request.getName(), 410, "Face not found"); return false; } else if (!face->isLocal()) { NFD_LOG_DEBUG("command result: cannot enable local control on non-local faceid " << face->getId()); sendResponse(request.getName(), 412, "Face is non-local"); return false; } outFace = dynamic_pointer_cast<LocalFace>(face); outFeature = static_cast<LocalControlFeature>(parameters.getLocalControlFeature()); return true; }
void StrategyChoiceManager::unsetStrategy(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::StrategyChoiceUnsetCommand command; if (!validateParameters(command, parameters)) { static const Name ROOT_PREFIX; if (parameters.hasName() && parameters.getName() == ROOT_PREFIX) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: unset-root"); setResponse(response, 403, "Cannot unset root prefix strategy"); } else { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); } return; } m_strategyChoice.erase(parameters.getName()); NFD_LOG_DEBUG("strategy-choice result: SUCCESS"); setResponse(response, 200, "Success", parameters.wireEncode()); }
void FibManager::removeNextHop(const Name& topPrefix, const Interest& interest, ControlParameters parameters, const ndn::mgmt::CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); NFD_LOG_TRACE("remove-nexthop prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); auto face = m_getFace(parameters.getFaceId()); if (static_cast<bool>(face)) { auto entry = m_fib.findExactMatch(parameters.getName()); if (static_cast<bool>(entry)) { entry->removeNextHop(face); NFD_LOG_DEBUG("remove-nexthop result: OK prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); if (!entry->hasNextHops()) { m_fib.erase(*entry); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK"); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK"); } done(ControlResponse(200, "Success").setBody(parameters.wireEncode())); }
void StrategyChoiceManager::onStrategyChoiceRequest(const Interest& request) { const Name& command = request.getName(); const size_t commandNComps = command.size(); if (command == LIST_DATASET_PREFIX) { listStrategies(request); return; } if (COMMAND_UNSIGNED_NCOMPS <= commandNComps && commandNComps < COMMAND_SIGNED_NCOMPS) { NFD_LOG_DEBUG("command result: unsigned verb: " << command); sendResponse(command, 401, "Signature required"); return; } else if (commandNComps < COMMAND_SIGNED_NCOMPS || !COMMAND_PREFIX.isPrefixOf(command)) { NFD_LOG_DEBUG("command result: malformed"); sendResponse(command, 400, "Malformed command"); return; } validate(request, bind(&StrategyChoiceManager::onValidatedStrategyChoiceRequest, this, _1), bind(&ManagerBase::onCommandValidationFailed, this, _1, _2)); }
void FaceManager::listQueriedFaces(const Interest& request) { NFD_LOG_DEBUG("in listQueriedFaces"); const Name& query = request.getName(); const size_t queryNComps = query.size(); if (queryNComps < FACES_QUERY_DATASET_NCOMPS || !FACES_QUERY_DATASET_PREFIX.isPrefixOf(query)) { NFD_LOG_DEBUG("query result: malformed"); sendNack(query); return; } ndn::nfd::FaceQueryFilter faceFilter; try { faceFilter.wireDecode(query[-1].blockFromValue()); } catch (tlv::Error&) { NFD_LOG_DEBUG("query result: malformed filter"); sendNack(query); return; } FaceQueryStatusPublisher faceQueryStatusPublisher(m_faceTable, *m_face, query, faceFilter, m_keyChain); faceQueryStatusPublisher.publish(); }
void StrategyChoiceManager::setStrategy(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::StrategyChoiceSetCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); return; } const Name& prefix = parameters.getName(); const Name& selectedStrategy = parameters.getStrategy(); if (!m_strategyChoice.hasStrategy(selectedStrategy)) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: unknown-strategy: " << parameters.getStrategy()); setResponse(response, 504, "Unsupported strategy"); return; } if (m_strategyChoice.insert(prefix, selectedStrategy)) { NFD_LOG_DEBUG("strategy-choice result: SUCCESS"); setResponse(response, 200, "Success", parameters.wireEncode()); } else { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: not-installed"); setResponse(response, 405, "Strategy not installed"); } }
void FibManager::onValidatedFibRequest(const shared_ptr<const Interest>& request) { const Name& command = request->getName(); const Name::Component& verb = command[COMMAND_PREFIX.size()]; const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1]; SignedVerbDispatchTable::const_iterator verbProcessor = m_signedVerbDispatch.find(verb); if (verbProcessor != m_signedVerbDispatch.end()) { ControlParameters parameters; if (!extractParameters(parameterComponent, parameters) || !parameters.hasFaceId()) { NFD_LOG_DEBUG("command result: malformed verb: " << verb); sendResponse(command, 400, "Malformed command"); return; } if (parameters.getFaceId() == 0) { parameters.setFaceId(request->getIncomingFaceId()); } NFD_LOG_DEBUG("command result: processing verb: " << verb); ControlResponse response; (verbProcessor->second)(this, parameters, response); sendResponse(command, response); } else { NFD_LOG_DEBUG("command result: unsupported verb: " << verb); sendResponse(command, 501, "Unsupported command"); } }
void FibManager::onFibRequest(const Interest& request) { const Name& command = request.getName(); const size_t commandNComps = command.size(); const Name::Component& verb = command.get(COMMAND_PREFIX.size()); UnsignedVerbDispatchTable::const_iterator unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb); if (unsignedVerbProcessor != m_unsignedVerbDispatch.end()) { NFD_LOG_DEBUG("command result: processing verb: " << verb); (unsignedVerbProcessor->second)(this, request); } else if (COMMAND_UNSIGNED_NCOMPS <= commandNComps && commandNComps < COMMAND_SIGNED_NCOMPS) { NFD_LOG_DEBUG("command result: unsigned verb: " << command); sendResponse(command, 401, "Signature required"); } else if (commandNComps < COMMAND_SIGNED_NCOMPS || !COMMAND_PREFIX.isPrefixOf(command)) { NFD_LOG_DEBUG("command result: malformed"); sendResponse(command, 400, "Malformed command"); } else { validate(request, bind(&FibManager::onValidatedFibRequest, this, _1), bind(&ManagerBase::onCommandValidationFailed, this, _1, _2)); } }
void Cs::find(const Interest& interest, const HitCallback& hitCallback, const MissCallback& missCallback) const { BOOST_ASSERT(static_cast<bool>(hitCallback)); BOOST_ASSERT(static_cast<bool>(missCallback)); const Name& prefix = interest.getName(); bool isRightmost = interest.getChildSelector() == 1; NFD_LOG_DEBUG("find " << prefix << (isRightmost ? " R" : " L")); iterator first = m_table.lower_bound(prefix); iterator last = m_table.end(); if (prefix.size() > 0) { last = m_table.lower_bound(prefix.getSuccessor()); } iterator match = last; if (isRightmost) { match = this->findRightmost(interest, first, last); } else { match = this->findLeftmost(interest, first, last); } if (match == last) { NFD_LOG_DEBUG(" no-match"); missCallback(interest); return; } NFD_LOG_DEBUG(" matching " << match->getName()); m_policy->beforeUse(match); hitCallback(interest, match->getData()); }
void LoggerFactory::onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename) { // log // { // ; default_level specifies the logging level for modules // ; that are not explicitly named. All debugging levels // ; listed above the selected value are enabled. // // default_level INFO // // ; You may also override the default for specific modules: // // FibManager DEBUG // Forwarder WARN // } if (!isDryRun) { ConfigSection::const_assoc_iterator item = section.find("default_level"); if (item != section.not_found()) { LogLevel level = extractLevel(item->second, "default_level"); setDefaultLevel(level); } else { setDefaultLevel(LOG_INFO); } } for (const auto& i : section) { LogLevel level = extractLevel(i.second, i.first); if (i.first == "default_level") { // do nothing } else { std::unique_lock<std::mutex> lock(m_loggersGuard); LoggerMap::iterator loggerIt = m_loggers.find(i.first); if (loggerIt == m_loggers.end()) { lock.unlock(); NFD_LOG_DEBUG("Failed to configure logging level for module \"" << i.first << "\" (module not found)"); } else if (!isDryRun) { loggerIt->second.setLogLevel(level); lock.unlock(); NFD_LOG_DEBUG("Changing level for module " << i.first << " to " << level); } } } }
unique_ptr<Strategy> Strategy::create(const Name& instanceName, Forwarder& forwarder) { auto found = Strategy::find(instanceName); if (found == getRegistry().end()) { NFD_LOG_DEBUG("create " << instanceName << " not-found"); return nullptr; } unique_ptr<Strategy> instance = found->second(forwarder, instanceName); NFD_LOG_DEBUG("create " << instanceName << " found=" << found->first << " created=" << instance->getInstanceName()); BOOST_ASSERT(!instance->getInstanceName().empty()); return instance; }
void MadmStrategy::probeInterests(const shared_ptr<Face> outFace, const Interest& interest, StrategyRequirements &requirements, const fib::NextHopList& nexthops, shared_ptr<pit::Entry> pitEntry) { for (auto n : nexthops) { const shared_ptr<Face>& thisFace = n.getFace(); bool costTooHigh = false; if (requirements.getLimits(RequirementType::COST).second != -1) { costTooHigh = costMap[thisFace->getId()].getCost() > (requirements.getLimits(RequirementType::COST)).second; if (costTooHigh) { NFD_LOG_DEBUG( "Cost too high: " << costMap[thisFace->getId()].getCost() << " > " << (requirements.getLimits(RequirementType::COST)).second); } } if (thisFace != outFace && !costTooHigh) { NFD_LOG_TRACE("Probing face: " << thisFace->getId()); faceInfoTable[thisFace->getId()].addSentInterest(interest.getName().toUri()); this->sendInterest(pitEntry, thisFace, true); } } }
void Strategy::beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry, const Face& inFace, const Data& data) { NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() << " inFace=" << inFace.getId() << " data=" << data.getName()); }
void StrategyChoiceManager::onValidatedStrategyChoiceRequest(const shared_ptr<const Interest>& request) { static const Name::Component VERB_SET("set"); static const Name::Component VERB_UNSET("unset"); const Name& command = request->getName(); const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1]; ControlParameters parameters; if (!extractParameters(parameterComponent, parameters)) { sendResponse(command, 400, "Malformed command"); return; } const Name::Component& verb = command[COMMAND_PREFIX.size()]; ControlResponse response; if (verb == VERB_SET) { setStrategy(parameters, response); } else if (verb == VERB_UNSET) { unsetStrategy(parameters, response); } else { NFD_LOG_DEBUG("command result: unsupported verb: " << verb); setResponse(response, 501, "Unsupported command"); } sendResponse(command, response); }
void Strategy::afterReceiveNack(const Face& inFace, const lp::Nack& nack, const shared_ptr<pit::Entry>& pitEntry) { NFD_LOG_DEBUG("afterReceiveNack inFace=" << inFace.getId() << " pitEntry=" << pitEntry->getName()); }
void onSuccess(const typename Protocol::endpoint& resolvedEndpoint, const typename Protocol::endpoint& expectedEndpoint, bool isValid, bool wantCheckAddress = false) { NFD_LOG_DEBUG("Resolved to: " << resolvedEndpoint); ++m_nSuccesses; if (!isValid) { BOOST_FAIL("Resolved to " + boost::lexical_cast<std::string>(resolvedEndpoint) + ", but it should have failed"); } BOOST_CHECK_EQUAL(resolvedEndpoint.port(), expectedEndpoint.port()); BOOST_CHECK_EQUAL(resolvedEndpoint.address().is_v4(), expectedEndpoint.address().is_v4()); // checking address is not deterministic and should be enabled only // if only one IP address will be returned by resolution if (wantCheckAddress) { BOOST_CHECK_EQUAL(resolvedEndpoint.address(), expectedEndpoint.address()); } }
void Strategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, const FaceEndpoint& ingress, const Data& data) { NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() << " in=" << ingress << " data=" << data.getName()); }
void AsfStrategy::afterReceiveNack(const Face& inFace, const lp::Nack& nack, const shared_ptr<pit::Entry>& pitEntry) { NFD_LOG_DEBUG("Nack for " << nack.getInterest() << " from=" << inFace.getId() << ": " << nack.getReason()); onTimeout(pitEntry->getName(), inFace.getId()); }
void FibManager::addNextHop(const Name& topPrefix, const Interest& interest, ControlParameters parameters, const ndn::mgmt::CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); const Name& prefix = parameters.getName(); FaceId faceId = parameters.getFaceId(); uint64_t cost = parameters.getCost(); NFD_LOG_TRACE("add-nexthop prefix: " << prefix << " faceid: " << faceId << " cost: " << cost); auto face = m_getFace(faceId); if (static_cast<bool>(face)) { auto entry = m_fib.insert(prefix).first; entry->addNextHop(face, cost); NFD_LOG_DEBUG("add-nexthop result: OK" << " prefix:" << prefix << " faceid: " << faceId << " cost: " << cost); return done(ControlResponse(200, "Success").setBody(parameters.wireEncode())); } else { NFD_LOG_INFO("add-nexthop result: FAIL reason: unknown-faceid: " << faceId); return done(ControlResponse(410, "Face not found")); } }
void ManagerBase::onCommandValidationFailed(const shared_ptr<const Interest>& command, const std::string& error) { NFD_LOG_DEBUG("command result: unauthorized command: " << *command << " (" << error << ")"); sendResponse(command->getName(), 403, "Unauthorized command"); }
void RibManager::unregisterEntry(const shared_ptr<const Interest>& request, ControlParameters& params) { ndn::nfd::RibUnregisterCommand command; // Passing all parameters gives error in validation, // so passing only the required arguments. ControlParameters parameters; parameters.setName(params.getName()); if (params.hasFaceId()) { parameters.setFaceId(params.getFaceId()); } if (params.hasOrigin()) { parameters.setOrigin(params.getOrigin()); } if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("unregister result: FAIL reason: malformed"); if (static_cast<bool>(request)) { sendResponse(request->getName(), 400, "Malformed command"); } return; } bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0); if (isSelfRegistration) { shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request->getTag<lp::IncomingFaceIdTag>(); if (incomingFaceIdTag == nullptr) { sendResponse(request->getName(), 503, "requested self-registration, but IncomingFaceId is unavailable"); return; } parameters.setFaceId(*incomingFaceIdTag); } // Respond since command is valid and authorized sendSuccessResponse(request, parameters); Route route; route.faceId = parameters.getFaceId(); route.origin = parameters.getOrigin(); NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId << " origin=" << route.origin); RibUpdate update; update.setAction(RibUpdate::UNREGISTER) .setName(parameters.getName()) .setRoute(route); m_managedRib.beginApplyUpdate(update, bind(&RibManager::onRibUpdateSuccess, this, update), bind(&RibManager::onRibUpdateFailure, this, update, _1, _2)); }
void Cs::dump() { NFD_LOG_DEBUG("dump table"); for (const EntryImpl& entry : m_table) { NFD_LOG_TRACE(entry.getFullName()); } }
void RibManager::onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error) { NFD_LOG_DEBUG("RIB update failed for " << update << " (code: " << code << ", error: " << error << ")"); // Since the FIB rejected the update, clean up invalid routes scheduleActiveFaceFetch(time::seconds(1)); }
void AccessStrategy::afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, weak_ptr<fib::Entry> fibWeak, FaceId inFace, FaceId firstOutFace) { shared_ptr<pit::Entry> pitEntry = pitWeak.lock(); BOOST_ASSERT(pitEntry != nullptr); // pitEntry can't become nullptr, because RTO timer should be cancelled upon pitEntry destruction shared_ptr<fib::Entry> fibEntry = fibWeak.lock(); if (fibEntry == nullptr) { NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " fib-gone"); return; } NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " multicast-except " << inFace << ',' << firstOutFace); this->multicast(pitEntry, fibEntry, {inFace, firstOutFace}); }
void AccessStrategy::afterReceiveRetxInterest(const Face& inFace, const Interest& interest, shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry) { NFD_LOG_DEBUG(interest << " interestFrom " << inFace.getId() << " retx-forward"); this->multicast(pitEntry, fibEntry, {inFace.getId()}); }
void Strategy::afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace, const Data& data) { NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName() << " inFace=" << inFace.getId() << " data=" << data.getName()); this->sendData(pitEntry, data, inFace); }
void FaceManager::listChannels(const Interest& request) { NFD_LOG_DEBUG("in listChannels"); const Name& command = request.getName(); const size_t commandNComps = command.size(); if (commandNComps < CHANNELS_LIST_DATASET_NCOMPS || !CHANNELS_LIST_DATASET_PREFIX.isPrefixOf(command)) { NFD_LOG_DEBUG("command result: malformed"); sendResponse(command, 400, "Malformed command"); return; } NFD_LOG_DEBUG("publishing"); m_channelStatusPublisher.publish(); }
void FibManager::removeNextHop(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::FibRemoveNextHopCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("remove-nexthop result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); return; } NFD_LOG_TRACE("remove-nexthop prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); shared_ptr<Face> faceToRemove = m_getFace(parameters.getFaceId()); if (static_cast<bool>(faceToRemove)) { shared_ptr<fib::Entry> entry = m_managedFib.findExactMatch(parameters.getName()); if (static_cast<bool>(entry)) { entry->removeNextHop(faceToRemove); NFD_LOG_DEBUG("remove-nexthop result: OK prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); if (!entry->hasNextHops()) { m_managedFib.erase(*entry); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK, but entry for face id " << parameters.getFaceId() << " not found"); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK, but face id " << parameters.getFaceId() << " not found"); } setResponse(response, 200, "Success", parameters.wireEncode()); }