blob: 98ee12c125ab54696923e6dcee40834c169120cf [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2024, 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 <http://www.gnu.org/licenses/>.
*/
#include "fw/retx-suppression-fixed.hpp"
#include "fw/retx-suppression-exponential.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/global-io-fixture.hpp"
#include "tests/daemon/face/dummy-face.hpp"
namespace nfd::tests {
using namespace nfd::fw;
BOOST_AUTO_TEST_SUITE(Fw)
BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, GlobalIoTimeFixture)
BOOST_AUTO_TEST_CASE(Fixed)
{
FaceTable faceTable;
Forwarder forwarder(faceTable);
Pit& pit = forwarder.getPit();
static const time::milliseconds MIN_RETX_INTERVAL(200);
RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
faceTable.add(face1);
faceTable.add(face2);
faceTable.add(face3);
shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
const time::nanoseconds RETRANSMISSION_10P =
time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
// @ time 0
pitEntry->insertOrUpdateInRecord(*face1, *interest);
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(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
pitEntry->insertOrUpdateInRecord(*face2, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
pitEntry->insertOrUpdateInRecord(*face2, *interest);
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(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(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
pitEntry->insertOrUpdateInRecord(*face2, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
}
BOOST_AUTO_TEST_CASE(Exponential)
{
FaceTable faceTable;
Forwarder forwarder(faceTable);
Pit& pit = forwarder.getPit();
RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
faceTable.add(face1);
faceTable.add(face2);
shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
// @ 0ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
pitEntry->insertOrUpdateOutRecord(*face2, *interest);
// suppression interval is 10ms, until 10ms
this->advanceClocks(5_ms); // @ 5ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
// suppression interval is 10ms, until 10ms
this->advanceClocks(6_ms); // @ 11ms
// note: what happens at *exactly* 10ms does not matter so it's untested,
// 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(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
pitEntry->insertOrUpdateOutRecord(*face2, *interest);
// suppression interval is 30ms, until 41ms
this->advanceClocks(25_ms); // @ 36ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
// suppression interval is 30ms, until 41ms
this->advanceClocks(6_ms); // @ 42ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
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(58_ms); // @ 100ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
// suppression interval is 90ms, until 101ms
this->advanceClocks(3_ms); // @ 103ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
pitEntry->insertOrUpdateOutRecord(*face2, *interest);
// suppression interval is 100ms, until 203ms
this->advanceClocks(99_ms); // @ 202ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
// suppression interval is 100ms, until 203ms
this->advanceClocks(2_ms); // @ 204ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
pitEntry->insertOrUpdateOutRecord(*face2, *interest);
// suppression interval is 100ms, until 304ms
}
BOOST_AUTO_TEST_CASE(ExponentialPerUpstream)
{
FaceTable faceTable;
Forwarder forwarder(faceTable);
Pit& pit = forwarder.getPit();
RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
faceTable.add(face1);
faceTable.add(face2);
shared_ptr<Interest> interest = makeInterest("ndn:/covfefeW6q");
shared_ptr<pit::Entry> 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(5_ms); // @ 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(6_ms); // @ 11ms
pitEntry->insertOrUpdateInRecord(*face1, *interest);
BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD);
// Assume interest is sent and increment interval
rs.incrementIntervalForOutRecord(*pitEntry->findOutRecord(*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
} // namespace nfd::tests