blob: b07d11be6b3a8d201874fda923ebc760e48ec5e1 [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"
8#include "fw/forwarder.hpp"
9#include "table/fib.hpp"
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070010#include "table/fib-nexthop.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070011#include "face/face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -070012#include "mgmt/internal-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070013#include "../face/dummy-face.hpp"
14
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070015#include <algorithm>
16
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070017#include <ndn-cpp-dev/management/fib-management-options.hpp>
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070018#include <ndn-cpp-dev/management/control-response.hpp>
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070019
20#include <boost/test/unit_test.hpp>
21
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070022namespace nfd {
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070023
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070024NFD_LOG_INIT("FibManagerTest");
25
26class FibManagerFixture
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070027{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070028public:
29
Steve DiBenedettobdedce92014-02-02 22:49:39 -070030 FibManagerFixture()
31 : m_callbackFired(false)
32 {
33
34 }
35
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070036 shared_ptr<Face>
37 getFace(FaceId id)
38 {
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070039 if (id > 0 && id <= m_faces.size())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070040 {
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070041 return m_faces[id-1];
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070042 }
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070043 NFD_LOG_DEBUG("No face found returning NULL");
44 return shared_ptr<DummyFace>();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070045 }
46
47 void
48 addFace(shared_ptr<Face> face)
49 {
50 m_faces.push_back(face);
51 }
52
Steve DiBenedettobdedce92014-02-02 22:49:39 -070053 void
54 validateControlResponse(const Data& response,
55 uint32_t expectedCode,
56 const std::string& expectedText)
57 {
58 m_callbackFired = true;
59 Block controlRaw = response.getContent().blockFromValue();
60
61 ndn::ControlResponse control;
62 control.wireDecode(controlRaw);
63
64 NFD_LOG_DEBUG("received control response"
65 << " Name: " << response.getName()
66 << " code: " << control.getCode()
67 << " text: " << control.getText());
68
69 BOOST_REQUIRE(control.getCode() == expectedCode);
70 BOOST_REQUIRE(control.getText() == expectedText);
71 }
72
73 bool
74 didCallbackFire()
75 {
76 return m_callbackFired;
77 }
78
79 void
80 resetCallbackFired()
81 {
82 m_callbackFired = false;
83 }
84
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070085private:
86 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -070087 bool m_callbackFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070088};
89
90
91BOOST_AUTO_TEST_SUITE(MgmtFibManager)
92
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070093
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070094
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070095bool
96foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
97{
98 return id == next.getFace()->getId() && next.getCost() == cost;
99}
100
101bool
102addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
103{
104 shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch(prefix);
105
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700106 if (static_cast<bool>(entry))
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700107 {
108 const fib::NextHopList& hops = entry->getNextHops();
109 return hops.size() == oldSize + 1 &&
110 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
111 }
112 return false;
113}
114
115BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700116{
117 FibManagerFixture fixture;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700118 shared_ptr<InternalFace> face(make_shared<InternalFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700119 Fib fib;
120 FibManager manager(fib,
121 bind(&FibManagerFixture::getFace,
122 &fixture, _1),
123 face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700124
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700125 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700126 bind(&FibManagerFixture::validateControlResponse, &fixture, _1, 400, "Malformed command");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700127
128 Interest command("/localhost/nfd/fib");
129 face->sendInterest(command);
130}
131
132BOOST_AUTO_TEST_CASE(MalformedCommmand)
133{
134 FibManagerFixture fixture;
135 shared_ptr<InternalFace> face(make_shared<InternalFace>());
136 Fib fib;
137 FibManager manager(fib,
138 bind(&FibManagerFixture::getFace,
139 &fixture, _1),
140 face);
141
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700142 BOOST_REQUIRE(fixture.didCallbackFire() == false);
143
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700144 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700145 bind(&FibManagerFixture::validateControlResponse, &fixture, _1, 400, "Malformed command");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700146
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700147 Interest command("/localhost/nfd/fib");
148 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700149
150 BOOST_REQUIRE(fixture.didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700151}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700152
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700153BOOST_FIXTURE_TEST_CASE(UnsupportedVerb, FibManagerFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700154{
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700155 shared_ptr<InternalFace> face(make_shared<InternalFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700156 Fib fib;
157 FibManager manager(fib,
158 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700159 this, _1),
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700160 face);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700161
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700162 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700163 bind(&FibManagerFixture::validateControlResponse, this, _1, 501, "Unsupported command");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700164
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700165 ndn::FibManagementOptions options;
166 options.setName("/hello");
167 options.setFaceId(1);
168 options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700169
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700170 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700171
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700172 Name commandName("/localhost/nfd/fib");
173 commandName.append("unsupported");
174 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700175
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700176 Interest command(commandName);
177 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700178
179 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700180}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700181
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700182BOOST_FIXTURE_TEST_CASE(UnsignedCommand, FibManagerFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700183{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700184 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700185
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700186 shared_ptr<InternalFace> face(make_shared<InternalFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700187 Fib fib;
188 FibManager manager(fib,
189 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700190 this, _1),
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700191 face);
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700192 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700193 bind(&FibManagerFixture::validateControlResponse, this, _1, 200, "OK");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700194 /// \todo enable once sig checking implement
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700195 // bind(&FibManagerFixture::validateControlResponse, this, _1, 401, "SIGREG");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700196
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700197 ndn::FibManagementOptions options;
198 options.setName("/hello");
199 options.setFaceId(1);
200 options.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700201
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700202 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700203
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700204 Name commandName("/localhost/nfd/fib");
205 commandName.append("add-nexthop");
206 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700207
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700208 Interest command(commandName);
209 manager.onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700210
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700211 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700212 BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101));
213}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700214
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700215BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, FibManagerFixture)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700216{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700217 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700218
219 shared_ptr<InternalFace> face(make_shared<InternalFace>());
220 Fib fib;
221 FibManager manager(fib,
222 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700223 this, _1),
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700224 face);
225 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700226 bind(&FibManagerFixture::validateControlResponse, this, _1, 200, "OK");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700227 /// \todo enable once sig checking implement
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700228 // bind(&FibManagerFixture::validateControlResponse, this, _1, 403, "Unauthorized command");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700229
230 ndn::FibManagementOptions options;
231 options.setName("/hello");
232 options.setFaceId(1);
233 options.setCost(101);
234
235 Block encodedOptions(options.wireEncode());
236
237 Name commandName("/localhost/nfd/fib");
238 commandName.append("add-nexthop");
239 commandName.append(encodedOptions);
240
241 Interest command(commandName);
242 manager.onFibRequest(command);
243
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700244 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700245 BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101));
246}
247
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700248BOOST_FIXTURE_TEST_CASE(BadOptionParse, FibManagerFixture)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700249{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700250 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700251
252 shared_ptr<InternalFace> face(make_shared<InternalFace>());
253 Fib fib;
254 FibManager manager(fib,
255 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700256 this, _1),
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700257 face);
258
259 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700260 bind(&FibManagerFixture::validateControlResponse, this, _1, 400, "Malformed command");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700261
262 Name commandName("/localhost/nfd/fib");
263 commandName.append("add-nexthop");
264 commandName.append("NotReallyOptions");
265
266 Interest command(commandName);
267 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700268
269 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700270}
271
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700272BOOST_FIXTURE_TEST_CASE(UnknownFaceId, FibManagerFixture)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700273{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700274 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700275
276 shared_ptr<InternalFace> face(make_shared<InternalFace>());
277 Fib fib;
278 FibManager manager(fib,
279 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700280 this, _1),
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700281 face);
282
283 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700284 bind(&FibManagerFixture::validateControlResponse, this, _1, 400, "Malformed command");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700285
286 ndn::FibManagementOptions options;
287 options.setName("/hello");
288 options.setFaceId(1000);
289 options.setCost(101);
290
291 Block encodedOptions(options.wireEncode());
292
293 Name commandName("/localhost/nfd/fib");
294 commandName.append("add-nexthop");
295 commandName.append(encodedOptions);
296
297 Interest command(commandName);
298 manager.onFibRequest(command);
299
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700300 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700301 BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101) == false);
302}
303
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700304BOOST_FIXTURE_TEST_CASE(AddNextHopVerbInitialAdd, FibManagerFixture)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700305{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700306 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700307
308 shared_ptr<InternalFace> face(make_shared<InternalFace>());
309 Fib fib;
310 FibManager manager(fib,
311 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700312 this, _1),
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700313 face);
314 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700315 bind(&FibManagerFixture::validateControlResponse, this, _1, 200, "OK");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700316
317 ndn::FibManagementOptions options;
318 options.setName("/hello");
319 options.setFaceId(1);
320 options.setCost(101);
321
322 Block encodedOptions(options.wireEncode());
323
324 Name commandName("/localhost/nfd/fib");
325 commandName.append("add-nexthop");
326 commandName.append(encodedOptions);
327
328 Interest command(commandName);
329 manager.onFibRequest(command);
330
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700331 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700332 BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700333}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700334
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700335BOOST_FIXTURE_TEST_CASE(AddNextHopVerbAddToExisting, FibManagerFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700336{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700337 addFace(make_shared<DummyFace>());
338 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700339
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700340 shared_ptr<InternalFace> face(make_shared<InternalFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700341 Fib fib;
342 FibManager manager(fib,
343 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700344 this, _1),
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700345 face);
346 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700347 bind(&FibManagerFixture::validateControlResponse, this, _1, 200, "OK");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700348
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700349 // Add faces with cost == FaceID for the name /hello
350 // This test assumes:
351 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700352
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700353 for (int i = 1; i <= 2; i++)
354 {
355 ndn::FibManagementOptions options;
356 options.setName("/hello");
357 options.setFaceId(i);
358 options.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700359
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700360 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700361
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700362 Name commandName("/localhost/nfd/fib");
363 commandName.append("add-nexthop");
364 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700365
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700366 Interest command(commandName);
367 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700368 BOOST_REQUIRE(didCallbackFire());
369 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700370
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700371 shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700372
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700373 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700374 {
375 const fib::NextHopList& hops = entry->getNextHops();
376 for (int j = 1; j <= i; j++)
377 {
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700378 BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", i - 1, 100 + j));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700379 }
380 }
381 else
382 {
383 BOOST_FAIL("Failed to find expected fib entry");
384 }
385 }
386}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700387
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700388BOOST_FIXTURE_TEST_CASE(AddNextHopVerbUpdateFaceCost, FibManagerFixture)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700389{
390 FibManagerFixture fixture;
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700391 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700392
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700393 shared_ptr<InternalFace> face(make_shared<InternalFace>());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700394 Fib fib;
395 FibManager manager(fib,
396 bind(&FibManagerFixture::getFace,
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700397 this, _1),
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700398 face);
399 face->onReceiveData +=
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700400 bind(&FibManagerFixture::validateControlResponse, this, _1, 200, "OK");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700401
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700402 ndn::FibManagementOptions options;
403 options.setName("/hello");
404 options.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700405
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700406 {
407 options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700408
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700409 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700410
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700411 Name commandName("/localhost/nfd/fib");
412 commandName.append("add-nexthop");
413 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700414
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700415 Interest command(commandName);
416 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700417 BOOST_REQUIRE(didCallbackFire());
418 resetCallbackFired();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700419 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700420
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700421 {
422 options.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700423
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700424 Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700425
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700426 Name commandName("/localhost/nfd/fib");
427 commandName.append("add-nexthop");
428 commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700429
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700430 Interest command(commandName);
431 manager.onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700432 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700433 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700434
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700435 shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700436
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700437 // Add faces with cost == FaceID for the name /hello
438 // This test assumes:
439 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700440 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700441 {
442 const fib::NextHopList& hops = entry->getNextHops();
443 BOOST_REQUIRE(hops.size() == 1);
444 BOOST_REQUIRE(std::find_if(hops.begin(),
445 hops.end(),
446 bind(&foundNextHop, -1, 102, _1)) != hops.end());
447 }
448 else
449 {
450 BOOST_FAIL("Failed to find expected fib entry");
451 }
452}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700453
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700454BOOST_AUTO_TEST_SUITE_END()
455
456} // namespace nfd