blob: ae9fb6a4a5f0a4c13870caec13cac0373172d20c [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:
Junxiao Shi88884492014-02-15 15:57:43 -070028 explicit
Alexander Afanasyev33b72772014-01-26 23:22:58 -080029 Forwarder(boost::asio::io_service& ioService);
30
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);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080042
Junxiao Shi8c8d2182014-01-30 22:33:00 -070043public:
44 Fib&
45 getFib();
46
47 Pit&
48 getPit();
49
50 Cs&
51 getCs();
52
Steve DiBenedetto26b730f2014-02-02 18:36:16 -070053 shared_ptr<Face>
54 getFace(FaceId id);
55
Junxiao Shi88884492014-02-15 15:57:43 -070056PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070057 /** \brief incoming Interest pipeline
58 */
Junxiao Shi88884492014-02-15 15:57:43 -070059 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070060 onIncomingInterest(Face& inFace, const Interest& interest);
61
62 /** \brief Interest loop pipeline
63 */
Junxiao Shi88884492014-02-15 15:57:43 -070064 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070065 onInterestLoop(Face& inFace, const Interest& interest,
66 shared_ptr<pit::Entry> pitEntry);
67
68 /** \brief outgoing Interest pipeline
69 */
Junxiao Shi88884492014-02-15 15:57:43 -070070 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070071 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
72
73 /** \brief Interest rebuff pipeline
74 */
Junxiao Shi88884492014-02-15 15:57:43 -070075 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070076 onInterestRebuff(shared_ptr<pit::Entry> pitEntry);
77
78 /** \brief Interest unsatisfied pipeline
79 */
Junxiao Shi88884492014-02-15 15:57:43 -070080 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070081 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
82
83 /** \brief incoming Data pipeline
84 */
Junxiao Shi88884492014-02-15 15:57:43 -070085 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070086 onIncomingData(Face& inFace, const Data& data);
87
88 /** \brief Data unsolicited pipeline
89 */
Junxiao Shi88884492014-02-15 15:57:43 -070090 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070091 onDataUnsolicited(Face& inFace, const Data& data);
92
93 /** \brief outgoing Data pipeline
94 */
Junxiao Shi88884492014-02-15 15:57:43 -070095 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070096 onOutgoingData(const Data& data, Face& outFace);
97
Junxiao Shi88884492014-02-15 15:57:43 -070098PROTECTED_WITH_TESTS_ELSE_PRIVATE:
99 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
101
Junxiao Shi88884492014-02-15 15:57:43 -0700102 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
104
Junxiao Shi88884492014-02-15 15:57:43 -0700105 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700106 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shi88884492014-02-15 15:57:43 -0700107
108 VIRTUAL_WITH_TESTS void
109 dispatchToStrategy(const Face& inFace,
110 const Interest& interest,
111 shared_ptr<fib::Entry> fibEntry,
112 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700113
114private:
115 Scheduler m_scheduler;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700116
117 FaceId m_lastFaceId;
118 std::map<FaceId, shared_ptr<Face> > m_faces;
119
Junxiao Shid3c792f2014-01-30 00:46:13 -0700120 Fib m_fib;
121 Pit m_pit;
122 Cs m_cs;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700123 /// the active strategy (only one strategy in mock)
124 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125
Junxiao Shi88884492014-02-15 15:57:43 -0700126 static const Name s_localhostName;
127
Junxiao Shid3c792f2014-01-30 00:46:13 -0700128 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700129 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800130};
131
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700132inline Fib&
133Forwarder::getFib()
134{
135 return m_fib;
136}
137
138inline Pit&
139Forwarder::getPit()
140{
141 return m_pit;
142}
143
144inline Cs&
145Forwarder::getCs()
146{
147 return m_cs;
148}
149
Junxiao Shid3c792f2014-01-30 00:46:13 -0700150} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800151
152#endif // NFD_FW_FORWARDER_HPP