blob: b71f2c6e12ced22d173ca34efa3f28256e07aee1 [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:
Junxiao Shi15e98b02016-08-12 11:21:44 +000052 explicit
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070053 AccessStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
54
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070055public: // triggers
56 virtual void
Junxiao Shi15e98b02016-08-12 11:21:44 +000057 afterReceiveInterest(const Face& inFace, const Interest& interest,
58 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070059
60 virtual void
Junxiao Shi15e98b02016-08-12 11:21:44 +000061 beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020062 const Face& inFace, const Data& data) override;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -070063
64private: // StrategyInfo
65 /** \brief StrategyInfo on PIT entry
66 */
67 class PitInfo : public StrategyInfo
68 {
69 public:
70 static constexpr int
71 getTypeId()
72 {
73 return 1010;
74 }
75
76 public:
77 scheduler::ScopedEventId rtoTimer;
78 };
79
80 /** \brief StrategyInfo in measurements table
81 */
82 class MtInfo : public StrategyInfo
83 {
84 public:
85 static constexpr int
86 getTypeId()
87 {
88 return 1011;
89 }
90
91 MtInfo();
92
93 public:
94 FaceId lastNexthop;
95 RttEstimator rtt;
96 };
97
98 /** \brief find per-prefix measurements for Interest
99 */
100 std::tuple<Name, shared_ptr<MtInfo>>
101 findPrefixMeasurements(const pit::Entry& pitEntry);
102
103 /** \brief get or create pre-prefix measurements for incoming Data
104 * \note This function creates MtInfo but doesn't update it.
105 */
106 shared_ptr<MtInfo>
107 addPrefixMeasurements(const Data& data);
108
109 /** \brief global per-face StrategyInfo
110 */
111 class FaceInfo
112 {
113 public:
114 FaceInfo();
115
116 public:
117 RttEstimator rtt;
118 };
119
120 typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
121
122 void
Junxiao Shiae04d342016-07-19 13:20:22 +0000123 removeFaceInfo(const Face& face);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700124
125private: // forwarding procedures
126 void
Junxiao Shi15e98b02016-08-12 11:21:44 +0000127 afterReceiveNewInterest(const Face& inFace, const Interest& interest,
128 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700129
130 void
Junxiao Shi15e98b02016-08-12 11:21:44 +0000131 afterReceiveRetxInterest(const Face& inFace, const Interest& interest,
132 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700133
134 /** \brief send to last working nexthop
135 * \return whether an Interest is sent
136 */
137 bool
Junxiao Shi15e98b02016-08-12 11:21:44 +0000138 sendToLastNexthop(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
Junxiao Shi8d843142016-07-11 22:42:42 +0000139 const fib::Entry& fibEntry);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700140
141 void
Junxiao Shi8d843142016-07-11 22:42:42 +0000142 afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, FaceId inFace, FaceId firstOutFace);
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700143
144 /** \brief multicast to all nexthops
145 * \param exceptFaces don't forward to those faces
146 */
147 void
Junxiao Shi15e98b02016-08-12 11:21:44 +0000148 multicast(const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700149 std::unordered_set<FaceId> exceptFaces = std::unordered_set<FaceId>());
150
151 void
152 updateMeasurements(const Face& inFace, const Data& data,
153 const RttEstimator::Duration& rtt);
154
155public:
156 static const Name STRATEGY_NAME;
157
158private:
159 FaceInfoTable m_fit;
Junxiao Shia788e252015-01-28 17:06:25 -0700160 RetxSuppressionFixed m_retxSuppression;
Junxiao Shi80ee7cb2014-12-14 10:53:05 -0700161 signal::ScopedConnection m_removeFaceInfoConn;
162};
163
164} // namespace fw
165} // namespace nfd
166
167#endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP