From 90015991bc02bf975944ecbf9c68910773e03d77 Mon Sep 17 00:00:00 2001 From: Ashlesh Gawande Date: Tue, 11 Jul 2017 17:25:48 -0500 Subject: [PATCH] fw: per upstream retx exponential suppression for multicast strategy refs: #4066 Change-Id: Ic1047b871dc9dc040e95ac5edceaae9994cd2849 --- daemon/fw/access-strategy.cpp | 12 ++-- daemon/fw/algorithm.cpp | 17 ++++- daemon/fw/algorithm.hpp | 6 ++ daemon/fw/asf-strategy.cpp | 10 +-- daemon/fw/best-route-strategy2.cpp | 8 +-- daemon/fw/multicast-strategy.cpp | 40 ++++++----- daemon/fw/retx-suppression-exponential.cpp | 53 ++++++++++++--- daemon/fw/retx-suppression-exponential.hpp | 25 +++++-- daemon/fw/retx-suppression-fixed.cpp | 16 ++--- daemon/fw/retx-suppression-fixed.hpp | 12 ++-- daemon/fw/retx-suppression.cpp | 45 ------------- daemon/fw/retx-suppression.hpp | 43 ++++-------- tests/daemon/fw/algorithm.t.cpp | 24 ++++++- tests/daemon/fw/retx-suppression.t.cpp | 78 ++++++++++++++++------ 14 files changed, 224 insertions(+), 165 deletions(-) delete mode 100644 daemon/fw/retx-suppression.cpp diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp index b391ba9a..2176f2f3 100644 --- a/daemon/fw/access-strategy.cpp +++ b/daemon/fw/access-strategy.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -60,15 +60,15 @@ void AccessStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, const shared_ptr& pitEntry) { - RetxSuppression::Result suppressResult = m_retxSuppression.decide(inFace, interest, *pitEntry); + RetxSuppressionResult suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry); switch (suppressResult) { - case RetxSuppression::NEW: + case RetxSuppressionResult::NEW: this->afterReceiveNewInterest(inFace, interest, pitEntry); break; - case RetxSuppression::FORWARD: + case RetxSuppressionResult::FORWARD: this->afterReceiveRetxInterest(inFace, interest, pitEntry); break; - case RetxSuppression::SUPPRESS: + case RetxSuppressionResult::SUPPRESS: NFD_LOG_DEBUG(interest << " interestFrom " << inFace.getId() << " retx-suppress"); break; default: diff --git a/daemon/fw/algorithm.cpp b/daemon/fw/algorithm.cpp index 320a92aa..db2c4cf5 100644 --- a/daemon/fw/algorithm.cpp +++ b/daemon/fw/algorithm.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -120,5 +120,18 @@ hasPendingOutRecords(const pit::Entry& pitEntry) }); } +time::steady_clock::TimePoint +getLastOutgoing(const pit::Entry& pitEntry) +{ + pit::OutRecordCollection::const_iterator lastOutgoing = std::max_element( + pitEntry.out_begin(), pitEntry.out_end(), + [] (const pit::OutRecord& a, const pit::OutRecord& b) { + return a.getLastRenewed() < b.getLastRenewed(); + }); + BOOST_ASSERT(lastOutgoing != pitEntry.out_end()); + + return lastOutgoing->getLastRenewed(); +} + } // namespace fw } // namespace nfd diff --git a/daemon/fw/algorithm.hpp b/daemon/fw/algorithm.hpp index 480fcab1..c696d166 100644 --- a/daemon/fw/algorithm.hpp +++ b/daemon/fw/algorithm.hpp @@ -108,6 +108,12 @@ findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face) bool hasPendingOutRecords(const pit::Entry& pitEntry); +/** \return last out-record time + * \pre pitEntry has one or more unexpired out-records + */ +time::steady_clock::TimePoint +getLastOutgoing(const pit::Entry& pitEntry); + } // namespace fw } // namespace nfd diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp index baf8230a..ffeaead8 100644 --- a/daemon/fw/asf-strategy.cpp +++ b/daemon/fw/asf-strategy.cpp @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** +/* * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, @@ -69,13 +69,13 @@ AsfStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, const shared_ptr& pitEntry) { // Should the Interest be suppressed? - RetxSuppression::Result suppressResult = m_retxSuppression.decide(inFace, interest, *pitEntry); + RetxSuppressionResult suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry); switch (suppressResult) { - case RetxSuppression::NEW: - case RetxSuppression::FORWARD: + case RetxSuppressionResult::NEW: + case RetxSuppressionResult::FORWARD: break; - case RetxSuppression::SUPPRESS: + case RetxSuppressionResult::SUPPRESS: NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " suppressed"); return; } diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp index 11add678..5f12ed25 100644 --- a/daemon/fw/best-route-strategy2.cpp +++ b/daemon/fw/best-route-strategy2.cpp @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** +/* * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, @@ -124,8 +124,8 @@ void BestRouteStrategy2::afterReceiveInterest(const Face& inFace, const Interest& interest, const shared_ptr& pitEntry) { - RetxSuppression::Result suppression = m_retxSuppression.decide(inFace, interest, *pitEntry); - if (suppression == RetxSuppression::SUPPRESS) { + RetxSuppressionResult suppression = m_retxSuppression.decidePerPitEntry(*pitEntry); + if (suppression == RetxSuppressionResult::SUPPRESS) { NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " suppressed"); return; @@ -135,7 +135,7 @@ BestRouteStrategy2::afterReceiveInterest(const Face& inFace, const Interest& int const fib::NextHopList& nexthops = fibEntry.getNextHops(); fib::NextHopList::const_iterator it = nexthops.end(); - if (suppression == RetxSuppression::NEW) { + if (suppression == RetxSuppressionResult::NEW) { // forward to nexthop with lowest cost except downstream it = std::find_if(nexthops.begin(), nexthops.end(), bind(&isNextHopEligible, cref(inFace), interest, _1, pitEntry, diff --git a/daemon/fw/multicast-strategy.cpp b/daemon/fw/multicast-strategy.cpp index 7b38bc1a..f51693bb 100644 --- a/daemon/fw/multicast-strategy.cpp +++ b/daemon/fw/multicast-strategy.cpp @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** +/* * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, @@ -66,25 +66,25 @@ void MulticastStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, const shared_ptr& pitEntry) { - // Should the Interest be suppressed? - RetxSuppression::Result suppressResult = m_retxSuppression.decide(inFace, interest, *pitEntry); - switch (suppressResult) { - case RetxSuppression::NEW: - case RetxSuppression::FORWARD: - break; - case RetxSuppression::SUPPRESS: - NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " suppressed"); - return; - } - const fib::Entry& fibEntry = this->lookupFib(*pitEntry); const fib::NextHopList& nexthops = fibEntry.getNextHops(); int nEligibleNextHops = 0; + bool isSuppressed = false; + for (const auto& nexthop : nexthops) { Face& outFace = nexthop.getFace(); + RetxSuppressionResult suppressResult = m_retxSuppression.decidePerUpstream(*pitEntry, outFace); + + if (suppressResult == RetxSuppressionResult::SUPPRESS) { + NFD_LOG_DEBUG(interest << " from=" << inFace.getId() + << "to=" << outFace.getId() << " suppressed"); + isSuppressed = true; + continue; + } + if ((outFace.getId() == inFace.getId() && outFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) || wouldViolateScope(inFace, interest, outFace)) { continue; @@ -93,17 +93,21 @@ MulticastStrategy::afterReceiveInterest(const Face& inFace, const Interest& inte this->sendInterest(pitEntry, outFace, interest); NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " pitEntry-to=" << outFace.getId()); + + if (suppressResult == RetxSuppressionResult::FORWARD) { + m_retxSuppression.incrementIntervalForOutRecord(*pitEntry->getOutRecord(outFace)); + } ++nEligibleNextHops; } - if (nEligibleNextHops == 0) { - NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop"); + if (nEligibleNextHops == 0 && !isSuppressed) { + NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop"); - lp::NackHeader nackHeader; - nackHeader.setReason(lp::NackReason::NO_ROUTE); - this->sendNack(pitEntry, inFace, nackHeader); + lp::NackHeader nackHeader; + nackHeader.setReason(lp::NackReason::NO_ROUTE); + this->sendNack(pitEntry, inFace, nackHeader); - this->rejectPendingInterest(pitEntry); + this->rejectPendingInterest(pitEntry); } } diff --git a/daemon/fw/retx-suppression-exponential.cpp b/daemon/fw/retx-suppression-exponential.cpp index 28f6df5e..f2ff1b2b 100644 --- a/daemon/fw/retx-suppression-exponential.cpp +++ b/daemon/fw/retx-suppression-exponential.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -24,7 +24,6 @@ */ #include "retx-suppression-exponential.hpp" -#include "algorithm.hpp" namespace nfd { namespace fw { @@ -69,16 +68,15 @@ RetxSuppressionExponential::RetxSuppressionExponential(const Duration& initialIn BOOST_ASSERT(maxInterval >= initialInterval); } -RetxSuppression::Result -RetxSuppressionExponential::decide(const Face& inFace, const Interest& interest, - pit::Entry& pitEntry) const +RetxSuppressionResult +RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry) { bool isNewPitEntry = !hasPendingOutRecords(pitEntry); if (isNewPitEntry) { - return NEW; + return RetxSuppressionResult::NEW; } - time::steady_clock::TimePoint lastOutgoing = this->getLastOutgoing(pitEntry); + time::steady_clock::TimePoint lastOutgoing = getLastOutgoing(pitEntry); time::steady_clock::TimePoint now = time::steady_clock::now(); time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing; @@ -86,12 +84,45 @@ RetxSuppressionExponential::decide(const Face& inFace, const Interest& interest, bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval; if (shouldSuppress) { - return SUPPRESS; + return RetxSuppressionResult::SUPPRESS; } pi->suppressionInterval = std::min(m_maxInterval, - time::duration_cast(pi->suppressionInterval * m_multiplier)); - return FORWARD; + time::duration_cast(pi->suppressionInterval * m_multiplier)); + + return RetxSuppressionResult::FORWARD; +} + +RetxSuppressionResult +RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace) +{ + // NEW if outRecord for the face does not exist + auto outRecord = pitEntry.getOutRecord(outFace); + if (outRecord == pitEntry.out_end()) { + return RetxSuppressionResult::NEW; + } + + time::steady_clock::TimePoint lastOutgoing = outRecord->getLastRenewed(); + time::steady_clock::TimePoint now = time::steady_clock::now(); + time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing; + + // insertStrategyInfo does not insert m_initialInterval again if it already exists + PitInfo* pi = outRecord->insertStrategyInfo(m_initialInterval).first; + bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval; + + if (shouldSuppress) { + return RetxSuppressionResult::SUPPRESS; + } + + return RetxSuppressionResult::FORWARD; +} + +void +RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord) +{ + PitInfo* pi = outRecord.insertStrategyInfo(m_initialInterval).first; + pi->suppressionInterval = std::min(m_maxInterval, + time::duration_cast(pi->suppressionInterval * m_multiplier)); } } // namespace fw diff --git a/daemon/fw/retx-suppression-exponential.hpp b/daemon/fw/retx-suppression-exponential.hpp index a2fbe7bc..8455b5e1 100644 --- a/daemon/fw/retx-suppression-exponential.hpp +++ b/daemon/fw/retx-suppression-exponential.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,6 +26,7 @@ #ifndef NFD_DAEMON_FW_RETX_SUPPRESSION_EXPONENTIAL_HPP #define NFD_DAEMON_FW_RETX_SUPPRESSION_EXPONENTIAL_HPP +#include "algorithm.hpp" #include "retx-suppression.hpp" namespace nfd { @@ -37,7 +38,7 @@ namespace fw { * The i-th retransmission will be suppressed if the last transmission (out-record) * occurred within MIN(initialInterval * multiplier^(i-1), maxInterval) */ -class RetxSuppressionExponential : public RetxSuppression +class RetxSuppressionExponential { public: /** \brief time granularity @@ -49,12 +50,22 @@ public: float multiplier = DEFAULT_MULTIPLIER, const Duration& maxInterval = DEFAULT_MAX_INTERVAL); - /** \brief determines whether Interest is a retransmission, + /** \brief determines whether Interest is a retransmission per pit entry * and if so, whether it shall be forwarded or suppressed */ - virtual Result - decide(const Face& inFace, const Interest& interest, - pit::Entry& pitEntry) const override; + RetxSuppressionResult + decidePerPitEntry(pit::Entry& pitEntry); + + /** \brief determines whether Interest is a retransmission per upstream + * and if so, whether it shall be forwarded or suppressed + */ + RetxSuppressionResult + decidePerUpstream(pit::Entry& pitEntry, Face& outFace); + + /** \brief Increment the suppression interval for out record + */ + void + incrementIntervalForOutRecord(pit::OutRecord& outRecord); public: /** \brief StrategyInfo on pit::Entry diff --git a/daemon/fw/retx-suppression-fixed.cpp b/daemon/fw/retx-suppression-fixed.cpp index d2c74dca..6245ae35 100644 --- a/daemon/fw/retx-suppression-fixed.cpp +++ b/daemon/fw/retx-suppression-fixed.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -24,7 +24,6 @@ */ #include "retx-suppression-fixed.hpp" -#include "algorithm.hpp" namespace nfd { namespace fw { @@ -37,20 +36,19 @@ RetxSuppressionFixed::RetxSuppressionFixed(const time::milliseconds& minRetxInte BOOST_ASSERT(minRetxInterval > time::milliseconds::zero()); } -RetxSuppression::Result -RetxSuppressionFixed::decide(const Face& inFace, const Interest& interest, - pit::Entry& pitEntry) const +RetxSuppressionResult +RetxSuppressionFixed::decidePerPitEntry(pit::Entry& pitEntry) const { bool isNewPitEntry = !hasPendingOutRecords(pitEntry); if (isNewPitEntry) { - return NEW; + return RetxSuppressionResult::NEW; } - time::steady_clock::TimePoint lastOutgoing = this->getLastOutgoing(pitEntry); + time::steady_clock::TimePoint lastOutgoing = getLastOutgoing(pitEntry); time::steady_clock::TimePoint now = time::steady_clock::now(); time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing; bool shouldSuppress = sinceLastOutgoing < m_minRetxInterval; - return shouldSuppress ? SUPPRESS : FORWARD; + return shouldSuppress ? RetxSuppressionResult::SUPPRESS : RetxSuppressionResult::FORWARD; } } // namespace fw diff --git a/daemon/fw/retx-suppression-fixed.hpp b/daemon/fw/retx-suppression-fixed.hpp index 95baae1a..33ee765f 100644 --- a/daemon/fw/retx-suppression-fixed.hpp +++ b/daemon/fw/retx-suppression-fixed.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,6 +26,7 @@ #ifndef NFD_DAEMON_FW_RETX_SUPPRESSION_FIXED_HPP #define NFD_DAEMON_FW_RETX_SUPPRESSION_FIXED_HPP +#include "algorithm.hpp" #include "retx-suppression.hpp" namespace nfd { @@ -34,7 +35,7 @@ namespace fw { /** \brief a retransmission suppression decision algorithm that * suppresses retransmissions within a fixed duration */ -class RetxSuppressionFixed : public RetxSuppression +class RetxSuppressionFixed { public: explicit @@ -43,9 +44,8 @@ public: /** \brief determines whether Interest is a retransmission, * and if so, whether it shall be forwarded or suppressed */ - virtual Result - decide(const Face& inFace, const Interest& interest, - pit::Entry& pitEntry) const override; + RetxSuppressionResult + decidePerPitEntry(pit::Entry& pitEntry) const; public: static const time::milliseconds DEFAULT_MIN_RETX_INTERVAL; diff --git a/daemon/fw/retx-suppression.cpp b/daemon/fw/retx-suppression.cpp deleted file mode 100644 index 9ae122a6..00000000 --- a/daemon/fw/retx-suppression.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology, - * The University of Memphis. - * - * This file is part of NFD (Named Data Networking Forwarding Daemon). - * See AUTHORS.md for complete list of NFD authors and contributors. - * - * NFD is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * NFD, e.g., in COPYING.md file. If not, see . - */ - -#include "retx-suppression.hpp" - -namespace nfd { -namespace fw { - -time::steady_clock::TimePoint -RetxSuppression::getLastOutgoing(const pit::Entry& pitEntry) const -{ - pit::OutRecordCollection::const_iterator lastOutgoing = std::max_element( - pitEntry.out_begin(), pitEntry.out_end(), - [] (const pit::OutRecord& a, const pit::OutRecord& b) { - return a.getLastRenewed() < b.getLastRenewed(); - }); - BOOST_ASSERT(lastOutgoing != pitEntry.out_end()); // otherwise it's new PIT entry - - return lastOutgoing->getLastRenewed(); -} - -} // namespace fw -} // namespace nfd diff --git a/daemon/fw/retx-suppression.hpp b/daemon/fw/retx-suppression.hpp index edc2a6d4..ad983e7f 100644 --- a/daemon/fw/retx-suppression.hpp +++ b/daemon/fw/retx-suppression.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2015, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,42 +26,23 @@ #ifndef NFD_DAEMON_FW_RETX_SUPPRESSION_HPP #define NFD_DAEMON_FW_RETX_SUPPRESSION_HPP -#include "strategy.hpp" +#include "core/common.hpp" namespace nfd { namespace fw { -/** \brief helper for consumer retransmission suppression - */ -class RetxSuppression : noncopyable -{ -public: - enum Result { - /** \brief Interest is new (not a retransmission) - */ - NEW, - - /** \brief Interest is retransmission and should be forwarded - */ - FORWARD, - - /** \brief Interest is retransmission and should be suppressed - */ - SUPPRESS - }; - - /** \brief determines whether Interest is a retransmission, - * and if so, whether it shall be forwarded or suppressed +enum class RetxSuppressionResult { + /** \brief Interest is new (not a retransmission) */ - virtual Result - decide(const Face& inFace, const Interest& interest, pit::Entry& pitEntry) const = 0; + NEW, -protected: - /** \return last out-record time - * \pre pitEntry has one or more unexpired out-records + /** \brief Interest is retransmission and should be forwarded */ - time::steady_clock::TimePoint - getLastOutgoing(const pit::Entry& pitEntry) const; + FORWARD, + + /** \brief Interest is retransmission and should be suppressed + */ + SUPPRESS }; } // namespace fw diff --git a/tests/daemon/fw/algorithm.t.cpp b/tests/daemon/fw/algorithm.t.cpp index 0986d24e..8a188e62 100644 --- a/tests/daemon/fw/algorithm.t.cpp +++ b/tests/daemon/fw/algorithm.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -204,6 +204,26 @@ BOOST_FIXTURE_TEST_CASE(HasPendingOutRecords, UnitTestTimeFixture) BOOST_CHECK_EQUAL(hasPendingOutRecords(entry), false); } +BOOST_FIXTURE_TEST_CASE(GetLastOutgoing, UnitTestTimeFixture) +{ + auto face1 = make_shared(); + auto face2 = make_shared(); + + shared_ptr interest = makeInterest("ndn:/c1I7QCtc"); + pit::Entry entry(*interest); + + time::steady_clock::TimePoint before = time::steady_clock::now(); + + entry.insertOrUpdateOutRecord(*face1, *interest); + this->advanceClocks(time::milliseconds(1000)); + + BOOST_CHECK_EQUAL(getLastOutgoing(entry), before); + + entry.insertOrUpdateOutRecord(*face2, *interest); + + BOOST_CHECK_EQUAL(getLastOutgoing(entry), time::steady_clock::now()); +} + BOOST_AUTO_TEST_SUITE_END() // TestPitAlgorithm BOOST_AUTO_TEST_SUITE_END() // Fw diff --git a/tests/daemon/fw/retx-suppression.t.cpp b/tests/daemon/fw/retx-suppression.t.cpp index 604dfb15..dce6da94 100644 --- a/tests/daemon/fw/retx-suppression.t.cpp +++ b/tests/daemon/fw/retx-suppression.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2016, Regents of the University of California, +/* + * Copyright (c) 2014-2017, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -23,7 +23,7 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#include "fw/retx-suppression.hpp" +#include "fw/strategy.hpp" #include "fw/retx-suppression-fixed.hpp" #include "fw/retx-suppression-exponential.hpp" @@ -61,31 +61,31 @@ BOOST_AUTO_TEST_CASE(Fixed) // @ time 0 pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW); pitEntry->insertOrUpdateOutRecord(*face3, *interest); this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); pitEntry->insertOrUpdateInRecord(*face2, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval pitEntry->insertOrUpdateInRecord(*face2, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); // but strategy decides not to forward this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); // retransmission suppress shall still give clearance for forwarding pitEntry->insertOrUpdateOutRecord(*face3, *interest); // and strategy forwards this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); pitEntry->insertOrUpdateInRecord(*face2, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); } BOOST_AUTO_TEST_CASE(Exponential) @@ -104,13 +104,13 @@ BOOST_AUTO_TEST_CASE(Exponential) // @ 0ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW); pitEntry->insertOrUpdateOutRecord(*face2, *interest); // suppression interval is 10ms, until 10ms this->advanceClocks(time::milliseconds(5)); // @ 5ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); // suppression interval is 10ms, until 10ms this->advanceClocks(time::milliseconds(6)); // @ 11ms @@ -118,44 +118,84 @@ BOOST_AUTO_TEST_CASE(Exponential) // because in reality network timing won't be exact: // incoming Interest is processed either before or after 10ms point pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); pitEntry->insertOrUpdateOutRecord(*face2, *interest); // suppression interval is 30ms, until 41ms this->advanceClocks(time::milliseconds(25)); // @ 36ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); // suppression interval is 30ms, until 41ms this->advanceClocks(time::milliseconds(6)); // @ 42ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); // strategy decides not to forward, but suppression interval is increased nevertheless // suppression interval is 90ms, until 101ms this->advanceClocks(time::milliseconds(58)); // @ 100ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); // suppression interval is 90ms, until 101ms this->advanceClocks(time::milliseconds(3)); // @ 103ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); pitEntry->insertOrUpdateOutRecord(*face2, *interest); // suppression interval is 100ms, until 203ms this->advanceClocks(time::milliseconds(99)); // @ 202ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); // suppression interval is 100ms, until 203ms this->advanceClocks(time::milliseconds(2)); // @ 204ms pitEntry->insertOrUpdateInRecord(*face1, *interest); - BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); + BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); pitEntry->insertOrUpdateOutRecord(*face2, *interest); // suppression interval is 100ms, until 304ms } +BOOST_AUTO_TEST_CASE(ExponentialPerUpstream) +{ + Forwarder forwarder; + Pit& pit = forwarder.getPit(); + RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100)); + + shared_ptr face1 = make_shared(); + shared_ptr face2 = make_shared(); + forwarder.addFace(face1); + forwarder.addFace(face2); + + shared_ptr interest = makeInterest("ndn:/covfefeW6q"); + shared_ptr pitEntry = pit.insert(*interest).first; + + // @ 0ms + pitEntry->insertOrUpdateInRecord(*face1, *interest); + BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::NEW); + + // Simluate forwarding an interest to face2 + pitEntry->insertOrUpdateOutRecord(*face2, *interest); + this->advanceClocks(time::milliseconds(5)); // @ 5ms + + pitEntry->insertOrUpdateInRecord(*face1, *interest); + BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS); + + // Return NEW since no outRecord for face1 + pitEntry->insertOrUpdateInRecord(*face2, *interest); + BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face1) == RetxSuppressionResult::NEW); + + this->advanceClocks(time::milliseconds(6)); // @ 11ms + + pitEntry->insertOrUpdateInRecord(*face1, *interest); + BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD); + // Assume interest is sent and increment interval + rs.incrementIntervalForOutRecord(*pitEntry->getOutRecord(*face2)); + + pitEntry->insertOrUpdateInRecord(*face2, *interest); + BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS); +} + BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression BOOST_AUTO_TEST_SUITE_END() // Fw