blob: 1b073a931b206120f68f4d5127d477003049c67e [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:
Junxiao Shi1391d612014-03-27 22:27:20 -070062 weak_ptr<Face> bestFace;
63 weak_ptr<Face> previousFace;
64 time::microseconds prediction;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070065
Junxiao Shi1391d612014-03-27 22:27:20 -070066 static const time::microseconds INITIAL_PREDICTION;
67 static const time::microseconds MIN_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070068 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
Junxiao Shi1391d612014-03-27 22:27:20 -070069 static const time::microseconds 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:
Junxiao Shi1391d612014-03-27 22:27:20 -070083 bool isNewInterest;
84 EventId bestFaceTimeout;
85 EventId propagateTimer;
86 time::microseconds 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:
Junxiao Shi1391d612014-03-27 22:27:20 -0700108 static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE;
109 static const time::microseconds 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