blob: 7ab08496ec60ab9b19b4d2100a1ac4f6da52e261 [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_FW_FORWARDER_HPP
8#define NFD_FW_FORWARDER_HPP
9
10#include "common.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070011#include "core/scheduler.hpp"
Junxiao Shia4f2be82014-03-02 22:56:41 -070012#include "face-table.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070013#include "table/fib.hpp"
14#include "table/pit.hpp"
15#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070016#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070017#include "table/strategy-choice.hpp"
Junxiao Shi8c8d2182014-01-30 22:33:00 -070018#include "strategy.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080019
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080020namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080021
22/**
23 * Forwarder is the main class of NFD.
Junxiao Shic041ca32014-02-25 20:01:15 -070024 *
Alexander Afanasyev33b72772014-01-26 23:22:58 -080025 * It creates and owns a set of Face listeners
26 */
27class Forwarder
28{
29public:
Junxiao Shic041ca32014-02-25 20:01:15 -070030 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080031
Junxiao Shia4f2be82014-03-02 22:56:41 -070032public: // faces
33 FaceTable&
34 getFaceTable();
35
36 /** \brief get existing Face
37 *
38 * shortcut to .getFaceTable().get(face)
39 */
40 shared_ptr<Face>
41 getFace(FaceId id) const;
42
43 /** \brief add new Face
44 *
45 * shortcut to .getFaceTable().add(face)
46 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070047 void
48 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080049
Junxiao Shia4f2be82014-03-02 22:56:41 -070050 /** \brief remove existing Face
51 *
52 * shortcut to .getFaceTable().remove(face)
53 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080054 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080056
Junxiao Shia4f2be82014-03-02 22:56:41 -070057public: // forwarding entrypoints and tables
Alexander Afanasyev33b72772014-01-26 23:22:58 -080058 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070059 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080060
61 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070062 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070063
Junxiao Shi8c8d2182014-01-30 22:33:00 -070064 Fib&
65 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070066
Junxiao Shi8c8d2182014-01-30 22:33:00 -070067 Pit&
68 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070069
Junxiao Shi8c8d2182014-01-30 22:33:00 -070070 Cs&
71 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070072
Junxiao Shidbe71732014-02-21 22:23:28 -070073 Measurements&
74 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070075
Junxiao Shibb5105f2014-03-03 12:06:45 -070076 StrategyChoice&
77 getStrategyChoice();
78
Junxiao Shi88884492014-02-15 15:57:43 -070079PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070080 /** \brief incoming Interest pipeline
81 */
Junxiao Shi88884492014-02-15 15:57:43 -070082 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070083 onIncomingInterest(Face& inFace, const Interest& interest);
84
85 /** \brief Interest loop pipeline
86 */
Junxiao Shi88884492014-02-15 15:57:43 -070087 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070088 onInterestLoop(Face& inFace, const Interest& interest,
89 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070090
Junxiao Shid3c792f2014-01-30 00:46:13 -070091 /** \brief outgoing Interest pipeline
92 */
Junxiao Shi88884492014-02-15 15:57:43 -070093 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070094 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
Junxiao Shic041ca32014-02-25 20:01:15 -070095
Junxiao Shi09498f02014-02-26 19:41:08 -070096 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -070097 */
Junxiao Shi88884492014-02-15 15:57:43 -070098 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -070099 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700100
Junxiao Shid3c792f2014-01-30 00:46:13 -0700101 /** \brief Interest unsatisfied pipeline
102 */
Junxiao Shi88884492014-02-15 15:57:43 -0700103 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700104 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700105
Junxiao Shid3c792f2014-01-30 00:46:13 -0700106 /** \brief incoming Data pipeline
107 */
Junxiao Shi88884492014-02-15 15:57:43 -0700108 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700109 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700110
Junxiao Shid3c792f2014-01-30 00:46:13 -0700111 /** \brief Data unsolicited pipeline
112 */
Junxiao Shi88884492014-02-15 15:57:43 -0700113 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700114 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700115
Junxiao Shid3c792f2014-01-30 00:46:13 -0700116 /** \brief outgoing Data pipeline
117 */
Junxiao Shi88884492014-02-15 15:57:43 -0700118 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700119 onOutgoingData(const Data& data, Face& outFace);
120
Junxiao Shi88884492014-02-15 15:57:43 -0700121PROTECTED_WITH_TESTS_ELSE_PRIVATE:
122 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700123 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700124
Junxiao Shi88884492014-02-15 15:57:43 -0700125 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700126 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700127
Junxiao Shi88884492014-02-15 15:57:43 -0700128 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700129 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700130
Junxiao Shi88884492014-02-15 15:57:43 -0700131 VIRTUAL_WITH_TESTS void
132 dispatchToStrategy(const Face& inFace,
133 const Interest& interest,
134 shared_ptr<fib::Entry> fibEntry,
135 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700136
137private:
Junxiao Shia4f2be82014-03-02 22:56:41 -0700138 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800139
Junxiao Shibb5105f2014-03-03 12:06:45 -0700140 // tables
141 NameTree m_nameTree;
142 Fib m_fib;
143 Pit m_pit;
144 Cs m_cs;
145 Measurements m_measurements;
146 StrategyChoice m_strategyChoice;
147
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700148 /// the active strategy (only one strategy in mock)
149 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shic041ca32014-02-25 20:01:15 -0700150
Junxiao Shi88884492014-02-15 15:57:43 -0700151 static const Name s_localhostName;
Junxiao Shic041ca32014-02-25 20:01:15 -0700152
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700154 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800155};
156
Junxiao Shia4f2be82014-03-02 22:56:41 -0700157inline FaceTable&
158Forwarder::getFaceTable()
159{
160 return m_faceTable;
161}
162
163inline shared_ptr<Face>
164Forwarder::getFace(FaceId id) const
165{
166 return m_faceTable.get(id);
167}
168
169inline void
170Forwarder::addFace(shared_ptr<Face> face)
171{
172 m_faceTable.add(face);
173}
174
175inline void
176Forwarder::removeFace(shared_ptr<Face> face)
177{
178 m_faceTable.remove(face);
179}
180
181inline void
182Forwarder::onInterest(Face& face, const Interest& interest)
183{
184 this->onIncomingInterest(face, interest);
185}
186
187inline void
188Forwarder::onData(Face& face, const Data& data)
189{
190 this->onIncomingData(face, data);
191}
192
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700193inline Fib&
194Forwarder::getFib()
195{
196 return m_fib;
197}
198
199inline Pit&
200Forwarder::getPit()
201{
202 return m_pit;
203}
204
205inline Cs&
206Forwarder::getCs()
207{
208 return m_cs;
209}
210
Junxiao Shidbe71732014-02-21 22:23:28 -0700211inline Measurements&
212Forwarder::getMeasurements()
213{
214 return m_measurements;
215}
216
Junxiao Shibb5105f2014-03-03 12:06:45 -0700217inline StrategyChoice&
218Forwarder::getStrategyChoice()
219{
220 return m_strategyChoice;
221}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700222
Junxiao Shid3c792f2014-01-30 00:46:13 -0700223} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800224
225#endif // NFD_FW_FORWARDER_HPP