blob: 00645badf446ef2bfcd18dd2475eed557d2898b7 [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi330136a2016-03-10 04:53:08 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
4 * 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"
Junxiao Shifbe8efe2016-08-22 16:02:30 +000033#include "unsolicited-data-policy.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070034#include "table/fib.hpp"
35#include "table/pit.hpp"
36#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070037#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070038#include "table/strategy-choice.hpp"
Junxiao Shia110f262014-10-12 12:35:20 -070039#include "table/dead-nonce-list.hpp"
Junxiao Shi0355e9f2015-09-02 07:24:53 -070040#include "table/network-region-table.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080041
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080042namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080043
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070044namespace fw {
45class Strategy;
46} // namespace fw
47
48/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070049 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070050 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080051 */
52class Forwarder
53{
54public:
Junxiao Shic041ca32014-02-25 20:01:15 -070055 Forwarder();
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 +000066public: // faces and policies
Junxiao Shia4f2be82014-03-02 22:56:41 -070067 FaceTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +000068 getFaceTable()
69 {
70 return m_faceTable;
71 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070072
73 /** \brief get existing Face
74 *
75 * shortcut to .getFaceTable().get(face)
76 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000077 Face*
Junxiao Shib9420cf2016-08-13 04:38:52 +000078 getFace(FaceId id) const
79 {
80 return m_faceTable.get(id);
81 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070082
83 /** \brief add new Face
84 *
85 * shortcut to .getFaceTable().add(face)
86 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070087 void
Junxiao Shib9420cf2016-08-13 04:38:52 +000088 addFace(shared_ptr<Face> face)
89 {
90 m_faceTable.add(face);
91 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080092
Junxiao Shifbe8efe2016-08-22 16:02:30 +000093 fw::UnsolicitedDataPolicy&
94 getUnsolicitedDataPolicy() const
95 {
96 return *m_unsolicitedDataPolicy;
97 }
98
99 void
100 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
101 {
102 BOOST_ASSERT(policy != nullptr);
103 m_unsolicitedDataPolicy = std::move(policy);
104 }
105
Junxiao Shia4f2be82014-03-02 22:56:41 -0700106public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700107 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500108 * \param face face on which Interest is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700109 * \param interest the incoming Interest, must be created with make_shared
110 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800111 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700112 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800113
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700114 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500115 * \param face face on which Data is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700116 * \param data the incoming Data, must be created with make_shared
117 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800118 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700119 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700120
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700121 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500122 * \param face face on which Nack is received
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700123 * \param nack the incoming Nack, must be created with make_shared
124 */
125 void
126 startProcessNack(Face& face, const lp::Nack& nack);
127
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700128 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000129 getNameTree()
130 {
131 return m_nameTree;
132 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700133
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700134 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000135 getFib()
136 {
137 return m_fib;
138 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700139
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700140 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000141 getPit()
142 {
143 return m_pit;
144 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700145
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700146 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000147 getCs()
148 {
149 return m_cs;
150 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700151
Junxiao Shidbe71732014-02-21 22:23:28 -0700152 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000153 getMeasurements()
154 {
155 return m_measurements;
156 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700157
Junxiao Shibb5105f2014-03-03 12:06:45 -0700158 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000159 getStrategyChoice()
160 {
161 return m_strategyChoice;
162 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700163
Junxiao Shia110f262014-10-12 12:35:20 -0700164 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000165 getDeadNonceList()
166 {
167 return m_deadNonceList;
168 }
Junxiao Shia110f262014-10-12 12:35:20 -0700169
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700170 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000171 getNetworkRegionTable()
172 {
173 return m_networkRegionTable;
174 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700175
Junxiao Shi05cc50a2016-07-11 22:38:21 +0000176 /** \brief performs a FIB lookup, considering Link object if present
177 */
178 const fib::Entry&
179 lookupFib(const pit::Entry& pitEntry) const;
180
Junxiao Shi88884492014-02-15 15:57:43 -0700181PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700182 /** \brief incoming Interest pipeline
183 */
Junxiao Shi88884492014-02-15 15:57:43 -0700184 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700185 onIncomingInterest(Face& inFace, const Interest& interest);
186
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700187 /** \brief Interest loop pipeline
188 */
189 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700190 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700191
mzhang4eab72492015-02-25 11:16:09 -0600192 /** \brief Content Store miss pipeline
193 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700194 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000195 onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
196 const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600197
198 /** \brief Content Store hit pipeline
199 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700200 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000201 onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600202 const Interest& interest, const Data& data);
203
Junxiao Shid3c792f2014-01-30 00:46:13 -0700204 /** \brief outgoing Interest pipeline
205 */
Junxiao Shi88884492014-02-15 15:57:43 -0700206 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000207 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
Junxiao Shid938a6b2014-05-11 23:40:29 -0700208 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700209
Junxiao Shi09498f02014-02-26 19:41:08 -0700210 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700211 */
Junxiao Shi88884492014-02-15 15:57:43 -0700212 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000213 onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700214
Junxiao Shid3c792f2014-01-30 00:46:13 -0700215 /** \brief Interest unsatisfied pipeline
216 */
Junxiao Shi88884492014-02-15 15:57:43 -0700217 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000218 onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700219
Junxiao Shia110f262014-10-12 12:35:20 -0700220 /** \brief Interest finalize pipeline
221 * \param isSatisfied whether the Interest has been satisfied
222 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
223 */
224 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000225 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
226 time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shia110f262014-10-12 12:35:20 -0700227
Junxiao Shid3c792f2014-01-30 00:46:13 -0700228 /** \brief incoming Data pipeline
229 */
Junxiao Shi88884492014-02-15 15:57:43 -0700230 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700231 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700232
Junxiao Shid3c792f2014-01-30 00:46:13 -0700233 /** \brief Data unsolicited pipeline
234 */
Junxiao Shi88884492014-02-15 15:57:43 -0700235 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700236 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700237
Junxiao Shid3c792f2014-01-30 00:46:13 -0700238 /** \brief outgoing Data pipeline
239 */
Junxiao Shi88884492014-02-15 15:57:43 -0700240 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700241 onOutgoingData(const Data& data, Face& outFace);
242
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700243 /** \brief incoming Nack pipeline
244 */
245 VIRTUAL_WITH_TESTS void
246 onIncomingNack(Face& inFace, const lp::Nack& nack);
247
248 /** \brief outgoing Nack pipeline
249 */
250 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000251 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700252
Junxiao Shi88884492014-02-15 15:57:43 -0700253PROTECTED_WITH_TESTS_ELSE_PRIVATE:
254 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000255 setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700256
Junxiao Shi88884492014-02-15 15:57:43 -0700257 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000258 setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
259 time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700260
Junxiao Shi88884492014-02-15 15:57:43 -0700261 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000262 cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700263
Junxiao Shia110f262014-10-12 12:35:20 -0700264 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700265 * \param upstream if null, insert Nonces from all out-records;
266 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700267 */
268 VIRTUAL_WITH_TESTS void
269 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
Junxiao Shib9420cf2016-08-13 04:38:52 +0000270 time::milliseconds dataFreshnessPeriod, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700271
Junxiao Shib9420cf2016-08-13 04:38:52 +0000272 /** \brief call trigger (method) on the effective strategy of pitEntry
273 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700274#ifdef WITH_TESTS
275 virtual void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000276 dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700277#else
278 template<class Function>
279 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000280 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700281#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000282 {
283 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
284 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700285
286private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700287 ForwarderCounters m_counters;
288
Junxiao Shia4f2be82014-03-02 22:56:41 -0700289 FaceTable m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000290 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800291
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700292 NameTree m_nameTree;
293 Fib m_fib;
294 Pit m_pit;
295 Cs m_cs;
296 Measurements m_measurements;
297 StrategyChoice m_strategyChoice;
298 DeadNonceList m_deadNonceList;
299 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700300
Junxiao Shid3c792f2014-01-30 00:46:13 -0700301 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700302 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800303};
304
Junxiao Shid3c792f2014-01-30 00:46:13 -0700305} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800306
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700307#endif // NFD_DAEMON_FW_FORWARDER_HPP