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