Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -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 | /* |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, Regents of the University of California, |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -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/>. |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FW_NCC_STRATEGY_HPP |
| 27 | #define NFD_DAEMON_FW_NCC_STRATEGY_HPP |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 28 | |
| 29 | #include "strategy.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace fw { |
| 33 | |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 34 | /** \brief A forwarding strategy similar to CCNx 0.7.2 |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 35 | */ |
| 36 | class NccStrategy : public Strategy |
| 37 | { |
| 38 | public: |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 39 | explicit |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 40 | NccStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
| 41 | |
| 42 | static const Name& |
| 43 | getStrategyName(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 44 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 45 | void |
| 46 | afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 47 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 48 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 49 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 50 | beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 51 | const FaceEndpoint& ingress, const Data& data) override; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 52 | |
Davide Pesavento | 264af77 | 2021-02-09 21:48:24 -0500 | [diff] [blame^] | 53 | NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 54 | /// StrategyInfo on measurements::Entry |
| 55 | class MeasurementsEntryInfo : public StrategyInfo |
| 56 | { |
| 57 | public: |
Junxiao Shi | 39ef261 | 2014-11-29 20:35:19 -0700 | [diff] [blame] | 58 | static constexpr int |
| 59 | getTypeId() |
| 60 | { |
| 61 | return 1000; |
| 62 | } |
| 63 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 64 | MeasurementsEntryInfo(); |
| 65 | |
| 66 | void |
| 67 | inheritFrom(const MeasurementsEntryInfo& other); |
| 68 | |
| 69 | shared_ptr<Face> |
| 70 | getBestFace(); |
| 71 | |
| 72 | void |
| 73 | updateBestFace(const Face& face); |
| 74 | |
| 75 | void |
| 76 | adjustPredictUp(); |
| 77 | |
| 78 | private: |
| 79 | void |
| 80 | adjustPredictDown(); |
| 81 | |
| 82 | void |
| 83 | ageBestFace(); |
| 84 | |
| 85 | public: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 86 | weak_ptr<Face> bestFace; |
| 87 | weak_ptr<Face> previousFace; |
| 88 | time::microseconds prediction; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 90 | static const time::microseconds INITIAL_PREDICTION; |
| 91 | static const time::microseconds MIN_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 92 | static const int ADJUST_PREDICT_DOWN_SHIFT = 7; |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 93 | static const time::microseconds MAX_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 94 | static const int ADJUST_PREDICT_UP_SHIFT = 3; |
| 95 | }; |
| 96 | |
| 97 | /// StrategyInfo on pit::Entry |
| 98 | class PitEntryInfo : public StrategyInfo |
| 99 | { |
| 100 | public: |
Junxiao Shi | 39ef261 | 2014-11-29 20:35:19 -0700 | [diff] [blame] | 101 | static constexpr int |
| 102 | getTypeId() |
| 103 | { |
| 104 | return 1001; |
| 105 | } |
| 106 | |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 107 | ~PitEntryInfo() override; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 108 | |
| 109 | public: |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 110 | /// timer that expires when best face does not respond within predicted time |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 111 | scheduler::EventId bestFaceTimeout; |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 112 | /// timer for propagating to another face |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 113 | scheduler::EventId propagateTimer; |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 114 | /// maximum interval between forwarding to two nexthops except best and previous |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 115 | time::microseconds maxInterval; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | protected: |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 119 | MeasurementsEntryInfo& |
| 120 | getMeasurementsEntryInfo(measurements::Entry* entry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 121 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 122 | MeasurementsEntryInfo& |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 123 | getMeasurementsEntryInfo(const shared_ptr<pit::Entry>& entry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 124 | |
| 125 | /// propagate to another upstream |
| 126 | void |
Junxiao Shi | e21b3f3 | 2016-11-24 14:13:46 +0000 | [diff] [blame] | 127 | doPropagate(FaceId inFaceId, weak_ptr<pit::Entry> pitEntryWeak); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 128 | |
| 129 | /// best face did not reply within prediction |
| 130 | void |
| 131 | timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak); |
| 132 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 133 | protected: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 134 | static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE; |
| 135 | static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 136 | static const int UPDATE_MEASUREMENTS_N_LEVELS = 2; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 137 | static const time::nanoseconds MEASUREMENTS_LIFETIME; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace fw |
| 141 | } // namespace nfd |
| 142 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 143 | #endif // NFD_DAEMON_FW_NCC_STRATEGY_HPP |