blob: 8688729fbe5a8eb74127b4651b426b17dac45826 [file] [log] [blame]
Vince Lehman8a4c29e2016-07-11 08:49:35 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande90015992017-07-11 17:25:48 -05002/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Vince Lehman8a4c29e2016-07-11 08:49:35 +00004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "asf-strategy.hpp"
Ashlesh Gawande2a73f352016-12-01 15:37:03 +000027#include "algorithm.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040028#include "common/logger.hpp"
awlaneee97f532024-09-19 15:48:21 -050029#include <boost/lexical_cast.hpp>
Vince Lehman8a4c29e2016-07-11 08:49:35 +000030
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::fw::asf {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000032
Davide Pesaventoa3148082018-04-12 18:21:54 -040033NFD_LOG_INIT(AsfStrategy);
Junxiao Shi037f4ab2016-12-13 04:27:06 +000034NFD_REGISTER_STRATEGY(AsfStrategy);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000035
Vince Lehman8a4c29e2016-07-11 08:49:35 +000036AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000037 : Strategy(forwarder)
awlane9acba9c2024-01-26 18:10:39 -060038 , ProcessNackTraits(this)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000039{
Junxiao Shi18739c42016-12-22 08:03:00 +000040 ParsedInstanceName parsed = parseInstanceName(name);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000041 if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050042 NDN_THROW(std::invalid_argument("AsfStrategy does not support version " +
43 std::to_string(*parsed.version)));
Junxiao Shi91f6ee02016-12-29 21:44:44 +000044 }
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040045
46 StrategyParameters params = parseParameters(parsed.parameters);
47 m_retxSuppression = RetxSuppressionExponential::construct(params);
48 auto probingInterval = params.getOrDefault<time::milliseconds::rep>("probing-interval",
49 m_probing.getProbingInterval().count());
50 m_probing.setProbingInterval(time::milliseconds(probingInterval));
51 m_nMaxTimeouts = params.getOrDefault<size_t>("max-timeouts", m_nMaxTimeouts);
awlaneee97f532024-09-19 15:48:21 -050052 auto measurementsLifetime = time::milliseconds(params.getOrDefault<time::milliseconds::rep>("measurements-lifetime",
53 AsfMeasurements::DEFAULT_MEASUREMENTS_LIFETIME.count()));
54 if (measurementsLifetime <= m_probing.getProbingInterval()) {
55 NDN_THROW(std::invalid_argument("Measurements lifetime (" + boost::lexical_cast<std::string>(measurementsLifetime) +
56 ") should be greater than the probing interval of " +
57 boost::lexical_cast<std::string>(m_probing.getProbingInterval())));
58 }
59 m_measurements.setMeasurementsLifetime(measurementsLifetime);
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040060
Junxiao Shi18739c42016-12-22 08:03:00 +000061 this->setInstanceName(makeInstanceName(name, getStrategyName()));
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050062
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040063 NDN_LOG_DEBUG(*m_retxSuppression);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040064 NFD_LOG_DEBUG("probing-interval=" << m_probing.getProbingInterval()
awlaneee97f532024-09-19 15:48:21 -050065 << " max-timeouts=" << m_nMaxTimeouts
66 << " measurements-lifetime=" << m_measurements.getMeasurementsLifetime());
Vince Lehman8a4c29e2016-07-11 08:49:35 +000067}
68
Junxiao Shi037f4ab2016-12-13 04:27:06 +000069const Name&
70AsfStrategy::getStrategyName()
71{
Davide Pesavento8e0dfcf2024-02-14 20:38:04 -050072 static const auto strategyName = Name("/localhost/nfd/strategy/asf").appendVersion(5);
Junxiao Shi037f4ab2016-12-13 04:27:06 +000073 return strategyName;
74}
75
Saurab Dulala6dec222019-04-01 00:15:10 -050076void
Davide Pesavento0498ce82021-06-14 02:02:21 -040077AsfStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000078 const shared_ptr<pit::Entry>& pitEntry)
Vince Lehman8a4c29e2016-07-11 08:49:35 +000079{
Saurab Dulal432be572021-01-26 12:09:29 -060080 const auto& fibEntry = this->lookupFib(*pitEntry);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000081
Saurab Dulal432be572021-01-26 12:09:29 -060082 // Check if the interest is new and, if so, skip the retx suppression check
83 if (!hasPendingOutRecords(*pitEntry)) {
awlane5fdcbec2023-12-15 14:56:05 -060084 auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry);
Saurab Dulal432be572021-01-26 12:09:29 -060085 if (faceToUse == nullptr) {
Alex Lane653eb072023-07-27 22:11:46 -040086 NFD_LOG_INTEREST_FROM(interest, ingress, "new no-nexthop");
Teng Liangebc20f62020-06-23 16:55:20 -070087 sendNoRouteNack(ingress.face, pitEntry);
Saurab Dulala6dec222019-04-01 00:15:10 -050088 }
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040089 else {
Alex Lane653eb072023-07-27 22:11:46 -040090 NFD_LOG_INTEREST_FROM(interest, ingress, "new forward-to=" << faceToUse->getId());
Saurab Dulal432be572021-01-26 12:09:29 -060091 forwardInterest(interest, *faceToUse, fibEntry, pitEntry);
92 sendProbe(interest, ingress, *faceToUse, fibEntry, pitEntry);
Saurab Dulala6dec222019-04-01 00:15:10 -050093 }
94 return;
95 }
96
awlane5fdcbec2023-12-15 14:56:05 -060097 auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false);
Saurab Dulala6dec222019-04-01 00:15:10 -050098 if (faceToUse != nullptr) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040099 auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, *faceToUse);
Saurab Dulal432be572021-01-26 12:09:29 -0600100 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
101 // Cannot be sent on this face, interest was received within the suppression window
Alex Lane653eb072023-07-27 22:11:46 -0400102 NFD_LOG_INTEREST_FROM(interest, ingress, "retx forward-to=" << faceToUse->getId() << " suppressed");
Saurab Dulal432be572021-01-26 12:09:29 -0600103 }
104 else {
105 // The retx arrived after the suppression period: forward it but don't probe, because
106 // probing was done earlier for this interest when it was newly received
Alex Lane653eb072023-07-27 22:11:46 -0400107 NFD_LOG_INTEREST_FROM(interest, ingress, "retx forward-to=" << faceToUse->getId());
Saurab Dulal432be572021-01-26 12:09:29 -0600108 auto* outRecord = forwardInterest(interest, *faceToUse, fibEntry, pitEntry);
109 if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400110 m_retxSuppression->incrementIntervalForOutRecord(*outRecord);
Saurab Dulal432be572021-01-26 12:09:29 -0600111 }
112 }
Saurab Dulala6dec222019-04-01 00:15:10 -0500113 return;
114 }
115
Saurab Dulal432be572021-01-26 12:09:29 -0600116 // If all eligible faces have been used (i.e., they all have a pending out-record),
117 // choose the nexthop with the earliest out-record
118 const auto& nexthops = fibEntry.getNextHops();
119 auto it = findEligibleNextHopWithEarliestOutRecord(ingress.face, interest, nexthops, pitEntry);
Saurab Dulala6dec222019-04-01 00:15:10 -0500120 if (it == nexthops.end()) {
Alex Lane653eb072023-07-27 22:11:46 -0400121 NFD_LOG_INTEREST_FROM(interest, ingress, "retx no-nexthop");
Saurab Dulal432be572021-01-26 12:09:29 -0600122 return;
123 }
124 auto& outFace = it->getFace();
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400125 auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace);
Saurab Dulal432be572021-01-26 12:09:29 -0600126 if (suppressResult == RetxSuppressionResult::SUPPRESS) {
Alex Lane653eb072023-07-27 22:11:46 -0400127 NFD_LOG_INTEREST_FROM(interest, ingress, "retx retry-to=" << outFace.getId() << " suppressed");
Saurab Dulala6dec222019-04-01 00:15:10 -0500128 }
129 else {
Alex Lane653eb072023-07-27 22:11:46 -0400130 NFD_LOG_INTEREST_FROM(interest, ingress, "retx retry-to=" << outFace.getId());
Saurab Dulal432be572021-01-26 12:09:29 -0600131 // sendInterest() is used here instead of forwardInterest() because the measurements info
132 // were already attached to this face in the previous forwarding
Davide Pesavento0498ce82021-06-14 02:02:21 -0400133 auto* outRecord = sendInterest(interest, outFace, pitEntry);
Saurab Dulal432be572021-01-26 12:09:29 -0600134 if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) {
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400135 m_retxSuppression->incrementIntervalForOutRecord(*outRecord);
Saurab Dulal432be572021-01-26 12:09:29 -0600136 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000137 }
138}
139
140void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400141AsfStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
142 const shared_ptr<pit::Entry>& pitEntry)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000143{
Junxiao Shifc021862016-08-25 21:51:18 +0000144 NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName());
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000145 if (namespaceInfo == nullptr) {
Alex Lane653eb072023-07-27 22:11:46 -0400146 NFD_LOG_DATA_FROM(data, ingress, "no-measurements");
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000147 return;
148 }
149
150 // Record the RTT between the Interest out to Data in
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400151 FaceInfo* faceInfo = namespaceInfo->getFaceInfo(ingress.face.getId());
Ashlesh Gawandecad76b62017-04-04 15:28:30 -0500152 if (faceInfo == nullptr) {
Alex Lane653eb072023-07-27 22:11:46 -0400153 NFD_LOG_DATA_FROM(data, ingress, "no-face-info");
Ashlesh Gawandecad76b62017-04-04 15:28:30 -0500154 return;
155 }
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400156
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500157 auto outRecord = pitEntry->findOutRecord(ingress.face);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400158 if (outRecord == pitEntry->out_end()) {
Alex Lane653eb072023-07-27 22:11:46 -0400159 NFD_LOG_DATA_FROM(data, ingress, "no-out-record");
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400160 }
161 else {
162 faceInfo->recordRtt(time::steady_clock::now() - outRecord->getLastRenewed());
Alex Lane653eb072023-07-27 22:11:46 -0400163 NFD_LOG_DATA_FROM(data, ingress, "rtt=" << faceInfo->getLastRtt() << " srtt=" << faceInfo->getSrtt());
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400164 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000165
166 // Extend lifetime for measurements associated with Face
ashiqopuc7079482019-02-20 05:34:37 +0000167 namespaceInfo->extendFaceInfoLifetime(*faceInfo, ingress.face.getId());
Alex Lane9cec6992020-03-05 19:10:09 -0600168 // Extend PIT entry timer to allow slower probes to arrive
169 this->setExpiryTimer(pitEntry, 50_ms);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400170 faceInfo->cancelTimeout(data.getName());
awlane5fdcbec2023-12-15 14:56:05 -0600171 faceInfo->setNTimeouts(0);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000172}
173
174void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400175AsfStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000176 const shared_ptr<pit::Entry>& pitEntry)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000177{
Alex Lane653eb072023-07-27 22:11:46 -0400178 NFD_LOG_NACK_FROM(nack, ingress, "");
Alex Lane9cec6992020-03-05 19:10:09 -0600179 onTimeoutOrNack(pitEntry->getName(), ingress.face.getId(), true);
awlane9acba9c2024-01-26 18:10:39 -0600180 this->processNack(nack, ingress.face, pitEntry);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000181}
182
Saurab Dulal432be572021-01-26 12:09:29 -0600183pit::OutRecord*
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400184AsfStrategy::forwardInterest(const Interest& interest, Face& outFace, const fib::Entry& fibEntry,
Saurab Dulal432be572021-01-26 12:09:29 -0600185 const shared_ptr<pit::Entry>& pitEntry)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000186{
Saurab Dulal432be572021-01-26 12:09:29 -0600187 const auto& interestName = interest.getName();
Teng Liangebc20f62020-06-23 16:55:20 -0700188 auto faceId = outFace.getId();
189
Davide Pesavento0498ce82021-06-14 02:02:21 -0400190 auto* outRecord = sendInterest(interest, outFace, pitEntry);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000191
Saurab Dulal432be572021-01-26 12:09:29 -0600192 FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interestName, faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000193
194 // Refresh measurements since Face is being used for forwarding
Saurab Dulal432be572021-01-26 12:09:29 -0600195 NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interestName);
Teng Liangebc20f62020-06-23 16:55:20 -0700196 namespaceInfo.extendFaceInfoLifetime(faceInfo, faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000197
198 if (!faceInfo.isTimeoutScheduled()) {
Saurab Dulal432be572021-01-26 12:09:29 -0600199 auto timeout = faceInfo.scheduleTimeout(interestName,
200 [this, name = interestName, faceId] {
201 onTimeoutOrNack(name, faceId, false);
202 });
Teng Liangebc20f62020-06-23 16:55:20 -0700203 NFD_LOG_TRACE("Scheduled timeout for " << fibEntry.getPrefix() << " to=" << faceId
Saurab Dulal432be572021-01-26 12:09:29 -0600204 << " in " << time::duration_cast<time::milliseconds>(timeout));
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000205 }
Saurab Dulal432be572021-01-26 12:09:29 -0600206
207 return outRecord;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000208}
209
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400210void
211AsfStrategy::sendProbe(const Interest& interest, const FaceEndpoint& ingress, const Face& faceToUse,
212 const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry)
213{
Saurab Dulal432be572021-01-26 12:09:29 -0600214 if (!m_probing.isProbingNeeded(fibEntry, interest.getName()))
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400215 return;
216
217 Face* faceToProbe = m_probing.getFaceToProbe(ingress.face, interest, fibEntry, faceToUse);
218 if (faceToProbe == nullptr)
219 return;
220
Saurab Dulal432be572021-01-26 12:09:29 -0600221 Interest probeInterest(interest);
222 probeInterest.refreshNonce();
Alex Lane653eb072023-07-27 22:11:46 -0400223 NFD_LOG_DEBUG("Sending probe " << probeInterest.getName() << " nonce=" << probeInterest.getNonce()
224 << " to=" << faceToProbe->getId() << " trigger-nonce=" << interest.getNonce());
Saurab Dulal432be572021-01-26 12:09:29 -0600225 forwardInterest(probeInterest, *faceToProbe, fibEntry, pitEntry);
226
227 m_probing.afterForwardingProbe(fibEntry, interest.getName());
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400228}
229
awlane5fdcbec2023-12-15 14:56:05 -0600230static auto
231getFaceRankForForwarding(const FaceStats& fs) noexcept
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000232{
awlane5fdcbec2023-12-15 14:56:05 -0600233 // The RTT is used to store the status of the face:
234 // - A positive value indicates data was received and is assumed to indicate a working face (group 1),
235 // - RTT_NO_MEASUREMENT indicates a face is unmeasured (group 2),
236 // - RTT_TIMEOUT indicates a face is timed out (group 3).
237 // These groups are defined in the technical report.
238 //
239 // When forwarding, we assume an order where working faces (group 1) are ranked
240 // higher than unmeasured faces (group 2), and unmeasured faces are ranked higher
241 // than timed out faces (group 3). We assign each group a priority value from 1-3
242 // to ensure lowest-to-highest ordering consistent with this logic.
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000243
awlane5fdcbec2023-12-15 14:56:05 -0600244 // Working faces are ranked first in priority; if RTT is not
245 // a special value, we assume the face to be in this group.
246 int priority = 1;
247 if (fs.rtt == FaceInfo::RTT_NO_MEASUREMENT) {
248 priority = 2;
249 }
250 else if (fs.rtt == FaceInfo::RTT_TIMEOUT) {
251 priority = 3;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000252 }
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400253
awlane5fdcbec2023-12-15 14:56:05 -0600254 // We set SRTT by default to the max value; if a face is working, we instead set it to the actual value.
255 // Unmeasured and timed out faces are not sorted by SRTT.
256 auto srtt = priority == 1 ? fs.srtt : time::nanoseconds::max();
257
258 // For ranking, group takes the priority over SRTT (if present) or cost, SRTT (if present)
259 // takes priority over cost, and cost takes priority over FaceId.
260 // FaceId is included to ensure all unique entries are included in the ranking (see #5310)
261 return std::tuple(priority, srtt, fs.cost, fs.face->getId());
262}
263
264bool
265AsfStrategy::FaceStatsForwardingCompare::operator()(const FaceStats& lhs, const FaceStats& rhs) const noexcept
266{
267 return getFaceRankForForwarding(lhs) < getFaceRankForForwarding(rhs);
268}
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000269
Junxiao Shia6de4292016-07-12 02:08:10 +0000270Face*
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400271AsfStrategy::getBestFaceForForwarding(const Interest& interest, const Face& inFace,
272 const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry,
Saurab Dulala6dec222019-04-01 00:15:10 -0500273 bool isInterestNew)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000274{
awlane5fdcbec2023-12-15 14:56:05 -0600275 FaceStatsForwardingSet rankedFaces;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000276
Saurab Dulala6dec222019-04-01 00:15:10 -0500277 auto now = time::steady_clock::now();
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400278 for (const auto& nh : fibEntry.getNextHops()) {
279 if (!isNextHopEligible(inFace, interest, nh, pitEntry, !isInterestNew, now)) {
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000280 continue;
281 }
282
Saurab Dulal432be572021-01-26 12:09:29 -0600283 const FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest.getName(), nh.getFace().getId());
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000284 if (info == nullptr) {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400285 rankedFaces.insert({&nh.getFace(), FaceInfo::RTT_NO_MEASUREMENT,
286 FaceInfo::RTT_NO_MEASUREMENT, nh.getCost()});
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000287 }
288 else {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400289 rankedFaces.insert({&nh.getFace(), info->getLastRtt(), info->getSrtt(), nh.getCost()});
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000290 }
291 }
292
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400293 auto it = rankedFaces.begin();
294 return it != rankedFaces.end() ? it->face : nullptr;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000295}
296
297void
Alex Lane9cec6992020-03-05 19:10:09 -0600298AsfStrategy::onTimeoutOrNack(const Name& interestName, FaceId faceId, bool isNack)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000299{
Junxiao Shifc021862016-08-25 21:51:18 +0000300 NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000301 if (namespaceInfo == nullptr) {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400302 NFD_LOG_TRACE(interestName << " FibEntry has been removed since timeout scheduling");
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000303 return;
304 }
305
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400306 FaceInfo* fiPtr = namespaceInfo->getFaceInfo(faceId);
307 if (fiPtr == nullptr) {
308 NFD_LOG_TRACE(interestName << " FaceInfo id=" << faceId << " has been removed since timeout scheduling");
309 return;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000310 }
311
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400312 auto& faceInfo = *fiPtr;
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -0400313 size_t nTimeouts = faceInfo.getNTimeouts() + 1;
314 faceInfo.setNTimeouts(nTimeouts);
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500315
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -0400316 if (nTimeouts < m_nMaxTimeouts && !isNack) {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400317 NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts << " ignoring");
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500318 // Extend lifetime for measurements associated with Face
319 namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400320 faceInfo.cancelTimeout(interestName);
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500321 }
322 else {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400323 NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts);
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500324 faceInfo.recordTimeout(interestName);
awlane5fdcbec2023-12-15 14:56:05 -0600325 faceInfo.setNTimeouts(0);
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500326 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000327}
328
329void
Teng Liangebc20f62020-06-23 16:55:20 -0700330AsfStrategy::sendNoRouteNack(Face& face, const shared_ptr<pit::Entry>& pitEntry)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000331{
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000332 lp::NackHeader nackHeader;
333 nackHeader.setReason(lp::NackReason::NO_ROUTE);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400334 this->sendNack(nackHeader, face, pitEntry);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400335 this->rejectPendingInterest(pitEntry);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000336}
337
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400338} // namespace nfd::fw::asf