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