blob: d9d23bc156985efb2498b63057b1c90acc080d4d [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"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080018
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080019namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080020
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070021namespace fw {
22class Strategy;
23} // namespace fw
24
25/** \brief main class of NFD
Junxiao Shic041ca32014-02-25 20:01:15 -070026 *
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070027 * Forwarder owns all faces and tables, and implements forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080028 */
29class Forwarder
30{
31public:
Junxiao Shic041ca32014-02-25 20:01:15 -070032 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080033
Junxiao Shia4f2be82014-03-02 22:56:41 -070034public: // faces
35 FaceTable&
36 getFaceTable();
37
38 /** \brief get existing Face
39 *
40 * shortcut to .getFaceTable().get(face)
41 */
42 shared_ptr<Face>
43 getFace(FaceId id) const;
44
45 /** \brief add new Face
46 *
47 * shortcut to .getFaceTable().add(face)
48 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070049 void
50 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080051
Junxiao Shia4f2be82014-03-02 22:56:41 -070052 /** \brief remove existing Face
53 *
54 * shortcut to .getFaceTable().remove(face)
55 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080056 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070057 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080058
Junxiao Shia4f2be82014-03-02 22:56:41 -070059public: // forwarding entrypoints and tables
Alexander Afanasyev33b72772014-01-26 23:22:58 -080060 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070061 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080062
63 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070064 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070065
Junxiao Shi8c8d2182014-01-30 22:33:00 -070066 Fib&
67 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070068
Junxiao Shi8c8d2182014-01-30 22:33:00 -070069 Pit&
70 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070071
Junxiao Shi8c8d2182014-01-30 22:33:00 -070072 Cs&
73 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070074
Junxiao Shidbe71732014-02-21 22:23:28 -070075 Measurements&
76 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070077
Junxiao Shibb5105f2014-03-03 12:06:45 -070078 StrategyChoice&
79 getStrategyChoice();
80
Junxiao Shi88884492014-02-15 15:57:43 -070081PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070082 /** \brief incoming Interest pipeline
83 */
Junxiao Shi88884492014-02-15 15:57:43 -070084 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070085 onIncomingInterest(Face& inFace, const Interest& interest);
86
87 /** \brief Interest loop pipeline
88 */
Junxiao Shi88884492014-02-15 15:57:43 -070089 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070090 onInterestLoop(Face& inFace, const Interest& interest,
91 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070092
Junxiao Shid3c792f2014-01-30 00:46:13 -070093 /** \brief outgoing Interest pipeline
94 */
Junxiao Shi88884492014-02-15 15:57:43 -070095 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070096 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
Junxiao Shic041ca32014-02-25 20:01:15 -070097
Junxiao Shi09498f02014-02-26 19:41:08 -070098 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -070099 */
Junxiao Shi88884492014-02-15 15:57:43 -0700100 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700101 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700102
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 /** \brief Interest unsatisfied pipeline
104 */
Junxiao Shi88884492014-02-15 15:57:43 -0700105 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700106 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700107
Junxiao Shid3c792f2014-01-30 00:46:13 -0700108 /** \brief incoming Data pipeline
109 */
Junxiao Shi88884492014-02-15 15:57:43 -0700110 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700111 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700112
Junxiao Shid3c792f2014-01-30 00:46:13 -0700113 /** \brief Data unsolicited pipeline
114 */
Junxiao Shi88884492014-02-15 15:57:43 -0700115 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700116 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700117
Junxiao Shid3c792f2014-01-30 00:46:13 -0700118 /** \brief outgoing Data pipeline
119 */
Junxiao Shi88884492014-02-15 15:57:43 -0700120 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700121 onOutgoingData(const Data& data, Face& outFace);
122
Junxiao Shi88884492014-02-15 15:57:43 -0700123PROTECTED_WITH_TESTS_ELSE_PRIVATE:
124 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700126
Junxiao Shi88884492014-02-15 15:57:43 -0700127 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700128 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700129
Junxiao Shi88884492014-02-15 15:57:43 -0700130 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700131 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700132
Junxiao Shi88884492014-02-15 15:57:43 -0700133 VIRTUAL_WITH_TESTS void
134 dispatchToStrategy(const Face& inFace,
135 const Interest& interest,
136 shared_ptr<fib::Entry> fibEntry,
137 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700138
139private:
Junxiao Shia4f2be82014-03-02 22:56:41 -0700140 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800141
Junxiao Shibb5105f2014-03-03 12:06:45 -0700142 // tables
143 NameTree m_nameTree;
144 Fib m_fib;
145 Pit m_pit;
146 Cs m_cs;
147 Measurements m_measurements;
148 StrategyChoice m_strategyChoice;
149
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700150 /// the active strategy (only one strategy in mock)
151 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shic041ca32014-02-25 20:01:15 -0700152
Junxiao Shi88884492014-02-15 15:57:43 -0700153 static const Name s_localhostName;
Junxiao Shic041ca32014-02-25 20:01:15 -0700154
Junxiao Shid3c792f2014-01-30 00:46:13 -0700155 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700156 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800157};
158
Junxiao Shia4f2be82014-03-02 22:56:41 -0700159inline FaceTable&
160Forwarder::getFaceTable()
161{
162 return m_faceTable;
163}
164
165inline shared_ptr<Face>
166Forwarder::getFace(FaceId id) const
167{
168 return m_faceTable.get(id);
169}
170
171inline void
172Forwarder::addFace(shared_ptr<Face> face)
173{
174 m_faceTable.add(face);
175}
176
177inline void
178Forwarder::removeFace(shared_ptr<Face> face)
179{
180 m_faceTable.remove(face);
181}
182
183inline void
184Forwarder::onInterest(Face& face, const Interest& interest)
185{
186 this->onIncomingInterest(face, interest);
187}
188
189inline void
190Forwarder::onData(Face& face, const Data& data)
191{
192 this->onIncomingData(face, data);
193}
194
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700195inline Fib&
196Forwarder::getFib()
197{
198 return m_fib;
199}
200
201inline Pit&
202Forwarder::getPit()
203{
204 return m_pit;
205}
206
207inline Cs&
208Forwarder::getCs()
209{
210 return m_cs;
211}
212
Junxiao Shidbe71732014-02-21 22:23:28 -0700213inline Measurements&
214Forwarder::getMeasurements()
215{
216 return m_measurements;
217}
218
Junxiao Shibb5105f2014-03-03 12:06:45 -0700219inline StrategyChoice&
220Forwarder::getStrategyChoice()
221{
222 return m_strategyChoice;
223}
Junxiao Shia4f2be82014-03-02 22:56:41 -0700224
Junxiao Shid3c792f2014-01-30 00:46:13 -0700225} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800226
227#endif // NFD_FW_FORWARDER_HPP