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" |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 12 | #include "forwarder-counter.hpp" |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 13 | #include "face-table.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 14 | #include "table/fib.hpp" |
| 15 | #include "table/pit.hpp" |
| 16 | #include "table/cs.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 17 | #include "table/measurements.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 18 | #include "table/strategy-choice.hpp" |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 20 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 21 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 22 | namespace fw { |
| 23 | class Strategy; |
| 24 | } // namespace fw |
| 25 | |
| 26 | /** \brief main class of NFD |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 27 | * |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 28 | * Forwarder owns all faces and tables, and implements forwarding pipelines. |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 29 | */ |
| 30 | class Forwarder |
| 31 | { |
| 32 | public: |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 33 | Forwarder(); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 34 | |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 35 | const ForwarderCounters& |
| 36 | getCounters() const; |
| 37 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 38 | public: // faces |
| 39 | FaceTable& |
| 40 | getFaceTable(); |
| 41 | |
| 42 | /** \brief get existing Face |
| 43 | * |
| 44 | * shortcut to .getFaceTable().get(face) |
| 45 | */ |
| 46 | shared_ptr<Face> |
| 47 | getFace(FaceId id) const; |
| 48 | |
| 49 | /** \brief add new Face |
| 50 | * |
| 51 | * shortcut to .getFaceTable().add(face) |
| 52 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 53 | void |
| 54 | addFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 55 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 56 | /** \brief remove existing Face |
| 57 | * |
| 58 | * shortcut to .getFaceTable().remove(face) |
| 59 | */ |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 60 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 61 | removeFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 62 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 63 | public: // forwarding entrypoints and tables |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 64 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 65 | onInterest(Face& face, const Interest& interest); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 66 | |
| 67 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 68 | onData(Face& face, const Data& data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 70 | Fib& |
| 71 | getFib(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 73 | Pit& |
| 74 | getPit(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 76 | Cs& |
| 77 | getCs(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 79 | Measurements& |
| 80 | getMeasurements(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 82 | StrategyChoice& |
| 83 | getStrategyChoice(); |
| 84 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 85 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 86 | /** \brief incoming Interest pipeline |
| 87 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 88 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 89 | onIncomingInterest(Face& inFace, const Interest& interest); |
| 90 | |
| 91 | /** \brief Interest loop pipeline |
| 92 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 93 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 94 | onInterestLoop(Face& inFace, const Interest& interest, |
| 95 | shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 96 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 97 | /** \brief outgoing Interest 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 | onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 101 | |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 102 | /** \brief Interest reject pipeline |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 103 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 104 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 105 | onInterestReject(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 106 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 107 | /** \brief Interest unsatisfied pipeline |
| 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 | onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 111 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 112 | /** \brief incoming Data pipeline |
| 113 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 114 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 115 | onIncomingData(Face& inFace, const Data& data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 116 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 117 | /** \brief Data unsolicited pipeline |
| 118 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 119 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 120 | onDataUnsolicited(Face& inFace, const Data& data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 121 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 122 | /** \brief outgoing Data pipeline |
| 123 | */ |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 124 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 125 | onOutgoingData(const Data& data, Face& outFace); |
| 126 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 127 | PROTECTED_WITH_TESTS_ELSE_PRIVATE: |
| 128 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 129 | setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 130 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 131 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 132 | setStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 133 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 134 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 135 | cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 136 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 137 | /// call trigger (method) on the effective strategy of pitEntry |
| 138 | #ifdef WITH_TESTS |
| 139 | virtual void |
| 140 | dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger); |
| 141 | #else |
| 142 | template<class Function> |
| 143 | void |
| 144 | dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger); |
| 145 | #endif |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 146 | |
| 147 | private: |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 148 | ForwarderCounters m_counters; |
| 149 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 150 | FaceTable m_faceTable; |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 151 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 152 | // tables |
| 153 | NameTree m_nameTree; |
| 154 | Fib m_fib; |
| 155 | Pit m_pit; |
| 156 | Cs m_cs; |
| 157 | Measurements m_measurements; |
| 158 | StrategyChoice m_strategyChoice; |
| 159 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 160 | static const Name LOCALHOST_NAME; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 161 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 162 | // allow Strategy (base class) to enter pipelines |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 163 | friend class fw::Strategy; |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 164 | }; |
| 165 | |
Junxiao Shi | b289cc1 | 2014-03-15 12:19:05 -0700 | [diff] [blame] | 166 | inline const ForwarderCounters& |
| 167 | Forwarder::getCounters() const |
| 168 | { |
| 169 | return m_counters; |
| 170 | } |
| 171 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 172 | inline FaceTable& |
| 173 | Forwarder::getFaceTable() |
| 174 | { |
| 175 | return m_faceTable; |
| 176 | } |
| 177 | |
| 178 | inline shared_ptr<Face> |
| 179 | Forwarder::getFace(FaceId id) const |
| 180 | { |
| 181 | return m_faceTable.get(id); |
| 182 | } |
| 183 | |
| 184 | inline void |
| 185 | Forwarder::addFace(shared_ptr<Face> face) |
| 186 | { |
| 187 | m_faceTable.add(face); |
| 188 | } |
| 189 | |
| 190 | inline void |
| 191 | Forwarder::removeFace(shared_ptr<Face> face) |
| 192 | { |
| 193 | m_faceTable.remove(face); |
| 194 | } |
| 195 | |
| 196 | inline void |
| 197 | Forwarder::onInterest(Face& face, const Interest& interest) |
| 198 | { |
| 199 | this->onIncomingInterest(face, interest); |
| 200 | } |
| 201 | |
| 202 | inline void |
| 203 | Forwarder::onData(Face& face, const Data& data) |
| 204 | { |
| 205 | this->onIncomingData(face, data); |
| 206 | } |
| 207 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 208 | inline Fib& |
| 209 | Forwarder::getFib() |
| 210 | { |
| 211 | return m_fib; |
| 212 | } |
| 213 | |
| 214 | inline Pit& |
| 215 | Forwarder::getPit() |
| 216 | { |
| 217 | return m_pit; |
| 218 | } |
| 219 | |
| 220 | inline Cs& |
| 221 | Forwarder::getCs() |
| 222 | { |
| 223 | return m_cs; |
| 224 | } |
| 225 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 226 | inline Measurements& |
| 227 | Forwarder::getMeasurements() |
| 228 | { |
| 229 | return m_measurements; |
| 230 | } |
| 231 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 232 | inline StrategyChoice& |
| 233 | Forwarder::getStrategyChoice() |
| 234 | { |
| 235 | return m_strategyChoice; |
| 236 | } |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 237 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 238 | #ifdef WITH_TESTS |
| 239 | inline void |
| 240 | Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger) |
| 241 | #else |
| 242 | template<class Function> |
| 243 | inline void |
| 244 | Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger) |
| 245 | #endif |
| 246 | { |
| 247 | fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry); |
| 248 | trigger(&strategy); |
| 249 | } |
| 250 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 251 | } // namespace nfd |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 252 | |
| 253 | #endif // NFD_FW_FORWARDER_HPP |