blob: c33ad5c9851382a8e2a65d95408dd98baecf1202 [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 Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, 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 Pesavento58091582021-03-05 19:02:48 -050038/** \brief Access Router strategy
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070039 *
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 */
49class AccessStrategy : public Strategy
50{
51public:
Junxiao Shi15e98b02016-08-12 11:21:44 +000052 explicit
Junxiao Shi037f4ab2016-12-13 04:27:06 +000053 AccessStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
54
55 static const Name&
56 getStrategyName();
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070057
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070058public: // triggers
Eric Newberry185ab292017-03-28 06:45:39 +000059 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040060 afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000061 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070062
Eric Newberry185ab292017-03-28 06:45:39 +000063 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040064 beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
65 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070066
67private: // StrategyInfo
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040068 using RttEstimator = ndn::util::RttEstimator;
69
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070070 /** \brief StrategyInfo on PIT entry
71 */
Davide Pesavento3db98072021-03-09 23:03:27 -050072 class PitInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070073 {
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 Pesavento3db98072021-03-09 23:03:27 -050087 class MtInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070088 {
89 public:
90 static constexpr int
91 getTypeId()
92 {
93 return 1011;
94 }
95
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040096 explicit
97 MtInfo(shared_ptr<const RttEstimator::Options> opts)
98 : rtt(std::move(opts))
99 {
100 }
101
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700102 public:
Davide Pesavento17c172b2019-03-23 15:11:44 -0400103 FaceId lastNexthop = face::INVALID_FACEID;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400104 RttEstimator rtt;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700105 };
106
107 /** \brief find per-prefix measurements for Interest
108 */
Junxiao Shifc021862016-08-25 21:51:18 +0000109 std::tuple<Name, MtInfo*>
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700110 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 Shifc021862016-08-25 21:51:18 +0000115 MtInfo*
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700116 addPrefixMeasurements(const Data& data);
117
118 /** \brief global per-face StrategyInfo
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400119 * \todo Currently stored inside AccessStrategy instance; should be moved
120 * to measurements table or somewhere else.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700121 */
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400122 class FaceInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700123 {
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400124 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 Shi80ee7cb2014-12-14 10:53:05 -0700133 };
134
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700135private: // forwarding procedures
136 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400137 afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000138 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700139
140 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400141 afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000142 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700143
144 /** \brief send to last working nexthop
145 * \return whether an Interest is sent
146 */
147 bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400148 sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000149 const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000150 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700151
152 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400153 afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak,
Teng Liangebc20f62020-06-23 16:55:20 -0700154 FaceId inFaceId, FaceId firstOutFaceId);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700155
156 /** \brief multicast to all nexthops
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400157 * \param exceptFace don't forward to this face; also, \p inFace is always excluded
158 * \return number of Interests that were sent
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700159 */
Davide Pesavento17c172b2019-03-23 15:11:44 -0400160 size_t
Davide Pesavento0498ce82021-06-14 02:02:21 -0400161 multicast(const Interest& interest, const Face& inFace,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000162 const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
163 FaceId exceptFace = face::INVALID_FACEID);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700164
165 void
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400166 updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700167
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700168private:
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400169 const shared_ptr<const RttEstimator::Options> m_rttEstimatorOpts;
170 std::unordered_map<FaceId, FaceInfo> m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700171 RetxSuppressionFixed m_retxSuppression;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400172 signal::ScopedConnection m_removeFaceConn;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700173};
174
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400175} // namespace nfd::fw
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700176
177#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP