blob: 0c08190b7242e518ba55ad3f766afbf1826f8b3d [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "mgmt/internal-face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -07008#include "../face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07009
Steve DiBenedetto5b433982014-01-29 17:14:27 -070010#include <boost/test/unit_test.hpp>
11
12namespace nfd {
13
Steve DiBenedetto3970c892014-01-31 23:31:13 -070014NFD_LOG_INIT("InternalFaceTest");
15
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070016class InternalFaceFixture
Steve DiBenedetto3970c892014-01-31 23:31:13 -070017{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070018public:
Steve DiBenedetto3970c892014-01-31 23:31:13 -070019
Steve DiBenedettobdedce92014-02-02 22:49:39 -070020 InternalFaceFixture()
21 : m_onInterestFired(false),
22 m_noOnInterestFired(false)
23 {
24
25 }
26
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070027 void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070028 validateOnInterestCallback(const Name& name, const Interest& interest)
29 {
30 m_onInterestFired = true;
31 }
32
33 void
34 validateNoOnInterestCallback(const Name& name, const Interest& interest)
35 {
36 m_noOnInterestFired = true;
37 }
38
39 void
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070040 addFace(shared_ptr<Face> face)
41 {
42 m_faces.push_back(face);
43 }
Steve DiBenedetto3970c892014-01-31 23:31:13 -070044
Steve DiBenedettobdedce92014-02-02 22:49:39 -070045 bool
46 didOnInterestFire()
47 {
48 return m_onInterestFired;
49 }
50
51 bool
52 didNoOnInterestFire()
53 {
54 return m_noOnInterestFired;
55 }
56
57 void
58 resetOnInterestFired()
59 {
60 m_onInterestFired = false;
61 }
62
63 void
64 resetNoOnInterestFired()
65 {
66 m_noOnInterestFired = false;
67 }
68
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070069private:
70 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070071 bool m_onInterestFired;
72 bool m_noOnInterestFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070073};
Steve DiBenedetto3970c892014-01-31 23:31:13 -070074
Steve DiBenedetto5b433982014-01-29 17:14:27 -070075BOOST_AUTO_TEST_SUITE(MgmtInternalFace)
76
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070077void
Steve DiBenedettobdedce92014-02-02 22:49:39 -070078validatePutData(bool& called, const Name& expectedName, const Data& data)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070079{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070080 called = true;
81 BOOST_CHECK_EQUAL(expectedName, data.getName());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070082}
83
Steve DiBenedettobdedce92014-02-02 22:49:39 -070084BOOST_FIXTURE_TEST_CASE(PutData, InternalFaceFixture)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070085{
Steve DiBenedettobdedce92014-02-02 22:49:39 -070086 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070087
Steve DiBenedetto3970c892014-01-31 23:31:13 -070088 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070089
Steve DiBenedettobdedce92014-02-02 22:49:39 -070090 bool didPutData = false;
91 Name dataName("/hello");
92 face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070093
Steve DiBenedettobdedce92014-02-02 22:49:39 -070094 Data testData(dataName);
95 face->sign(testData);
96 face->put(testData);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070097
Steve DiBenedettobdedce92014-02-02 22:49:39 -070098 BOOST_REQUIRE(didPutData);
Steve DiBenedetto5b433982014-01-29 17:14:27 -070099}
100
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700101BOOST_FIXTURE_TEST_CASE(SendInterestHitEnd, InternalFaceFixture)
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700102{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700103 addFace(make_shared<DummyFace>());
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700104
105 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700106
107 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700108 bind(&InternalFaceFixture::validateOnInterestCallback,
109 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700110
111 // generate command whose name is canonically
112 // ordered after /localhost/nfd/fib so that
113 // we hit the end of the std::map
114
115 Name commandName("/localhost/nfd/fib/end");
116 Interest command(commandName);
117 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700118
119 BOOST_REQUIRE(didOnInterestFire());
120 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700121}
122
123
124
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700125BOOST_FIXTURE_TEST_CASE(SendInterestHitBegin, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700126{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700127 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700128
129 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700130
131 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700132 bind(&InternalFaceFixture::validateNoOnInterestCallback,
133 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700134
135 // generate command whose name is canonically
136 // ordered before /localhost/nfd/fib so that
137 // we hit the beginning of the std::map
138
139 Name commandName("/localhost/nfd");
140 Interest command(commandName);
141 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700142
143 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700144}
145
146
147
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700148BOOST_FIXTURE_TEST_CASE(SendInterestHitExact, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700149{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700150 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700151
152 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700153
154 face->setInterestFilter("/localhost/nfd/eib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700155 bind(&InternalFaceFixture::validateNoOnInterestCallback,
156 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700157
158 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700159 bind(&InternalFaceFixture::validateOnInterestCallback,
160 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700161
162 face->setInterestFilter("/localhost/nfd/gib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700163 bind(&InternalFaceFixture::validateNoOnInterestCallback,
164 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700165
166 // generate command whose name exactly matches
167 // /localhost/nfd/fib
168
169 Name commandName("/localhost/nfd/fib");
170 Interest command(commandName);
171 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700172
173 BOOST_REQUIRE(didOnInterestFire());
174 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700175}
176
177
178
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700179BOOST_FIXTURE_TEST_CASE(SendInterestHitPrevious, InternalFaceFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700180{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700181 addFace(make_shared<DummyFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700182
183 shared_ptr<InternalFace> face(new InternalFace);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700184
185 face->setInterestFilter("/localhost/nfd/fib",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700186 bind(&InternalFaceFixture::validateOnInterestCallback,
187 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700188
189 face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700190 bind(&InternalFaceFixture::validateNoOnInterestCallback,
191 this, _1, _2));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700192
193 // generate command whose name exactly matches
194 // an Interest filter
195
196 Name commandName("/localhost/nfd/fib/previous");
197 Interest command(commandName);
198 face->sendInterest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700199
200 BOOST_REQUIRE(didOnInterestFire());
201 BOOST_REQUIRE(didNoOnInterestFire() == false);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700202}
203
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700204BOOST_AUTO_TEST_SUITE_END()
205
206} // namespace nfd