blob: 2305c2ca7f388a03e70dd2d328a9ad40c8b10fbf [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070024
25#include "mgmt/fib-manager.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070026#include "table/fib.hpp"
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070027#include "table/fib-nexthop.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070028#include "face/face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -070029#include "mgmt/internal-face.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070030#include "tests/daemon/face/dummy-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070031
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070032#include "validation-common.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033#include "tests/test-common.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070034
Steve DiBenedetto6214e562014-03-15 16:27:04 -060035#include "fib-enumeration-publisher-common.hpp"
36
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070037namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038namespace tests {
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070039
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070040NFD_LOG_INIT("FibManagerTest");
41
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070042class FibManagerFixture : public FibEnumerationPublisherFixture
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070043{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070044public:
45
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070046 virtual
47 ~FibManagerFixture()
Steve DiBenedettobdedce92014-02-02 22:49:39 -070048 {
Steve DiBenedettobdedce92014-02-02 22:49:39 -070049 }
50
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070051 shared_ptr<Face>
52 getFace(FaceId id)
53 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070054 if (id > 0 && static_cast<size_t>(id) <= m_faces.size())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070055 {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070056 return m_faces[id - 1];
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070057 }
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070058 NFD_LOG_DEBUG("No face found returning NULL");
59 return shared_ptr<DummyFace>();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070060 }
61
62 void
63 addFace(shared_ptr<Face> face)
64 {
65 m_faces.push_back(face);
66 }
67
Steve DiBenedettobdedce92014-02-02 22:49:39 -070068 void
Steve DiBenedetto2693db92014-02-10 15:58:36 -070069 validateControlResponseCommon(const Data& response,
70 const Name& expectedName,
71 uint32_t expectedCode,
72 const std::string& expectedText,
73 ControlResponse& control)
Steve DiBenedettobdedce92014-02-02 22:49:39 -070074 {
75 m_callbackFired = true;
76 Block controlRaw = response.getContent().blockFromValue();
77
Steve DiBenedettobdedce92014-02-02 22:49:39 -070078 control.wireDecode(controlRaw);
79
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070080 // NFD_LOG_DEBUG("received control response"
81 // << " Name: " << response.getName()
82 // << " code: " << control.getCode()
83 // << " text: " << control.getText());
Steve DiBenedettobdedce92014-02-02 22:49:39 -070084
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070085 BOOST_CHECK_EQUAL(response.getName(), expectedName);
86 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
87 BOOST_CHECK_EQUAL(control.getText(), expectedText);
Steve DiBenedettobdedce92014-02-02 22:49:39 -070088 }
89
Steve DiBenedetto2693db92014-02-10 15:58:36 -070090 void
91 validateControlResponse(const Data& response,
92 const Name& expectedName,
93 uint32_t expectedCode,
94 const std::string& expectedText)
95 {
96 ControlResponse control;
97 validateControlResponseCommon(response, expectedName,
98 expectedCode, expectedText, control);
99
100 if (!control.getBody().empty())
101 {
102 BOOST_FAIL("found unexpected control response body");
103 }
104 }
105
106 void
107 validateControlResponse(const Data& response,
108 const Name& expectedName,
109 uint32_t expectedCode,
110 const std::string& expectedText,
111 const Block& expectedBody)
112 {
113 ControlResponse control;
114 validateControlResponseCommon(response, expectedName,
115 expectedCode, expectedText, control);
116
117 BOOST_REQUIRE(!control.getBody().empty());
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600118 BOOST_REQUIRE_EQUAL(control.getBody().value_size(), expectedBody.value_size());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700119
120 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
121 expectedBody.value_size()) == 0);
122
123 }
124
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700125 bool
126 didCallbackFire()
127 {
128 return m_callbackFired;
129 }
130
131 void
132 resetCallbackFired()
133 {
134 m_callbackFired = false;
135 }
136
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700137 shared_ptr<InternalFace>
138 getInternalFace()
139 {
140 return m_face;
141 }
142
143 FibManager&
144 getFibManager()
145 {
146 return m_manager;
147 }
148
149 Fib&
150 getFib()
151 {
152 return m_fib;
153 }
154
155 void
156 addInterestRule(const std::string& regex,
157 ndn::IdentityCertificate& certificate)
158 {
159 m_manager.addInterestRule(regex, certificate);
160 }
161
162protected:
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700163 FibManagerFixture()
164 : m_manager(ref(m_fib), bind(&FibManagerFixture::getFace, this, _1), m_face)
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700165 , m_callbackFired(false)
166 {
167 }
168
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600169protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700170 FibManager m_manager;
171
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700172 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700173 bool m_callbackFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700174};
175
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700176template <typename T> class AuthorizedCommandFixture:
177 public CommandFixture<T>
178{
179public:
180 AuthorizedCommandFixture()
181 {
182 const std::string regex = "^<localhost><nfd><fib>";
183 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
184 }
185
186 virtual
187 ~AuthorizedCommandFixture()
188 {
189 }
190};
191
192BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, AuthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700193
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700194bool
195foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
196{
197 return id == next.getFace()->getId() && next.getCost() == cost;
198}
199
200bool
201addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
202{
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700203 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700204
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700205 if (static_cast<bool>(entry))
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700206 {
207 const fib::NextHopList& hops = entry->getNextHops();
208 return hops.size() == oldSize + 1 &&
209 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
210 }
211 return false;
212}
213
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700214bool
215foundNextHopWithFace(FaceId id, uint32_t cost,
216 shared_ptr<Face> face, const fib::NextHop& next)
217{
218 return id == next.getFace()->getId() && next.getCost() == cost && face == next.getFace();
219}
220
221bool
222addedNextHopWithFace(const Fib& fib, const Name& prefix, size_t oldSize,
223 uint32_t cost, shared_ptr<Face> face)
224{
225 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
226
227 if (static_cast<bool>(entry))
228 {
229 const fib::NextHopList& hops = entry->getNextHops();
230 return hops.size() == oldSize + 1 &&
231 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
232 }
233 return false;
234}
235
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700236BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700237{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700238 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700239
Junxiao Shi72c3e042014-04-08 15:02:37 -0700240 shared_ptr<Interest> command = makeInterest("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700241
242 face->onReceiveData +=
243 bind(&FibManagerFixture::validateControlResponse, this, _1,
Junxiao Shi72c3e042014-04-08 15:02:37 -0700244 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700245
Junxiao Shi72c3e042014-04-08 15:02:37 -0700246 face->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700247 g_io.run_one();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700248
249 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700250}
251
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700252BOOST_AUTO_TEST_CASE(MalformedCommmand)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700253{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700254 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700255
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700256 BOOST_REQUIRE(didCallbackFire() == false);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700257
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700258 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700259
260 face->onReceiveData +=
261 bind(&FibManagerFixture::validateControlResponse, this, _1,
262 command.getName(), 400, "Malformed command");
263
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700264 getFibManager().onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700265
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700266 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700267}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700268
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700269BOOST_AUTO_TEST_CASE(UnsupportedVerb)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700270{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700271 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700272
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600273 ControlParameters parameters;
274 parameters.setName("/hello");
275 parameters.setFaceId(1);
276 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700277
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600278 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700279
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700280 Name commandName("/localhost/nfd/fib");
281 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600282 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700283
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700284 shared_ptr<Interest> command(make_shared<Interest>(commandName));
285 generateCommand(*command);
286
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700287 face->onReceiveData +=
288 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700289 command->getName(), 501, "Unsupported command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700290
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700291 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700292
293 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700294}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700295
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700296BOOST_AUTO_TEST_CASE(UnsignedCommand)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700297{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700298 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700299
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700300 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700301
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600302 ControlParameters parameters;
303 parameters.setName("/hello");
304 parameters.setFaceId(1);
305 parameters.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700306
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600307 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700308
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700309 Name commandName("/localhost/nfd/fib");
310 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600311 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700312
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700313 Interest command(commandName);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700314
315 face->onReceiveData +=
316 bind(&FibManagerFixture::validateControlResponse,
317 this, _1, command.getName(), 401, "Signature required");
318
319
320 getFibManager().onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700321
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700322 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700323 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700324}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700325
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700326BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700327{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700328 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700329
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700330 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700331
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600332 ControlParameters parameters;
333 parameters.setName("/hello");
334 parameters.setFaceId(1);
335 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700336
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600337 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700338
339 Name commandName("/localhost/nfd/fib");
340 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600341 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700342
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700343 shared_ptr<Interest> command(make_shared<Interest>(commandName));
344 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700345
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700346 face->onReceiveData +=
347 bind(&FibManagerFixture::validateControlResponse,
348 this, _1, command->getName(), 403, "Unauthorized command");
349
350 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700351
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700352 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700353 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700354}
355
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700356BOOST_AUTO_TEST_CASE(BadOptionParse)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700357{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700358 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700359
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700360 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700361
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700362 Name commandName("/localhost/nfd/fib");
363 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600364 commandName.append("NotReallyParameters");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700365
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700366 shared_ptr<Interest> command(make_shared<Interest>(commandName));
367 generateCommand(*command);
368
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700369 face->onReceiveData +=
370 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700371 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700372
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700373 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700374
375 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700376}
377
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700378BOOST_AUTO_TEST_CASE(UnknownFaceId)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700379{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700380 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700381
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700382 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700383
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600384 ControlParameters parameters;
385 parameters.setName("/hello");
386 parameters.setFaceId(1000);
387 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700388
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600389 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700390
391 Name commandName("/localhost/nfd/fib");
392 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600393 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700394
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700395 shared_ptr<Interest> command(make_shared<Interest>(commandName));
396 generateCommand(*command);
397
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700398 face->onReceiveData +=
399 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600400 command->getName(), 410, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700401
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700402 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700403
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700404 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700405 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101) == false);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700406}
407
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700408BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700409{
410 addFace(make_shared<DummyFace>());
411
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700412 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700413
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600414 ControlParameters parameters;
415 parameters.setName("/hello");
416 parameters.setFaceId(0);
417 parameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700418
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600419 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700420
421 Name commandName("/localhost/nfd/fib");
422 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600423 commandName.append(encodedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700424
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600425 ControlParameters expectedParameters;
426 expectedParameters.setName("/hello");
427 expectedParameters.setFaceId(1);
428 expectedParameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700429
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600430 Block encodedExpectedParameters(expectedParameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700431
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700432 shared_ptr<Interest> command(make_shared<Interest>(commandName));
433 command->setIncomingFaceId(1);
434 generateCommand(*command);
435
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700436 face->onReceiveData +=
437 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600438 command->getName(), 200, "Success", encodedExpectedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700439
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700440 getFibManager().onFibRequest(*command);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700441
442 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700443 BOOST_REQUIRE(addedNextHopWithFace(getFib(), "/hello", 0, 101, getFace(1)));
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700444}
445
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700446BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700447{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700448 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700449
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700450 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700451
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600452 ControlParameters parameters;
453 parameters.setName("/hello");
454 parameters.setFaceId(1);
455 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700456
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600457 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700458
459 Name commandName("/localhost/nfd/fib");
460 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600461 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700462
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700463 shared_ptr<Interest> command(make_shared<Interest>(commandName));
464 generateCommand(*command);
465
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700466 face->onReceiveData +=
467 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600468 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700469
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700470 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700471
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700472 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700473 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700474}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700475
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600476BOOST_AUTO_TEST_CASE(AddNextHopVerbImplicitCost)
477{
478 addFace(make_shared<DummyFace>());
479
480 shared_ptr<InternalFace> face = getInternalFace();
481
482 ControlParameters parameters;
483 parameters.setName("/hello");
484 parameters.setFaceId(1);
485
486 Block encodedParameters(parameters.wireEncode());
487
488 Name commandName("/localhost/nfd/fib");
489 commandName.append("add-nexthop");
490 commandName.append(encodedParameters);
491
492 shared_ptr<Interest> command(make_shared<Interest>(commandName));
493 generateCommand(*command);
494
495 ControlParameters resultParameters;
496 resultParameters.setName("/hello");
497 resultParameters.setFaceId(1);
498 resultParameters.setCost(0);
499
500 face->onReceiveData +=
501 bind(&FibManagerFixture::validateControlResponse, this, _1,
502 command->getName(), 200, "Success", resultParameters.wireEncode());
503
504 getFibManager().onFibRequest(*command);
505
506 BOOST_REQUIRE(didCallbackFire());
507 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 0));
508}
509
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700510BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700511{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700512 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700513 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700514
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700515 for (int i = 1; i <= 2; i++)
516 {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700517
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600518 ControlParameters parameters;
519 parameters.setName("/hello");
520 parameters.setFaceId(1);
521 parameters.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700522
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600523 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700524
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700525 Name commandName("/localhost/nfd/fib");
526 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600527 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700528
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700529 shared_ptr<Interest> command(make_shared<Interest>(commandName));
530 generateCommand(*command);
531
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700532 face->onReceiveData +=
533 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600534 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700535
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700536 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700537 BOOST_REQUIRE(didCallbackFire());
538 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700539
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700540 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700541
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700542 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700543 {
544 const fib::NextHopList& hops = entry->getNextHops();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700545 BOOST_REQUIRE(hops.size() == 1);
546 BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(),
547 bind(&foundNextHop, -1, 100 + i, _1)) != hops.end());
548
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700549 }
550 else
551 {
552 BOOST_FAIL("Failed to find expected fib entry");
553 }
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700554
555 face->onReceiveData.clear();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700556 }
557}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700558
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700559BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700560{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700561 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700562 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700563
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600564 ControlParameters parameters;
565 parameters.setName("/hello");
566 parameters.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700567
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700568 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600569 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700570
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600571 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700572
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700573 Name commandName("/localhost/nfd/fib");
574 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600575 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700576
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700577 shared_ptr<Interest> command(make_shared<Interest>(commandName));
578 generateCommand(*command);
579
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700580 face->onReceiveData +=
581 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600582 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700583
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700584 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700585
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700586 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700587 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700588
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700589 resetCallbackFired();
590 face->onReceiveData.clear();
591
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700592 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600593 parameters.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700594
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600595 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700596
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700597 Name commandName("/localhost/nfd/fib");
598 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600599 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700600
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700601 shared_ptr<Interest> command(make_shared<Interest>(commandName));
602 generateCommand(*command);
603
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700604 face->onReceiveData +=
605 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600606 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700607
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700608 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700609
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700610 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700611 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700612
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700613 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700614
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700615 // Add faces with cost == FaceID for the name /hello
616 // This test assumes:
617 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700618 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700619 {
620 const fib::NextHopList& hops = entry->getNextHops();
621 BOOST_REQUIRE(hops.size() == 1);
622 BOOST_REQUIRE(std::find_if(hops.begin(),
623 hops.end(),
624 bind(&foundNextHop, -1, 102, _1)) != hops.end());
625 }
626 else
627 {
628 BOOST_FAIL("Failed to find expected fib entry");
629 }
630}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700631
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600632BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingPrefix)
633{
634 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700635
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600636 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700637
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600638 ControlParameters parameters;
639 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700640
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600641 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700642
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600643 Name commandName("/localhost/nfd/fib");
644 commandName.append("add-nexthop");
645 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700646
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600647 shared_ptr<Interest> command(make_shared<Interest>(commandName));
648 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700649
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600650 face->onReceiveData +=
651 bind(&FibManagerFixture::validateControlResponse, this, _1,
652 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700653
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600654 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700655
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600656 BOOST_REQUIRE(didCallbackFire());
657}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700658
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600659BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingFaceId)
660{
661 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700662
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600663 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700664
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600665 ControlParameters parameters;
666 parameters.setName("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700667
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600668 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700669
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600670 Name commandName("/localhost/nfd/fib");
671 commandName.append("add-nexthop");
672 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700673
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600674 shared_ptr<Interest> command(make_shared<Interest>(commandName));
675 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700676
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600677 face->onReceiveData +=
678 bind(&FibManagerFixture::validateControlResponse, this, _1,
679 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700680
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600681 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700682
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600683 BOOST_REQUIRE(didCallbackFire());
684}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700685
686bool
687removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
688{
689 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
690
691 if (static_cast<bool>(entry))
692 {
693 const fib::NextHopList& hops = entry->getNextHops();
694 return hops.size() == oldSize - 1 &&
695 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end();
696 }
697 return false;
698}
699
700void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700701testRemoveNextHop(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700702 FibManager& manager,
703 Fib& fib,
704 shared_ptr<Face> face,
705 const Name& targetName,
706 FaceId targetFace)
707{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600708 ControlParameters parameters;
709 parameters.setName(targetName);
710 parameters.setFaceId(targetFace);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700711
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600712 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700713
714 Name commandName("/localhost/nfd/fib");
715 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600716 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700717
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700718 shared_ptr<Interest> command(make_shared<Interest>(commandName));
719 fixture->generateCommand(*command);
720
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700721 face->onReceiveData +=
722 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600723 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700724
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700725 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700726
727 BOOST_REQUIRE(fixture->didCallbackFire());
728
729 fixture->resetCallbackFired();
730 face->onReceiveData.clear();
731}
732
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700733BOOST_AUTO_TEST_CASE(RemoveNextHop)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700734{
735 shared_ptr<Face> face1 = make_shared<DummyFace>();
736 shared_ptr<Face> face2 = make_shared<DummyFace>();
737 shared_ptr<Face> face3 = make_shared<DummyFace>();
738
739 addFace(face1);
740 addFace(face2);
741 addFace(face3);
742
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700743 shared_ptr<InternalFace> face = getInternalFace();
744 FibManager& manager = getFibManager();
745 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700746
747 shared_ptr<fib::Entry> entry = fib.insert("/hello").first;
748
749 entry->addNextHop(face1, 101);
750 entry->addNextHop(face2, 202);
751 entry->addNextHop(face3, 303);
752
753 testRemoveNextHop(this, manager, fib, face, "/hello", 2);
754 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202));
755
756 testRemoveNextHop(this, manager, fib, face, "/hello", 3);
757 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303));
758
759 testRemoveNextHop(this, manager, fib, face, "/hello", 1);
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600760 // BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700761
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600762 BOOST_CHECK(!static_cast<bool>(getFib().findExactMatch("/hello")));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700763}
764
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600765BOOST_AUTO_TEST_CASE(RemoveFaceNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700766{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700767 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700768
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600769 ControlParameters parameters;
770 parameters.setName("/hello");
771 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700772
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600773 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700774
775 Name commandName("/localhost/nfd/fib");
776 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600777 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700778
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700779 shared_ptr<Interest> command(make_shared<Interest>(commandName));
780 generateCommand(*command);
781
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700782 face->onReceiveData +=
783 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600784 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700785
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700786 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700787
788 BOOST_REQUIRE(didCallbackFire());
789}
790
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600791BOOST_AUTO_TEST_CASE(RemovePrefixNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700792{
793 addFace(make_shared<DummyFace>());
794
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700795 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700796
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600797 ControlParameters parameters;
798 parameters.setName("/hello");
799 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700800
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600801 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700802
803 Name commandName("/localhost/nfd/fib");
804 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600805 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700806
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700807 shared_ptr<Interest> command(make_shared<Interest>(commandName));
808 generateCommand(*command);
809
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700810 face->onReceiveData +=
811 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600812 command->getName(), 200, "Success", encodedParameters);
813
814 getFibManager().onFibRequest(*command);
815
816 BOOST_REQUIRE(didCallbackFire());
817}
818
819BOOST_AUTO_TEST_CASE(RemoveMissingPrefix)
820{
821 addFace(make_shared<DummyFace>());
822
823 shared_ptr<InternalFace> face = getInternalFace();
824
825 ControlParameters parameters;
826 parameters.setFaceId(1);
827
828 Block encodedParameters(parameters.wireEncode());
829
830 Name commandName("/localhost/nfd/fib");
831 commandName.append("remove-nexthop");
832 commandName.append(encodedParameters);
833
834 shared_ptr<Interest> command(make_shared<Interest>(commandName));
835 generateCommand(*command);
836
837 face->onReceiveData +=
838 bind(&FibManagerFixture::validateControlResponse, this, _1,
839 command->getName(), 400, "Malformed command");
840
841 getFibManager().onFibRequest(*command);
842
843 BOOST_REQUIRE(didCallbackFire());
844}
845
846BOOST_AUTO_TEST_CASE(RemoveMissingFaceId)
847{
848 addFace(make_shared<DummyFace>());
849
850 shared_ptr<InternalFace> face = getInternalFace();
851
852 ControlParameters parameters;
853 parameters.setName("/hello");
854
855 Block encodedParameters(parameters.wireEncode());
856
857 Name commandName("/localhost/nfd/fib");
858 commandName.append("remove-nexthop");
859 commandName.append(encodedParameters);
860
861 shared_ptr<Interest> command(make_shared<Interest>(commandName));
862 generateCommand(*command);
863
864 face->onReceiveData +=
865 bind(&FibManagerFixture::validateControlResponse, this, _1,
866 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700867
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700868 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700869
870 BOOST_REQUIRE(didCallbackFire());
871}
872
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600873BOOST_FIXTURE_TEST_CASE(TestFibEnumerationRequest, FibManagerFixture)
874{
875 for (int i = 0; i < 87; i++)
876 {
877 Name prefix("/test");
878 prefix.appendSegment(i);
879
880 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
881 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
882
883 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
884 entry->addNextHop(dummy1, std::numeric_limits<uint64_t>::max() - 1);
885 entry->addNextHop(dummy2, std::numeric_limits<uint64_t>::max() - 2);
886
887 m_referenceEntries.insert(entry);
888 }
889 for (int i = 0; i < 2; i++)
890 {
891 Name prefix("/test2");
892 prefix.appendSegment(i);
893
894 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
895 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
896
897 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
898 entry->addNextHop(dummy1, std::numeric_limits<uint8_t>::max() - 1);
899 entry->addNextHop(dummy2, std::numeric_limits<uint8_t>::max() - 2);
900
901 m_referenceEntries.insert(entry);
902 }
903
904 ndn::EncodingBuffer buffer;
905
906 m_face->onReceiveData +=
907 bind(&FibEnumerationPublisherFixture::decodeFibEntryBlock, this, _1);
908
909 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/fib/list"));
910
911 m_manager.onFibRequest(*command);
912 BOOST_REQUIRE(m_finished);
913}
914
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700915BOOST_AUTO_TEST_SUITE_END()
916
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700917} // namespace tests
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700918} // namespace nfd