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: |
| 28 | Forwarder(boost::asio::io_service& ioService); |
| 29 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 30 | void |
| 31 | addFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 32 | |
| 33 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 34 | removeFace(shared_ptr<Face> face); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 35 | |
| 36 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | onInterest(Face& face, const Interest& interest); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 38 | |
| 39 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 40 | onData(Face& face, const Data& data); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 41 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 42 | public: |
| 43 | Fib& |
| 44 | getFib(); |
| 45 | |
| 46 | Pit& |
| 47 | getPit(); |
| 48 | |
| 49 | Cs& |
| 50 | getCs(); |
| 51 | |
Steve DiBenedetto | 26b730f | 2014-02-02 18:36:16 -0700 | [diff] [blame] | 52 | shared_ptr<Face> |
| 53 | getFace(FaceId id); |
| 54 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 55 | private: // pipelines |
| 56 | /** \brief incoming Interest pipeline |
| 57 | */ |
| 58 | void |
| 59 | onIncomingInterest(Face& inFace, const Interest& interest); |
| 60 | |
| 61 | /** \brief Interest loop pipeline |
| 62 | */ |
| 63 | void |
| 64 | onInterestLoop(Face& inFace, const Interest& interest, |
| 65 | shared_ptr<pit::Entry> pitEntry); |
| 66 | |
| 67 | /** \brief outgoing Interest pipeline |
| 68 | */ |
| 69 | void |
| 70 | onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace); |
| 71 | |
| 72 | /** \brief Interest rebuff pipeline |
| 73 | */ |
| 74 | void |
| 75 | onInterestRebuff(shared_ptr<pit::Entry> pitEntry); |
| 76 | |
| 77 | /** \brief Interest unsatisfied pipeline |
| 78 | */ |
| 79 | void |
| 80 | onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry); |
| 81 | |
| 82 | /** \brief incoming Data pipeline |
| 83 | */ |
| 84 | void |
| 85 | onIncomingData(Face& inFace, const Data& data); |
| 86 | |
| 87 | /** \brief Data unsolicited pipeline |
| 88 | */ |
| 89 | void |
| 90 | onDataUnsolicited(Face& inFace, const Data& data); |
| 91 | |
| 92 | /** \brief outgoing Data pipeline |
| 93 | */ |
| 94 | void |
| 95 | onOutgoingData(const Data& data, Face& outFace); |
| 96 | |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 97 | private: |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 98 | void |
| 99 | setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry); |
| 100 | |
| 101 | void |
| 102 | setStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
| 103 | |
| 104 | void |
| 105 | cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry); |
| 106 | |
| 107 | private: |
| 108 | Scheduler m_scheduler; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 109 | |
| 110 | FaceId m_lastFaceId; |
| 111 | std::map<FaceId, shared_ptr<Face> > m_faces; |
| 112 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 113 | Fib m_fib; |
| 114 | Pit m_pit; |
| 115 | Cs m_cs; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 116 | /// the active strategy (only one strategy in mock) |
| 117 | shared_ptr<fw::Strategy> m_strategy; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 118 | |
| 119 | // allow Strategy (base class) to enter pipelines |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 120 | friend class fw::Strategy; |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 123 | inline Fib& |
| 124 | Forwarder::getFib() |
| 125 | { |
| 126 | return m_fib; |
| 127 | } |
| 128 | |
| 129 | inline Pit& |
| 130 | Forwarder::getPit() |
| 131 | { |
| 132 | return m_pit; |
| 133 | } |
| 134 | |
| 135 | inline Cs& |
| 136 | Forwarder::getCs() |
| 137 | { |
| 138 | return m_cs; |
| 139 | } |
| 140 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 141 | } // namespace nfd |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 142 | |
| 143 | #endif // NFD_FW_FORWARDER_HPP |