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