blob: 324fea889a923aa46ace347a1edbc07f3debf17e [file] [log] [blame]
Junxiao Shi80ee7cb2014-12-14 10:53:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc0822fa2018-05-10 21:54:10 -04002/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Junxiao Shi80ee7cb2014-12-14 10:53:05 -07004 * 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 Shia788e252015-01-28 17:06:25 -070030#include "retx-suppression-fixed.hpp"
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040031
32#include <ndn-cxx/util/rtt-estimator.hpp>
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070033
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040034#include <unordered_map>
35
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036namespace nfd::fw {
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070037
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040038/**
39 * \brief A forwarding strategy for "access" routers.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070040 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040041 * 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 Shi80ee7cb2014-12-14 10:53:05 -070043 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040044 * 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 Shi80ee7cb2014-12-14 10:53:05 -070049 */
50class AccessStrategy : public Strategy
51{
52public:
Junxiao Shi15e98b02016-08-12 11:21:44 +000053 explicit
Junxiao Shi037f4ab2016-12-13 04:27:06 +000054 AccessStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
55
56 static const Name&
57 getStrategyName();
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070058
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070059public: // triggers
Eric Newberry185ab292017-03-28 06:45:39 +000060 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040061 afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000062 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070063
Eric Newberry185ab292017-03-28 06:45:39 +000064 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040065 beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
66 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070067
68private: // StrategyInfo
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040069 using RttEstimator = ndn::util::RttEstimator;
70
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040071 /** \brief StrategyInfo on PIT entry.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070072 */
Davide Pesavento3db98072021-03-09 23:03:27 -050073 class PitInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070074 {
75 public:
76 static constexpr int
77 getTypeId()
78 {
79 return 1010;
80 }
81
82 public:
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050083 ndn::scheduler::ScopedEventId rtoTimer;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070084 };
85
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040086 /** \brief StrategyInfo in measurements table.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070087 */
Davide Pesavento3db98072021-03-09 23:03:27 -050088 class MtInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070089 {
90 public:
91 static constexpr int
92 getTypeId()
93 {
94 return 1011;
95 }
96
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040097 explicit
98 MtInfo(shared_ptr<const RttEstimator::Options> opts)
99 : rtt(std::move(opts))
100 {
101 }
102
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700103 public:
Davide Pesavento17c172b2019-03-23 15:11:44 -0400104 FaceId lastNexthop = face::INVALID_FACEID;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400105 RttEstimator rtt;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700106 };
107
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400108 /** \brief Find per-prefix measurements for Interest.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700109 */
Junxiao Shifc021862016-08-25 21:51:18 +0000110 std::tuple<Name, MtInfo*>
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700111 findPrefixMeasurements(const pit::Entry& pitEntry);
112
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400113 /** \brief Get or create pre-prefix measurements for incoming Data.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700114 * \note This function creates MtInfo but doesn't update it.
115 */
Junxiao Shifc021862016-08-25 21:51:18 +0000116 MtInfo*
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700117 addPrefixMeasurements(const Data& data);
118
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400119 /** \brief Global per-face StrategyInfo.
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400120 * \todo Currently stored inside AccessStrategy instance; should be moved
121 * to measurements table or somewhere else.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700122 */
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400123 class FaceInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700124 {
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400125 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 Shi80ee7cb2014-12-14 10:53:05 -0700134 };
135
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700136private: // forwarding procedures
137 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400138 afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000139 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700140
141 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400142 afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000143 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700144
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400145 /** \brief Send to last working nexthop.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700146 * \return whether an Interest is sent
147 */
148 bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400149 sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000150 const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000151 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700152
153 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400154 afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak,
Teng Liangebc20f62020-06-23 16:55:20 -0700155 FaceId inFaceId, FaceId firstOutFaceId);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700156
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400157 /** \brief Multicast to all nexthops.
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400158 * \param exceptFace don't forward to this face; also, \p inFace is always excluded
159 * \return number of Interests that were sent
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700160 */
Davide Pesavento17c172b2019-03-23 15:11:44 -0400161 size_t
Davide Pesavento0498ce82021-06-14 02:02:21 -0400162 multicast(const Interest& interest, const Face& inFace,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000163 const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
164 FaceId exceptFace = face::INVALID_FACEID);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700165
166 void
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400167 updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700168
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700169private:
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400170 const shared_ptr<const RttEstimator::Options> m_rttEstimatorOpts;
171 std::unordered_map<FaceId, FaceInfo> m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700172 RetxSuppressionFixed m_retxSuppression;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400173 signal::ScopedConnection m_removeFaceConn;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700174};
175
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400176} // namespace nfd::fw
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700177
178#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP