blob: 726d8a064e41ef03dc70a64a641bb9b2a70d7c13 [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 Shi8c8d2182014-01-30 22:33:00 -070017#include "strategy.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
21/**
22 * Forwarder is the main class of NFD.
Junxiao Shic041ca32014-02-25 20:01:15 -070023 *
Alexander Afanasyev33b72772014-01-26 23:22:58 -080024 * It creates and owns a set of Face listeners
25 */
26class Forwarder
27{
28public:
Junxiao Shic041ca32014-02-25 20:01:15 -070029 Forwarder();
Alexander Afanasyev33b72772014-01-26 23:22:58 -080030
Junxiao Shia4f2be82014-03-02 22:56:41 -070031public: // faces
32 FaceTable&
33 getFaceTable();
34
35 /** \brief get existing Face
36 *
37 * shortcut to .getFaceTable().get(face)
38 */
39 shared_ptr<Face>
40 getFace(FaceId id) const;
41
42 /** \brief add new Face
43 *
44 * shortcut to .getFaceTable().add(face)
45 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -070046 void
47 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080048
Junxiao Shia4f2be82014-03-02 22:56:41 -070049 /** \brief remove existing Face
50 *
51 * shortcut to .getFaceTable().remove(face)
52 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080053 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070054 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080055
Junxiao Shia4f2be82014-03-02 22:56:41 -070056public: // forwarding entrypoints and tables
Alexander Afanasyev33b72772014-01-26 23:22:58 -080057 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070058 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080059
60 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070061 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070062
Junxiao Shi8c8d2182014-01-30 22:33:00 -070063 Fib&
64 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070065
Junxiao Shi8c8d2182014-01-30 22:33:00 -070066 Pit&
67 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070068
Junxiao Shi8c8d2182014-01-30 22:33:00 -070069 Cs&
70 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070071
Junxiao Shidbe71732014-02-21 22:23:28 -070072 Measurements&
73 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070074
Junxiao Shi88884492014-02-15 15:57:43 -070075PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070076 /** \brief incoming Interest pipeline
77 */
Junxiao Shi88884492014-02-15 15:57:43 -070078 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070079 onIncomingInterest(Face& inFace, const Interest& interest);
80
81 /** \brief Interest loop pipeline
82 */
Junxiao Shi88884492014-02-15 15:57:43 -070083 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070084 onInterestLoop(Face& inFace, const Interest& interest,
85 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070086
Junxiao Shid3c792f2014-01-30 00:46:13 -070087 /** \brief outgoing Interest pipeline
88 */
Junxiao Shi88884492014-02-15 15:57:43 -070089 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070090 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
Junxiao Shic041ca32014-02-25 20:01:15 -070091
Junxiao Shi09498f02014-02-26 19:41:08 -070092 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -070093 */
Junxiao Shi88884492014-02-15 15:57:43 -070094 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -070095 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070096
Junxiao Shid3c792f2014-01-30 00:46:13 -070097 /** \brief Interest unsatisfied pipeline
98 */
Junxiao Shi88884492014-02-15 15:57:43 -070099 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700101
Junxiao Shid3c792f2014-01-30 00:46:13 -0700102 /** \brief incoming Data pipeline
103 */
Junxiao Shi88884492014-02-15 15:57:43 -0700104 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700105 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700106
Junxiao Shid3c792f2014-01-30 00:46:13 -0700107 /** \brief Data unsolicited pipeline
108 */
Junxiao Shi88884492014-02-15 15:57:43 -0700109 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700110 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -0700111
Junxiao Shid3c792f2014-01-30 00:46:13 -0700112 /** \brief outgoing Data pipeline
113 */
Junxiao Shi88884492014-02-15 15:57:43 -0700114 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700115 onOutgoingData(const Data& data, Face& outFace);
116
Junxiao Shi88884492014-02-15 15:57:43 -0700117PROTECTED_WITH_TESTS_ELSE_PRIVATE:
118 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700119 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700120
Junxiao Shi88884492014-02-15 15:57:43 -0700121 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700122 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700123
Junxiao Shi88884492014-02-15 15:57:43 -0700124 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125 cancelUnsatisfyAndStragglerTimer(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
128 dispatchToStrategy(const Face& inFace,
129 const Interest& interest,
130 shared_ptr<fib::Entry> fibEntry,
131 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132
133private:
Junxiao Shia4f2be82014-03-02 22:56:41 -0700134 FaceTable m_faceTable;
HangZhangad4afd12014-03-01 11:03:08 +0800135
Haowei Yuan78c84d12014-02-27 15:35:13 -0600136 NameTree m_nameTree;
Junxiao Shidbe71732014-02-21 22:23:28 -0700137 Fib m_fib;
138 Pit m_pit;
139 Cs m_cs;
140 Measurements m_measurements;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700141 /// the active strategy (only one strategy in mock)
142 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shic041ca32014-02-25 20:01:15 -0700143
Junxiao Shi88884492014-02-15 15:57:43 -0700144 static const Name s_localhostName;
Junxiao Shic041ca32014-02-25 20:01:15 -0700145
Junxiao Shid3c792f2014-01-30 00:46:13 -0700146 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700147 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800148};
149
Junxiao Shia4f2be82014-03-02 22:56:41 -0700150inline FaceTable&
151Forwarder::getFaceTable()
152{
153 return m_faceTable;
154}
155
156inline shared_ptr<Face>
157Forwarder::getFace(FaceId id) const
158{
159 return m_faceTable.get(id);
160}
161
162inline void
163Forwarder::addFace(shared_ptr<Face> face)
164{
165 m_faceTable.add(face);
166}
167
168inline void
169Forwarder::removeFace(shared_ptr<Face> face)
170{
171 m_faceTable.remove(face);
172}
173
174inline void
175Forwarder::onInterest(Face& face, const Interest& interest)
176{
177 this->onIncomingInterest(face, interest);
178}
179
180inline void
181Forwarder::onData(Face& face, const Data& data)
182{
183 this->onIncomingData(face, data);
184}
185
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700186inline Fib&
187Forwarder::getFib()
188{
189 return m_fib;
190}
191
192inline Pit&
193Forwarder::getPit()
194{
195 return m_pit;
196}
197
198inline Cs&
199Forwarder::getCs()
200{
201 return m_cs;
202}
203
Junxiao Shidbe71732014-02-21 22:23:28 -0700204inline Measurements&
205Forwarder::getMeasurements()
206{
207 return m_measurements;
208}
209
Junxiao Shia4f2be82014-03-02 22:56:41 -0700210
Junxiao Shid3c792f2014-01-30 00:46:13 -0700211} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800212
213#endif // NFD_FW_FORWARDER_HPP