Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |
| 27 | #define NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |
| 28 | |
| 29 | #include "strategy.hpp" |
| 30 | #include "rtt-estimator.hpp" |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 31 | #include "retx-suppression-fixed.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 32 | #include <unordered_set> |
| 33 | #include <unordered_map> |
| 34 | |
| 35 | namespace nfd { |
| 36 | namespace fw { |
| 37 | |
| 38 | /** \brief Access Router Strategy version 1 |
| 39 | * |
| 40 | * This strategy is designed for the last hop on the NDN testbed, |
| 41 | * where each nexthop connects to a laptop, links are lossy, and FIB is mostly correct. |
| 42 | * |
| 43 | * 1. Multicast the first Interest to all nexthops. |
| 44 | * 2. When Data comes back, remember last working nexthop of the prefix; |
| 45 | * the granularity of this knowledge is the parent of Data Name. |
| 46 | * 3. Forward subsequent Interests to the last working nexthop. |
| 47 | * If it doesn't respond, multicast again. |
| 48 | */ |
| 49 | class AccessStrategy : public Strategy |
| 50 | { |
| 51 | public: |
| 52 | AccessStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME); |
| 53 | |
| 54 | virtual |
| 55 | ~AccessStrategy(); |
| 56 | |
| 57 | public: // triggers |
| 58 | virtual void |
| 59 | afterReceiveInterest(const Face& inFace, |
| 60 | const Interest& interest, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 61 | shared_ptr<pit::Entry> pitEntry) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 62 | |
| 63 | virtual void |
| 64 | beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 65 | const Face& inFace, const Data& data) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 66 | |
| 67 | private: // StrategyInfo |
| 68 | /** \brief StrategyInfo on PIT entry |
| 69 | */ |
| 70 | class PitInfo : public StrategyInfo |
| 71 | { |
| 72 | public: |
| 73 | static constexpr int |
| 74 | getTypeId() |
| 75 | { |
| 76 | return 1010; |
| 77 | } |
| 78 | |
| 79 | public: |
| 80 | scheduler::ScopedEventId rtoTimer; |
| 81 | }; |
| 82 | |
| 83 | /** \brief StrategyInfo in measurements table |
| 84 | */ |
| 85 | class MtInfo : public StrategyInfo |
| 86 | { |
| 87 | public: |
| 88 | static constexpr int |
| 89 | getTypeId() |
| 90 | { |
| 91 | return 1011; |
| 92 | } |
| 93 | |
| 94 | MtInfo(); |
| 95 | |
| 96 | public: |
| 97 | FaceId lastNexthop; |
| 98 | RttEstimator rtt; |
| 99 | }; |
| 100 | |
| 101 | /** \brief find per-prefix measurements for Interest |
| 102 | */ |
| 103 | std::tuple<Name, shared_ptr<MtInfo>> |
| 104 | findPrefixMeasurements(const pit::Entry& pitEntry); |
| 105 | |
| 106 | /** \brief get or create pre-prefix measurements for incoming Data |
| 107 | * \note This function creates MtInfo but doesn't update it. |
| 108 | */ |
| 109 | shared_ptr<MtInfo> |
| 110 | addPrefixMeasurements(const Data& data); |
| 111 | |
| 112 | /** \brief global per-face StrategyInfo |
| 113 | */ |
| 114 | class FaceInfo |
| 115 | { |
| 116 | public: |
| 117 | FaceInfo(); |
| 118 | |
| 119 | public: |
| 120 | RttEstimator rtt; |
| 121 | }; |
| 122 | |
| 123 | typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable; |
| 124 | |
| 125 | void |
| 126 | removeFaceInfo(shared_ptr<Face> face); |
| 127 | |
| 128 | private: // forwarding procedures |
| 129 | void |
| 130 | afterReceiveNewInterest(const Face& inFace, |
| 131 | const Interest& interest, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 132 | shared_ptr<pit::Entry> pitEntry); |
| 133 | |
| 134 | void |
| 135 | afterReceiveRetxInterest(const Face& inFace, |
| 136 | const Interest& interest, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 137 | shared_ptr<pit::Entry> pitEntry); |
| 138 | |
| 139 | /** \brief send to last working nexthop |
| 140 | * \return whether an Interest is sent |
| 141 | */ |
| 142 | bool |
| 143 | sendToLastNexthop(const Face& inFace, shared_ptr<pit::Entry> pitEntry, MtInfo& mi, |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 144 | const fib::Entry& fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 145 | |
| 146 | void |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 147 | afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, FaceId inFace, FaceId firstOutFace); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 148 | |
| 149 | /** \brief multicast to all nexthops |
| 150 | * \param exceptFaces don't forward to those faces |
| 151 | */ |
| 152 | void |
| 153 | multicast(shared_ptr<pit::Entry> pitEntry, |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 154 | const fib::Entry& fibEntry, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 155 | std::unordered_set<FaceId> exceptFaces = std::unordered_set<FaceId>()); |
| 156 | |
| 157 | void |
| 158 | updateMeasurements(const Face& inFace, const Data& data, |
| 159 | const RttEstimator::Duration& rtt); |
| 160 | |
| 161 | public: |
| 162 | static const Name STRATEGY_NAME; |
| 163 | |
| 164 | private: |
| 165 | FaceInfoTable m_fit; |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 166 | RetxSuppressionFixed m_retxSuppression; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 167 | signal::ScopedConnection m_removeFaceInfoConn; |
| 168 | }; |
| 169 | |
| 170 | } // namespace fw |
| 171 | } // namespace nfd |
| 172 | |
| 173 | #endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |