blob: cde9b44a926da41fab97ba30d8315ceac326a75a [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shi727ed292014-02-19 23:26:45 -070024
25#include "fw/broadcast-strategy.hpp"
26#include "strategy-tester.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070027#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070030
31namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070033
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture)
Junxiao Shi727ed292014-02-19 23:26:45 -070035
Junxiao Shi57f0f312014-03-16 11:52:20 -070036BOOST_AUTO_TEST_CASE(Forward2)
Junxiao Shi727ed292014-02-19 23:26:45 -070037{
Junxiao Shic041ca32014-02-25 20:01:15 -070038 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070039 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
40 BroadcastStrategyTester strategy(forwarder);
41
42 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
43 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
44 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
45 forwarder.addFace(face1);
46 forwarder.addFace(face2);
47 forwarder.addFace(face3);
48
49 Fib& fib = forwarder.getFib();
Junxiao Shi57f0f312014-03-16 11:52:20 -070050 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -070051 fibEntry->addNextHop(face1, 0);
52 fibEntry->addNextHop(face2, 0);
53 fibEntry->addNextHop(face3, 0);
54
Junxiao Shi57f0f312014-03-16 11:52:20 -070055 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -070056 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -070057 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
58 pitEntry->insertOrUpdateInRecord(face3, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -070059
Junxiao Shi57f0f312014-03-16 11:52:20 -070060 strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -070061 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
Junxiao Shi727ed292014-02-19 23:26:45 -070062 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
63 bool hasFace1 = false;
64 bool hasFace2 = false;
65 for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it =
66 strategy.m_sendInterestHistory.begin();
67 it != strategy.m_sendInterestHistory.end(); ++it) {
68 if (it->get<1>() == face1) {
69 hasFace1 = true;
70 }
71 if (it->get<1>() == face2) {
72 hasFace2 = true;
73 }
74 }
75 BOOST_CHECK(hasFace1 && hasFace2);
76}
77
Junxiao Shi57f0f312014-03-16 11:52:20 -070078BOOST_AUTO_TEST_CASE(RejectScope)
79{
80 Forwarder forwarder;
81 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
82 BroadcastStrategyTester strategy(forwarder);
83
84 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
85 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
86 forwarder.addFace(face1);
87 forwarder.addFace(face2);
88
89 Fib& fib = forwarder.getFib();
90 shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first;
91 fibEntry->addNextHop(face2, 0);
92
93 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
94 Pit& pit = forwarder.getPit();
95 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
96 pitEntry->insertOrUpdateInRecord(face1, *interest);
97
98 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
99 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
100 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
101}
102
103BOOST_AUTO_TEST_CASE(RejectLoopback)
Junxiao Shi727ed292014-02-19 23:26:45 -0700104{
Junxiao Shic041ca32014-02-25 20:01:15 -0700105 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -0700106 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
107 BroadcastStrategyTester strategy(forwarder);
108
109 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
110 forwarder.addFace(face1);
111
112 Fib& fib = forwarder.getFib();
Junxiao Shi57f0f312014-03-16 11:52:20 -0700113 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -0700114 fibEntry->addNextHop(face1, 0);
115
Junxiao Shi57f0f312014-03-16 11:52:20 -0700116 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -0700117 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -0700118 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
119 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -0700120
Junxiao Shi57f0f312014-03-16 11:52:20 -0700121 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -0700122 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
Junxiao Shi727ed292014-02-19 23:26:45 -0700123 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
124}
125
126BOOST_AUTO_TEST_SUITE_END()
127
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700128} // namespace tests
Junxiao Shi727ed292014-02-19 23:26:45 -0700129} // namespace nfd