Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c0822fa | 2018-05-10 21:54:10 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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" |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 30 | #include "retx-suppression-fixed.hpp" |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 31 | |
| 32 | #include <ndn-cxx/util/rtt-estimator.hpp> |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace fw { |
| 36 | |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 37 | /** \brief Access Router strategy |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 38 | * |
| 39 | * This strategy is designed for the last hop on the NDN testbed, |
| 40 | * where each nexthop connects to a laptop, links are lossy, and FIB is mostly correct. |
| 41 | * |
| 42 | * 1. Multicast the first Interest to all nexthops. |
| 43 | * 2. When Data comes back, remember last working nexthop of the prefix; |
| 44 | * the granularity of this knowledge is the parent of Data Name. |
| 45 | * 3. Forward subsequent Interests to the last working nexthop. |
| 46 | * If it doesn't respond, multicast again. |
| 47 | */ |
| 48 | class AccessStrategy : public Strategy |
| 49 | { |
| 50 | public: |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 51 | explicit |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 52 | AccessStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
| 53 | |
| 54 | static const Name& |
| 55 | getStrategyName(); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 57 | public: // triggers |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 58 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 59 | afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 60 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 61 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 62 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 63 | beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 64 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 65 | |
| 66 | private: // StrategyInfo |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 67 | using RttEstimator = ndn::util::RttEstimator; |
| 68 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 69 | /** \brief StrategyInfo on PIT entry |
| 70 | */ |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 71 | class PitInfo final : public StrategyInfo |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 72 | { |
| 73 | public: |
| 74 | static constexpr int |
| 75 | getTypeId() |
| 76 | { |
| 77 | return 1010; |
| 78 | } |
| 79 | |
| 80 | public: |
| 81 | scheduler::ScopedEventId rtoTimer; |
| 82 | }; |
| 83 | |
| 84 | /** \brief StrategyInfo in measurements table |
| 85 | */ |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 86 | class MtInfo final : public StrategyInfo |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 87 | { |
| 88 | public: |
| 89 | static constexpr int |
| 90 | getTypeId() |
| 91 | { |
| 92 | return 1011; |
| 93 | } |
| 94 | |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 95 | explicit |
| 96 | MtInfo(shared_ptr<const RttEstimator::Options> opts) |
| 97 | : rtt(std::move(opts)) |
| 98 | { |
| 99 | } |
| 100 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 101 | public: |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 102 | FaceId lastNexthop = face::INVALID_FACEID; |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 103 | RttEstimator rtt; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | /** \brief find per-prefix measurements for Interest |
| 107 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 108 | std::tuple<Name, MtInfo*> |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 109 | findPrefixMeasurements(const pit::Entry& pitEntry); |
| 110 | |
| 111 | /** \brief get or create pre-prefix measurements for incoming Data |
| 112 | * \note This function creates MtInfo but doesn't update it. |
| 113 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 114 | MtInfo* |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 115 | addPrefixMeasurements(const Data& data); |
| 116 | |
| 117 | /** \brief global per-face StrategyInfo |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 118 | * \todo Currently stored inside AccessStrategy instance; should be moved |
| 119 | * to measurements table or somewhere else. |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 120 | */ |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 121 | class FaceInfo |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 122 | { |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 123 | public: |
| 124 | explicit |
| 125 | FaceInfo(shared_ptr<const RttEstimator::Options> opts) |
| 126 | : rtt(std::move(opts)) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | public: |
| 131 | RttEstimator rtt; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 134 | private: // forwarding procedures |
| 135 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 136 | afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 137 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 138 | |
| 139 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 140 | afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 141 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 142 | |
| 143 | /** \brief send to last working nexthop |
| 144 | * \return whether an Interest is sent |
| 145 | */ |
| 146 | bool |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 147 | sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 148 | const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi, |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 149 | const fib::Entry& fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 150 | |
| 151 | void |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 152 | afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak, |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 153 | FaceId inFaceId, FaceId firstOutFaceId); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 154 | |
| 155 | /** \brief multicast to all nexthops |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 156 | * \param exceptFace don't forward to this face; also, \p inFace is always excluded |
| 157 | * \return number of Interests that were sent |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 158 | */ |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 159 | size_t |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame^] | 160 | multicast(const Interest& interest, const Face& inFace, |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 161 | const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry, |
| 162 | FaceId exceptFace = face::INVALID_FACEID); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 163 | |
| 164 | void |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 165 | updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 166 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 167 | private: |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 168 | const shared_ptr<const RttEstimator::Options> m_rttEstimatorOpts; |
| 169 | std::unordered_map<FaceId, FaceInfo> m_fit; |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 170 | RetxSuppressionFixed m_retxSuppression; |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 171 | signal::ScopedConnection m_removeFaceConn; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | } // namespace fw |
| 175 | } // namespace nfd |
| 176 | |
| 177 | #endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |