blob: 47c6e03fd3b677b6acfdefea42ccf54e7548e357 [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 Pesavento264af772021-02-09 21:48:24 -05003 * Copyright (c) 2014-2021, 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 Pesavento264af772021-02-09 21:48:24 -050059 NFD_VIRTUAL_WITH_TESTS
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060060 ~Forwarder();
61
Junxiao Shib289cc12014-03-15 12:19:05 -070062 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000063 getCounters() const
64 {
65 return m_counters;
66 }
Junxiao Shib289cc12014-03-15 12:19:05 -070067
Junxiao Shifbe8efe2016-08-22 16:02:30 +000068 fw::UnsolicitedDataPolicy&
69 getUnsolicitedDataPolicy() const
70 {
71 return *m_unsolicitedDataPolicy;
72 }
73
74 void
75 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
76 {
77 BOOST_ASSERT(policy != nullptr);
78 m_unsolicitedDataPolicy = std::move(policy);
79 }
80
Junxiao Shiea48d8b2014-03-16 13:53:47 -070081 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +000082 getNameTree()
83 {
84 return m_nameTree;
85 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -070086
Junxiao Shi8c8d2182014-01-30 22:33:00 -070087 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +000088 getFib()
89 {
90 return m_fib;
91 }
Junxiao Shic041ca32014-02-25 20:01:15 -070092
Junxiao Shi8c8d2182014-01-30 22:33:00 -070093 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +000094 getPit()
95 {
96 return m_pit;
97 }
Junxiao Shic041ca32014-02-25 20:01:15 -070098
Junxiao Shi8c8d2182014-01-30 22:33:00 -070099 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000100 getCs()
101 {
102 return m_cs;
103 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700104
Junxiao Shidbe71732014-02-21 22:23:28 -0700105 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000106 getMeasurements()
107 {
108 return m_measurements;
109 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700110
Junxiao Shibb5105f2014-03-03 12:06:45 -0700111 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000112 getStrategyChoice()
113 {
114 return m_strategyChoice;
115 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700116
Junxiao Shia110f262014-10-12 12:35:20 -0700117 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000118 getDeadNonceList()
119 {
120 return m_deadNonceList;
121 }
Junxiao Shia110f262014-10-12 12:35:20 -0700122
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700123 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000124 getNetworkRegionTable()
125 {
126 return m_networkRegionTable;
127 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700128
Philipp Molla1033342021-06-14 09:34:21 +0200129 /** \brief register handler for forwarder section of NFD configuration file
130 */
131 void
132 setConfigFile(ConfigFile& configFile);
133
Davide Pesavento264af772021-02-09 21:48:24 -0500134NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700135 /** \brief incoming Interest pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400136 * \param interest the incoming Interest, must be well-formed and created with make_shared
137 * \param ingress face on which \p interest was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700138 */
Davide Pesavento264af772021-02-09 21:48:24 -0500139 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400140 onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700141
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700142 /** \brief Interest loop pipeline
143 */
Davide Pesavento264af772021-02-09 21:48:24 -0500144 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400145 onInterestLoop(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700146
mzhang4eab72492015-02-25 11:16:09 -0600147 /** \brief Content Store miss pipeline
148 */
Davide Pesavento264af772021-02-09 21:48:24 -0500149 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400150 onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
151 const shared_ptr<pit::Entry>& pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600152
153 /** \brief Content Store hit pipeline
154 */
Davide Pesavento264af772021-02-09 21:48:24 -0500155 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400156 onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
157 const shared_ptr<pit::Entry>& pitEntry, const Data& data);
mzhang4eab72492015-02-25 11:16:09 -0600158
Junxiao Shid3c792f2014-01-30 00:46:13 -0700159 /** \brief outgoing Interest pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700160 * \return A pointer to the out-record created or nullptr if the Interest was dropped
Junxiao Shid3c792f2014-01-30 00:46:13 -0700161 */
Davide Pesavento264af772021-02-09 21:48:24 -0500162 NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400163 onOutgoingInterest(const Interest& interest, Face& egress,
164 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700165
Junxiao Shia110f262014-10-12 12:35:20 -0700166 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700167 */
Davide Pesavento264af772021-02-09 21:48:24 -0500168 NFD_VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700169 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700170
Junxiao Shid3c792f2014-01-30 00:46:13 -0700171 /** \brief incoming Data pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400172 * \param data the incoming Data, must be well-formed and created with make_shared
173 * \param ingress face on which \p data was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700174 */
Davide Pesavento264af772021-02-09 21:48:24 -0500175 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400176 onIncomingData(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700177
Junxiao Shid3c792f2014-01-30 00:46:13 -0700178 /** \brief Data unsolicited pipeline
179 */
Davide Pesavento264af772021-02-09 21:48:24 -0500180 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400181 onDataUnsolicited(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700182
Junxiao Shid3c792f2014-01-30 00:46:13 -0700183 /** \brief outgoing Data pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700184 * \return Whether the Data was transmitted (true) or dropped (false)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700185 */
Davide Pesavento264af772021-02-09 21:48:24 -0500186 NFD_VIRTUAL_WITH_TESTS bool
Teng Liangebc20f62020-06-23 16:55:20 -0700187 onOutgoingData(const Data& data, Face& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700188
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700189 /** \brief incoming Nack pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400190 * \param nack the incoming Nack, must be well-formed
191 * \param ingress face on which \p nack is received and endpoint of the sender
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700192 */
Davide Pesavento264af772021-02-09 21:48:24 -0500193 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400194 onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700195
196 /** \brief outgoing Nack pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700197 * \return Whether the Nack was transmitted (true) or dropped (false)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700198 */
Davide Pesavento264af772021-02-09 21:48:24 -0500199 NFD_VIRTUAL_WITH_TESTS bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400200 onOutgoingNack(const lp::NackHeader& nack, Face& egress,
201 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700202
Davide Pesavento264af772021-02-09 21:48:24 -0500203 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400204 onDroppedInterest(const Interest& interest, Face& egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700205
Davide Pesavento264af772021-02-09 21:48:24 -0500206 NFD_VIRTUAL_WITH_TESTS void
Ju Pan2feb4592019-09-16 20:56:38 +0000207 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
208
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400209private:
Teng Liang7003e0b2018-03-03 16:03:30 -0700210 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
211 */
212 void
213 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700214
Junxiao Shia110f262014-10-12 12:35:20 -0700215 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700216 * \param upstream if null, insert Nonces from all out-records;
217 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700218 */
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400219 void
220 insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700221
Philipp Molla1033342021-06-14 09:34:21 +0200222 void
223 processConfig(const ConfigSection& configSection, bool isDryRun,
224 const std::string& filename);
225
226NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
227 /**
228 * \brief Configuration options from "forwarder" section
229 */
230 struct Config
231 {
232 /// Initial value of HopLimit that should be added to Interests that don't have one.
233 /// A value of zero disables the feature.
234 uint8_t defaultHopLimit = 0;
235 };
236 Config m_config;
237
Junxiao Shid3c792f2014-01-30 00:46:13 -0700238private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700239 ForwarderCounters m_counters;
240
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400241 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000242 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800243
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700244 NameTree m_nameTree;
245 Fib m_fib;
246 Pit m_pit;
247 Cs m_cs;
248 Measurements m_measurements;
249 StrategyChoice m_strategyChoice;
250 DeadNonceList m_deadNonceList;
251 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700252
Junxiao Shid3c792f2014-01-30 00:46:13 -0700253 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700254 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800255};
256
Junxiao Shid3c792f2014-01-30 00:46:13 -0700257} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800258
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700259#endif // NFD_DAEMON_FW_FORWARDER_HPP