blob: 473a87d87fa29908b8a395601781458a7e16911a [file] [log] [blame]
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopuc7079482019-02-20 05:34:37 +00002/*
3 * Copyright (c) 2014-2019, 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
ashiqopuc7079482019-02-20 05:34:37 +000035 *
36 * \note This strategy is not EndpointId-aware.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070037 */
38class NccStrategy : public Strategy
39{
40public:
Junxiao Shi15e98b02016-08-12 11:21:44 +000041 explicit
Junxiao Shi037f4ab2016-12-13 04:27:06 +000042 NccStrategy(Forwarder& forwarder, const Name& name = getStrategyName());
43
44 static const Name&
45 getStrategyName();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070046
ashiqopuc7079482019-02-20 05:34:37 +000047 void
48 afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi15e98b02016-08-12 11:21:44 +000049 const shared_ptr<pit::Entry>& pitEntry) override;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070050
ashiqopuc7079482019-02-20 05:34:37 +000051 void
Junxiao Shi15e98b02016-08-12 11:21:44 +000052 beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
ashiqopuc7079482019-02-20 05:34:37 +000053 const FaceEndpoint& ingress, const Data& data) override;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070054
Hila Ben Abraham39a79be2016-03-30 22:00:55 -070055PUBLIC_WITH_TESTS_ELSE_PROTECTED:
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070056 /// StrategyInfo on measurements::Entry
57 class MeasurementsEntryInfo : public StrategyInfo
58 {
59 public:
Junxiao Shi39ef2612014-11-29 20:35:19 -070060 static constexpr int
61 getTypeId()
62 {
63 return 1000;
64 }
65
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070066 MeasurementsEntryInfo();
67
68 void
69 inheritFrom(const MeasurementsEntryInfo& other);
70
71 shared_ptr<Face>
72 getBestFace();
73
74 void
75 updateBestFace(const Face& face);
76
77 void
78 adjustPredictUp();
79
80 private:
81 void
82 adjustPredictDown();
83
84 void
85 ageBestFace();
86
87 public:
Junxiao Shi1391d612014-03-27 22:27:20 -070088 weak_ptr<Face> bestFace;
89 weak_ptr<Face> previousFace;
90 time::microseconds prediction;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070091
Junxiao Shi1391d612014-03-27 22:27:20 -070092 static const time::microseconds INITIAL_PREDICTION;
93 static const time::microseconds MIN_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070094 static const int ADJUST_PREDICT_DOWN_SHIFT = 7;
Junxiao Shi1391d612014-03-27 22:27:20 -070095 static const time::microseconds MAX_PREDICTION;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070096 static const int ADJUST_PREDICT_UP_SHIFT = 3;
97 };
98
99 /// StrategyInfo on pit::Entry
100 class PitEntryInfo : public StrategyInfo
101 {
102 public:
Junxiao Shi39ef2612014-11-29 20:35:19 -0700103 static constexpr int
104 getTypeId()
105 {
106 return 1001;
107 }
108
Junxiao Shi15e98b02016-08-12 11:21:44 +0000109 ~PitEntryInfo() override;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700110
111 public:
Junxiao Shicbb490a2014-08-13 12:24:24 -0700112 /// timer that expires when best face does not respond within predicted time
Junxiao Shi1e46be32015-01-08 20:18:05 -0700113 scheduler::EventId bestFaceTimeout;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700114 /// timer for propagating to another face
Junxiao Shi1e46be32015-01-08 20:18:05 -0700115 scheduler::EventId propagateTimer;
Junxiao Shicbb490a2014-08-13 12:24:24 -0700116 /// maximum interval between forwarding to two nexthops except best and previous
Junxiao Shi1391d612014-03-27 22:27:20 -0700117 time::microseconds maxInterval;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700118 };
119
120protected:
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000121 MeasurementsEntryInfo&
122 getMeasurementsEntryInfo(measurements::Entry* entry);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700123
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000124 MeasurementsEntryInfo&
Junxiao Shi15e98b02016-08-12 11:21:44 +0000125 getMeasurementsEntryInfo(const shared_ptr<pit::Entry>& entry);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700126
127 /// propagate to another upstream
128 void
Junxiao Shie21b3f32016-11-24 14:13:46 +0000129 doPropagate(FaceId inFaceId, weak_ptr<pit::Entry> pitEntryWeak);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700130
131 /// best face did not reply within prediction
132 void
133 timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak);
134
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700135protected:
Junxiao Shi1391d612014-03-27 22:27:20 -0700136 static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE;
137 static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700138 static const int UPDATE_MEASUREMENTS_N_LEVELS = 2;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700139 static const time::nanoseconds MEASUREMENTS_LIFETIME;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -0700140};
141
142} // namespace fw
143} // namespace nfd
144
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700145#endif // NFD_DAEMON_FW_NCC_STRATEGY_HPP