blob: c1ba968f18f9cd9f1eb17ccf8be0d3a0a0ec5800 [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
26#include "fw/retransmission-suppression.hpp"
27#include "strategy-tester.hpp"
28
29#include "tests/test-common.hpp"
30#include "tests/daemon/face/dummy-face.hpp"
31
32namespace nfd {
33namespace tests {
34
35using fw::RetransmissionSuppression;
36
37BOOST_FIXTURE_TEST_SUITE(FwRetransmissionSuppression, UnitTestTimeFixture)
38
39BOOST_AUTO_TEST_CASE(Basic)
40{
41 Forwarder forwarder;
42 Pit& pit = forwarder.getPit();
43 RetransmissionSuppression rs;
44
45 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
46 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
47 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
48 forwarder.addFace(face1);
49 forwarder.addFace(face2);
50 forwarder.addFace(face3);
51
52 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
53 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
54
55 const time::nanoseconds RETRANSMISSION_10P = time::duration_cast<time::nanoseconds>(
56 fw::RetransmissionSuppression::MIN_RETRANSMISSION_INTERVAL * 0.1);
57
58 // @ time 0
59 pitEntry->insertOrUpdateInRecord(face1, *interest);
60 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetransmissionSuppression::NEW);
61 pitEntry->insertOrUpdateOutRecord(face3, *interest);
62
63 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
64 pitEntry->insertOrUpdateInRecord(face1, *interest);
65 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
66 pitEntry->insertOrUpdateInRecord(face2, *interest);
67 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
68
69 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
70 pitEntry->insertOrUpdateInRecord(face2, *interest);
71 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::FORWARD);
72 // but strategy decides not to forward
73
74 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
75 pitEntry->insertOrUpdateInRecord(face1, *interest);
76 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetransmissionSuppression::FORWARD);
77 // retransmission suppress shall still give clearance for forwarding
78 pitEntry->insertOrUpdateOutRecord(face3, *interest); // and strategy forwards
79
80 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
81 pitEntry->insertOrUpdateInRecord(face1, *interest);
82 BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
83 pitEntry->insertOrUpdateInRecord(face2, *interest);
84 BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetransmissionSuppression::SUPPRESS);
85}
86
87BOOST_AUTO_TEST_SUITE_END()
88
89} // namespace tests
90} // namespace nfd