Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 25 | #ifndef NFD_DAEMON_FW_NCC_STRATEGY_HPP |
| 26 | #define NFD_DAEMON_FW_NCC_STRATEGY_HPP |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 27 | |
| 28 | #include "strategy.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | namespace fw { |
| 32 | |
| 33 | /** \brief a forwarding strategy similar to CCNx 0.7.2 |
| 34 | */ |
| 35 | class NccStrategy : public Strategy |
| 36 | { |
| 37 | public: |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 38 | NccStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 39 | |
| 40 | virtual |
| 41 | ~NccStrategy(); |
| 42 | |
| 43 | virtual void |
| 44 | afterReceiveInterest(const Face& inFace, |
| 45 | const Interest& interest, |
| 46 | shared_ptr<fib::Entry> fibEntry, |
| 47 | shared_ptr<pit::Entry> pitEntry); |
| 48 | |
| 49 | virtual void |
| 50 | beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry, |
| 51 | const Face& inFace, const Data& data); |
| 52 | |
| 53 | protected: |
| 54 | /// StrategyInfo on measurements::Entry |
| 55 | class MeasurementsEntryInfo : public StrategyInfo |
| 56 | { |
| 57 | public: |
| 58 | MeasurementsEntryInfo(); |
| 59 | |
| 60 | void |
| 61 | inheritFrom(const MeasurementsEntryInfo& other); |
| 62 | |
| 63 | shared_ptr<Face> |
| 64 | getBestFace(); |
| 65 | |
| 66 | void |
| 67 | updateBestFace(const Face& face); |
| 68 | |
| 69 | void |
| 70 | adjustPredictUp(); |
| 71 | |
| 72 | private: |
| 73 | void |
| 74 | adjustPredictDown(); |
| 75 | |
| 76 | void |
| 77 | ageBestFace(); |
| 78 | |
| 79 | public: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 80 | weak_ptr<Face> bestFace; |
| 81 | weak_ptr<Face> previousFace; |
| 82 | time::microseconds prediction; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 84 | static const time::microseconds INITIAL_PREDICTION; |
| 85 | static const time::microseconds MIN_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 86 | static const int ADJUST_PREDICT_DOWN_SHIFT = 7; |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 87 | static const time::microseconds MAX_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 88 | static const int ADJUST_PREDICT_UP_SHIFT = 3; |
| 89 | }; |
| 90 | |
| 91 | /// StrategyInfo on pit::Entry |
| 92 | class PitEntryInfo : public StrategyInfo |
| 93 | { |
| 94 | public: |
| 95 | PitEntryInfo(); |
| 96 | |
| 97 | virtual |
| 98 | ~PitEntryInfo(); |
| 99 | |
| 100 | public: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 101 | bool isNewInterest; |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame^] | 102 | /// timer that expires when best face does not respond within predicted time |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 103 | EventId bestFaceTimeout; |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame^] | 104 | /// timer for propagating to another face |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 105 | EventId propagateTimer; |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame^] | 106 | /// maximum interval between forwarding to two nexthops except best and previous |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 107 | time::microseconds maxInterval; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | protected: |
| 111 | shared_ptr<MeasurementsEntryInfo> |
| 112 | getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry); |
| 113 | |
| 114 | shared_ptr<MeasurementsEntryInfo> |
| 115 | getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry); |
| 116 | |
| 117 | /// propagate to another upstream |
| 118 | void |
| 119 | doPropagate(weak_ptr<pit::Entry> pitEntryWeak, weak_ptr<fib::Entry> fibEntryWeak); |
| 120 | |
| 121 | /// best face did not reply within prediction |
| 122 | void |
| 123 | timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak); |
| 124 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 125 | public: |
| 126 | static const Name STRATEGY_NAME; |
| 127 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 128 | protected: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 129 | static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE; |
| 130 | static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 131 | static const int UPDATE_MEASUREMENTS_N_LEVELS = 2; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 132 | static const time::nanoseconds MEASUREMENTS_LIFETIME; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace fw |
| 136 | } // namespace nfd |
| 137 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 138 | #endif // NFD_DAEMON_FW_NCC_STRATEGY_HPP |