31#include <ndn-cxx/util/random.hpp>
40 : m_probingInterval(DEFAULT_PROBING_INTERVAL)
41 , m_measurements(measurements)
53 if (info ==
nullptr) {
90 auto srtt = priority == 2 ? fs.srtt : time::nanoseconds::max();
95 return std::tuple(priority, srtt, fs.cost, fs.face->getId());
107 static std::uniform_real_distribution<> randDist;
108 static auto& rng = ndn::random::getRandomNumberEngine();
109 const double randomNumber = randDist(rng);
111 const auto nFaces = rankedFaces.size();
112 const double rankSum = (nFaces + 1) * nFaces / 2;
116 for (
const auto& faceStat : rankedFaces) {
120 double probability =
static_cast<double>(nFaces + 1 - rank) / rankSum;
132 offset += probability;
133 if (randomNumber <= offset) {
135 return faceStat.face;
152 Face& hopFace = hop.getFace();
167 rankedFaces.insert({&hopFace, info->
getLastRtt(), info->
getSrtt(), hop.getCost()});
171 if (ndn_cxx_getLogger().isLevelEnabled(ndn::util::LogLevel::TRACE)) {
172 NFD_LOG_TRACE(
"Current ranking of the faces for probing: " << interest.getName());
173 for (
const FaceStats& probeRank : rankedFaces) {
174 NFD_LOG_TRACE(
" Face: " << probeRank.face->getId() <<
", " << probeRank.rtt <<
", " << probeRank.srtt);
178 if (rankedFaces.empty()) {
185 return rankedFaces.begin()->face;
200 static std::uniform_int_distribution<> randDist(0, 5000);
201 static auto& rng = ndn::random::getRandomNumberEngine();
202 auto interval = randDist(rng);
225 m_probingInterval = probingInterval;
228 NDN_THROW(std::invalid_argument(
"Probing interval must be >= " +
This file contains common algorithms used by forwarding strategies.
Generalization of a network interface.
FaceId getId() const noexcept
Returns the face ID.
Represents an entry in the FIB.
const Name & getPrefix() const noexcept
const NextHopList & getNextHops() const noexcept
Helper class to retrieve and create strategy measurements.
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Name &prefix)
static constexpr time::milliseconds DEFAULT_MEASUREMENTS_LIFETIME
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Name &interestName, FaceId faceId)
NamespaceInfo * getNamespaceInfo(const Name &prefix)
Strategy information for each face in a namespace.
static constexpr time::nanoseconds RTT_TIMEOUT
static constexpr time::nanoseconds RTT_NO_MEASUREMENT
time::nanoseconds getSrtt() const
time::nanoseconds getLastRtt() const
Stores strategy information about each face in this namespace.
void setIsFirstProbeScheduled(bool isScheduled)
bool isFirstProbeScheduled() const
void setIsProbingDue(bool isProbingDue)
bool isProbingDue() const
Face * getFaceToProbe(const Face &inFace, const Interest &interest, const fib::Entry &fibEntry, const Face &faceUsed)
bool isProbingNeeded(const fib::Entry &fibEntry, const Name &interestName)
static constexpr time::milliseconds MIN_PROBING_INTERVAL
std::set< FaceStats, FaceStatsProbingCompare > FaceStatsProbingSet
void afterForwardingProbe(const fib::Entry &fibEntry, const Name &interestName)
void setProbingInterval(time::milliseconds probingInterval)
void scheduleProbe(const fib::Entry &fibEntry, time::milliseconds interval)
ProbingModule(AsfMeasurements &measurements)
static constexpr time::milliseconds DEFAULT_PROBING_INTERVAL
#define NFD_LOG_INIT(name)
static Face * chooseFace(const ProbingModule::FaceStatsProbingSet &rankedFaces)
static auto getFaceRankForProbing(const FaceStats &fs) noexcept
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
Determine whether forwarding the Interest in pitEntry to outFace would violate scope.
ndn::Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
Container for ranking-related values.
bool operator()(const FaceStats &lhs, const FaceStats &rhs) const noexcept