blob: 6a245decd474e73ab14b7043a2a25607a4b0d2d2 [file] [log] [blame]
Alexander Afanasyev33b72772014-01-26 23:22:58 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shifc2e13d2017-07-25 02:08:48 +00002/*
Davide Pesavento264af772021-02-09 21:48:24 -05003 * Copyright (c) 2014-2021, Regents of the University of California,
Junxiao Shi330136a2016-03-10 04:53:08 -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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shia110f262014-10-12 12:35:20 -070024 */
Alexander Afanasyev33b72772014-01-26 23:22:58 -080025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FW_FORWARDER_HPP
27#define NFD_DAEMON_FW_FORWARDER_HPP
Alexander Afanasyev33b72772014-01-26 23:22:58 -080028
Davide Pesavento3dade002019-03-19 11:29:56 -060029#include "face-table.hpp"
30#include "forwarder-counters.hpp"
Junxiao Shifbe8efe2016-08-22 16:02:30 +000031#include "unsolicited-data-policy.hpp"
ashiqopu075bb7d2019-03-10 01:38:21 +000032#include "face/face-endpoint.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070033#include "table/fib.hpp"
34#include "table/pit.hpp"
35#include "table/cs.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070036#include "table/measurements.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070037#include "table/strategy-choice.hpp"
Junxiao Shia110f262014-10-12 12:35:20 -070038#include "table/dead-nonce-list.hpp"
Junxiao Shi0355e9f2015-09-02 07:24:53 -070039#include "table/network-region-table.hpp"
Alexander Afanasyev33b72772014-01-26 23:22:58 -080040
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080041namespace nfd {
Alexander Afanasyev33b72772014-01-26 23:22:58 -080042
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070043namespace fw {
44class Strategy;
45} // namespace fw
46
Davide Pesavento0498ce82021-06-14 02:02:21 -040047/**
48 * \brief Main class of NFD's forwarding engine.
Junxiao Shic041ca32014-02-25 20:01:15 -070049 *
Davide Pesavento0498ce82021-06-14 02:02:21 -040050 * The Forwarder class owns all tables and implements the forwarding pipelines.
Alexander Afanasyev33b72772014-01-26 23:22:58 -080051 */
52class Forwarder
53{
54public:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040055 explicit
56 Forwarder(FaceTable& faceTable);
Alexander Afanasyev33b72772014-01-26 23:22:58 -080057
Davide Pesavento264af772021-02-09 21:48:24 -050058 NFD_VIRTUAL_WITH_TESTS
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060059 ~Forwarder();
60
Junxiao Shib289cc12014-03-15 12:19:05 -070061 const ForwarderCounters&
Junxiao Shib9420cf2016-08-13 04:38:52 +000062 getCounters() const
63 {
64 return m_counters;
65 }
Junxiao Shib289cc12014-03-15 12:19:05 -070066
Junxiao Shifbe8efe2016-08-22 16:02:30 +000067 fw::UnsolicitedDataPolicy&
68 getUnsolicitedDataPolicy() const
69 {
70 return *m_unsolicitedDataPolicy;
71 }
72
73 void
74 setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
75 {
76 BOOST_ASSERT(policy != nullptr);
77 m_unsolicitedDataPolicy = std::move(policy);
78 }
79
Junxiao Shiea48d8b2014-03-16 13:53:47 -070080 NameTree&
Junxiao Shib9420cf2016-08-13 04:38:52 +000081 getNameTree()
82 {
83 return m_nameTree;
84 }
Junxiao Shiea48d8b2014-03-16 13:53:47 -070085
Junxiao Shi8c8d2182014-01-30 22:33:00 -070086 Fib&
Junxiao Shib9420cf2016-08-13 04:38:52 +000087 getFib()
88 {
89 return m_fib;
90 }
Junxiao Shic041ca32014-02-25 20:01:15 -070091
Junxiao Shi8c8d2182014-01-30 22:33:00 -070092 Pit&
Junxiao Shib9420cf2016-08-13 04:38:52 +000093 getPit()
94 {
95 return m_pit;
96 }
Junxiao Shic041ca32014-02-25 20:01:15 -070097
Junxiao Shi8c8d2182014-01-30 22:33:00 -070098 Cs&
Junxiao Shib9420cf2016-08-13 04:38:52 +000099 getCs()
100 {
101 return m_cs;
102 }
Junxiao Shic041ca32014-02-25 20:01:15 -0700103
Junxiao Shidbe71732014-02-21 22:23:28 -0700104 Measurements&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000105 getMeasurements()
106 {
107 return m_measurements;
108 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700109
Junxiao Shibb5105f2014-03-03 12:06:45 -0700110 StrategyChoice&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000111 getStrategyChoice()
112 {
113 return m_strategyChoice;
114 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700115
Junxiao Shia110f262014-10-12 12:35:20 -0700116 DeadNonceList&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000117 getDeadNonceList()
118 {
119 return m_deadNonceList;
120 }
Junxiao Shia110f262014-10-12 12:35:20 -0700121
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700122 NetworkRegionTable&
Junxiao Shib9420cf2016-08-13 04:38:52 +0000123 getNetworkRegionTable()
124 {
125 return m_networkRegionTable;
126 }
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700127
Davide Pesavento264af772021-02-09 21:48:24 -0500128NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
Junxiao Shid3c792f2014-01-30 00:46:13 -0700129 /** \brief incoming Interest pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400130 * \param interest the incoming Interest, must be well-formed and created with make_shared
131 * \param ingress face on which \p interest was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132 */
Davide Pesavento264af772021-02-09 21:48:24 -0500133 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400134 onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700135
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700136 /** \brief Interest loop pipeline
137 */
Davide Pesavento264af772021-02-09 21:48:24 -0500138 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400139 onInterestLoop(const Interest& interest, const FaceEndpoint& ingress);
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700140
mzhang4eab72492015-02-25 11:16:09 -0600141 /** \brief Content Store miss pipeline
142 */
Davide Pesavento264af772021-02-09 21:48:24 -0500143 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400144 onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
145 const shared_ptr<pit::Entry>& pitEntry);
mzhang4eab72492015-02-25 11:16:09 -0600146
147 /** \brief Content Store hit pipeline
148 */
Davide Pesavento264af772021-02-09 21:48:24 -0500149 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400150 onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
151 const shared_ptr<pit::Entry>& pitEntry, const Data& data);
mzhang4eab72492015-02-25 11:16:09 -0600152
Junxiao Shid3c792f2014-01-30 00:46:13 -0700153 /** \brief outgoing Interest pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700154 * \return A pointer to the out-record created or nullptr if the Interest was dropped
Junxiao Shid3c792f2014-01-30 00:46:13 -0700155 */
Davide Pesavento264af772021-02-09 21:48:24 -0500156 NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
Davide Pesavento0498ce82021-06-14 02:02:21 -0400157 onOutgoingInterest(const Interest& interest, Face& egress,
158 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shic041ca32014-02-25 20:01:15 -0700159
Junxiao Shia110f262014-10-12 12:35:20 -0700160 /** \brief Interest finalize pipeline
Junxiao Shia110f262014-10-12 12:35:20 -0700161 */
Davide Pesavento264af772021-02-09 21:48:24 -0500162 NFD_VIRTUAL_WITH_TESTS void
Teng Liang6f09ab62018-03-01 20:04:08 -0700163 onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shia110f262014-10-12 12:35:20 -0700164
Junxiao Shid3c792f2014-01-30 00:46:13 -0700165 /** \brief incoming Data pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400166 * \param data the incoming Data, must be well-formed and created with make_shared
167 * \param ingress face on which \p data was received and endpoint of the sender
Junxiao Shid3c792f2014-01-30 00:46:13 -0700168 */
Davide Pesavento264af772021-02-09 21:48:24 -0500169 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400170 onIncomingData(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700171
Junxiao Shid3c792f2014-01-30 00:46:13 -0700172 /** \brief Data unsolicited pipeline
173 */
Davide Pesavento264af772021-02-09 21:48:24 -0500174 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400175 onDataUnsolicited(const Data& data, const FaceEndpoint& ingress);
Junxiao Shic041ca32014-02-25 20:01:15 -0700176
Junxiao Shid3c792f2014-01-30 00:46:13 -0700177 /** \brief outgoing Data pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700178 * \return Whether the Data was transmitted (true) or dropped (false)
Junxiao Shid3c792f2014-01-30 00:46:13 -0700179 */
Davide Pesavento264af772021-02-09 21:48:24 -0500180 NFD_VIRTUAL_WITH_TESTS bool
Teng Liangebc20f62020-06-23 16:55:20 -0700181 onOutgoingData(const Data& data, Face& egress);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700182
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700183 /** \brief incoming Nack pipeline
Davide Pesavento0498ce82021-06-14 02:02:21 -0400184 * \param nack the incoming Nack, must be well-formed
185 * \param ingress face on which \p nack is received and endpoint of the sender
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700186 */
Davide Pesavento264af772021-02-09 21:48:24 -0500187 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400188 onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700189
190 /** \brief outgoing Nack pipeline
Eric Newberry2377ada2020-09-28 22:40:14 -0700191 * \return Whether the Nack was transmitted (true) or dropped (false)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700192 */
Davide Pesavento264af772021-02-09 21:48:24 -0500193 NFD_VIRTUAL_WITH_TESTS bool
Davide Pesavento0498ce82021-06-14 02:02:21 -0400194 onOutgoingNack(const lp::NackHeader& nack, Face& egress,
195 const shared_ptr<pit::Entry>& pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700196
Davide Pesavento264af772021-02-09 21:48:24 -0500197 NFD_VIRTUAL_WITH_TESTS void
Davide Pesavento0498ce82021-06-14 02:02:21 -0400198 onDroppedInterest(const Interest& interest, Face& egress);
Eric Newberry41aba102017-11-01 16:42:13 -0700199
Davide Pesavento264af772021-02-09 21:48:24 -0500200 NFD_VIRTUAL_WITH_TESTS void
Ju Pan2feb4592019-09-16 20:56:38 +0000201 onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
202
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400203private:
Teng Liang7003e0b2018-03-03 16:03:30 -0700204 /** \brief set a new expiry timer (now + \p duration) on a PIT entry
205 */
206 void
207 setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
Junxiao Shic041ca32014-02-25 20:01:15 -0700208
Junxiao Shia110f262014-10-12 12:35:20 -0700209 /** \brief insert Nonce to Dead Nonce List if necessary
Junxiao Shi4846f372016-04-05 13:39:30 -0700210 * \param upstream if null, insert Nonces from all out-records;
211 * if not null, insert Nonce only on the out-records of this face
Junxiao Shia110f262014-10-12 12:35:20 -0700212 */
Davide Pesaventoe08cc4c2021-06-08 18:22:46 -0400213 void
214 insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream);
Junxiao Shia110f262014-10-12 12:35:20 -0700215
Junxiao Shid3c792f2014-01-30 00:46:13 -0700216private:
Junxiao Shib289cc12014-03-15 12:19:05 -0700217 ForwarderCounters m_counters;
218
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400219 FaceTable& m_faceTable;
Junxiao Shifbe8efe2016-08-22 16:02:30 +0000220 unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
HangZhangad4afd12014-03-01 11:03:08 +0800221
Junxiao Shi0355e9f2015-09-02 07:24:53 -0700222 NameTree m_nameTree;
223 Fib m_fib;
224 Pit m_pit;
225 Cs m_cs;
226 Measurements m_measurements;
227 StrategyChoice m_strategyChoice;
228 DeadNonceList m_deadNonceList;
229 NetworkRegionTable m_networkRegionTable;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700230
Junxiao Shid3c792f2014-01-30 00:46:13 -0700231 // allow Strategy (base class) to enter pipelines
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700232 friend class fw::Strategy;
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800233};
234
Junxiao Shid3c792f2014-01-30 00:46:13 -0700235} // namespace nfd
Alexander Afanasyev33b72772014-01-26 23:22:58 -0800236
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700237#endif // NFD_DAEMON_FW_FORWARDER_HPP