blob: 1359737bf1b9215d5975faf119bbbe5d2b9cf45c [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
Junxiao Shid3c792f2014-01-30 00:46:13 -070052private: // pipelines
53 /** \brief incoming Interest pipeline
54 */
55 void
56 onIncomingInterest(Face& inFace, const Interest& interest);
57
58 /** \brief Interest loop pipeline
59 */
60 void
61 onInterestLoop(Face& inFace, const Interest& interest,
62 shared_ptr<pit::Entry> pitEntry);
63
64 /** \brief outgoing Interest pipeline
65 */
66 void
67 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
68
69 /** \brief Interest rebuff pipeline
70 */
71 void
72 onInterestRebuff(shared_ptr<pit::Entry> pitEntry);
73
74 /** \brief Interest unsatisfied pipeline
75 */
76 void
77 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
78
79 /** \brief incoming Data pipeline
80 */
81 void
82 onIncomingData(Face& inFace, const Data& data);
83
84 /** \brief Data unsolicited pipeline
85 */
86 void
87 onDataUnsolicited(Face& inFace, const Data& data);
88
89 /** \brief outgoing Data pipeline
90 */
91 void
92 onOutgoingData(const Data& data, Face& outFace);
93
Alexander Afanasyev33b72772014-01-26 23:22:58 -080094private:
Junxiao Shid3c792f2014-01-30 00:46:13 -070095 void
96 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
97
98 void
99 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
100
101 void
102 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
103
104private:
105 Scheduler m_scheduler;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700106
107 FaceId m_lastFaceId;
108 std::map<FaceId, shared_ptr<Face> > m_faces;
109
Junxiao Shid3c792f2014-01-30 00:46:13 -0700110 Fib m_fib;
111 Pit m_pit;
112 Cs m_cs;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700113 /// the active strategy (only one strategy in mock)
114 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700115
116 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700117 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800118};
119
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120inline Fib&
121Forwarder::getFib()
122{
123 return m_fib;
124}
125
126inline Pit&
127Forwarder::getPit()
128{
129 return m_pit;
130}
131
132inline Cs&
133Forwarder::getCs()
134{
135 return m_cs;
136}
137
138
Junxiao Shid3c792f2014-01-30 00:46:13 -0700139} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800140
141#endif // NFD_FW_FORWARDER_HPP