face: use ndn-cxx's RttEstimator in LpReliability
Refs: #4887
Change-Id: Iaf8b04e33de363bae2c99f10f3866773c900f30d
diff --git a/daemon/face/lp-reliability.cpp b/daemon/face/lp-reliability.cpp
index f19f713..4489f6c 100644
--- a/daemon/face/lp-reliability.cpp
+++ b/daemon/face/lp-reliability.cpp
@@ -36,7 +36,6 @@
, m_linkService(linkService)
, m_firstUnackedFrag(m_unackedFrags.begin())
, m_lastTxSeqNo(-1) // set to "-1" to start TxSequence numbers at 0
- , m_isIdleAckTimerRunning(false)
{
BOOST_ASSERT(m_linkService != nullptr);
BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns);
@@ -48,7 +47,7 @@
BOOST_ASSERT(options.idleAckTimerPeriod > 0_ns);
if (m_options.isEnabled && !options.isEnabled) {
- this->stopIdleAckTimer();
+ m_idleAckTimer.cancel();
}
m_options = options;
@@ -81,7 +80,7 @@
std::forward_as_tuple(txSeq),
std::forward_as_tuple(frag));
unackedFragsIt->second.sendTime = sendTime;
- unackedFragsIt->second.rtoTimer = getScheduler().schedule(m_rto.computeRto(),
+ unackedFragsIt->second.rtoTimer = getScheduler().schedule(m_rttEst.getEstimatedRto(),
[=] { onLpPacketLost(txSeq); });
unackedFragsIt->second.netPkt = netPkt;
@@ -114,8 +113,8 @@
frag.rtoTimer.cancel();
if (frag.retxCount == 0) {
- // This sequence had no retransmissions, so use it to calculate the RTO
- m_rto.addMeasurement(time::duration_cast<RttEstimator::Duration>(now - frag.sendTime));
+ // This sequence had no retransmissions, so use it to estimate the RTO
+ m_rttEst.addMeasurement(now - frag.sendTime, 1);
}
// Look for frags with TxSequence numbers < ackSeq (allowing for wraparound) and consider them
@@ -136,7 +135,7 @@
// Resend or fail fragments considered lost. Potentially increment the start of the window.
for (lp::Sequence txSeq : lostLpPackets) {
if (removedLpPackets.find(txSeq) == removedLpPackets.end()) {
- auto removedThisTxSeq = this->onLpPacketLost(txSeq);
+ auto removedThisTxSeq = onLpPacketLost(txSeq);
for (auto removedTxSeq : removedThisTxSeq) {
removedLpPackets.insert(removedTxSeq);
}
@@ -147,9 +146,7 @@
// If packet has Fragment and TxSequence fields, extract TxSequence and add to AckQueue
if (pkt.has<lp::FragmentField>() && pkt.has<lp::TxSequenceField>()) {
m_ackQueue.push(pkt.get<lp::TxSequenceField>());
- if (!m_isIdleAckTimerRunning) {
- this->startIdleAckTimer();
- }
+ startIdleAckTimer();
}
}
@@ -168,7 +165,7 @@
while (!m_ackQueue.empty()) {
lp::Sequence ackSeq = m_ackQueue.front();
- // Ack size = Ack TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + uint64_t (8 octets)
+ // Ack size = Ack TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
const ssize_t ackSize = tlv::sizeOfVarNumber(lp::tlv::Ack) +
tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
sizeof(lp::Sequence);
@@ -197,25 +194,18 @@
void
LpReliability::startIdleAckTimer()
{
- BOOST_ASSERT(!m_isIdleAckTimerRunning);
- m_isIdleAckTimerRunning = true;
+ if (m_idleAckTimer) {
+ // timer is already running, do nothing
+ return;
+ }
m_idleAckTimer = getScheduler().schedule(m_options.idleAckTimerPeriod, [this] {
while (!m_ackQueue.empty()) {
m_linkService->requestIdlePacket(0);
}
-
- m_isIdleAckTimerRunning = false;
});
}
-void
-LpReliability::stopIdleAckTimer()
-{
- m_idleAckTimer.cancel();
- m_isIdleAckTimerRunning = false;
-}
-
std::vector<lp::Sequence>
LpReliability::findLostLpPackets(LpReliability::UnackedFrags::iterator ackIt)
{
@@ -305,7 +295,8 @@
m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt), 0);
// Start RTO timer for this sequence
- newTxFrag.rtoTimer = getScheduler().schedule(m_rto.computeRto(), [=] { onLpPacketLost(newTxSeq); });
+ newTxFrag.rtoTimer = getScheduler().schedule(m_rttEst.getEstimatedRto(),
+ [=] { onLpPacketLost(newTxSeq); });
}
return removedThisTxSeq;
diff --git a/daemon/face/lp-reliability.hpp b/daemon/face/lp-reliability.hpp
index 5018730..ca8f360 100644
--- a/daemon/face/lp-reliability.hpp
+++ b/daemon/face/lp-reliability.hpp
@@ -26,10 +26,11 @@
#ifndef NFD_DAEMON_FACE_LP_RELIABILITY_HPP
#define NFD_DAEMON_FACE_LP_RELIABILITY_HPP
-#include "core/rtt-estimator.hpp"
+#include "core/common.hpp"
#include <ndn-cxx/lp/packet.hpp>
#include <ndn-cxx/lp/sequence.hpp>
+#include <ndn-cxx/util/rtt-estimator.hpp>
#include <queue>
@@ -126,11 +127,6 @@
void
startIdleAckTimer();
- /** \brief cancel the idle Ack timer
- */
- void
- stopIdleAckTimer();
-
/** \brief find and mark as lost fragments where a configurable number of Acks
* (\p m_options.seqNumLossThreshold) have been received for greater TxSequence numbers
* \param ackIt iterator pointing to acknowledged fragment
@@ -198,8 +194,10 @@
};
public:
- /// TxSequence TLV-TYPE (3 octets) + TxSequence TLV-LENGTH (1 octet) + sizeof(lp::Sequence)
- static constexpr size_t RESERVED_HEADER_SPACE = 3 + 1 + sizeof(lp::Sequence);
+ /// TxSequence TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
+ static constexpr size_t RESERVED_HEADER_SPACE = tlv::sizeOfVarNumber(lp::tlv::TxSequence) +
+ tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
+ sizeof(lp::Sequence);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Options m_options;
@@ -214,8 +212,7 @@
std::queue<lp::Sequence> m_ackQueue;
lp::Sequence m_lastTxSeqNo;
scheduler::ScopedEventId m_idleAckTimer;
- bool m_isIdleAckTimerRunning;
- RttEstimator m_rto;
+ ndn::util::RttEstimator m_rttEst;
};
} // namespace face