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" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 28 | #include "core/logger.hpp" |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 29 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 30 | #include <boost/range/adaptor/map.hpp> |
| 31 | #include <boost/range/algorithm/copy.hpp> |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 34 | namespace fw { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 36 | NFD_LOG_INIT(Strategy); |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 38 | Strategy::Registry& |
| 39 | Strategy::getRegistry() |
| 40 | { |
| 41 | static Registry registry; |
| 42 | return registry; |
| 43 | } |
| 44 | |
| 45 | Strategy::Registry::const_iterator |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 46 | Strategy::find(const Name& instanceName) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 47 | { |
| 48 | const Registry& registry = getRegistry(); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 49 | ParsedInstanceName parsed = parseInstanceName(instanceName); |
| 50 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 51 | if (parsed.version) { |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 52 | // specified version: find exact or next higher version |
| 53 | |
| 54 | auto found = registry.lower_bound(parsed.strategyName); |
| 55 | if (found != registry.end()) { |
| 56 | if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) { |
| 57 | NFD_LOG_TRACE("find " << instanceName << " versioned found=" << found->first); |
| 58 | return found; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | NFD_LOG_TRACE("find " << instanceName << " versioned not-found"); |
| 63 | return registry.end(); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 66 | // no version specified: find highest version |
| 67 | |
| 68 | if (!parsed.strategyName.empty()) { // Name().getSuccessor() would be invalid |
| 69 | auto found = registry.lower_bound(parsed.strategyName.getSuccessor()); |
| 70 | if (found != registry.begin()) { |
| 71 | --found; |
| 72 | if (parsed.strategyName.isPrefixOf(found->first)) { |
| 73 | NFD_LOG_TRACE("find " << instanceName << " unversioned found=" << found->first); |
| 74 | return found; |
| 75 | } |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 78 | |
| 79 | NFD_LOG_TRACE("find " << instanceName << " unversioned not-found"); |
| 80 | return registry.end(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | bool |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 84 | Strategy::canCreate(const Name& instanceName) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 85 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 86 | return Strategy::find(instanceName) != getRegistry().end(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | unique_ptr<Strategy> |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 90 | Strategy::create(const Name& instanceName, Forwarder& forwarder) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 91 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 92 | auto found = Strategy::find(instanceName); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 93 | if (found == getRegistry().end()) { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 94 | NFD_LOG_DEBUG("create " << instanceName << " not-found"); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 95 | return nullptr; |
| 96 | } |
| 97 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 98 | unique_ptr<Strategy> instance = found->second(forwarder, instanceName); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 99 | NFD_LOG_DEBUG("create " << instanceName << " found=" << found->first |
| 100 | << " created=" << instance->getInstanceName()); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 101 | BOOST_ASSERT(!instance->getInstanceName().empty()); |
| 102 | return instance; |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 105 | bool |
| 106 | Strategy::areSameType(const Name& instanceNameA, const Name& instanceNameB) |
| 107 | { |
| 108 | return Strategy::find(instanceNameA) == Strategy::find(instanceNameB); |
| 109 | } |
| 110 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 111 | std::set<Name> |
| 112 | Strategy::listRegistered() |
| 113 | { |
| 114 | std::set<Name> strategyNames; |
| 115 | boost::copy(getRegistry() | boost::adaptors::map_keys, |
| 116 | std::inserter(strategyNames, strategyNames.end())); |
| 117 | return strategyNames; |
| 118 | } |
| 119 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 120 | Strategy::ParsedInstanceName |
| 121 | Strategy::parseInstanceName(const Name& input) |
| 122 | { |
| 123 | for (ssize_t i = input.size() - 1; i > 0; --i) { |
| 124 | if (input[i].isVersion()) { |
| 125 | return {input.getPrefix(i + 1), input[i].toVersion(), input.getSubName(i + 1)}; |
| 126 | } |
| 127 | } |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 128 | return {input, nullopt, PartialName()}; |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | Name |
| 132 | Strategy::makeInstanceName(const Name& input, const Name& strategyName) |
| 133 | { |
| 134 | BOOST_ASSERT(strategyName.at(-1).isVersion()); |
| 135 | |
| 136 | bool hasVersion = std::any_of(input.rbegin(), input.rend(), |
| 137 | [] (const name::Component& comp) { return comp.isVersion(); }); |
| 138 | return hasVersion ? input : Name(input).append(strategyName.at(-1)); |
| 139 | } |
| 140 | |
| 141 | Strategy::Strategy(Forwarder& forwarder) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 142 | : afterAddFace(forwarder.getFaceTable().afterAdd) |
| 143 | , beforeRemoveFace(forwarder.getFaceTable().beforeRemove) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 144 | , m_forwarder(forwarder) |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 145 | , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getStrategyChoice(), *this) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 146 | { |
| 147 | } |
| 148 | |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 149 | Strategy::~Strategy() = default; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 150 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 151 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 152 | Strategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 153 | const FaceEndpoint& ingress, const Data& data) |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 154 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 155 | NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() |
| 156 | << " in=" << ingress << " data=" << data.getName()); |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 160 | Strategy::afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 161 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 162 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 163 | NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName() |
| 164 | << " in=" << ingress << " data=" << data.getName()); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 165 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 166 | this->sendData(pitEntry, data, ingress); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 170 | Strategy::afterReceiveData(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 171 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 172 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 173 | NFD_LOG_DEBUG("afterReceiveData pitEntry=" << pitEntry->getName() |
| 174 | << " in=" << ingress << " data=" << data.getName()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 175 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 176 | this->beforeSatisfyInterest(pitEntry, ingress, data); |
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->sendDataToAll(pitEntry, ingress, data); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 182 | Strategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 183 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 184 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 185 | NFD_LOG_DEBUG("afterReceiveNack in=" << ingress << " pitEntry=" << pitEntry->getName()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 189 | Strategy::onDroppedInterest(const FaceEndpoint& egress, const Interest& interest) |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 190 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 191 | NFD_LOG_DEBUG("onDroppedInterest out=" << egress << " name=" << interest.getName()); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 195 | Strategy::sendData(const shared_ptr<pit::Entry>& pitEntry, const Data& data, |
| 196 | const FaceEndpoint& egress) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 197 | { |
| 198 | BOOST_ASSERT(pitEntry->getInterest().matchesData(data)); |
| 199 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 200 | // delete the PIT entry's in-record based on egress, |
| 201 | // since Data is sent to face and endpoint from which the Interest was received |
| 202 | pitEntry->deleteInRecord(egress.face, egress.endpoint); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 203 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 204 | m_forwarder.onOutgoingData(data, egress); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 208 | Strategy::sendDataToAll(const shared_ptr<pit::Entry>& pitEntry, |
| 209 | const FaceEndpoint& ingress, const Data& data) |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 210 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 211 | std::set<std::pair<Face*, EndpointId>> pendingDownstreams; |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 212 | auto now = time::steady_clock::now(); |
| 213 | |
| 214 | // remember pending downstreams |
| 215 | for (const pit::InRecord& inRecord : pitEntry->getInRecords()) { |
| 216 | if (inRecord.getExpiry() > now) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 217 | if (inRecord.getFace().getId() == ingress.face.getId() && |
| 218 | inRecord.getEndpointId() == ingress.endpoint && |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 219 | inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) { |
| 220 | continue; |
| 221 | } |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 222 | pendingDownstreams.emplace(&inRecord.getFace(), inRecord.getEndpointId()); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 226 | for (const auto& pendingDownstream : pendingDownstreams) { |
| 227 | this->sendData(pitEntry, data, FaceEndpoint(*pendingDownstream.first, pendingDownstream.second)); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 232 | Strategy::sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 233 | std::initializer_list<FaceEndpoint> exceptFaceEndpoints) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 234 | { |
| 235 | // populate downstreams with all downstreams faces |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 236 | std::set<std::pair<Face*, EndpointId>> downstreams; |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 237 | std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()), |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 238 | [] (const pit::InRecord& inR) { |
| 239 | return std::make_pair(&inR.getFace(), inR.getEndpointId()); |
| 240 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 241 | |
| 242 | // delete excluded faces |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 243 | for (const auto& exceptFaceEndpoint : exceptFaceEndpoints) { |
| 244 | downstreams.erase({&exceptFaceEndpoint.face, exceptFaceEndpoint.endpoint}); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // send Nacks |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 248 | for (const auto& downstream : downstreams) { |
| 249 | this->sendNack(pitEntry, FaceEndpoint(*downstream.first, downstream.second), header); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 250 | } |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 251 | // 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] | 252 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 253 | |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 254 | const fib::Entry& |
| 255 | Strategy::lookupFib(const pit::Entry& pitEntry) const |
| 256 | { |
| 257 | const Fib& fib = m_forwarder.getFib(); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 258 | |
| 259 | const Interest& interest = pitEntry.getInterest(); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 260 | // has forwarding hint? |
| 261 | if (interest.getForwardingHint().empty()) { |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 262 | // FIB lookup with Interest name |
| 263 | const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 264 | NFD_LOG_TRACE("lookupFib noForwardingHint found=" << fibEntry.getPrefix()); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 265 | return fibEntry; |
| 266 | } |
| 267 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 268 | const DelegationList& fh = interest.getForwardingHint(); |
| 269 | // Forwarding hint should have been stripped by incoming Interest pipeline when reaching producer region |
| 270 | BOOST_ASSERT(!m_forwarder.getNetworkRegionTable().isInProducerRegion(fh)); |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 271 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 272 | const fib::Entry* fibEntry = nullptr; |
| 273 | for (const Delegation& del : fh) { |
| 274 | fibEntry = &fib.findLongestPrefixMatch(del.name); |
| 275 | if (fibEntry->hasNextHops()) { |
| 276 | if (fibEntry->getPrefix().size() == 0) { |
| 277 | // in consumer region, return the default route |
| 278 | NFD_LOG_TRACE("lookupFib inConsumerRegion found=" << fibEntry->getPrefix()); |
| 279 | } |
| 280 | else { |
| 281 | // in default-free zone, use the first delegation that finds a FIB entry |
| 282 | NFD_LOG_TRACE("lookupFib delegation=" << del.name << " found=" << fibEntry->getPrefix()); |
| 283 | } |
| 284 | return *fibEntry; |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 285 | } |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 286 | 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] | 287 | } |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 288 | BOOST_ASSERT(fibEntry != nullptr && fibEntry->getPrefix().size() == 0); |
| 289 | return *fibEntry; // only occurs if no delegation finds a FIB nexthop |
Junxiao Shi | cf0f3ce | 2016-09-02 13:01:59 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 292 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 293 | } // namespace nfd |