fw: use ndn-cxx's RttEstimator in AccessStrategy
Refs: #4887
Change-Id: I7e404df953f99374e676c7eb29897c45d0868eef
diff --git a/daemon/face/lp-reliability.cpp b/daemon/face/lp-reliability.cpp
index 4489f6c..310f78e 100644
--- a/daemon/face/lp-reliability.cpp
+++ b/daemon/face/lp-reliability.cpp
@@ -114,7 +114,7 @@
if (frag.retxCount == 0) {
// This sequence had no retransmissions, so use it to estimate the RTO
- m_rttEst.addMeasurement(now - frag.sendTime, 1);
+ m_rttEst.addMeasurement(now - frag.sendTime);
}
// Look for frags with TxSequence numbers < ackSeq (allowing for wraparound) and consider them
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index b82ba40..6ae2767 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -36,7 +36,8 @@
AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name)
: Strategy(forwarder)
- , m_removeFaceInfoConn(beforeRemoveFace.connect([this] (const Face& face) { removeFaceInfo(face); }))
+ , m_rttEstimatorOpts(make_shared<RttEstimator::Options>()) // use the default options
+ , m_removeFaceConn(beforeRemoveFace.connect([this] (const Face& face) { m_fit.erase(face.getId()); }))
{
ParsedInstanceName parsed = parseInstanceName(name);
if (!parsed.parameters.empty()) {
@@ -139,7 +140,7 @@
return false;
}
- auto rto = mi.rtt.computeRto();
+ auto rto = mi.rtt.getEstimatedRto();
NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << mi.lastNexthop
<< " last-nexthop rto=" << time::duration_cast<time::microseconds>(rto).count());
@@ -147,10 +148,11 @@
// schedule RTO timeout
PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first;
- pi->rtoTimer = getScheduler().schedule(rto, [=] {
- afterRtoTimeout(weak_ptr<pit::Entry>(pitEntry),
- ingress.face.getId(), ingress.endpoint, mi.lastNexthop);
- });
+ pi->rtoTimer = getScheduler().schedule(rto,
+ [this, pitWeak = weak_ptr<pit::Entry>(pitEntry), face = ingress.face.getId(),
+ endpoint = ingress.endpoint, lastNexthop = mi.lastNexthop] {
+ afterRtoTimeout(pitWeak, face, endpoint, lastNexthop);
+ });
return true;
}
@@ -226,15 +228,16 @@
auto rtt = time::steady_clock::now() - outRecord->getLastRenewed();
NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << ingress
<< " rtt=" << time::duration_cast<time::microseconds>(rtt).count());
- this->updateMeasurements(ingress.face, data, time::duration_cast<RttEstimator::Duration>(rtt));
+ this->updateMeasurements(ingress.face, data, rtt);
}
void
-AccessStrategy::updateMeasurements(const Face& inFace, const Data& data,
- const RttEstimator::Duration& rtt)
+AccessStrategy::updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt)
{
- ///\todo move FaceInfoTable out of AccessStrategy instance, to Measurements or somewhere else
- FaceInfo& fi = m_fit[inFace.getId()];
+ auto ret = m_fit.emplace(std::piecewise_construct,
+ std::forward_as_tuple(inFace.getId()),
+ std::forward_as_tuple(m_rttEstimatorOpts));
+ FaceInfo& fi = ret.first->second;
fi.rtt.addMeasurement(rtt);
MtInfo* mi = this->addPrefixMeasurements(data);
@@ -276,14 +279,7 @@
}
this->getMeasurements().extendLifetime(*me, 8_s);
-
- return me->insertStrategyInfo<MtInfo>().first;
-}
-
-void
-AccessStrategy::removeFaceInfo(const Face& face)
-{
- m_fit.erase(face.getId());
+ return me->insertStrategyInfo<MtInfo>(m_rttEstimatorOpts).first;
}
} // namespace fw
diff --git a/daemon/fw/access-strategy.hpp b/daemon/fw/access-strategy.hpp
index 857592b..0ce8917 100644
--- a/daemon/fw/access-strategy.hpp
+++ b/daemon/fw/access-strategy.hpp
@@ -28,7 +28,8 @@
#include "strategy.hpp"
#include "retx-suppression-fixed.hpp"
-#include "core/rtt-estimator.hpp"
+
+#include <ndn-cxx/util/rtt-estimator.hpp>
namespace nfd {
namespace fw {
@@ -65,6 +66,8 @@
const FaceEndpoint& ingress, const Data& data) override;
private: // StrategyInfo
+ using RttEstimator = ndn::util::RttEstimator;
+
/** \brief StrategyInfo on PIT entry
*/
class PitInfo : public StrategyInfo
@@ -91,9 +94,15 @@
return 1011;
}
+ explicit
+ MtInfo(shared_ptr<const RttEstimator::Options> opts)
+ : rtt(std::move(opts))
+ {
+ }
+
public:
FaceId lastNexthop = face::INVALID_FACEID;
- RttEstimator rtt{1, 1_ms, 0.1};
+ RttEstimator rtt;
};
/** \brief find per-prefix measurements for Interest
@@ -108,17 +117,22 @@
addPrefixMeasurements(const Data& data);
/** \brief global per-face StrategyInfo
+ * \todo Currently stored inside AccessStrategy instance; should be moved
+ * to measurements table or somewhere else.
*/
- struct FaceInfo
+ class FaceInfo
{
- RttEstimator rtt{1, 1_ms, 0.1};
+ public:
+ explicit
+ FaceInfo(shared_ptr<const RttEstimator::Options> opts)
+ : rtt(std::move(opts))
+ {
+ }
+
+ public:
+ RttEstimator rtt;
};
- typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
-
- void
- removeFaceInfo(const Face& face);
-
private: // forwarding procedures
void
afterReceiveNewInterest(const FaceEndpoint& ingress, const Interest& interest,
@@ -141,8 +155,8 @@
FaceId inFaceId, EndpointId inEndpointId, FaceId firstOutFaceId);
/** \brief multicast to all nexthops
- * \param exceptFace don't forward to this face; also, inFace is always excluded
- * \return how many Interests are sent
+ * \param exceptFace don't forward to this face; also, \p inFace is always excluded
+ * \return number of Interests that were sent
*/
size_t
multicast(const Face& inFace, const Interest& interest,
@@ -150,13 +164,13 @@
FaceId exceptFace = face::INVALID_FACEID);
void
- updateMeasurements(const Face& inFace, const Data& data,
- const RttEstimator::Duration& rtt);
+ updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt);
private:
- FaceInfoTable m_fit;
+ const shared_ptr<const RttEstimator::Options> m_rttEstimatorOpts;
+ std::unordered_map<FaceId, FaceInfo> m_fit;
RetxSuppressionFixed m_retxSuppression;
- signal::ScopedConnection m_removeFaceInfoConn;
+ signal::ScopedConnection m_removeFaceConn;
};
} // namespace fw