Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 1 | /* -*- 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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 11 | #include "core/scheduler.hpp" |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 12 | #include "face/face.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 13 | #include "table/fib.hpp" |
| 14 | #include "table/pit.hpp" |
| 15 | #include "table/cs.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame^] | 16 | #include "table/measurements.hpp" |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 17 | #include "strategy.hpp" |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 19 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Forwarder is the main class of NFD. |
| 23 | * |
| 24 | * It creates and owns a set of Face listeners |
| 25 | */ |
| 26 | class Forwarder |
| 27 | { |
| 28 | public: |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 29 | explicit |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 30 | Forwarder(boost::asio::io_service& ioService); |
| 31 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 32 | void |
| 33 | addFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 34 | |
| 35 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 36 | removeFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 37 | |
| 38 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 39 | onInterest(Face& face, const Interest& interest); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 40 | |
| 41 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 42 | onData(Face& face, const Data& data); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 43 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 44 | public: |
| 45 | Fib& |
| 46 | getFib(); |
| 47 | |
| 48 | Pit& |
| 49 | getPit(); |
| 50 | |
| 51 | Cs& |
| 52 | getCs(); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame^] | 53 | |
| 54 | Measurements& |
| 55 | getMeasurements(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 56 | |
Steve DiBenedetto | 26b730f | 2014-02-02 18:36:16 -0700 | [diff] [blame] | 57 | shared_ptr<Face> |
| 58 | getFace(FaceId id); |
| 59 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 60 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 61 | /** \brief incoming Interest pipeline |
| 62 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 63 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 64 | onIncomingInterest(Face& inFace, const Interest& interest); |
| 65 | |
| 66 | /** \brief Interest loop pipeline |
| 67 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 68 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 69 | onInterestLoop(Face& inFace, const Interest& interest, |
| 70 | shared_ptr<pit::Entry> pitEntry); |
| 71 | |
| 72 | /** \brief outgoing Interest pipeline |
| 73 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 74 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 75 | onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace); |
| 76 | |
| 77 | /** \brief Interest rebuff pipeline |
| 78 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 79 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 80 | onInterestRebuff(shared_ptr<pit::Entry> pitEntry); |
| 81 | |
| 82 | /** \brief Interest unsatisfied pipeline |
| 83 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 84 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 85 | onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry); |
| 86 | |
| 87 | /** \brief incoming Data pipeline |
| 88 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 89 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 90 | onIncomingData(Face& inFace, const Data& data); |
| 91 | |
| 92 | /** \brief Data unsolicited pipeline |
| 93 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 94 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 95 | onDataUnsolicited(Face& inFace, const Data& data); |
| 96 | |
| 97 | /** \brief outgoing Data pipeline |
| 98 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 99 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 100 | onOutgoingData(const Data& data, Face& outFace); |
| 101 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 102 | PROTECTED_WITH_TESTS_ELSE_PRIVATE: |
| 103 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 104 | setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry); |
| 105 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 106 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 107 | setStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
| 108 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 109 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 110 | cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 111 | |
| 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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | Scheduler m_scheduler; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 120 | |
| 121 | FaceId m_lastFaceId; |
| 122 | std::map<FaceId, shared_ptr<Face> > m_faces; |
| 123 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame^] | 124 | Fib m_fib; |
| 125 | Pit m_pit; |
| 126 | Cs m_cs; |
| 127 | Measurements m_measurements; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 128 | /// the active strategy (only one strategy in mock) |
| 129 | shared_ptr<fw::Strategy> m_strategy; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 130 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 131 | static const Name s_localhostName; |
| 132 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 133 | // allow Strategy (base class) to enter pipelines |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 134 | friend class fw::Strategy; |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 135 | }; |
| 136 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 137 | inline Fib& |
| 138 | Forwarder::getFib() |
| 139 | { |
| 140 | return m_fib; |
| 141 | } |
| 142 | |
| 143 | inline Pit& |
| 144 | Forwarder::getPit() |
| 145 | { |
| 146 | return m_pit; |
| 147 | } |
| 148 | |
| 149 | inline Cs& |
| 150 | Forwarder::getCs() |
| 151 | { |
| 152 | return m_cs; |
| 153 | } |
| 154 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame^] | 155 | inline Measurements& |
| 156 | Forwarder::getMeasurements() |
| 157 | { |
| 158 | return m_measurements; |
| 159 | } |
| 160 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 161 | } // namespace nfd |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 162 | |
| 163 | #endif // NFD_FW_FORWARDER_HPP |