blob: 0ea838be31bfe77b94594b50a31b75bdd92e34cb [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 Shi8c8d2182014-01-30 22:33:00 -070016#include "strategy.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080017
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080018namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080019
20/**
21 * Forwarder is the main class of NFD.
22 *
23 * It creates and owns a set of Face listeners
24 */
25class Forwarder
26{
27public:
28 Forwarder(boost::asio::io_service& ioService);
29
Junxiao Shi8c8d2182014-01-30 22:33:00 -070030 void
31 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080032
33 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070034 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080035
36 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080038
39 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070040 onData(Face& face, const Data& data);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080041
Junxiao Shi8c8d2182014-01-30 22:33:00 -070042public:
43 Fib&
44 getFib();
45
46 Pit&
47 getPit();
48
49 Cs&
50 getCs();
51
Steve DiBenedetto26b730f2014-02-02 18:36:16 -070052 shared_ptr<Face>
53 getFace(FaceId id);
54
Junxiao Shid3c792f2014-01-30 00:46:13 -070055private: // pipelines
56 /** \brief incoming Interest pipeline
57 */
58 void
59 onIncomingInterest(Face& inFace, const Interest& interest);
60
61 /** \brief Interest loop pipeline
62 */
63 void
64 onInterestLoop(Face& inFace, const Interest& interest,
65 shared_ptr<pit::Entry> pitEntry);
66
67 /** \brief outgoing Interest pipeline
68 */
69 void
70 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
71
72 /** \brief Interest rebuff pipeline
73 */
74 void
75 onInterestRebuff(shared_ptr<pit::Entry> pitEntry);
76
77 /** \brief Interest unsatisfied pipeline
78 */
79 void
80 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
81
82 /** \brief incoming Data pipeline
83 */
84 void
85 onIncomingData(Face& inFace, const Data& data);
86
87 /** \brief Data unsolicited pipeline
88 */
89 void
90 onDataUnsolicited(Face& inFace, const Data& data);
91
92 /** \brief outgoing Data pipeline
93 */
94 void
95 onOutgoingData(const Data& data, Face& outFace);
96
Alexander Afanasyev33b72772014-01-26 23:22:58 -080097private:
Junxiao Shid3c792f2014-01-30 00:46:13 -070098 void
99 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
100
101 void
102 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
103
104 void
105 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
106
107private:
108 Scheduler m_scheduler;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700109
110 FaceId m_lastFaceId;
111 std::map<FaceId, shared_ptr<Face> > m_faces;
112
Junxiao Shid3c792f2014-01-30 00:46:13 -0700113 Fib m_fib;
114 Pit m_pit;
115 Cs m_cs;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700116 /// the active strategy (only one strategy in mock)
117 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700118
119 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800121};
122
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700123inline Fib&
124Forwarder::getFib()
125{
126 return m_fib;
127}
128
129inline Pit&
130Forwarder::getPit()
131{
132 return m_pit;
133}
134
135inline Cs&
136Forwarder::getCs()
137{
138 return m_cs;
139}
140
Junxiao Shid3c792f2014-01-30 00:46:13 -0700141} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800142
143#endif // NFD_FW_FORWARDER_HPP