blob: 744338a202325de1a2c401a1ee71a4de5780631d [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 Shib289cc12014-03-15 12:19:05 -070030#include "forwarder-counter.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 Shid3c792f2014-01-30 00:46:13 -0700117 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
Junxiao Shic041ca32014-02-25 20:01:15 -0700118
Junxiao Shi09498f02014-02-26 19:41:08 -0700119 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -0700120 */
Junxiao Shi88884492014-02-15 15:57:43 -0700121 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700122 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700123
Junxiao Shid3c792f2014-01-30 00:46:13 -0700124 /** \brief Interest unsatisfied pipeline
125 */
Junxiao Shi88884492014-02-15 15:57:43 -0700126 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700127 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700128
Junxiao Shid3c792f2014-01-30 00:46:13 -0700129 /** \brief incoming Data pipeline
130 */
Junxiao Shi88884492014-02-15 15:57:43 -0700131 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700133
Junxiao Shid3c792f2014-01-30 00:46:13 -0700134 /** \brief Data unsolicited pipeline
135 */
Junxiao Shi88884492014-02-15 15:57:43 -0700136 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700137 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700138
Junxiao Shid3c792f2014-01-30 00:46:13 -0700139 /** \brief outgoing Data pipeline
140 */
Junxiao Shi88884492014-02-15 15:57:43 -0700141 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700142 onOutgoingData(const Data& data, Face& outFace);
143
Junxiao Shi88884492014-02-15 15:57:43 -0700144PROTECTED_WITH_TESTS_ELSE_PRIVATE:
145 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700146 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700147
Junxiao Shi88884492014-02-15 15:57:43 -0700148 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700149 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700150
Junxiao Shi88884492014-02-15 15:57:43 -0700151 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700152 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700153
Junxiao Shif3c07812014-03-11 21:48:49 -0700154 /// call trigger (method) on the effective strategy of pitEntry
155#ifdef WITH_TESTS
156 virtual void
157 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
158#else
159 template<class Function>
160 void
161 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
162#endif
Junxiao Shid3c792f2014-01-30 00:46:13 -0700163
164private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700165 ForwarderCounters m_counters;
166
Junxiao Shia4f2be82014-03-02 22:56:41 -0700167 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800168
Junxiao Shibb5105f2014-03-03 12:06:45 -0700169 // tables
170 NameTree m_nameTree;
171 Fib m_fib;
172 Pit m_pit;
173 Cs m_cs;
174 Measurements m_measurements;
175 StrategyChoice m_strategyChoice;
176
Junxiao Shif3c07812014-03-11 21:48:49 -0700177 static const Name LOCALHOST_NAME;
Junxiao Shic041ca32014-02-25 20:01:15 -0700178
Junxiao Shid3c792f2014-01-30 00:46:13 -0700179 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700180 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800181};
182
Junxiao Shib289cc12014-03-15 12:19:05 -0700183inline const ForwarderCounters&
184Forwarder::getCounters() const
185{
186 return m_counters;
187}
188
Junxiao Shia4f2be82014-03-02 22:56:41 -0700189inline FaceTable&
190Forwarder::getFaceTable()
191{
192 return m_faceTable;
193}
194
195inline shared_ptr<Face>
196Forwarder::getFace(FaceId id) const
197{
198 return m_faceTable.get(id);
199}
200
201inline void
202Forwarder::addFace(shared_ptr<Face> face)
203{
204 m_faceTable.add(face);
205}
206
207inline void
Junxiao Shia4f2be82014-03-02 22:56:41 -0700208Forwarder::onInterest(Face& face, const Interest& interest)
209{
210 this->onIncomingInterest(face, interest);
211}
212
213inline void
214Forwarder::onData(Face& face, const Data& data)
215{
216 this->onIncomingData(face, data);
217}
218
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700219inline NameTree&
220Forwarder::getNameTree()
221{
222 return m_nameTree;
223}
224
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700225inline Fib&
226Forwarder::getFib()
227{
228 return m_fib;
229}
230
231inline Pit&
232Forwarder::getPit()
233{
234 return m_pit;
235}
236
237inline Cs&
238Forwarder::getCs()
239{
240 return m_cs;
241}
242
Junxiao Shidbe71732014-02-21 22:23:28 -0700243inline Measurements&
244Forwarder::getMeasurements()
245{
246 return m_measurements;
247}
248
Junxiao Shibb5105f2014-03-03 12:06:45 -0700249inline StrategyChoice&
250Forwarder::getStrategyChoice()
251{
252 return m_strategyChoice;
253}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700254
Junxiao Shif3c07812014-03-11 21:48:49 -0700255#ifdef WITH_TESTS
256inline void
257Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
258#else
259template<class Function>
260inline void
261Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
262#endif
263{
264 fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
265 trigger(&strategy);
266}
267
Junxiao Shid3c792f2014-01-30 00:46:13 -0700268} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800269
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700270#endif // NFD_DAEMON_FW_FORWARDER_HPP