Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 2 | /* |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 4 | * 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 Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP |
| 27 | #define NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 28 | |
| 29 | #include "strategy.hpp" |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 30 | #include "process-nack-traits.hpp" |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 31 | #include "retx-suppression-exponential.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace fw { |
| 35 | |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 36 | /** \brief Best Route strategy |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 37 | * |
| 38 | * This strategy forwards a new Interest to the lowest-cost nexthop (except downstream). |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 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. |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 42 | * If all nexthops have been used, the strategy starts over with the first nexthop. |
| 43 | * |
| 44 | * This strategy returns Nack to all downstreams with reason NoRoute |
| 45 | * if there is no usable nexthop, which may be caused by: |
| 46 | * (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 | * |
| 50 | * 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 Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 52 | */ |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 53 | class BestRouteStrategy : public Strategy |
| 54 | , public ProcessNackTraits<BestRouteStrategy> |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 55 | { |
| 56 | public: |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 57 | explicit |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 58 | BestRouteStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 59 | |
| 60 | static const Name& |
| 61 | getStrategyName(); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 62 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 63 | public: // triggers |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 64 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 65 | afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 66 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 67 | |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 68 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 69 | afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 70 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame] | 72 | NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 1ef93d0 | 2022-04-08 00:25:06 -0400 | [diff] [blame^] | 73 | std::unique_ptr<RetxSuppressionExponential> m_retxSuppression; |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 74 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 75 | friend ProcessNackTraits<BestRouteStrategy>; |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace fw |
| 79 | } // namespace nfd |
| 80 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 81 | #endif // NFD_DAEMON_FW_BEST_ROUTE_STRATEGY_HPP |