fw: abstract retransmission suppression logic
Consumer retransmission suppression logic of best-route v2 strategy
is abstracted into RetransmissionSuppression class, so that it can
be reused in other strategies.
refs #2377
Change-Id: I7de2c2d0e60c5ad3467e24283e9b03bd03f65bdc
diff --git a/tests/daemon/fw/retransmission-suppression.cpp b/tests/daemon/fw/retransmission-suppression.cpp
new file mode 100644
index 0000000..c1ba968
--- /dev/null
+++ b/tests/daemon/fw/retransmission-suppression.cpp
@@ -0,0 +1,90 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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/retransmission-suppression.hpp"
+#include "strategy-tester.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/daemon/face/dummy-face.hpp"
+
+namespace nfd {
+namespace tests {
+
+using fw::RetransmissionSuppression;
+
+BOOST_FIXTURE_TEST_SUITE(FwRetransmissionSuppression, UnitTestTimeFixture)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ Forwarder forwarder;
+ Pit& pit = forwarder.getPit();
+ RetransmissionSuppression rs;
+
+ shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
+ shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
+ shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(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>(
+ fw::RetransmissionSuppression::MIN_RETRANSMISSION_INTERVAL * 0.1);
+
+ // @ time 0
+ pitEntry->insertOrUpdateInRecord(face1, *interest);
+ BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetransmissionSuppression::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), RetransmissionSuppression::SUPPRESS);
+ pitEntry->insertOrUpdateInRecord(face2, *interest);
+ BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
+
+ this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
+ pitEntry->insertOrUpdateInRecord(face2, *interest);
+ BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::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), RetransmissionSuppression::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), RetransmissionSuppression::SUPPRESS);
+ pitEntry->insertOrUpdateInRecord(face2, *interest);
+ BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd