blob: 5130c76b489508e911673f6f4addbbefcec57dd8 [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"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080012#include "face/face.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 Shi8c8d2182014-01-30 22:33:00 -070031 void
32 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080033
34 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070035 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080036
37 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070038 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080039
40 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070041 onData(Face& face, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070042
Junxiao Shi8c8d2182014-01-30 22:33:00 -070043public:
44 Fib&
45 getFib();
Junxiao Shic041ca32014-02-25 20:01:15 -070046
Junxiao Shi8c8d2182014-01-30 22:33:00 -070047 Pit&
48 getPit();
Junxiao Shic041ca32014-02-25 20:01:15 -070049
Junxiao Shi8c8d2182014-01-30 22:33:00 -070050 Cs&
51 getCs();
Junxiao Shic041ca32014-02-25 20:01:15 -070052
Junxiao Shidbe71732014-02-21 22:23:28 -070053 Measurements&
54 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055
Steve DiBenedetto26b730f2014-02-02 18:36:16 -070056 shared_ptr<Face>
57 getFace(FaceId id);
58
Junxiao Shi88884492014-02-15 15:57:43 -070059PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070060 /** \brief incoming Interest pipeline
61 */
Junxiao Shi88884492014-02-15 15:57:43 -070062 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070063 onIncomingInterest(Face& inFace, const Interest& interest);
64
65 /** \brief Interest loop pipeline
66 */
Junxiao Shi88884492014-02-15 15:57:43 -070067 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070068 onInterestLoop(Face& inFace, const Interest& interest,
69 shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070070
Junxiao Shid3c792f2014-01-30 00:46:13 -070071 /** \brief outgoing Interest pipeline
72 */
Junxiao Shi88884492014-02-15 15:57:43 -070073 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070074 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
Junxiao Shic041ca32014-02-25 20:01:15 -070075
Junxiao Shi09498f02014-02-26 19:41:08 -070076 /** \brief Interest reject pipeline
Junxiao Shid3c792f2014-01-30 00:46:13 -070077 */
Junxiao Shi88884492014-02-15 15:57:43 -070078 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -070079 onInterestReject(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070080
Junxiao Shid3c792f2014-01-30 00:46:13 -070081 /** \brief Interest unsatisfied pipeline
82 */
Junxiao Shi88884492014-02-15 15:57:43 -070083 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070084 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -070085
Junxiao Shid3c792f2014-01-30 00:46:13 -070086 /** \brief incoming Data pipeline
87 */
Junxiao Shi88884492014-02-15 15:57:43 -070088 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070089 onIncomingData(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070090
Junxiao Shid3c792f2014-01-30 00:46:13 -070091 /** \brief Data unsolicited pipeline
92 */
Junxiao Shi88884492014-02-15 15:57:43 -070093 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070094 onDataUnsolicited(Face& inFace, const Data& data);
Junxiao Shic041ca32014-02-25 20:01:15 -070095
Junxiao Shid3c792f2014-01-30 00:46:13 -070096 /** \brief outgoing Data pipeline
97 */
Junxiao Shi88884492014-02-15 15:57:43 -070098 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070099 onOutgoingData(const Data& data, Face& outFace);
100
Junxiao Shi88884492014-02-15 15:57:43 -0700101PROTECTED_WITH_TESTS_ELSE_PRIVATE:
102 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700104
Junxiao Shi88884492014-02-15 15:57:43 -0700105 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700106 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700107
Junxiao Shi88884492014-02-15 15:57:43 -0700108 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700109 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700110
Junxiao Shi88884492014-02-15 15:57:43 -0700111 VIRTUAL_WITH_TESTS void
112 dispatchToStrategy(const Face& inFace,
113 const Interest& interest,
114 shared_ptr<fib::Entry> fibEntry,
115 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700116
117private:
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700118 FaceId m_lastFaceId;
119 std::map<FaceId, shared_ptr<Face> > m_faces;
HangZhangad4afd12014-03-01 11:03:08 +0800120
Haowei Yuan78c84d12014-02-27 15:35:13 -0600121 NameTree m_nameTree;
Junxiao Shidbe71732014-02-21 22:23:28 -0700122 Fib m_fib;
123 Pit m_pit;
124 Cs m_cs;
125 Measurements m_measurements;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700126 /// the active strategy (only one strategy in mock)
127 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shic041ca32014-02-25 20:01:15 -0700128
Junxiao Shi88884492014-02-15 15:57:43 -0700129 static const Name s_localhostName;
Junxiao Shic041ca32014-02-25 20:01:15 -0700130
Junxiao Shid3c792f2014-01-30 00:46:13 -0700131 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700132 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800133};
134
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700135inline Fib&
136Forwarder::getFib()
137{
138 return m_fib;
139}
140
141inline Pit&
142Forwarder::getPit()
143{
144 return m_pit;
145}
146
147inline Cs&
148Forwarder::getCs()
149{
150 return m_cs;
151}
152
Junxiao Shidbe71732014-02-21 22:23:28 -0700153inline Measurements&
154Forwarder::getMeasurements()
155{
156 return m_measurements;
157}
158
Junxiao Shid3c792f2014-01-30 00:46:13 -0700159} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800160
161#endif // NFD_FW_FORWARDER_HPP