blob: aaef44c9cbb81cf9a609a21a6ee509c6436e5ce7 [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"
ashiqopu075bb7d2019-03-10 01:38:21 +000032#include "face/face-endpoint.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070033#include "table/fib.hpp"
34#include "table/pit.hpp"
35#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070036#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070037#include "table/strategy-choice.hpp"
Junxiao Shia110f262014-10-12 12:35:20 -070038#include "table/dead-nonce-list.hpp"
Junxiao Shi0355e9f2015-09-02 07:24:53 -070039#include "table/network-region-table.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080040
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080041namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080042
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070043namespace fw {
44class Strategy;
45} // namespace fw
46
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040047/** \brief Main class of NFD's forwarding engine.
Junxiao Shic041ca32014-02-25 20:01:15 -070048 *
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040049 * Forwarder owns all tables and implements the forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080050 */
51class Forwarder
52{
53public:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040054 explicit
55 Forwarder(FaceTable& faceTable);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080056
Davide Pesavento264af772021-02-09 21:48:24 -050057 NFD_VIRTUAL_WITH_TESTS
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060058 ~Forwarder();
59
Junxiao Shib289cc12014-03-15 12:19:05 -070060 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000061 getCounters() const
62 {
63 return m_counters;
64 }
Junxiao Shib289cc12014-03-15 12:19:05 -070065
Junxiao Shifbe8efe2016-08-22 16:02:30 +000066 fw::UnsolicitedDataPolicy&
67 getUnsolicitedDataPolicy() const
68 {
69 return *m_unsolicitedDataPolicy;
70 }
71
72 void
73 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
74 {
75 BOOST_ASSERT(policy != nullptr);
76 m_unsolicitedDataPolicy = std::move(policy);
77 }
78
Junxiao Shia4f2be82014-03-02 22:56:41 -070079public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -070080 /** \brief start incoming Interest processing
ashiqopuc7079482019-02-20 05:34:37 +000081 * \param ingress face on which Interest is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +000082 * \param interest the incoming Interest, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -070083 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080084 void
ashiqopuc7079482019-02-20 05:34:37 +000085 startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000086 {
ashiqopuc7079482019-02-20 05:34:37 +000087 this->onIncomingInterest(ingress, interest);
Junxiao Shifc2e13d2017-07-25 02:08:48 +000088 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080089
Junxiao Shi0355e9f2015-09-02 07:24:53 -070090 /** \brief start incoming Data processing
ashiqopuc7079482019-02-20 05:34:37 +000091 * \param ingress face on which Data is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +000092 * \param data the incoming Data, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -070093 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080094 void
ashiqopuc7079482019-02-20 05:34:37 +000095 startProcessData(const FaceEndpoint& ingress, const Data& data)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000096 {
ashiqopuc7079482019-02-20 05:34:37 +000097 this->onIncomingData(ingress, data);
Junxiao Shifc2e13d2017-07-25 02:08:48 +000098 }
Junxiao Shic041ca32014-02-25 20:01:15 -070099
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700100 /** \brief start incoming Nack processing
ashiqopuc7079482019-02-20 05:34:37 +0000101 * \param ingress face on which Nack is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000102 * \param nack the incoming Nack, must be well-formed
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700103 */
104 void
ashiqopuc7079482019-02-20 05:34:37 +0000105 startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000106 {
ashiqopuc7079482019-02-20 05:34:37 +0000107 this->onIncomingNack(ingress, nack);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000108 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700109
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700110 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000111 getNameTree()
112 {
113 return m_nameTree;
114 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700115
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700116 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000117 getFib()
118 {
119 return m_fib;
120 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700121
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700122 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000123 getPit()
124 {
125 return m_pit;
126 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700127
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700128 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000129 getCs()
130 {
131 return m_cs;
132 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700133
Junxiao Shidbe71732014-02-21 22:23:28 -0700134 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000135 getMeasurements()
136 {
137 return m_measurements;
138 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700139
Junxiao Shibb5105f2014-03-03 12:06:45 -0700140 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000141 getStrategyChoice()
142 {
143 return m_strategyChoice;
144 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700145
Junxiao Shia110f262014-10-12 12:35:20 -0700146 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000147 getDeadNonceList()
148 {
149 return m_deadNonceList;
150 }
Junxiao Shia110f262014-10-12 12:35:20 -0700151
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700152 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000153 getNetworkRegionTable()
154 {
155 return m_networkRegionTable;
156 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700157
Davide Pesavento264af772021-02-09 21:48:24 -0500158NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700159 /** \brief incoming Interest pipeline
160 */
Davide Pesavento264af772021-02-09 21:48:24 -0500161 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000162 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700163
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700164 /** \brief Interest loop pipeline
165 */
Davide Pesavento264af772021-02-09 21:48:24 -0500166 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000167 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700168
mzhang4eab72492015-02-25 11:16:09 -0600169 /** \brief Content Store miss pipeline
170 */
Davide Pesavento264af772021-02-09 21:48:24 -0500171 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000172 onContentStoreMiss(const FaceEndpoint& ingress,
173 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600174
175 /** \brief Content Store hit pipeline
176 */
Davide Pesavento264af772021-02-09 21:48:24 -0500177 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000178 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600179 const Interest& interest, const Data& data);
180
Junxiao Shid3c792f2014-01-30 00:46:13 -0700181 /** \brief outgoing Interest pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700182 * \return A pointer to the out-record created or nullptr if the Interest was dropped
Junxiao Shid3c792f2014-01-30 00:46:13 -0700183 */
Davide Pesavento264af772021-02-09 21:48:24 -0500184 NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
ashiqopuc7079482019-02-20 05:34:37 +0000185 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
Teng Liangebc20f62020-06-23 16:55:20 -0700186 Face& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700187
Junxiao Shia110f262014-10-12 12:35:20 -0700188 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700189 */
Davide Pesavento264af772021-02-09 21:48:24 -0500190 NFD_VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700191 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700192
Junxiao Shid3c792f2014-01-30 00:46:13 -0700193 /** \brief incoming Data pipeline
194 */
Davide Pesavento264af772021-02-09 21:48:24 -0500195 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000196 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700197
Junxiao Shid3c792f2014-01-30 00:46:13 -0700198 /** \brief Data unsolicited pipeline
199 */
Davide Pesavento264af772021-02-09 21:48:24 -0500200 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000201 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700202
Junxiao Shid3c792f2014-01-30 00:46:13 -0700203 /** \brief outgoing Data pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700204 * \return Whether the Data was transmitted (true) or dropped (false)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700205 */
Davide Pesavento264af772021-02-09 21:48:24 -0500206 NFD_VIRTUAL_WITH_TESTS bool
Teng Liangebc20f62020-06-23 16:55:20 -0700207 onOutgoingData(const Data& data, Face& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700208
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700209 /** \brief incoming Nack pipeline
210 */
Davide Pesavento264af772021-02-09 21:48:24 -0500211 NFD_VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000212 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700213
214 /** \brief outgoing Nack pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700215 * \return Whether the Nack was transmitted (true) or dropped (false)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700216 */
Davide Pesavento264af772021-02-09 21:48:24 -0500217 NFD_VIRTUAL_WITH_TESTS bool
ashiqopuc7079482019-02-20 05:34:37 +0000218 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
Teng Liangebc20f62020-06-23 16:55:20 -0700219 Face& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700220
Davide Pesavento264af772021-02-09 21:48:24 -0500221 NFD_VIRTUAL_WITH_TESTS void
Teng Liangebc20f62020-06-23 16:55:20 -0700222 onDroppedInterest(const Face& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700223
Davide Pesavento264af772021-02-09 21:48:24 -0500224 NFD_VIRTUAL_WITH_TESTS void
Ju Pan2feb4592019-09-16 20:56:38 +0000225 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
226
Davide Pesavento264af772021-02-09 21:48:24 -0500227NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700228 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
229 */
230 void
231 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700232
Junxiao Shia110f262014-10-12 12:35:20 -0700233 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700234 * \param upstream if null, insert Nonces from all out-records;
235 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700236 */
Davide Pesavento264af772021-02-09 21:48:24 -0500237 NFD_VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700238 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700239
Junxiao Shib9420cf2016-08-13 04:38:52 +0000240 /** \brief call trigger (method) on the effective strategy of pitEntry
241 */
Davide Pesavento264af772021-02-09 21:48:24 -0500242#ifdef NFD_WITH_TESTS
Junxiao Shif3c07812014-03-11 21:48:49 -0700243 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400244 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700245#else
246 template<class Function>
247 void
Davide Pesavento264af772021-02-09 21:48:24 -0500248 dispatchToStrategy(pit::Entry& pitEntry, Function&& trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700249#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000250 {
251 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
252 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700253
254private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700255 ForwarderCounters m_counters;
256
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400257 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000258 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800259
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700260 NameTree m_nameTree;
261 Fib m_fib;
262 Pit m_pit;
263 Cs m_cs;
264 Measurements m_measurements;
265 StrategyChoice m_strategyChoice;
266 DeadNonceList m_deadNonceList;
267 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700268
Junxiao Shid3c792f2014-01-30 00:46:13 -0700269 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700270 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800271};
272
Junxiao Shid3c792f2014-01-30 00:46:13 -0700273} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800274
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700275#endif // NFD_DAEMON_FW_FORWARDER_HPP