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