blob: bfbb06d7d44e08f7485b52008186f0ffa34a32b5 [file] [log] [blame]
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Hila Ben Abraham39a79be2016-03-30 22:00:55 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shi1e46be32015-01-08 20:18:05 -07004 * 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,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020047 shared_ptr<pit::Entry> pitEntry) override;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070048
49 virtual void
Junxiao Shi82e7f582014-09-07 15:15:40 -070050 beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020051 const Face& inFace, const Data& data) override;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070052
Hila Ben Abraham39a79be2016-03-30 22:00:55 -070053PUBLIC_WITH_TESTS_ELSE_PROTECTED:
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070054 /// StrategyInfo on measurements::Entry
55 class MeasurementsEntryInfo : public StrategyInfo
56 {
57 public:
Junxiao Shi39ef2612014-11-29 20:35:19 -070058 static constexpr int
59 getTypeId()
60 {
61 return 1000;
62 }
63
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070064 MeasurementsEntryInfo();
65
66 void
67 inheritFrom(const MeasurementsEntryInfo& other);
68
69 shared_ptr<Face>
70 getBestFace();
71
72 void
73 updateBestFace(const Face& face);
74
75 void
76 adjustPredictUp();
77
78 private:
79 void
80 adjustPredictDown();
81
82 void
83 ageBestFace();
84
85 public:
Junxiao Shi1391d612014-03-27 22:27:20 -070086 weak_ptr<Face> bestFace;
87 weak_ptr<Face> previousFace;
88 time::microseconds prediction;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070089
Junxiao Shi1391d612014-03-27 22:27:20 -070090 static const time::microseconds INITIAL_PREDICTION;
91 static const time::microseconds MIN_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070092 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
Junxiao Shi1391d612014-03-27 22:27:20 -070093 static const time::microseconds MAX_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070094 static const int ADJUST_PREDICT_UP_SHIFT = 3;
95 };
96
97 /// StrategyInfo on pit::Entry
98 class PitEntryInfo : public StrategyInfo
99 {
100 public:
Junxiao Shi39ef2612014-11-29 20:35:19 -0700101 static constexpr int
102 getTypeId()
103 {
104 return 1001;
105 }
106
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700107 virtual
108 ~PitEntryInfo();
109
110 public:
Junxiao Shicbb490a2014-08-13 12:24:24 -0700111 /// timer that expires when best face does not respond within predicted time
Junxiao Shi1e46be32015-01-08 20:18:05 -0700112 scheduler::EventId bestFaceTimeout;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700113 /// timer for propagating to another face
Junxiao Shi1e46be32015-01-08 20:18:05 -0700114 scheduler::EventId propagateTimer;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700115 /// maximum interval between forwarding to two nexthops except best and previous
Junxiao Shi1391d612014-03-27 22:27:20 -0700116 time::microseconds maxInterval;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700117 };
118
119protected:
120 shared_ptr<MeasurementsEntryInfo>
121 getMeasurementsEntryInfo(shared_ptr<measurements::Entry> entry);
122
123 shared_ptr<MeasurementsEntryInfo>
124 getMeasurementsEntryInfo(shared_ptr<pit::Entry> entry);
125
126 /// propagate to another upstream
127 void
Junxiao Shi8d843142016-07-11 22:42:42 +0000128 doPropagate(weak_ptr<pit::Entry> pitEntryWeak);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700129
130 /// best face did not reply within prediction
131 void
132 timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak);
133
Junxiao Shif3c07812014-03-11 21:48:49 -0700134public:
135 static const Name STRATEGY_NAME;
136
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700137protected:
Junxiao Shi1391d612014-03-27 22:27:20 -0700138 static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE;
139 static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700140 static const int UPDATE_MEASUREMENTS_N_LEVELS = 2;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700141 static const time::nanoseconds MEASUREMENTS_LIFETIME;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700142};
143
144} // namespace fw
145} // namespace nfd
146
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700147#endif // NFD_DAEMON_FW_NCC_STRATEGY_HPP