blob: d984f0cb01432b9ac5b47b29de998559209622e3 [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 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 Shidcffdaa2016-07-26 02:23:56 +000089Forwarder::~Forwarder() = default;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060090
Junxiao Shi0355e9f2015-09-02 07:24:53 -070091void
Davide Pesavento0498ce82021-06-14 02:02:21 -040092Forwarder::onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -070093{
94 // receive Interest
ashiqopuc7079482019-02-20 05:34:37 +000095 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName());
96 interest.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -070097 ++m_counters.nInInterests;
Junxiao Shic041ca32014-02-25 20:01:15 -070098
Eric Newberry9d283ad2020-04-12 23:37:17 -070099 // drop if HopLimit zero, decrement otherwise (if present)
100 if (interest.getHopLimit()) {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400101 if (*interest.getHopLimit() == 0) {
Eric Newberry9d283ad2020-04-12 23:37:17 -0700102 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
103 << " hop-limit=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 }
Eric Newberry9d283ad2020-04-12 23:37:17 -0700108 const_cast<Interest&>(interest).setHopLimit(*interest.getHopLimit() - 1);
109 }
110
Junxiao Shi88884492014-02-15 15:57:43 -0700111 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000112 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700113 scope_prefix::LOCALHOST.isPrefixOf(interest.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700114 if (isViolatingLocalhost) {
ashiqopuc7079482019-02-20 05:34:37 +0000115 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress
116 << " interest=" << interest.getName() << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400117 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700118 return;
119 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700120
Junxiao Shi330136a2016-03-10 04:53:08 -0700121 // detect duplicate Nonce with Dead Nonce List
122 bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), interest.getNonce());
123 if (hasDuplicateNonceInDnl) {
124 // goto Interest loop pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400125 this->onInterestLoop(interest, ingress);
Junxiao Shi330136a2016-03-10 04:53:08 -0700126 return;
127 }
128
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000129 // strip forwarding hint if Interest has reached producer region
130 if (!interest.getForwardingHint().empty() &&
131 m_networkRegionTable.isInProducerRegion(interest.getForwardingHint())) {
ashiqopuc7079482019-02-20 05:34:37 +0000132 NFD_LOG_DEBUG("onIncomingInterest in=" << ingress
133 << " interest=" << interest.getName() << " reaching-producer-region");
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000134 const_cast<Interest&>(interest).setForwardingHint({});
Junxiao Shif9858fd2017-02-01 16:22:44 +0000135 }
136
Junxiao Shid3c792f2014-01-30 00:46:13 -0700137 // PIT insert
Junxiao Shi40631842014-03-01 13:52:37 -0700138 shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;
Junxiao Shic041ca32014-02-25 20:01:15 -0700139
Junxiao Shi330136a2016-03-10 04:53:08 -0700140 // detect duplicate Nonce in PIT entry
ashiqopuc7079482019-02-20 05:34:37 +0000141 int dnw = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), ingress.face);
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000142 bool hasDuplicateNonceInPit = dnw != fw::DUPLICATE_NONCE_NONE;
ashiqopuc7079482019-02-20 05:34:37 +0000143 if (ingress.face.getLinkType() == ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Junxiao Shi2fe3af02017-03-04 17:24:19 +0000144 // for p2p face: duplicate Nonce from same incoming face is not loop
145 hasDuplicateNonceInPit = hasDuplicateNonceInPit && !(dnw & fw::DUPLICATE_NONCE_IN_SAME);
146 }
Junxiao Shi330136a2016-03-10 04:53:08 -0700147 if (hasDuplicateNonceInPit) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700148 // goto Interest loop pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400149 this->onInterestLoop(interest, ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700150 return;
151 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700152
Junxiao Shif3c07812014-03-11 21:48:49 -0700153 // is pending?
Junxiao Shi4846f372016-04-05 13:39:30 -0700154 if (!pitEntry->hasInRecords()) {
mzhang4eab72492015-02-25 11:16:09 -0600155 m_cs.find(interest,
Davide Pesavento0498ce82021-06-14 02:02:21 -0400156 [=] (const Interest& i, const Data& d) { onContentStoreHit(i, ingress, pitEntry, d); },
157 [=] (const Interest& i) { onContentStoreMiss(i, ingress, pitEntry); });
Junxiao Shid3c792f2014-01-30 00:46:13 -0700158 }
mzhang4eab72492015-02-25 11:16:09 -0600159 else {
Davide Pesavento0498ce82021-06-14 02:02:21 -0400160 this->onContentStoreMiss(interest, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600161 }
162}
Junxiao Shic041ca32014-02-25 20:01:15 -0700163
mzhang4eab72492015-02-25 11:16:09 -0600164void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400165Forwarder::onInterestLoop(const Interest& interest, const FaceEndpoint& ingress)
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700166{
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700167 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000168 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
169 NFD_LOG_DEBUG("onInterestLoop in=" << ingress
170 << " interest=" << interest.getName() << " drop");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700171 return;
172 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700173
ashiqopuc7079482019-02-20 05:34:37 +0000174 NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " interest=" << interest.getName()
175 << " send-Nack-duplicate");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700176
177 // send Nack with reason=DUPLICATE
178 // note: Don't enter outgoing Nack pipeline because it needs an in-record.
179 lp::Nack nack(interest);
180 nack.setReason(lp::NackReason::DUPLICATE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700181 ingress.face.sendNack(nack);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700182}
183
184void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400185Forwarder::onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
186 const shared_ptr<pit::Entry>& pitEntry)
mzhang4eab72492015-02-25 11:16:09 -0600187{
188 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000189 ++m_counters.nCsMisses;
mzhang4eab72492015-02-25 11:16:09 -0600190
Philipp Molla1033342021-06-14 09:34:21 +0200191 // attach HopLimit if configured and not present in Interest
192 if (m_config.defaultHopLimit > 0 && !interest.getHopLimit()) {
193 const_cast<Interest&>(interest).setHopLimit(m_config.defaultHopLimit);
194 }
195
Md Ashiqur Rahman115ea632019-07-06 02:34:31 +0000196 // insert in-record
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000197 pitEntry->insertOrUpdateInRecord(ingress.face, interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700198
Teng Liang7003e0b2018-03-03 16:03:30 -0700199 // set PIT expiry timer to the time that the last PIT in-record expires
Davide Pesaventob31206e2019-04-20 22:34:12 -0400200 auto lastExpiring = std::max_element(pitEntry->in_begin(), pitEntry->in_end(),
201 [] (const auto& a, const auto& b) {
202 return a.getExpiry() < b.getExpiry();
203 });
Teng Liang7003e0b2018-03-03 16:03:30 -0700204 auto lastExpiryFromNow = lastExpiring->getExpiry() - time::steady_clock::now();
205 this->setExpiryTimer(pitEntry, time::duration_cast<time::milliseconds>(lastExpiryFromNow));
Alexander Afanasyeva57f8b42014-07-10 20:11:32 -0700206
Junxiao Shie342e8d2016-09-18 16:48:00 +0000207 // has NextHopFaceId?
Davide Pesaventob31206e2019-04-20 22:34:12 -0400208 auto nextHopTag = interest.getTag<lp::NextHopFaceIdTag>();
Junxiao Shie342e8d2016-09-18 16:48:00 +0000209 if (nextHopTag != nullptr) {
210 // chosen NextHop face exists?
211 Face* nextHopFace = m_faceTable.get(*nextHopTag);
212 if (nextHopFace != nullptr) {
Davide Pesaventob31206e2019-04-20 22:34:12 -0400213 NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName()
214 << " nexthop-faceid=" << nextHopFace->getId());
Junxiao Shie342e8d2016-09-18 16:48:00 +0000215 // go to outgoing Interest pipeline
Junxiao Shic5f651f2016-11-17 22:58:12 +0000216 // scope control is unnecessary, because privileged app explicitly wants to forward
Davide Pesavento0498ce82021-06-14 02:02:21 -0400217 this->onOutgoingInterest(interest, *nextHopFace, pitEntry);
Junxiao Shie342e8d2016-09-18 16:48:00 +0000218 }
219 return;
220 }
221
Davide Pesavento05590472021-02-17 15:53:27 -0500222 // dispatch to strategy: after receive Interest
223 m_strategyChoice.findEffectiveStrategy(*pitEntry)
Davide Pesavento0498ce82021-06-14 02:02:21 -0400224 .afterReceiveInterest(interest, FaceEndpoint(ingress.face, 0), pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700225}
226
227void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400228Forwarder::onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
229 const shared_ptr<pit::Entry>& pitEntry, const Data& data)
mzhang4eab72492015-02-25 11:16:09 -0600230{
Vince Lehmanfaa5c0c2015-08-18 12:52:46 -0500231 NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
Junxiao Shi06a1eab2017-09-04 13:13:02 +0000232 ++m_counters.nCsHits;
mzhang4eab72492015-02-25 11:16:09 -0600233
Junxiao Shicde37ad2015-12-24 01:02:05 -0700234 data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
Junxiao Shic29eb7f2020-04-14 18:20:32 +0000235 data.setTag(interest.getTag<lp::PitToken>());
Davide Pesaventob31206e2019-04-20 22:34:12 -0400236 // FIXME Should we lookup PIT for other Interests that also match the data?
mzhang4eab72492015-02-25 11:16:09 -0600237
Teng Liang6f09ab62018-03-01 20:04:08 -0700238 pitEntry->isSatisfied = true;
239 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
240
Teng Liang85a36632018-03-21 05:59:34 -0700241 // set PIT expiry timer to now
242 this->setExpiryTimer(pitEntry, 0_ms);
mzhang4eab72492015-02-25 11:16:09 -0600243
Teng Liang85a36632018-03-21 05:59:34 -0700244 // dispatch to strategy: after Content Store hit
Davide Pesavento0498ce82021-06-14 02:02:21 -0400245 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(data, ingress, pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600246}
247
Eric Newberry2377ada2020-09-28 22:40:14 -0700248pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400249Forwarder::onOutgoingInterest(const Interest& interest, Face& egress,
250 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700251{
Eric Newberry9d283ad2020-04-12 23:37:17 -0700252 // drop if HopLimit == 0 but sending on non-local face
Teng Liangebc20f62020-06-23 16:55:20 -0700253 if (interest.getHopLimit() == 0 && egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
254 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << pitEntry->getName()
Eric Newberry9d283ad2020-04-12 23:37:17 -0700255 << " non-local hop-limit=0");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400256 ++egress.getCounters().nOutHopLimitZero;
Eric Newberry2377ada2020-09-28 22:40:14 -0700257 return nullptr;
Eric Newberry9d283ad2020-04-12 23:37:17 -0700258 }
259
Teng Liangebc20f62020-06-23 16:55:20 -0700260 NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << pitEntry->getName());
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700261
Junxiao Shi4846f372016-04-05 13:39:30 -0700262 // insert out-record
Eric Newberry2377ada2020-09-28 22:40:14 -0700263 auto it = pitEntry->insertOrUpdateOutRecord(egress, interest);
264 BOOST_ASSERT(it != pitEntry->out_end());
Junxiao Shic041ca32014-02-25 20:01:15 -0700265
Junxiao Shid3c792f2014-01-30 00:46:13 -0700266 // send Interest
Teng Liangebc20f62020-06-23 16:55:20 -0700267 egress.sendInterest(interest);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700268 ++m_counters.nOutInterests;
Eric Newberry2377ada2020-09-28 22:40:14 -0700269 return &*it;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700270}
271
272void
Teng Liang6f09ab62018-03-01 20:04:08 -0700273Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shia110f262014-10-12 12:35:20 -0700274{
ashiqopuc7079482019-02-20 05:34:37 +0000275 NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName()
276 << (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
Junxiao Shia110f262014-10-12 12:35:20 -0700277
278 // Dead Nonce List insert if necessary
Davide Pesavento3dade002019-03-19 11:29:56 -0600279 this->insertDeadNonceList(*pitEntry, nullptr);
Junxiao Shia110f262014-10-12 12:35:20 -0700280
Ju Pan6eb1ac92018-10-26 16:26:15 +0000281 // Increment satisfied/unsatisfied Interests counter
282 if (pitEntry->isSatisfied) {
283 ++m_counters.nSatisfiedInterests;
284 }
285 else {
286 ++m_counters.nUnsatisfiedInterests;
287 }
288
Junxiao Shif3c07812014-03-11 21:48:49 -0700289 // PIT delete
Davide Pesavento3dade002019-03-19 11:29:56 -0600290 pitEntry->expiryTimer.cancel();
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000291 m_pit.erase(pitEntry.get());
Junxiao Shid3c792f2014-01-30 00:46:13 -0700292}
293
294void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400295Forwarder::onIncomingData(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700296{
297 // receive Data
ashiqopuc7079482019-02-20 05:34:37 +0000298 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName());
299 data.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700300 ++m_counters.nInData;
Junxiao Shic041ca32014-02-25 20:01:15 -0700301
Junxiao Shi88884492014-02-15 15:57:43 -0700302 // /localhost scope control
ashiqopuc7079482019-02-20 05:34:37 +0000303 bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
Junxiao Shif3410d82016-04-05 13:49:44 -0700304 scope_prefix::LOCALHOST.isPrefixOf(data.getName());
Junxiao Shif3c07812014-03-11 21:48:49 -0700305 if (isViolatingLocalhost) {
ashiqopuc7079482019-02-20 05:34:37 +0000306 NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName() << " violates /localhost");
Davide Pesavento0498ce82021-06-14 02:02:21 -0400307 // drop
Junxiao Shi88884492014-02-15 15:57:43 -0700308 return;
309 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700310
Junxiao Shid3c792f2014-01-30 00:46:13 -0700311 // PIT match
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700312 pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data);
Teng Liang43bb2312018-03-26 04:16:42 -0700313 if (pitMatches.size() == 0) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700314 // goto Data unsolicited pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400315 this->onDataUnsolicited(data, ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700316 return;
317 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700318
Junxiao Shid3c792f2014-01-30 00:46:13 -0700319 // CS insert
320 m_cs.insert(data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700321
Teng Liang43bb2312018-03-26 04:16:42 -0700322 // when only one PIT entry is matched, trigger strategy: after receive Data
323 if (pitMatches.size() == 1) {
324 auto& pitEntry = pitMatches.front();
Junxiao Shic041ca32014-02-25 20:01:15 -0700325
Teng Liang43bb2312018-03-26 04:16:42 -0700326 NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -0700327
Teng Liang7003e0b2018-03-03 16:03:30 -0700328 // set PIT expiry timer to now
329 this->setExpiryTimer(pitEntry, 0_ms);
330
Teng Liang43bb2312018-03-26 04:16:42 -0700331 // trigger strategy: after receive Data
Davide Pesavento0498ce82021-06-14 02:02:21 -0400332 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveData(data, ingress, pitEntry);
Junxiao Shid938a6b2014-05-11 23:40:29 -0700333
Teng Liang43bb2312018-03-26 04:16:42 -0700334 // mark PIT satisfied
Teng Liang6f09ab62018-03-01 20:04:08 -0700335 pitEntry->isSatisfied = true;
336 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
337
Teng Liangebc20f62020-06-23 16:55:20 -0700338 // Dead Nonce List insert if necessary (for out-record of ingress face)
ashiqopuc7079482019-02-20 05:34:37 +0000339 this->insertDeadNonceList(*pitEntry, &ingress.face);
Junxiao Shia110f262014-10-12 12:35:20 -0700340
Teng Liang43bb2312018-03-26 04:16:42 -0700341 // delete PIT entry's out-record
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000342 pitEntry->deleteOutRecord(ingress.face);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700343 }
Teng Liang43bb2312018-03-26 04:16:42 -0700344 // when more than one PIT entry is matched, trigger strategy: before satisfy Interest,
345 // and send Data to all matched out faces
346 else {
Teng Liangebc20f62020-06-23 16:55:20 -0700347 std::set<Face*> pendingDownstreams;
Teng Liang43bb2312018-03-26 04:16:42 -0700348 auto now = time::steady_clock::now();
Junxiao Shic041ca32014-02-25 20:01:15 -0700349
Davide Pesaventob31206e2019-04-20 22:34:12 -0400350 for (const auto& pitEntry : pitMatches) {
Teng Liang43bb2312018-03-26 04:16:42 -0700351 NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
352
353 // remember pending downstreams
354 for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
355 if (inRecord.getExpiry() > now) {
Teng Liangebc20f62020-06-23 16:55:20 -0700356 pendingDownstreams.insert(&inRecord.getFace());
Teng Liang43bb2312018-03-26 04:16:42 -0700357 }
358 }
359
360 // set PIT expiry timer to now
361 this->setExpiryTimer(pitEntry, 0_ms);
362
363 // invoke PIT satisfy callback
Davide Pesavento0498ce82021-06-14 02:02:21 -0400364 m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(data, ingress, pitEntry);
Teng Liang43bb2312018-03-26 04:16:42 -0700365
366 // mark PIT satisfied
367 pitEntry->isSatisfied = true;
368 pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod();
369
Teng Liangebc20f62020-06-23 16:55:20 -0700370 // Dead Nonce List insert if necessary (for out-record of ingress face)
ashiqopuc7079482019-02-20 05:34:37 +0000371 this->insertDeadNonceList(*pitEntry, &ingress.face);
Teng Liang43bb2312018-03-26 04:16:42 -0700372
373 // clear PIT entry's in and out records
374 pitEntry->clearInRecords();
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000375 pitEntry->deleteOutRecord(ingress.face);
Junxiao Shida006f52014-05-16 11:18:00 -0700376 }
Teng Liang43bb2312018-03-26 04:16:42 -0700377
378 // foreach pending downstream
ashiqopuc7079482019-02-20 05:34:37 +0000379 for (const auto& pendingDownstream : pendingDownstreams) {
Teng Liangebc20f62020-06-23 16:55:20 -0700380 if (pendingDownstream->getId() == ingress.face.getId() &&
381 pendingDownstream->getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
Teng Liang43bb2312018-03-26 04:16:42 -0700382 continue;
383 }
384 // goto outgoing Data pipeline
Teng Liangebc20f62020-06-23 16:55:20 -0700385 this->onOutgoingData(data, *pendingDownstream);
Teng Liang43bb2312018-03-26 04:16:42 -0700386 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700387 }
388}
389
390void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400391Forwarder::onDataUnsolicited(const Data& data, const FaceEndpoint& ingress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700392{
393 // accept to cache?
Alex Lane6bead9b2020-05-12 19:08:20 -0500394 auto decision = m_unsolicitedDataPolicy->decide(ingress.face, data);
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000395 if (decision == fw::UnsolicitedDataDecision::CACHE) {
Junxiao Shid3c792f2014-01-30 00:46:13 -0700396 // CS insert
Junxiao Shif3c07812014-03-11 21:48:49 -0700397 m_cs.insert(data, true);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700398 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700399
Teng Liangebc20f62020-06-23 16:55:20 -0700400 NFD_LOG_DEBUG("onDataUnsolicited in=" << ingress << " data=" << data.getName()
401 << " decision=" << decision);
Alex Lane6bead9b2020-05-12 19:08:20 -0500402 ++m_counters.nUnsolicitedData;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700403}
404
Eric Newberry2377ada2020-09-28 22:40:14 -0700405bool
Teng Liangebc20f62020-06-23 16:55:20 -0700406Forwarder::onOutgoingData(const Data& data, Face& egress)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700407{
Teng Liangebc20f62020-06-23 16:55:20 -0700408 if (egress.getId() == face::INVALID_FACEID) {
ashiqopuc7079482019-02-20 05:34:37 +0000409 NFD_LOG_WARN("onOutgoingData out=(invalid) data=" << data.getName());
Eric Newberry2377ada2020-09-28 22:40:14 -0700410 return false;
Junxiao Shi223271b2014-07-03 22:06:13 -0700411 }
Teng Liangebc20f62020-06-23 16:55:20 -0700412 NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName());
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
Junxiao Shif3c07812014-03-11 21:48:49 -0700424 // TODO traffic manager
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{
Junxiao Shi0de23a22015-12-03 20:07:02 +0000436 // receive Nack
ashiqopuc7079482019-02-20 05:34:37 +0000437 nack.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700438 ++m_counters.nInNacks;
439
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700440 // if multi-access or ad hoc face, drop
ashiqopuc7079482019-02-20 05:34:37 +0000441 if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
Davide Pesaventob31206e2019-04-20 22:34:12 -0400442 NFD_LOG_DEBUG("onIncomingNack in=" << ingress
443 << " nack=" << nack.getInterest().getName() << "~" << nack.getReason()
444 << " link-type=" << ingress.face.getLinkType());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700445 return;
446 }
447
448 // PIT match
449 shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest());
450 // if no PIT entry found, drop
451 if (pitEntry == nullptr) {
ashiqopuc7079482019-02-20 05:34:37 +0000452 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
453 << "~" << nack.getReason() << " no-PIT-entry");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700454 return;
455 }
456
457 // has out-record?
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000458 auto outRecord = pitEntry->getOutRecord(ingress.face);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700459 // if no out-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700460 if (outRecord == pitEntry->out_end()) {
ashiqopuc7079482019-02-20 05:34:37 +0000461 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
462 << "~" << nack.getReason() << " no-out-record");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700463 return;
464 }
465
466 // if out-record has different Nonce, drop
467 if (nack.getInterest().getNonce() != outRecord->getLastNonce()) {
ashiqopuc7079482019-02-20 05:34:37 +0000468 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
469 << "~" << nack.getReason() << " wrong-Nonce " << nack.getInterest().getNonce()
470 << "!=" << outRecord->getLastNonce());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700471 return;
472 }
473
ashiqopuc7079482019-02-20 05:34:37 +0000474 NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
475 << "~" << nack.getReason() << " OK");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700476
477 // record Nack on out-record
478 outRecord->setIncomingNack(nack);
479
Teng Liang7003e0b2018-03-03 16:03:30 -0700480 // set PIT expiry timer to now when all out-record receive Nack
481 if (!fw::hasPendingOutRecords(*pitEntry)) {
482 this->setExpiryTimer(pitEntry, 0_ms);
483 }
484
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700485 // trigger strategy: after receive NACK
Davide Pesavento0498ce82021-06-14 02:02:21 -0400486 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(nack, ingress, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700487}
488
Eric Newberry2377ada2020-09-28 22:40:14 -0700489bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400490Forwarder::onOutgoingNack(const lp::NackHeader& nack, Face& egress,
491 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700492{
Teng Liangebc20f62020-06-23 16:55:20 -0700493 if (egress.getId() == face::INVALID_FACEID) {
ashiqopuc7079482019-02-20 05:34:37 +0000494 NFD_LOG_WARN("onOutgoingNack out=(invalid)"
Davide Pesaventob31206e2019-04-20 22:34:12 -0400495 << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason());
Eric Newberry2377ada2020-09-28 22:40:14 -0700496 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700497 }
498
499 // has in-record?
Teng Liangebc20f62020-06-23 16:55:20 -0700500 auto inRecord = pitEntry->getInRecord(egress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700501
502 // if no in-record found, drop
Junxiao Shi4846f372016-04-05 13:39:30 -0700503 if (inRecord == pitEntry->in_end()) {
Teng Liangebc20f62020-06-23 16:55:20 -0700504 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
ashiqopuc7079482019-02-20 05:34:37 +0000505 << " nack=" << pitEntry->getInterest().getName()
506 << "~" << nack.getReason() << " no-in-record");
Eric Newberry2377ada2020-09-28 22:40:14 -0700507 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700508 }
509
Teng Liang4f5cdcf2017-03-16 15:33:31 -0700510 // if multi-access or ad hoc face, drop
Teng Liangebc20f62020-06-23 16:55:20 -0700511 if (egress.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
512 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
Davide Pesaventob31206e2019-04-20 22:34:12 -0400513 << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason()
Teng Liangebc20f62020-06-23 16:55:20 -0700514 << " link-type=" << egress.getLinkType());
Eric Newberry2377ada2020-09-28 22:40:14 -0700515 return false;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700516 }
517
Teng Liangebc20f62020-06-23 16:55:20 -0700518 NFD_LOG_DEBUG("onOutgoingNack out=" << egress.getId()
ashiqopuc7079482019-02-20 05:34:37 +0000519 << " nack=" << pitEntry->getInterest().getName()
520 << "~" << nack.getReason() << " OK");
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700521
522 // create Nack packet with the Interest from in-record
523 lp::Nack nackPkt(inRecord->getInterest());
524 nackPkt.setHeader(nack);
525
526 // erase in-record
Teng Liangebc20f62020-06-23 16:55:20 -0700527 pitEntry->deleteInRecord(egress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700528
529 // send Nack on face
Teng Liangebc20f62020-06-23 16:55:20 -0700530 egress.sendNack(nackPkt);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700531 ++m_counters.nOutNacks;
Eric Newberry2377ada2020-09-28 22:40:14 -0700532
533 return true;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700534}
535
Eric Newberry41aba102017-11-01 16:42:13 -0700536void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400537Forwarder::onDroppedInterest(const Interest& interest, Face& egress)
Eric Newberry41aba102017-11-01 16:42:13 -0700538{
Davide Pesavento0498ce82021-06-14 02:02:21 -0400539 m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(interest, egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700540}
541
Junxiao Shid3c792f2014-01-30 00:46:13 -0700542void
Ju Pan2feb4592019-09-16 20:56:38 +0000543Forwarder::onNewNextHop(const Name& prefix, const fib::NextHop& nextHop)
544{
545 const auto affectedEntries = this->getNameTree().partialEnumerate(prefix,
546 [&] (const name_tree::Entry& nte) -> std::pair<bool, bool> {
Davide Pesaventob21bed82021-02-13 00:20:06 -0500547 // we ignore an NTE and skip visiting its descendants if that NTE has an
548 // associated FIB entry (1st condition), since in that case the new nexthop
549 // won't affect any PIT entries anywhere in that subtree, *unless* this is
550 // the initial NTE from which the enumeration started (2nd condition), which
551 // must always be considered
552 if (nte.getFibEntry() != nullptr && nte.getName().size() > prefix.size()) {
Ju Pan2feb4592019-09-16 20:56:38 +0000553 return {false, false};
554 }
Davide Pesaventob21bed82021-02-13 00:20:06 -0500555 return {nte.hasPitEntries(), true};
Ju Pan2feb4592019-09-16 20:56:38 +0000556 });
557
558 for (const auto& nte : affectedEntries) {
559 for (const auto& pitEntry : nte.getPitEntries()) {
Davide Pesavento05590472021-02-17 15:53:27 -0500560 m_strategyChoice.findEffectiveStrategy(*pitEntry).afterNewNextHop(nextHop, pitEntry);
Ju Pan2feb4592019-09-16 20:56:38 +0000561 }
562 }
563}
564
565void
Teng Liang7003e0b2018-03-03 16:03:30 -0700566Forwarder::setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700567{
Teng Liang39465c22018-11-12 19:43:04 -0700568 BOOST_ASSERT(pitEntry);
Junxiao Shie1cf4ba2020-06-19 16:40:53 -0600569 duration = std::max(duration, 0_ms);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700570
Davide Pesavento3dade002019-03-19 11:29:56 -0600571 pitEntry->expiryTimer.cancel();
572 pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); });
Junxiao Shia110f262014-10-12 12:35:20 -0700573}
574
575void
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400576Forwarder::insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream)
Junxiao Shia110f262014-10-12 12:35:20 -0700577{
578 // need Dead Nonce List insert?
Eric Newberryf4056d02017-05-26 17:31:53 +0000579 bool needDnl = true;
Teng Liang6f09ab62018-03-01 20:04:08 -0700580 if (pitEntry.isSatisfied) {
581 BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms);
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400582 needDnl = pitEntry.getInterest().getMustBeFresh() &&
Teng Liang6f09ab62018-03-01 20:04:08 -0700583 pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime();
Junxiao Shia110f262014-10-12 12:35:20 -0700584 }
585
586 if (!needDnl) {
587 return;
588 }
589
590 // Dead Nonce List insert
Teng Liangf995f382017-04-04 22:09:39 +0000591 if (upstream == nullptr) {
Junxiao Shia110f262014-10-12 12:35:20 -0700592 // insert all outgoing Nonces
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400593 const auto& outRecords = pitEntry.getOutRecords();
594 std::for_each(outRecords.begin(), outRecords.end(), [&] (const auto& outRecord) {
595 m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce());
596 });
Junxiao Shia110f262014-10-12 12:35:20 -0700597 }
598 else {
599 // insert outgoing Nonce of a specific face
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000600 auto outRecord = pitEntry.getOutRecord(*upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700601 if (outRecord != pitEntry.getOutRecords().end()) {
602 m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
603 }
604 }
605}
606
Philipp Molla1033342021-06-14 09:34:21 +0200607void
608Forwarder::setConfigFile(ConfigFile& configFile)
609{
Davide Pesavento412c9822021-07-02 00:21:05 -0400610 configFile.addSectionHandler(CFG_FORWARDER, [this] (auto&&... args) {
611 processConfig(std::forward<decltype(args)>(args)...);
612 });
Philipp Molla1033342021-06-14 09:34:21 +0200613}
614
615void
616Forwarder::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
617{
618 Config config;
619
620 for (const auto& pair : configSection) {
621 const std::string& key = pair.first;
622 if (key == "default_hop_limit") {
Davide Pesavento412c9822021-07-02 00:21:05 -0400623 config.defaultHopLimit = ConfigFile::parseNumber<uint8_t>(pair, CFG_FORWARDER);
Philipp Molla1033342021-06-14 09:34:21 +0200624 }
625 else {
Davide Pesavento412c9822021-07-02 00:21:05 -0400626 NDN_THROW(ConfigFile::Error("Unrecognized option " + CFG_FORWARDER + "." + key));
Philipp Molla1033342021-06-14 09:34:21 +0200627 }
628 }
629
630 if (!isDryRun) {
631 m_config = config;
632 }
633}
634
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800635} // namespace nfd