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