blob: 2da7c878f8f57e9365f6a822d7930c54c7037530 [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
Junxiao Shi88884492014-02-15 15:57:43 -0700168PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700169 /** \brief incoming Interest pipeline
170 */
Junxiao Shi88884492014-02-15 15:57:43 -0700171 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000172 onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700173
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700174 /** \brief Interest loop pipeline
175 */
176 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000177 onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700178
mzhang4eab72492015-02-25 11:16:09 -0600179 /** \brief Content Store miss pipeline
180 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700181 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000182 onContentStoreMiss(const FaceEndpoint& ingress,
183 const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600184
185 /** \brief Content Store hit pipeline
186 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700187 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000188 onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600189 const Interest& interest, const Data& data);
190
Junxiao Shid3c792f2014-01-30 00:46:13 -0700191 /** \brief outgoing Interest pipeline
192 */
Junxiao Shi88884492014-02-15 15:57:43 -0700193 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000194 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
195 const FaceEndpoint& egress, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700196
Junxiao Shia110f262014-10-12 12:35:20 -0700197 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700198 */
199 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700200 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700201
Junxiao Shid3c792f2014-01-30 00:46:13 -0700202 /** \brief incoming Data pipeline
203 */
Junxiao Shi88884492014-02-15 15:57:43 -0700204 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000205 onIncomingData(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700206
Junxiao Shid3c792f2014-01-30 00:46:13 -0700207 /** \brief Data unsolicited pipeline
208 */
Junxiao Shi88884492014-02-15 15:57:43 -0700209 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000210 onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700211
Junxiao Shid3c792f2014-01-30 00:46:13 -0700212 /** \brief outgoing Data pipeline
213 */
Junxiao Shi88884492014-02-15 15:57:43 -0700214 VIRTUAL_WITH_TESTS void
ashiqopu075bb7d2019-03-10 01:38:21 +0000215 onOutgoingData(const Data& data, const FaceEndpoint& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700216
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700217 /** \brief incoming Nack pipeline
218 */
219 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000220 onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700221
222 /** \brief outgoing Nack pipeline
223 */
224 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000225 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
226 const FaceEndpoint& egress, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700227
Eric Newberry41aba102017-11-01 16:42:13 -0700228 VIRTUAL_WITH_TESTS void
ashiqopuc7079482019-02-20 05:34:37 +0000229 onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
Eric Newberry41aba102017-11-01 16:42:13 -0700230
Ju Pan2feb4592019-09-16 20:56:38 +0000231 VIRTUAL_WITH_TESTS void
232 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
233
Junxiao Shi88884492014-02-15 15:57:43 -0700234PROTECTED_WITH_TESTS_ELSE_PRIVATE:
Teng Liang7003e0b2018-03-03 16:03:30 -0700235 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
236 */
237 void
238 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700239
Junxiao Shia110f262014-10-12 12:35:20 -0700240 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700241 * \param upstream if null, insert Nonces from all out-records;
242 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700243 */
244 VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700245 insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700246
Junxiao Shib9420cf2016-08-13 04:38:52 +0000247 /** \brief call trigger (method) on the effective strategy of pitEntry
248 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700249#ifdef WITH_TESTS
250 virtual void
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400251 dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700252#else
253 template<class Function>
254 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000255 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700256#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000257 {
258 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
259 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700260
261private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700262 ForwarderCounters m_counters;
263
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400264 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000265 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800266
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700267 NameTree m_nameTree;
268 Fib m_fib;
269 Pit m_pit;
270 Cs m_cs;
271 Measurements m_measurements;
272 StrategyChoice m_strategyChoice;
273 DeadNonceList m_deadNonceList;
274 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700275
Junxiao Shid3c792f2014-01-30 00:46:13 -0700276 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700277 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800278};
279
Junxiao Shid3c792f2014-01-30 00:46:13 -0700280} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800281
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700282#endif // NFD_DAEMON_FW_FORWARDER_HPP