blob: 04ef4a277241d32733074c1b67e0836bc4430699 [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -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 **/
Steve DiBenedetto5b433982014-01-29 17:14:27 -070024
25#include "mgmt/internal-face.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#include "tests/daemon/face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070027
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Steve DiBenedetto5b433982014-01-29 17:14:27 -070029
30namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070031namespace tests {
Steve DiBenedetto5b433982014-01-29 17:14:27 -070032
Steve DiBenedetto3970c892014-01-31 23:31:13 -070033NFD_LOG_INIT("InternalFaceTest");
34
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035class InternalFaceFixture : protected BaseFixture
Steve DiBenedetto3970c892014-01-31 23:31:13 -070036{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070037public:
Steve DiBenedetto3970c892014-01-31 23:31:13 -070038
Steve DiBenedettobdedce92014-02-02 22:49:39 -070039 InternalFaceFixture()
40 : m_onInterestFired(false),
41 m_noOnInterestFired(false)
42 {
43
44 }
45
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070046 void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070047 validateOnInterestCallback(const Name& name, const Interest& interest)
48 {
49 m_onInterestFired = true;
50 }
51
52 void
53 validateNoOnInterestCallback(const Name& name, const Interest& interest)
54 {
55 m_noOnInterestFired = true;
56 }
57
58 void
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070059 addFace(shared_ptr<Face> face)
60 {
61 m_faces.push_back(face);
62 }
Steve DiBenedetto3970c892014-01-31 23:31:13 -070063
Steve DiBenedettobdedce92014-02-02 22:49:39 -070064 bool
65 didOnInterestFire()
66 {
67 return m_onInterestFired;
68 }
69
70 bool
71 didNoOnInterestFire()
72 {
73 return m_noOnInterestFired;
74 }
75
76 void
77 resetOnInterestFired()
78 {
79 m_onInterestFired = false;
80 }
81
82 void
83 resetNoOnInterestFired()
84 {
85 m_noOnInterestFired = false;
86 }
87
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070088private:
89 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070090 bool m_onInterestFired;
91 bool m_noOnInterestFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070092};
Steve DiBenedetto3970c892014-01-31 23:31:13 -070093
Junxiao Shid9ee45c2014-02-27 15:38:11 -070094BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture)
Steve DiBenedetto5b433982014-01-29 17:14:27 -070095
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070096void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070097validatePutData(bool& called, const Name& expectedName, const Data& data)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070098{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070099 called = true;
100 BOOST_CHECK_EQUAL(expectedName, data.getName());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700101}
102
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700103BOOST_AUTO_TEST_CASE(PutData)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700104{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700105 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700106
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700107 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700108
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700109 bool didPutData = false;
110 Name dataName("/hello");
111 face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700112
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700113 Data testData(dataName);
114 face->sign(testData);
115 face->put(testData);
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700116
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700117 BOOST_REQUIRE(didPutData);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800118
119 BOOST_CHECK_THROW(face->close(), InternalFace::Error);
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700120}
121
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700122BOOST_AUTO_TEST_CASE(SendInterestHitEnd)
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700123{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700124 addFace(make_shared<DummyFace>());
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700125
126 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700127
128 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700129 bind(&InternalFaceFixture::validateOnInterestCallback,
130 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700131
132 // generate command whose name is canonically
133 // ordered after /localhost/nfd/fib so that
134 // we hit the end of the std::map
135
136 Name commandName("/localhost/nfd/fib/end");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700137 shared_ptr<Interest> command = makeInterest(commandName);
138 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700139 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700140
141 BOOST_REQUIRE(didOnInterestFire());
142 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700143}
144
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700145BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700146{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700147 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700148
149 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700150
151 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700152 bind(&InternalFaceFixture::validateNoOnInterestCallback,
153 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700154
155 // generate command whose name is canonically
156 // ordered before /localhost/nfd/fib so that
157 // we hit the beginning of the std::map
158
159 Name commandName("/localhost/nfd");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700160 shared_ptr<Interest> command = makeInterest(commandName);
161 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700162 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700163
164 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700165}
166
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700167BOOST_AUTO_TEST_CASE(SendInterestHitExact)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700168{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700169 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700170
171 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700172
173 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700174 bind(&InternalFaceFixture::validateNoOnInterestCallback,
175 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700176
177 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700178 bind(&InternalFaceFixture::validateOnInterestCallback,
179 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700180
181 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700182 bind(&InternalFaceFixture::validateNoOnInterestCallback,
183 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700184
185 // generate command whose name exactly matches
186 // /localhost/nfd/fib
187
188 Name commandName("/localhost/nfd/fib");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700189 shared_ptr<Interest> command = makeInterest(commandName);
190 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700191 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700192
193 BOOST_REQUIRE(didOnInterestFire());
194 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700195}
196
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700197BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700198{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700199 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700200
201 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700202
203 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700204 bind(&InternalFaceFixture::validateOnInterestCallback,
205 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700206
207 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700208 bind(&InternalFaceFixture::validateNoOnInterestCallback,
209 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700210
211 // generate command whose name exactly matches
212 // an Interest filter
213
214 Name commandName("/localhost/nfd/fib/previous");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700215 shared_ptr<Interest> command = makeInterest(commandName);
216 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700217 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700218
219 BOOST_REQUIRE(didOnInterestFire());
220 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700221}
222
Junxiao Shi72c3e042014-04-08 15:02:37 -0700223BOOST_AUTO_TEST_CASE(InterestGone)
224{
225 shared_ptr<InternalFace> face = make_shared<InternalFace>();
226 shared_ptr<Interest> interest = makeInterest("ndn:/localhost/nfd/gone");
227 face->sendInterest(*interest);
228
229 interest.reset();
230 BOOST_CHECK_NO_THROW(g_io.poll());
231}
232
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700233BOOST_AUTO_TEST_SUITE_END()
234
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700235} // namespace tests
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700236} // namespace nfd