blob: 2df13ad16fb41b8ef8dac97d41124b7a8322caee [file] [log] [blame]
Junxiao Shi80ee7cb2014-12-14 10:53:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventob84bd3a2016-04-22 02:21:45 +02003 * Copyright (c) 2014-2016, 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"
30#include "rtt-estimator.hpp"
Junxiao Shia788e252015-01-28 17:06:25 -070031#include "retx-suppression-fixed.hpp"
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070032#include <unordered_set>
33#include <unordered_map>
34
35namespace nfd {
36namespace fw {
37
38/** \brief Access Router Strategy version 1
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 */
49class AccessStrategy : public Strategy
50{
51public:
52 AccessStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
53
54 virtual
55 ~AccessStrategy();
56
57public: // triggers
58 virtual void
59 afterReceiveInterest(const Face& inFace,
60 const Interest& interest,
61 shared_ptr<fib::Entry> fibEntry,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020062 shared_ptr<pit::Entry> pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070063
64 virtual void
65 beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020066 const Face& inFace, const Data& data) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070067
68private: // StrategyInfo
69 /** \brief StrategyInfo on PIT entry
70 */
71 class PitInfo : public StrategyInfo
72 {
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 */
86 class MtInfo : public StrategyInfo
87 {
88 public:
89 static constexpr int
90 getTypeId()
91 {
92 return 1011;
93 }
94
95 MtInfo();
96
97 public:
98 FaceId lastNexthop;
99 RttEstimator rtt;
100 };
101
102 /** \brief find per-prefix measurements for Interest
103 */
104 std::tuple<Name, shared_ptr<MtInfo>>
105 findPrefixMeasurements(const pit::Entry& pitEntry);
106
107 /** \brief get or create pre-prefix measurements for incoming Data
108 * \note This function creates MtInfo but doesn't update it.
109 */
110 shared_ptr<MtInfo>
111 addPrefixMeasurements(const Data& data);
112
113 /** \brief global per-face StrategyInfo
114 */
115 class FaceInfo
116 {
117 public:
118 FaceInfo();
119
120 public:
121 RttEstimator rtt;
122 };
123
124 typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
125
126 void
127 removeFaceInfo(shared_ptr<Face> face);
128
129private: // forwarding procedures
130 void
131 afterReceiveNewInterest(const Face& inFace,
132 const Interest& interest,
133 shared_ptr<fib::Entry> fibEntry,
134 shared_ptr<pit::Entry> pitEntry);
135
136 void
137 afterReceiveRetxInterest(const Face& inFace,
138 const Interest& interest,
139 shared_ptr<fib::Entry> fibEntry,
140 shared_ptr<pit::Entry> pitEntry);
141
142 /** \brief send to last working nexthop
143 * \return whether an Interest is sent
144 */
145 bool
146 sendToLastNexthop(const Face& inFace, shared_ptr<pit::Entry> pitEntry, MtInfo& mi,
147 shared_ptr<fib::Entry> fibEntry);
148
149 void
150 afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, weak_ptr<fib::Entry> fibWeak,
151 FaceId inFace, FaceId firstOutFace);
152
153 /** \brief multicast to all nexthops
154 * \param exceptFaces don't forward to those faces
155 */
156 void
157 multicast(shared_ptr<pit::Entry> pitEntry,
158 shared_ptr<fib::Entry> fibEntry,
159 std::unordered_set<FaceId> exceptFaces = std::unordered_set<FaceId>());
160
161 void
162 updateMeasurements(const Face& inFace, const Data& data,
163 const RttEstimator::Duration& rtt);
164
165public:
166 static const Name STRATEGY_NAME;
167
168private:
169 FaceInfoTable m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700170 RetxSuppressionFixed m_retxSuppression;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700171 signal::ScopedConnection m_removeFaceInfoConn;
172};
173
174} // namespace fw
175} // namespace nfd
176
177#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP