blob: 6da99c7bef63a2f949fa0ac9565b3c488c8a01c5 [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.
23 *
24 * It creates and owns a set of Face listeners
25 */
26class Forwarder
27{
28public:
Junxiao Shi88884492014-02-15 15:57:43 -070029 explicit
Alexander Afanasyev33b72772014-01-26 23:22:58 -080030 Forwarder(boost::asio::io_service& ioService);
31
Junxiao Shi8c8d2182014-01-30 22:33:00 -070032 void
33 addFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080034
35 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070036 removeFace(shared_ptr<Face> face);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080037
38 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070039 onInterest(Face& face, const Interest& interest);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080040
41 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070042 onData(Face& face, const Data& data);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080043
Junxiao Shi8c8d2182014-01-30 22:33:00 -070044public:
45 Fib&
46 getFib();
47
48 Pit&
49 getPit();
50
51 Cs&
52 getCs();
Junxiao Shidbe71732014-02-21 22:23:28 -070053
54 Measurements&
55 getMeasurements();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070056
Steve DiBenedetto26b730f2014-02-02 18:36:16 -070057 shared_ptr<Face>
58 getFace(FaceId id);
59
Junxiao Shi88884492014-02-15 15:57:43 -070060PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -070061 /** \brief incoming Interest pipeline
62 */
Junxiao Shi88884492014-02-15 15:57:43 -070063 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070064 onIncomingInterest(Face& inFace, const Interest& interest);
65
66 /** \brief Interest loop pipeline
67 */
Junxiao Shi88884492014-02-15 15:57:43 -070068 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070069 onInterestLoop(Face& inFace, const Interest& interest,
70 shared_ptr<pit::Entry> pitEntry);
71
72 /** \brief outgoing Interest pipeline
73 */
Junxiao Shi88884492014-02-15 15:57:43 -070074 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070075 onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace);
76
77 /** \brief Interest rebuff pipeline
78 */
Junxiao Shi88884492014-02-15 15:57:43 -070079 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070080 onInterestRebuff(shared_ptr<pit::Entry> pitEntry);
81
82 /** \brief Interest unsatisfied pipeline
83 */
Junxiao Shi88884492014-02-15 15:57:43 -070084 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070085 onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
86
87 /** \brief incoming Data pipeline
88 */
Junxiao Shi88884492014-02-15 15:57:43 -070089 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070090 onIncomingData(Face& inFace, const Data& data);
91
92 /** \brief Data unsolicited pipeline
93 */
Junxiao Shi88884492014-02-15 15:57:43 -070094 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070095 onDataUnsolicited(Face& inFace, const Data& data);
96
97 /** \brief outgoing Data pipeline
98 */
Junxiao Shi88884492014-02-15 15:57:43 -070099 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 onOutgoingData(const Data& data, Face& outFace);
101
Junxiao Shi88884492014-02-15 15:57:43 -0700102PROTECTED_WITH_TESTS_ELSE_PRIVATE:
103 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700104 setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
105
Junxiao Shi88884492014-02-15 15:57:43 -0700106 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700107 setStragglerTimer(shared_ptr<pit::Entry> pitEntry);
108
Junxiao Shi88884492014-02-15 15:57:43 -0700109 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700110 cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
Junxiao Shi88884492014-02-15 15:57:43 -0700111
112 VIRTUAL_WITH_TESTS void
113 dispatchToStrategy(const Face& inFace,
114 const Interest& interest,
115 shared_ptr<fib::Entry> fibEntry,
116 shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700117
118private:
119 Scheduler m_scheduler;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120
121 FaceId m_lastFaceId;
122 std::map<FaceId, shared_ptr<Face> > m_faces;
123
Junxiao Shidbe71732014-02-21 22:23:28 -0700124 Fib m_fib;
125 Pit m_pit;
126 Cs m_cs;
127 Measurements m_measurements;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700128 /// the active strategy (only one strategy in mock)
129 shared_ptr<fw::Strategy> m_strategy;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700130
Junxiao Shi88884492014-02-15 15:57:43 -0700131 static const Name s_localhostName;
132
Junxiao Shid3c792f2014-01-30 00:46:13 -0700133 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700134 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800135};
136
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700137inline Fib&
138Forwarder::getFib()
139{
140 return m_fib;
141}
142
143inline Pit&
144Forwarder::getPit()
145{
146 return m_pit;
147}
148
149inline Cs&
150Forwarder::getCs()
151{
152 return m_cs;
153}
154
Junxiao Shidbe71732014-02-21 22:23:28 -0700155inline Measurements&
156Forwarder::getMeasurements()
157{
158 return m_measurements;
159}
160
Junxiao Shid3c792f2014-01-30 00:46:13 -0700161} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800162
163#endif // NFD_FW_FORWARDER_HPP