Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 4 | * 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 Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 27 | #include "algorithm.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 28 | #include "common/logger.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 29 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 30 | namespace nfd::fw::asf { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 31 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 32 | NFD_LOG_INIT(AsfStrategy); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 33 | NFD_REGISTER_STRATEGY(AsfStrategy); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 34 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 35 | AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 36 | : Strategy(forwarder) |
awlane | 9acba9c | 2024-01-26 18:10:39 -0600 | [diff] [blame] | 37 | , ProcessNackTraits(this) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 38 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 39 | ParsedInstanceName parsed = parseInstanceName(name); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 40 | if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) { |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 41 | NDN_THROW(std::invalid_argument("AsfStrategy does not support version " + |
| 42 | std::to_string(*parsed.version))); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 43 | } |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 44 | |
| 45 | StrategyParameters params = parseParameters(parsed.parameters); |
| 46 | m_retxSuppression = RetxSuppressionExponential::construct(params); |
| 47 | auto probingInterval = params.getOrDefault<time::milliseconds::rep>("probing-interval", |
| 48 | m_probing.getProbingInterval().count()); |
| 49 | m_probing.setProbingInterval(time::milliseconds(probingInterval)); |
| 50 | m_nMaxTimeouts = params.getOrDefault<size_t>("max-timeouts", m_nMaxTimeouts); |
| 51 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 52 | this->setInstanceName(makeInstanceName(name, getStrategyName())); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 53 | |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 54 | NDN_LOG_DEBUG(*m_retxSuppression); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 55 | NFD_LOG_DEBUG("probing-interval=" << m_probing.getProbingInterval() |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 56 | << " max-timeouts=" << m_nMaxTimeouts); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 59 | const Name& |
| 60 | AsfStrategy::getStrategyName() |
| 61 | { |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 62 | static const auto strategyName = Name("/localhost/nfd/strategy/asf").appendVersion(4); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 63 | return strategyName; |
| 64 | } |
| 65 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 66 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 67 | AsfStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 68 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 69 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 70 | const auto& fibEntry = this->lookupFib(*pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 71 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 72 | // Check if the interest is new and, if so, skip the retx suppression check |
| 73 | if (!hasPendingOutRecords(*pitEntry)) { |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 74 | auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 75 | if (faceToUse == nullptr) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 76 | NFD_LOG_INTEREST_FROM(interest, ingress, "new no-nexthop"); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 77 | sendNoRouteNack(ingress.face, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 78 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 79 | else { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 80 | NFD_LOG_INTEREST_FROM(interest, ingress, "new forward-to=" << faceToUse->getId()); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 81 | forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
| 82 | sendProbe(interest, ingress, *faceToUse, fibEntry, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 83 | } |
| 84 | return; |
| 85 | } |
| 86 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 87 | auto faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 88 | if (faceToUse != nullptr) { |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 89 | auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, *faceToUse); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 90 | if (suppressResult == RetxSuppressionResult::SUPPRESS) { |
| 91 | // Cannot be sent on this face, interest was received within the suppression window |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 92 | NFD_LOG_INTEREST_FROM(interest, ingress, "retx forward-to=" << faceToUse->getId() << " suppressed"); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 93 | } |
| 94 | else { |
| 95 | // The retx arrived after the suppression period: forward it but don't probe, because |
| 96 | // probing was done earlier for this interest when it was newly received |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 97 | NFD_LOG_INTEREST_FROM(interest, ingress, "retx forward-to=" << faceToUse->getId()); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 98 | auto* outRecord = forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
| 99 | if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) { |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 100 | m_retxSuppression->incrementIntervalForOutRecord(*outRecord); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 101 | } |
| 102 | } |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 103 | return; |
| 104 | } |
| 105 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 106 | // If all eligible faces have been used (i.e., they all have a pending out-record), |
| 107 | // choose the nexthop with the earliest out-record |
| 108 | const auto& nexthops = fibEntry.getNextHops(); |
| 109 | auto it = findEligibleNextHopWithEarliestOutRecord(ingress.face, interest, nexthops, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 110 | if (it == nexthops.end()) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 111 | NFD_LOG_INTEREST_FROM(interest, ingress, "retx no-nexthop"); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | auto& outFace = it->getFace(); |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 115 | auto suppressResult = m_retxSuppression->decidePerUpstream(*pitEntry, outFace); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 116 | if (suppressResult == RetxSuppressionResult::SUPPRESS) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 117 | NFD_LOG_INTEREST_FROM(interest, ingress, "retx retry-to=" << outFace.getId() << " suppressed"); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 118 | } |
| 119 | else { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 120 | NFD_LOG_INTEREST_FROM(interest, ingress, "retx retry-to=" << outFace.getId()); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 121 | // sendInterest() is used here instead of forwardInterest() because the measurements info |
| 122 | // were already attached to this face in the previous forwarding |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 123 | auto* outRecord = sendInterest(interest, outFace, pitEntry); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 124 | if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) { |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 125 | m_retxSuppression->incrementIntervalForOutRecord(*outRecord); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 126 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 131 | AsfStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 132 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 133 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 134 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 135 | if (namespaceInfo == nullptr) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 136 | NFD_LOG_DATA_FROM(data, ingress, "no-measurements"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
| 140 | // Record the RTT between the Interest out to Data in |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 141 | FaceInfo* faceInfo = namespaceInfo->getFaceInfo(ingress.face.getId()); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 142 | if (faceInfo == nullptr) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 143 | NFD_LOG_DATA_FROM(data, ingress, "no-face-info"); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 144 | return; |
| 145 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 146 | |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 147 | auto outRecord = pitEntry->getOutRecord(ingress.face); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 148 | if (outRecord == pitEntry->out_end()) { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 149 | NFD_LOG_DATA_FROM(data, ingress, "no-out-record"); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 150 | } |
| 151 | else { |
| 152 | faceInfo->recordRtt(time::steady_clock::now() - outRecord->getLastRenewed()); |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 153 | NFD_LOG_DATA_FROM(data, ingress, "rtt=" << faceInfo->getLastRtt() << " srtt=" << faceInfo->getSrtt()); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 154 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 155 | |
| 156 | // Extend lifetime for measurements associated with Face |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 157 | namespaceInfo->extendFaceInfoLifetime(*faceInfo, ingress.face.getId()); |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 158 | // Extend PIT entry timer to allow slower probes to arrive |
| 159 | this->setExpiryTimer(pitEntry, 50_ms); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 160 | faceInfo->cancelTimeout(data.getName()); |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 161 | faceInfo->setNTimeouts(0); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 165 | AsfStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 166 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 167 | { |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 168 | NFD_LOG_NACK_FROM(nack, ingress, ""); |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 169 | onTimeoutOrNack(pitEntry->getName(), ingress.face.getId(), true); |
awlane | 9acba9c | 2024-01-26 18:10:39 -0600 | [diff] [blame] | 170 | this->processNack(nack, ingress.face, pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 173 | pit::OutRecord* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 174 | AsfStrategy::forwardInterest(const Interest& interest, Face& outFace, const fib::Entry& fibEntry, |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 175 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 176 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 177 | const auto& interestName = interest.getName(); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 178 | auto faceId = outFace.getId(); |
| 179 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 180 | auto* outRecord = sendInterest(interest, outFace, pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 181 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 182 | FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interestName, faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 183 | |
| 184 | // Refresh measurements since Face is being used for forwarding |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 185 | NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interestName); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 186 | namespaceInfo.extendFaceInfoLifetime(faceInfo, faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 187 | |
| 188 | if (!faceInfo.isTimeoutScheduled()) { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 189 | auto timeout = faceInfo.scheduleTimeout(interestName, |
| 190 | [this, name = interestName, faceId] { |
| 191 | onTimeoutOrNack(name, faceId, false); |
| 192 | }); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 193 | NFD_LOG_TRACE("Scheduled timeout for " << fibEntry.getPrefix() << " to=" << faceId |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 194 | << " in " << time::duration_cast<time::milliseconds>(timeout)); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 195 | } |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 196 | |
| 197 | return outRecord; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 200 | void |
| 201 | AsfStrategy::sendProbe(const Interest& interest, const FaceEndpoint& ingress, const Face& faceToUse, |
| 202 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry) |
| 203 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 204 | if (!m_probing.isProbingNeeded(fibEntry, interest.getName())) |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 205 | return; |
| 206 | |
| 207 | Face* faceToProbe = m_probing.getFaceToProbe(ingress.face, interest, fibEntry, faceToUse); |
| 208 | if (faceToProbe == nullptr) |
| 209 | return; |
| 210 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 211 | Interest probeInterest(interest); |
| 212 | probeInterest.refreshNonce(); |
Alex Lane | 653eb07 | 2023-07-27 22:11:46 -0400 | [diff] [blame] | 213 | NFD_LOG_DEBUG("Sending probe " << probeInterest.getName() << " nonce=" << probeInterest.getNonce() |
| 214 | << " to=" << faceToProbe->getId() << " trigger-nonce=" << interest.getNonce()); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 215 | forwardInterest(probeInterest, *faceToProbe, fibEntry, pitEntry); |
| 216 | |
| 217 | m_probing.afterForwardingProbe(fibEntry, interest.getName()); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 218 | } |
| 219 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 220 | static auto |
| 221 | getFaceRankForForwarding(const FaceStats& fs) noexcept |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 222 | { |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 223 | // The RTT is used to store the status of the face: |
| 224 | // - A positive value indicates data was received and is assumed to indicate a working face (group 1), |
| 225 | // - RTT_NO_MEASUREMENT indicates a face is unmeasured (group 2), |
| 226 | // - RTT_TIMEOUT indicates a face is timed out (group 3). |
| 227 | // These groups are defined in the technical report. |
| 228 | // |
| 229 | // When forwarding, we assume an order where working faces (group 1) are ranked |
| 230 | // higher than unmeasured faces (group 2), and unmeasured faces are ranked higher |
| 231 | // than timed out faces (group 3). We assign each group a priority value from 1-3 |
| 232 | // to ensure lowest-to-highest ordering consistent with this logic. |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 233 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 234 | // Working faces are ranked first in priority; if RTT is not |
| 235 | // a special value, we assume the face to be in this group. |
| 236 | int priority = 1; |
| 237 | if (fs.rtt == FaceInfo::RTT_NO_MEASUREMENT) { |
| 238 | priority = 2; |
| 239 | } |
| 240 | else if (fs.rtt == FaceInfo::RTT_TIMEOUT) { |
| 241 | priority = 3; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 242 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 243 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 244 | // We set SRTT by default to the max value; if a face is working, we instead set it to the actual value. |
| 245 | // Unmeasured and timed out faces are not sorted by SRTT. |
| 246 | auto srtt = priority == 1 ? fs.srtt : time::nanoseconds::max(); |
| 247 | |
| 248 | // For ranking, group takes the priority over SRTT (if present) or cost, SRTT (if present) |
| 249 | // takes priority over cost, and cost takes priority over FaceId. |
| 250 | // FaceId is included to ensure all unique entries are included in the ranking (see #5310) |
| 251 | return std::tuple(priority, srtt, fs.cost, fs.face->getId()); |
| 252 | } |
| 253 | |
| 254 | bool |
| 255 | AsfStrategy::FaceStatsForwardingCompare::operator()(const FaceStats& lhs, const FaceStats& rhs) const noexcept |
| 256 | { |
| 257 | return getFaceRankForForwarding(lhs) < getFaceRankForForwarding(rhs); |
| 258 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 259 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 260 | Face* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 261 | AsfStrategy::getBestFaceForForwarding(const Interest& interest, const Face& inFace, |
| 262 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry, |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 263 | bool isInterestNew) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 264 | { |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 265 | FaceStatsForwardingSet rankedFaces; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 266 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 267 | auto now = time::steady_clock::now(); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 268 | for (const auto& nh : fibEntry.getNextHops()) { |
| 269 | if (!isNextHopEligible(inFace, interest, nh, pitEntry, !isInterestNew, now)) { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 270 | continue; |
| 271 | } |
| 272 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 273 | const FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest.getName(), nh.getFace().getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 274 | if (info == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 275 | rankedFaces.insert({&nh.getFace(), FaceInfo::RTT_NO_MEASUREMENT, |
| 276 | FaceInfo::RTT_NO_MEASUREMENT, nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 277 | } |
| 278 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 279 | rankedFaces.insert({&nh.getFace(), info->getLastRtt(), info->getSrtt(), nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 283 | auto it = rankedFaces.begin(); |
| 284 | return it != rankedFaces.end() ? it->face : nullptr; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 288 | AsfStrategy::onTimeoutOrNack(const Name& interestName, FaceId faceId, bool isNack) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 289 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 290 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 291 | if (namespaceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 292 | NFD_LOG_TRACE(interestName << " FibEntry has been removed since timeout scheduling"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 293 | return; |
| 294 | } |
| 295 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 296 | FaceInfo* fiPtr = namespaceInfo->getFaceInfo(faceId); |
| 297 | if (fiPtr == nullptr) { |
| 298 | NFD_LOG_TRACE(interestName << " FaceInfo id=" << faceId << " has been removed since timeout scheduling"); |
| 299 | return; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 302 | auto& faceInfo = *fiPtr; |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 303 | size_t nTimeouts = faceInfo.getNTimeouts() + 1; |
| 304 | faceInfo.setNTimeouts(nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 305 | |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 306 | if (nTimeouts < m_nMaxTimeouts && !isNack) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 307 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts << " ignoring"); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 308 | // Extend lifetime for measurements associated with Face |
| 309 | namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 310 | faceInfo.cancelTimeout(interestName); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 311 | } |
| 312 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 313 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 314 | faceInfo.recordTimeout(interestName); |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame^] | 315 | faceInfo.setNTimeouts(0); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 316 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 320 | AsfStrategy::sendNoRouteNack(Face& face, const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 321 | { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 322 | lp::NackHeader nackHeader; |
| 323 | nackHeader.setReason(lp::NackReason::NO_ROUTE); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 324 | this->sendNack(nackHeader, face, pitEntry); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 325 | this->rejectPendingInterest(pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 328 | } // namespace nfd::fw::asf |