Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Mark Theeranantachai | 195b78a | 2024-02-14 20:54:44 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Junxiao Shi | 3535396 | 2015-01-08 09:13:47 -0700 | [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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 25 | |
| 26 | #include "strategy.hpp" |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 27 | #include "forwarder.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 28 | #include "common/logger.hpp" |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 29 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 30 | #include <ndn-cxx/lp/pit-token.hpp> |
| 31 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 32 | #include <boost/range/adaptor/map.hpp> |
| 33 | #include <boost/range/algorithm/copy.hpp> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 34 | #include <unordered_set> |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 36 | namespace nfd::fw { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 38 | NFD_LOG_INIT(Strategy); |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 40 | Strategy::Registry& |
| 41 | Strategy::getRegistry() |
| 42 | { |
| 43 | static Registry registry; |
| 44 | return registry; |
| 45 | } |
| 46 | |
| 47 | Strategy::Registry::const_iterator |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 48 | Strategy::find(const Name& instanceName) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 49 | { |
| 50 | const Registry& registry = getRegistry(); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 51 | ParsedInstanceName parsed = parseInstanceName(instanceName); |
| 52 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 53 | if (parsed.version) { |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 54 | // specified version: find exact or next higher version |
| 55 | |
| 56 | auto found = registry.lower_bound(parsed.strategyName); |
| 57 | if (found != registry.end()) { |
| 58 | if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) { |
| 59 | NFD_LOG_TRACE("find " << instanceName << " versioned found=" << found->first); |
| 60 | return found; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | NFD_LOG_TRACE("find " << instanceName << " versioned not-found"); |
| 65 | return registry.end(); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 68 | // no version specified: find highest version |
| 69 | |
| 70 | if (!parsed.strategyName.empty()) { // Name().getSuccessor() would be invalid |
| 71 | auto found = registry.lower_bound(parsed.strategyName.getSuccessor()); |
| 72 | if (found != registry.begin()) { |
| 73 | --found; |
| 74 | if (parsed.strategyName.isPrefixOf(found->first)) { |
| 75 | NFD_LOG_TRACE("find " << instanceName << " unversioned found=" << found->first); |
| 76 | return found; |
| 77 | } |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 80 | |
| 81 | NFD_LOG_TRACE("find " << instanceName << " unversioned not-found"); |
| 82 | return registry.end(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 86 | Strategy::canCreate(const Name& instanceName) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 87 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 88 | return Strategy::find(instanceName) != getRegistry().end(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | unique_ptr<Strategy> |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 92 | Strategy::create(const Name& instanceName, Forwarder& forwarder) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 93 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 94 | auto found = Strategy::find(instanceName); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 95 | if (found == getRegistry().end()) { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 96 | NFD_LOG_DEBUG("create " << instanceName << " not-found"); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 97 | return nullptr; |
| 98 | } |
| 99 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 100 | unique_ptr<Strategy> instance = found->second(forwarder, instanceName); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 101 | NFD_LOG_DEBUG("create " << instanceName << " found=" << found->first |
| 102 | << " created=" << instance->getInstanceName()); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 103 | BOOST_ASSERT(!instance->getInstanceName().empty()); |
| 104 | return instance; |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 107 | bool |
| 108 | Strategy::areSameType(const Name& instanceNameA, const Name& instanceNameB) |
| 109 | { |
| 110 | return Strategy::find(instanceNameA) == Strategy::find(instanceNameB); |
| 111 | } |
| 112 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 113 | std::set<Name> |
| 114 | Strategy::listRegistered() |
| 115 | { |
| 116 | std::set<Name> strategyNames; |
| 117 | boost::copy(getRegistry() | boost::adaptors::map_keys, |
| 118 | std::inserter(strategyNames, strategyNames.end())); |
| 119 | return strategyNames; |
| 120 | } |
| 121 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 122 | Strategy::ParsedInstanceName |
| 123 | Strategy::parseInstanceName(const Name& input) |
| 124 | { |
| 125 | for (ssize_t i = input.size() - 1; i > 0; --i) { |
| 126 | if (input[i].isVersion()) { |
| 127 | return {input.getPrefix(i + 1), input[i].toVersion(), input.getSubName(i + 1)}; |
| 128 | } |
| 129 | } |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 130 | return {input, std::nullopt, PartialName()}; |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | Name |
| 134 | Strategy::makeInstanceName(const Name& input, const Name& strategyName) |
| 135 | { |
| 136 | BOOST_ASSERT(strategyName.at(-1).isVersion()); |
| 137 | |
| 138 | bool hasVersion = std::any_of(input.rbegin(), input.rend(), |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 139 | [] (const auto& comp) { return comp.isVersion(); }); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 140 | return hasVersion ? input : Name(input).append(strategyName.at(-1)); |
| 141 | } |
| 142 | |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 143 | StrategyParameters |
| 144 | Strategy::parseParameters(const PartialName& params) |
| 145 | { |
| 146 | StrategyParameters parsed; |
| 147 | |
| 148 | for (const auto& component : params) { |
| 149 | auto sep = std::find(component.value_begin(), component.value_end(), '~'); |
| 150 | if (sep == component.value_end()) { |
| 151 | NDN_THROW(std::invalid_argument("Strategy parameters format is (<parameter>~<value>)*")); |
| 152 | } |
| 153 | |
| 154 | std::string p(component.value_begin(), sep); |
| 155 | std::advance(sep, 1); |
| 156 | std::string v(sep, component.value_end()); |
| 157 | if (p.empty() || v.empty()) { |
| 158 | NDN_THROW(std::invalid_argument("Strategy parameter name and value cannot be empty")); |
| 159 | } |
| 160 | parsed[std::move(p)] = std::move(v); |
| 161 | } |
| 162 | |
| 163 | return parsed; |
| 164 | } |
| 165 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 166 | Strategy::Strategy(Forwarder& forwarder) |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 167 | : afterAddFace(forwarder.m_faceTable.afterAdd) |
| 168 | , beforeRemoveFace(forwarder.m_faceTable.beforeRemove) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 169 | , m_forwarder(forwarder) |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 170 | , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getStrategyChoice(), *this) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 171 | { |
| 172 | } |
| 173 | |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 174 | Strategy::~Strategy() = default; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 175 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 176 | void |
Mark Theeranantachai | 195b78a | 2024-02-14 20:54:44 -0500 | [diff] [blame] | 177 | Strategy::onInterestLoop(const Interest& interest, const FaceEndpoint& ingress) |
| 178 | { |
| 179 | NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " name=" << interest.getName()); |
| 180 | |
| 181 | lp::Nack nack(interest); |
| 182 | nack.setReason(lp::NackReason::DUPLICATE); |
| 183 | this->sendNack(nack, ingress.face); |
| 184 | } |
| 185 | |
| 186 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 187 | Strategy::afterContentStoreHit(const Data& data, const FaceEndpoint& ingress, |
| 188 | const shared_ptr<pit::Entry>& pitEntry) |
| 189 | { |
| 190 | NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName() |
| 191 | << " in=" << ingress << " data=" << data.getName()); |
| 192 | |
| 193 | this->sendData(data, ingress.face, pitEntry); |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | Strategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 198 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 199 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 200 | NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() |
| 201 | << " in=" << ingress << " data=" << data.getName()); |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 205 | Strategy::afterReceiveData(const Data& data, const FaceEndpoint& ingress, |
| 206 | const shared_ptr<pit::Entry>& pitEntry) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 207 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 208 | NFD_LOG_DEBUG("afterReceiveData pitEntry=" << pitEntry->getName() |
| 209 | << " in=" << ingress << " data=" << data.getName()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 210 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 211 | this->beforeSatisfyInterest(data, ingress, pitEntry); |
| 212 | this->sendDataToAll(data, pitEntry, ingress.face); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 216 | Strategy::afterReceiveNack(const lp::Nack&, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 217 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 218 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 219 | NFD_LOG_DEBUG("afterReceiveNack in=" << ingress << " pitEntry=" << pitEntry->getName()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 223 | Strategy::onDroppedInterest(const Interest& interest, Face& egress) |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 224 | { |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 225 | NFD_LOG_DEBUG("onDroppedInterest out=" << egress.getId() << " name=" << interest.getName()); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 228 | void |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame] | 229 | Strategy::afterNewNextHop(const fib::NextHop& nextHop, const shared_ptr<pit::Entry>& pitEntry) |
| 230 | { |
| 231 | NFD_LOG_DEBUG("afterNewNextHop pitEntry=" << pitEntry->getName() |
| 232 | << " nexthop=" << nextHop.getFace().getId()); |
| 233 | } |
| 234 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 235 | pit::OutRecord* |
| 236 | Strategy::sendInterest(const Interest& interest, Face& egress, const shared_ptr<pit::Entry>& pitEntry) |
| 237 | { |
| 238 | if (interest.getTag<lp::PitToken>() != nullptr) { |
| 239 | Interest interest2 = interest; // make a copy to preserve tag on original packet |
| 240 | interest2.removeTag<lp::PitToken>(); |
| 241 | return m_forwarder.onOutgoingInterest(interest2, egress, pitEntry); |
| 242 | } |
| 243 | return m_forwarder.onOutgoingInterest(interest, egress, pitEntry); |
| 244 | } |
| 245 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 246 | bool |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 247 | Strategy::sendData(const Data& data, Face& egress, const shared_ptr<pit::Entry>& pitEntry) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 248 | { |
| 249 | BOOST_ASSERT(pitEntry->getInterest().matchesData(data)); |
| 250 | |
Davide Pesavento | b124b8e | 2024-02-16 16:54:26 -0500 | [diff] [blame] | 251 | auto inRecord = pitEntry->findInRecord(egress); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 252 | if (inRecord != pitEntry->in_end()) { |
Davide Pesavento | 4d2e788 | 2024-02-15 23:00:21 -0500 | [diff] [blame] | 253 | auto pitToken = inRecord->getInterest().getTag<lp::PitToken>(); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 254 | |
Davide Pesavento | 4d2e788 | 2024-02-15 23:00:21 -0500 | [diff] [blame] | 255 | // delete the PIT entry's in-record based on egress, |
| 256 | // since the Data is sent to the face from which the Interest was received |
| 257 | pitEntry->deleteInRecord(inRecord); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 258 | |
Davide Pesavento | 4d2e788 | 2024-02-15 23:00:21 -0500 | [diff] [blame] | 259 | if (pitToken != nullptr) { |
| 260 | Data data2 = data; // make a copy so each downstream can get a different PIT token |
| 261 | data2.setTag(pitToken); |
| 262 | return m_forwarder.onOutgoingData(data2, egress); |
| 263 | } |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 264 | } |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 265 | return m_forwarder.onOutgoingData(data, egress); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 269 | Strategy::sendDataToAll(const Data& data, const shared_ptr<pit::Entry>& pitEntry, const Face& inFace) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 270 | { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 271 | std::set<Face*> pendingDownstreams; |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 272 | auto now = time::steady_clock::now(); |
| 273 | |
| 274 | // remember pending downstreams |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 275 | for (const auto& inRecord : pitEntry->getInRecords()) { |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 276 | if (inRecord.getExpiry() > now) { |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 277 | if (inRecord.getFace().getId() == inFace.getId() && |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 278 | inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) { |
| 279 | continue; |
| 280 | } |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 281 | pendingDownstreams.emplace(&inRecord.getFace()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 285 | for (const auto& pendingDownstream : pendingDownstreams) { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 286 | this->sendData(data, *pendingDownstream, pitEntry); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 291 | Strategy::sendNacks(const lp::NackHeader& header, const shared_ptr<pit::Entry>& pitEntry, |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 292 | std::initializer_list<const Face*> exceptFaces) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 293 | { |
| 294 | // populate downstreams with all downstreams faces |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 295 | std::unordered_set<Face*> downstreams; |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 296 | std::transform(pitEntry->in_begin(), pitEntry->in_end(), |
| 297 | std::inserter(downstreams, downstreams.end()), |
| 298 | [] (const auto& inR) { return &inR.getFace(); }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 299 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 300 | // remove excluded faces |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 301 | for (auto exceptFace : exceptFaces) { |
| 302 | downstreams.erase(const_cast<Face*>(exceptFace)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // send Nacks |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 306 | for (auto downstream : downstreams) { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 307 | this->sendNack(header, *downstream, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 308 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 309 | // warning: don't loop on pitEntry->getInRecords(), because in-record is deleted when sending Nack |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 310 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 311 | |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 312 | const fib::Entry& |
| 313 | Strategy::lookupFib(const pit::Entry& pitEntry) const |
| 314 | { |
| 315 | const Fib& fib = m_forwarder.getFib(); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 316 | |
| 317 | const Interest& interest = pitEntry.getInterest(); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 318 | // has forwarding hint? |
| 319 | if (interest.getForwardingHint().empty()) { |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 320 | // FIB lookup with Interest name |
| 321 | const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 322 | NFD_LOG_TRACE("lookupFib noForwardingHint found=" << fibEntry.getPrefix()); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 323 | return fibEntry; |
| 324 | } |
| 325 | |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 326 | const auto& fh = interest.getForwardingHint(); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 327 | // Forwarding hint should have been stripped by incoming Interest pipeline when reaching producer region |
| 328 | BOOST_ASSERT(!m_forwarder.getNetworkRegionTable().isInProducerRegion(fh)); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 329 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 330 | const fib::Entry* fibEntry = nullptr; |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 331 | for (const auto& delegation : fh) { |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame] | 332 | fibEntry = &fib.findLongestPrefixMatch(delegation); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 333 | if (fibEntry->hasNextHops()) { |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 334 | if (fibEntry->getPrefix().empty()) { |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 335 | // in consumer region, return the default route |
| 336 | NFD_LOG_TRACE("lookupFib inConsumerRegion found=" << fibEntry->getPrefix()); |
| 337 | } |
| 338 | else { |
| 339 | // in default-free zone, use the first delegation that finds a FIB entry |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame] | 340 | NFD_LOG_TRACE("lookupFib delegation=" << delegation << " found=" << fibEntry->getPrefix()); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 341 | } |
| 342 | return *fibEntry; |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 343 | } |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 344 | BOOST_ASSERT(fibEntry->getPrefix().empty()); // only ndn:/ FIB entry can have zero nexthop |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 345 | } |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame] | 346 | BOOST_ASSERT(fibEntry != nullptr && fibEntry->getPrefix().empty()); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 347 | return *fibEntry; // only occurs if no delegation finds a FIB nexthop |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 350 | } // namespace nfd::fw |