blob: 56e64a57a445e3bc9ffd12d8d4f65301530f0e1c [file] [log] [blame]
Junxiao Shi986b8492014-08-20 12:07:14 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopuc7079482019-02-20 05:34:37 +00002/*
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi192af1f2015-01-13 23:19:39 -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.
Junxiao Shi986b8492014-08-20 12:07:14 -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/>.
24 */
25
Davide Pesavento7922d122021-03-05 22:41:23 -050026#ifndef NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP
27#define NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP
Junxiao Shi986b8492014-08-20 12:07:14 -070028
29#include "strategy.hpp"
Junxiao Shi99540072017-01-27 19:57:33 +000030#include "process-nack-traits.hpp"
Junxiao Shi684fa0f2015-02-23 21:39:57 -070031#include "retx-suppression-exponential.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070032
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::fw {
Junxiao Shi986b8492014-08-20 12:07:14 -070034
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040035/**
36 * \brief "Best route" forwarding strategy.
Junxiao Shi986b8492014-08-20 12:07:14 -070037 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040038 * This strategy forwards a new Interest to the lowest-cost nexthop (except downstream).
39 * After that, if consumer retransmits the Interest (and is not suppressed according to
40 * exponential backoff algorithm), the strategy forwards the Interest again to
41 * the lowest-cost nexthop (except downstream) that is not previously used.
42 * If all nexthops have been used, the strategy starts over with the first nexthop.
Junxiao Shi5e5e4452015-09-24 16:56:52 -070043 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040044 * This strategy returns Nack to all downstreams with reason NoRoute
45 * if there is no usable nexthop, which may be caused by:
Junxiao Shi5e5e4452015-09-24 16:56:52 -070046 * (a) the FIB entry contains no nexthop;
47 * (b) the FIB nexthop happens to be the sole downstream;
48 * (c) the FIB nexthops violate scope.
49 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040050 * This strategy returns Nack to all downstreams if all upstreams have returned Nacks.
51 * The reason of the sent Nack equals the least severe reason among received Nacks.
Junxiao Shi986b8492014-08-20 12:07:14 -070052 */
Davide Pesavento7922d122021-03-05 22:41:23 -050053class BestRouteStrategy : public Strategy
54 , public ProcessNackTraits<BestRouteStrategy>
Junxiao Shi986b8492014-08-20 12:07:14 -070055{
56public:
Junxiao Shi15e98b02016-08-12 11:21:44 +000057 explicit
Davide Pesavento7922d122021-03-05 22:41:23 -050058 BestRouteStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
Junxiao Shi037f4ab2016-12-13 04:27:06 +000059
60 static const Name&
61 getStrategyName();
Junxiao Shi986b8492014-08-20 12:07:14 -070062
Davide Pesavento0498ce82021-06-14 02:02:21 -040063public: // triggers
Junxiao Shi99540072017-01-27 19:57:33 +000064 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040065 afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000066 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi986b8492014-08-20 12:07:14 -070067
Junxiao Shi99540072017-01-27 19:57:33 +000068 void
Davide Pesavento0498ce82021-06-14 02:02:21 -040069 afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
Junxiao Shi15e98b02016-08-12 11:21:44 +000070 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070071
Davide Pesavento264af772021-02-09 21:48:24 -050072NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040073 std::unique_ptr<RetxSuppressionExponential> m_retxSuppression;
Junxiao Shi99540072017-01-27 19:57:33 +000074
Davide Pesavento7922d122021-03-05 22:41:23 -050075 friend ProcessNackTraits<BestRouteStrategy>;
Junxiao Shi986b8492014-08-20 12:07:14 -070076};
77
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040078} // namespace nfd::fw
Junxiao Shi986b8492014-08-20 12:07:14 -070079
Davide Pesavento7922d122021-03-05 22:41:23 -050080#endif // NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP