blob: 627148eb4413dee10d60e37a97f537382138acd4 [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 Mastorakisde1f7732014-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 Mastorakisde1f7732014-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
119 /** \brief Interest loop pipeline
120 */
Junxiao Shi88884492014-02-15 15:57:43 -0700121 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700122 onInterestLoop(Face& inFace, const Interest& interest,
123 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700124
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125 /** \brief outgoing Interest pipeline
126 */
Junxiao Shi88884492014-02-15 15:57:43 -0700127 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700128 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
129 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700130
Junxiao Shi09498f02014-02-26 19:41:08 -0700131 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132 */
Junxiao Shi88884492014-02-15 15:57:43 -0700133 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700134 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700135
Junxiao Shid3c792f2014-01-30 00:46:13 -0700136 /** \brief Interest unsatisfied pipeline
137 */
Junxiao Shi88884492014-02-15 15:57:43 -0700138 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700139 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700140
Junxiao Shia110f262014-10-12 12:35:20 -0700141 /** \brief Interest finalize pipeline
142 * \param isSatisfied whether the Interest has been satisfied
143 * \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
144 */
145 VIRTUAL_WITH_TESTS void
146 onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
147 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
148
Junxiao Shid3c792f2014-01-30 00:46:13 -0700149 /** \brief incoming Data pipeline
150 */
Junxiao Shi88884492014-02-15 15:57:43 -0700151 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700152 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700153
Junxiao Shid3c792f2014-01-30 00:46:13 -0700154 /** \brief Data unsolicited pipeline
155 */
Junxiao Shi88884492014-02-15 15:57:43 -0700156 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700157 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700158
Junxiao Shid3c792f2014-01-30 00:46:13 -0700159 /** \brief outgoing Data pipeline
160 */
Junxiao Shi88884492014-02-15 15:57:43 -0700161 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700162 onOutgoingData(const Data& data, Face& outFace);
163
Junxiao Shi88884492014-02-15 15:57:43 -0700164PROTECTED_WITH_TESTS_ELSE_PRIVATE:
165 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700166 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700167
Junxiao Shi88884492014-02-15 15:57:43 -0700168 VIRTUAL_WITH_TESTS void
Junxiao Shia110f262014-10-12 12:35:20 -0700169 setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
170 const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
Junxiao Shic041ca32014-02-25 20:01:15 -0700171
Junxiao Shi88884492014-02-15 15:57:43 -0700172 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700173 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700174
Junxiao Shia110f262014-10-12 12:35:20 -0700175 /** \brief insert Nonce to Dead Nonce List if necessary
176 * \param upstream if null, insert Nonces from all OutRecords;
177 * if not null, insert Nonce only on the OutRecord of this face
178 */
179 VIRTUAL_WITH_TESTS void
180 insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
181 const time::milliseconds& dataFreshnessPeriod,
182 Face* upstream);
183
Junxiao Shif3c07812014-03-11 21:48:49 -0700184 /// call trigger (method) on the effective strategy of pitEntry
185#ifdef WITH_TESTS
186 virtual void
187 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
188#else
189 template<class Function>
190 void
191 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
192#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700193
194private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700195 ForwarderCounters m_counters;
196
Junxiao Shia4f2be82014-03-02 22:56:41 -0700197 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800198
Junxiao Shibb5105f2014-03-03 12:06:45 -0700199 // tables
200 NameTree m_nameTree;
201 Fib m_fib;
202 Pit m_pit;
203 Cs m_cs;
204 Measurements m_measurements;
205 StrategyChoice m_strategyChoice;
Junxiao Shia110f262014-10-12 12:35:20 -0700206 DeadNonceList m_deadNonceList;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700207
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800208 ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
209
Junxiao Shif3c07812014-03-11 21:48:49 -0700210 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700211
Junxiao Shid3c792f2014-01-30 00:46:13 -0700212 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700213 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800214};
215
Junxiao Shib289cc12014-03-15 12:19:05 -0700216inline const ForwarderCounters&
217Forwarder::getCounters() const
218{
219 return m_counters;
220}
221
Junxiao Shia4f2be82014-03-02 22:56:41 -0700222inline FaceTable&
223Forwarder::getFaceTable()
224{
225 return m_faceTable;
226}
227
228inline shared_ptr<Face>
229Forwarder::getFace(FaceId id) const
230{
231 return m_faceTable.get(id);
232}
233
234inline void
235Forwarder::addFace(shared_ptr<Face> face)
236{
237 m_faceTable.add(face);
238}
239
240inline void
Junxiao Shia4f2be82014-03-02 22:56:41 -0700241Forwarder::onInterest(Face& face, const Interest& interest)
242{
243 this->onIncomingInterest(face, interest);
244}
245
246inline void
247Forwarder::onData(Face& face, const Data& data)
248{
249 this->onIncomingData(face, data);
250}
251
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700252inline NameTree&
253Forwarder::getNameTree()
254{
255 return m_nameTree;
256}
257
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700258inline Fib&
259Forwarder::getFib()
260{
261 return m_fib;
262}
263
264inline Pit&
265Forwarder::getPit()
266{
267 return m_pit;
268}
269
270inline Cs&
271Forwarder::getCs()
272{
273 return m_cs;
274}
275
Junxiao Shidbe71732014-02-21 22:23:28 -0700276inline Measurements&
277Forwarder::getMeasurements()
278{
279 return m_measurements;
280}
281
Junxiao Shibb5105f2014-03-03 12:06:45 -0700282inline StrategyChoice&
283Forwarder::getStrategyChoice()
284{
285 return m_strategyChoice;
286}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700287
Junxiao Shia110f262014-10-12 12:35:20 -0700288inline DeadNonceList&
289Forwarder::getDeadNonceList()
290{
291 return m_deadNonceList;
292}
293
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800294inline void
295Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
296{
297 m_csFromNdnSim = cs;
298}
299
Junxiao Shif3c07812014-03-11 21:48:49 -0700300#ifdef WITH_TESTS
301inline void
302Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
303#else
304template<class Function>
305inline void
306Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
307#endif
308{
309 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
310 trigger(&strategy);
311}
312
Junxiao Shid3c792f2014-01-30 00:46:13 -0700313} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800314
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700315#endif // NFD_DAEMON_FW_FORWARDER_HPP