blob: 72f39e48159c3eee9633da1999c0c2508cbd6843 [file] [log] [blame]
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi82e7f582014-09-07 15:15:40 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi82e7f582014-09-07 15:15:40 -070024 */
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FW_NCC_STRATEGY_HPP
27#define NFD_DAEMON_FW_NCC_STRATEGY_HPP
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070028
29#include "strategy.hpp"
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070030
31namespace nfd {
32namespace fw {
33
34/** \brief a forwarding strategy similar to CCNx 0.7.2
35 */
36class NccStrategy : public Strategy
37{
38public:
Junxiao Shif3c07812014-03-11 21:48:49 -070039 NccStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070040
41 virtual
42 ~NccStrategy();
43
44 virtual void
45 afterReceiveInterest(const Face& inFace,
46 const Interest& interest,
47 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi1c93cae2014-12-09 22:52:17 -070048 shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070049
50 virtual void
Junxiao Shi82e7f582014-09-07 15:15:40 -070051 beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
Junxiao Shi1c93cae2014-12-09 22:52:17 -070052 const Face& inFace, const Data& data) DECL_OVERRIDE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070053
54protected:
55 /// StrategyInfo on measurements::Entry
56 class MeasurementsEntryInfo : public StrategyInfo
57 {
58 public:
59 MeasurementsEntryInfo();
60
61 void
62 inheritFrom(const MeasurementsEntryInfo& other);
63
64 shared_ptr<Face>
65 getBestFace();
66
67 void
68 updateBestFace(const Face& face);
69
70 void
71 adjustPredictUp();
72
73 private:
74 void
75 adjustPredictDown();
76
77 void
78 ageBestFace();
79
80 public:
Junxiao Shi1391d612014-03-27 22:27:20 -070081 weak_ptr<Face> bestFace;
82 weak_ptr<Face> previousFace;
83 time::microseconds prediction;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070084
Junxiao Shi1391d612014-03-27 22:27:20 -070085 static const time::microseconds INITIAL_PREDICTION;
86 static const time::microseconds MIN_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070087 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
Junxiao Shi1391d612014-03-27 22:27:20 -070088 static const time::microseconds MAX_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070089 static const int ADJUST_PREDICT_UP_SHIFT = 3;
90 };
91
92 /// StrategyInfo on pit::Entry
93 class PitEntryInfo : public StrategyInfo
94 {
95 public:
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070096 virtual
97 ~PitEntryInfo();
98
99 public:
Junxiao Shicbb490a2014-08-13 12:24:24 -0700100 /// timer that expires when best face does not respond within predicted time
Junxiao Shi1391d612014-03-27 22:27:20 -0700101 EventId bestFaceTimeout;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700102 /// timer for propagating to another face
Junxiao Shi1391d612014-03-27 22:27:20 -0700103 EventId propagateTimer;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700104 /// maximum interval between forwarding to two nexthops except best and previous
Junxiao Shi1391d612014-03-27 22:27:20 -0700105 time::microseconds maxInterval;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700106 };
107
108protected:
109 shared_ptr<MeasurementsEntryInfo>
110 getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry);
111
112 shared_ptr<MeasurementsEntryInfo>
113 getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry);
114
115 /// propagate to another upstream
116 void
117 doPropagate(weak_ptr<pit::Entry> pitEntryWeak, weak_ptr<fib::Entry> fibEntryWeak);
118
119 /// best face did not reply within prediction
120 void
121 timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak);
122
Junxiao Shif3c07812014-03-11 21:48:49 -0700123public:
124 static const Name STRATEGY_NAME;
125
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700126protected:
Junxiao Shi1391d612014-03-27 22:27:20 -0700127 static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE;
128 static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700129 static const int UPDATE_MEASUREMENTS_N_LEVELS = 2;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700130 static const time::nanoseconds MEASUREMENTS_LIFETIME;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700131};
132
133} // namespace fw
134} // namespace nfd
135
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700136#endif // NFD_DAEMON_FW_NCC_STRATEGY_HPP