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 | /* |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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/global.hpp" |
| 29 | #include "common/logger.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace fw { |
| 33 | namespace asf { |
| 34 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 35 | NFD_LOG_INIT(AsfStrategy); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 36 | NFD_REGISTER_STRATEGY(AsfStrategy); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 37 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 38 | const time::milliseconds AsfStrategy::RETX_SUPPRESSION_INITIAL(10); |
| 39 | const time::milliseconds AsfStrategy::RETX_SUPPRESSION_MAX(250); |
| 40 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 41 | AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 42 | : Strategy(forwarder) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 43 | , m_measurements(getMeasurements()) |
| 44 | , m_probing(m_measurements) |
| 45 | , m_retxSuppression(RETX_SUPPRESSION_INITIAL, |
| 46 | RetxSuppressionExponential::DEFAULT_MULTIPLIER, |
| 47 | RETX_SUPPRESSION_MAX) |
| 48 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 49 | ParsedInstanceName parsed = parseInstanceName(name); |
| 50 | if (!parsed.parameters.empty()) { |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 51 | processParams(parsed.parameters); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 52 | } |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 53 | |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 54 | if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 55 | NDN_THROW(std::invalid_argument( |
Alexander Afanasyev | 0c63c63 | 2017-12-05 11:17:09 -0500 | [diff] [blame] | 56 | "AsfStrategy does not support version " + to_string(*parsed.version))); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 57 | } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 58 | this->setInstanceName(makeInstanceName(name, getStrategyName())); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 59 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 60 | NFD_LOG_DEBUG("probing-interval=" << m_probing.getProbingInterval() |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame^] | 61 | << " max-timeouts=" << m_nMaxTimeouts); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 64 | const Name& |
| 65 | AsfStrategy::getStrategyName() |
| 66 | { |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 67 | static const auto strategyName = Name("/localhost/nfd/strategy/asf").appendVersion(4); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 68 | return strategyName; |
| 69 | } |
| 70 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 71 | static uint64_t |
| 72 | getParamValue(const std::string& param, const std::string& value) |
| 73 | { |
| 74 | try { |
| 75 | if (!value.empty() && value[0] == '-') |
| 76 | NDN_THROW(boost::bad_lexical_cast()); |
| 77 | |
| 78 | return boost::lexical_cast<uint64_t>(value); |
| 79 | } |
| 80 | catch (const boost::bad_lexical_cast&) { |
| 81 | NDN_THROW(std::invalid_argument("Value of " + param + " must be a non-negative integer")); |
| 82 | } |
| 83 | } |
| 84 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 85 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 86 | AsfStrategy::processParams(const PartialName& parsed) |
| 87 | { |
| 88 | for (const auto& component : parsed) { |
| 89 | std::string parsedStr(reinterpret_cast<const char*>(component.value()), component.value_size()); |
| 90 | auto n = parsedStr.find("~"); |
| 91 | if (n == std::string::npos) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 92 | NDN_THROW(std::invalid_argument("Format is <parameter>~<value>")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | auto f = parsedStr.substr(0, n); |
| 96 | auto s = parsedStr.substr(n + 1); |
| 97 | if (f == "probing-interval") { |
| 98 | m_probing.setProbingInterval(getParamValue(f, s)); |
| 99 | } |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame^] | 100 | else if (f == "max-timeouts") { |
| 101 | m_nMaxTimeouts = getParamValue(f, s); |
| 102 | if (m_nMaxTimeouts <= 0) |
| 103 | NDN_THROW(std::invalid_argument("max-timeouts should be greater than 0")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 104 | } |
| 105 | else { |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame^] | 106 | NDN_THROW(std::invalid_argument("Parameter should be probing-interval or max-timeouts")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 111 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 112 | AsfStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 113 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 114 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 115 | const auto& fibEntry = this->lookupFib(*pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 116 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 117 | // Check if the interest is new and, if so, skip the retx suppression check |
| 118 | if (!hasPendingOutRecords(*pitEntry)) { |
| 119 | auto* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry); |
| 120 | if (faceToUse == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 121 | NFD_LOG_DEBUG(interest << " new-interest from=" << ingress << " no-nexthop"); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 122 | sendNoRouteNack(ingress.face, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 123 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 124 | else { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 125 | NFD_LOG_DEBUG(interest << " new-interest from=" << ingress << " forward-to=" << faceToUse->getId()); |
| 126 | forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
| 127 | sendProbe(interest, ingress, *faceToUse, fibEntry, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 128 | } |
| 129 | return; |
| 130 | } |
| 131 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 132 | auto* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 133 | if (faceToUse != nullptr) { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 134 | auto suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, *faceToUse); |
| 135 | if (suppressResult == RetxSuppressionResult::SUPPRESS) { |
| 136 | // Cannot be sent on this face, interest was received within the suppression window |
| 137 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress |
| 138 | << " forward-to=" << faceToUse->getId() << " suppressed"); |
| 139 | } |
| 140 | else { |
| 141 | // The retx arrived after the suppression period: forward it but don't probe, because |
| 142 | // probing was done earlier for this interest when it was newly received |
| 143 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " forward-to=" << faceToUse->getId()); |
| 144 | auto* outRecord = forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
| 145 | if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) { |
| 146 | m_retxSuppression.incrementIntervalForOutRecord(*outRecord); |
| 147 | } |
| 148 | } |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 152 | // If all eligible faces have been used (i.e., they all have a pending out-record), |
| 153 | // choose the nexthop with the earliest out-record |
| 154 | const auto& nexthops = fibEntry.getNextHops(); |
| 155 | auto it = findEligibleNextHopWithEarliestOutRecord(ingress.face, interest, nexthops, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 156 | if (it == nexthops.end()) { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 157 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " no eligible nexthop"); |
| 158 | return; |
| 159 | } |
| 160 | auto& outFace = it->getFace(); |
| 161 | auto suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace); |
| 162 | if (suppressResult == RetxSuppressionResult::SUPPRESS) { |
| 163 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress |
| 164 | << " retry-to=" << outFace.getId() << " suppressed"); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 165 | } |
| 166 | else { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 167 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " retry-to=" << outFace.getId()); |
| 168 | // sendInterest() is used here instead of forwardInterest() because the measurements info |
| 169 | // were already attached to this face in the previous forwarding |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 170 | auto* outRecord = sendInterest(interest, outFace, pitEntry); |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 171 | if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) { |
| 172 | m_retxSuppression.incrementIntervalForOutRecord(*outRecord); |
| 173 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 178 | AsfStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 179 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 180 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 181 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 182 | if (namespaceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 183 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-measurements"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | |
| 187 | // Record the RTT between the Interest out to Data in |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 188 | FaceInfo* faceInfo = namespaceInfo->getFaceInfo(ingress.face.getId()); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 189 | if (faceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 190 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-face-info"); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 191 | return; |
| 192 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 193 | |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 194 | auto outRecord = pitEntry->getOutRecord(ingress.face); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 195 | if (outRecord == pitEntry->out_end()) { |
| 196 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-out-record"); |
| 197 | } |
| 198 | else { |
| 199 | faceInfo->recordRtt(time::steady_clock::now() - outRecord->getLastRenewed()); |
| 200 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress |
| 201 | << " rtt=" << faceInfo->getLastRtt() << " srtt=" << faceInfo->getSrtt()); |
| 202 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 203 | |
| 204 | // Extend lifetime for measurements associated with Face |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 205 | namespaceInfo->extendFaceInfoLifetime(*faceInfo, ingress.face.getId()); |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 206 | // Extend PIT entry timer to allow slower probes to arrive |
| 207 | this->setExpiryTimer(pitEntry, 50_ms); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 208 | faceInfo->cancelTimeout(data.getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 212 | AsfStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 213 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 214 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 215 | NFD_LOG_DEBUG(nack.getInterest() << " nack from=" << ingress << " reason=" << nack.getReason()); |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 216 | onTimeoutOrNack(pitEntry->getName(), ingress.face.getId(), true); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 219 | pit::OutRecord* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 220 | AsfStrategy::forwardInterest(const Interest& interest, Face& outFace, const fib::Entry& fibEntry, |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 221 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 222 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 223 | const auto& interestName = interest.getName(); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 224 | auto faceId = outFace.getId(); |
| 225 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 226 | auto* outRecord = sendInterest(interest, outFace, pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 227 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 228 | FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interestName, faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 229 | |
| 230 | // Refresh measurements since Face is being used for forwarding |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 231 | NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interestName); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 232 | namespaceInfo.extendFaceInfoLifetime(faceInfo, faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 233 | |
| 234 | if (!faceInfo.isTimeoutScheduled()) { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 235 | auto timeout = faceInfo.scheduleTimeout(interestName, |
| 236 | [this, name = interestName, faceId] { |
| 237 | onTimeoutOrNack(name, faceId, false); |
| 238 | }); |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 239 | NFD_LOG_TRACE("Scheduled timeout for " << fibEntry.getPrefix() << " to=" << faceId |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 240 | << " in " << time::duration_cast<time::milliseconds>(timeout)); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 241 | } |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 242 | |
| 243 | return outRecord; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 246 | void |
| 247 | AsfStrategy::sendProbe(const Interest& interest, const FaceEndpoint& ingress, const Face& faceToUse, |
| 248 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry) |
| 249 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 250 | if (!m_probing.isProbingNeeded(fibEntry, interest.getName())) |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 251 | return; |
| 252 | |
| 253 | Face* faceToProbe = m_probing.getFaceToProbe(ingress.face, interest, fibEntry, faceToUse); |
| 254 | if (faceToProbe == nullptr) |
| 255 | return; |
| 256 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 257 | Interest probeInterest(interest); |
| 258 | probeInterest.refreshNonce(); |
| 259 | NFD_LOG_TRACE("Sending probe " << probeInterest << " to=" << faceToProbe->getId()); |
| 260 | forwardInterest(probeInterest, *faceToProbe, fibEntry, pitEntry); |
| 261 | |
| 262 | m_probing.afterForwardingProbe(fibEntry, interest.getName()); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 265 | struct FaceStats |
| 266 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 267 | Face* face; |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 268 | time::nanoseconds rtt; |
| 269 | time::nanoseconds srtt; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 270 | uint64_t cost; |
| 271 | }; |
| 272 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 273 | struct FaceStatsCompare |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 274 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 275 | bool |
| 276 | operator()(const FaceStats& lhs, const FaceStats& rhs) const |
| 277 | { |
| 278 | time::nanoseconds lhsValue = getValueForSorting(lhs); |
| 279 | time::nanoseconds rhsValue = getValueForSorting(rhs); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 280 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 281 | // Sort by RTT and then by cost |
| 282 | return std::tie(lhsValue, lhs.cost) < std::tie(rhsValue, rhs.cost); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 283 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 284 | |
| 285 | private: |
| 286 | static time::nanoseconds |
| 287 | getValueForSorting(const FaceStats& stats) |
| 288 | { |
| 289 | // These values allow faces with no measurements to be ranked better than timeouts |
| 290 | // srtt < RTT_NO_MEASUREMENT < RTT_TIMEOUT |
| 291 | if (stats.rtt == FaceInfo::RTT_TIMEOUT) { |
| 292 | return time::nanoseconds::max(); |
| 293 | } |
| 294 | else if (stats.rtt == FaceInfo::RTT_NO_MEASUREMENT) { |
| 295 | return time::nanoseconds::max() / 2; |
| 296 | } |
| 297 | else { |
| 298 | return stats.srtt; |
| 299 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 300 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 301 | }; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 302 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 303 | Face* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 304 | AsfStrategy::getBestFaceForForwarding(const Interest& interest, const Face& inFace, |
| 305 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry, |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 306 | bool isInterestNew) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 307 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 308 | std::set<FaceStats, FaceStatsCompare> rankedFaces; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 309 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 310 | auto now = time::steady_clock::now(); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 311 | for (const auto& nh : fibEntry.getNextHops()) { |
| 312 | if (!isNextHopEligible(inFace, interest, nh, pitEntry, !isInterestNew, now)) { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 313 | continue; |
| 314 | } |
| 315 | |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 316 | const FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest.getName(), nh.getFace().getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 317 | if (info == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 318 | rankedFaces.insert({&nh.getFace(), FaceInfo::RTT_NO_MEASUREMENT, |
| 319 | FaceInfo::RTT_NO_MEASUREMENT, nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 320 | } |
| 321 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 322 | rankedFaces.insert({&nh.getFace(), info->getLastRtt(), info->getSrtt(), nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 326 | auto it = rankedFaces.begin(); |
| 327 | return it != rankedFaces.end() ? it->face : nullptr; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void |
Alex Lane | 9cec699 | 2020-03-05 19:10:09 -0600 | [diff] [blame] | 331 | AsfStrategy::onTimeoutOrNack(const Name& interestName, FaceId faceId, bool isNack) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 332 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 333 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 334 | if (namespaceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 335 | NFD_LOG_TRACE(interestName << " FibEntry has been removed since timeout scheduling"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 339 | FaceInfo* fiPtr = namespaceInfo->getFaceInfo(faceId); |
| 340 | if (fiPtr == nullptr) { |
| 341 | NFD_LOG_TRACE(interestName << " FaceInfo id=" << faceId << " has been removed since timeout scheduling"); |
| 342 | return; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 345 | auto& faceInfo = *fiPtr; |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame^] | 346 | size_t nTimeouts = faceInfo.getNTimeouts() + 1; |
| 347 | faceInfo.setNTimeouts(nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 348 | |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame^] | 349 | if (nTimeouts < m_nMaxTimeouts && !isNack) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 350 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts << " ignoring"); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 351 | // Extend lifetime for measurements associated with Face |
| 352 | namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 353 | faceInfo.cancelTimeout(interestName); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 354 | } |
| 355 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 356 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 357 | faceInfo.recordTimeout(interestName); |
| 358 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 362 | AsfStrategy::sendNoRouteNack(Face& face, const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 363 | { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 364 | lp::NackHeader nackHeader; |
| 365 | nackHeader.setReason(lp::NackReason::NO_ROUTE); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 366 | this->sendNack(nackHeader, face, pitEntry); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 367 | this->rejectPendingInterest(pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | } // namespace asf |
| 371 | } // namespace fw |
| 372 | } // namespace nfd |