blob: c8bd4026192b558f569d516d832540bce8fafee8 [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"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080039
Spyridon Mastorakis9d9c9ae2014-12-05 22:43:34 -080040#include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
41
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080042namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080043
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070044namespace fw {
45class Strategy;
46} // namespace fw
47
48/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070049 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070050 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080051 */
52class Forwarder
53{
54public:
Junxiao Shic041ca32014-02-25 20:01:15 -070055 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080056
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060057 VIRTUAL_WITH_TESTS
58 ~Forwarder();
59
Junxiao Shib289cc12014-03-15 12:19:05 -070060 const ForwarderCounters&
61 getCounters() const;
62
Junxiao Shia4f2be82014-03-02 22:56:41 -070063public: // faces
64 FaceTable&
65 getFaceTable();
66
67 /** \brief get existing Face
68 *
69 * shortcut to .getFaceTable().get(face)
70 */
71 shared_ptr<Face>
72 getFace(FaceId id) const;
73
74 /** \brief add new Face
75 *
76 * shortcut to .getFaceTable().add(face)
77 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070078 void
79 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080080
Junxiao Shia4f2be82014-03-02 22:56:41 -070081public: // forwarding entrypoints and tables
Alexander Afanasyev33b72772014-01-26 23:22:58 -080082 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070083 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080084
85 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070086 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070087
Junxiao Shiea48d8b2014-03-16 13:53:47 -070088 NameTree&
89 getNameTree();
90
Junxiao Shi8c8d2182014-01-30 22:33:00 -070091 Fib&
92 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070093
Junxiao Shi8c8d2182014-01-30 22:33:00 -070094 Pit&
95 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070096
Junxiao Shi8c8d2182014-01-30 22:33:00 -070097 Cs&
98 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070099
Junxiao Shidbe71732014-02-21 22:23:28 -0700100 Measurements&
101 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700102
Junxiao Shibb5105f2014-03-03 12:06:45 -0700103 StrategyChoice&
104 getStrategyChoice();
105
Junxiao Shia110f262014-10-12 12:35:20 -0700106 DeadNonceList&
107 getDeadNonceList();
108
Spyridon Mastorakis9d9c9ae2014-12-05 22:43:34 -0800109public: // allow enabling ndnSIM content store (will be removed in the future)
110 void
111 setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
112
Junxiao Shi88884492014-02-15 15:57:43 -0700113PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700114 /** \brief incoming Interest pipeline
115 */
Junxiao Shi88884492014-02-15 15:57:43 -0700116 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700117 onIncomingInterest(Face& inFace, const Interest& interest);
118
mzhang4eab72492015-02-25 11:16:09 -0600119 /** \brief Content Store miss pipeline
120 */
121 void
122 onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
123
124 /** \brief Content Store hit pipeline
125 */
126 void
127 onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
128 const Interest& interest, const Data& data);
129
Junxiao Shid3c792f2014-01-30 00:46:13 -0700130 /** \brief Interest loop pipeline
131 */
Junxiao Shi88884492014-02-15 15:57:43 -0700132 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700133 onInterestLoop(Face& inFace, const Interest& interest,
134 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700135
Junxiao Shid3c792f2014-01-30 00:46:13 -0700136 /** \brief outgoing Interest pipeline
137 */
Junxiao Shi88884492014-02-15 15:57:43 -0700138 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700139 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
140 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700141
Junxiao Shi09498f02014-02-26 19:41:08 -0700142 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700143 */
Junxiao Shi88884492014-02-15 15:57:43 -0700144 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700145 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700146
Junxiao Shid3c792f2014-01-30 00:46:13 -0700147 /** \brief Interest unsatisfied pipeline
148 */
Junxiao Shi88884492014-02-15 15:57:43 -0700149 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700150 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700151
Junxiao Shia110f262014-10-12 12:35:20 -0700152 /** \brief Interest finalize pipeline
153 * \param isSatisfied whether the Interest has been satisfied
154 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
155 */
156 VIRTUAL_WITH_TESTS void
157 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
158 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
159
Junxiao Shid3c792f2014-01-30 00:46:13 -0700160 /** \brief incoming Data pipeline
161 */
Junxiao Shi88884492014-02-15 15:57:43 -0700162 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700163 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700164
Junxiao Shid3c792f2014-01-30 00:46:13 -0700165 /** \brief Data unsolicited pipeline
166 */
Junxiao Shi88884492014-02-15 15:57:43 -0700167 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700168 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700169
Junxiao Shid3c792f2014-01-30 00:46:13 -0700170 /** \brief outgoing Data pipeline
171 */
Junxiao Shi88884492014-02-15 15:57:43 -0700172 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700173 onOutgoingData(const Data& data, Face& outFace);
174
Junxiao Shi88884492014-02-15 15:57:43 -0700175PROTECTED_WITH_TESTS_ELSE_PRIVATE:
176 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700177 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700178
Junxiao Shi88884492014-02-15 15:57:43 -0700179 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700180 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
181 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700182
Junxiao Shi88884492014-02-15 15:57:43 -0700183 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700184 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700185
Junxiao Shia110f262014-10-12 12:35:20 -0700186 /** \brief insert Nonce to Dead Nonce List if necessary
187 * \param upstream if null, insert Nonces from all OutRecords;
188 * if not null, insert Nonce only on the OutRecord of this face
189 */
190 VIRTUAL_WITH_TESTS void
191 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
192 const time::milliseconds& dataFreshnessPeriod,
193 Face* upstream);
194
Junxiao Shif3c07812014-03-11 21:48:49 -0700195 /// call trigger (method) on the effective strategy of pitEntry
196#ifdef WITH_TESTS
197 virtual void
198 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
199#else
200 template<class Function>
201 void
202 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
203#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700204
205private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700206 ForwarderCounters m_counters;
207
Junxiao Shia4f2be82014-03-02 22:56:41 -0700208 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800209
Junxiao Shibb5105f2014-03-03 12:06:45 -0700210 // tables
211 NameTree m_nameTree;
212 Fib m_fib;
213 Pit m_pit;
214 Cs m_cs;
215 Measurements m_measurements;
216 StrategyChoice m_strategyChoice;
Junxiao Shia110f262014-10-12 12:35:20 -0700217 DeadNonceList m_deadNonceList;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700218
Spyridon Mastorakis9d9c9ae2014-12-05 22:43:34 -0800219 ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
220
Junxiao Shif3c07812014-03-11 21:48:49 -0700221 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700222
Junxiao Shid3c792f2014-01-30 00:46:13 -0700223 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700224 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800225};
226
Junxiao Shib289cc12014-03-15 12:19:05 -0700227inline const ForwarderCounters&
228Forwarder::getCounters() const
229{
230 return m_counters;
231}
232
Junxiao Shia4f2be82014-03-02 22:56:41 -0700233inline FaceTable&
234Forwarder::getFaceTable()
235{
236 return m_faceTable;
237}
238
239inline shared_ptr<Face>
240Forwarder::getFace(FaceId id) const
241{
242 return m_faceTable.get(id);
243}
244
245inline void
246Forwarder::addFace(shared_ptr<Face> face)
247{
248 m_faceTable.add(face);
249}
250
251inline void
Junxiao Shia4f2be82014-03-02 22:56:41 -0700252Forwarder::onInterest(Face& face, const Interest& interest)
253{
254 this->onIncomingInterest(face, interest);
255}
256
257inline void
258Forwarder::onData(Face& face, const Data& data)
259{
260 this->onIncomingData(face, data);
261}
262
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700263inline NameTree&
264Forwarder::getNameTree()
265{
266 return m_nameTree;
267}
268
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700269inline Fib&
270Forwarder::getFib()
271{
272 return m_fib;
273}
274
275inline Pit&
276Forwarder::getPit()
277{
278 return m_pit;
279}
280
281inline Cs&
282Forwarder::getCs()
283{
284 return m_cs;
285}
286
Junxiao Shidbe71732014-02-21 22:23:28 -0700287inline Measurements&
288Forwarder::getMeasurements()
289{
290 return m_measurements;
291}
292
Junxiao Shibb5105f2014-03-03 12:06:45 -0700293inline StrategyChoice&
294Forwarder::getStrategyChoice()
295{
296 return m_strategyChoice;
297}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700298
Junxiao Shia110f262014-10-12 12:35:20 -0700299inline DeadNonceList&
300Forwarder::getDeadNonceList()
301{
302 return m_deadNonceList;
303}
304
Spyridon Mastorakis9d9c9ae2014-12-05 22:43:34 -0800305inline void
306Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
307{
308 m_csFromNdnSim = cs;
309}
310
Junxiao Shif3c07812014-03-11 21:48:49 -0700311#ifdef WITH_TESTS
312inline void
313Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
314#else
315template<class Function>
316inline void
317Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
318#endif
319{
320 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
321 trigger(&strategy);
322}
323
Junxiao Shid3c792f2014-01-30 00:46:13 -0700324} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800325
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700326#endif // NFD_DAEMON_FW_FORWARDER_HPP