blob: 48614f657c66dea2439d8dfd07cc701672a29af0 [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
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
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -080041#include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
42
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080043namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080044
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070045namespace fw {
46class Strategy;
47} // namespace fw
48
Alexander Afanasyevd980dcd2015-01-08 21:41:48 -080049class NullFace;
50
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070051/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070052 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070053 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080054 */
55class Forwarder
56{
57public:
Junxiao Shic041ca32014-02-25 20:01:15 -070058 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080059
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060060 VIRTUAL_WITH_TESTS
61 ~Forwarder();
62
Junxiao Shib289cc12014-03-15 12:19:05 -070063 const ForwarderCounters&
64 getCounters() const;
65
Junxiao Shia4f2be82014-03-02 22:56:41 -070066public: // faces
67 FaceTable&
68 getFaceTable();
69
70 /** \brief get existing Face
71 *
72 * shortcut to .getFaceTable().get(face)
73 */
74 shared_ptr<Face>
75 getFace(FaceId id) const;
76
77 /** \brief add new Face
78 *
79 * shortcut to .getFaceTable().add(face)
80 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070081 void
82 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080083
Junxiao Shia4f2be82014-03-02 22:56:41 -070084public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -070085 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050086 * \param face face on which Interest is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070087 * \param interest the incoming Interest, must be created with make_shared
88 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080089 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070090 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080091
Junxiao Shi0355e9f2015-09-02 07:24:53 -070092 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050093 * \param face face on which Data is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070094 * \param data the incoming Data, must be created with make_shared
95 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080096 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070097 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070098
Junxiao Shi5e5e4452015-09-24 16:56:52 -070099 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -0500100 * \param face face on which Nack is received
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700101 * \param nack the incoming Nack, must be created with make_shared
102 */
103 void
104 startProcessNack(Face& face, const lp::Nack& nack);
105
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700106 NameTree&
107 getNameTree();
108
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700109 Fib&
110 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -0700111
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700112 Pit&
113 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -0700114
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700115 Cs&
116 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -0700117
Junxiao Shidbe71732014-02-21 22:23:28 -0700118 Measurements&
119 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120
Junxiao Shibb5105f2014-03-03 12:06:45 -0700121 StrategyChoice&
122 getStrategyChoice();
123
Junxiao Shia110f262014-10-12 12:35:20 -0700124 DeadNonceList&
125 getDeadNonceList();
126
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700127 NetworkRegionTable&
128 getNetworkRegionTable();
129
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800130public: // allow enabling ndnSIM content store (will be removed in the future)
131 void
132 setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
133
Alexander Afanasyevd980dcd2015-01-08 21:41:48 -0800134public:
135 /** \brief trigger before PIT entry is satisfied
136 * \sa Strategy::beforeSatisfyInterest
137 */
138 signal::Signal<Forwarder, pit::Entry, Face, Data> beforeSatisfyInterest;
139
140 /** \brief trigger before PIT entry expires
141 * \sa Strategy::beforeExpirePendingInterest
142 */
143 signal::Signal<Forwarder, pit::Entry> beforeExpirePendingInterest;
144
Junxiao Shi88884492014-02-15 15:57:43 -0700145PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700146 /** \brief incoming Interest pipeline
147 */
Junxiao Shi88884492014-02-15 15:57:43 -0700148 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700149 onIncomingInterest(Face& inFace, const Interest& interest);
150
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700151 /** \brief Interest loop pipeline
152 */
153 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700154 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700155
mzhang4eab72492015-02-25 11:16:09 -0600156 /** \brief Content Store miss pipeline
157 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700158 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600159 onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
160
161 /** \brief Content Store hit pipeline
162 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700163 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600164 onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
165 const Interest& interest, const Data& data);
166
Junxiao Shid3c792f2014-01-30 00:46:13 -0700167 /** \brief outgoing Interest pipeline
168 */
Junxiao Shi88884492014-02-15 15:57:43 -0700169 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700170 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
171 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700172
Junxiao Shi09498f02014-02-26 19:41:08 -0700173 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700174 */
Junxiao Shi88884492014-02-15 15:57:43 -0700175 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700176 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700177
Junxiao Shid3c792f2014-01-30 00:46:13 -0700178 /** \brief Interest unsatisfied pipeline
179 */
Junxiao Shi88884492014-02-15 15:57:43 -0700180 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700181 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700182
Junxiao Shia110f262014-10-12 12:35:20 -0700183 /** \brief Interest finalize pipeline
184 * \param isSatisfied whether the Interest has been satisfied
185 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
186 */
187 VIRTUAL_WITH_TESTS void
188 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
189 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
190
Junxiao Shid3c792f2014-01-30 00:46:13 -0700191 /** \brief incoming Data pipeline
192 */
Junxiao Shi88884492014-02-15 15:57:43 -0700193 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700194 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700195
Junxiao Shid3c792f2014-01-30 00:46:13 -0700196 /** \brief Data unsolicited pipeline
197 */
Junxiao Shi88884492014-02-15 15:57:43 -0700198 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700199 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700200
Junxiao Shid3c792f2014-01-30 00:46:13 -0700201 /** \brief outgoing Data pipeline
202 */
Junxiao Shi88884492014-02-15 15:57:43 -0700203 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700204 onOutgoingData(const Data& data, Face& outFace);
205
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700206 /** \brief incoming Nack pipeline
207 */
208 VIRTUAL_WITH_TESTS void
209 onIncomingNack(Face& inFace, const lp::Nack& nack);
210
211 /** \brief outgoing Nack pipeline
212 */
213 VIRTUAL_WITH_TESTS void
214 onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
215
Junxiao Shi88884492014-02-15 15:57:43 -0700216PROTECTED_WITH_TESTS_ELSE_PRIVATE:
217 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700218 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700219
Junxiao Shi88884492014-02-15 15:57:43 -0700220 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700221 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
222 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700223
Junxiao Shi88884492014-02-15 15:57:43 -0700224 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700225 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700226
Junxiao Shia110f262014-10-12 12:35:20 -0700227 /** \brief insert Nonce to Dead Nonce List if necessary
228 * \param upstream if null, insert Nonces from all OutRecords;
229 * if not null, insert Nonce only on the OutRecord of this face
230 */
231 VIRTUAL_WITH_TESTS void
232 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
233 const time::milliseconds& dataFreshnessPeriod,
234 Face* upstream);
235
Junxiao Shif3c07812014-03-11 21:48:49 -0700236 /// call trigger (method) on the effective strategy of pitEntry
237#ifdef WITH_TESTS
238 virtual void
239 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
240#else
241 template<class Function>
242 void
243 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
244#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700245
246private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700247 ForwarderCounters m_counters;
248
Junxiao Shia4f2be82014-03-02 22:56:41 -0700249 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800250
Junxiao Shibb5105f2014-03-03 12:06:45 -0700251 // tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700252 NameTree m_nameTree;
253 Fib m_fib;
254 Pit m_pit;
255 Cs m_cs;
256 Measurements m_measurements;
257 StrategyChoice m_strategyChoice;
258 DeadNonceList m_deadNonceList;
259 NetworkRegionTable m_networkRegionTable;
Alexander Afanasyevd980dcd2015-01-08 21:41:48 -0800260 shared_ptr<Face> m_csFace;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700261
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800262 ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
263
Junxiao Shif3c07812014-03-11 21:48:49 -0700264 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700265
Junxiao Shid3c792f2014-01-30 00:46:13 -0700266 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700267 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800268};
269
Junxiao Shib289cc12014-03-15 12:19:05 -0700270inline const ForwarderCounters&
271Forwarder::getCounters() const
272{
273 return m_counters;
274}
275
Junxiao Shia4f2be82014-03-02 22:56:41 -0700276inline FaceTable&
277Forwarder::getFaceTable()
278{
279 return m_faceTable;
280}
281
282inline shared_ptr<Face>
283Forwarder::getFace(FaceId id) const
284{
285 return m_faceTable.get(id);
286}
287
288inline void
289Forwarder::addFace(shared_ptr<Face> face)
290{
291 m_faceTable.add(face);
292}
293
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700294inline NameTree&
295Forwarder::getNameTree()
296{
297 return m_nameTree;
298}
299
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700300inline Fib&
301Forwarder::getFib()
302{
303 return m_fib;
304}
305
306inline Pit&
307Forwarder::getPit()
308{
309 return m_pit;
310}
311
312inline Cs&
313Forwarder::getCs()
314{
315 return m_cs;
316}
317
Junxiao Shidbe71732014-02-21 22:23:28 -0700318inline Measurements&
319Forwarder::getMeasurements()
320{
321 return m_measurements;
322}
323
Junxiao Shibb5105f2014-03-03 12:06:45 -0700324inline StrategyChoice&
325Forwarder::getStrategyChoice()
326{
327 return m_strategyChoice;
328}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700329
Junxiao Shia110f262014-10-12 12:35:20 -0700330inline DeadNonceList&
331Forwarder::getDeadNonceList()
332{
333 return m_deadNonceList;
334}
335
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700336inline NetworkRegionTable&
337Forwarder::getNetworkRegionTable()
338{
339 return m_networkRegionTable;
340}
341
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800342inline void
343Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
344{
345 m_csFromNdnSim = cs;
346}
347
Junxiao Shif3c07812014-03-11 21:48:49 -0700348#ifdef WITH_TESTS
349inline void
350Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
351#else
352template<class Function>
353inline void
354Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
355#endif
356{
357 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
358 trigger(&strategy);
359}
360
Junxiao Shid3c792f2014-01-30 00:46:13 -0700361} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800362
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700363#endif // NFD_DAEMON_FW_FORWARDER_HPP