blob: ecc4d728c639711321a5e3b5320d346b6fa2ed06 [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/*
ashiqopuc7079482019-02-20 05:34:37 +00003 * Copyright (c) 2014-2019, 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
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070030#include "core/scheduler.hpp"
Junxiao Shi33152f12014-07-16 19:54:32 -070031#include "forwarder-counters.hpp"
Junxiao Shia4f2be82014-03-02 22:56:41 -070032#include "face-table.hpp"
ashiqopuc7079482019-02-20 05:34:37 +000033#include "face-endpoint.hpp"
Junxiao Shifbe8efe2016-08-22 16:02:30 +000034#include "unsolicited-data-policy.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070035#include "table/fib.hpp"
36#include "table/pit.hpp"
37#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070038#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070039#include "table/strategy-choice.hpp"
Junxiao Shia110f262014-10-12 12:35:20 -070040#include "table/dead-nonce-list.hpp"
Junxiao Shi0355e9f2015-09-02 07:24:53 -070041#include "table/network-region-table.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080042
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080043namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080044
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070045namespace fw {
46class Strategy;
47} // namespace fw
48
49/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070050 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070051 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080052 */
53class Forwarder
54{
55public:
Junxiao Shic041ca32014-02-25 20:01:15 -070056 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080057
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060058 VIRTUAL_WITH_TESTS
59 ~Forwarder();
60
Junxiao Shib289cc12014-03-15 12:19:05 -070061 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000062 getCounters() const
63 {
64 return m_counters;
65 }
Junxiao Shib289cc12014-03-15 12:19:05 -070066
Junxiao Shifbe8efe2016-08-22 16:02:30 +000067public: // faces and policies
Junxiao Shia4f2be82014-03-02 22:56:41 -070068 FaceTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +000069 getFaceTable()
70 {
71 return m_faceTable;
72 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070073
74 /** \brief get existing Face
75 *
76 * shortcut to .getFaceTable().get(face)
77 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000078 Face*
Junxiao Shib9420cf2016-08-13 04:38:52 +000079 getFace(FaceId id) const
80 {
81 return m_faceTable.get(id);
82 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070083
84 /** \brief add new Face
85 *
86 * shortcut to .getFaceTable().add(face)
87 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070088 void
Junxiao Shib9420cf2016-08-13 04:38:52 +000089 addFace(shared_ptr<Face> face)
90 {
91 m_faceTable.add(face);
92 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080093
Junxiao Shifbe8efe2016-08-22 16:02:30 +000094 fw::UnsolicitedDataPolicy&
95 getUnsolicitedDataPolicy() const
96 {
97 return *m_unsolicitedDataPolicy;
98 }
99
100 void
101 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
102 {
103 BOOST_ASSERT(policy != nullptr);
104 m_unsolicitedDataPolicy = std::move(policy);
105 }
106
Junxiao Shia4f2be82014-03-02 22:56:41 -0700107public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700108 /** \brief start incoming Interest processing
ashiqopuc7079482019-02-20 05:34:37 +0000109 * \param ingress face on which Interest is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000110 * \param interest the incoming Interest, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700111 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800112 void
ashiqopuc7079482019-02-20 05:34:37 +0000113 startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000114 {
ashiqopuc7079482019-02-20 05:34:37 +0000115 this->onIncomingInterest(ingress, interest);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000116 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800117
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700118 /** \brief start incoming Data processing
ashiqopuc7079482019-02-20 05:34:37 +0000119 * \param ingress face on which Data is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000120 * \param data the incoming Data, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700121 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800122 void
ashiqopuc7079482019-02-20 05:34:37 +0000123 startProcessData(const FaceEndpoint& ingress, const Data& data)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000124 {
ashiqopuc7079482019-02-20 05:34:37 +0000125 this->onIncomingData(ingress, data);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000126 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700127
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700128 /** \brief start incoming Nack processing
ashiqopuc7079482019-02-20 05:34:37 +0000129 * \param ingress face on which Nack is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000130 * \param nack the incoming Nack, must be well-formed
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700131 */
132 void
ashiqopuc7079482019-02-20 05:34:37 +0000133 startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000134 {
ashiqopuc7079482019-02-20 05:34:37 +0000135 this->onIncomingNack(ingress, nack);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000136 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700137
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700138 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000139 getNameTree()
140 {
141 return m_nameTree;
142 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700143
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700144 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000145 getFib()
146 {
147 return m_fib;
148 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700149
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700150 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000151 getPit()
152 {
153 return m_pit;
154 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700155
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700156 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000157 getCs()
158 {
159 return m_cs;
160 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700161
Junxiao Shidbe71732014-02-21 22:23:28 -0700162 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000163 getMeasurements()
164 {
165 return m_measurements;
166 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700167
Junxiao Shibb5105f2014-03-03 12:06:45 -0700168 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000169 getStrategyChoice()
170 {
171 return m_strategyChoice;
172 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700173
Junxiao Shia110f262014-10-12 12:35:20 -0700174 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000175 getDeadNonceList()
176 {
177 return m_deadNonceList;
178 }
Junxiao Shia110f262014-10-12 12:35:20 -0700179
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700180 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000181 getNetworkRegionTable()
182 {
183 return m_networkRegionTable;
184 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700185
Junxiao Shi88884492014-02-15 15:57:43 -0700186PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700187 /** \brief incoming Interest pipeline
188 */
Junxiao Shi88884492014-02-15 15:57:43 -0700189 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000190 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700191
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700192 /** \brief Interest loop pipeline
193 */
194 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000195 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700196
mzhang4eab72492015-02-25 11:16:09 -0600197 /** \brief Content Store miss pipeline
198 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700199 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000200 onContentStoreMiss(const FaceEndpoint& ingress,
201 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600202
203 /** \brief Content Store hit pipeline
204 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700205 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000206 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600207 const Interest& interest, const Data& data);
208
Junxiao Shid3c792f2014-01-30 00:46:13 -0700209 /** \brief outgoing Interest pipeline
210 */
Junxiao Shi88884492014-02-15 15:57:43 -0700211 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000212 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
213 const FaceEndpoint& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700214
Junxiao Shia110f262014-10-12 12:35:20 -0700215 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700216 */
217 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700218 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700219
Junxiao Shid3c792f2014-01-30 00:46:13 -0700220 /** \brief incoming Data pipeline
221 */
Junxiao Shi88884492014-02-15 15:57:43 -0700222 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000223 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700224
Junxiao Shid3c792f2014-01-30 00:46:13 -0700225 /** \brief Data unsolicited pipeline
226 */
Junxiao Shi88884492014-02-15 15:57:43 -0700227 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000228 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700229
Junxiao Shid3c792f2014-01-30 00:46:13 -0700230 /** \brief outgoing Data pipeline
231 */
Junxiao Shi88884492014-02-15 15:57:43 -0700232 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000233 onOutgoingData(const Data& data, FaceEndpoint egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700234
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700235 /** \brief incoming Nack pipeline
236 */
237 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000238 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700239
240 /** \brief outgoing Nack pipeline
241 */
242 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000243 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
244 const FaceEndpoint& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700245
Eric Newberry41aba102017-11-01 16:42:13 -0700246 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000247 onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700248
Junxiao Shi88884492014-02-15 15:57:43 -0700249PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700250 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
251 */
252 void
253 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700254
Junxiao Shia110f262014-10-12 12:35:20 -0700255 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700256 * \param upstream if null, insert Nonces from all out-records;
257 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700258 */
259 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700260 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700261
Junxiao Shib9420cf2016-08-13 04:38:52 +0000262 /** \brief call trigger (method) on the effective strategy of pitEntry
263 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700264#ifdef WITH_TESTS
265 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400266 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700267#else
268 template<class Function>
269 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000270 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700271#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000272 {
273 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
274 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700275
276private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700277 ForwarderCounters m_counters;
278
Junxiao Shia4f2be82014-03-02 22:56:41 -0700279 FaceTable m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000280 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800281
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700282 NameTree m_nameTree;
283 Fib m_fib;
284 Pit m_pit;
285 Cs m_cs;
286 Measurements m_measurements;
287 StrategyChoice m_strategyChoice;
288 DeadNonceList m_deadNonceList;
289 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700290
Junxiao Shid3c792f2014-01-30 00:46:13 -0700291 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700292 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800293};
294
Junxiao Shid3c792f2014-01-30 00:46:13 -0700295} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800296
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700297#endif // NFD_DAEMON_FW_FORWARDER_HPP