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: |
| 62 | weak_ptr<Face> m_bestFace; |
| 63 | weak_ptr<Face> m_previousFace; |
| 64 | time::Duration m_prediction; |
| 65 | |
| 66 | static const time::Duration INITIAL_PREDICTION; |
| 67 | static const time::Duration MIN_PREDICTION; |
| 68 | static const int ADJUST_PREDICT_DOWN_SHIFT = 7; |
| 69 | static const time::Duration MAX_PREDICTION; |
| 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: |
| 83 | bool m_isNewInterest; |
| 84 | EventId m_bestFaceTimeout; |
| 85 | EventId m_propagateTimer; |
| 86 | time::Duration m_maxInterval; |
| 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: |
| 108 | static const time::Duration DEFER_FIRST_WITHOUT_BEST_FACE; |
| 109 | static const time::Duration DEFER_RANGE_WITHOUT_BEST_FACE; |
| 110 | static const int UPDATE_MEASUREMENTS_N_LEVELS = 2; |
| 111 | static const time::Duration MEASUREMENTS_LIFETIME; |
| 112 | }; |
| 113 | |
| 114 | } // namespace fw |
| 115 | } // namespace nfd |
| 116 | |
| 117 | #endif // NFD_FW_NCC_STRATEGY_HPP |