blob: 3b28a261502344dcd4cb71998c3ac5e961b83917 [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
Alexander Afanasyev48ba4c12019-07-27 18:36:48 -0400179 /** \brief Signals when the incoming interest pipeline gets a hit from the content store
180 */
181 signal::Signal<Forwarder, Interest, Data> afterCsHit;
182
183 /** \brief Signals when the incoming interest pipeline gets a miss from the content store
184 */
185 signal::Signal<Forwarder, Interest> afterCsMiss;
186
Junxiao Shi88884492014-02-15 15:57:43 -0700187PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700188 /** \brief incoming Interest pipeline
189 */
Junxiao Shi88884492014-02-15 15:57:43 -0700190 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000191 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700192
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700193 /** \brief Interest loop pipeline
194 */
195 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000196 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700197
mzhang4eab72492015-02-25 11:16:09 -0600198 /** \brief Content Store miss pipeline
199 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700200 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000201 onContentStoreMiss(const FaceEndpoint& ingress,
202 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600203
204 /** \brief Content Store hit pipeline
205 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700206 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000207 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600208 const Interest& interest, const Data& data);
209
Junxiao Shid3c792f2014-01-30 00:46:13 -0700210 /** \brief outgoing Interest pipeline
211 */
Junxiao Shi88884492014-02-15 15:57:43 -0700212 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000213 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
214 const FaceEndpoint& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700215
Junxiao Shia110f262014-10-12 12:35:20 -0700216 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700217 */
218 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700219 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700220
Junxiao Shid3c792f2014-01-30 00:46:13 -0700221 /** \brief incoming Data pipeline
222 */
Junxiao Shi88884492014-02-15 15:57:43 -0700223 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000224 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700225
Junxiao Shid3c792f2014-01-30 00:46:13 -0700226 /** \brief Data unsolicited pipeline
227 */
Junxiao Shi88884492014-02-15 15:57:43 -0700228 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000229 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700230
Junxiao Shid3c792f2014-01-30 00:46:13 -0700231 /** \brief outgoing Data pipeline
232 */
Junxiao Shi88884492014-02-15 15:57:43 -0700233 VIRTUAL_WITH_TESTS void
ashiqopu075bb7d2019-03-10 01:38:21 +0000234 onOutgoingData(const Data& data, const FaceEndpoint& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700235
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700236 /** \brief incoming Nack pipeline
237 */
238 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000239 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700240
241 /** \brief outgoing Nack pipeline
242 */
243 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000244 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
245 const FaceEndpoint& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700246
Eric Newberry41aba102017-11-01 16:42:13 -0700247 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000248 onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700249
Ju Pan2feb4592019-09-16 20:56:38 +0000250 VIRTUAL_WITH_TESTS void
251 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
252
Junxiao Shi88884492014-02-15 15:57:43 -0700253PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700254 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
255 */
256 void
257 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700258
Junxiao Shia110f262014-10-12 12:35:20 -0700259 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700260 * \param upstream if null, insert Nonces from all out-records;
261 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700262 */
263 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700264 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700265
Junxiao Shib9420cf2016-08-13 04:38:52 +0000266 /** \brief call trigger (method) on the effective strategy of pitEntry
267 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700268#ifdef WITH_TESTS
269 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400270 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700271#else
272 template<class Function>
273 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000274 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700275#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000276 {
277 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
278 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700279
280private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700281 ForwarderCounters m_counters;
282
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400283 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000284 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800285
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700286 NameTree m_nameTree;
287 Fib m_fib;
288 Pit m_pit;
289 Cs m_cs;
290 Measurements m_measurements;
291 StrategyChoice m_strategyChoice;
292 DeadNonceList m_deadNonceList;
293 NetworkRegionTable m_networkRegionTable;
Alexander Afanasyev54c4c5d2018-08-06 17:28:36 -0400294 shared_ptr<Face> m_csFace;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700295
Junxiao Shid3c792f2014-01-30 00:46:13 -0700296 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700297 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800298};
299
Junxiao Shid3c792f2014-01-30 00:46:13 -0700300} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800301
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700302#endif // NFD_DAEMON_FW_FORWARDER_HPP