blob: 59cf98b45ccdac388c8e5abdc151f6bf65e3f947 [file] [log] [blame]
Teng Liang39465c22018-11-12 19:43:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Teng Liang39465c22018-11-12 19:43:04 -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_SELF_LEARNING_STRATEGY_HPP
27#define NFD_DAEMON_FW_SELF_LEARNING_STRATEGY_HPP
28
29#include "fw/strategy.hpp"
30
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040031#include <ndn-cxx/prefix-announcement.hpp>
Teng Liang39465c22018-11-12 19:43:04 -070032
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::fw {
Teng Liang39465c22018-11-12 19:43:04 -070034
Teng Liangebc20f62020-06-23 16:55:20 -070035/** \brief Self-learning forwarding strategy
Teng Liang39465c22018-11-12 19:43:04 -070036 *
37 * This strategy first broadcasts Interest to learn a single path towards data,
Teng Liangebc20f62020-06-23 16:55:20 -070038 * then unicasts subsequent Interests along the learned path.
Teng Liang39465c22018-11-12 19:43:04 -070039 *
40 * \see https://redmine.named-data.net/attachments/864/Self-learning-strategy-v1.pdf
41 */
42class SelfLearningStrategy : public Strategy
43{
44public:
45 explicit
46 SelfLearningStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
47
48 static const Name&
49 getStrategyName();
50
51 /// StrategyInfo on pit::InRecord
Davide Pesavento3db98072021-03-09 23:03:27 -050052 class InRecordInfo final : public StrategyInfo
Teng Liang39465c22018-11-12 19:43:04 -070053 {
54 public:
55 static constexpr int
56 getTypeId()
57 {
58 return 1040;
59 }
60
61 public:
62 bool isNonDiscoveryInterest = false;
63 };
64
65 /// StrategyInfo on pit::OutRecord
Davide Pesavento3db98072021-03-09 23:03:27 -050066 class OutRecordInfo final : public StrategyInfo
Teng Liang39465c22018-11-12 19:43:04 -070067 {
68 public:
69 static constexpr int
70 getTypeId()
71 {
72 return 1041;
73 }
74
75 public:
76 bool isNonDiscoveryInterest = false;
77 };
78
79public: // triggers
80 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040081 afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Teng Liang39465c22018-11-12 19:43:04 -070082 const shared_ptr<pit::Entry>& pitEntry) override;
83
84 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040085 afterReceiveData(const Data& data, const FaceEndpoint& ingress,
86 const shared_ptr<pit::Entry>& pitEntry) override;
Teng Liang39465c22018-11-12 19:43:04 -070087
88 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040089 afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
Teng Liang39465c22018-11-12 19:43:04 -070090 const shared_ptr<pit::Entry>& pitEntry) override;
91
92private: // operations
Teng Liang39465c22018-11-12 19:43:04 -070093 /** \brief Send an Interest to all possible faces
94 *
95 * This function is invoked when the forwarder has no matching FIB entries for
96 * an incoming discovery Interest, which will be forwarded to faces that
97 * - do not violate the Interest scope
98 * - are non-local
99 * - are not the face from which the Interest arrived, unless the face is ad-hoc
100 */
101 void
102 broadcastInterest(const Interest& interest, const Face& inFace,
103 const shared_ptr<pit::Entry>& pitEntry);
104
105 /** \brief Send an Interest to \p nexthops
106 */
107 void
108 multicastInterest(const Interest& interest, const Face& inFace,
109 const shared_ptr<pit::Entry>& pitEntry,
110 const fib::NextHopList& nexthops);
111
112 /** \brief Find a Prefix Announcement for the Data on the RIB thread, and forward
113 * the Data with the Prefix Announcement on the main thread
114 */
115 void
116 asyncProcessData(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace, const Data& data);
117
118 /** \brief Check whether a PrefixAnnouncement needs to be attached to an incoming Data
119 *
120 * The conditions that a Data packet requires a PrefixAnnouncement are
121 * - the incoming Interest was discovery and
122 * - the outgoing Interest was non-discovery and
123 * - this forwarder does not directly connect to the consumer
124 */
125 static bool
126 needPrefixAnn(const shared_ptr<pit::Entry>& pitEntry);
127
128 /** \brief Add a route using RibManager::slAnnounce on the RIB thread
129 */
130 void
131 addRoute(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace,
132 const Data& data, const ndn::PrefixAnnouncement& pa);
133
134 /** \brief renew a route using RibManager::slRenew on the RIB thread
135 */
136 void
137 renewRoute(const Name& name, FaceId inFaceId, time::milliseconds maxLifetime);
Teng Liang39465c22018-11-12 19:43:04 -0700138};
139
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400140} // namespace nfd::fw
Teng Liang39465c22018-11-12 19:43:04 -0700141
142#endif // NFD_DAEMON_FW_SELF_LEARNING_STRATEGY_HPP