31 #include <ndn-cxx/util/random.hpp>
38 : m_probingInterval(DEFAULT_PROBING_INTERVAL)
39 , m_measurements(measurements)
51 if (info ==
nullptr) {
88 auto srtt = priority == 2 ? fs.srtt : time::nanoseconds::max();
93 return std::tuple(priority, srtt, fs.cost, fs.face->getId());
105 static std::uniform_real_distribution<> randDist;
106 static auto& rng = ndn::random::getRandomNumberEngine();
107 const double randomNumber = randDist(rng);
109 const auto nFaces = rankedFaces.size();
110 const double rankSum = (nFaces + 1) * nFaces / 2;
114 for (
const auto& faceStat : rankedFaces) {
118 double probability =
static_cast<double>(nFaces + 1 - rank) / rankSum;
130 offset += probability;
131 if (randomNumber <= offset) {
133 return faceStat.face;
150 Face& hopFace = hop.getFace();
165 rankedFaces.insert({&hopFace, info->
getLastRtt(), info->
getSrtt(), hop.getCost()});
169 if (rankedFaces.empty()) {
176 return rankedFaces.begin()->face;
191 static std::uniform_int_distribution<> randDist(0, 5000);
192 static auto& rng = ndn::random::getRandomNumberEngine();
193 auto interval = randDist(rng);
216 m_probingInterval = probingInterval;
219 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 NextHopList & getNextHops() const noexcept
const Name & getPrefix() const noexcept
Helper class to retrieve and create strategy measurements.
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Name &prefix)
static constexpr time::microseconds 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
static auto getFaceRankForProbing(const FaceStats &fs) noexcept
static Face * chooseFace(const ProbingModule::FaceStatsProbingSet &rankedFaces)
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