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