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" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 28 | #include "core/logger.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace fw { |
| 32 | namespace asf { |
| 33 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 34 | NFD_LOG_INIT(AsfStrategy); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 35 | NFD_REGISTER_STRATEGY(AsfStrategy); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 36 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 37 | const time::milliseconds AsfStrategy::RETX_SUPPRESSION_INITIAL(10); |
| 38 | const time::milliseconds AsfStrategy::RETX_SUPPRESSION_MAX(250); |
| 39 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 40 | AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 41 | : Strategy(forwarder) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 42 | , m_measurements(getMeasurements()) |
| 43 | , m_probing(m_measurements) |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 44 | , m_maxSilentTimeouts(0) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 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 | |
| 60 | NFD_LOG_DEBUG("Probing interval=" << m_probing.getProbingInterval() |
| 61 | << ", Num 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 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 71 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 72 | AsfStrategy::processParams(const PartialName& parsed) |
| 73 | { |
| 74 | for (const auto& component : parsed) { |
| 75 | std::string parsedStr(reinterpret_cast<const char*>(component.value()), component.value_size()); |
| 76 | auto n = parsedStr.find("~"); |
| 77 | if (n == std::string::npos) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 78 | NDN_THROW(std::invalid_argument("Format is <parameter>~<value>")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | auto f = parsedStr.substr(0, n); |
| 82 | auto s = parsedStr.substr(n + 1); |
| 83 | if (f == "probing-interval") { |
| 84 | m_probing.setProbingInterval(getParamValue(f, s)); |
| 85 | } |
| 86 | else if (f == "n-silent-timeouts") { |
| 87 | m_maxSilentTimeouts = getParamValue(f, s); |
| 88 | } |
| 89 | else { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 90 | 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] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | uint64_t |
| 96 | AsfStrategy::getParamValue(const std::string& param, const std::string& value) |
| 97 | { |
| 98 | try { |
| 99 | if (!value.empty() && value[0] == '-') |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 100 | NDN_THROW(boost::bad_lexical_cast()); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 101 | |
| 102 | return boost::lexical_cast<uint64_t>(value); |
| 103 | } |
| 104 | catch (const boost::bad_lexical_cast&) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 105 | NDN_THROW(std::invalid_argument("Value of " + param + " must be a non-negative integer")); |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 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? |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 114 | RetxSuppressionResult suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 115 | |
| 116 | switch (suppressResult) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 117 | case RetxSuppressionResult::NEW: |
| 118 | case RetxSuppressionResult::FORWARD: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 119 | break; |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 120 | case RetxSuppressionResult::SUPPRESS: |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 121 | NFD_LOG_DEBUG(interest << " from=" << ingress << " suppressed"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 125 | const fib::Entry& fibEntry = this->lookupFib(*pitEntry); |
| 126 | const fib::NextHopList& nexthops = fibEntry.getNextHops(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 127 | |
| 128 | if (nexthops.size() == 0) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 129 | sendNoRouteNack(ingress, interest, pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 130 | this->rejectPendingInterest(pitEntry); |
| 131 | return; |
| 132 | } |
| 133 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 134 | Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, ingress.face); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 135 | |
| 136 | if (faceToUse == nullptr) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 137 | sendNoRouteNack(ingress, interest, pitEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 138 | this->rejectPendingInterest(pitEntry); |
| 139 | return; |
| 140 | } |
| 141 | |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 142 | NFD_LOG_TRACE("Forwarding interest to face: " << faceToUse->getId()); |
| 143 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 144 | forwardInterest(interest, fibEntry, pitEntry, *faceToUse); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 145 | |
| 146 | // If necessary, send probe |
| 147 | if (m_probing.isProbingNeeded(fibEntry, interest)) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 148 | Face* faceToProbe = m_probing.getFaceToProbe(ingress.face, interest, fibEntry, *faceToUse); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 149 | |
| 150 | if (faceToProbe != nullptr) { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 151 | bool wantNewNonce = true; |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 152 | forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 153 | m_probing.afterForwardingProbe(fibEntry, interest); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 159 | AsfStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 160 | const FaceEndpoint& ingress, const Data& data) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 161 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 162 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 163 | |
| 164 | if (namespaceInfo == nullptr) { |
| 165 | NFD_LOG_TRACE("Could not find measurements entry for " << pitEntry->getName()); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | // Record the RTT between the Interest out to Data in |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 170 | FaceInfo* faceInfo = namespaceInfo->get(ingress.face.getId()); |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 171 | if (faceInfo == nullptr) { |
| 172 | return; |
| 173 | } |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 174 | faceInfo->recordRtt(pitEntry, ingress.face); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 175 | |
| 176 | // Extend lifetime for measurements associated with Face |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 177 | namespaceInfo->extendFaceInfoLifetime(*faceInfo, ingress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 178 | |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 179 | if (faceInfo->isTimeoutScheduled()) { |
| 180 | faceInfo->cancelTimeoutEvent(data.getName()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 185 | AsfStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 186 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 187 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 188 | NFD_LOG_DEBUG("Nack for " << nack.getInterest() << " from=" << ingress << ": reason=" << nack.getReason()); |
| 189 | onTimeout(pitEntry->getName(), ingress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | //////////////////////////////////////////////////////////////////////////////// |
| 193 | //////////////////////////////////////////////////////////////////////////////// |
| 194 | |
| 195 | void |
| 196 | AsfStrategy::forwardInterest(const Interest& interest, |
| 197 | const fib::Entry& fibEntry, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 198 | const shared_ptr<pit::Entry>& pitEntry, |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 199 | Face& outFace, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 200 | bool wantNewNonce) |
| 201 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 202 | auto egress = FaceEndpoint(outFace, 0); |
| 203 | |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 204 | if (wantNewNonce) { |
| 205 | //Send probe: interest with new Nonce |
| 206 | Interest probeInterest(interest); |
| 207 | probeInterest.refreshNonce(); |
| 208 | NFD_LOG_TRACE("Sending probe for " << probeInterest << probeInterest.getNonce() |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 209 | << " to: " << egress); |
| 210 | this->sendInterest(pitEntry, egress, probeInterest); |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 211 | } |
| 212 | else { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 213 | this->sendInterest(pitEntry, egress, interest); |
Ashlesh Gawande | 2a73f35 | 2016-12-01 15:37:03 +0000 | [diff] [blame] | 214 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 215 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 216 | FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interest, egress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 217 | |
| 218 | // Refresh measurements since Face is being used for forwarding |
| 219 | NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interest); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 220 | namespaceInfo.extendFaceInfoLifetime(faceInfo, egress.face.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 221 | |
| 222 | if (!faceInfo.isTimeoutScheduled()) { |
| 223 | // Estimate and schedule timeout |
| 224 | RttEstimator::Duration timeout = faceInfo.computeRto(); |
| 225 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 226 | NFD_LOG_TRACE("Scheduling timeout for " << fibEntry.getPrefix() << " to: " << egress |
| 227 | << " in " << time::duration_cast<time::milliseconds>(timeout) << " ms"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 228 | |
| 229 | scheduler::EventId id = scheduler::schedule(timeout, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 230 | bind(&AsfStrategy::onTimeout, this, interest.getName(), egress.face.getId())); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 231 | |
| 232 | faceInfo.setTimeoutEvent(id, interest.getName()); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | struct FaceStats |
| 237 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 238 | Face* face; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 239 | RttStats::Rtt rtt; |
| 240 | RttStats::Rtt srtt; |
| 241 | uint64_t cost; |
| 242 | }; |
| 243 | |
| 244 | double |
| 245 | getValueForSorting(const FaceStats& stats) |
| 246 | { |
| 247 | // These values allow faces with no measurements to be ranked better than timeouts |
| 248 | // srtt < RTT_NO_MEASUREMENT < RTT_TIMEOUT |
| 249 | static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max(); |
| 250 | static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2; |
| 251 | |
| 252 | if (stats.rtt == RttStats::RTT_TIMEOUT) { |
| 253 | return SORTING_RTT_TIMEOUT.count(); |
| 254 | } |
| 255 | else if (stats.rtt == RttStats::RTT_NO_MEASUREMENT) { |
| 256 | return SORTING_RTT_NO_MEASUREMENT.count(); |
| 257 | } |
| 258 | else { |
| 259 | return stats.srtt.count(); |
| 260 | } |
| 261 | } |
| 262 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 263 | Face* |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 264 | AsfStrategy::getBestFaceForForwarding(const fib::Entry& fibEntry, const Interest& interest, |
| 265 | const Face& inFace) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 266 | { |
| 267 | NFD_LOG_TRACE("Looking for best face for " << fibEntry.getPrefix()); |
| 268 | |
| 269 | typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate; |
| 270 | typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet; |
| 271 | |
| 272 | FaceStatsSet rankedFaces( |
| 273 | [] (const FaceStats& lhs, const FaceStats& rhs) -> bool { |
| 274 | // Sort by RTT and then by cost |
| 275 | double lhsValue = getValueForSorting(lhs); |
| 276 | double rhsValue = getValueForSorting(rhs); |
| 277 | |
| 278 | if (lhsValue < rhsValue) { |
| 279 | return true; |
| 280 | } |
| 281 | else if (lhsValue == rhsValue) { |
| 282 | return lhs.cost < rhs.cost; |
| 283 | } |
| 284 | else { |
| 285 | return false; |
| 286 | } |
| 287 | }); |
| 288 | |
| 289 | for (const fib::NextHop& hop : fibEntry.getNextHops()) { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 290 | Face& hopFace = hop.getFace(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 291 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 292 | if ((hopFace.getId() == inFace.getId() && hopFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) || |
| 293 | wouldViolateScope(inFace, interest, hopFace)) { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 294 | continue; |
| 295 | } |
| 296 | |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 297 | FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace.getId()); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 298 | |
| 299 | if (info == nullptr) { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 300 | FaceStats stats = {&hopFace, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 301 | RttStats::RTT_NO_MEASUREMENT, |
| 302 | RttStats::RTT_NO_MEASUREMENT, |
| 303 | hop.getCost()}; |
| 304 | |
| 305 | rankedFaces.insert(stats); |
| 306 | } |
| 307 | else { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 308 | FaceStats stats = {&hopFace, info->getRtt(), info->getSrtt(), hop.getCost()}; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 309 | rankedFaces.insert(stats); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | FaceStatsSet::iterator it = rankedFaces.begin(); |
| 314 | |
| 315 | if (it != rankedFaces.end()) { |
| 316 | return it->face; |
| 317 | } |
| 318 | else { |
| 319 | return nullptr; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 324 | AsfStrategy::onTimeout(const Name& interestName, const face::FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 325 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 326 | NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 327 | |
| 328 | if (namespaceInfo == nullptr) { |
| 329 | NFD_LOG_TRACE("FibEntry for " << interestName << " has been removed since timeout scheduling"); |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | FaceInfoTable::iterator it = namespaceInfo->find(faceId); |
| 334 | |
| 335 | if (it == namespaceInfo->end()) { |
| 336 | it = namespaceInfo->insert(faceId); |
| 337 | } |
| 338 | |
| 339 | FaceInfo& faceInfo = it->second; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 340 | |
| 341 | faceInfo.setNSilentTimeouts(faceInfo.getNSilentTimeouts() + 1); |
| 342 | |
| 343 | if (faceInfo.getNSilentTimeouts() <= m_maxSilentTimeouts) { |
| 344 | NFD_LOG_TRACE("FaceId " << faceId << " for " << interestName << " has timed-out " |
| 345 | << faceInfo.getNSilentTimeouts() << " time(s), ignoring"); |
| 346 | // Extend lifetime for measurements associated with Face |
| 347 | namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId); |
| 348 | |
| 349 | if (faceInfo.isTimeoutScheduled()) { |
| 350 | faceInfo.cancelTimeoutEvent(interestName); |
| 351 | } |
| 352 | } |
| 353 | else { |
| 354 | NFD_LOG_TRACE("FaceId " << faceId << " for " << interestName << " has timed-out"); |
| 355 | faceInfo.recordTimeout(interestName); |
| 356 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 360 | AsfStrategy::sendNoRouteNack(const FaceEndpoint& ingress, const Interest& interest, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 361 | const shared_ptr<pit::Entry>& pitEntry) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 362 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 363 | NFD_LOG_DEBUG(interest << " from=" << ingress << " noNextHop"); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 364 | |
| 365 | lp::NackHeader nackHeader; |
| 366 | nackHeader.setReason(lp::NackReason::NO_ROUTE); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 367 | this->sendNack(pitEntry, ingress, nackHeader); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | } // namespace asf |
| 371 | } // namespace fw |
| 372 | } // namespace nfd |