blob: 43a649d6334c0d417bf74db01f49fec70d3b6ccb [file] [log] [blame]
Steve DiBenedetto471c0602014-02-18 12:32:00 -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/local-control-header-manager.hpp"
Steve DiBenedetto471c0602014-02-18 12:32:00 -07008#include "mgmt/internal-face.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -07009#include "tests/face/dummy-face.hpp"
Steve DiBenedetto471c0602014-02-18 12:32:00 -070010
Junxiao Shid9ee45c2014-02-27 15:38:11 -070011#include "tests/test-common.hpp"
Steve DiBenedetto471c0602014-02-18 12:32:00 -070012
13namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070014namespace tests {
Steve DiBenedetto471c0602014-02-18 12:32:00 -070015
16NFD_LOG_INIT("LocalControlHeaderManagerTest");
17
Junxiao Shid9ee45c2014-02-27 15:38:11 -070018class LocalControlHeaderManagerFixture : protected BaseFixture
Steve DiBenedetto471c0602014-02-18 12:32:00 -070019{
20public:
21
22 LocalControlHeaderManagerFixture()
23 : m_callbackFired(false)
24 {
25
26 }
27
28 shared_ptr<Face>
29 getFace(FaceId id)
30 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070031 if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
Steve DiBenedetto471c0602014-02-18 12:32:00 -070032 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033 return m_faces[id - 1];
Steve DiBenedetto471c0602014-02-18 12:32:00 -070034 }
35 NFD_LOG_DEBUG("No face found returning NULL");
36 return shared_ptr<DummyFace>();
37 }
38
39 void
40 addFace(shared_ptr<Face> face)
41 {
42 m_faces.push_back(face);
43 }
44
45 void
46 validateControlResponse(const Data& response,
47 const Name& expectedName,
48 uint32_t expectedCode,
49 const std::string& expectedText)
50 {
51 m_callbackFired = true;
52
53 ControlResponse control;
54 Block controlRaw = response.getContent().blockFromValue();
55
56 control.wireDecode(controlRaw);
57
58 NFD_LOG_DEBUG("received control response"
59 << " Name: " << response.getName()
60 << " code: " << control.getCode()
61 << " text: " << control.getText());
62
63 BOOST_CHECK_EQUAL(response.getName(), expectedName);
64 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
65 BOOST_CHECK_EQUAL(control.getText(), expectedText);
66
67 if (!control.getBody().empty())
68 {
69 BOOST_FAIL("found unexpected control response body");
70 }
71 }
72
73 bool
74 didCallbackFire()
75 {
76 return m_callbackFired;
77 }
78
79 void
80 resetCallbackFired()
81 {
82 m_callbackFired = false;
83 }
84
85private:
86 std::vector<shared_ptr<Face> > m_faces;
87 bool m_callbackFired;
88};
89
Junxiao Shid9ee45c2014-02-27 15:38:11 -070090BOOST_FIXTURE_TEST_SUITE(MgmtLocalControlHeaderManager, LocalControlHeaderManagerFixture)
Steve DiBenedetto471c0602014-02-18 12:32:00 -070091
Junxiao Shid9ee45c2014-02-27 15:38:11 -070092BOOST_AUTO_TEST_CASE(InFaceId)
Steve DiBenedetto471c0602014-02-18 12:32:00 -070093{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080094 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -070095 addFace(dummy);
96
97 shared_ptr<InternalFace> face(make_shared<InternalFace>());
98
99 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
100 face);
101
102 Name enable("/localhost/nfd/control-header/in-faceid/enable");
103
104 face->onReceiveData +=
105 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
106 enable, 200, "Success");
107
108 Interest enableCommand(enable);
109 enableCommand.setIncomingFaceId(1);
110 manager.onLocalControlHeaderRequest(enableCommand);
111
112 BOOST_REQUIRE(didCallbackFire());
113 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
114 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
115
116 face->onReceiveData.clear();
117 resetCallbackFired();
118
119 Name disable("/localhost/nfd/control-header/in-faceid/disable");
120
121 face->onReceiveData +=
122 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
123 disable, 200, "Success");
124
125 Interest disableCommand(disable);
126 disableCommand.setIncomingFaceId(1);
127 manager.onLocalControlHeaderRequest(disableCommand);
128
129 BOOST_REQUIRE(didCallbackFire());
130 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
131 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
132}
133
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700134BOOST_AUTO_TEST_CASE(NextHopFaceId)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700135{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800136 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700137 addFace(dummy);
138
139 shared_ptr<InternalFace> face(make_shared<InternalFace>());
140
141 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
142 face);
143
144 Name enable("/localhost/nfd/control-header/nexthop-faceid/enable");
145
146 face->onReceiveData +=
147 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
148 enable, 200, "Success");
149
150 Interest enableCommand(enable);
151 enableCommand.setIncomingFaceId(1);
152 manager.onLocalControlHeaderRequest(enableCommand);
153
154 BOOST_REQUIRE(didCallbackFire());
155 BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
156 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
157
158
159 face->onReceiveData.clear();
160 resetCallbackFired();
161
162 Name disable("/localhost/nfd/control-header/nexthop-faceid/disable");
163
164 face->onReceiveData +=
165 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
166 disable, 200, "Success");
167
168 Interest disableCommand(disable);
169 disableCommand.setIncomingFaceId(1);
170 manager.onLocalControlHeaderRequest(disableCommand);
171
172 BOOST_REQUIRE(didCallbackFire());
173 BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
174 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
175}
176
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700177BOOST_AUTO_TEST_CASE(ShortCommand)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700178{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800179 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700180 addFace(dummy);
181
182 shared_ptr<InternalFace> face(make_shared<InternalFace>());
183
184 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
185 face);
186
187 Name commandName("/localhost/nfd/control-header");
188
189 face->onReceiveData +=
190 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
191 commandName, 400, "Malformed command");
192
193 Interest command(commandName);
194 command.setIncomingFaceId(1);
195 manager.onLocalControlHeaderRequest(command);
196
197 BOOST_REQUIRE(didCallbackFire());
198 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
199 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
200}
201
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700202BOOST_AUTO_TEST_CASE(ShortCommandModule)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700203{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800204 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700205 addFace(dummy);
206
207 shared_ptr<InternalFace> face(make_shared<InternalFace>());
208
209 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
210 face);
211
212 Name commandName("/localhost/nfd/control-header/in-faceid");
213
214 face->onReceiveData +=
215 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
216 commandName, 400, "Malformed command");
217
218 Interest command(commandName);
219 command.setIncomingFaceId(1);
220 manager.onLocalControlHeaderRequest(command);
221
222 BOOST_REQUIRE(didCallbackFire());
223 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
224 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
225}
226
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700227BOOST_AUTO_TEST_CASE(UnsupportedModule)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700228{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800229 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700230 addFace(dummy);
231
232 shared_ptr<InternalFace> face(make_shared<InternalFace>());
233
234 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
235 face);
236
237 Name commandName("/localhost/nfd/control-header/madeup/moremadeup");
238
239 face->onReceiveData +=
240 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
241 commandName, 501, "Unsupported");
242
243 Interest command(commandName);
244 command.setIncomingFaceId(1);
245 manager.onLocalControlHeaderRequest(command);
246
247 BOOST_REQUIRE(didCallbackFire());
248 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
249 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
250}
251
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700252BOOST_AUTO_TEST_CASE(InFaceIdUnsupportedVerb)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700253{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800254 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700255 addFace(dummy);
256
257 shared_ptr<InternalFace> face(make_shared<InternalFace>());
258
259 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
260 face);
261
262 Name commandName("/localhost/nfd/control-header/in-faceid/madeup");
263
264 face->onReceiveData +=
265 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
266 commandName, 501, "Unsupported");
267
268 Interest command(commandName);
269 command.setIncomingFaceId(1);
270 manager.onLocalControlHeaderRequest(command);
271
272 BOOST_REQUIRE(didCallbackFire());
273 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
274 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
275}
276
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700277BOOST_AUTO_TEST_CASE(NextHopFaceIdUnsupportedVerb)
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700278{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800279 shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>();
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700280 addFace(dummy);
281
282 shared_ptr<InternalFace> face(make_shared<InternalFace>());
283
284 LocalControlHeaderManager manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1),
285 face);
286
287 Name commandName("/localhost/nfd/control-header/nexthop-faceid/madeup");
288
289 face->onReceiveData +=
290 bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1,
291 commandName, 501, "Unsupported");
292
293 Interest command(commandName);
294 command.setIncomingFaceId(1);
295 manager.onLocalControlHeaderRequest(command);
296
297 BOOST_REQUIRE(didCallbackFire());
298 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID));
299 BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
300}
301
302BOOST_AUTO_TEST_SUITE_END()
303
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700304} // namespace tests
Steve DiBenedetto471c0602014-02-18 12:32:00 -0700305} // namespace nfd