blob: e6748be968a95bc2a5b90cbe4e85af21a0958d0a [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -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/fib-manager.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07008#include "table/fib.hpp"
Steve DiBenedetto43cd0372014-02-01 17:05:07 -07009#include "table/fib-nexthop.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070010#include "face/face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -070011#include "mgmt/internal-face.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070012#include "tests/face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070013
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070014#include "validation-common.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070015#include "tests/test-common.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070016
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070017namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070018namespace tests {
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070019
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070020NFD_LOG_INIT("FibManagerTest");
21
Junxiao Shid9ee45c2014-02-27 15:38:11 -070022class FibManagerFixture : protected BaseFixture
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070023{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070024public:
25
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070026 virtual
27 ~FibManagerFixture()
Steve DiBenedettobdedce92014-02-02 22:49:39 -070028 {
Steve DiBenedettobdedce92014-02-02 22:49:39 -070029 }
30
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070031 shared_ptr<Face>
32 getFace(FaceId id)
33 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034 if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070035 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036 return m_faces[id - 1];
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070037 }
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070038 NFD_LOG_DEBUG("No face found returning NULL");
39 return shared_ptr<DummyFace>();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070040 }
41
42 void
43 addFace(shared_ptr<Face> face)
44 {
45 m_faces.push_back(face);
46 }
47
Steve DiBenedettobdedce92014-02-02 22:49:39 -070048 void
Steve DiBenedetto2693db92014-02-10 15:58:36 -070049 validateControlResponseCommon(const Data& response,
50 const Name& expectedName,
51 uint32_t expectedCode,
52 const std::string& expectedText,
53 ControlResponse& control)
Steve DiBenedettobdedce92014-02-02 22:49:39 -070054 {
55 m_callbackFired = true;
56 Block controlRaw = response.getContent().blockFromValue();
57
Steve DiBenedettobdedce92014-02-02 22:49:39 -070058 control.wireDecode(controlRaw);
59
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070060 // NFD_LOG_DEBUG("received control response"
61 // << " Name: " << response.getName()
62 // << " code: " << control.getCode()
63 // << " text: " << control.getText());
Steve DiBenedettobdedce92014-02-02 22:49:39 -070064
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070065 BOOST_CHECK_EQUAL(response.getName(), expectedName);
66 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
67 BOOST_CHECK_EQUAL(control.getText(), expectedText);
Steve DiBenedettobdedce92014-02-02 22:49:39 -070068 }
69
Steve DiBenedetto2693db92014-02-10 15:58:36 -070070 void
71 validateControlResponse(const Data& response,
72 const Name& expectedName,
73 uint32_t expectedCode,
74 const std::string& expectedText)
75 {
76 ControlResponse control;
77 validateControlResponseCommon(response, expectedName,
78 expectedCode, expectedText, control);
79
80 if (!control.getBody().empty())
81 {
82 BOOST_FAIL("found unexpected control response body");
83 }
84 }
85
86 void
87 validateControlResponse(const Data& response,
88 const Name& expectedName,
89 uint32_t expectedCode,
90 const std::string& expectedText,
91 const Block& expectedBody)
92 {
93 ControlResponse control;
94 validateControlResponseCommon(response, expectedName,
95 expectedCode, expectedText, control);
96
97 BOOST_REQUIRE(!control.getBody().empty());
98 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
99
100 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
101 expectedBody.value_size()) == 0);
102
103 }
104
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700105 bool
106 didCallbackFire()
107 {
108 return m_callbackFired;
109 }
110
111 void
112 resetCallbackFired()
113 {
114 m_callbackFired = false;
115 }
116
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700117 shared_ptr<InternalFace>
118 getInternalFace()
119 {
120 return m_face;
121 }
122
123 FibManager&
124 getFibManager()
125 {
126 return m_manager;
127 }
128
129 Fib&
130 getFib()
131 {
132 return m_fib;
133 }
134
135 void
136 addInterestRule(const std::string& regex,
137 ndn::IdentityCertificate& certificate)
138 {
139 m_manager.addInterestRule(regex, certificate);
140 }
141
142protected:
143 FibManagerFixture()
144 : m_face(make_shared<InternalFace>())
145 , m_nameTree(1024)
146 , m_fib(m_nameTree)
147 , m_manager(boost::ref(m_fib),
148 bind(&FibManagerFixture::getFace, this, _1),
149 m_face)
150 , m_callbackFired(false)
151 {
152 }
153
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700154private:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700155 shared_ptr<InternalFace> m_face;
156 NameTree m_nameTree;
157 Fib m_fib;
158 FibManager m_manager;
159
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700160 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700161 bool m_callbackFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700162};
163
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700164template <typename T> class AuthorizedCommandFixture:
165 public CommandFixture<T>
166{
167public:
168 AuthorizedCommandFixture()
169 {
170 const std::string regex = "^<localhost><nfd><fib>";
171 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
172 }
173
174 virtual
175 ~AuthorizedCommandFixture()
176 {
177 }
178};
179
180BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, AuthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700181
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700182bool
183foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
184{
185 return id == next.getFace()->getId() && next.getCost() == cost;
186}
187
188bool
189addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
190{
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700191 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700192
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700193 if (static_cast<bool>(entry))
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700194 {
195 const fib::NextHopList& hops = entry->getNextHops();
196 return hops.size() == oldSize + 1 &&
197 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
198 }
199 return false;
200}
201
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700202bool
203foundNextHopWithFace(FaceId id, uint32_t cost,
204 shared_ptr<Face> face, const fib::NextHop& next)
205{
206 return id == next.getFace()->getId() && next.getCost() == cost && face == next.getFace();
207}
208
209bool
210addedNextHopWithFace(const Fib& fib, const Name& prefix, size_t oldSize,
211 uint32_t cost, shared_ptr<Face> face)
212{
213 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
214
215 if (static_cast<bool>(entry))
216 {
217 const fib::NextHopList& hops = entry->getNextHops();
218 return hops.size() == oldSize + 1 &&
219 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
220 }
221 return false;
222}
223
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700224BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700225{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700226 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700227
228 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700229
230 face->onReceiveData +=
231 bind(&FibManagerFixture::validateControlResponse, this, _1,
232 command.getName(), 400, "Malformed command");
233
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700234 face->sendInterest(command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700235
236 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700237}
238
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700239BOOST_AUTO_TEST_CASE(MalformedCommmand)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700240{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700241 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700242
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700243 BOOST_REQUIRE(didCallbackFire() == false);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700244
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700245 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700246
247 face->onReceiveData +=
248 bind(&FibManagerFixture::validateControlResponse, this, _1,
249 command.getName(), 400, "Malformed command");
250
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700251 getFibManager().onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700252
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700253 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700254}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700255
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700256BOOST_AUTO_TEST_CASE(UnsupportedVerb)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700257{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700258 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700259
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800260 FibManagementOptions options;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700261 options.setName("/hello");
262 options.setFaceId(1);
263 options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700264
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700265 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700266
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700267 Name commandName("/localhost/nfd/fib");
268 commandName.append("unsupported");
269 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700270
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700271 shared_ptr<Interest> command(make_shared<Interest>(commandName));
272 generateCommand(*command);
273
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700274 face->onReceiveData +=
275 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700276 command->getName(), 501, "Unsupported command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700277
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700278 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700279
280 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700281}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700282
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700283BOOST_AUTO_TEST_CASE(UnsignedCommand)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700284{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700285 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700286
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700287 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700288
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800289 FibManagementOptions options;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700290 options.setName("/hello");
291 options.setFaceId(1);
292 options.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700293
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700294 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700295
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700296 Name commandName("/localhost/nfd/fib");
297 commandName.append("add-nexthop");
298 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700299
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700300 Interest command(commandName);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700301
302 face->onReceiveData +=
303 bind(&FibManagerFixture::validateControlResponse,
304 this, _1, command.getName(), 401, "Signature required");
305
306
307 getFibManager().onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700308
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700309 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700310 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700311}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700312
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700313BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700314{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700315 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700316
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700317 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700318
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800319 FibManagementOptions options;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700320 options.setName("/hello");
321 options.setFaceId(1);
322 options.setCost(101);
323
324 Block encodedOptions(options.wireEncode());
325
326 Name commandName("/localhost/nfd/fib");
327 commandName.append("add-nexthop");
328 commandName.append(encodedOptions);
329
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700330 shared_ptr<Interest> command(make_shared<Interest>(commandName));
331 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700332
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700333 face->onReceiveData +=
334 bind(&FibManagerFixture::validateControlResponse,
335 this, _1, command->getName(), 403, "Unauthorized command");
336
337 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700338
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700339 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700340 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700341}
342
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700343BOOST_AUTO_TEST_CASE(BadOptionParse)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700344{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700345 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700346
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700347 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700348
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700349 Name commandName("/localhost/nfd/fib");
350 commandName.append("add-nexthop");
351 commandName.append("NotReallyOptions");
352
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700353 shared_ptr<Interest> command(make_shared<Interest>(commandName));
354 generateCommand(*command);
355
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700356 face->onReceiveData +=
357 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700358 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700359
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700360 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700361
362 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700363}
364
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700365BOOST_AUTO_TEST_CASE(UnknownFaceId)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700366{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700367 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700368
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700369 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700370
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800371 FibManagementOptions options;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700372 options.setName("/hello");
373 options.setFaceId(1000);
374 options.setCost(101);
375
376 Block encodedOptions(options.wireEncode());
377
378 Name commandName("/localhost/nfd/fib");
379 commandName.append("add-nexthop");
380 commandName.append(encodedOptions);
381
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700382 shared_ptr<Interest> command(make_shared<Interest>(commandName));
383 generateCommand(*command);
384
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700385 face->onReceiveData +=
386 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700387 command->getName(), 404, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700388
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700389 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700390
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700391 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700392 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101) == false);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700393}
394
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700395BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700396{
397 addFace(make_shared<DummyFace>());
398
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700399 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700400
401 FibManagementOptions options;
402 options.setName("/hello");
403 options.setFaceId(0);
404 options.setCost(101);
405
406 Block encodedOptions(options.wireEncode());
407
408 Name commandName("/localhost/nfd/fib");
409 commandName.append("add-nexthop");
410 commandName.append(encodedOptions);
411
412 FibManagementOptions expectedOptions;
413 expectedOptions.setName("/hello");
414 expectedOptions.setFaceId(1);
415 expectedOptions.setCost(101);
416
417 Block encodedExpectedOptions(expectedOptions.wireEncode());
418
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700419 shared_ptr<Interest> command(make_shared<Interest>(commandName));
420 command->setIncomingFaceId(1);
421 generateCommand(*command);
422
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700423 face->onReceiveData +=
424 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700425 command->getName(), 200, "Success", encodedExpectedOptions);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700426
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700427 getFib().insert("/hello");
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700428
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700429 getFibManager().onFibRequest(*command);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700430
431 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700432 BOOST_REQUIRE(addedNextHopWithFace(getFib(), "/hello", 0, 101, getFace(1)));
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700433}
434
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700435BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700436{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700437 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700438
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700439 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700440
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800441 FibManagementOptions options;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700442 options.setName("/hello");
443 options.setFaceId(1);
444 options.setCost(101);
445
446 Block encodedOptions(options.wireEncode());
447
448 Name commandName("/localhost/nfd/fib");
449 commandName.append("add-nexthop");
450 commandName.append(encodedOptions);
451
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700452 shared_ptr<Interest> command(make_shared<Interest>(commandName));
453 generateCommand(*command);
454
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700455 face->onReceiveData +=
456 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700457 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700458
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700459 getFib().insert("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700460
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700461 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700462
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700463 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700464 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700465}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700466
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700467BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700468{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700469 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700470 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700471
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700472 getFib().insert("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700473
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700474 for (int i = 1; i <= 2; i++)
475 {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700476
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800477 FibManagementOptions options;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700478 options.setName("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700479 options.setFaceId(1);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700480 options.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700481
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700482 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700483
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700484 Name commandName("/localhost/nfd/fib");
485 commandName.append("add-nexthop");
486 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700487
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700488 shared_ptr<Interest> command(make_shared<Interest>(commandName));
489 generateCommand(*command);
490
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700491 face->onReceiveData +=
492 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700493 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700494
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700495 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700496 BOOST_REQUIRE(didCallbackFire());
497 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700498
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700499 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700500
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700501 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700502 {
503 const fib::NextHopList& hops = entry->getNextHops();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700504 BOOST_REQUIRE(hops.size() == 1);
505 BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(),
506 bind(&foundNextHop, -1, 100 + i, _1)) != hops.end());
507
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700508 }
509 else
510 {
511 BOOST_FAIL("Failed to find expected fib entry");
512 }
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700513
514 face->onReceiveData.clear();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700515 }
516}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700517
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700518BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700519{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700520 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700521 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700522
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700523 getFib().insert("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700524
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800525 FibManagementOptions options;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700526 options.setName("/hello");
527 options.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700528
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700529 {
530 options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700531
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700532 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700533
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700534 Name commandName("/localhost/nfd/fib");
535 commandName.append("add-nexthop");
536 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700537
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700538 shared_ptr<Interest> command(make_shared<Interest>(commandName));
539 generateCommand(*command);
540
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700541 face->onReceiveData +=
542 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700543 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700544
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700545 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700546
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700547 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700548 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700549
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700550 resetCallbackFired();
551 face->onReceiveData.clear();
552
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700553 {
554 options.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700555
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700556 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700557
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700558 Name commandName("/localhost/nfd/fib");
559 commandName.append("add-nexthop");
560 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700561
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700562 shared_ptr<Interest> command(make_shared<Interest>(commandName));
563 generateCommand(*command);
564
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700565 face->onReceiveData +=
566 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700567 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700568
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700569 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700570
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700571 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700572 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700573
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700574 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700575
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700576 // Add faces with cost == FaceID for the name /hello
577 // This test assumes:
578 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700579 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700580 {
581 const fib::NextHopList& hops = entry->getNextHops();
582 BOOST_REQUIRE(hops.size() == 1);
583 BOOST_REQUIRE(std::find_if(hops.begin(),
584 hops.end(),
585 bind(&foundNextHop, -1, 102, _1)) != hops.end());
586 }
587 else
588 {
589 BOOST_FAIL("Failed to find expected fib entry");
590 }
591}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700592
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700593BOOST_AUTO_TEST_CASE(Insert)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700594{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700595 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700596
597 {
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800598 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700599 options.setName("/hello");
600
601 Block encodedOptions(options.wireEncode());
602
603 Name commandName("/localhost/nfd/fib");
604 commandName.append("insert");
605 commandName.append(encodedOptions);
606
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700607 shared_ptr<Interest> command(make_shared<Interest>(commandName));
608 generateCommand(*command);
609
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700610 face->onReceiveData +=
611 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700612 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700613
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700614 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700615 }
616
617 BOOST_REQUIRE(didCallbackFire());
618
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700619 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700620 if (static_cast<bool>(entry))
621 {
622 const fib::NextHopList& hops = entry->getNextHops();
623 BOOST_CHECK_EQUAL(hops.size(), 0);
624 }
625
626 resetCallbackFired();
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700627 face->onReceiveData.clear();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700628
629 {
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800630 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700631 options.setName("/hello");
632
633 Block encodedOptions(options.wireEncode());
634
635 Name commandName("/localhost/nfd/fib");
636 commandName.append("insert");
637 commandName.append(encodedOptions);
638
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700639 shared_ptr<Interest> command(make_shared<Interest>(commandName));
640 generateCommand(*command);
641
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700642 face->onReceiveData +=
643 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700644 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700645
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700646 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700647 }
648
649 BOOST_REQUIRE(didCallbackFire());
650
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700651 entry = getFib().findExactMatch("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700652 if (static_cast<bool>(entry))
653 {
654 const fib::NextHopList& hops = entry->getNextHops();
655 BOOST_CHECK_EQUAL(hops.size(), 0);
656 }
657
658}
659
660void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700661testRemove(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700662 FibManager& manager,
663 Fib& fib,
664 shared_ptr<Face> face,
665 const Name& target)
666{
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800667 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700668 options.setName(target);
669
670 Block encodedOptions(options.wireEncode());
671
672 Name commandName("/localhost/nfd/fib");
673 commandName.append("delete");
674 commandName.append(encodedOptions);
675
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700676 shared_ptr<Interest> command(make_shared<Interest>(commandName));
677 fixture->generateCommand(*command);
678
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700679 face->onReceiveData +=
680 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700681 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700682
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700683 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700684
685 BOOST_REQUIRE(fixture->didCallbackFire());
686
687 if (static_cast<bool>(fib.findExactMatch(target)))
688 {
689 BOOST_FAIL("Found \"removed\" prefix");
690 }
691 face->onReceiveData.clear();
692}
693
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700694BOOST_AUTO_TEST_CASE(Delete)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700695{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700696 shared_ptr<InternalFace> face = getInternalFace();
697 FibManager& manager = getFibManager();
698 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700699
700 fib.insert("/a");
701 fib.insert("/a/b");
702 fib.insert("/a/b/c");
703
704 testRemove(this, manager, fib, face, "/");
705
706 if (!static_cast<bool>(fib.findExactMatch("/a")) ||
707 !static_cast<bool>(fib.findExactMatch("/a/b")) ||
708 !static_cast<bool>(fib.findExactMatch("/a/b/c")))
709 {
710 BOOST_FAIL("Removed incorrect entry");
711 }
712
713 testRemove(this, manager, fib, face, "/a/b");
714
715 if (!static_cast<bool>(fib.findExactMatch("/a")) ||
716 !static_cast<bool>(fib.findExactMatch("/a/b/c")))
717 {
718 BOOST_FAIL("Removed incorrect entry");
719 }
720
721 testRemove(this, manager, fib, face, "/a/b/c");
722
723 if (!static_cast<bool>(fib.findExactMatch("/a")))
724 {
725 BOOST_FAIL("Removed incorrect entry");
726 }
727
728 testRemove(this, manager, fib, face, "/a");
729
730 testRemove(this, manager, fib, face, "/does/not/exist");
731}
732
733bool
734removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
735{
736 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
737
738 if (static_cast<bool>(entry))
739 {
740 const fib::NextHopList& hops = entry->getNextHops();
741 return hops.size() == oldSize - 1 &&
742 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end();
743 }
744 return false;
745}
746
747void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700748testRemoveNextHop(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700749 FibManager& manager,
750 Fib& fib,
751 shared_ptr<Face> face,
752 const Name& targetName,
753 FaceId targetFace)
754{
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800755 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700756 options.setName(targetName);
757 options.setFaceId(targetFace);
758
759 Block encodedOptions(options.wireEncode());
760
761 Name commandName("/localhost/nfd/fib");
762 commandName.append("remove-nexthop");
763 commandName.append(encodedOptions);
764
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700765 shared_ptr<Interest> command(make_shared<Interest>(commandName));
766 fixture->generateCommand(*command);
767
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700768 face->onReceiveData +=
769 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700770 command->getName(), 200, "Success", encodedOptions);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700771
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700772 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700773
774 BOOST_REQUIRE(fixture->didCallbackFire());
775
776 fixture->resetCallbackFired();
777 face->onReceiveData.clear();
778}
779
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700780BOOST_AUTO_TEST_CASE(RemoveNextHop)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700781{
782 shared_ptr<Face> face1 = make_shared<DummyFace>();
783 shared_ptr<Face> face2 = make_shared<DummyFace>();
784 shared_ptr<Face> face3 = make_shared<DummyFace>();
785
786 addFace(face1);
787 addFace(face2);
788 addFace(face3);
789
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700790 shared_ptr<InternalFace> face = getInternalFace();
791 FibManager& manager = getFibManager();
792 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700793
794 shared_ptr<fib::Entry> entry = fib.insert("/hello").first;
795
796 entry->addNextHop(face1, 101);
797 entry->addNextHop(face2, 202);
798 entry->addNextHop(face3, 303);
799
800 testRemoveNextHop(this, manager, fib, face, "/hello", 2);
801 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202));
802
803 testRemoveNextHop(this, manager, fib, face, "/hello", 3);
804 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303));
805
806 testRemoveNextHop(this, manager, fib, face, "/hello", 1);
807 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101));
808
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700809 if (!static_cast<bool>(getFib().findExactMatch("/hello")))
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700810 {
811 BOOST_FAIL("removed entry after removing all next hops");
812 }
813
814}
815
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700816BOOST_AUTO_TEST_CASE(RemoveNoFace)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700817{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700818 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700819
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800820 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700821 options.setName("/hello");
822 options.setFaceId(1);
823
824 Block encodedOptions(options.wireEncode());
825
826 Name commandName("/localhost/nfd/fib");
827 commandName.append("remove-nexthop");
828 commandName.append(encodedOptions);
829
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700830 shared_ptr<Interest> command(make_shared<Interest>(commandName));
831 generateCommand(*command);
832
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700833 face->onReceiveData +=
834 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700835 command->getName(), 404, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700836
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700837 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700838
839 BOOST_REQUIRE(didCallbackFire());
840}
841
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700842BOOST_AUTO_TEST_CASE(RemoveNoPrefix)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700843{
844 addFace(make_shared<DummyFace>());
845
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700846 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700847
Alexander Afanasyevd482fd32014-02-09 23:40:20 -0800848 FibManagementOptions options;
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700849 options.setName("/hello");
850 options.setFaceId(1);
851
852 Block encodedOptions(options.wireEncode());
853
854 Name commandName("/localhost/nfd/fib");
855 commandName.append("remove-nexthop");
856 commandName.append(encodedOptions);
857
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700858 shared_ptr<Interest> command(make_shared<Interest>(commandName));
859 generateCommand(*command);
860
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700861 face->onReceiveData +=
862 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700863 command->getName(), 404, "Prefix not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700864
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700865 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700866
867 BOOST_REQUIRE(didCallbackFire());
868}
869
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700870BOOST_AUTO_TEST_SUITE_END()
871
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700872} // namespace tests
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700873} // namespace nfd