blob: 0d6b212772ed4d9742e59e3634f19e5787633ce6 [file] [log] [blame]
Vince Lehman8a4c29e2016-07-11 08:49:35 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -05002/*
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Vince Lehman8a4c29e2016-07-11 08:49:35 +00004 * 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.
10 *
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/>.
24 */
25
26#ifndef NFD_DAEMON_FW_ASF_PROBING_MODULE_HPP
27#define NFD_DAEMON_FW_ASF_PROBING_MODULE_HPP
28
29#include "asf-measurements.hpp"
30
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::fw::asf {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000032
33/** \brief ASF Probing Module
34 */
35class ProbingModule
36{
37public:
38 explicit
39 ProbingModule(AsfMeasurements& measurements);
40
41 void
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040042 scheduleProbe(const fib::Entry& fibEntry, time::milliseconds interval);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000043
Junxiao Shia6de4292016-07-12 02:08:10 +000044 Face*
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040045 getFaceToProbe(const Face& inFace, const Interest& interest,
46 const fib::Entry& fibEntry, const Face& faceUsed);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000047
48 bool
Saurab Dulal432be572021-01-26 12:09:29 -060049 isProbingNeeded(const fib::Entry& fibEntry, const Name& interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000050
51 void
Saurab Dulal432be572021-01-26 12:09:29 -060052 afterForwardingProbe(const fib::Entry& fibEntry, const Name& interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000053
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050054 void
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040055 setProbingInterval(time::milliseconds probingInterval);
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050056
57 time::milliseconds
58 getProbingInterval() const
59 {
60 return m_probingInterval;
61 }
62
Vince Lehman8a4c29e2016-07-11 08:49:35 +000063private:
64 // Used to associate FaceInfo with the face in a NextHop
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040065 using FaceInfoFacePair = std::pair<FaceInfo*, Face*>;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000066
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040067 struct FaceInfoCompare
68 {
69 bool
70 operator()(const FaceInfoFacePair& leftPair, const FaceInfoFacePair& rightPair) const
71 {
72 const FaceInfo& lhs = *leftPair.first;
73 const FaceInfo& rhs = *rightPair.first;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000074
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040075 // Sort by RTT: if a face has timed-out, rank it behind non-timed-out faces
76 return (!lhs.hasTimeout() && rhs.hasTimeout()) ||
77 (lhs.hasTimeout() == rhs.hasTimeout() && lhs.getSrtt() < rhs.getSrtt());
78 }
79 };
80
81 using FaceInfoFacePairSet = std::set<FaceInfoFacePair, FaceInfoCompare>;
82
83 static Face*
84 chooseFace(const FaceInfoFacePairSet& rankedFaces);
85
86 static double
Vince Lehman8a4c29e2016-07-11 08:49:35 +000087 getProbingProbability(uint64_t rank, uint64_t rankSum, uint64_t nFaces);
88
Vince Lehman8a4c29e2016-07-11 08:49:35 +000089public:
Davide Pesaventoe4b22382018-06-10 14:37:24 -040090 static constexpr time::milliseconds DEFAULT_PROBING_INTERVAL = 1_min;
91 static constexpr time::milliseconds MIN_PROBING_INTERVAL = 1_s;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000092
93private:
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050094 time::milliseconds m_probingInterval;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000095 AsfMeasurements& m_measurements;
96};
97
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040098} // namespace nfd::fw::asf
Vince Lehman8a4c29e2016-07-11 08:49:35 +000099
100#endif // NFD_DAEMON_FW_ASF_PROBING_MODULE_HPP