blob: 6e915aa8d486cefe2d157fb473da3ac8ffaf87e2 [file] [log] [blame]
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -07001/* -*- 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 Shi0b5fbbb2014-02-20 15:54:03 -070011
12namespace nfd {
13namespace fw {
14
15/** \brief a forwarding strategy similar to CCNx 0.7.2
16 */
17class NccStrategy : public Strategy
18{
19public:
20 explicit
21 NccStrategy(Forwarder& forwarder);
22
23 virtual
24 ~NccStrategy();
25
26 virtual void
27 afterReceiveInterest(const Face& inFace,
28 const Interest& interest,
29 shared_ptr<fib::Entry> fibEntry,
30 shared_ptr<pit::Entry> pitEntry);
31
32 virtual void
33 beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
34 const Face& inFace, const Data& data);
35
36protected:
37 /// StrategyInfo on measurements::Entry
38 class MeasurementsEntryInfo : public StrategyInfo
39 {
40 public:
41 MeasurementsEntryInfo();
42
43 void
44 inheritFrom(const MeasurementsEntryInfo& other);
45
46 shared_ptr<Face>
47 getBestFace();
48
49 void
50 updateBestFace(const Face& face);
51
52 void
53 adjustPredictUp();
54
55 private:
56 void
57 adjustPredictDown();
58
59 void
60 ageBestFace();
61
62 public:
63 weak_ptr<Face> m_bestFace;
64 weak_ptr<Face> m_previousFace;
65 time::Duration m_prediction;
66
67 static const time::Duration INITIAL_PREDICTION;
68 static const time::Duration MIN_PREDICTION;
69 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
70 static const time::Duration MAX_PREDICTION;
71 static const int ADJUST_PREDICT_UP_SHIFT = 3;
72 };
73
74 /// StrategyInfo on pit::Entry
75 class PitEntryInfo : public StrategyInfo
76 {
77 public:
78 PitEntryInfo();
79
80 virtual
81 ~PitEntryInfo();
82
83 public:
84 bool m_isNewInterest;
85 EventId m_bestFaceTimeout;
86 EventId m_propagateTimer;
87 time::Duration m_maxInterval;
88 };
89
90protected:
91 shared_ptr<MeasurementsEntryInfo>
92 getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry);
93
94 shared_ptr<MeasurementsEntryInfo>
95 getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry);
96
97 /// propagate to another upstream
98 void
99 doPropagate(weak_ptr<pit::Entry> pitEntryWeak, weak_ptr<fib::Entry> fibEntryWeak);
100
101 /// best face did not reply within prediction
102 void
103 timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak);
104
105protected:
106 static const time::Duration DEFER_FIRST_WITHOUT_BEST_FACE;
107 static const time::Duration DEFER_RANGE_WITHOUT_BEST_FACE;
108 static const int UPDATE_MEASUREMENTS_N_LEVELS = 2;
109 static const time::Duration MEASUREMENTS_LIFETIME;
110};
111
112} // namespace fw
113} // namespace nfd
114
115#endif // NFD_FW_NCC_STRATEGY_HPP