blob: e4417ce54f236bf3b290edd5f0e19ecc5efddfd9 [file] [log] [blame]
Junxiao Shi192af1f2015-01-13 23:19:39 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Junxiao Shia788e252015-01-28 17:06:25 -070026#include "fw/retx-suppression.hpp"
27#include "fw/retx-suppression-fixed.hpp"
Junxiao Shi192af1f2015-01-13 23:19:39 -070028#include "strategy-tester.hpp"
29
30#include "tests/test-common.hpp"
31#include "tests/daemon/face/dummy-face.hpp"
32
33namespace nfd {
34namespace tests {
35
Junxiao Shia788e252015-01-28 17:06:25 -070036using fw::RetxSuppression;
37using fw::RetxSuppressionFixed;
Junxiao Shi192af1f2015-01-13 23:19:39 -070038
Junxiao Shia788e252015-01-28 17:06:25 -070039BOOST_FIXTURE_TEST_SUITE(FwRetxSuppression, UnitTestTimeFixture)
Junxiao Shi192af1f2015-01-13 23:19:39 -070040
Junxiao Shia788e252015-01-28 17:06:25 -070041BOOST_AUTO_TEST_CASE(Fixed)
Junxiao Shi192af1f2015-01-13 23:19:39 -070042{
43 Forwarder forwarder;
44 Pit& pit = forwarder.getPit();
Junxiao Shia788e252015-01-28 17:06:25 -070045 static const time::milliseconds MIN_RETX_INTERVAL(200);
46 RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
Junxiao Shi192af1f2015-01-13 23:19:39 -070047
48 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
49 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
50 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
51 forwarder.addFace(face1);
52 forwarder.addFace(face2);
53 forwarder.addFace(face3);
54
55 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
56 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
57
Junxiao Shia788e252015-01-28 17:06:25 -070058 const time::nanoseconds RETRANSMISSION_10P =
59 time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
Junxiao Shi192af1f2015-01-13 23:19:39 -070060
61 // @ time 0
62 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070063 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW);
Junxiao Shi192af1f2015-01-13 23:19:39 -070064 pitEntry->insertOrUpdateOutRecord(face3, *interest);
65
66 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
67 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070068 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070069 pitEntry->insertOrUpdateInRecord(face2, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070070 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070071
72 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
73 pitEntry->insertOrUpdateInRecord(face2, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070074 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070075 // but strategy decides not to forward
76
77 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
78 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070079 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070080 // retransmission suppress shall still give clearance for forwarding
81 pitEntry->insertOrUpdateOutRecord(face3, *interest); // and strategy forwards
82
83 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
84 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070085 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070086 pitEntry->insertOrUpdateInRecord(face2, *interest);
Junxiao Shia788e252015-01-28 17:06:25 -070087 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070088}
89
90BOOST_AUTO_TEST_SUITE_END()
91
92} // namespace tests
93} // namespace nfd