blob: 857592bd244830604ea8902ecbcee3200035f54f [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/*
ashiqopuc7079482019-02-20 05:34:37 +00003 * Copyright (c) 2014-2019, 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 Pesaventoc0822fa2018-05-10 21:54:10 -040031#include "core/rtt-estimator.hpp"
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070032
33namespace nfd {
34namespace fw {
35
36/** \brief Access Router Strategy version 1
37 *
38 * This strategy is designed for the last hop on the NDN testbed,
39 * where each nexthop connects to a laptop, links are lossy, and FIB is mostly correct.
40 *
41 * 1. Multicast the first Interest to all nexthops.
42 * 2. When Data comes back, remember last working nexthop of the prefix;
43 * the granularity of this knowledge is the parent of Data Name.
44 * 3. Forward subsequent Interests to the last working nexthop.
45 * If it doesn't respond, multicast again.
ashiqopuc7079482019-02-20 05:34:37 +000046 *
47 * \note This strategy is not EndpointId-aware.
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070048 */
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
ashiqopuc7079482019-02-20 05:34:37 +000060 afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
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
Junxiao Shi15e98b02016-08-12 11:21:44 +000064 beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
ashiqopuc7079482019-02-20 05:34:37 +000065 const FaceEndpoint& ingress, const Data& data) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070066
67private: // StrategyInfo
68 /** \brief StrategyInfo on PIT entry
69 */
70 class PitInfo : public StrategyInfo
71 {
72 public:
73 static constexpr int
74 getTypeId()
75 {
76 return 1010;
77 }
78
79 public:
80 scheduler::ScopedEventId rtoTimer;
81 };
82
83 /** \brief StrategyInfo in measurements table
84 */
85 class MtInfo : public StrategyInfo
86 {
87 public:
88 static constexpr int
89 getTypeId()
90 {
91 return 1011;
92 }
93
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070094 public:
Davide Pesavento17c172b2019-03-23 15:11:44 -040095 FaceId lastNexthop = face::INVALID_FACEID;
96 RttEstimator rtt{1, 1_ms, 0.1};
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070097 };
98
99 /** \brief find per-prefix measurements for Interest
100 */
Junxiao Shifc021862016-08-25 21:51:18 +0000101 std::tuple<Name, MtInfo*>
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700102 findPrefixMeasurements(const pit::Entry& pitEntry);
103
104 /** \brief get or create pre-prefix measurements for incoming Data
105 * \note This function creates MtInfo but doesn't update it.
106 */
Junxiao Shifc021862016-08-25 21:51:18 +0000107 MtInfo*
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700108 addPrefixMeasurements(const Data& data);
109
110 /** \brief global per-face StrategyInfo
111 */
Davide Pesavento17c172b2019-03-23 15:11:44 -0400112 struct FaceInfo
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700113 {
Davide Pesavento17c172b2019-03-23 15:11:44 -0400114 RttEstimator rtt{1, 1_ms, 0.1};
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700115 };
116
117 typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
118
119 void
Junxiao Shiae04d342016-07-19 13:20:22 +0000120 removeFaceInfo(const Face& face);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700121
122private: // forwarding procedures
123 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400124 afterReceiveNewInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000125 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700126
127 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400128 afterReceiveRetxInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000129 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700130
131 /** \brief send to last working nexthop
132 * \return whether an Interest is sent
133 */
134 bool
Davide Pesavento17c172b2019-03-23 15:11:44 -0400135 sendToLastNexthop(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shia7f9a292016-11-22 16:31:38 +0000136 const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000137 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700138
139 void
Davide Pesavento17c172b2019-03-23 15:11:44 -0400140 afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak,
141 FaceId inFaceId, EndpointId inEndpointId, FaceId firstOutFaceId);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700142
143 /** \brief multicast to all nexthops
Junxiao Shia7f9a292016-11-22 16:31:38 +0000144 * \param exceptFace don't forward to this face; also, inFace is always excluded
145 * \return how many Interests are sent
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700146 */
Davide Pesavento17c172b2019-03-23 15:11:44 -0400147 size_t
Junxiao Shia7f9a292016-11-22 16:31:38 +0000148 multicast(const Face& inFace, const Interest& interest,
149 const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
150 FaceId exceptFace = face::INVALID_FACEID);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700151
152 void
153 updateMeasurements(const Face& inFace, const Data& data,
154 const RttEstimator::Duration& rtt);
155
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700156private:
157 FaceInfoTable m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700158 RetxSuppressionFixed m_retxSuppression;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700159 signal::ScopedConnection m_removeFaceInfoConn;
160};
161
162} // namespace fw
163} // namespace nfd
164
165#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP