blob: 5d886e83d741f2cbc16aca822c807285f5ad3ab5 [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shifc2e13d2017-07-25 02:08:48 +00002/*
Davide Pesaventob21bed82021-02-13 00:20:06 -05003 * Copyright (c) 2014-2021, Regents of the University of California,
Junxiao Shifaf3eb02015-02-16 10:50:36 -07004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shiaf6569a2014-06-14 00:01:34 -070024 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080025
26#include "forwarder.hpp"
Davide Pesaventoa3148082018-04-12 18:21:54 -040027
Junxiao Shi00dc9142016-11-21 14:23:12 +000028#include "algorithm.hpp"
Davide Pesavento7922d122021-03-05 22:41:23 -050029#include "best-route-strategy.hpp"
Davide Pesavento58091582021-03-05 19:02:48 -050030#include "scope-prefix.hpp"
Junxiao Shifaf3eb02015-02-16 10:50:36 -070031#include "strategy.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040032#include "common/global.hpp"
33#include "common/logger.hpp"
Junxiao Shi02b73f52016-07-28 01:48:27 +000034#include "table/cleanup.hpp"
Davide Pesaventoa3148082018-04-12 18:21:54 -040035
Junxiao Shic29eb7f2020-04-14 18:20:32 +000036#include <ndn-cxx/lp/pit-token.hpp>
Junxiao Shicbc8e942016-09-06 03:17:45 +000037#include <ndn-cxx/lp/tags.hpp>
Alexander Afanasyev33b72772014-01-26 23:22:58 -080038
Alexander Afanasyev89023c82018-08-06 17:28:36 -040039#include "face/null-face.hpp"
40
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080041namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080042
Davide Pesaventoa3148082018-04-12 18:21:54 -040043NFD_LOG_INIT(Forwarder);
Junxiao Shi8c8d2182014-01-30 22:33:00 -070044
Davide Pesavento412c9822021-07-02 00:21:05 -040045const std::string CFG_FORWARDER = "forwarder";
Philipp Molla1033342021-06-14 09:34:21 +020046
Junxiao Shic34d1672016-12-09 15:57:59 +000047static Name
48getDefaultStrategyName()
49{
Davide Pesavento7922d122021-03-05 22:41:23 -050050 return fw::BestRouteStrategy::getStrategyName();
Junxiao Shic34d1672016-12-09 15:57:59 +000051}
52
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040053Forwarder::Forwarder(FaceTable& faceTable)
54 : m_faceTable(faceTable)
55 , m_unsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>())
Junxiao Shifbe8efe2016-08-22 16:02:30 +000056 , m_fib(m_nameTree)
Haowei Yuan78c84d12014-02-27 15:35:13 -060057 , m_pit(m_nameTree)
HangZhangc85a23c2014-03-01 15:55:55 +080058 , m_measurements(m_nameTree)
Junxiao Shic34d1672016-12-09 15:57:59 +000059 , m_strategyChoice(*this)
Alexander Afanasyev89023c82018-08-06 17:28:36 -040060 , m_csFace(face::makeNullFace(FaceUri("contentstore://")))
Alexander Afanasyev33b72772014-01-26 23:22:58 -080061{
Alexander Afanasyev1d453e52020-02-21 16:37:25 -050062 m_faceTable.addReserved(m_csFace, face::FACEID_CONTENT_STORE);
Alexander Afanasyev89023c82018-08-06 17:28:36 -040063
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040064 m_faceTable.afterAdd.connect([this] (const Face& face) {
Junxiao Shidcffdaa2016-07-26 02:23:56 +000065 face.afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000066 [this, &face] (const Interest& interest, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040067 this->onIncomingInterest(interest, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000068 });
69 face.afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000070 [this, &face] (const Data& data, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040071 this->onIncomingData(data, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000072 });
73 face.afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000074 [this, &face] (const lp::Nack& nack, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040075 this->onIncomingNack(nack, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000076 });
Eric Newberry41aba102017-11-01 16:42:13 -070077 face.onDroppedInterest.connect(
78 [this, &face] (const Interest& interest) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040079 this->onDroppedInterest(interest, const_cast<Face&>(face));
Eric Newberry41aba102017-11-01 16:42:13 -070080 });
Junxiao Shidcffdaa2016-07-26 02:23:56 +000081 });
82
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040083 m_faceTable.beforeRemove.connect([this] (const Face& face) {
Junxiao Shi02b73f52016-07-28 01:48:27 +000084 cleanupOnFaceRemoval(m_nameTree, m_fib, m_pit, face);
Junxiao Shidcffdaa2016-07-26 02:23:56 +000085 });
Junxiao Shic34d1672016-12-09 15:57:59 +000086
Davide Pesaventob21bed82021-02-13 00:20:06 -050087 m_fib.afterNewNextHop.connect([this] (const Name& prefix, const fib::NextHop& nextHop) {
88 this->onNewNextHop(prefix, nextHop);
Ju Pan2feb4592019-09-16 20:56:38 +000089 });
90
Junxiao Shic34d1672016-12-09 15:57:59 +000091 m_strategyChoice.setDefaultStrategy(getDefaultStrategyName());
Alexander Afanasyev33b72772014-01-26 23:22:58 -080092}
93
Junxiao Shidcffdaa2016-07-26 02:23:56 +000094Forwarder::~Forwarder() = default;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060095
Junxiao Shi0355e9f2015-09-02 07:24:53 -070096void
Davide Pesavento0498ce82021-06-14 02:02:21 -040097Forwarder::onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -070098{
99 // receive Interest
ashiqopuc7079482019-02-20 05:34:37 +0000100 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName());
101 interest.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700102 ++m_counters.nInInterests;
Junxiao Shic041ca32014-02-25 20:01:15 -0700103
Eric Newberry9d283ad2020-04-12 23:37:17 -0700104 // drop if HopLimit zero, decrement otherwise (if present)
105 if (interest.getHopLimit()) {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400106 if (*interest.getHopLimit() == 0) {
Eric Newberry9d283ad2020-04-12 23:37:17 -0700107 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
108 << " hop-limit=0");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400109 ++ingress.face.getCounters().nInHopLimitZero;
110 // drop
Eric Newberry9d283ad2020-04-12 23:37:17 -0700111 return;
112 }
Eric Newberry9d283ad2020-04-12 23:37:17 -0700113 const_cast<Interest&>(interest).setHopLimit(*interest.getHopLimit() - 1);
114 }
115
Junxiao Shi88884492014-02-15 15:57:43 -0700116 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000117 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700118 scope_prefix::LOCALHOST.isPrefixOf(interest.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700119 if (isViolatingLocalhost) {
ashiqopuc7079482019-02-20 05:34:37 +0000120 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress
121 << " interest=" << interest.getName() << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400122 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700123 return;
124 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700125
Junxiao Shi330136a2016-03-10 04:53:08 -0700126 // detect duplicate Nonce with Dead Nonce List
127 bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), interest.getNonce());
128 if (hasDuplicateNonceInDnl) {
129 // goto Interest loop pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400130 this->onInterestLoop(interest, ingress);
Junxiao Shi330136a2016-03-10 04:53:08 -0700131 return;
132 }
133
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000134 // strip forwarding hint if Interest has reached producer region
135 if (!interest.getForwardingHint().empty() &&
136 m_networkRegionTable.isInProducerRegion(interest.getForwardingHint())) {
ashiqopuc7079482019-02-20 05:34:37 +0000137 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress
138 << " interest=" << interest.getName() << " reaching-producer-region");
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000139 const_cast<Interest&>(interest).setForwardingHint({});
Junxiao Shif9858fd2017-02-01 16:22:44 +0000140 }
141
Junxiao Shid3c792f2014-01-30 00:46:13 -0700142 // PIT insert
Junxiao Shi40631842014-03-01 13:52:37 -0700143 shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;
Junxiao Shic041ca32014-02-25 20:01:15 -0700144
Junxiao Shi330136a2016-03-10 04:53:08 -0700145 // detect duplicate Nonce in PIT entry
ashiqopuc7079482019-02-20 05:34:37 +0000146 int dnw = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), ingress.face);
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000147 bool hasDuplicateNonceInPit = dnw != fw::DUPLICATE_NONCE_NONE;
ashiqopuc7079482019-02-20 05:34:37 +0000148 if (ingress.face.getLinkType() == ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000149 // for p2p face: duplicate Nonce from same incoming face is not loop
150 hasDuplicateNonceInPit = hasDuplicateNonceInPit && !(dnw & fw::DUPLICATE_NONCE_IN_SAME);
151 }
Junxiao Shi330136a2016-03-10 04:53:08 -0700152 if (hasDuplicateNonceInPit) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 // goto Interest loop pipeline
Alexander Afanasyev361b3812022-05-05 11:53:58 -0400154 this->onInterestLoop(interest, ingress);
Alexander Afanasyeva646b422019-07-29 11:45:37 -0400155 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveLoopedInterest(ingress, interest, *pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700156 return;
157 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700158
Junxiao Shif3c07812014-03-11 21:48:49 -0700159 // is pending?
Junxiao Shi4846f372016-04-05 13:39:30 -0700160 if (!pitEntry->hasInRecords()) {
mzhang4eab72492015-02-25 11:16:09 -0600161 m_cs.find(interest,
Davide Pesavento0498ce82021-06-14 02:02:21 -0400162 [=] (const Interest& i, const Data& d) { onContentStoreHit(i, ingress, pitEntry, d); },
163 [=] (const Interest& i) { onContentStoreMiss(i, ingress, pitEntry); });
Junxiao Shid3c792f2014-01-30 00:46:13 -0700164 }
mzhang4eab72492015-02-25 11:16:09 -0600165 else {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400166 this->onContentStoreMiss(interest, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600167 }
168}
Junxiao Shic041ca32014-02-25 20:01:15 -0700169
mzhang4eab72492015-02-25 11:16:09 -0600170void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400171Forwarder::onInterestLoop(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700172{
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700173 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000174 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
175 NFD_LOG_DEBUG("onInterestLoop in=" << ingress
176 << " interest=" << interest.getName() << " drop");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700177 return;
178 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700179
ashiqopuc7079482019-02-20 05:34:37 +0000180 NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " interest=" << interest.getName()
181 << " send-Nack-duplicate");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700182
183 // send Nack with reason=DUPLICATE
184 // note: Don't enter outgoing Nack pipeline because it needs an in-record.
185 lp::Nack nack(interest);
186 nack.setReason(lp::NackReason::DUPLICATE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700187 ingress.face.sendNack(nack);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700188}
189
190void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400191Forwarder::onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
192 const shared_ptr<pit::Entry>& pitEntry)
mzhang4eab72492015-02-25 11:16:09 -0600193{
194 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000195 ++m_counters.nCsMisses;
Alexander Afanasyev276f92c2019-07-27 18:36:48 -0400196 afterCsMiss(interest);
mzhang4eab72492015-02-25 11:16:09 -0600197
Philipp Molla1033342021-06-14 09:34:21 +0200198 // attach HopLimit if configured and not present in Interest
199 if (m_config.defaultHopLimit > 0 && !interest.getHopLimit()) {
200 const_cast<Interest&>(interest).setHopLimit(m_config.defaultHopLimit);
201 }
202
Md Ashiqur Rahman115ea632019-07-06 02:34:31 +0000203 // insert in-record
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000204 pitEntry->insertOrUpdateInRecord(ingress.face, interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700205
Teng Liang7003e0b2018-03-03 16:03:30 -0700206 // set PIT expiry timer to the time that the last PIT in-record expires
Davide Pesaventob31206e2019-04-20 22:34:12 -0400207 auto lastExpiring = std::max_element(pitEntry->in_begin(), pitEntry->in_end(),
208 [] (const auto& a, const auto& b) {
209 return a.getExpiry() < b.getExpiry();
210 });
Teng Liang7003e0b2018-03-03 16:03:30 -0700211 auto lastExpiryFromNow = lastExpiring->getExpiry() - time::steady_clock::now();
212 this->setExpiryTimer(pitEntry, time::duration_cast<time::milliseconds>(lastExpiryFromNow));
Alexander Afanasyeva57f8b42014-07-10 20:11:32 -0700213
Junxiao Shie342e8d2016-09-18 16:48:00 +0000214 // has NextHopFaceId?
Davide Pesaventob31206e2019-04-20 22:34:12 -0400215 auto nextHopTag = interest.getTag<lp::NextHopFaceIdTag>();
Junxiao Shie342e8d2016-09-18 16:48:00 +0000216 if (nextHopTag != nullptr) {
217 // chosen NextHop face exists?
218 Face* nextHopFace = m_faceTable.get(*nextHopTag);
219 if (nextHopFace != nullptr) {
Davide Pesaventob31206e2019-04-20 22:34:12 -0400220 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName()
221 << " nexthop-faceid=" << nextHopFace->getId());
Junxiao Shie342e8d2016-09-18 16:48:00 +0000222 // go to outgoing Interest pipeline
Junxiao Shic5f651f2016-11-17 22:58:12 +0000223 // scope control is unnecessary, because privileged app explicitly wants to forward
Davide Pesavento0498ce82021-06-14 02:02:21 -0400224 this->onOutgoingInterest(interest, *nextHopFace, pitEntry);
Junxiao Shie342e8d2016-09-18 16:48:00 +0000225 }
226 return;
227 }
228
Davide Pesavento05590472021-02-17 15:53:27 -0500229 // dispatch to strategy: after receive Interest
230 m_strategyChoice.findEffectiveStrategy(*pitEntry)
Davide Pesavento0498ce82021-06-14 02:02:21 -0400231 .afterReceiveInterest(interest, FaceEndpoint(ingress.face, 0), pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700232}
233
234void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400235Forwarder::onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
236 const shared_ptr<pit::Entry>& pitEntry, const Data& data)
mzhang4eab72492015-02-25 11:16:09 -0600237{
Vince Lehmanfaa5c0c2015-08-18 12:52:46 -0500238 NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000239 ++m_counters.nCsHits;
Alexander Afanasyev276f92c2019-07-27 18:36:48 -0400240 afterCsHit(interest, data);
mzhang4eab72492015-02-25 11:16:09 -0600241
Junxiao Shicde37ad2015-12-24 01:02:05 -0700242 data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
Junxiao Shic29eb7f2020-04-14 18:20:32 +0000243 data.setTag(interest.getTag<lp::PitToken>());
Davide Pesaventob31206e2019-04-20 22:34:12 -0400244 // FIXME Should we lookup PIT for other Interests that also match the data?
mzhang4eab72492015-02-25 11:16:09 -0600245
Teng Liang6f09ab62018-03-01 20:04:08 -0700246 pitEntry->isSatisfied = true;
247 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
248
Teng Liang85a36632018-03-21 05:59:34 -0700249 // set PIT expiry timer to now
250 this->setExpiryTimer(pitEntry, 0_ms);
mzhang4eab72492015-02-25 11:16:09 -0600251
Alexander Afanasyev89023c82018-08-06 17:28:36 -0400252 beforeSatisfyInterest(*pitEntry, *m_csFace, data);
253 m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(data, FaceEndpoint(*m_csFace, 0), pitEntry);
254
Teng Liang85a36632018-03-21 05:59:34 -0700255 // dispatch to strategy: after Content Store hit
Davide Pesavento0498ce82021-06-14 02:02:21 -0400256 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(data, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600257}
258
Eric Newberry2377ada2020-09-28 22:40:14 -0700259pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400260Forwarder::onOutgoingInterest(const Interest& interest, Face& egress,
261 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700262{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700263 // drop if HopLimit == 0 but sending on non-local face
Teng Liangebc20f62020-06-23 16:55:20 -0700264 if (interest.getHopLimit() == 0 && egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
265 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << pitEntry->getName()
Eric Newberry9d283ad2020-04-12 23:37:17 -0700266 << " non-local hop-limit=0");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400267 ++egress.getCounters().nOutHopLimitZero;
Eric Newberry2377ada2020-09-28 22:40:14 -0700268 return nullptr;
Eric Newberry9d283ad2020-04-12 23:37:17 -0700269 }
270
Teng Liangebc20f62020-06-23 16:55:20 -0700271 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << pitEntry->getName());
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700272
Junxiao Shi4846f372016-04-05 13:39:30 -0700273 // insert out-record
Eric Newberry2377ada2020-09-28 22:40:14 -0700274 auto it = pitEntry->insertOrUpdateOutRecord(egress, interest);
275 BOOST_ASSERT(it != pitEntry->out_end());
Junxiao Shic041ca32014-02-25 20:01:15 -0700276
Junxiao Shid3c792f2014-01-30 00:46:13 -0700277 // send Interest
Teng Liangebc20f62020-06-23 16:55:20 -0700278 egress.sendInterest(interest);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700279 ++m_counters.nOutInterests;
Eric Newberry2377ada2020-09-28 22:40:14 -0700280 return &*it;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700281}
282
283void
Teng Liang6f09ab62018-03-01 20:04:08 -0700284Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shia110f262014-10-12 12:35:20 -0700285{
ashiqopuc7079482019-02-20 05:34:37 +0000286 NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName()
287 << (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
Junxiao Shia110f262014-10-12 12:35:20 -0700288
Alexander Afanasyev89023c82018-08-06 17:28:36 -0400289 if (!pitEntry->isSatisfied) {
290 beforeExpirePendingInterest(*pitEntry);
291 }
292
Junxiao Shia110f262014-10-12 12:35:20 -0700293 // Dead Nonce List insert if necessary
Davide Pesavento3dade002019-03-19 11:29:56 -0600294 this->insertDeadNonceList(*pitEntry, nullptr);
Junxiao Shia110f262014-10-12 12:35:20 -0700295
Ju Pan6eb1ac92018-10-26 16:26:15 +0000296 // Increment satisfied/unsatisfied Interests counter
297 if (pitEntry->isSatisfied) {
298 ++m_counters.nSatisfiedInterests;
299 }
300 else {
301 ++m_counters.nUnsatisfiedInterests;
302 }
303
Junxiao Shif3c07812014-03-11 21:48:49 -0700304 // PIT delete
Davide Pesavento3dade002019-03-19 11:29:56 -0600305 pitEntry->expiryTimer.cancel();
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000306 m_pit.erase(pitEntry.get());
Junxiao Shid3c792f2014-01-30 00:46:13 -0700307}
308
309void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400310Forwarder::onIncomingData(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700311{
312 // receive Data
ashiqopuc7079482019-02-20 05:34:37 +0000313 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName());
314 data.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700315 ++m_counters.nInData;
Junxiao Shic041ca32014-02-25 20:01:15 -0700316
Junxiao Shi88884492014-02-15 15:57:43 -0700317 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000318 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700319 scope_prefix::LOCALHOST.isPrefixOf(data.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700320 if (isViolatingLocalhost) {
ashiqopuc7079482019-02-20 05:34:37 +0000321 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName() << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400322 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700323 return;
324 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700325
Junxiao Shid3c792f2014-01-30 00:46:13 -0700326 // PIT match
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700327 pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data);
Teng Liang43bb2312018-03-26 04:16:42 -0700328 if (pitMatches.size() == 0) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700329 // goto Data unsolicited pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400330 this->onDataUnsolicited(data, ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700331 return;
332 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700333
Junxiao Shid3c792f2014-01-30 00:46:13 -0700334 // CS insert
335 m_cs.insert(data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700336
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500337 std::set<std::pair<Face*, EndpointId>> satisfiedDownstreams;
338 std::multimap<std::pair<Face*, EndpointId>, std::shared_ptr<pit::Entry>> unsatisfiedPitEntries;
Junxiao Shic041ca32014-02-25 20:01:15 -0700339
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500340 for (const auto& pitEntry : pitMatches) {
Teng Liang43bb2312018-03-26 04:16:42 -0700341 NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -0700342
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500343 // invoke PIT satisfy callback
Alexander Afanasyev89023c82018-08-06 17:28:36 -0400344 beforeSatisfyInterest(*pitEntry, ingress.face, data);
Junxiao Shid938a6b2014-05-11 23:40:29 -0700345
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500346 std::set<std::pair<Face*, EndpointId>> unsatisfiedDownstreams;
Alexander Afanasyev361b3812022-05-05 11:53:58 -0400347 m_strategyChoice.findEffectiveStrategy(*pitEntry).satisfyInterest(pitEntry, ingress, data,
348 satisfiedDownstreams, unsatisfiedDownstreams);
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500349 for (const auto& endpoint : unsatisfiedDownstreams) {
350 unsatisfiedPitEntries.emplace(endpoint, pitEntry);
351 }
Teng Liang6f09ab62018-03-01 20:04:08 -0700352
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500353 if (unsatisfiedDownstreams.empty()) {
Teng Liang43bb2312018-03-26 04:16:42 -0700354 // set PIT expiry timer to now
355 this->setExpiryTimer(pitEntry, 0_ms);
356
Teng Liang43bb2312018-03-26 04:16:42 -0700357 // mark PIT satisfied
358 pitEntry->isSatisfied = true;
Junxiao Shida006f52014-05-16 11:18:00 -0700359 }
Teng Liang43bb2312018-03-26 04:16:42 -0700360
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500361 // Dead Nonce List insert if necessary (for out-record of inFace)
362 this->insertDeadNonceList(*pitEntry, &ingress.face);
363
364 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
365
366 // clear PIT entry's in and out records
367 for (const auto& endpoint : satisfiedDownstreams) {
368 pitEntry->deleteInRecord(*endpoint.first);
369 }
370 pitEntry->deleteOutRecord(ingress.face);
371 }
372
373 // now check all unsatisfied entries against to be satisfied downstreams, in case there is
374 // intersect, and those PIT entries will be actually satisfied regardless strategy's choice
375 for (const auto& unsatisfied : unsatisfiedPitEntries) {
376 auto downstreamIt = satisfiedDownstreams.find(unsatisfied.first);
377 if (downstreamIt != satisfiedDownstreams.end()) {
378 auto pitEntry = unsatisfied.second;
379 pitEntry->deleteInRecord(*unsatisfied.first.first);
380
381 if (pitEntry->getInRecords().empty()) { // if nothing left, "closing down" the entry
382 // set PIT expiry timer to now
383 this->setExpiryTimer(pitEntry, 0_ms);
384
385 // mark PIT satisfied
386 pitEntry->isSatisfied = true;
Teng Liang43bb2312018-03-26 04:16:42 -0700387 }
Teng Liang43bb2312018-03-26 04:16:42 -0700388 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700389 }
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500390
391 // foreach pending downstream
392 for (const auto& downstream : satisfiedDownstreams) {
393 if (downstream.first->getId() == ingress.face.getId() &&
394 downstream.second == ingress.endpoint &&
395 downstream.first->getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
396 continue;
397 }
398
Alexander Afanasyev361b3812022-05-05 11:53:58 -0400399 this->onOutgoingData(data, *downstream.first);
Alexander Afanasyev0e97f172020-11-19 12:49:20 -0500400 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700401}
402
403void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400404Forwarder::onDataUnsolicited(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700405{
406 // accept to cache?
Alex Lane6bead9b2020-05-12 19:08:20 -0500407 auto decision = m_unsolicitedDataPolicy->decide(ingress.face, data);
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000408 if (decision == fw::UnsolicitedDataDecision::CACHE) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700409 // CS insert
Junxiao Shif3c07812014-03-11 21:48:49 -0700410 m_cs.insert(data, true);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700411 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700412
Teng Liangebc20f62020-06-23 16:55:20 -0700413 NFD_LOG_DEBUG("onDataUnsolicited in=" << ingress << " data=" << data.getName()
414 << " decision=" << decision);
Alex Lane6bead9b2020-05-12 19:08:20 -0500415 ++m_counters.nUnsolicitedData;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700416}
417
Eric Newberry2377ada2020-09-28 22:40:14 -0700418bool
Teng Liangebc20f62020-06-23 16:55:20 -0700419Forwarder::onOutgoingData(const Data& data, Face& egress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700420{
Teng Liangebc20f62020-06-23 16:55:20 -0700421 if (egress.getId() == face::INVALID_FACEID) {
ashiqopuc7079482019-02-20 05:34:37 +0000422 NFD_LOG_WARN("onOutgoingData out=(invalid) data=" << data.getName());
Eric Newberry2377ada2020-09-28 22:40:14 -0700423 return false;
Junxiao Shi223271b2014-07-03 22:06:13 -0700424 }
Teng Liangebc20f62020-06-23 16:55:20 -0700425 NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName());
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700426
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700427 // /localhost scope control
Teng Liangebc20f62020-06-23 16:55:20 -0700428 bool isViolatingLocalhost = egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700429 scope_prefix::LOCALHOST.isPrefixOf(data.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700430 if (isViolatingLocalhost) {
Teng Liangebc20f62020-06-23 16:55:20 -0700431 NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName()
432 << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400433 // drop
Eric Newberry2377ada2020-09-28 22:40:14 -0700434 return false;
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700435 }
436
Junxiao Shif3c07812014-03-11 21:48:49 -0700437 // TODO traffic manager
Junxiao Shic041ca32014-02-25 20:01:15 -0700438
Junxiao Shid3c792f2014-01-30 00:46:13 -0700439 // send Data
Teng Liangebc20f62020-06-23 16:55:20 -0700440 egress.sendData(data);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700441 ++m_counters.nOutData;
Eric Newberry2377ada2020-09-28 22:40:14 -0700442
443 return true;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700444}
445
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700446void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400447Forwarder::onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700448{
Junxiao Shi0de23a22015-12-03 20:07:02 +0000449 // receive Nack
ashiqopuc7079482019-02-20 05:34:37 +0000450 nack.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700451 ++m_counters.nInNacks;
452
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700453 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000454 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Davide Pesaventob31206e2019-04-20 22:34:12 -0400455 NFD_LOG_DEBUG("onIncomingNack in=" << ingress
456 << " nack=" << nack.getInterest().getName() << "~" << nack.getReason()
457 << " link-type=" << ingress.face.getLinkType());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700458 return;
459 }
460
461 // PIT match
462 shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest());
463 // if no PIT entry found, drop
464 if (pitEntry == nullptr) {
ashiqopuc7079482019-02-20 05:34:37 +0000465 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
466 << "~" << nack.getReason() << " no-PIT-entry");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700467 return;
468 }
469
470 // has out-record?
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000471 auto outRecord = pitEntry->getOutRecord(ingress.face);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700472 // if no out-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700473 if (outRecord == pitEntry->out_end()) {
ashiqopuc7079482019-02-20 05:34:37 +0000474 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
475 << "~" << nack.getReason() << " no-out-record");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700476 return;
477 }
478
479 // if out-record has different Nonce, drop
480 if (nack.getInterest().getNonce() != outRecord->getLastNonce()) {
ashiqopuc7079482019-02-20 05:34:37 +0000481 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
482 << "~" << nack.getReason() << " wrong-Nonce " << nack.getInterest().getNonce()
483 << "!=" << outRecord->getLastNonce());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700484 return;
485 }
486
ashiqopuc7079482019-02-20 05:34:37 +0000487 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
488 << "~" << nack.getReason() << " OK");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700489
490 // record Nack on out-record
491 outRecord->setIncomingNack(nack);
492
Teng Liang7003e0b2018-03-03 16:03:30 -0700493 // set PIT expiry timer to now when all out-record receive Nack
494 if (!fw::hasPendingOutRecords(*pitEntry)) {
495 this->setExpiryTimer(pitEntry, 0_ms);
496 }
497
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700498 // trigger strategy: after receive NACK
Davide Pesavento0498ce82021-06-14 02:02:21 -0400499 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(nack, ingress, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700500}
501
Eric Newberry2377ada2020-09-28 22:40:14 -0700502bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400503Forwarder::onOutgoingNack(const lp::NackHeader& nack, Face& egress,
504 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700505{
Teng Liangebc20f62020-06-23 16:55:20 -0700506 if (egress.getId() == face::INVALID_FACEID) {
ashiqopuc7079482019-02-20 05:34:37 +0000507 NFD_LOG_WARN("onOutgoingNack out=(invalid)"
Davide Pesaventob31206e2019-04-20 22:34:12 -0400508 << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason());
Eric Newberry2377ada2020-09-28 22:40:14 -0700509 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700510 }
511
512 // has in-record?
Teng Liangebc20f62020-06-23 16:55:20 -0700513 auto inRecord = pitEntry->getInRecord(egress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700514
515 // if no in-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700516 if (inRecord == pitEntry->in_end()) {
Teng Liangebc20f62020-06-23 16:55:20 -0700517 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
ashiqopuc7079482019-02-20 05:34:37 +0000518 << " nack=" << pitEntry->getInterest().getName()
519 << "~" << nack.getReason() << " no-in-record");
Eric Newberry2377ada2020-09-28 22:40:14 -0700520 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700521 }
522
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700523 // if multi-access or ad hoc face, drop
Teng Liangebc20f62020-06-23 16:55:20 -0700524 if (egress.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
525 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
Davide Pesaventob31206e2019-04-20 22:34:12 -0400526 << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason()
Teng Liangebc20f62020-06-23 16:55:20 -0700527 << " link-type=" << egress.getLinkType());
Eric Newberry2377ada2020-09-28 22:40:14 -0700528 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700529 }
530
Teng Liangebc20f62020-06-23 16:55:20 -0700531 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
ashiqopuc7079482019-02-20 05:34:37 +0000532 << " nack=" << pitEntry->getInterest().getName()
533 << "~" << nack.getReason() << " OK");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700534
535 // create Nack packet with the Interest from in-record
536 lp::Nack nackPkt(inRecord->getInterest());
537 nackPkt.setHeader(nack);
538
539 // erase in-record
Teng Liangebc20f62020-06-23 16:55:20 -0700540 pitEntry->deleteInRecord(egress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700541
542 // send Nack on face
Teng Liangebc20f62020-06-23 16:55:20 -0700543 egress.sendNack(nackPkt);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700544 ++m_counters.nOutNacks;
Eric Newberry2377ada2020-09-28 22:40:14 -0700545
546 return true;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700547}
548
Eric Newberry41aba102017-11-01 16:42:13 -0700549void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400550Forwarder::onDroppedInterest(const Interest& interest, Face& egress)
Eric Newberry41aba102017-11-01 16:42:13 -0700551{
Davide Pesavento0498ce82021-06-14 02:02:21 -0400552 m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(interest, egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700553}
554
Junxiao Shid3c792f2014-01-30 00:46:13 -0700555void
Ju Pan2feb4592019-09-16 20:56:38 +0000556Forwarder::onNewNextHop(const Name& prefix, const fib::NextHop& nextHop)
557{
558 const auto affectedEntries = this->getNameTree().partialEnumerate(prefix,
559 [&] (const name_tree::Entry& nte) -> std::pair<bool, bool> {
Davide Pesaventob21bed82021-02-13 00:20:06 -0500560 // we ignore an NTE and skip visiting its descendants if that NTE has an
561 // associated FIB entry (1st condition), since in that case the new nexthop
562 // won't affect any PIT entries anywhere in that subtree, *unless* this is
563 // the initial NTE from which the enumeration started (2nd condition), which
564 // must always be considered
565 if (nte.getFibEntry() != nullptr && nte.getName().size() > prefix.size()) {
Ju Pan2feb4592019-09-16 20:56:38 +0000566 return {false, false};
567 }
Davide Pesaventob21bed82021-02-13 00:20:06 -0500568 return {nte.hasPitEntries(), true};
Ju Pan2feb4592019-09-16 20:56:38 +0000569 });
570
571 for (const auto& nte : affectedEntries) {
572 for (const auto& pitEntry : nte.getPitEntries()) {
Davide Pesavento05590472021-02-17 15:53:27 -0500573 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterNewNextHop(nextHop, pitEntry);
Ju Pan2feb4592019-09-16 20:56:38 +0000574 }
575 }
576}
577
578void
Teng Liang7003e0b2018-03-03 16:03:30 -0700579Forwarder::setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700580{
Teng Liang39465c22018-11-12 19:43:04 -0700581 BOOST_ASSERT(pitEntry);
Junxiao Shie1cf4ba2020-06-19 16:40:53 -0600582 duration = std::max(duration, 0_ms);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700583
Davide Pesavento3dade002019-03-19 11:29:56 -0600584 pitEntry->expiryTimer.cancel();
585 pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); });
Junxiao Shia110f262014-10-12 12:35:20 -0700586}
587
588void
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400589Forwarder::insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream)
Junxiao Shia110f262014-10-12 12:35:20 -0700590{
591 // need Dead Nonce List insert?
Eric Newberryf4056d02017-05-26 17:31:53 +0000592 bool needDnl = true;
Teng Liang6f09ab62018-03-01 20:04:08 -0700593 if (pitEntry.isSatisfied) {
594 BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms);
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400595 needDnl = pitEntry.getInterest().getMustBeFresh() &&
Teng Liang6f09ab62018-03-01 20:04:08 -0700596 pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime();
Junxiao Shia110f262014-10-12 12:35:20 -0700597 }
598
599 if (!needDnl) {
600 return;
601 }
602
603 // Dead Nonce List insert
Teng Liangf995f382017-04-04 22:09:39 +0000604 if (upstream == nullptr) {
Junxiao Shia110f262014-10-12 12:35:20 -0700605 // insert all outgoing Nonces
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400606 const auto& outRecords = pitEntry.getOutRecords();
607 std::for_each(outRecords.begin(), outRecords.end(), [&] (const auto& outRecord) {
608 m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce());
609 });
Junxiao Shia110f262014-10-12 12:35:20 -0700610 }
611 else {
612 // insert outgoing Nonce of a specific face
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000613 auto outRecord = pitEntry.getOutRecord(*upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700614 if (outRecord != pitEntry.getOutRecords().end()) {
615 m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
616 }
617 }
618}
619
Philipp Molla1033342021-06-14 09:34:21 +0200620void
621Forwarder::setConfigFile(ConfigFile& configFile)
622{
Davide Pesavento412c9822021-07-02 00:21:05 -0400623 configFile.addSectionHandler(CFG_FORWARDER, [this] (auto&&... args) {
624 processConfig(std::forward<decltype(args)>(args)...);
625 });
Philipp Molla1033342021-06-14 09:34:21 +0200626}
627
628void
629Forwarder::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
630{
631 Config config;
632
633 for (const auto& pair : configSection) {
634 const std::string& key = pair.first;
635 if (key == "default_hop_limit") {
Davide Pesavento412c9822021-07-02 00:21:05 -0400636 config.defaultHopLimit = ConfigFile::parseNumber<uint8_t>(pair, CFG_FORWARDER);
Philipp Molla1033342021-06-14 09:34:21 +0200637 }
638 else {
Davide Pesavento412c9822021-07-02 00:21:05 -0400639 NDN_THROW(ConfigFile::Error("Unrecognized option " + CFG_FORWARDER + "." + key));
Philipp Molla1033342021-06-14 09:34:21 +0200640 }
641 }
642
643 if (!isDryRun) {
644 m_config = config;
645 }
646}
647
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800648} // namespace nfd