blob: b561d6f2fba88da465b6f2306eef69cf44856f3c [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 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
47/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070048 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070049 * Forwarder owns all faces and tables, and implements 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&
60 getCounters() const;
61
Junxiao Shia4f2be82014-03-02 22:56:41 -070062public: // faces
63 FaceTable&
64 getFaceTable();
65
66 /** \brief get existing Face
67 *
68 * shortcut to .getFaceTable().get(face)
69 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000070 Face*
Junxiao Shia4f2be82014-03-02 22:56:41 -070071 getFace(FaceId id) const;
72
73 /** \brief add new Face
74 *
75 * shortcut to .getFaceTable().add(face)
76 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070077 void
78 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080079
Junxiao Shia4f2be82014-03-02 22:56:41 -070080public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -070081 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050082 * \param face face on which Interest is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070083 * \param interest the incoming Interest, must be created with make_shared
84 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080085 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070086 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080087
Junxiao Shi0355e9f2015-09-02 07:24:53 -070088 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050089 * \param face face on which Data is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070090 * \param data the incoming Data, must be created with make_shared
91 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080092 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070093 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070094
Junxiao Shi5e5e4452015-09-24 16:56:52 -070095 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050096 * \param face face on which Nack is received
Junxiao Shi5e5e4452015-09-24 16:56:52 -070097 * \param nack the incoming Nack, must be created with make_shared
98 */
99 void
100 startProcessNack(Face& face, const lp::Nack& nack);
101
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700102 NameTree&
103 getNameTree();
104
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700105 Fib&
106 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -0700107
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700108 Pit&
109 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -0700110
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700111 Cs&
112 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -0700113
Junxiao Shidbe71732014-02-21 22:23:28 -0700114 Measurements&
115 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700116
Junxiao Shibb5105f2014-03-03 12:06:45 -0700117 StrategyChoice&
118 getStrategyChoice();
119
Junxiao Shia110f262014-10-12 12:35:20 -0700120 DeadNonceList&
121 getDeadNonceList();
122
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700123 NetworkRegionTable&
124 getNetworkRegionTable();
125
Junxiao Shi05cc50a2016-07-11 22:38:21 +0000126 /** \brief performs a FIB lookup, considering Link object if present
127 */
128 const fib::Entry&
129 lookupFib(const pit::Entry& pitEntry) const;
130
Junxiao Shi88884492014-02-15 15:57:43 -0700131PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132 /** \brief incoming Interest pipeline
133 */
Junxiao Shi88884492014-02-15 15:57:43 -0700134 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700135 onIncomingInterest(Face& inFace, const Interest& interest);
136
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700137 /** \brief Interest loop pipeline
138 */
139 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700140 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700141
mzhang4eab72492015-02-25 11:16:09 -0600142 /** \brief Content Store miss pipeline
143 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700144 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600145 onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
146
147 /** \brief Content Store hit pipeline
148 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700149 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600150 onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
151 const Interest& interest, const Data& data);
152
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 /** \brief outgoing Interest pipeline
154 */
Junxiao Shi88884492014-02-15 15:57:43 -0700155 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700156 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
157 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700158
Junxiao Shi09498f02014-02-26 19:41:08 -0700159 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700160 */
Junxiao Shi88884492014-02-15 15:57:43 -0700161 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700162 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700163
Junxiao Shid3c792f2014-01-30 00:46:13 -0700164 /** \brief Interest unsatisfied pipeline
165 */
Junxiao Shi88884492014-02-15 15:57:43 -0700166 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700167 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700168
Junxiao Shia110f262014-10-12 12:35:20 -0700169 /** \brief Interest finalize pipeline
170 * \param isSatisfied whether the Interest has been satisfied
171 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
172 */
173 VIRTUAL_WITH_TESTS void
174 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
175 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
176
Junxiao Shid3c792f2014-01-30 00:46:13 -0700177 /** \brief incoming Data pipeline
178 */
Junxiao Shi88884492014-02-15 15:57:43 -0700179 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700180 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700181
Junxiao Shid3c792f2014-01-30 00:46:13 -0700182 /** \brief Data unsolicited pipeline
183 */
Junxiao Shi88884492014-02-15 15:57:43 -0700184 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700185 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700186
Junxiao Shid3c792f2014-01-30 00:46:13 -0700187 /** \brief outgoing Data pipeline
188 */
Junxiao Shi88884492014-02-15 15:57:43 -0700189 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700190 onOutgoingData(const Data& data, Face& outFace);
191
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700192 /** \brief incoming Nack pipeline
193 */
194 VIRTUAL_WITH_TESTS void
195 onIncomingNack(Face& inFace, const lp::Nack& nack);
196
197 /** \brief outgoing Nack pipeline
198 */
199 VIRTUAL_WITH_TESTS void
200 onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
201
Junxiao Shi88884492014-02-15 15:57:43 -0700202PROTECTED_WITH_TESTS_ELSE_PRIVATE:
203 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700204 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700205
Junxiao Shi88884492014-02-15 15:57:43 -0700206 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700207 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
208 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700209
Junxiao Shi88884492014-02-15 15:57:43 -0700210 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700211 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700212
Junxiao Shia110f262014-10-12 12:35:20 -0700213 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700214 * \param upstream if null, insert Nonces from all out-records;
215 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700216 */
217 VIRTUAL_WITH_TESTS void
218 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
219 const time::milliseconds& dataFreshnessPeriod,
220 Face* upstream);
221
Junxiao Shif3c07812014-03-11 21:48:49 -0700222 /// call trigger (method) on the effective strategy of pitEntry
223#ifdef WITH_TESTS
224 virtual void
225 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
226#else
227 template<class Function>
228 void
229 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
230#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700231
232private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700233 ForwarderCounters m_counters;
234
Junxiao Shia4f2be82014-03-02 22:56:41 -0700235 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800236
Junxiao Shibb5105f2014-03-03 12:06:45 -0700237 // tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700238 NameTree m_nameTree;
239 Fib m_fib;
240 Pit m_pit;
241 Cs m_cs;
242 Measurements m_measurements;
243 StrategyChoice m_strategyChoice;
244 DeadNonceList m_deadNonceList;
245 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700246
Junxiao Shid3c792f2014-01-30 00:46:13 -0700247 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700248 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800249};
250
Junxiao Shib289cc12014-03-15 12:19:05 -0700251inline const ForwarderCounters&
252Forwarder::getCounters() const
253{
254 return m_counters;
255}
256
Junxiao Shia4f2be82014-03-02 22:56:41 -0700257inline FaceTable&
258Forwarder::getFaceTable()
259{
260 return m_faceTable;
261}
262
Junxiao Shi5b43f9a2016-07-19 13:15:56 +0000263inline Face*
Junxiao Shia4f2be82014-03-02 22:56:41 -0700264Forwarder::getFace(FaceId id) const
265{
266 return m_faceTable.get(id);
267}
268
269inline void
270Forwarder::addFace(shared_ptr<Face> face)
271{
272 m_faceTable.add(face);
273}
274
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700275inline NameTree&
276Forwarder::getNameTree()
277{
278 return m_nameTree;
279}
280
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700281inline Fib&
282Forwarder::getFib()
283{
284 return m_fib;
285}
286
287inline Pit&
288Forwarder::getPit()
289{
290 return m_pit;
291}
292
293inline Cs&
294Forwarder::getCs()
295{
296 return m_cs;
297}
298
Junxiao Shidbe71732014-02-21 22:23:28 -0700299inline Measurements&
300Forwarder::getMeasurements()
301{
302 return m_measurements;
303}
304
Junxiao Shibb5105f2014-03-03 12:06:45 -0700305inline StrategyChoice&
306Forwarder::getStrategyChoice()
307{
308 return m_strategyChoice;
309}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700310
Junxiao Shia110f262014-10-12 12:35:20 -0700311inline DeadNonceList&
312Forwarder::getDeadNonceList()
313{
314 return m_deadNonceList;
315}
316
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700317inline NetworkRegionTable&
318Forwarder::getNetworkRegionTable()
319{
320 return m_networkRegionTable;
321}
322
Junxiao Shif3c07812014-03-11 21:48:49 -0700323#ifdef WITH_TESTS
324inline void
325Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
326#else
327template<class Function>
328inline void
329Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
330#endif
331{
332 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
333 trigger(&strategy);
334}
335
Junxiao Shid3c792f2014-01-30 00:46:13 -0700336} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800337
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700338#endif // NFD_DAEMON_FW_FORWARDER_HPP