blob: a8587583b1916d52718a5b3369a6995e3deaa8cd [file] [log] [blame]
Junxiao Shi36b22252016-08-25 13:22:21 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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/unsolicited-data-policy.hpp"
27#include "fw/forwarder.hpp"
28#include "tests/daemon/face/dummy-face.hpp"
29
30#include "tests/test-common.hpp"
31#include <boost/logic/tribool.hpp>
32#include <boost/mpl/vector.hpp>
33
34namespace nfd {
35namespace fw {
36namespace tests {
37
38using namespace nfd::tests;
39
40class UnsolicitedDataPolicyFixture : public UnitTestTimeFixture
41{
42protected:
43 UnsolicitedDataPolicyFixture()
44 : cs(forwarder.getCs())
45 {
46 }
47
48 /** \tparam Policy policy type, or void to keep default policy
49 */
50 template<typename Policy>
51 void
52 setPolicy()
53 {
54 forwarder.setUnsolicitedDataPolicy(make_unique<Policy>());
55 }
56
57 bool
58 isInCs(const Data& data)
59 {
60 using namespace boost::logic;
61
62 tribool isFound = indeterminate;
63 cs.find(Interest(data.getFullName()),
64 bind([&] { isFound = true; }),
65 bind([&] { isFound = false; }));
66
67 this->advanceClocks(time::milliseconds(1));
68 BOOST_REQUIRE(!indeterminate(isFound));
69 return isFound;
70 }
71
72protected:
73 Forwarder forwarder;
74 Cs& cs;
75};
76
77template<>
78void
79UnsolicitedDataPolicyFixture::setPolicy<void>()
80{
81 // void keeps the default policy
82}
83
84BOOST_AUTO_TEST_SUITE(Fw)
85BOOST_FIXTURE_TEST_SUITE(TestUnsolicitedDataPolicy, UnsolicitedDataPolicyFixture)
86
87template<typename Policy, bool shouldAdmitLocal, bool shouldAdmitNonLocal>
88struct FaceScopePolicyTest
89{
90 typedef Policy PolicyType;
91 typedef std::integral_constant<bool, shouldAdmitLocal> ShouldAdmitLocal;
92 typedef std::integral_constant<bool, shouldAdmitNonLocal> ShouldAdmitNonLocal;
93};
94
95typedef boost::mpl::vector<
96 FaceScopePolicyTest<void, true, false>, // default policy
97 FaceScopePolicyTest<DropAllUnsolicitedDataPolicy, false, false>,
98 FaceScopePolicyTest<AdmitLocalUnsolicitedDataPolicy, true, false>,
99 FaceScopePolicyTest<AdmitNetworkUnsolicitedDataPolicy, false, true>,
100 FaceScopePolicyTest<AdmitAllUnsolicitedDataPolicy, true, true>
101> FaceScopePolicyTests;
102
103BOOST_AUTO_TEST_CASE_TEMPLATE(FaceScopePolicy, T, FaceScopePolicyTests)
104{
105 setPolicy<typename T::PolicyType>();
106
107 auto face1 = make_shared<DummyFace>("dummy://", "dummy://",
108 ndn::nfd::FACE_SCOPE_LOCAL);
109 forwarder.addFace(face1);
110
111 shared_ptr<Data> data1 = makeData("/unsolicited-from-local");
112 forwarder.onIncomingData(*face1, *data1);
113 BOOST_CHECK_EQUAL(isInCs(*data1), T::ShouldAdmitLocal::value);
114
115 auto face2 = make_shared<DummyFace>("dummy://", "dummy://",
116 ndn::nfd::FACE_SCOPE_NON_LOCAL);
117 forwarder.addFace(face2);
118
119 shared_ptr<Data> data2 = makeData("/unsolicited-from-non-local");
120 forwarder.onIncomingData(*face2, *data2);
121 BOOST_CHECK_EQUAL(isInCs(*data2), T::ShouldAdmitNonLocal::value);
122}
123
124BOOST_AUTO_TEST_SUITE_END() // TestUnsolicitedDataPolicy
125BOOST_AUTO_TEST_SUITE_END() // Fw
126
127} // namespace tests
128} // namespace fw
129} // namespace nfd