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