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 | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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() |
| 61 | << " n-silent-timeouts=" << m_maxSilentTimeouts); |
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 | { |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 67 | static Name strategyName("/localhost/nfd/strategy/asf/%FD%03"); |
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 | } |
| 100 | else if (f == "n-silent-timeouts") { |
| 101 | m_maxSilentTimeouts = getParamValue(f, s); |
| 102 | } |
| 103 | else { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 104 | NDN_THROW(std::invalid_argument("Parameter should be probing-interval or n-silent-timeouts")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 109 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 110 | AsfStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 111 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 112 | { |
| 113 | // Should the Interest be suppressed? |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 114 | auto suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 115 | if (suppressResult == RetxSuppressionResult::SUPPRESS) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 116 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " suppressed"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 120 | const fib::Entry& fibEntry = this->lookupFib(*pitEntry); |
| 121 | const fib::NextHopList& nexthops = fibEntry.getNextHops(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 122 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 123 | if (suppressResult == RetxSuppressionResult::NEW) { |
| 124 | if (nexthops.size() == 0) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 125 | NFD_LOG_DEBUG(interest << " new-interest from=" << ingress << " no-nexthop"); |
| 126 | sendNoRouteNack(ingress, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 127 | return; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 128 | } |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 129 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 130 | Face* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry); |
| 131 | if (faceToUse != nullptr) { |
| 132 | NFD_LOG_DEBUG(interest << " new-interest from=" << ingress << " forward-to=" << faceToUse->getId()); |
| 133 | forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 134 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 135 | // If necessary, send probe |
| 136 | sendProbe(interest, ingress, *faceToUse, fibEntry, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 137 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 138 | else { |
| 139 | NFD_LOG_DEBUG(interest << " new-interest from=" << ingress << " no-nexthop"); |
| 140 | sendNoRouteNack(ingress, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 141 | } |
| 142 | return; |
| 143 | } |
| 144 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 145 | Face* faceToUse = getBestFaceForForwarding(interest, ingress.face, fibEntry, pitEntry, false); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 146 | // if unused face not found, select nexthop with earliest out record |
| 147 | if (faceToUse != nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 148 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " forward-to=" << faceToUse->getId()); |
| 149 | forwardInterest(interest, *faceToUse, fibEntry, pitEntry); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 150 | // avoid probing in case of forwarding |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // find an eligible upstream that is used earliest |
| 155 | auto it = nexthops.end(); |
| 156 | it = findEligibleNextHopWithEarliestOutRecord(ingress.face, interest, nexthops, pitEntry); |
| 157 | if (it == nexthops.end()) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 158 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " no-nexthop"); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 159 | } |
| 160 | else { |
| 161 | auto egress = FaceEndpoint(it->getFace(), 0); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 162 | NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " retry-to=" << egress); |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 163 | this->sendInterest(pitEntry, egress, interest); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 168 | AsfStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 169 | const FaceEndpoint& ingress, const Data& data) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 170 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 171 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 172 | if (namespaceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 173 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-measurements"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | |
| 177 | // Record the RTT between the Interest out to Data in |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 178 | FaceInfo* faceInfo = namespaceInfo->getFaceInfo(ingress.face.getId()); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 179 | if (faceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 180 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-face-info"); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 181 | return; |
| 182 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 183 | |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame^] | 184 | auto outRecord = pitEntry->getOutRecord(ingress.face); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 185 | if (outRecord == pitEntry->out_end()) { |
| 186 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress << " no-out-record"); |
| 187 | } |
| 188 | else { |
| 189 | faceInfo->recordRtt(time::steady_clock::now() - outRecord->getLastRenewed()); |
| 190 | NFD_LOG_DEBUG(pitEntry->getName() << " data from=" << ingress |
| 191 | << " rtt=" << faceInfo->getLastRtt() << " srtt=" << faceInfo->getSrtt()); |
| 192 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 193 | |
| 194 | // Extend lifetime for measurements associated with Face |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 195 | namespaceInfo->extendFaceInfoLifetime(*faceInfo, ingress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 196 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 197 | faceInfo->cancelTimeout(data.getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 201 | AsfStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 202 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 203 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 204 | NFD_LOG_DEBUG(nack.getInterest() << " nack from=" << ingress << " reason=" << nack.getReason()); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 205 | onTimeout(pitEntry->getName(), ingress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 208 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 209 | AsfStrategy::forwardInterest(const Interest& interest, Face& outFace, const fib::Entry& fibEntry, |
| 210 | const shared_ptr<pit::Entry>& pitEntry, bool wantNewNonce) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 211 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 212 | auto egress = FaceEndpoint(outFace, 0); |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 213 | if (wantNewNonce) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 214 | // Send probe: interest with new Nonce |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 215 | Interest probeInterest(interest); |
| 216 | probeInterest.refreshNonce(); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 217 | NFD_LOG_TRACE("Sending probe for " << probeInterest << " to=" << egress); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 218 | this->sendInterest(pitEntry, egress, probeInterest); |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 219 | } |
| 220 | else { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 221 | this->sendInterest(pitEntry, egress, interest); |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 222 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 223 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 224 | FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interest, egress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 225 | |
| 226 | // Refresh measurements since Face is being used for forwarding |
| 227 | NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interest); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 228 | namespaceInfo.extendFaceInfoLifetime(faceInfo, egress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 229 | |
| 230 | if (!faceInfo.isTimeoutScheduled()) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 231 | auto timeout = faceInfo.scheduleTimeout(interest.getName(), |
| 232 | [this, name = interest.getName(), faceId = egress.face.getId()] { |
| 233 | onTimeout(name, faceId); |
| 234 | }); |
| 235 | NFD_LOG_TRACE("Scheduled timeout for " << fibEntry.getPrefix() << " to=" << egress |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 236 | << " in " << time::duration_cast<time::milliseconds>(timeout) << " ms"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 240 | void |
| 241 | AsfStrategy::sendProbe(const Interest& interest, const FaceEndpoint& ingress, const Face& faceToUse, |
| 242 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry) |
| 243 | { |
| 244 | if (!m_probing.isProbingNeeded(fibEntry, interest)) |
| 245 | return; |
| 246 | |
| 247 | Face* faceToProbe = m_probing.getFaceToProbe(ingress.face, interest, fibEntry, faceToUse); |
| 248 | if (faceToProbe == nullptr) |
| 249 | return; |
| 250 | |
| 251 | forwardInterest(interest, *faceToProbe, fibEntry, pitEntry, true); |
| 252 | m_probing.afterForwardingProbe(fibEntry, interest); |
| 253 | } |
| 254 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 255 | struct FaceStats |
| 256 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 257 | Face* face; |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 258 | time::nanoseconds rtt; |
| 259 | time::nanoseconds srtt; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 260 | uint64_t cost; |
| 261 | }; |
| 262 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 263 | struct FaceStatsCompare |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 264 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 265 | bool |
| 266 | operator()(const FaceStats& lhs, const FaceStats& rhs) const |
| 267 | { |
| 268 | time::nanoseconds lhsValue = getValueForSorting(lhs); |
| 269 | time::nanoseconds rhsValue = getValueForSorting(rhs); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 270 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 271 | // Sort by RTT and then by cost |
| 272 | return std::tie(lhsValue, lhs.cost) < std::tie(rhsValue, rhs.cost); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 273 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 274 | |
| 275 | private: |
| 276 | static time::nanoseconds |
| 277 | getValueForSorting(const FaceStats& stats) |
| 278 | { |
| 279 | // These values allow faces with no measurements to be ranked better than timeouts |
| 280 | // srtt < RTT_NO_MEASUREMENT < RTT_TIMEOUT |
| 281 | if (stats.rtt == FaceInfo::RTT_TIMEOUT) { |
| 282 | return time::nanoseconds::max(); |
| 283 | } |
| 284 | else if (stats.rtt == FaceInfo::RTT_NO_MEASUREMENT) { |
| 285 | return time::nanoseconds::max() / 2; |
| 286 | } |
| 287 | else { |
| 288 | return stats.srtt; |
| 289 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 290 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 291 | }; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 292 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 293 | Face* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 294 | AsfStrategy::getBestFaceForForwarding(const Interest& interest, const Face& inFace, |
| 295 | const fib::Entry& fibEntry, const shared_ptr<pit::Entry>& pitEntry, |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 296 | bool isInterestNew) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 297 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 298 | std::set<FaceStats, FaceStatsCompare> rankedFaces; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 299 | |
Saurab Dulal | a6dec22 | 2019-04-01 00:15:10 -0500 | [diff] [blame] | 300 | auto now = time::steady_clock::now(); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 301 | for (const auto& nh : fibEntry.getNextHops()) { |
| 302 | if (!isNextHopEligible(inFace, interest, nh, pitEntry, !isInterestNew, now)) { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 303 | continue; |
| 304 | } |
| 305 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 306 | FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, nh.getFace().getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 307 | if (info == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 308 | rankedFaces.insert({&nh.getFace(), FaceInfo::RTT_NO_MEASUREMENT, |
| 309 | FaceInfo::RTT_NO_MEASUREMENT, nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 310 | } |
| 311 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 312 | rankedFaces.insert({&nh.getFace(), info->getLastRtt(), info->getSrtt(), nh.getCost()}); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 316 | auto it = rankedFaces.begin(); |
| 317 | return it != rankedFaces.end() ? it->face : nullptr; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 321 | AsfStrategy::onTimeout(const Name& interestName, FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 322 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 323 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 324 | if (namespaceInfo == nullptr) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 325 | NFD_LOG_TRACE(interestName << " FibEntry has been removed since timeout scheduling"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 326 | return; |
| 327 | } |
| 328 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 329 | FaceInfo* fiPtr = namespaceInfo->getFaceInfo(faceId); |
| 330 | if (fiPtr == nullptr) { |
| 331 | NFD_LOG_TRACE(interestName << " FaceInfo id=" << faceId << " has been removed since timeout scheduling"); |
| 332 | return; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 335 | auto& faceInfo = *fiPtr; |
| 336 | size_t nTimeouts = faceInfo.getNSilentTimeouts() + 1; |
| 337 | faceInfo.setNSilentTimeouts(nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 338 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 339 | if (nTimeouts <= m_maxSilentTimeouts) { |
| 340 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts << " ignoring"); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 341 | // Extend lifetime for measurements associated with Face |
| 342 | namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 343 | faceInfo.cancelTimeout(interestName); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 344 | } |
| 345 | else { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 346 | NFD_LOG_TRACE(interestName << " face=" << faceId << " timeout-count=" << nTimeouts); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 347 | faceInfo.recordTimeout(interestName); |
| 348 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 352 | AsfStrategy::sendNoRouteNack(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 353 | { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 354 | lp::NackHeader nackHeader; |
| 355 | nackHeader.setReason(lp::NackReason::NO_ROUTE); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 356 | this->sendNack(pitEntry, ingress, nackHeader); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 357 | this->rejectPendingInterest(pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | } // namespace asf |
| 361 | } // namespace fw |
| 362 | } // namespace nfd |