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