Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_FW_NCC_STRATEGY_HPP |
| 8 | #define NFD_FW_NCC_STRATEGY_HPP |
| 9 | |
| 10 | #include "strategy.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
| 13 | namespace fw { |
| 14 | |
| 15 | /** \brief a forwarding strategy similar to CCNx 0.7.2 |
| 16 | */ |
| 17 | class NccStrategy : public Strategy |
| 18 | { |
| 19 | public: |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 20 | NccStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 21 | |
| 22 | virtual |
| 23 | ~NccStrategy(); |
| 24 | |
| 25 | virtual void |
| 26 | afterReceiveInterest(const Face& inFace, |
| 27 | const Interest& interest, |
| 28 | shared_ptr<fib::Entry> fibEntry, |
| 29 | shared_ptr<pit::Entry> pitEntry); |
| 30 | |
| 31 | virtual void |
| 32 | beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry, |
| 33 | const Face& inFace, const Data& data); |
| 34 | |
| 35 | protected: |
| 36 | /// StrategyInfo on measurements::Entry |
| 37 | class MeasurementsEntryInfo : public StrategyInfo |
| 38 | { |
| 39 | public: |
| 40 | MeasurementsEntryInfo(); |
| 41 | |
| 42 | void |
| 43 | inheritFrom(const MeasurementsEntryInfo& other); |
| 44 | |
| 45 | shared_ptr<Face> |
| 46 | getBestFace(); |
| 47 | |
| 48 | void |
| 49 | updateBestFace(const Face& face); |
| 50 | |
| 51 | void |
| 52 | adjustPredictUp(); |
| 53 | |
| 54 | private: |
| 55 | void |
| 56 | adjustPredictDown(); |
| 57 | |
| 58 | void |
| 59 | ageBestFace(); |
| 60 | |
| 61 | public: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 62 | weak_ptr<Face> bestFace; |
| 63 | weak_ptr<Face> previousFace; |
| 64 | time::microseconds prediction; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 65 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 66 | static const time::microseconds INITIAL_PREDICTION; |
| 67 | static const time::microseconds MIN_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 68 | static const int ADJUST_PREDICT_DOWN_SHIFT = 7; |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 69 | static const time::microseconds MAX_PREDICTION; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 70 | static const int ADJUST_PREDICT_UP_SHIFT = 3; |
| 71 | }; |
| 72 | |
| 73 | /// StrategyInfo on pit::Entry |
| 74 | class PitEntryInfo : public StrategyInfo |
| 75 | { |
| 76 | public: |
| 77 | PitEntryInfo(); |
| 78 | |
| 79 | virtual |
| 80 | ~PitEntryInfo(); |
| 81 | |
| 82 | public: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 83 | bool isNewInterest; |
| 84 | EventId bestFaceTimeout; |
| 85 | EventId propagateTimer; |
| 86 | time::microseconds maxInterval; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | protected: |
| 90 | shared_ptr<MeasurementsEntryInfo> |
| 91 | getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry); |
| 92 | |
| 93 | shared_ptr<MeasurementsEntryInfo> |
| 94 | getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry); |
| 95 | |
| 96 | /// propagate to another upstream |
| 97 | void |
| 98 | doPropagate(weak_ptr<pit::Entry> pitEntryWeak, weak_ptr<fib::Entry> fibEntryWeak); |
| 99 | |
| 100 | /// best face did not reply within prediction |
| 101 | void |
| 102 | timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak); |
| 103 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 104 | public: |
| 105 | static const Name STRATEGY_NAME; |
| 106 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 107 | protected: |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 108 | static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE; |
| 109 | static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 110 | static const int UPDATE_MEASUREMENTS_N_LEVELS = 2; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 111 | static const time::nanoseconds MEASUREMENTS_LIFETIME; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace fw |
| 115 | } // namespace nfd |
| 116 | |
| 117 | #endif // NFD_FW_NCC_STRATEGY_HPP |