fw: ASF: Fix implementation not matching technical report
This commit resolves several issues. First, a bug was discovered
regarding the usage of std::set objects when ranking faces for
forwarding and probing purposes. These objects enforce uniqueness;
however, this is defined based on the comparison function provided.
As no fields that were inherently unique were used to rank faces, this
would mean that a face with matching ranking information as one
inserted previously would be blocked from being inserted into face
ranking for forwarding and probing. We add faceId as a tiebreaker to
ensure deterministic behavior in these cases. We also fix an issue
where the count of consecutive silent timeouts was not properly cleared
upon the receipt of data or when a timeout was marked.
Additionally, this commit replaces previous implementations of the
ranking code for forwarding and probing. This is partially in order
to eliminate bugs introduced by incorrect implementations of the ranking
for probing and forwarding, as well as trying to make the code easier
to understand and maintain. This included removing a specific
optimization in probing by including unmeasured faces in the
ranking rather than have probes to unmeasured faces be ordered
based on undefined metrics (in practice, tied faces were inserted
in route creation order). However, we did make the choice to add
cost as a tiebreaker for working measured faces, as was the case
with the initial implementation for forwarding.
Refs #5310
Change-Id: Iabfdafea764fe24fe6c478a6073734e51aaf9fa1
diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp
index 2373c69..24aa9d7 100644
--- a/daemon/fw/asf-strategy.cpp
+++ b/daemon/fw/asf-strategy.cpp
@@ -35,8 +35,6 @@
AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name)
: Strategy(forwarder)
, ProcessNackTraits(this)
- , m_measurements(getMeasurements())
- , m_probing(m_measurements)
{
ParsedInstanceName parsed = parseInstanceName(name);
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
@@ -73,7 +71,7 @@
// Check if the interest is new and, if so, skip the retx suppression check
if (!hasPendingOutRecords(*pitEntry)) {
- auto* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry);
+ auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry);
if (faceToUse == nullptr) {
NFD_LOG_INTEREST_FROM(interest, ingress, "new no-nexthop");
sendNoRouteNack(ingress.face, pitEntry);
@@ -86,7 +84,7 @@
return;
}
- auto* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false);
+ auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false);
if (faceToUse != nullptr) {
auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, *faceToUse);
if (suppressResult == RetxSuppressionResult::SUPPRESS) {
@@ -160,6 +158,7 @@
// Extend PIT entry timer to allow slower probes to arrive
this->setExpiryTimer(pitEntry, 50_ms);
faceInfo->cancelTimeout(data.getName());
+ faceInfo->setNTimeouts(0);
}
void
@@ -218,50 +217,52 @@
m_probing.afterForwardingProbe(fibEntry, interest.getName());
}
-struct FaceStats
+static auto
+getFaceRankForForwarding(const FaceStats& fs) noexcept
{
- Face* face;
- time::nanoseconds rtt;
- time::nanoseconds srtt;
- uint64_t cost;
-};
+ // The RTT is used to store the status of the face:
+ // - A positive value indicates data was received and is assumed to indicate a working face (group 1),
+ // - RTT_NO_MEASUREMENT indicates a face is unmeasured (group 2),
+ // - RTT_TIMEOUT indicates a face is timed out (group 3).
+ // These groups are defined in the technical report.
+ //
+ // When forwarding, we assume an order where working faces (group 1) are ranked
+ // higher than unmeasured faces (group 2), and unmeasured faces are ranked higher
+ // than timed out faces (group 3). We assign each group a priority value from 1-3
+ // to ensure lowest-to-highest ordering consistent with this logic.
-struct FaceStatsCompare
-{
- bool
- operator()(const FaceStats& lhs, const FaceStats& rhs) const
- {
- time::nanoseconds lhsValue = getValueForSorting(lhs);
- time::nanoseconds rhsValue = getValueForSorting(rhs);
-
- // Sort by RTT and then by cost
- return std::tie(lhsValue, lhs.cost) < std::tie(rhsValue, rhs.cost);
+ // Working faces are ranked first in priority; if RTT is not
+ // a special value, we assume the face to be in this group.
+ int priority = 1;
+ if (fs.rtt == FaceInfo::RTT_NO_MEASUREMENT) {
+ priority = 2;
+ }
+ else if (fs.rtt == FaceInfo::RTT_TIMEOUT) {
+ priority = 3;
}
-private:
- static time::nanoseconds
- getValueForSorting(const FaceStats& stats)
- {
- // These values allow faces with no measurements to be ranked better than timeouts
- // srtt < RTT_NO_MEASUREMENT < RTT_TIMEOUT
- if (stats.rtt == FaceInfo::RTT_TIMEOUT) {
- return time::nanoseconds::max();
- }
- else if (stats.rtt == FaceInfo::RTT_NO_MEASUREMENT) {
- return time::nanoseconds::max() / 2;
- }
- else {
- return stats.srtt;
- }
- }
-};
+ // We set SRTT by default to the max value; if a face is working, we instead set it to the actual value.
+ // Unmeasured and timed out faces are not sorted by SRTT.
+ auto srtt = priority == 1 ? fs.srtt : time::nanoseconds::max();
+
+ // For ranking, group takes the priority over SRTT (if present) or cost, SRTT (if present)
+ // takes priority over cost, and cost takes priority over FaceId.
+ // FaceId is included to ensure all unique entries are included in the ranking (see #5310)
+ return std::tuple(priority, srtt, fs.cost, fs.face->getId());
+}
+
+bool
+AsfStrategy::FaceStatsForwardingCompare::operator()(const FaceStats& lhs, const FaceStats& rhs) const noexcept
+{
+ return getFaceRankForForwarding(lhs) < getFaceRankForForwarding(rhs);
+}
Face*
AsfStrategy::getBestFaceForForwarding(const Interest& interest, const Face& inFace,
const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry,
bool isInterestNew)
{
- std::set<FaceStats, FaceStatsCompare> rankedFaces;
+ FaceStatsForwardingSet rankedFaces;
auto now = time::steady_clock::now();
for (const auto& nh : fibEntry.getNextHops()) {
@@ -311,6 +312,7 @@
else {
NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts);
faceInfo.recordTimeout(interestName);
+ faceInfo.setNTimeouts(0);
}
}