blob: d2a5eb8b0c7cd8136211c76baf830186b5dbf980 [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
49/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070050 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070051 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080052 */
53class Forwarder
54{
55public:
Junxiao Shic041ca32014-02-25 20:01:15 -070056 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080057
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060058 VIRTUAL_WITH_TESTS
59 ~Forwarder();
60
Junxiao Shib289cc12014-03-15 12:19:05 -070061 const ForwarderCounters&
62 getCounters() const;
63
Junxiao Shia4f2be82014-03-02 22:56:41 -070064public: // faces
65 FaceTable&
66 getFaceTable();
67
68 /** \brief get existing Face
69 *
70 * shortcut to .getFaceTable().get(face)
71 */
72 shared_ptr<Face>
73 getFace(FaceId id) const;
74
75 /** \brief add new Face
76 *
77 * shortcut to .getFaceTable().add(face)
78 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070079 void
80 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080081
Junxiao Shia4f2be82014-03-02 22:56:41 -070082public: // forwarding entrypoints and tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -070083 /** \brief start incoming Interest processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050084 * \param face face on which Interest is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070085 * \param interest the incoming Interest, must be created with make_shared
86 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080087 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070088 startProcessInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080089
Junxiao Shi0355e9f2015-09-02 07:24:53 -070090 /** \brief start incoming Data processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050091 * \param face face on which Data is received
Junxiao Shi0355e9f2015-09-02 07:24:53 -070092 * \param data the incoming Data, must be created with make_shared
93 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080094 void
Junxiao Shi0355e9f2015-09-02 07:24:53 -070095 startProcessData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070096
Junxiao Shi5e5e4452015-09-24 16:56:52 -070097 /** \brief start incoming Nack processing
Alexander Afanasyevb755e9d2015-10-20 17:35:51 -050098 * \param face face on which Nack is received
Junxiao Shi5e5e4452015-09-24 16:56:52 -070099 * \param nack the incoming Nack, must be created with make_shared
100 */
101 void
102 startProcessNack(Face& face, const lp::Nack& nack);
103
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700104 NameTree&
105 getNameTree();
106
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700107 Fib&
108 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -0700109
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700110 Pit&
111 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -0700112
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700113 Cs&
114 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -0700115
Junxiao Shidbe71732014-02-21 22:23:28 -0700116 Measurements&
117 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700118
Junxiao Shibb5105f2014-03-03 12:06:45 -0700119 StrategyChoice&
120 getStrategyChoice();
121
Junxiao Shia110f262014-10-12 12:35:20 -0700122 DeadNonceList&
123 getDeadNonceList();
124
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700125 NetworkRegionTable&
126 getNetworkRegionTable();
127
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800128public: // allow enabling ndnSIM content store (will be removed in the future)
129 void
130 setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
131
Junxiao Shi88884492014-02-15 15:57:43 -0700132PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700133 /** \brief incoming Interest pipeline
134 */
Junxiao Shi88884492014-02-15 15:57:43 -0700135 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700136 onIncomingInterest(Face& inFace, const Interest& interest);
137
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700138 /** \brief Interest loop pipeline
139 */
140 VIRTUAL_WITH_TESTS void
Junxiao Shi330136a2016-03-10 04:53:08 -0700141 onInterestLoop(Face& inFace, const Interest& interest);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700142
mzhang4eab72492015-02-25 11:16:09 -0600143 /** \brief Content Store miss pipeline
144 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700145 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600146 onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
147
148 /** \brief Content Store hit pipeline
149 */
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700150 VIRTUAL_WITH_TESTS void
mzhang4eab72492015-02-25 11:16:09 -0600151 onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
152 const Interest& interest, const Data& data);
153
Junxiao Shid3c792f2014-01-30 00:46:13 -0700154 /** \brief outgoing Interest pipeline
155 */
Junxiao Shi88884492014-02-15 15:57:43 -0700156 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700157 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
158 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700159
Junxiao Shi09498f02014-02-26 19:41:08 -0700160 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700161 */
Junxiao Shi88884492014-02-15 15:57:43 -0700162 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700163 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700164
Junxiao Shid3c792f2014-01-30 00:46:13 -0700165 /** \brief Interest unsatisfied pipeline
166 */
Junxiao Shi88884492014-02-15 15:57:43 -0700167 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700168 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700169
Junxiao Shia110f262014-10-12 12:35:20 -0700170 /** \brief Interest finalize pipeline
171 * \param isSatisfied whether the Interest has been satisfied
172 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
173 */
174 VIRTUAL_WITH_TESTS void
175 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
176 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
177
Junxiao Shid3c792f2014-01-30 00:46:13 -0700178 /** \brief incoming Data pipeline
179 */
Junxiao Shi88884492014-02-15 15:57:43 -0700180 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700181 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700182
Junxiao Shid3c792f2014-01-30 00:46:13 -0700183 /** \brief Data unsolicited pipeline
184 */
Junxiao Shi88884492014-02-15 15:57:43 -0700185 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700186 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700187
Junxiao Shid3c792f2014-01-30 00:46:13 -0700188 /** \brief outgoing Data pipeline
189 */
Junxiao Shi88884492014-02-15 15:57:43 -0700190 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700191 onOutgoingData(const Data& data, Face& outFace);
192
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700193 /** \brief incoming Nack pipeline
194 */
195 VIRTUAL_WITH_TESTS void
196 onIncomingNack(Face& inFace, const lp::Nack& nack);
197
198 /** \brief outgoing Nack pipeline
199 */
200 VIRTUAL_WITH_TESTS void
201 onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
202
Junxiao Shi88884492014-02-15 15:57:43 -0700203PROTECTED_WITH_TESTS_ELSE_PRIVATE:
204 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700205 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700206
Junxiao Shi88884492014-02-15 15:57:43 -0700207 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700208 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
209 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700210
Junxiao Shi88884492014-02-15 15:57:43 -0700211 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700212 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700213
Junxiao Shia110f262014-10-12 12:35:20 -0700214 /** \brief insert Nonce to Dead Nonce List if necessary
215 * \param upstream if null, insert Nonces from all OutRecords;
216 * if not null, insert Nonce only on the OutRecord of this face
217 */
218 VIRTUAL_WITH_TESTS void
219 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
220 const time::milliseconds& dataFreshnessPeriod,
221 Face* upstream);
222
Junxiao Shif3c07812014-03-11 21:48:49 -0700223 /// call trigger (method) on the effective strategy of pitEntry
224#ifdef WITH_TESTS
225 virtual void
226 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
227#else
228 template<class Function>
229 void
230 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
231#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700232
233private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700234 ForwarderCounters m_counters;
235
Junxiao Shia4f2be82014-03-02 22:56:41 -0700236 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800237
Junxiao Shibb5105f2014-03-03 12:06:45 -0700238 // tables
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700239 NameTree m_nameTree;
240 Fib m_fib;
241 Pit m_pit;
242 Cs m_cs;
243 Measurements m_measurements;
244 StrategyChoice m_strategyChoice;
245 DeadNonceList m_deadNonceList;
246 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700247
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800248 ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
249
Junxiao Shif3c07812014-03-11 21:48:49 -0700250 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700251
Junxiao Shid3c792f2014-01-30 00:46:13 -0700252 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700253 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800254};
255
Junxiao Shib289cc12014-03-15 12:19:05 -0700256inline const ForwarderCounters&
257Forwarder::getCounters() const
258{
259 return m_counters;
260}
261
Junxiao Shia4f2be82014-03-02 22:56:41 -0700262inline FaceTable&
263Forwarder::getFaceTable()
264{
265 return m_faceTable;
266}
267
268inline shared_ptr<Face>
269Forwarder::getFace(FaceId id) const
270{
271 return m_faceTable.get(id);
272}
273
274inline void
275Forwarder::addFace(shared_ptr<Face> face)
276{
277 m_faceTable.add(face);
278}
279
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700280inline NameTree&
281Forwarder::getNameTree()
282{
283 return m_nameTree;
284}
285
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700286inline Fib&
287Forwarder::getFib()
288{
289 return m_fib;
290}
291
292inline Pit&
293Forwarder::getPit()
294{
295 return m_pit;
296}
297
298inline Cs&
299Forwarder::getCs()
300{
301 return m_cs;
302}
303
Junxiao Shidbe71732014-02-21 22:23:28 -0700304inline Measurements&
305Forwarder::getMeasurements()
306{
307 return m_measurements;
308}
309
Junxiao Shibb5105f2014-03-03 12:06:45 -0700310inline StrategyChoice&
311Forwarder::getStrategyChoice()
312{
313 return m_strategyChoice;
314}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700315
Junxiao Shia110f262014-10-12 12:35:20 -0700316inline DeadNonceList&
317Forwarder::getDeadNonceList()
318{
319 return m_deadNonceList;
320}
321
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700322inline NetworkRegionTable&
323Forwarder::getNetworkRegionTable()
324{
325 return m_networkRegionTable;
326}
327
Spyridon Mastorakis31d4a082014-12-05 22:43:34 -0800328inline void
329Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
330{
331 m_csFromNdnSim = cs;
332}
333
Junxiao Shif3c07812014-03-11 21:48:49 -0700334#ifdef WITH_TESTS
335inline void
336Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
337#else
338template<class Function>
339inline void
340Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
341#endif
342{
343 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
344 trigger(&strategy);
345}
346
Junxiao Shid3c792f2014-01-30 00:46:13 -0700347} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800348
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700349#endif // NFD_DAEMON_FW_FORWARDER_HPP