blob: ad47daa7783cd143fcda99b75e8234b59897d0eb [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080024 */
Junxiao Shi727ed292014-02-19 23:26:45 -070025
26#include "fw/broadcast-strategy.hpp"
27#include "strategy-tester.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070028#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070029
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030#include "tests/test-common.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070031
32namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080033namespace fw {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070035
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080036using namespace nfd::tests;
37
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture)
Junxiao Shi727ed292014-02-19 23:26:45 -070039
Junxiao Shi57f0f312014-03-16 11:52:20 -070040BOOST_AUTO_TEST_CASE(Forward2)
Junxiao Shi727ed292014-02-19 23:26:45 -070041{
Junxiao Shic041ca32014-02-25 20:01:15 -070042 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070043 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
44 BroadcastStrategyTester strategy(forwarder);
45
46 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
47 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
48 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
49 forwarder.addFace(face1);
50 forwarder.addFace(face2);
51 forwarder.addFace(face3);
52
53 Fib& fib = forwarder.getFib();
Junxiao Shi57f0f312014-03-16 11:52:20 -070054 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -070055 fibEntry->addNextHop(face1, 0);
56 fibEntry->addNextHop(face2, 0);
57 fibEntry->addNextHop(face3, 0);
58
Junxiao Shi57f0f312014-03-16 11:52:20 -070059 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -070060 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -070061 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
62 pitEntry->insertOrUpdateInRecord(face3, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -070063
Junxiao Shi57f0f312014-03-16 11:52:20 -070064 strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -070065 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
Junxiao Shi727ed292014-02-19 23:26:45 -070066 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
67 bool hasFace1 = false;
68 bool hasFace2 = false;
69 for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it =
70 strategy.m_sendInterestHistory.begin();
71 it != strategy.m_sendInterestHistory.end(); ++it) {
72 if (it->get<1>() == face1) {
73 hasFace1 = true;
74 }
75 if (it->get<1>() == face2) {
76 hasFace2 = true;
77 }
78 }
79 BOOST_CHECK(hasFace1 && hasFace2);
80}
81
Junxiao Shi57f0f312014-03-16 11:52:20 -070082BOOST_AUTO_TEST_CASE(RejectScope)
83{
84 Forwarder forwarder;
85 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
86 BroadcastStrategyTester strategy(forwarder);
87
88 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
89 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
90 forwarder.addFace(face1);
91 forwarder.addFace(face2);
92
93 Fib& fib = forwarder.getFib();
94 shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first;
95 fibEntry->addNextHop(face2, 0);
96
97 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
98 Pit& pit = forwarder.getPit();
99 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
100 pitEntry->insertOrUpdateInRecord(face1, *interest);
101
102 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
103 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
104 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
105}
106
107BOOST_AUTO_TEST_CASE(RejectLoopback)
Junxiao Shi727ed292014-02-19 23:26:45 -0700108{
Junxiao Shic041ca32014-02-25 20:01:15 -0700109 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -0700110 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
111 BroadcastStrategyTester strategy(forwarder);
112
113 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
114 forwarder.addFace(face1);
115
116 Fib& fib = forwarder.getFib();
Junxiao Shi57f0f312014-03-16 11:52:20 -0700117 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -0700118 fibEntry->addNextHop(face1, 0);
119
Junxiao Shi57f0f312014-03-16 11:52:20 -0700120 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -0700121 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -0700122 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
123 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -0700124
Junxiao Shi57f0f312014-03-16 11:52:20 -0700125 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -0700126 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
Junxiao Shi727ed292014-02-19 23:26:45 -0700127 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
128}
129
130BOOST_AUTO_TEST_SUITE_END()
131
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700132} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800133} // namespace fw
Junxiao Shi727ed292014-02-19 23:26:45 -0700134} // namespace nfd