blob: a2f2af7b26ee0b07d20f0785e1ad1af9056d8289 [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 Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi330136a2016-03-10 04:53:08 -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 Shia110f262014-10-12 12:35:20 -070024 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FW_FORWARDER_HPP
27#define NFD_DAEMON_FW_FORWARDER_HPP
Alexander Afanasyev33b72772014-01-26 23:22:58 -080028
Davide Pesavento3dade002019-03-19 11:29:56 -060029#include "face-table.hpp"
30#include "forwarder-counters.hpp"
Junxiao Shifbe8efe2016-08-22 16:02:30 +000031#include "unsolicited-data-policy.hpp"
Philipp Molla1033342021-06-14 09:34:21 +020032#include "common/config-file.hpp"
ashiqopu075bb7d2019-03-10 01:38:21 +000033#include "face/face-endpoint.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070034#include "table/fib.hpp"
35#include "table/pit.hpp"
36#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070037#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070038#include "table/strategy-choice.hpp"
Junxiao Shia110f262014-10-12 12:35:20 -070039#include "table/dead-nonce-list.hpp"
Junxiao Shi0355e9f2015-09-02 07:24:53 -070040#include "table/network-region-table.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080041
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080042namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080043
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070044namespace fw {
45class Strategy;
46} // namespace fw
47
Davide Pesavento0498ce82021-06-14 02:02:21 -040048/**
49 * \brief Main class of NFD's forwarding engine.
Junxiao Shic041ca32014-02-25 20:01:15 -070050 *
Davide Pesavento0498ce82021-06-14 02:02:21 -040051 * The Forwarder class owns all tables and implements the forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080052 */
53class Forwarder
54{
55public:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040056 explicit
57 Forwarder(FaceTable& faceTable);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080058
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040059#ifdef NFD_WITH_TESTS
60 virtual
61 ~Forwarder() = default;
62#endif
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060063
Junxiao Shib289cc12014-03-15 12:19:05 -070064 const ForwarderCounters&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040065 getCounters() const noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +000066 {
67 return m_counters;
68 }
Junxiao Shib289cc12014-03-15 12:19:05 -070069
Junxiao Shifbe8efe2016-08-22 16:02:30 +000070 fw::UnsolicitedDataPolicy&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040071 getUnsolicitedDataPolicy() const noexcept
Junxiao Shifbe8efe2016-08-22 16:02:30 +000072 {
73 return *m_unsolicitedDataPolicy;
74 }
75
76 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040077 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy) noexcept
Junxiao Shifbe8efe2016-08-22 16:02:30 +000078 {
79 BOOST_ASSERT(policy != nullptr);
80 m_unsolicitedDataPolicy = std::move(policy);
81 }
82
Junxiao Shiea48d8b2014-03-16 13:53:47 -070083 NameTree&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040084 getNameTree() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +000085 {
86 return m_nameTree;
87 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -070088
Junxiao Shi8c8d2182014-01-30 22:33:00 -070089 Fib&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040090 getFib() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +000091 {
92 return m_fib;
93 }
Junxiao Shic041ca32014-02-25 20:01:15 -070094
Junxiao Shi8c8d2182014-01-30 22:33:00 -070095 Pit&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040096 getPit() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +000097 {
98 return m_pit;
99 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700100
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700101 Cs&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400102 getCs() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +0000103 {
104 return m_cs;
105 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700106
Junxiao Shidbe71732014-02-21 22:23:28 -0700107 Measurements&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400108 getMeasurements() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +0000109 {
110 return m_measurements;
111 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700112
Junxiao Shibb5105f2014-03-03 12:06:45 -0700113 StrategyChoice&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400114 getStrategyChoice() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +0000115 {
116 return m_strategyChoice;
117 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700118
Junxiao Shia110f262014-10-12 12:35:20 -0700119 DeadNonceList&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400120 getDeadNonceList() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +0000121 {
122 return m_deadNonceList;
123 }
Junxiao Shia110f262014-10-12 12:35:20 -0700124
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700125 NetworkRegionTable&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400126 getNetworkRegionTable() noexcept
Junxiao Shib9420cf2016-08-13 04:38:52 +0000127 {
128 return m_networkRegionTable;
129 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700130
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400131 /** \brief Register handler for forwarder section of NFD configuration file.
Philipp Molla1033342021-06-14 09:34:21 +0200132 */
133 void
134 setConfigFile(ConfigFile& configFile);
135
Davide Pesavento264af772021-02-09 21:48:24 -0500136NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400137 /** \brief Incoming Interest pipeline.
Davide Pesavento0498ce82021-06-14 02:02:21 -0400138 * \param interest the incoming Interest, must be well-formed and created with make_shared
139 * \param ingress face on which \p interest was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700140 */
Davide Pesavento264af772021-02-09 21:48:24 -0500141 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400142 onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700143
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400144 /** \brief Interest loop pipeline.
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700145 */
Davide Pesavento264af772021-02-09 21:48:24 -0500146 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400147 onInterestLoop(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700148
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400149 /** \brief Content Store miss pipeline.
mzhang4eab72492015-02-25 11:16:09 -0600150 */
Davide Pesavento264af772021-02-09 21:48:24 -0500151 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400152 onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
153 const shared_ptr<pit::Entry>& pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600154
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400155 /** \brief Content Store hit pipeline.
mzhang4eab72492015-02-25 11:16:09 -0600156 */
Davide Pesavento264af772021-02-09 21:48:24 -0500157 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400158 onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
159 const shared_ptr<pit::Entry>& pitEntry, const Data& data);
mzhang4eab72492015-02-25 11:16:09 -0600160
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400161 /** \brief Outgoing Interest pipeline.
Eric Newberry2377ada2020-09-28 22:40:14 -0700162 * \return A pointer to the out-record created or nullptr if the Interest was dropped
Junxiao Shid3c792f2014-01-30 00:46:13 -0700163 */
Davide Pesavento264af772021-02-09 21:48:24 -0500164 NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400165 onOutgoingInterest(const Interest& interest, Face& egress,
166 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700167
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400168 /** \brief Interest finalize pipeline.
Junxiao Shia110f262014-10-12 12:35:20 -0700169 */
Davide Pesavento264af772021-02-09 21:48:24 -0500170 NFD_VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700171 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700172
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400173 /** \brief Incoming Data pipeline.
Davide Pesavento0498ce82021-06-14 02:02:21 -0400174 * \param data the incoming Data, must be well-formed and created with make_shared
175 * \param ingress face on which \p data was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700176 */
Davide Pesavento264af772021-02-09 21:48:24 -0500177 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400178 onIncomingData(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700179
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400180 /** \brief Data unsolicited pipeline.
Junxiao Shid3c792f2014-01-30 00:46:13 -0700181 */
Davide Pesavento264af772021-02-09 21:48:24 -0500182 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400183 onDataUnsolicited(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700184
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400185 /** \brief Outgoing Data pipeline.
Eric Newberry2377ada2020-09-28 22:40:14 -0700186 * \return Whether the Data was transmitted (true) or dropped (false)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700187 */
Davide Pesavento264af772021-02-09 21:48:24 -0500188 NFD_VIRTUAL_WITH_TESTS bool
Teng Liangebc20f62020-06-23 16:55:20 -0700189 onOutgoingData(const Data& data, Face& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700190
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400191 /** \brief Incoming Nack pipeline.
Davide Pesavento0498ce82021-06-14 02:02:21 -0400192 * \param nack the incoming Nack, must be well-formed
193 * \param ingress face on which \p nack is received and endpoint of the sender
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700194 */
Davide Pesavento264af772021-02-09 21:48:24 -0500195 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400196 onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700197
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400198 /** \brief Outgoing Nack pipeline.
Eric Newberry2377ada2020-09-28 22:40:14 -0700199 * \return Whether the Nack was transmitted (true) or dropped (false)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700200 */
Davide Pesavento264af772021-02-09 21:48:24 -0500201 NFD_VIRTUAL_WITH_TESTS bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400202 onOutgoingNack(const lp::NackHeader& nack, Face& egress,
203 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700204
Davide Pesavento264af772021-02-09 21:48:24 -0500205 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400206 onDroppedInterest(const Interest& interest, Face& egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700207
Davide Pesavento264af772021-02-09 21:48:24 -0500208 NFD_VIRTUAL_WITH_TESTS void
Ju Pan2feb4592019-09-16 20:56:38 +0000209 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
210
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400211private:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400212 /** \brief Set a new expiry timer (now + \p duration) on a PIT entry.
Teng Liang7003e0b2018-03-03 16:03:30 -0700213 */
214 void
215 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700216
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400217 /** \brief Insert Nonce to Dead Nonce List if necessary.
Junxiao Shi4846f372016-04-05 13:39:30 -0700218 * \param upstream if null, insert Nonces from all out-records;
219 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700220 */
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400221 void
222 insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700223
Philipp Molla1033342021-06-14 09:34:21 +0200224 void
225 processConfig(const ConfigSection& configSection, bool isDryRun,
226 const std::string& filename);
227
228NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
229 /**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400230 * \brief Configuration options from the `forwarder` section.
Philipp Molla1033342021-06-14 09:34:21 +0200231 */
232 struct Config
233 {
234 /// Initial value of HopLimit that should be added to Interests that don't have one.
235 /// A value of zero disables the feature.
236 uint8_t defaultHopLimit = 0;
237 };
238 Config m_config;
239
Junxiao Shid3c792f2014-01-30 00:46:13 -0700240private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700241 ForwarderCounters m_counters;
242
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400243 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000244 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800245
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700246 NameTree m_nameTree;
247 Fib m_fib;
248 Pit m_pit;
249 Cs m_cs;
250 Measurements m_measurements;
251 StrategyChoice m_strategyChoice;
252 DeadNonceList m_deadNonceList;
253 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700254
Junxiao Shid3c792f2014-01-30 00:46:13 -0700255 // allow Strategy (base class) to enter pipelines
Davide Pesavento9a28c3f2022-06-11 21:50:01 -0400256 friend ::nfd::fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800257};
258
Junxiao Shid3c792f2014-01-30 00:46:13 -0700259} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800260
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700261#endif // NFD_DAEMON_FW_FORWARDER_HPP