blob: 39cc0b811414fc90ac232558c38907f6a2ca223f [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
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
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060057 VIRTUAL_WITH_TESTS
58 ~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
Ju Pan2feb4592019-09-16 20:56:38 +0000110 /** \brief start new nexthop processing
111 * \param prefix the prefix of the FibEntry containing the new nexthop
112 * \param nextHop the new NextHop
113 */
114 void
115 startProcessNewNextHop(const Name& prefix, const fib::NextHop& nextHop)
116 {
117 this->onNewNextHop(prefix, nextHop);
118 }
119
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700120 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000121 getNameTree()
122 {
123 return m_nameTree;
124 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700125
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700126 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000127 getFib()
128 {
129 return m_fib;
130 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700131
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700132 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000133 getPit()
134 {
135 return m_pit;
136 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700137
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700138 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000139 getCs()
140 {
141 return m_cs;
142 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700143
Junxiao Shidbe71732014-02-21 22:23:28 -0700144 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000145 getMeasurements()
146 {
147 return m_measurements;
148 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700149
Junxiao Shibb5105f2014-03-03 12:06:45 -0700150 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000151 getStrategyChoice()
152 {
153 return m_strategyChoice;
154 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700155
Junxiao Shia110f262014-10-12 12:35:20 -0700156 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000157 getDeadNonceList()
158 {
159 return m_deadNonceList;
160 }
Junxiao Shia110f262014-10-12 12:35:20 -0700161
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700162 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000163 getNetworkRegionTable()
164 {
165 return m_networkRegionTable;
166 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700167
Alexander Afanasyev54c4c5d2018-08-06 17:28:36 -0400168public:
169 /** \brief trigger before PIT entry is satisfied
170 * \sa Strategy::beforeSatisfyInterest
171 */
172 signal::Signal<Forwarder, pit::Entry, Face, Data> beforeSatisfyInterest;
173
174 /** \brief trigger before PIT entry expires
175 * \sa Strategy::beforeExpirePendingInterest
176 */
177 signal::Signal<Forwarder, pit::Entry> beforeExpirePendingInterest;
178
Junxiao Shi88884492014-02-15 15:57:43 -0700179PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700180 /** \brief incoming Interest pipeline
181 */
Junxiao Shi88884492014-02-15 15:57:43 -0700182 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000183 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700184
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700185 /** \brief Interest loop pipeline
186 */
187 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000188 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700189
mzhang4eab72492015-02-25 11:16:09 -0600190 /** \brief Content Store miss pipeline
191 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700192 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000193 onContentStoreMiss(const FaceEndpoint& ingress,
194 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600195
196 /** \brief Content Store hit pipeline
197 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700198 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000199 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600200 const Interest& interest, const Data& data);
201
Junxiao Shid3c792f2014-01-30 00:46:13 -0700202 /** \brief outgoing Interest pipeline
203 */
Junxiao Shi88884492014-02-15 15:57:43 -0700204 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000205 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
206 const FaceEndpoint& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700207
Junxiao Shia110f262014-10-12 12:35:20 -0700208 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700209 */
210 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700211 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700212
Junxiao Shid3c792f2014-01-30 00:46:13 -0700213 /** \brief incoming Data pipeline
214 */
Junxiao Shi88884492014-02-15 15:57:43 -0700215 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000216 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700217
Junxiao Shid3c792f2014-01-30 00:46:13 -0700218 /** \brief Data unsolicited pipeline
219 */
Junxiao Shi88884492014-02-15 15:57:43 -0700220 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000221 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700222
Junxiao Shid3c792f2014-01-30 00:46:13 -0700223 /** \brief outgoing Data pipeline
224 */
Junxiao Shi88884492014-02-15 15:57:43 -0700225 VIRTUAL_WITH_TESTS void
ashiqopu075bb7d2019-03-10 01:38:21 +0000226 onOutgoingData(const Data& data, const FaceEndpoint& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700227
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700228 /** \brief incoming Nack pipeline
229 */
230 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000231 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700232
233 /** \brief outgoing Nack pipeline
234 */
235 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000236 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
237 const FaceEndpoint& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700238
Eric Newberry41aba102017-11-01 16:42:13 -0700239 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000240 onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700241
Ju Pan2feb4592019-09-16 20:56:38 +0000242 VIRTUAL_WITH_TESTS void
243 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
244
Junxiao Shi88884492014-02-15 15:57:43 -0700245PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700246 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
247 */
248 void
249 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700250
Junxiao Shia110f262014-10-12 12:35:20 -0700251 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700252 * \param upstream if null, insert Nonces from all out-records;
253 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700254 */
255 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700256 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700257
Junxiao Shib9420cf2016-08-13 04:38:52 +0000258 /** \brief call trigger (method) on the effective strategy of pitEntry
259 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700260#ifdef WITH_TESTS
261 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400262 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700263#else
264 template<class Function>
265 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000266 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700267#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000268 {
269 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
270 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700271
272private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700273 ForwarderCounters m_counters;
274
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400275 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000276 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800277
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700278 NameTree m_nameTree;
279 Fib m_fib;
280 Pit m_pit;
281 Cs m_cs;
282 Measurements m_measurements;
283 StrategyChoice m_strategyChoice;
284 DeadNonceList m_deadNonceList;
285 NetworkRegionTable m_networkRegionTable;
Alexander Afanasyev54c4c5d2018-08-06 17:28:36 -0400286 shared_ptr<Face> m_csFace;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700287
Junxiao Shid3c792f2014-01-30 00:46:13 -0700288 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700289 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800290};
291
Junxiao Shid3c792f2014-01-30 00:46:13 -0700292} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800293
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700294#endif // NFD_DAEMON_FW_FORWARDER_HPP