blob: 855c24e86f033321e4ffa696a24806a43ced23ed [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&
Junxiao Shib9420cf2016-08-13 04:38:52 +000060 getCounters() const
61 {
62 return m_counters;
63 }
Junxiao Shib289cc12014-03-15 12:19:05 -070064
Junxiao Shia4f2be82014-03-02 22:56:41 -070065public: // faces
66 FaceTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +000067 getFaceTable()
68 {
69 return m_faceTable;
70 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070071
72 /** \brief get existing Face
73 *
74 * shortcut to .getFaceTable().get(face)
75 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000076 Face*
Junxiao Shib9420cf2016-08-13 04:38:52 +000077 getFace(FaceId id) const
78 {
79 return m_faceTable.get(id);
80 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070081
82 /** \brief add new Face
83 *
84 * shortcut to .getFaceTable().add(face)
85 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070086 void
Junxiao Shib9420cf2016-08-13 04:38:52 +000087 addFace(shared_ptr<Face> face)
88 {
89 m_faceTable.add(face);
90 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080091
Junxiao Shia4f2be82014-03-02 22:56:41 -070092public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -070093 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050094 * \param face face on which Interest is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070095 * \param interest the incoming Interest, must be created with make_shared
96 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080097 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070098 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080099
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700100 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500101 * \param face face on which Data is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700102 * \param data the incoming Data, must be created with make_shared
103 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800104 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700105 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700106
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700107 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500108 * \param face face on which Nack is received
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700109 * \param nack the incoming Nack, must be created with make_shared
110 */
111 void
112 startProcessNack(Face& face, const lp::Nack& nack);
113
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700114 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000115 getNameTree()
116 {
117 return m_nameTree;
118 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700119
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000121 getFib()
122 {
123 return m_fib;
124 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700125
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700126 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000127 getPit()
128 {
129 return m_pit;
130 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700131
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700132 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000133 getCs()
134 {
135 return m_cs;
136 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700137
Junxiao Shidbe71732014-02-21 22:23:28 -0700138 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000139 getMeasurements()
140 {
141 return m_measurements;
142 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700143
Junxiao Shibb5105f2014-03-03 12:06:45 -0700144 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000145 getStrategyChoice()
146 {
147 return m_strategyChoice;
148 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700149
Junxiao Shia110f262014-10-12 12:35:20 -0700150 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000151 getDeadNonceList()
152 {
153 return m_deadNonceList;
154 }
Junxiao Shia110f262014-10-12 12:35:20 -0700155
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700156 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000157 getNetworkRegionTable()
158 {
159 return m_networkRegionTable;
160 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700161
Junxiao Shi05cc50a2016-07-11 22:38:21 +0000162 /** \brief performs a FIB lookup, considering Link object if present
163 */
164 const fib::Entry&
165 lookupFib(const pit::Entry& pitEntry) const;
166
Junxiao Shi88884492014-02-15 15:57:43 -0700167PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700168 /** \brief incoming Interest pipeline
169 */
Junxiao Shi88884492014-02-15 15:57:43 -0700170 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700171 onIncomingInterest(Face& inFace, const Interest& interest);
172
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700173 /** \brief Interest loop pipeline
174 */
175 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700176 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700177
mzhang4eab72492015-02-25 11:16:09 -0600178 /** \brief Content Store miss pipeline
179 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700180 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000181 onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
182 const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600183
184 /** \brief Content Store hit pipeline
185 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700186 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000187 onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600188 const Interest& interest, const Data& data);
189
Junxiao Shid3c792f2014-01-30 00:46:13 -0700190 /** \brief outgoing Interest pipeline
191 */
Junxiao Shi88884492014-02-15 15:57:43 -0700192 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000193 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
Junxiao Shid938a6b2014-05-11 23:40:29 -0700194 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700195
Junxiao Shi09498f02014-02-26 19:41:08 -0700196 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700197 */
Junxiao Shi88884492014-02-15 15:57:43 -0700198 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000199 onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700200
Junxiao Shid3c792f2014-01-30 00:46:13 -0700201 /** \brief Interest unsatisfied pipeline
202 */
Junxiao Shi88884492014-02-15 15:57:43 -0700203 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000204 onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700205
Junxiao Shia110f262014-10-12 12:35:20 -0700206 /** \brief Interest finalize pipeline
207 * \param isSatisfied whether the Interest has been satisfied
208 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
209 */
210 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000211 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
212 time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shia110f262014-10-12 12:35:20 -0700213
Junxiao Shid3c792f2014-01-30 00:46:13 -0700214 /** \brief incoming Data pipeline
215 */
Junxiao Shi88884492014-02-15 15:57:43 -0700216 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700217 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700218
Junxiao Shid3c792f2014-01-30 00:46:13 -0700219 /** \brief Data unsolicited pipeline
220 */
Junxiao Shi88884492014-02-15 15:57:43 -0700221 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700222 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700223
Junxiao Shid3c792f2014-01-30 00:46:13 -0700224 /** \brief outgoing Data pipeline
225 */
Junxiao Shi88884492014-02-15 15:57:43 -0700226 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700227 onOutgoingData(const Data& data, Face& outFace);
228
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700229 /** \brief incoming Nack pipeline
230 */
231 VIRTUAL_WITH_TESTS void
232 onIncomingNack(Face& inFace, const lp::Nack& nack);
233
234 /** \brief outgoing Nack pipeline
235 */
236 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000237 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700238
Junxiao Shi88884492014-02-15 15:57:43 -0700239PROTECTED_WITH_TESTS_ELSE_PRIVATE:
240 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000241 setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700242
Junxiao Shi88884492014-02-15 15:57:43 -0700243 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000244 setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
245 time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700246
Junxiao Shi88884492014-02-15 15:57:43 -0700247 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000248 cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700249
Junxiao Shia110f262014-10-12 12:35:20 -0700250 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700251 * \param upstream if null, insert Nonces from all out-records;
252 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700253 */
254 VIRTUAL_WITH_TESTS void
255 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
Junxiao Shib9420cf2016-08-13 04:38:52 +0000256 time::milliseconds dataFreshnessPeriod, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700257
Junxiao Shib9420cf2016-08-13 04:38:52 +0000258 /** \brief call trigger (method) on the effective strategy of pitEntry
259 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700260#ifdef WITH_TESTS
261 virtual void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000262 dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700263#else
264 template<class Function>
265 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000266 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700267#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000268 {
269 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
270 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700271
272private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700273 ForwarderCounters m_counters;
274
Junxiao Shia4f2be82014-03-02 22:56:41 -0700275 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800276
Junxiao Shibb5105f2014-03-03 12:06:45 -0700277 // tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700278 NameTree m_nameTree;
279 Fib m_fib;
280 Pit m_pit;
281 Cs m_cs;
282 Measurements m_measurements;
283 StrategyChoice m_strategyChoice;
284 DeadNonceList m_deadNonceList;
285 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700286
Junxiao Shid3c792f2014-01-30 00:46:13 -0700287 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700288 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800289};
290
Junxiao Shid3c792f2014-01-30 00:46:13 -0700291} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800292
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700293#endif // NFD_DAEMON_FW_FORWARDER_HPP