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