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 | /* |
Davide Pesavento | b8bd5ee | 2019-02-03 22:53:40 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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> |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 36 | namespace 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 | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 130 | return {input, 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(), |
| 139 | [] (const name::Component& comp) { return comp.isVersion(); }); |
| 140 | return hasVersion ? input : Name(input).append(strategyName.at(-1)); |
| 141 | } |
| 142 | |
| 143 | Strategy::Strategy(Forwarder& forwarder) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 144 | : afterAddFace(forwarder.getFaceTable().afterAdd) |
| 145 | , beforeRemoveFace(forwarder.getFaceTable().beforeRemove) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 146 | , m_forwarder(forwarder) |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 147 | , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getStrategyChoice(), *this) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 148 | { |
| 149 | } |
| 150 | |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 151 | Strategy::~Strategy() = default; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 152 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 153 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 154 | Strategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 155 | const FaceEndpoint& ingress, const Data& data) |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 156 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 157 | NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() |
| 158 | << " in=" << ingress << " data=" << data.getName()); |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 162 | Strategy::afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 163 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 164 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 165 | NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName() |
| 166 | << " in=" << ingress << " data=" << data.getName()); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 167 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 168 | this->sendData(pitEntry, data, ingress); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 172 | Strategy::afterReceiveData(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 173 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 174 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 175 | NFD_LOG_DEBUG("afterReceiveData pitEntry=" << pitEntry->getName() |
| 176 | << " in=" << ingress << " data=" << data.getName()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 177 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 178 | this->beforeSatisfyInterest(pitEntry, ingress, data); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 179 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 180 | this->sendDataToAll(pitEntry, ingress, data); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 184 | Strategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 185 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 186 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 187 | NFD_LOG_DEBUG("afterReceiveNack in=" << ingress << " pitEntry=" << pitEntry->getName()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 191 | Strategy::onDroppedInterest(const FaceEndpoint& egress, const Interest& interest) |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 192 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 193 | NFD_LOG_DEBUG("onDroppedInterest out=" << egress << " name=" << interest.getName()); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame^] | 197 | Strategy::sendInterest(const shared_ptr<pit::Entry>& pitEntry, |
| 198 | const FaceEndpoint& egress, const Interest& interest) |
| 199 | { |
| 200 | if (interest.getTag<lp::PitToken>() != nullptr) { |
| 201 | Interest interest2 = interest; // make a copy to preserve tag on original packet |
| 202 | interest2.removeTag<lp::PitToken>(); |
| 203 | m_forwarder.onOutgoingInterest(pitEntry, egress, interest2); |
| 204 | return; |
| 205 | } |
| 206 | m_forwarder.onOutgoingInterest(pitEntry, egress, interest); |
| 207 | } |
| 208 | |
| 209 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 210 | Strategy::sendData(const shared_ptr<pit::Entry>& pitEntry, const Data& data, |
| 211 | const FaceEndpoint& egress) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 212 | { |
| 213 | BOOST_ASSERT(pitEntry->getInterest().matchesData(data)); |
| 214 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame^] | 215 | shared_ptr<lp::PitToken> pitToken; |
| 216 | auto inRecord = pitEntry->getInRecord(egress.face); |
| 217 | if (inRecord != pitEntry->in_end()) { |
| 218 | pitToken = inRecord->getInterest().getTag<lp::PitToken>(); |
| 219 | } |
| 220 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 221 | // delete the PIT entry's in-record based on egress, |
| 222 | // since Data is sent to face and endpoint from which the Interest was received |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 223 | pitEntry->deleteInRecord(egress.face); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 224 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame^] | 225 | if (pitToken != nullptr) { |
| 226 | Data data2 = data; // make a copy so each downstream can get a different PIT token |
| 227 | data2.setTag(pitToken); |
| 228 | m_forwarder.onOutgoingData(data2, egress); |
| 229 | return; |
| 230 | } |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 231 | m_forwarder.onOutgoingData(data, egress); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 235 | Strategy::sendDataToAll(const shared_ptr<pit::Entry>& pitEntry, |
| 236 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 237 | { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 238 | std::set<Face*> pendingDownstreams; |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 239 | auto now = time::steady_clock::now(); |
| 240 | |
| 241 | // remember pending downstreams |
| 242 | for (const pit::InRecord& inRecord : pitEntry->getInRecords()) { |
| 243 | if (inRecord.getExpiry() > now) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 244 | if (inRecord.getFace().getId() == ingress.face.getId() && |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 245 | inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) { |
| 246 | continue; |
| 247 | } |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 248 | pendingDownstreams.emplace(&inRecord.getFace()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 252 | for (const auto& pendingDownstream : pendingDownstreams) { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 253 | this->sendData(pitEntry, data, FaceEndpoint(*pendingDownstream, 0)); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 258 | Strategy::sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 259 | std::initializer_list<FaceEndpoint> exceptFaceEndpoints) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 260 | { |
| 261 | // populate downstreams with all downstreams faces |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 262 | std::set<Face*> downstreams; |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 263 | std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()), |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 264 | [] (const pit::InRecord& inR) { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 265 | return &inR.getFace(); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 266 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 267 | |
| 268 | // delete excluded faces |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 269 | for (const auto& exceptFaceEndpoint : exceptFaceEndpoints) { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 270 | downstreams.erase(&exceptFaceEndpoint.face); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | // send Nacks |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 274 | for (const auto& downstream : downstreams) { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 275 | this->sendNack(pitEntry, FaceEndpoint(*downstream, 0), header); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 276 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 277 | // 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] | 278 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 279 | |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 280 | const fib::Entry& |
| 281 | Strategy::lookupFib(const pit::Entry& pitEntry) const |
| 282 | { |
| 283 | const Fib& fib = m_forwarder.getFib(); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 284 | |
| 285 | const Interest& interest = pitEntry.getInterest(); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 286 | // has forwarding hint? |
| 287 | if (interest.getForwardingHint().empty()) { |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 288 | // FIB lookup with Interest name |
| 289 | const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 290 | NFD_LOG_TRACE("lookupFib noForwardingHint found=" << fibEntry.getPrefix()); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 291 | return fibEntry; |
| 292 | } |
| 293 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 294 | const DelegationList& fh = interest.getForwardingHint(); |
| 295 | // Forwarding hint should have been stripped by incoming Interest pipeline when reaching producer region |
| 296 | BOOST_ASSERT(!m_forwarder.getNetworkRegionTable().isInProducerRegion(fh)); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 297 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 298 | const fib::Entry* fibEntry = nullptr; |
| 299 | for (const Delegation& del : fh) { |
| 300 | fibEntry = &fib.findLongestPrefixMatch(del.name); |
| 301 | if (fibEntry->hasNextHops()) { |
| 302 | if (fibEntry->getPrefix().size() == 0) { |
| 303 | // in consumer region, return the default route |
| 304 | NFD_LOG_TRACE("lookupFib inConsumerRegion found=" << fibEntry->getPrefix()); |
| 305 | } |
| 306 | else { |
| 307 | // in default-free zone, use the first delegation that finds a FIB entry |
| 308 | NFD_LOG_TRACE("lookupFib delegation=" << del.name << " found=" << fibEntry->getPrefix()); |
| 309 | } |
| 310 | return *fibEntry; |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 311 | } |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 312 | BOOST_ASSERT(fibEntry->getPrefix().size() == 0); // only ndn:/ FIB entry can have zero nexthop |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 313 | } |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 314 | BOOST_ASSERT(fibEntry != nullptr && fibEntry->getPrefix().size() == 0); |
| 315 | return *fibEntry; // only occurs if no delegation finds a FIB nexthop |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 318 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 319 | } // namespace nfd |