blob: 5076e0de4eace68b17dea09d1ae54096a8a9bc97 [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 DiBenedetto6214e562014-03-15 16:27:04 -060017#include "fib-enumeration-publisher-common.hpp"
18
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070019namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070020namespace tests {
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070021
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070022NFD_LOG_INIT("FibManagerTest");
23
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070024class FibManagerFixture : public FibEnumerationPublisherFixture
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070025{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070026public:
27
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070028 virtual
29 ~FibManagerFixture()
Steve DiBenedettobdedce92014-02-02 22:49:39 -070030 {
Steve DiBenedettobdedce92014-02-02 22:49:39 -070031 }
32
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070033 shared_ptr<Face>
34 getFace(FaceId id)
35 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036 if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070037 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038 return m_faces[id - 1];
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070039 }
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070040 NFD_LOG_DEBUG("No face found returning NULL");
41 return shared_ptr<DummyFace>();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070042 }
43
44 void
45 addFace(shared_ptr<Face> face)
46 {
47 m_faces.push_back(face);
48 }
49
Steve DiBenedettobdedce92014-02-02 22:49:39 -070050 void
Steve DiBenedetto2693db92014-02-10 15:58:36 -070051 validateControlResponseCommon(const Data& response,
52 const Name& expectedName,
53 uint32_t expectedCode,
54 const std::string& expectedText,
55 ControlResponse& control)
Steve DiBenedettobdedce92014-02-02 22:49:39 -070056 {
57 m_callbackFired = true;
58 Block controlRaw = response.getContent().blockFromValue();
59
Steve DiBenedettobdedce92014-02-02 22:49:39 -070060 control.wireDecode(controlRaw);
61
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070062 // NFD_LOG_DEBUG("received control response"
63 // << " Name: " << response.getName()
64 // << " code: " << control.getCode()
65 // << " text: " << control.getText());
Steve DiBenedettobdedce92014-02-02 22:49:39 -070066
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070067 BOOST_CHECK_EQUAL(response.getName(), expectedName);
68 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
69 BOOST_CHECK_EQUAL(control.getText(), expectedText);
Steve DiBenedettobdedce92014-02-02 22:49:39 -070070 }
71
Steve DiBenedetto2693db92014-02-10 15:58:36 -070072 void
73 validateControlResponse(const Data& response,
74 const Name& expectedName,
75 uint32_t expectedCode,
76 const std::string& expectedText)
77 {
78 ControlResponse control;
79 validateControlResponseCommon(response, expectedName,
80 expectedCode, expectedText, control);
81
82 if (!control.getBody().empty())
83 {
84 BOOST_FAIL("found unexpected control response body");
85 }
86 }
87
88 void
89 validateControlResponse(const Data& response,
90 const Name& expectedName,
91 uint32_t expectedCode,
92 const std::string& expectedText,
93 const Block& expectedBody)
94 {
95 ControlResponse control;
96 validateControlResponseCommon(response, expectedName,
97 expectedCode, expectedText, control);
98
99 BOOST_REQUIRE(!control.getBody().empty());
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600100 BOOST_REQUIRE_EQUAL(control.getBody().value_size(), expectedBody.value_size());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700101
102 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
103 expectedBody.value_size()) == 0);
104
105 }
106
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700107 bool
108 didCallbackFire()
109 {
110 return m_callbackFired;
111 }
112
113 void
114 resetCallbackFired()
115 {
116 m_callbackFired = false;
117 }
118
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700119 shared_ptr<InternalFace>
120 getInternalFace()
121 {
122 return m_face;
123 }
124
125 FibManager&
126 getFibManager()
127 {
128 return m_manager;
129 }
130
131 Fib&
132 getFib()
133 {
134 return m_fib;
135 }
136
137 void
138 addInterestRule(const std::string& regex,
139 ndn::IdentityCertificate& certificate)
140 {
141 m_manager.addInterestRule(regex, certificate);
142 }
143
144protected:
145 FibManagerFixture()
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600146 : m_manager(boost::ref(m_fib),
147 bind(&FibManagerFixture::getFace, this, _1),
148 m_face)
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700149 , m_callbackFired(false)
150 {
151 }
152
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600153protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700154 FibManager m_manager;
155
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700156 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700157 bool m_callbackFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700158};
159
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700160template <typename T> class AuthorizedCommandFixture:
161 public CommandFixture<T>
162{
163public:
164 AuthorizedCommandFixture()
165 {
166 const std::string regex = "^<localhost><nfd><fib>";
167 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
168 }
169
170 virtual
171 ~AuthorizedCommandFixture()
172 {
173 }
174};
175
176BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, AuthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700177
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700178bool
179foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
180{
181 return id == next.getFace()->getId() && next.getCost() == cost;
182}
183
184bool
185addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
186{
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700187 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700188
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700189 if (static_cast<bool>(entry))
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700190 {
191 const fib::NextHopList& hops = entry->getNextHops();
192 return hops.size() == oldSize + 1 &&
193 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
194 }
195 return false;
196}
197
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700198bool
199foundNextHopWithFace(FaceId id, uint32_t cost,
200 shared_ptr<Face> face, const fib::NextHop& next)
201{
202 return id == next.getFace()->getId() && next.getCost() == cost && face == next.getFace();
203}
204
205bool
206addedNextHopWithFace(const Fib& fib, const Name& prefix, size_t oldSize,
207 uint32_t cost, shared_ptr<Face> face)
208{
209 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
210
211 if (static_cast<bool>(entry))
212 {
213 const fib::NextHopList& hops = entry->getNextHops();
214 return hops.size() == oldSize + 1 &&
215 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
216 }
217 return false;
218}
219
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700220BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700221{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700222 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700223
224 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700225
226 face->onReceiveData +=
227 bind(&FibManagerFixture::validateControlResponse, this, _1,
228 command.getName(), 400, "Malformed command");
229
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700230 face->sendInterest(command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700231
232 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700233}
234
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700235BOOST_AUTO_TEST_CASE(MalformedCommmand)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700236{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700237 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700238
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700239 BOOST_REQUIRE(didCallbackFire() == false);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700240
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700241 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700242
243 face->onReceiveData +=
244 bind(&FibManagerFixture::validateControlResponse, this, _1,
245 command.getName(), 400, "Malformed command");
246
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700247 getFibManager().onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700248
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700249 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700250}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700251
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700252BOOST_AUTO_TEST_CASE(UnsupportedVerb)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700253{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700254 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700255
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600256 ControlParameters parameters;
257 parameters.setName("/hello");
258 parameters.setFaceId(1);
259 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700260
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600261 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700262
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700263 Name commandName("/localhost/nfd/fib");
264 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600265 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700266
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700267 shared_ptr<Interest> command(make_shared<Interest>(commandName));
268 generateCommand(*command);
269
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700270 face->onReceiveData +=
271 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700272 command->getName(), 501, "Unsupported command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700273
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700274 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700275
276 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700277}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700278
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700279BOOST_AUTO_TEST_CASE(UnsignedCommand)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700280{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700281 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700282
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700283 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700284
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600285 ControlParameters parameters;
286 parameters.setName("/hello");
287 parameters.setFaceId(1);
288 parameters.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700289
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600290 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700291
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700292 Name commandName("/localhost/nfd/fib");
293 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600294 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700295
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700296 Interest command(commandName);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700297
298 face->onReceiveData +=
299 bind(&FibManagerFixture::validateControlResponse,
300 this, _1, command.getName(), 401, "Signature required");
301
302
303 getFibManager().onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700304
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700305 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700306 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700307}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700308
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700309BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700310{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700311 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700312
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700313 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700314
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600315 ControlParameters parameters;
316 parameters.setName("/hello");
317 parameters.setFaceId(1);
318 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700319
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600320 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700321
322 Name commandName("/localhost/nfd/fib");
323 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600324 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700325
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700326 shared_ptr<Interest> command(make_shared<Interest>(commandName));
327 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700328
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700329 face->onReceiveData +=
330 bind(&FibManagerFixture::validateControlResponse,
331 this, _1, command->getName(), 403, "Unauthorized command");
332
333 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700334
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700335 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700336 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700337}
338
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700339BOOST_AUTO_TEST_CASE(BadOptionParse)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700340{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700341 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700342
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700343 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700344
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700345 Name commandName("/localhost/nfd/fib");
346 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600347 commandName.append("NotReallyParameters");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700348
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700349 shared_ptr<Interest> command(make_shared<Interest>(commandName));
350 generateCommand(*command);
351
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700352 face->onReceiveData +=
353 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700354 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700355
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700356 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700357
358 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700359}
360
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700361BOOST_AUTO_TEST_CASE(UnknownFaceId)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700362{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700363 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700364
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700365 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700366
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600367 ControlParameters parameters;
368 parameters.setName("/hello");
369 parameters.setFaceId(1000);
370 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700371
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600372 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700373
374 Name commandName("/localhost/nfd/fib");
375 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600376 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700377
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700378 shared_ptr<Interest> command(make_shared<Interest>(commandName));
379 generateCommand(*command);
380
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700381 face->onReceiveData +=
382 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600383 command->getName(), 410, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700384
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700385 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700386
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700387 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700388 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101) == false);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700389}
390
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700391BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700392{
393 addFace(make_shared<DummyFace>());
394
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700395 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700396
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600397 ControlParameters parameters;
398 parameters.setName("/hello");
399 parameters.setFaceId(0);
400 parameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700401
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600402 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700403
404 Name commandName("/localhost/nfd/fib");
405 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600406 commandName.append(encodedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700407
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600408 ControlParameters expectedParameters;
409 expectedParameters.setName("/hello");
410 expectedParameters.setFaceId(1);
411 expectedParameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700412
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600413 Block encodedExpectedParameters(expectedParameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700414
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700415 shared_ptr<Interest> command(make_shared<Interest>(commandName));
416 command->setIncomingFaceId(1);
417 generateCommand(*command);
418
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700419 face->onReceiveData +=
420 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600421 command->getName(), 200, "Success", encodedExpectedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700422
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700423 getFibManager().onFibRequest(*command);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700424
425 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700426 BOOST_REQUIRE(addedNextHopWithFace(getFib(), "/hello", 0, 101, getFace(1)));
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700427}
428
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700429BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700430{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700431 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700432
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700433 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700434
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600435 ControlParameters parameters;
436 parameters.setName("/hello");
437 parameters.setFaceId(1);
438 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700439
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600440 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700441
442 Name commandName("/localhost/nfd/fib");
443 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600444 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700445
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700446 shared_ptr<Interest> command(make_shared<Interest>(commandName));
447 generateCommand(*command);
448
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700449 face->onReceiveData +=
450 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600451 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700452
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700453 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700454
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700455 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700456 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700457}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700458
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600459BOOST_AUTO_TEST_CASE(AddNextHopVerbImplicitCost)
460{
461 addFace(make_shared<DummyFace>());
462
463 shared_ptr<InternalFace> face = getInternalFace();
464
465 ControlParameters parameters;
466 parameters.setName("/hello");
467 parameters.setFaceId(1);
468
469 Block encodedParameters(parameters.wireEncode());
470
471 Name commandName("/localhost/nfd/fib");
472 commandName.append("add-nexthop");
473 commandName.append(encodedParameters);
474
475 shared_ptr<Interest> command(make_shared<Interest>(commandName));
476 generateCommand(*command);
477
478 ControlParameters resultParameters;
479 resultParameters.setName("/hello");
480 resultParameters.setFaceId(1);
481 resultParameters.setCost(0);
482
483 face->onReceiveData +=
484 bind(&FibManagerFixture::validateControlResponse, this, _1,
485 command->getName(), 200, "Success", resultParameters.wireEncode());
486
487 getFibManager().onFibRequest(*command);
488
489 BOOST_REQUIRE(didCallbackFire());
490 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 0));
491}
492
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700493BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700494{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700495 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700496 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700497
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700498 for (int i = 1; i <= 2; i++)
499 {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700500
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600501 ControlParameters parameters;
502 parameters.setName("/hello");
503 parameters.setFaceId(1);
504 parameters.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700505
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600506 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700507
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700508 Name commandName("/localhost/nfd/fib");
509 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600510 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700511
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700512 shared_ptr<Interest> command(make_shared<Interest>(commandName));
513 generateCommand(*command);
514
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700515 face->onReceiveData +=
516 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600517 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700518
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700519 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700520 BOOST_REQUIRE(didCallbackFire());
521 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700522
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700523 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700524
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700525 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700526 {
527 const fib::NextHopList& hops = entry->getNextHops();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700528 BOOST_REQUIRE(hops.size() == 1);
529 BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(),
530 bind(&foundNextHop, -1, 100 + i, _1)) != hops.end());
531
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700532 }
533 else
534 {
535 BOOST_FAIL("Failed to find expected fib entry");
536 }
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700537
538 face->onReceiveData.clear();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700539 }
540}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700541
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700542BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700543{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700544 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700545 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700546
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600547 ControlParameters parameters;
548 parameters.setName("/hello");
549 parameters.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700550
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700551 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600552 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700553
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600554 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700555
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700556 Name commandName("/localhost/nfd/fib");
557 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600558 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700559
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700560 shared_ptr<Interest> command(make_shared<Interest>(commandName));
561 generateCommand(*command);
562
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700563 face->onReceiveData +=
564 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600565 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700566
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700567 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700568
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700569 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700570 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700571
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700572 resetCallbackFired();
573 face->onReceiveData.clear();
574
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700575 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600576 parameters.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700577
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600578 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700579
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700580 Name commandName("/localhost/nfd/fib");
581 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600582 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700583
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700584 shared_ptr<Interest> command(make_shared<Interest>(commandName));
585 generateCommand(*command);
586
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700587 face->onReceiveData +=
588 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600589 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700590
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700591 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700592
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700593 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700594 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700595
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700596 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700597
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700598 // Add faces with cost == FaceID for the name /hello
599 // This test assumes:
600 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700601 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700602 {
603 const fib::NextHopList& hops = entry->getNextHops();
604 BOOST_REQUIRE(hops.size() == 1);
605 BOOST_REQUIRE(std::find_if(hops.begin(),
606 hops.end(),
607 bind(&foundNextHop, -1, 102, _1)) != hops.end());
608 }
609 else
610 {
611 BOOST_FAIL("Failed to find expected fib entry");
612 }
613}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700614
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600615BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingPrefix)
616{
617 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700618
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600619 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700620
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600621 ControlParameters parameters;
622 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700623
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600624 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700625
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600626 Name commandName("/localhost/nfd/fib");
627 commandName.append("add-nexthop");
628 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700629
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600630 shared_ptr<Interest> command(make_shared<Interest>(commandName));
631 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700632
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600633 face->onReceiveData +=
634 bind(&FibManagerFixture::validateControlResponse, this, _1,
635 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700636
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600637 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700638
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600639 BOOST_REQUIRE(didCallbackFire());
640}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700641
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600642BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingFaceId)
643{
644 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700645
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600646 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700647
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600648 ControlParameters parameters;
649 parameters.setName("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700650
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600651 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700652
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600653 Name commandName("/localhost/nfd/fib");
654 commandName.append("add-nexthop");
655 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700656
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600657 shared_ptr<Interest> command(make_shared<Interest>(commandName));
658 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700659
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600660 face->onReceiveData +=
661 bind(&FibManagerFixture::validateControlResponse, this, _1,
662 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700663
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600664 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700665
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600666 BOOST_REQUIRE(didCallbackFire());
667}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700668
669bool
670removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
671{
672 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
673
674 if (static_cast<bool>(entry))
675 {
676 const fib::NextHopList& hops = entry->getNextHops();
677 return hops.size() == oldSize - 1 &&
678 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end();
679 }
680 return false;
681}
682
683void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700684testRemoveNextHop(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700685 FibManager& manager,
686 Fib& fib,
687 shared_ptr<Face> face,
688 const Name& targetName,
689 FaceId targetFace)
690{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600691 ControlParameters parameters;
692 parameters.setName(targetName);
693 parameters.setFaceId(targetFace);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700694
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600695 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700696
697 Name commandName("/localhost/nfd/fib");
698 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600699 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700700
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700701 shared_ptr<Interest> command(make_shared<Interest>(commandName));
702 fixture->generateCommand(*command);
703
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700704 face->onReceiveData +=
705 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600706 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700707
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700708 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700709
710 BOOST_REQUIRE(fixture->didCallbackFire());
711
712 fixture->resetCallbackFired();
713 face->onReceiveData.clear();
714}
715
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700716BOOST_AUTO_TEST_CASE(RemoveNextHop)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700717{
718 shared_ptr<Face> face1 = make_shared<DummyFace>();
719 shared_ptr<Face> face2 = make_shared<DummyFace>();
720 shared_ptr<Face> face3 = make_shared<DummyFace>();
721
722 addFace(face1);
723 addFace(face2);
724 addFace(face3);
725
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700726 shared_ptr<InternalFace> face = getInternalFace();
727 FibManager& manager = getFibManager();
728 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700729
730 shared_ptr<fib::Entry> entry = fib.insert("/hello").first;
731
732 entry->addNextHop(face1, 101);
733 entry->addNextHop(face2, 202);
734 entry->addNextHop(face3, 303);
735
736 testRemoveNextHop(this, manager, fib, face, "/hello", 2);
737 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202));
738
739 testRemoveNextHop(this, manager, fib, face, "/hello", 3);
740 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303));
741
742 testRemoveNextHop(this, manager, fib, face, "/hello", 1);
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600743 // BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700744
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600745 BOOST_CHECK(!static_cast<bool>(getFib().findExactMatch("/hello")));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700746}
747
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600748BOOST_AUTO_TEST_CASE(RemoveFaceNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700749{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700750 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700751
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600752 ControlParameters parameters;
753 parameters.setName("/hello");
754 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700755
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600756 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700757
758 Name commandName("/localhost/nfd/fib");
759 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600760 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700761
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700762 shared_ptr<Interest> command(make_shared<Interest>(commandName));
763 generateCommand(*command);
764
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700765 face->onReceiveData +=
766 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600767 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700768
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700769 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700770
771 BOOST_REQUIRE(didCallbackFire());
772}
773
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600774BOOST_AUTO_TEST_CASE(RemovePrefixNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700775{
776 addFace(make_shared<DummyFace>());
777
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700778 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700779
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600780 ControlParameters parameters;
781 parameters.setName("/hello");
782 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700783
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600784 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700785
786 Name commandName("/localhost/nfd/fib");
787 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600788 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700789
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700790 shared_ptr<Interest> command(make_shared<Interest>(commandName));
791 generateCommand(*command);
792
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700793 face->onReceiveData +=
794 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600795 command->getName(), 200, "Success", encodedParameters);
796
797 getFibManager().onFibRequest(*command);
798
799 BOOST_REQUIRE(didCallbackFire());
800}
801
802BOOST_AUTO_TEST_CASE(RemoveMissingPrefix)
803{
804 addFace(make_shared<DummyFace>());
805
806 shared_ptr<InternalFace> face = getInternalFace();
807
808 ControlParameters parameters;
809 parameters.setFaceId(1);
810
811 Block encodedParameters(parameters.wireEncode());
812
813 Name commandName("/localhost/nfd/fib");
814 commandName.append("remove-nexthop");
815 commandName.append(encodedParameters);
816
817 shared_ptr<Interest> command(make_shared<Interest>(commandName));
818 generateCommand(*command);
819
820 face->onReceiveData +=
821 bind(&FibManagerFixture::validateControlResponse, this, _1,
822 command->getName(), 400, "Malformed command");
823
824 getFibManager().onFibRequest(*command);
825
826 BOOST_REQUIRE(didCallbackFire());
827}
828
829BOOST_AUTO_TEST_CASE(RemoveMissingFaceId)
830{
831 addFace(make_shared<DummyFace>());
832
833 shared_ptr<InternalFace> face = getInternalFace();
834
835 ControlParameters parameters;
836 parameters.setName("/hello");
837
838 Block encodedParameters(parameters.wireEncode());
839
840 Name commandName("/localhost/nfd/fib");
841 commandName.append("remove-nexthop");
842 commandName.append(encodedParameters);
843
844 shared_ptr<Interest> command(make_shared<Interest>(commandName));
845 generateCommand(*command);
846
847 face->onReceiveData +=
848 bind(&FibManagerFixture::validateControlResponse, this, _1,
849 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700850
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700851 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700852
853 BOOST_REQUIRE(didCallbackFire());
854}
855
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600856BOOST_FIXTURE_TEST_CASE(TestFibEnumerationRequest, FibManagerFixture)
857{
858 for (int i = 0; i < 87; i++)
859 {
860 Name prefix("/test");
861 prefix.appendSegment(i);
862
863 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
864 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
865
866 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
867 entry->addNextHop(dummy1, std::numeric_limits<uint64_t>::max() - 1);
868 entry->addNextHop(dummy2, std::numeric_limits<uint64_t>::max() - 2);
869
870 m_referenceEntries.insert(entry);
871 }
872 for (int i = 0; i < 2; i++)
873 {
874 Name prefix("/test2");
875 prefix.appendSegment(i);
876
877 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
878 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
879
880 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
881 entry->addNextHop(dummy1, std::numeric_limits<uint8_t>::max() - 1);
882 entry->addNextHop(dummy2, std::numeric_limits<uint8_t>::max() - 2);
883
884 m_referenceEntries.insert(entry);
885 }
886
887 ndn::EncodingBuffer buffer;
888
889 m_face->onReceiveData +=
890 bind(&FibEnumerationPublisherFixture::decodeFibEntryBlock, this, _1);
891
892 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/fib/list"));
893
894 m_manager.onFibRequest(*command);
895 BOOST_REQUIRE(m_finished);
896}
897
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700898BOOST_AUTO_TEST_SUITE_END()
899
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700900} // namespace tests
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700901} // namespace nfd