blob: ca7a2e33756070e4b9f891ca66e78a72edee44a0 [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,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020061 shared_ptr<pit::Entry> pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070062
63 virtual void
64 beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020065 const Face& inFace, 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
94 MtInfo();
95
96 public:
97 FaceId lastNexthop;
98 RttEstimator rtt;
99 };
100
101 /** \brief find per-prefix measurements for Interest
102 */
103 std::tuple<Name, shared_ptr<MtInfo>>
104 findPrefixMeasurements(const pit::Entry& pitEntry);
105
106 /** \brief get or create pre-prefix measurements for incoming Data
107 * \note This function creates MtInfo but doesn't update it.
108 */
109 shared_ptr<MtInfo>
110 addPrefixMeasurements(const Data& data);
111
112 /** \brief global per-face StrategyInfo
113 */
114 class FaceInfo
115 {
116 public:
117 FaceInfo();
118
119 public:
120 RttEstimator rtt;
121 };
122
123 typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
124
125 void
126 removeFaceInfo(shared_ptr<Face> face);
127
128private: // forwarding procedures
129 void
130 afterReceiveNewInterest(const Face& inFace,
131 const Interest& interest,
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700132 shared_ptr<pit::Entry> pitEntry);
133
134 void
135 afterReceiveRetxInterest(const Face& inFace,
136 const Interest& interest,
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700137 shared_ptr<pit::Entry> pitEntry);
138
139 /** \brief send to last working nexthop
140 * \return whether an Interest is sent
141 */
142 bool
143 sendToLastNexthop(const Face& inFace, shared_ptr<pit::Entry> pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000144 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700145
146 void
Junxiao Shi8d843142016-07-11 22:42:42 +0000147 afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, FaceId inFace, FaceId firstOutFace);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700148
149 /** \brief multicast to all nexthops
150 * \param exceptFaces don't forward to those faces
151 */
152 void
153 multicast(shared_ptr<pit::Entry> pitEntry,
Junxiao Shi8d843142016-07-11 22:42:42 +0000154 const fib::Entry& fibEntry,
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700155 std::unordered_set<FaceId> exceptFaces = std::unordered_set<FaceId>());
156
157 void
158 updateMeasurements(const Face& inFace, const Data& data,
159 const RttEstimator::Duration& rtt);
160
161public:
162 static const Name STRATEGY_NAME;
163
164private:
165 FaceInfoTable m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700166 RetxSuppressionFixed m_retxSuppression;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700167 signal::ScopedConnection m_removeFaceInfoConn;
168};
169
170} // namespace fw
171} // namespace nfd
172
173#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP