blob: 58792ed8220d6d0ed844e232c2ea1f50775b4308 [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/*
Eric Newberryf4056d02017-05-26 17:31:53 +00003 * Copyright (c) 2014-2017, 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
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
Spyridon Mastorakis01091f32014-12-05 22:43:34 -080042#include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
43
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080044namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080045
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070046namespace fw {
47class Strategy;
48} // namespace fw
49
50/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070051 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070052 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080053 */
54class Forwarder
55{
56public:
Junxiao Shic041ca32014-02-25 20:01:15 -070057 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080058
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060059 VIRTUAL_WITH_TESTS
60 ~Forwarder();
61
Junxiao Shib289cc12014-03-15 12:19:05 -070062 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000063 getCounters() const
64 {
65 return m_counters;
66 }
Junxiao Shib289cc12014-03-15 12:19:05 -070067
Junxiao Shifbe8efe2016-08-22 16:02:30 +000068public: // faces and policies
Junxiao Shia4f2be82014-03-02 22:56:41 -070069 FaceTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +000070 getFaceTable()
71 {
72 return m_faceTable;
73 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070074
75 /** \brief get existing Face
76 *
77 * shortcut to .getFaceTable().get(face)
78 */
Junxiao Shi5b43f9a2016-07-19 13:15:56 +000079 Face*
Junxiao Shib9420cf2016-08-13 04:38:52 +000080 getFace(FaceId id) const
81 {
82 return m_faceTable.get(id);
83 }
Junxiao Shia4f2be82014-03-02 22:56:41 -070084
85 /** \brief add new Face
86 *
87 * shortcut to .getFaceTable().add(face)
88 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070089 void
Junxiao Shib9420cf2016-08-13 04:38:52 +000090 addFace(shared_ptr<Face> face)
91 {
92 m_faceTable.add(face);
93 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -080094
Junxiao Shifbe8efe2016-08-22 16:02:30 +000095 fw::UnsolicitedDataPolicy&
96 getUnsolicitedDataPolicy() const
97 {
98 return *m_unsolicitedDataPolicy;
99 }
100
101 void
102 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
103 {
104 BOOST_ASSERT(policy != nullptr);
105 m_unsolicitedDataPolicy = std::move(policy);
106 }
107
Junxiao Shia4f2be82014-03-02 22:56:41 -0700108public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700109 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500110 * \param face face on which Interest is received
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000111 * \param interest the incoming Interest, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700112 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800113 void
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000114 startProcessInterest(Face& face, const Interest& interest)
115 {
116 this->onIncomingInterest(face, interest);
117 }
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800118
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700119 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500120 * \param face face on which Data is received
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000121 * \param data the incoming Data, must be well-formed and created with make_shared
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700122 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800123 void
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000124 startProcessData(Face& face, const Data& data)
125 {
126 this->onIncomingData(face, data);
127 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700128
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700129 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500130 * \param face face on which Nack is received
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000131 * \param nack the incoming Nack, must be well-formed
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700132 */
133 void
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000134 startProcessNack(Face& face, const lp::Nack& nack)
135 {
136 this->onIncomingNack(face, nack);
137 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700138
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700139 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000140 getNameTree()
141 {
142 return m_nameTree;
143 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700144
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700145 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000146 getFib()
147 {
148 return m_fib;
149 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700150
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700151 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000152 getPit()
153 {
154 return m_pit;
155 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700156
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700157 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000158 getCs()
159 {
160 return m_cs;
161 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700162
Junxiao Shidbe71732014-02-21 22:23:28 -0700163 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000164 getMeasurements()
165 {
166 return m_measurements;
167 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700168
Junxiao Shibb5105f2014-03-03 12:06:45 -0700169 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000170 getStrategyChoice()
171 {
172 return m_strategyChoice;
173 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700174
Junxiao Shia110f262014-10-12 12:35:20 -0700175 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000176 getDeadNonceList()
177 {
178 return m_deadNonceList;
179 }
Junxiao Shia110f262014-10-12 12:35:20 -0700180
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700181 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000182 getNetworkRegionTable()
183 {
184 return m_networkRegionTable;
185 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700186
Spyridon Mastorakis01091f32014-12-05 22:43:34 -0800187public: // allow enabling ndnSIM content store (will be removed in the future)
188 void
189 setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
190 {
191 m_csFromNdnSim = cs;
192 }
193
194public:
195 /** \brief trigger before PIT entry is satisfied
196 * \sa Strategy::beforeSatisfyInterest
197 */
198 signal::Signal<Forwarder, pit::Entry, Face, Data> beforeSatisfyInterest;
199
200 /** \brief trigger before PIT entry expires
201 * \sa Strategy::beforeExpirePendingInterest
202 */
203 signal::Signal<Forwarder, pit::Entry> beforeExpirePendingInterest;
204
Junxiao Shi88884492014-02-15 15:57:43 -0700205PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700206 /** \brief incoming Interest pipeline
207 */
Junxiao Shi88884492014-02-15 15:57:43 -0700208 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700209 onIncomingInterest(Face& inFace, const Interest& interest);
210
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700211 /** \brief Interest loop pipeline
212 */
213 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700214 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700215
mzhang4eab72492015-02-25 11:16:09 -0600216 /** \brief Content Store miss pipeline
217 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700218 VIRTUAL_WITH_TESTS void
Junxiao Shic5f651f2016-11-17 22:58:12 +0000219 onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
mzhang4eab72492015-02-25 11:16:09 -0600220
221 /** \brief Content Store hit pipeline
222 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700223 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000224 onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
mzhang4eab72492015-02-25 11:16:09 -0600225 const Interest& interest, const Data& data);
226
Junxiao Shid3c792f2014-01-30 00:46:13 -0700227 /** \brief outgoing Interest pipeline
228 */
Junxiao Shi88884492014-02-15 15:57:43 -0700229 VIRTUAL_WITH_TESTS void
Junxiao Shic5f651f2016-11-17 22:58:12 +0000230 onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest);
Junxiao Shic041ca32014-02-25 20:01:15 -0700231
Junxiao Shi09498f02014-02-26 19:41:08 -0700232 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700233 */
Junxiao Shi88884492014-02-15 15:57:43 -0700234 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000235 onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700236
Junxiao Shid3c792f2014-01-30 00:46:13 -0700237 /** \brief Interest unsatisfied pipeline
238 */
Junxiao Shi88884492014-02-15 15:57:43 -0700239 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000240 onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700241
Junxiao Shia110f262014-10-12 12:35:20 -0700242 /** \brief Interest finalize pipeline
243 * \param isSatisfied whether the Interest has been satisfied
244 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
245 */
246 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000247 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
Eric Newberryf4056d02017-05-26 17:31:53 +0000248 ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
Junxiao Shia110f262014-10-12 12:35:20 -0700249
Junxiao Shid3c792f2014-01-30 00:46:13 -0700250 /** \brief incoming Data pipeline
251 */
Junxiao Shi88884492014-02-15 15:57:43 -0700252 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700253 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700254
Junxiao Shid3c792f2014-01-30 00:46:13 -0700255 /** \brief Data unsolicited pipeline
256 */
Junxiao Shi88884492014-02-15 15:57:43 -0700257 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700258 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700259
Junxiao Shid3c792f2014-01-30 00:46:13 -0700260 /** \brief outgoing Data pipeline
261 */
Junxiao Shi88884492014-02-15 15:57:43 -0700262 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700263 onOutgoingData(const Data& data, Face& outFace);
264
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700265 /** \brief incoming Nack pipeline
266 */
267 VIRTUAL_WITH_TESTS void
268 onIncomingNack(Face& inFace, const lp::Nack& nack);
269
270 /** \brief outgoing Nack pipeline
271 */
272 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000273 onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700274
Junxiao Shi88884492014-02-15 15:57:43 -0700275PROTECTED_WITH_TESTS_ELSE_PRIVATE:
276 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000277 setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700278
Junxiao Shi88884492014-02-15 15:57:43 -0700279 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000280 setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
Eric Newberryf4056d02017-05-26 17:31:53 +0000281 ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
Junxiao Shic041ca32014-02-25 20:01:15 -0700282
Junxiao Shi88884492014-02-15 15:57:43 -0700283 VIRTUAL_WITH_TESTS void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000284 cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700285
Junxiao Shia110f262014-10-12 12:35:20 -0700286 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700287 * \param upstream if null, insert Nonces from all out-records;
288 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700289 */
290 VIRTUAL_WITH_TESTS void
291 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
Eric Newberryf4056d02017-05-26 17:31:53 +0000292 ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700293
Junxiao Shib9420cf2016-08-13 04:38:52 +0000294 /** \brief call trigger (method) on the effective strategy of pitEntry
295 */
Junxiao Shif3c07812014-03-11 21:48:49 -0700296#ifdef WITH_TESTS
297 virtual void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000298 dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700299#else
300 template<class Function>
301 void
Junxiao Shib9420cf2016-08-13 04:38:52 +0000302 dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
Junxiao Shif3c07812014-03-11 21:48:49 -0700303#endif
Junxiao Shib9420cf2016-08-13 04:38:52 +0000304 {
305 trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
306 }
Junxiao Shid3c792f2014-01-30 00:46:13 -0700307
308private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700309 ForwarderCounters m_counters;
310
Junxiao Shia4f2be82014-03-02 22:56:41 -0700311 FaceTable m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000312 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800313
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700314 NameTree m_nameTree;
315 Fib m_fib;
316 Pit m_pit;
317 Cs m_cs;
318 Measurements m_measurements;
319 StrategyChoice m_strategyChoice;
320 DeadNonceList m_deadNonceList;
321 NetworkRegionTable m_networkRegionTable;
Spyridon Mastorakis01091f32014-12-05 22:43:34 -0800322 shared_ptr<Face> m_csFace;
323
324 ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700325
Junxiao Shid3c792f2014-01-30 00:46:13 -0700326 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700327 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800328};
329
Junxiao Shid3c792f2014-01-30 00:46:13 -0700330} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800331
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700332#endif // NFD_DAEMON_FW_FORWARDER_HPP