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