blob: 993f773c978184eb5e48b6efa3d1c473ef307f34 [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/*
Mark Theeranantachai195b78a2024-02-14 20:54:44 -05003 * Copyright (c) 2014-2024, 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 Afanasyev18bbf812014-01-29 01:40:23 -080039namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080040
Davide Pesaventoa3148082018-04-12 18:21:54 -040041NFD_LOG_INIT(Forwarder);
Junxiao Shi8c8d2182014-01-30 22:33:00 -070042
Davide Pesavento412c9822021-07-02 00:21:05 -040043const std::string CFG_FORWARDER = "forwarder";
Philipp Molla1033342021-06-14 09:34:21 +020044
Junxiao Shic34d1672016-12-09 15:57:59 +000045static Name
46getDefaultStrategyName()
47{
Davide Pesavento7922d122021-03-05 22:41:23 -050048 return fw::BestRouteStrategy::getStrategyName();
Junxiao Shic34d1672016-12-09 15:57:59 +000049}
50
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040051Forwarder::Forwarder(FaceTable& faceTable)
52 : m_faceTable(faceTable)
53 , m_unsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>())
Junxiao Shifbe8efe2016-08-22 16:02:30 +000054 , m_fib(m_nameTree)
Haowei Yuan78c84d12014-02-27 15:35:13 -060055 , m_pit(m_nameTree)
HangZhangc85a23c2014-03-01 15:55:55 +080056 , m_measurements(m_nameTree)
Junxiao Shic34d1672016-12-09 15:57:59 +000057 , m_strategyChoice(*this)
Alexander Afanasyev33b72772014-01-26 23:22:58 -080058{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040059 m_faceTable.afterAdd.connect([this] (const Face& face) {
Junxiao Shidcffdaa2016-07-26 02:23:56 +000060 face.afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000061 [this, &face] (const Interest& interest, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040062 this->onIncomingInterest(interest, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000063 });
64 face.afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000065 [this, &face] (const Data& data, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040066 this->onIncomingData(data, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000067 });
68 face.afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000069 [this, &face] (const lp::Nack& nack, const EndpointId& endpointId) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040070 this->onIncomingNack(nack, FaceEndpoint(const_cast<Face&>(face), endpointId));
Junxiao Shidcffdaa2016-07-26 02:23:56 +000071 });
Eric Newberry41aba102017-11-01 16:42:13 -070072 face.onDroppedInterest.connect(
73 [this, &face] (const Interest& interest) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040074 this->onDroppedInterest(interest, const_cast<Face&>(face));
Eric Newberry41aba102017-11-01 16:42:13 -070075 });
Junxiao Shidcffdaa2016-07-26 02:23:56 +000076 });
77
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040078 m_faceTable.beforeRemove.connect([this] (const Face& face) {
Junxiao Shi02b73f52016-07-28 01:48:27 +000079 cleanupOnFaceRemoval(m_nameTree, m_fib, m_pit, face);
Junxiao Shidcffdaa2016-07-26 02:23:56 +000080 });
Junxiao Shic34d1672016-12-09 15:57:59 +000081
Davide Pesaventob21bed82021-02-13 00:20:06 -050082 m_fib.afterNewNextHop.connect([this] (const Name& prefix, const fib::NextHop& nextHop) {
83 this->onNewNextHop(prefix, nextHop);
Ju Pan2feb4592019-09-16 20:56:38 +000084 });
85
Junxiao Shic34d1672016-12-09 15:57:59 +000086 m_strategyChoice.setDefaultStrategy(getDefaultStrategyName());
Alexander Afanasyev33b72772014-01-26 23:22:58 -080087}
88
Junxiao Shi0355e9f2015-09-02 07:24:53 -070089void
Davide Pesavento0498ce82021-06-14 02:02:21 -040090Forwarder::onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -070091{
ashiqopuc7079482019-02-20 05:34:37 +000092 interest.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -070093 ++m_counters.nInInterests;
Junxiao Shic041ca32014-02-25 20:01:15 -070094
Alex Lane6bf94c02023-05-22 21:45:45 -050095 // ensure the received Interest has a Nonce
96 auto nonce = interest.getNonce();
97 auto hopLimit = interest.getHopLimit();
98
Eric Newberry9d283ad2020-04-12 23:37:17 -070099 // drop if HopLimit zero, decrement otherwise (if present)
Alex Lane6bf94c02023-05-22 21:45:45 -0500100 if (hopLimit) {
101 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
102 << " nonce=" << nonce << " hop-limit=" << static_cast<unsigned>(*hopLimit));
103 if (*hopLimit == 0) {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400104 ++ingress.face.getCounters().nInHopLimitZero;
105 // drop
Eric Newberry9d283ad2020-04-12 23:37:17 -0700106 return;
107 }
Alex Lane6bf94c02023-05-22 21:45:45 -0500108 const_cast<Interest&>(interest).setHopLimit(*hopLimit - 1);
109 }
110 else {
111 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
112 << " nonce=" << nonce);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700113 }
114
Junxiao Shi88884492014-02-15 15:57:43 -0700115 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000116 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700117 scope_prefix::LOCALHOST.isPrefixOf(interest.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700118 if (isViolatingLocalhost) {
Alex Lane6bf94c02023-05-22 21:45:45 -0500119 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
120 << " nonce=" << nonce << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400121 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700122 return;
123 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700124
Junxiao Shi330136a2016-03-10 04:53:08 -0700125 // detect duplicate Nonce with Dead Nonce List
Alex Lane6bf94c02023-05-22 21:45:45 -0500126 bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), nonce);
Junxiao Shi330136a2016-03-10 04:53:08 -0700127 if (hasDuplicateNonceInDnl) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500128 // go to Interest loop pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400129 this->onInterestLoop(interest, ingress);
Junxiao Shi330136a2016-03-10 04:53:08 -0700130 return;
131 }
132
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000133 // strip forwarding hint if Interest has reached producer region
134 if (!interest.getForwardingHint().empty() &&
135 m_networkRegionTable.isInProducerRegion(interest.getForwardingHint())) {
Alex Lane6bf94c02023-05-22 21:45:45 -0500136 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
137 << " nonce=" << nonce << " reaching-producer-region");
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000138 const_cast<Interest&>(interest).setForwardingHint({});
Junxiao Shif9858fd2017-02-01 16:22:44 +0000139 }
140
Junxiao Shid3c792f2014-01-30 00:46:13 -0700141 // PIT insert
Junxiao Shi40631842014-03-01 13:52:37 -0700142 shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;
Junxiao Shic041ca32014-02-25 20:01:15 -0700143
Junxiao Shi330136a2016-03-10 04:53:08 -0700144 // detect duplicate Nonce in PIT entry
Alex Lane6bf94c02023-05-22 21:45:45 -0500145 int dnw = fw::findDuplicateNonce(*pitEntry, nonce, ingress.face);
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000146 bool hasDuplicateNonceInPit = dnw != fw::DUPLICATE_NONCE_NONE;
ashiqopuc7079482019-02-20 05:34:37 +0000147 if (ingress.face.getLinkType() == ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000148 // for p2p face: duplicate Nonce from same incoming face is not loop
149 hasDuplicateNonceInPit = hasDuplicateNonceInPit && !(dnw & fw::DUPLICATE_NONCE_IN_SAME);
150 }
Junxiao Shi330136a2016-03-10 04:53:08 -0700151 if (hasDuplicateNonceInPit) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500152 // go to Interest loop pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400153 this->onInterestLoop(interest, ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700154 return;
155 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700156
Junxiao Shif3c07812014-03-11 21:48:49 -0700157 // is pending?
Junxiao Shi4846f372016-04-05 13:39:30 -0700158 if (!pitEntry->hasInRecords()) {
mzhang4eab72492015-02-25 11:16:09 -0600159 m_cs.find(interest,
Davide Pesavento0498ce82021-06-14 02:02:21 -0400160 [=] (const Interest& i, const Data& d) { onContentStoreHit(i, ingress, pitEntry, d); },
161 [=] (const Interest& i) { onContentStoreMiss(i, ingress, pitEntry); });
Junxiao Shid3c792f2014-01-30 00:46:13 -0700162 }
mzhang4eab72492015-02-25 11:16:09 -0600163 else {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400164 this->onContentStoreMiss(interest, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600165 }
166}
Junxiao Shic041ca32014-02-25 20:01:15 -0700167
mzhang4eab72492015-02-25 11:16:09 -0600168void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400169Forwarder::onInterestLoop(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700170{
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700171 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000172 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Alex Lane6bf94c02023-05-22 21:45:45 -0500173 NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " interest=" << interest.getName()
174 << " nonce=" << interest.getNonce() << " drop");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700175 return;
176 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700177
ashiqopuc7079482019-02-20 05:34:37 +0000178 NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " interest=" << interest.getName()
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500179 << " nonce=" << interest.getNonce());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700180
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500181 // leave loop handling up to the strategy (e.g., whether to reply with a Nack)
182 m_strategyChoice.findEffectiveStrategy(interest.getName()).onInterestLoop(interest, ingress);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700183}
184
185void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400186Forwarder::onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
187 const shared_ptr<pit::Entry>& pitEntry)
mzhang4eab72492015-02-25 11:16:09 -0600188{
Alex Lane6bf94c02023-05-22 21:45:45 -0500189 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName() << " nonce=" << interest.getNonce());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000190 ++m_counters.nCsMisses;
mzhang4eab72492015-02-25 11:16:09 -0600191
Philipp Molla1033342021-06-14 09:34:21 +0200192 // attach HopLimit if configured and not present in Interest
193 if (m_config.defaultHopLimit > 0 && !interest.getHopLimit()) {
194 const_cast<Interest&>(interest).setHopLimit(m_config.defaultHopLimit);
195 }
196
Md Ashiqur Rahman115ea632019-07-06 02:34:31 +0000197 // insert in-record
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000198 pitEntry->insertOrUpdateInRecord(ingress.face, interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700199
Teng Liang7003e0b2018-03-03 16:03:30 -0700200 // set PIT expiry timer to the time that the last PIT in-record expires
Davide Pesaventob31206e2019-04-20 22:34:12 -0400201 auto lastExpiring = std::max_element(pitEntry->in_begin(), pitEntry->in_end(),
202 [] (const auto& a, const auto& b) {
203 return a.getExpiry() < b.getExpiry();
204 });
Teng Liang7003e0b2018-03-03 16:03:30 -0700205 auto lastExpiryFromNow = lastExpiring->getExpiry() - time::steady_clock::now();
206 this->setExpiryTimer(pitEntry, time::duration_cast<time::milliseconds>(lastExpiryFromNow));
Alexander Afanasyeva57f8b42014-07-10 20:11:32 -0700207
Junxiao Shie342e8d2016-09-18 16:48:00 +0000208 // has NextHopFaceId?
Davide Pesaventob31206e2019-04-20 22:34:12 -0400209 auto nextHopTag = interest.getTag<lp::NextHopFaceIdTag>();
Junxiao Shie342e8d2016-09-18 16:48:00 +0000210 if (nextHopTag != nullptr) {
211 // chosen NextHop face exists?
212 Face* nextHopFace = m_faceTable.get(*nextHopTag);
213 if (nextHopFace != nullptr) {
Davide Pesaventob31206e2019-04-20 22:34:12 -0400214 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName()
Alex Lane6bf94c02023-05-22 21:45:45 -0500215 << " nonce=" << interest.getNonce() << " nexthop-faceid=" << nextHopFace->getId());
Junxiao Shie342e8d2016-09-18 16:48:00 +0000216 // go to outgoing Interest pipeline
Junxiao Shic5f651f2016-11-17 22:58:12 +0000217 // scope control is unnecessary, because privileged app explicitly wants to forward
Davide Pesavento0498ce82021-06-14 02:02:21 -0400218 this->onOutgoingInterest(interest, *nextHopFace, pitEntry);
Junxiao Shie342e8d2016-09-18 16:48:00 +0000219 }
220 return;
221 }
222
Davide Pesavento05590472021-02-17 15:53:27 -0500223 // dispatch to strategy: after receive Interest
224 m_strategyChoice.findEffectiveStrategy(*pitEntry)
Teng Liangd94b7b32022-07-10 21:29:37 +0800225 .afterReceiveInterest(interest, FaceEndpoint(ingress.face), pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700226}
227
228void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400229Forwarder::onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
230 const shared_ptr<pit::Entry>& pitEntry, const Data& data)
mzhang4eab72492015-02-25 11:16:09 -0600231{
Alex Lane6bf94c02023-05-22 21:45:45 -0500232 NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName() << " nonce=" << interest.getNonce());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000233 ++m_counters.nCsHits;
mzhang4eab72492015-02-25 11:16:09 -0600234
Junxiao Shicde37ad2015-12-24 01:02:05 -0700235 data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
Junxiao Shic29eb7f2020-04-14 18:20:32 +0000236 data.setTag(interest.getTag<lp::PitToken>());
Davide Pesaventob31206e2019-04-20 22:34:12 -0400237 // FIXME Should we lookup PIT for other Interests that also match the data?
mzhang4eab72492015-02-25 11:16:09 -0600238
Teng Liang6f09ab62018-03-01 20:04:08 -0700239 pitEntry->isSatisfied = true;
240 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
241
Teng Liang85a36632018-03-21 05:59:34 -0700242 // set PIT expiry timer to now
243 this->setExpiryTimer(pitEntry, 0_ms);
mzhang4eab72492015-02-25 11:16:09 -0600244
Teng Liang85a36632018-03-21 05:59:34 -0700245 // dispatch to strategy: after Content Store hit
Davide Pesavento0498ce82021-06-14 02:02:21 -0400246 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(data, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600247}
248
Eric Newberry2377ada2020-09-28 22:40:14 -0700249pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400250Forwarder::onOutgoingInterest(const Interest& interest, Face& egress,
251 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700252{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700253 // drop if HopLimit == 0 but sending on non-local face
Teng Liangebc20f62020-06-23 16:55:20 -0700254 if (interest.getHopLimit() == 0 && egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
Alex Lane6bf94c02023-05-22 21:45:45 -0500255 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << interest.getName()
256 << " nonce=" << interest.getNonce() << " non-local hop-limit=0");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400257 ++egress.getCounters().nOutHopLimitZero;
Eric Newberry2377ada2020-09-28 22:40:14 -0700258 return nullptr;
Eric Newberry9d283ad2020-04-12 23:37:17 -0700259 }
260
Alex Lane6bf94c02023-05-22 21:45:45 -0500261 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << interest.getName()
262 << " nonce=" << interest.getNonce());
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700263
Junxiao Shi4846f372016-04-05 13:39:30 -0700264 // insert out-record
Eric Newberry2377ada2020-09-28 22:40:14 -0700265 auto it = pitEntry->insertOrUpdateOutRecord(egress, interest);
266 BOOST_ASSERT(it != pitEntry->out_end());
Junxiao Shic041ca32014-02-25 20:01:15 -0700267
Junxiao Shid3c792f2014-01-30 00:46:13 -0700268 // send Interest
Teng Liangebc20f62020-06-23 16:55:20 -0700269 egress.sendInterest(interest);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700270 ++m_counters.nOutInterests;
Davide Pesavento95afc6d2023-08-02 20:50:25 -0400271
Eric Newberry2377ada2020-09-28 22:40:14 -0700272 return &*it;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700273}
274
275void
Teng Liang6f09ab62018-03-01 20:04:08 -0700276Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shia110f262014-10-12 12:35:20 -0700277{
ashiqopuc7079482019-02-20 05:34:37 +0000278 NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName()
279 << (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
Junxiao Shia110f262014-10-12 12:35:20 -0700280
281 // Dead Nonce List insert if necessary
Davide Pesavento3dade002019-03-19 11:29:56 -0600282 this->insertDeadNonceList(*pitEntry, nullptr);
Junxiao Shia110f262014-10-12 12:35:20 -0700283
Ju Pan6eb1ac92018-10-26 16:26:15 +0000284 // Increment satisfied/unsatisfied Interests counter
285 if (pitEntry->isSatisfied) {
286 ++m_counters.nSatisfiedInterests;
287 }
288 else {
289 ++m_counters.nUnsatisfiedInterests;
290 }
291
Junxiao Shif3c07812014-03-11 21:48:49 -0700292 // PIT delete
Davide Pesavento3dade002019-03-19 11:29:56 -0600293 pitEntry->expiryTimer.cancel();
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000294 m_pit.erase(pitEntry.get());
Junxiao Shid3c792f2014-01-30 00:46:13 -0700295}
296
297void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400298Forwarder::onIncomingData(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700299{
ashiqopuc7079482019-02-20 05:34:37 +0000300 data.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700301 ++m_counters.nInData;
Alex Lane6bf94c02023-05-22 21:45:45 -0500302 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName());
Junxiao Shic041ca32014-02-25 20:01:15 -0700303
Junxiao Shi88884492014-02-15 15:57:43 -0700304 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000305 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700306 scope_prefix::LOCALHOST.isPrefixOf(data.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700307 if (isViolatingLocalhost) {
ashiqopuc7079482019-02-20 05:34:37 +0000308 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName() << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400309 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700310 return;
311 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700312
Junxiao Shid3c792f2014-01-30 00:46:13 -0700313 // PIT match
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700314 pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data);
Teng Liang43bb2312018-03-26 04:16:42 -0700315 if (pitMatches.size() == 0) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500316 // go to Data unsolicited pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400317 this->onDataUnsolicited(data, ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700318 return;
319 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700320
Junxiao Shid3c792f2014-01-30 00:46:13 -0700321 // CS insert
322 m_cs.insert(data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700323
Teng Liang43bb2312018-03-26 04:16:42 -0700324 // when only one PIT entry is matched, trigger strategy: after receive Data
325 if (pitMatches.size() == 1) {
326 auto& pitEntry = pitMatches.front();
Junxiao Shic041ca32014-02-25 20:01:15 -0700327
Teng Liang43bb2312018-03-26 04:16:42 -0700328 NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -0700329
Teng Liang7003e0b2018-03-03 16:03:30 -0700330 // set PIT expiry timer to now
331 this->setExpiryTimer(pitEntry, 0_ms);
332
Teng Liang43bb2312018-03-26 04:16:42 -0700333 // trigger strategy: after receive Data
Davide Pesavento0498ce82021-06-14 02:02:21 -0400334 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveData(data, ingress, pitEntry);
Junxiao Shid938a6b2014-05-11 23:40:29 -0700335
Teng Liang43bb2312018-03-26 04:16:42 -0700336 // mark PIT satisfied
Teng Liang6f09ab62018-03-01 20:04:08 -0700337 pitEntry->isSatisfied = true;
338 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
339
Teng Liangebc20f62020-06-23 16:55:20 -0700340 // Dead Nonce List insert if necessary (for out-record of ingress face)
ashiqopuc7079482019-02-20 05:34:37 +0000341 this->insertDeadNonceList(*pitEntry, &ingress.face);
Junxiao Shia110f262014-10-12 12:35:20 -0700342
Teng Liang43bb2312018-03-26 04:16:42 -0700343 // delete PIT entry's out-record
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000344 pitEntry->deleteOutRecord(ingress.face);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700345 }
Teng Liang43bb2312018-03-26 04:16:42 -0700346 // when more than one PIT entry is matched, trigger strategy: before satisfy Interest,
347 // and send Data to all matched out faces
348 else {
Teng Liangebc20f62020-06-23 16:55:20 -0700349 std::set<Face*> pendingDownstreams;
Teng Liang43bb2312018-03-26 04:16:42 -0700350 auto now = time::steady_clock::now();
Junxiao Shic041ca32014-02-25 20:01:15 -0700351
Davide Pesaventob31206e2019-04-20 22:34:12 -0400352 for (const auto& pitEntry : pitMatches) {
Teng Liang43bb2312018-03-26 04:16:42 -0700353 NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
354
355 // remember pending downstreams
356 for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
357 if (inRecord.getExpiry() > now) {
Teng Liangebc20f62020-06-23 16:55:20 -0700358 pendingDownstreams.insert(&inRecord.getFace());
Teng Liang43bb2312018-03-26 04:16:42 -0700359 }
360 }
361
362 // set PIT expiry timer to now
363 this->setExpiryTimer(pitEntry, 0_ms);
364
365 // invoke PIT satisfy callback
Davide Pesavento0498ce82021-06-14 02:02:21 -0400366 m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(data, ingress, pitEntry);
Teng Liang43bb2312018-03-26 04:16:42 -0700367
368 // mark PIT satisfied
369 pitEntry->isSatisfied = true;
370 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
371
Teng Liangebc20f62020-06-23 16:55:20 -0700372 // Dead Nonce List insert if necessary (for out-record of ingress face)
ashiqopuc7079482019-02-20 05:34:37 +0000373 this->insertDeadNonceList(*pitEntry, &ingress.face);
Teng Liang43bb2312018-03-26 04:16:42 -0700374
375 // clear PIT entry's in and out records
376 pitEntry->clearInRecords();
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000377 pitEntry->deleteOutRecord(ingress.face);
Junxiao Shida006f52014-05-16 11:18:00 -0700378 }
Teng Liang43bb2312018-03-26 04:16:42 -0700379
Davide Pesavento4d2e7882024-02-15 23:00:21 -0500380 for (Face* pendingDownstream : pendingDownstreams) {
Teng Liangebc20f62020-06-23 16:55:20 -0700381 if (pendingDownstream->getId() == ingress.face.getId() &&
382 pendingDownstream->getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
Teng Liang43bb2312018-03-26 04:16:42 -0700383 continue;
384 }
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500385 // go to outgoing Data pipeline
Teng Liangebc20f62020-06-23 16:55:20 -0700386 this->onOutgoingData(data, *pendingDownstream);
Teng Liang43bb2312018-03-26 04:16:42 -0700387 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700388 }
389}
390
391void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400392Forwarder::onDataUnsolicited(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700393{
Alex Lane6bf94c02023-05-22 21:45:45 -0500394 ++m_counters.nUnsolicitedData;
395
Junxiao Shid3c792f2014-01-30 00:46:13 -0700396 // accept to cache?
Alex Lane6bead9b2020-05-12 19:08:20 -0500397 auto decision = m_unsolicitedDataPolicy->decide(ingress.face, data);
Alex Lane6bf94c02023-05-22 21:45:45 -0500398 NFD_LOG_DEBUG("onDataUnsolicited in=" << ingress << " data=" << data.getName()
399 << " decision=" << decision);
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000400 if (decision == fw::UnsolicitedDataDecision::CACHE) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700401 // CS insert
Junxiao Shif3c07812014-03-11 21:48:49 -0700402 m_cs.insert(data, true);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700403 }
404}
405
Eric Newberry2377ada2020-09-28 22:40:14 -0700406bool
Teng Liangebc20f62020-06-23 16:55:20 -0700407Forwarder::onOutgoingData(const Data& data, Face& egress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700408{
Teng Liangebc20f62020-06-23 16:55:20 -0700409 if (egress.getId() == face::INVALID_FACEID) {
ashiqopuc7079482019-02-20 05:34:37 +0000410 NFD_LOG_WARN("onOutgoingData out=(invalid) data=" << data.getName());
Eric Newberry2377ada2020-09-28 22:40:14 -0700411 return false;
Junxiao Shi223271b2014-07-03 22:06:13 -0700412 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700413
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700414 // /localhost scope control
Teng Liangebc20f62020-06-23 16:55:20 -0700415 bool isViolatingLocalhost = egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700416 scope_prefix::LOCALHOST.isPrefixOf(data.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700417 if (isViolatingLocalhost) {
Teng Liangebc20f62020-06-23 16:55:20 -0700418 NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName()
419 << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400420 // drop
Eric Newberry2377ada2020-09-28 22:40:14 -0700421 return false;
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700422 }
423
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500424 NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName());
Junxiao Shic041ca32014-02-25 20:01:15 -0700425
Junxiao Shid3c792f2014-01-30 00:46:13 -0700426 // send Data
Teng Liangebc20f62020-06-23 16:55:20 -0700427 egress.sendData(data);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700428 ++m_counters.nOutData;
Eric Newberry2377ada2020-09-28 22:40:14 -0700429
430 return true;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700431}
432
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700433void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400434Forwarder::onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700435{
ashiqopuc7079482019-02-20 05:34:37 +0000436 nack.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700437 ++m_counters.nInNacks;
438
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700439 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000440 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Alex Lane6bf94c02023-05-22 21:45:45 -0500441 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
442 << "~" << nack.getReason() << " link-type=" << ingress.face.getLinkType());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700443 return;
444 }
445
446 // PIT match
447 shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest());
448 // if no PIT entry found, drop
449 if (pitEntry == nullptr) {
ashiqopuc7079482019-02-20 05:34:37 +0000450 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
Alex Lane6bf94c02023-05-22 21:45:45 -0500451 << "~" << nack.getReason() << " no-pit-entry");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700452 return;
453 }
454
455 // has out-record?
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500456 auto outRecord = pitEntry->findOutRecord(ingress.face);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700457 // if no out-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700458 if (outRecord == pitEntry->out_end()) {
ashiqopuc7079482019-02-20 05:34:37 +0000459 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
460 << "~" << nack.getReason() << " no-out-record");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700461 return;
462 }
463
464 // if out-record has different Nonce, drop
465 if (nack.getInterest().getNonce() != outRecord->getLastNonce()) {
ashiqopuc7079482019-02-20 05:34:37 +0000466 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
Alex Lane6bf94c02023-05-22 21:45:45 -0500467 << "~" << nack.getReason() << " nonce-mismatch " << nack.getInterest().getNonce()
ashiqopuc7079482019-02-20 05:34:37 +0000468 << "!=" << outRecord->getLastNonce());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700469 return;
470 }
471
ashiqopuc7079482019-02-20 05:34:37 +0000472 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
Alex Lane6bf94c02023-05-22 21:45:45 -0500473 << "~" << nack.getReason());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700474
475 // record Nack on out-record
476 outRecord->setIncomingNack(nack);
477
Teng Liang7003e0b2018-03-03 16:03:30 -0700478 // set PIT expiry timer to now when all out-record receive Nack
479 if (!fw::hasPendingOutRecords(*pitEntry)) {
480 this->setExpiryTimer(pitEntry, 0_ms);
481 }
482
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500483 // trigger strategy: after receive Nack
Davide Pesavento0498ce82021-06-14 02:02:21 -0400484 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(nack, ingress, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700485}
486
Eric Newberry2377ada2020-09-28 22:40:14 -0700487bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400488Forwarder::onOutgoingNack(const lp::NackHeader& nack, Face& egress,
489 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700490{
Teng Liangebc20f62020-06-23 16:55:20 -0700491 if (egress.getId() == face::INVALID_FACEID) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500492 NFD_LOG_WARN("onOutgoingNack out=(invalid)" << " nack=" << pitEntry->getName()
493 << "~" << nack.getReason());
Eric Newberry2377ada2020-09-28 22:40:14 -0700494 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700495 }
496
497 // has in-record?
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500498 auto inRecord = pitEntry->findInRecord(egress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700499
500 // if no in-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700501 if (inRecord == pitEntry->in_end()) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500502 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId() << " nack=" << pitEntry->getName()
ashiqopuc7079482019-02-20 05:34:37 +0000503 << "~" << nack.getReason() << " no-in-record");
Eric Newberry2377ada2020-09-28 22:40:14 -0700504 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700505 }
506
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700507 // if multi-access or ad hoc face, drop
Teng Liangebc20f62020-06-23 16:55:20 -0700508 if (egress.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500509 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId() << " nack=" << pitEntry->getName()
510 << "~" << nack.getReason() << " link-type=" << egress.getLinkType());
Eric Newberry2377ada2020-09-28 22:40:14 -0700511 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700512 }
513
Mark Theeranantachai195b78a2024-02-14 20:54:44 -0500514 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId() << " nack=" << pitEntry->getName()
515 << "~" << nack.getReason());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700516
517 // create Nack packet with the Interest from in-record
518 lp::Nack nackPkt(inRecord->getInterest());
519 nackPkt.setHeader(nack);
520
521 // erase in-record
Davide Pesavento4d2e7882024-02-15 23:00:21 -0500522 pitEntry->deleteInRecord(inRecord);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700523
524 // send Nack on face
Teng Liangebc20f62020-06-23 16:55:20 -0700525 egress.sendNack(nackPkt);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700526 ++m_counters.nOutNacks;
Eric Newberry2377ada2020-09-28 22:40:14 -0700527
528 return true;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700529}
530
Eric Newberry41aba102017-11-01 16:42:13 -0700531void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400532Forwarder::onDroppedInterest(const Interest& interest, Face& egress)
Eric Newberry41aba102017-11-01 16:42:13 -0700533{
Davide Pesavento0498ce82021-06-14 02:02:21 -0400534 m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(interest, egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700535}
536
Junxiao Shid3c792f2014-01-30 00:46:13 -0700537void
Ju Pan2feb4592019-09-16 20:56:38 +0000538Forwarder::onNewNextHop(const Name& prefix, const fib::NextHop& nextHop)
539{
540 const auto affectedEntries = this->getNameTree().partialEnumerate(prefix,
541 [&] (const name_tree::Entry& nte) -> std::pair<bool, bool> {
Davide Pesaventob21bed82021-02-13 00:20:06 -0500542 // we ignore an NTE and skip visiting its descendants if that NTE has an
543 // associated FIB entry (1st condition), since in that case the new nexthop
544 // won't affect any PIT entries anywhere in that subtree, *unless* this is
545 // the initial NTE from which the enumeration started (2nd condition), which
546 // must always be considered
547 if (nte.getFibEntry() != nullptr && nte.getName().size() > prefix.size()) {
Ju Pan2feb4592019-09-16 20:56:38 +0000548 return {false, false};
549 }
Davide Pesaventob21bed82021-02-13 00:20:06 -0500550 return {nte.hasPitEntries(), true};
Ju Pan2feb4592019-09-16 20:56:38 +0000551 });
552
553 for (const auto& nte : affectedEntries) {
554 for (const auto& pitEntry : nte.getPitEntries()) {
Davide Pesavento05590472021-02-17 15:53:27 -0500555 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterNewNextHop(nextHop, pitEntry);
Ju Pan2feb4592019-09-16 20:56:38 +0000556 }
557 }
558}
559
560void
Teng Liang7003e0b2018-03-03 16:03:30 -0700561Forwarder::setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700562{
Teng Liang39465c22018-11-12 19:43:04 -0700563 BOOST_ASSERT(pitEntry);
Junxiao Shie1cf4ba2020-06-19 16:40:53 -0600564 duration = std::max(duration, 0_ms);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700565
Davide Pesavento3dade002019-03-19 11:29:56 -0600566 pitEntry->expiryTimer.cancel();
567 pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); });
Junxiao Shia110f262014-10-12 12:35:20 -0700568}
569
570void
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400571Forwarder::insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream)
Junxiao Shia110f262014-10-12 12:35:20 -0700572{
573 // need Dead Nonce List insert?
Eric Newberryf4056d02017-05-26 17:31:53 +0000574 bool needDnl = true;
Teng Liang6f09ab62018-03-01 20:04:08 -0700575 if (pitEntry.isSatisfied) {
576 BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms);
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400577 needDnl = pitEntry.getInterest().getMustBeFresh() &&
Teng Liang6f09ab62018-03-01 20:04:08 -0700578 pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime();
Junxiao Shia110f262014-10-12 12:35:20 -0700579 }
580
581 if (!needDnl) {
582 return;
583 }
584
585 // Dead Nonce List insert
Teng Liangf995f382017-04-04 22:09:39 +0000586 if (upstream == nullptr) {
Junxiao Shia110f262014-10-12 12:35:20 -0700587 // insert all outgoing Nonces
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500588 std::for_each(pitEntry.out_begin(), pitEntry.out_end(), [&] (const auto& outRecord) {
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400589 m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce());
590 });
Junxiao Shia110f262014-10-12 12:35:20 -0700591 }
592 else {
593 // insert outgoing Nonce of a specific face
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500594 auto outRecord = pitEntry.findOutRecord(*upstream);
595 if (outRecord != pitEntry.out_end()) {
Junxiao Shia110f262014-10-12 12:35:20 -0700596 m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
597 }
598 }
599}
600
Philipp Molla1033342021-06-14 09:34:21 +0200601void
602Forwarder::setConfigFile(ConfigFile& configFile)
603{
Davide Pesavento412c9822021-07-02 00:21:05 -0400604 configFile.addSectionHandler(CFG_FORWARDER, [this] (auto&&... args) {
605 processConfig(std::forward<decltype(args)>(args)...);
606 });
Philipp Molla1033342021-06-14 09:34:21 +0200607}
608
609void
610Forwarder::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
611{
612 Config config;
613
614 for (const auto& pair : configSection) {
615 const std::string& key = pair.first;
616 if (key == "default_hop_limit") {
Davide Pesavento412c9822021-07-02 00:21:05 -0400617 config.defaultHopLimit = ConfigFile::parseNumber<uint8_t>(pair, CFG_FORWARDER);
Philipp Molla1033342021-06-14 09:34:21 +0200618 }
619 else {
Davide Pesavento412c9822021-07-02 00:21:05 -0400620 NDN_THROW(ConfigFile::Error("Unrecognized option " + CFG_FORWARDER + "." + key));
Philipp Molla1033342021-06-14 09:34:21 +0200621 }
622 }
623
624 if (!isDryRun) {
625 m_config = config;
626 }
627}
628
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800629} // namespace nfd