blob: 6a41b1a5567055c6a04e8b90c5b10baea299f5b3 [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:
Junxiao Shif3c07812014-03-11 21:48:49 -070020 NccStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070021
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
35protected:
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;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070064 time::nanoseconds m_prediction;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070065
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070066 static const time::nanoseconds INITIAL_PREDICTION;
67 static const time::nanoseconds MIN_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070068 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070069 static const time::nanoseconds MAX_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070070 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;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070086 time::nanoseconds m_maxInterval;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070087 };
88
89protected:
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 Shif3c07812014-03-11 21:48:49 -0700104public:
105 static const Name STRATEGY_NAME;
106
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700107protected:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700108 static const time::nanoseconds DEFER_FIRST_WITHOUT_BEST_FACE;
109 static const time::nanoseconds DEFER_RANGE_WITHOUT_BEST_FACE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700110 static const int UPDATE_MEASUREMENTS_N_LEVELS = 2;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700111 static const time::nanoseconds MEASUREMENTS_LIFETIME;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700112};
113
114} // namespace fw
115} // namespace nfd
116
117#endif // NFD_FW_NCC_STRATEGY_HPP