blob: 8c5ed79689279c468fe4a7e6fd084224c795d38b [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Alexander Afanasyev33b72772014-01-26 23:22:58 -080024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_FW_FORWARDER_HPP
26#define NFD_DAEMON_FW_FORWARDER_HPP
Alexander Afanasyev33b72772014-01-26 23:22:58 -080027
28#include "common.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070029#include "core/scheduler.hpp"
Junxiao Shi33152f12014-07-16 19:54:32 -070030#include "forwarder-counters.hpp"
Junxiao Shia4f2be82014-03-02 22:56:41 -070031#include "face-table.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070032#include "table/fib.hpp"
33#include "table/pit.hpp"
34#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070035#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070036#include "table/strategy-choice.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080037
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080038namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080039
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070040namespace fw {
41class Strategy;
42} // namespace fw
43
44/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070045 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070046 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080047 */
48class Forwarder
49{
50public:
Junxiao Shic041ca32014-02-25 20:01:15 -070051 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080052
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060053 VIRTUAL_WITH_TESTS
54 ~Forwarder();
55
Junxiao Shib289cc12014-03-15 12:19:05 -070056 const ForwarderCounters&
57 getCounters() const;
58
Junxiao Shia4f2be82014-03-02 22:56:41 -070059public: // faces
60 FaceTable&
61 getFaceTable();
62
63 /** \brief get existing Face
64 *
65 * shortcut to .getFaceTable().get(face)
66 */
67 shared_ptr<Face>
68 getFace(FaceId id) const;
69
70 /** \brief add new Face
71 *
72 * shortcut to .getFaceTable().add(face)
73 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070074 void
75 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080076
Junxiao Shia4f2be82014-03-02 22:56:41 -070077public: // forwarding entrypoints and tables
Alexander Afanasyev33b72772014-01-26 23:22:58 -080078 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070079 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080080
81 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070082 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070083
Junxiao Shiea48d8b2014-03-16 13:53:47 -070084 NameTree&
85 getNameTree();
86
Junxiao Shi8c8d2182014-01-30 22:33:00 -070087 Fib&
88 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070089
Junxiao Shi8c8d2182014-01-30 22:33:00 -070090 Pit&
91 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070092
Junxiao Shi8c8d2182014-01-30 22:33:00 -070093 Cs&
94 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070095
Junxiao Shidbe71732014-02-21 22:23:28 -070096 Measurements&
97 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070098
Junxiao Shibb5105f2014-03-03 12:06:45 -070099 StrategyChoice&
100 getStrategyChoice();
101
Junxiao Shi88884492014-02-15 15:57:43 -0700102PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 /** \brief incoming Interest pipeline
104 */
Junxiao Shi88884492014-02-15 15:57:43 -0700105 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700106 onIncomingInterest(Face& inFace, const Interest& interest);
107
108 /** \brief Interest loop pipeline
109 */
Junxiao Shi88884492014-02-15 15:57:43 -0700110 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700111 onInterestLoop(Face& inFace, const Interest& interest,
112 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700113
Junxiao Shid3c792f2014-01-30 00:46:13 -0700114 /** \brief outgoing Interest pipeline
115 */
Junxiao Shi88884492014-02-15 15:57:43 -0700116 VIRTUAL_WITH_TESTS void
Junxiao Shid938a6b2014-05-11 23:40:29 -0700117 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
118 bool wantNewNonce = false);
Junxiao Shic041ca32014-02-25 20:01:15 -0700119
Junxiao Shi09498f02014-02-26 19:41:08 -0700120 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700121 */
Junxiao Shi88884492014-02-15 15:57:43 -0700122 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700123 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700124
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125 /** \brief Interest unsatisfied pipeline
126 */
Junxiao Shi88884492014-02-15 15:57:43 -0700127 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700128 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700129
Junxiao Shid3c792f2014-01-30 00:46:13 -0700130 /** \brief incoming Data pipeline
131 */
Junxiao Shi88884492014-02-15 15:57:43 -0700132 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700133 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700134
Junxiao Shid3c792f2014-01-30 00:46:13 -0700135 /** \brief Data unsolicited pipeline
136 */
Junxiao Shi88884492014-02-15 15:57:43 -0700137 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700138 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700139
Junxiao Shid3c792f2014-01-30 00:46:13 -0700140 /** \brief outgoing Data pipeline
141 */
Junxiao Shi88884492014-02-15 15:57:43 -0700142 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700143 onOutgoingData(const Data& data, Face& outFace);
144
Junxiao Shi88884492014-02-15 15:57:43 -0700145PROTECTED_WITH_TESTS_ELSE_PRIVATE:
146 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700147 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700148
Junxiao Shi88884492014-02-15 15:57:43 -0700149 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700150 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700151
Junxiao Shi88884492014-02-15 15:57:43 -0700152 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700154
Junxiao Shif3c07812014-03-11 21:48:49 -0700155 /// call trigger (method) on the effective strategy of pitEntry
156#ifdef WITH_TESTS
157 virtual void
158 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
159#else
160 template<class Function>
161 void
162 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
163#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700164
165private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700166 ForwarderCounters m_counters;
167
Junxiao Shia4f2be82014-03-02 22:56:41 -0700168 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800169
Junxiao Shibb5105f2014-03-03 12:06:45 -0700170 // tables
171 NameTree m_nameTree;
172 Fib m_fib;
173 Pit m_pit;
174 Cs m_cs;
175 Measurements m_measurements;
176 StrategyChoice m_strategyChoice;
177
Junxiao Shif3c07812014-03-11 21:48:49 -0700178 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700179
Junxiao Shid3c792f2014-01-30 00:46:13 -0700180 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700181 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800182};
183
Junxiao Shib289cc12014-03-15 12:19:05 -0700184inline const ForwarderCounters&
185Forwarder::getCounters() const
186{
187 return m_counters;
188}
189
Junxiao Shia4f2be82014-03-02 22:56:41 -0700190inline FaceTable&
191Forwarder::getFaceTable()
192{
193 return m_faceTable;
194}
195
196inline shared_ptr<Face>
197Forwarder::getFace(FaceId id) const
198{
199 return m_faceTable.get(id);
200}
201
202inline void
203Forwarder::addFace(shared_ptr<Face> face)
204{
205 m_faceTable.add(face);
206}
207
208inline void
Junxiao Shia4f2be82014-03-02 22:56:41 -0700209Forwarder::onInterest(Face& face, const Interest& interest)
210{
211 this->onIncomingInterest(face, interest);
212}
213
214inline void
215Forwarder::onData(Face& face, const Data& data)
216{
217 this->onIncomingData(face, data);
218}
219
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700220inline NameTree&
221Forwarder::getNameTree()
222{
223 return m_nameTree;
224}
225
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700226inline Fib&
227Forwarder::getFib()
228{
229 return m_fib;
230}
231
232inline Pit&
233Forwarder::getPit()
234{
235 return m_pit;
236}
237
238inline Cs&
239Forwarder::getCs()
240{
241 return m_cs;
242}
243
Junxiao Shidbe71732014-02-21 22:23:28 -0700244inline Measurements&
245Forwarder::getMeasurements()
246{
247 return m_measurements;
248}
249
Junxiao Shibb5105f2014-03-03 12:06:45 -0700250inline StrategyChoice&
251Forwarder::getStrategyChoice()
252{
253 return m_strategyChoice;
254}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700255
Junxiao Shif3c07812014-03-11 21:48:49 -0700256#ifdef WITH_TESTS
257inline void
258Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
259#else
260template<class Function>
261inline void
262Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
263#endif
264{
265 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
266 trigger(&strategy);
267}
268
Junxiao Shid3c792f2014-01-30 00:46:13 -0700269} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800270
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700271#endif // NFD_DAEMON_FW_FORWARDER_HPP