blob: ebfaa053f0be4a50e21e34fc082b60a5f0377cb8 [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shia110f262014-10-12 12:35:20 -07003 * Copyright (c) 2014, 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
29#include "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 */
70 shared_ptr<Face>
71 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
82 * \param interest the incoming Interest, must be created with make_shared
83 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080084 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070085 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080086
Junxiao Shi0355e9f2015-09-02 07:24:53 -070087 /** \brief start incoming Data processing
88 * \param data the incoming Data, must be created with make_shared
89 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080090 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070091 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070092
Junxiao Shi5e5e4452015-09-24 16:56:52 -070093 /** \brief start incoming Nack processing
94 * \param nack the incoming Nack, must be created with make_shared
95 */
96 void
97 startProcessNack(Face& face, const lp::Nack& nack);
98
Junxiao Shiea48d8b2014-03-16 13:53:47 -070099 NameTree&
100 getNameTree();
101
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700102 Fib&
103 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -0700104
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700105 Pit&
106 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -0700107
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700108 Cs&
109 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -0700110
Junxiao Shidbe71732014-02-21 22:23:28 -0700111 Measurements&
112 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700113
Junxiao Shibb5105f2014-03-03 12:06:45 -0700114 StrategyChoice&
115 getStrategyChoice();
116
Junxiao Shia110f262014-10-12 12:35:20 -0700117 DeadNonceList&
118 getDeadNonceList();
119
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700120 NetworkRegionTable&
121 getNetworkRegionTable();
122
Junxiao Shi88884492014-02-15 15:57:43 -0700123PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700124 /** \brief incoming Interest pipeline
125 */
Junxiao Shi88884492014-02-15 15:57:43 -0700126 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700127 onIncomingInterest(Face& inFace, const Interest& interest);
128
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700129 /** \brief Interest loop pipeline
130 */
131 VIRTUAL_WITH_TESTS void
132 onInterestLoop(Face& inFace, const Interest& interest,
133 shared_ptr<pit::Entry> pitEntry);
134
mzhang4eab72492015-02-25 11:16:09 -0600135 /** \brief Content Store miss pipeline
136 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700137 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600138 onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
139
140 /** \brief Content Store hit pipeline
141 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700142 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600143 onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
144 const Interest& interest, const Data& data);
145
Junxiao Shid3c792f2014-01-30 00:46:13 -0700146 /** \brief outgoing Interest pipeline
147 */
Junxiao Shi88884492014-02-15 15:57:43 -0700148 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700149 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
150 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700151
Junxiao Shi09498f02014-02-26 19:41:08 -0700152 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 */
Junxiao Shi88884492014-02-15 15:57:43 -0700154 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700155 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700156
Junxiao Shid3c792f2014-01-30 00:46:13 -0700157 /** \brief Interest unsatisfied pipeline
158 */
Junxiao Shi88884492014-02-15 15:57:43 -0700159 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700160 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700161
Junxiao Shia110f262014-10-12 12:35:20 -0700162 /** \brief Interest finalize pipeline
163 * \param isSatisfied whether the Interest has been satisfied
164 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
165 */
166 VIRTUAL_WITH_TESTS void
167 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
168 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
169
Junxiao Shid3c792f2014-01-30 00:46:13 -0700170 /** \brief incoming Data pipeline
171 */
Junxiao Shi88884492014-02-15 15:57:43 -0700172 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700173 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700174
Junxiao Shid3c792f2014-01-30 00:46:13 -0700175 /** \brief Data unsolicited pipeline
176 */
Junxiao Shi88884492014-02-15 15:57:43 -0700177 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700178 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700179
Junxiao Shid3c792f2014-01-30 00:46:13 -0700180 /** \brief outgoing Data pipeline
181 */
Junxiao Shi88884492014-02-15 15:57:43 -0700182 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700183 onOutgoingData(const Data& data, Face& outFace);
184
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700185 /** \brief incoming Nack pipeline
186 */
187 VIRTUAL_WITH_TESTS void
188 onIncomingNack(Face& inFace, const lp::Nack& nack);
189
190 /** \brief outgoing Nack pipeline
191 */
192 VIRTUAL_WITH_TESTS void
193 onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
194
Junxiao Shi88884492014-02-15 15:57:43 -0700195PROTECTED_WITH_TESTS_ELSE_PRIVATE:
196 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700197 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700198
Junxiao Shi88884492014-02-15 15:57:43 -0700199 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700200 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
201 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700202
Junxiao Shi88884492014-02-15 15:57:43 -0700203 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700204 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700205
Junxiao Shia110f262014-10-12 12:35:20 -0700206 /** \brief insert Nonce to Dead Nonce List if necessary
207 * \param upstream if null, insert Nonces from all OutRecords;
208 * if not null, insert Nonce only on the OutRecord of this face
209 */
210 VIRTUAL_WITH_TESTS void
211 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
212 const time::milliseconds& dataFreshnessPeriod,
213 Face* upstream);
214
Junxiao Shif3c07812014-03-11 21:48:49 -0700215 /// call trigger (method) on the effective strategy of pitEntry
216#ifdef WITH_TESTS
217 virtual void
218 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
219#else
220 template<class Function>
221 void
222 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
223#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700224
225private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700226 ForwarderCounters m_counters;
227
Junxiao Shia4f2be82014-03-02 22:56:41 -0700228 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800229
Junxiao Shibb5105f2014-03-03 12:06:45 -0700230 // tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700231 NameTree m_nameTree;
232 Fib m_fib;
233 Pit m_pit;
234 Cs m_cs;
235 Measurements m_measurements;
236 StrategyChoice m_strategyChoice;
237 DeadNonceList m_deadNonceList;
238 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700239
Junxiao Shif3c07812014-03-11 21:48:49 -0700240 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700241
Junxiao Shid3c792f2014-01-30 00:46:13 -0700242 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700243 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800244};
245
Junxiao Shib289cc12014-03-15 12:19:05 -0700246inline const ForwarderCounters&
247Forwarder::getCounters() const
248{
249 return m_counters;
250}
251
Junxiao Shia4f2be82014-03-02 22:56:41 -0700252inline FaceTable&
253Forwarder::getFaceTable()
254{
255 return m_faceTable;
256}
257
258inline shared_ptr<Face>
259Forwarder::getFace(FaceId id) const
260{
261 return m_faceTable.get(id);
262}
263
264inline void
265Forwarder::addFace(shared_ptr<Face> face)
266{
267 m_faceTable.add(face);
268}
269
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700270inline NameTree&
271Forwarder::getNameTree()
272{
273 return m_nameTree;
274}
275
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700276inline Fib&
277Forwarder::getFib()
278{
279 return m_fib;
280}
281
282inline Pit&
283Forwarder::getPit()
284{
285 return m_pit;
286}
287
288inline Cs&
289Forwarder::getCs()
290{
291 return m_cs;
292}
293
Junxiao Shidbe71732014-02-21 22:23:28 -0700294inline Measurements&
295Forwarder::getMeasurements()
296{
297 return m_measurements;
298}
299
Junxiao Shibb5105f2014-03-03 12:06:45 -0700300inline StrategyChoice&
301Forwarder::getStrategyChoice()
302{
303 return m_strategyChoice;
304}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700305
Junxiao Shia110f262014-10-12 12:35:20 -0700306inline DeadNonceList&
307Forwarder::getDeadNonceList()
308{
309 return m_deadNonceList;
310}
311
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700312inline NetworkRegionTable&
313Forwarder::getNetworkRegionTable()
314{
315 return m_networkRegionTable;
316}
317
Junxiao Shif3c07812014-03-11 21:48:49 -0700318#ifdef WITH_TESTS
319inline void
320Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
321#else
322template<class Function>
323inline void
324Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
325#endif
326{
327 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
328 trigger(&strategy);
329}
330
Junxiao Shid3c792f2014-01-30 00:46:13 -0700331} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800332
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700333#endif // NFD_DAEMON_FW_FORWARDER_HPP