blob: 18ca4839acd78cc13ce229e0506c500d3852c5af [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
ashiqopuc7079482019-02-20 05:34:37 +000029#include "face-endpoint.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060030#include "face-table.hpp"
31#include "forwarder-counters.hpp"
Junxiao Shifbe8efe2016-08-22 16:02:30 +000032#include "unsolicited-data-policy.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 Pesavento3dade002019-03-19 11:29:56 -060047/** \brief Main class of NFD forwarding engine.
Junxiao Shic041ca32014-02-25 20:01:15 -070048 *
Davide Pesavento3dade002019-03-19 11:29:56 -060049 * Forwarder owns all faces and tables, and implements the forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080050 */
51class Forwarder
52{
53public:
Junxiao Shic041ca32014-02-25 20:01:15 -070054 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080055
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060056 VIRTUAL_WITH_TESTS
57 ~Forwarder();
58
Junxiao Shib289cc12014-03-15 12:19:05 -070059 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000060 getCounters() const
61 {
62 return m_counters;
63 }
Junxiao Shib289cc12014-03-15 12:19:05 -070064
Junxiao Shifbe8efe2016-08-22 16:02:30 +000065public: // faces and policies
Junxiao Shia4f2be82014-03-02 22:56:41 -070066 FaceTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +000067 getFaceTable()
68 {
69 return m_faceTable;
70 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070071
72 /** \brief get existing Face
73 *
74 * shortcut to .getFaceTable().get(face)
75 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000076 Face*
Junxiao Shib9420cf2016-08-13 04:38:52 +000077 getFace(FaceId id) const
78 {
79 return m_faceTable.get(id);
80 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070081
82 /** \brief add new Face
83 *
84 * shortcut to .getFaceTable().add(face)
85 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070086 void
Junxiao Shib9420cf2016-08-13 04:38:52 +000087 addFace(shared_ptr<Face> face)
88 {
89 m_faceTable.add(face);
90 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080091
Junxiao Shifbe8efe2016-08-22 16:02:30 +000092 fw::UnsolicitedDataPolicy&
93 getUnsolicitedDataPolicy() const
94 {
95 return *m_unsolicitedDataPolicy;
96 }
97
98 void
99 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
100 {
101 BOOST_ASSERT(policy != nullptr);
102 m_unsolicitedDataPolicy = std::move(policy);
103 }
104
Junxiao Shia4f2be82014-03-02 22:56:41 -0700105public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700106 /** \brief start incoming Interest processing
ashiqopuc7079482019-02-20 05:34:37 +0000107 * \param ingress face on which Interest is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000108 * \param interest the incoming Interest, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700109 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800110 void
ashiqopuc7079482019-02-20 05:34:37 +0000111 startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000112 {
ashiqopuc7079482019-02-20 05:34:37 +0000113 this->onIncomingInterest(ingress, interest);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000114 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800115
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700116 /** \brief start incoming Data processing
ashiqopuc7079482019-02-20 05:34:37 +0000117 * \param ingress face on which Data is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000118 * \param data the incoming Data, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700119 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800120 void
ashiqopuc7079482019-02-20 05:34:37 +0000121 startProcessData(const FaceEndpoint& ingress, const Data& data)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000122 {
ashiqopuc7079482019-02-20 05:34:37 +0000123 this->onIncomingData(ingress, data);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000124 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700125
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700126 /** \brief start incoming Nack processing
ashiqopuc7079482019-02-20 05:34:37 +0000127 * \param ingress face on which Nack is received and endpoint of the sender
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000128 * \param nack the incoming Nack, must be well-formed
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700129 */
130 void
ashiqopuc7079482019-02-20 05:34:37 +0000131 startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000132 {
ashiqopuc7079482019-02-20 05:34:37 +0000133 this->onIncomingNack(ingress, nack);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000134 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700135
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700136 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000137 getNameTree()
138 {
139 return m_nameTree;
140 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700141
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700142 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000143 getFib()
144 {
145 return m_fib;
146 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700147
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700148 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000149 getPit()
150 {
151 return m_pit;
152 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700153
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700154 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000155 getCs()
156 {
157 return m_cs;
158 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700159
Junxiao Shidbe71732014-02-21 22:23:28 -0700160 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000161 getMeasurements()
162 {
163 return m_measurements;
164 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700165
Junxiao Shibb5105f2014-03-03 12:06:45 -0700166 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000167 getStrategyChoice()
168 {
169 return m_strategyChoice;
170 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700171
Junxiao Shia110f262014-10-12 12:35:20 -0700172 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000173 getDeadNonceList()
174 {
175 return m_deadNonceList;
176 }
Junxiao Shia110f262014-10-12 12:35:20 -0700177
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700178 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000179 getNetworkRegionTable()
180 {
181 return m_networkRegionTable;
182 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700183
Junxiao Shi88884492014-02-15 15:57:43 -0700184PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700185 /** \brief incoming Interest pipeline
186 */
Junxiao Shi88884492014-02-15 15:57:43 -0700187 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000188 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700189
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700190 /** \brief Interest loop pipeline
191 */
192 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000193 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700194
mzhang4eab72492015-02-25 11:16:09 -0600195 /** \brief Content Store miss pipeline
196 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700197 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000198 onContentStoreMiss(const FaceEndpoint& ingress,
199 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600200
201 /** \brief Content Store hit pipeline
202 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700203 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000204 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600205 const Interest& interest, const Data& data);
206
Junxiao Shid3c792f2014-01-30 00:46:13 -0700207 /** \brief outgoing Interest pipeline
208 */
Junxiao Shi88884492014-02-15 15:57:43 -0700209 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000210 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
211 const FaceEndpoint& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700212
Junxiao Shia110f262014-10-12 12:35:20 -0700213 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700214 */
215 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700216 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700217
Junxiao Shid3c792f2014-01-30 00:46:13 -0700218 /** \brief incoming Data pipeline
219 */
Junxiao Shi88884492014-02-15 15:57:43 -0700220 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000221 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700222
Junxiao Shid3c792f2014-01-30 00:46:13 -0700223 /** \brief Data unsolicited pipeline
224 */
Junxiao Shi88884492014-02-15 15:57:43 -0700225 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000226 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700227
Junxiao Shid3c792f2014-01-30 00:46:13 -0700228 /** \brief outgoing Data pipeline
229 */
Junxiao Shi88884492014-02-15 15:57:43 -0700230 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000231 onOutgoingData(const Data& data, FaceEndpoint egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700232
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700233 /** \brief incoming Nack pipeline
234 */
235 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000236 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700237
238 /** \brief outgoing Nack pipeline
239 */
240 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000241 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
242 const FaceEndpoint& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700243
Eric Newberry41aba102017-11-01 16:42:13 -0700244 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000245 onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700246
Junxiao Shi88884492014-02-15 15:57:43 -0700247PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700248 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
249 */
250 void
251 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700252
Junxiao Shia110f262014-10-12 12:35:20 -0700253 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700254 * \param upstream if null, insert Nonces from all out-records;
255 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700256 */
257 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700258 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700259
Junxiao Shib9420cf2016-08-13 04:38:52 +0000260 /** \brief call trigger (method) on the effective strategy of pitEntry
261 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700262#ifdef WITH_TESTS
263 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400264 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700265#else
266 template<class Function>
267 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000268 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700269#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000270 {
271 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
272 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700273
274private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700275 ForwarderCounters m_counters;
276
Junxiao Shia4f2be82014-03-02 22:56:41 -0700277 FaceTable m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000278 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800279
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700280 NameTree m_nameTree;
281 Fib m_fib;
282 Pit m_pit;
283 Cs m_cs;
284 Measurements m_measurements;
285 StrategyChoice m_strategyChoice;
286 DeadNonceList m_deadNonceList;
287 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700288
Junxiao Shid3c792f2014-01-30 00:46:13 -0700289 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700290 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800291};
292
Junxiao Shid3c792f2014-01-30 00:46:13 -0700293} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800294
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700295#endif // NFD_DAEMON_FW_FORWARDER_HPP