blob: edcf63b41ded33e24373c7813bc1ce7ad2e351d5 [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 Pesavento58091582021-03-05 19:02:48 -05003 * Copyright (c) 2014-2021, 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
34namespace nfd {
35namespace fw {
36
Davide Pesavento58091582021-03-05 19:02:48 -050037/** \brief Access Router strategy
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070038 *
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 */
48class AccessStrategy : public Strategy
49{
50public:
Junxiao Shi15e98b02016-08-12 11:21:44 +000051 explicit
Junxiao Shi037f4ab2016-12-13 04:27:06 +000052 AccessStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
53
54 static const Name&
55 getStrategyName();
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070056
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070057public: // triggers
Eric Newberry185ab292017-03-28 06:45:39 +000058 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040059 afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000060 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070061
Eric Newberry185ab292017-03-28 06:45:39 +000062 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040063 beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
64 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070065
66private: // StrategyInfo
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040067 using RttEstimator = ndn::util::RttEstimator;
68
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070069 /** \brief StrategyInfo on PIT entry
70 */
Davide Pesavento3db98072021-03-09 23:03:27 -050071 class PitInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070072 {
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 Pesavento3db98072021-03-09 23:03:27 -050086 class MtInfo final : public StrategyInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070087 {
88 public:
89 static constexpr int
90 getTypeId()
91 {
92 return 1011;
93 }
94
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -040095 explicit
96 MtInfo(shared_ptr<const RttEstimator::Options> opts)
97 : rtt(std::move(opts))
98 {
99 }
100
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700101 public:
Davide Pesavento17c172b2019-03-23 15:11:44 -0400102 FaceId lastNexthop = face::INVALID_FACEID;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400103 RttEstimator rtt;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700104 };
105
106 /** \brief find per-prefix measurements for Interest
107 */
Junxiao Shifc021862016-08-25 21:51:18 +0000108 std::tuple<Name, MtInfo*>
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700109 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 Shifc021862016-08-25 21:51:18 +0000114 MtInfo*
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700115 addPrefixMeasurements(const Data& data);
116
117 /** \brief global per-face StrategyInfo
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400118 * \todo Currently stored inside AccessStrategy instance; should be moved
119 * to measurements table or somewhere else.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700120 */
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400121 class FaceInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700122 {
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400123 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 Shi80ee7cb2014-12-14 10:53:05 -0700132 };
133
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700134private: // forwarding procedures
135 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400136 afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000137 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700138
139 void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400140 afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000141 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700142
143 /** \brief send to last working nexthop
144 * \return whether an Interest is sent
145 */
146 bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400147 sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000148 const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000149 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700150
151 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400152 afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak,
Teng Liangebc20f62020-06-23 16:55:20 -0700153 FaceId inFaceId, FaceId firstOutFaceId);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700154
155 /** \brief multicast to all nexthops
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400156 * \param exceptFace don't forward to this face; also, \p inFace is always excluded
157 * \return number of Interests that were sent
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700158 */
Davide Pesavento17c172b2019-03-23 15:11:44 -0400159 size_t
Davide Pesavento0498ce82021-06-14 02:02:21 -0400160 multicast(const Interest& interest, const Face& inFace,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000161 const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
162 FaceId exceptFace = face::INVALID_FACEID);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700163
164 void
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400165 updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700166
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700167private:
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400168 const shared_ptr<const RttEstimator::Options> m_rttEstimatorOpts;
169 std::unordered_map<FaceId, FaceInfo> m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700170 RetxSuppressionFixed m_retxSuppression;
Davide Pesaventoeb7b7ab2019-08-14 19:00:15 -0400171 signal::ScopedConnection m_removeFaceConn;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700172};
173
174} // namespace fw
175} // namespace nfd
176
177#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP