blob: ca2a899c3c18586985f5c9413e30235846777e79 [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehman5144f822014-07-23 15:12:56 -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 * 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/>.
Vince Lehman5144f822014-07-23 15:12:56 -070024 */
Steve DiBenedetto5b433982014-01-29 17:14:27 -070025
26#include "mgmt/internal-face.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070027#include "tests/daemon/face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Steve DiBenedetto5b433982014-01-29 17:14:27 -070030
31namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Steve DiBenedetto5b433982014-01-29 17:14:27 -070033
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034class InternalFaceFixture : protected BaseFixture
Steve DiBenedetto3970c892014-01-31 23:31:13 -070035{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070036public:
Steve DiBenedetto3970c892014-01-31 23:31:13 -070037
Steve DiBenedettobdedce92014-02-02 22:49:39 -070038 InternalFaceFixture()
39 : m_onInterestFired(false),
40 m_noOnInterestFired(false)
41 {
42
43 }
44
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070045 void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070046 validateOnInterestCallback(const Name& name, const Interest& interest)
47 {
48 m_onInterestFired = true;
49 }
50
51 void
52 validateNoOnInterestCallback(const Name& name, const Interest& interest)
53 {
54 m_noOnInterestFired = true;
55 }
56
57 void
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070058 addFace(shared_ptr<Face> face)
59 {
60 m_faces.push_back(face);
61 }
Steve DiBenedetto3970c892014-01-31 23:31:13 -070062
Steve DiBenedettobdedce92014-02-02 22:49:39 -070063 bool
64 didOnInterestFire()
65 {
66 return m_onInterestFired;
67 }
68
69 bool
70 didNoOnInterestFire()
71 {
72 return m_noOnInterestFired;
73 }
74
75 void
76 resetOnInterestFired()
77 {
78 m_onInterestFired = false;
79 }
80
81 void
82 resetNoOnInterestFired()
83 {
84 m_noOnInterestFired = false;
85 }
86
Vince Lehman5144f822014-07-23 15:12:56 -070087protected:
88 ndn::KeyChain m_keyChain;
89
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070090private:
91 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070092 bool m_onInterestFired;
93 bool m_noOnInterestFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070094};
Steve DiBenedetto3970c892014-01-31 23:31:13 -070095
Junxiao Shid9ee45c2014-02-27 15:38:11 -070096BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture)
Steve DiBenedetto5b433982014-01-29 17:14:27 -070097
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070098void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070099validatePutData(bool& called, const Name& expectedName, const Data& data)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700100{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700101 called = true;
102 BOOST_CHECK_EQUAL(expectedName, data.getName());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700103}
104
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700105BOOST_AUTO_TEST_CASE(PutData)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700106{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700107 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700108
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700109 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700110
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700111 bool didPutData = false;
112 Name dataName("/hello");
Junxiao Shic099ddb2014-12-25 20:53:20 -0700113 face->onReceiveData.connect(bind(&validatePutData, ref(didPutData), dataName, _1));
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700114
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700115 Data testData(dataName);
Vince Lehman5144f822014-07-23 15:12:56 -0700116 m_keyChain.sign(testData);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700117 face->put(testData);
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700118
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700119 BOOST_REQUIRE(didPutData);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800120
121 BOOST_CHECK_THROW(face->close(), InternalFace::Error);
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700122}
123
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700124BOOST_AUTO_TEST_CASE(SendInterestHitEnd)
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700125{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700126 addFace(make_shared<DummyFace>());
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700127
128 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700129
130 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700131 bind(&InternalFaceFixture::validateOnInterestCallback,
132 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700133
134 // generate command whose name is canonically
135 // ordered after /localhost/nfd/fib so that
136 // we hit the end of the std::map
137
138 Name commandName("/localhost/nfd/fib/end");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700139 shared_ptr<Interest> command = makeInterest(commandName);
140 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700141 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700142
143 BOOST_REQUIRE(didOnInterestFire());
144 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700145}
146
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700147BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700148{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700149 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700150
151 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700152
153 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700154 bind(&InternalFaceFixture::validateNoOnInterestCallback,
155 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700156
157 // generate command whose name is canonically
158 // ordered before /localhost/nfd/fib so that
159 // we hit the beginning of the std::map
160
161 Name commandName("/localhost/nfd");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700162 shared_ptr<Interest> command = makeInterest(commandName);
163 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700164 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700165
166 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700167}
168
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700169BOOST_AUTO_TEST_CASE(SendInterestHitExact)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700170{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700171 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700172
173 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700174
175 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700176 bind(&InternalFaceFixture::validateNoOnInterestCallback,
177 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700178
179 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700180 bind(&InternalFaceFixture::validateOnInterestCallback,
181 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700182
183 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700184 bind(&InternalFaceFixture::validateNoOnInterestCallback,
185 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700186
187 // generate command whose name exactly matches
188 // /localhost/nfd/fib
189
190 Name commandName("/localhost/nfd/fib");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700191 shared_ptr<Interest> command = makeInterest(commandName);
192 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700193 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700194
195 BOOST_REQUIRE(didOnInterestFire());
196 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700197}
198
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700199BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700200{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700201 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700202
203 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700204
205 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700206 bind(&InternalFaceFixture::validateOnInterestCallback,
207 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700208
209 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700210 bind(&InternalFaceFixture::validateNoOnInterestCallback,
211 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700212
213 // generate command whose name exactly matches
214 // an Interest filter
215
216 Name commandName("/localhost/nfd/fib/previous");
Junxiao Shi72c3e042014-04-08 15:02:37 -0700217 shared_ptr<Interest> command = makeInterest(commandName);
218 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700219 g_io.run_one();
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700220
221 BOOST_REQUIRE(didOnInterestFire());
222 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700223}
224
Junxiao Shi72c3e042014-04-08 15:02:37 -0700225BOOST_AUTO_TEST_CASE(InterestGone)
226{
227 shared_ptr<InternalFace> face = make_shared<InternalFace>();
228 shared_ptr<Interest> interest = makeInterest("ndn:/localhost/nfd/gone");
229 face->sendInterest(*interest);
230
231 interest.reset();
232 BOOST_CHECK_NO_THROW(g_io.poll());
233}
234
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700235BOOST_AUTO_TEST_SUITE_END()
236
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700237} // namespace tests
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700238} // namespace nfd