blob: f2d059add2bbdfaae354d669e00b8a05b744b298 [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"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030#include "tests/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:
163 FibManagerFixture()
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600164 : m_manager(boost::ref(m_fib),
165 bind(&FibManagerFixture::getFace, this, _1),
166 m_face)
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700167 , m_callbackFired(false)
168 {
169 }
170
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600171protected:
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700172 FibManager m_manager;
173
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700174 std::vector<shared_ptr<Face> > m_faces;
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700175 bool m_callbackFired;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700176};
177
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700178template <typename T> class AuthorizedCommandFixture:
179 public CommandFixture<T>
180{
181public:
182 AuthorizedCommandFixture()
183 {
184 const std::string regex = "^<localhost><nfd><fib>";
185 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
186 }
187
188 virtual
189 ~AuthorizedCommandFixture()
190 {
191 }
192};
193
194BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, AuthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700195
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700196bool
197foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next)
198{
199 return id == next.getFace()->getId() && next.getCost() == cost;
200}
201
202bool
203addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
204{
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700205 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700206
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700207 if (static_cast<bool>(entry))
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700208 {
209 const fib::NextHopList& hops = entry->getNextHops();
210 return hops.size() == oldSize + 1 &&
211 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
212 }
213 return false;
214}
215
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700216bool
217foundNextHopWithFace(FaceId id, uint32_t cost,
218 shared_ptr<Face> face, const fib::NextHop& next)
219{
220 return id == next.getFace()->getId() && next.getCost() == cost && face == next.getFace();
221}
222
223bool
224addedNextHopWithFace(const Fib& fib, const Name& prefix, size_t oldSize,
225 uint32_t cost, shared_ptr<Face> face)
226{
227 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
228
229 if (static_cast<bool>(entry))
230 {
231 const fib::NextHopList& hops = entry->getNextHops();
232 return hops.size() == oldSize + 1 &&
233 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end();
234 }
235 return false;
236}
237
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700238BOOST_AUTO_TEST_CASE(TestFireInterestFilter)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700239{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700240 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700241
242 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700243
244 face->onReceiveData +=
245 bind(&FibManagerFixture::validateControlResponse, this, _1,
246 command.getName(), 400, "Malformed command");
247
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700248 face->sendInterest(command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700249 g_io.run_one();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700250
251 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700252}
253
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700254BOOST_AUTO_TEST_CASE(MalformedCommmand)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700255{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700256 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700257
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700258 BOOST_REQUIRE(didCallbackFire() == false);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700259
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700260 Interest command("/localhost/nfd/fib");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700261
262 face->onReceiveData +=
263 bind(&FibManagerFixture::validateControlResponse, this, _1,
264 command.getName(), 400, "Malformed command");
265
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700266 getFibManager().onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700267
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700268 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700269}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700270
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700271BOOST_AUTO_TEST_CASE(UnsupportedVerb)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700272{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700273 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700274
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600275 ControlParameters parameters;
276 parameters.setName("/hello");
277 parameters.setFaceId(1);
278 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700279
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600280 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700281
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700282 Name commandName("/localhost/nfd/fib");
283 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600284 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700285
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700286 shared_ptr<Interest> command(make_shared<Interest>(commandName));
287 generateCommand(*command);
288
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700289 face->onReceiveData +=
290 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700291 command->getName(), 501, "Unsupported command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700292
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700293 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700294
295 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700296}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700297
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700298BOOST_AUTO_TEST_CASE(UnsignedCommand)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700299{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700300 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700301
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700302 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700303
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600304 ControlParameters parameters;
305 parameters.setName("/hello");
306 parameters.setFaceId(1);
307 parameters.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700308
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600309 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700310
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700311 Name commandName("/localhost/nfd/fib");
312 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600313 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700314
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700315 Interest command(commandName);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700316
317 face->onReceiveData +=
318 bind(&FibManagerFixture::validateControlResponse,
319 this, _1, command.getName(), 401, "Signature required");
320
321
322 getFibManager().onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700323
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700324 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700325 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700326}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700327
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700328BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700329{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700330 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700331
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700332 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700333
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600334 ControlParameters parameters;
335 parameters.setName("/hello");
336 parameters.setFaceId(1);
337 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700338
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600339 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700340
341 Name commandName("/localhost/nfd/fib");
342 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600343 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700344
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700345 shared_ptr<Interest> command(make_shared<Interest>(commandName));
346 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700347
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700348 face->onReceiveData +=
349 bind(&FibManagerFixture::validateControlResponse,
350 this, _1, command->getName(), 403, "Unauthorized command");
351
352 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700353
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700354 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700355 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700356}
357
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700358BOOST_AUTO_TEST_CASE(BadOptionParse)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700359{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700360 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700361
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700362 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700363
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700364 Name commandName("/localhost/nfd/fib");
365 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600366 commandName.append("NotReallyParameters");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700367
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700368 shared_ptr<Interest> command(make_shared<Interest>(commandName));
369 generateCommand(*command);
370
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700371 face->onReceiveData +=
372 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700373 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700374
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700375 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700376
377 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700378}
379
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700380BOOST_AUTO_TEST_CASE(UnknownFaceId)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700381{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700382 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700383
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700384 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700385
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600386 ControlParameters parameters;
387 parameters.setName("/hello");
388 parameters.setFaceId(1000);
389 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700390
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600391 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700392
393 Name commandName("/localhost/nfd/fib");
394 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600395 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700396
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700397 shared_ptr<Interest> command(make_shared<Interest>(commandName));
398 generateCommand(*command);
399
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700400 face->onReceiveData +=
401 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600402 command->getName(), 410, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700403
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700404 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700405
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700406 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700407 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101) == false);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700408}
409
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700410BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700411{
412 addFace(make_shared<DummyFace>());
413
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700414 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700415
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600416 ControlParameters parameters;
417 parameters.setName("/hello");
418 parameters.setFaceId(0);
419 parameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700420
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600421 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700422
423 Name commandName("/localhost/nfd/fib");
424 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600425 commandName.append(encodedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700426
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600427 ControlParameters expectedParameters;
428 expectedParameters.setName("/hello");
429 expectedParameters.setFaceId(1);
430 expectedParameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700431
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600432 Block encodedExpectedParameters(expectedParameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700433
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700434 shared_ptr<Interest> command(make_shared<Interest>(commandName));
435 command->setIncomingFaceId(1);
436 generateCommand(*command);
437
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700438 face->onReceiveData +=
439 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600440 command->getName(), 200, "Success", encodedExpectedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700441
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700442 getFibManager().onFibRequest(*command);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700443
444 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700445 BOOST_REQUIRE(addedNextHopWithFace(getFib(), "/hello", 0, 101, getFace(1)));
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700446}
447
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700448BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700449{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700450 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700451
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700452 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700453
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600454 ControlParameters parameters;
455 parameters.setName("/hello");
456 parameters.setFaceId(1);
457 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700458
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600459 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700460
461 Name commandName("/localhost/nfd/fib");
462 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600463 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700464
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700465 shared_ptr<Interest> command(make_shared<Interest>(commandName));
466 generateCommand(*command);
467
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700468 face->onReceiveData +=
469 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600470 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700471
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700472 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700473
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700474 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700475 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700476}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700477
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600478BOOST_AUTO_TEST_CASE(AddNextHopVerbImplicitCost)
479{
480 addFace(make_shared<DummyFace>());
481
482 shared_ptr<InternalFace> face = getInternalFace();
483
484 ControlParameters parameters;
485 parameters.setName("/hello");
486 parameters.setFaceId(1);
487
488 Block encodedParameters(parameters.wireEncode());
489
490 Name commandName("/localhost/nfd/fib");
491 commandName.append("add-nexthop");
492 commandName.append(encodedParameters);
493
494 shared_ptr<Interest> command(make_shared<Interest>(commandName));
495 generateCommand(*command);
496
497 ControlParameters resultParameters;
498 resultParameters.setName("/hello");
499 resultParameters.setFaceId(1);
500 resultParameters.setCost(0);
501
502 face->onReceiveData +=
503 bind(&FibManagerFixture::validateControlResponse, this, _1,
504 command->getName(), 200, "Success", resultParameters.wireEncode());
505
506 getFibManager().onFibRequest(*command);
507
508 BOOST_REQUIRE(didCallbackFire());
509 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 0));
510}
511
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700512BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700513{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700514 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700515 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700516
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700517 for (int i = 1; i <= 2; i++)
518 {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700519
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600520 ControlParameters parameters;
521 parameters.setName("/hello");
522 parameters.setFaceId(1);
523 parameters.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700524
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600525 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700526
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700527 Name commandName("/localhost/nfd/fib");
528 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600529 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700530
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700531 shared_ptr<Interest> command(make_shared<Interest>(commandName));
532 generateCommand(*command);
533
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700534 face->onReceiveData +=
535 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600536 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700537
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700538 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700539 BOOST_REQUIRE(didCallbackFire());
540 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700541
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700542 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700543
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700544 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700545 {
546 const fib::NextHopList& hops = entry->getNextHops();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700547 BOOST_REQUIRE(hops.size() == 1);
548 BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(),
549 bind(&foundNextHop, -1, 100 + i, _1)) != hops.end());
550
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700551 }
552 else
553 {
554 BOOST_FAIL("Failed to find expected fib entry");
555 }
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700556
557 face->onReceiveData.clear();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700558 }
559}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700560
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700561BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700562{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700563 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700564 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700565
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600566 ControlParameters parameters;
567 parameters.setName("/hello");
568 parameters.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700569
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700570 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600571 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700572
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600573 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700574
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700575 Name commandName("/localhost/nfd/fib");
576 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600577 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700578
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700579 shared_ptr<Interest> command(make_shared<Interest>(commandName));
580 generateCommand(*command);
581
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700582 face->onReceiveData +=
583 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600584 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700585
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700586 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700587
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700588 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700589 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700590
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700591 resetCallbackFired();
592 face->onReceiveData.clear();
593
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700594 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600595 parameters.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700596
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600597 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700598
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700599 Name commandName("/localhost/nfd/fib");
600 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600601 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700602
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700603 shared_ptr<Interest> command(make_shared<Interest>(commandName));
604 generateCommand(*command);
605
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700606 face->onReceiveData +=
607 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600608 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700609
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700610 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700611
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700612 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700613 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700614
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700615 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700616
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700617 // Add faces with cost == FaceID for the name /hello
618 // This test assumes:
619 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700620 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700621 {
622 const fib::NextHopList& hops = entry->getNextHops();
623 BOOST_REQUIRE(hops.size() == 1);
624 BOOST_REQUIRE(std::find_if(hops.begin(),
625 hops.end(),
626 bind(&foundNextHop, -1, 102, _1)) != hops.end());
627 }
628 else
629 {
630 BOOST_FAIL("Failed to find expected fib entry");
631 }
632}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700633
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600634BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingPrefix)
635{
636 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700637
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600638 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700639
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600640 ControlParameters parameters;
641 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700642
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600643 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700644
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600645 Name commandName("/localhost/nfd/fib");
646 commandName.append("add-nexthop");
647 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700648
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600649 shared_ptr<Interest> command(make_shared<Interest>(commandName));
650 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700651
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600652 face->onReceiveData +=
653 bind(&FibManagerFixture::validateControlResponse, this, _1,
654 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700655
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600656 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700657
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600658 BOOST_REQUIRE(didCallbackFire());
659}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700660
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600661BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingFaceId)
662{
663 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700664
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600665 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700666
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600667 ControlParameters parameters;
668 parameters.setName("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700669
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600670 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700671
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600672 Name commandName("/localhost/nfd/fib");
673 commandName.append("add-nexthop");
674 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700675
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600676 shared_ptr<Interest> command(make_shared<Interest>(commandName));
677 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700678
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600679 face->onReceiveData +=
680 bind(&FibManagerFixture::validateControlResponse, this, _1,
681 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700682
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600683 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700684
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600685 BOOST_REQUIRE(didCallbackFire());
686}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700687
688bool
689removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
690{
691 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
692
693 if (static_cast<bool>(entry))
694 {
695 const fib::NextHopList& hops = entry->getNextHops();
696 return hops.size() == oldSize - 1 &&
697 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end();
698 }
699 return false;
700}
701
702void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700703testRemoveNextHop(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700704 FibManager& manager,
705 Fib& fib,
706 shared_ptr<Face> face,
707 const Name& targetName,
708 FaceId targetFace)
709{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600710 ControlParameters parameters;
711 parameters.setName(targetName);
712 parameters.setFaceId(targetFace);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700713
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600714 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700715
716 Name commandName("/localhost/nfd/fib");
717 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600718 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700719
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700720 shared_ptr<Interest> command(make_shared<Interest>(commandName));
721 fixture->generateCommand(*command);
722
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700723 face->onReceiveData +=
724 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600725 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700726
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700727 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700728
729 BOOST_REQUIRE(fixture->didCallbackFire());
730
731 fixture->resetCallbackFired();
732 face->onReceiveData.clear();
733}
734
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700735BOOST_AUTO_TEST_CASE(RemoveNextHop)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700736{
737 shared_ptr<Face> face1 = make_shared<DummyFace>();
738 shared_ptr<Face> face2 = make_shared<DummyFace>();
739 shared_ptr<Face> face3 = make_shared<DummyFace>();
740
741 addFace(face1);
742 addFace(face2);
743 addFace(face3);
744
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700745 shared_ptr<InternalFace> face = getInternalFace();
746 FibManager& manager = getFibManager();
747 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700748
749 shared_ptr<fib::Entry> entry = fib.insert("/hello").first;
750
751 entry->addNextHop(face1, 101);
752 entry->addNextHop(face2, 202);
753 entry->addNextHop(face3, 303);
754
755 testRemoveNextHop(this, manager, fib, face, "/hello", 2);
756 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202));
757
758 testRemoveNextHop(this, manager, fib, face, "/hello", 3);
759 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303));
760
761 testRemoveNextHop(this, manager, fib, face, "/hello", 1);
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600762 // BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700763
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600764 BOOST_CHECK(!static_cast<bool>(getFib().findExactMatch("/hello")));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700765}
766
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600767BOOST_AUTO_TEST_CASE(RemoveFaceNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700768{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700769 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700770
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600771 ControlParameters parameters;
772 parameters.setName("/hello");
773 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700774
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600775 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700776
777 Name commandName("/localhost/nfd/fib");
778 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600779 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700780
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700781 shared_ptr<Interest> command(make_shared<Interest>(commandName));
782 generateCommand(*command);
783
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700784 face->onReceiveData +=
785 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600786 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700787
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700788 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700789
790 BOOST_REQUIRE(didCallbackFire());
791}
792
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600793BOOST_AUTO_TEST_CASE(RemovePrefixNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700794{
795 addFace(make_shared<DummyFace>());
796
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700797 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700798
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600799 ControlParameters parameters;
800 parameters.setName("/hello");
801 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700802
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600803 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700804
805 Name commandName("/localhost/nfd/fib");
806 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600807 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700808
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700809 shared_ptr<Interest> command(make_shared<Interest>(commandName));
810 generateCommand(*command);
811
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700812 face->onReceiveData +=
813 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600814 command->getName(), 200, "Success", encodedParameters);
815
816 getFibManager().onFibRequest(*command);
817
818 BOOST_REQUIRE(didCallbackFire());
819}
820
821BOOST_AUTO_TEST_CASE(RemoveMissingPrefix)
822{
823 addFace(make_shared<DummyFace>());
824
825 shared_ptr<InternalFace> face = getInternalFace();
826
827 ControlParameters parameters;
828 parameters.setFaceId(1);
829
830 Block encodedParameters(parameters.wireEncode());
831
832 Name commandName("/localhost/nfd/fib");
833 commandName.append("remove-nexthop");
834 commandName.append(encodedParameters);
835
836 shared_ptr<Interest> command(make_shared<Interest>(commandName));
837 generateCommand(*command);
838
839 face->onReceiveData +=
840 bind(&FibManagerFixture::validateControlResponse, this, _1,
841 command->getName(), 400, "Malformed command");
842
843 getFibManager().onFibRequest(*command);
844
845 BOOST_REQUIRE(didCallbackFire());
846}
847
848BOOST_AUTO_TEST_CASE(RemoveMissingFaceId)
849{
850 addFace(make_shared<DummyFace>());
851
852 shared_ptr<InternalFace> face = getInternalFace();
853
854 ControlParameters parameters;
855 parameters.setName("/hello");
856
857 Block encodedParameters(parameters.wireEncode());
858
859 Name commandName("/localhost/nfd/fib");
860 commandName.append("remove-nexthop");
861 commandName.append(encodedParameters);
862
863 shared_ptr<Interest> command(make_shared<Interest>(commandName));
864 generateCommand(*command);
865
866 face->onReceiveData +=
867 bind(&FibManagerFixture::validateControlResponse, this, _1,
868 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700869
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700870 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700871
872 BOOST_REQUIRE(didCallbackFire());
873}
874
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600875BOOST_FIXTURE_TEST_CASE(TestFibEnumerationRequest, FibManagerFixture)
876{
877 for (int i = 0; i < 87; i++)
878 {
879 Name prefix("/test");
880 prefix.appendSegment(i);
881
882 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
883 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
884
885 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
886 entry->addNextHop(dummy1, std::numeric_limits<uint64_t>::max() - 1);
887 entry->addNextHop(dummy2, std::numeric_limits<uint64_t>::max() - 2);
888
889 m_referenceEntries.insert(entry);
890 }
891 for (int i = 0; i < 2; i++)
892 {
893 Name prefix("/test2");
894 prefix.appendSegment(i);
895
896 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
897 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
898
899 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
900 entry->addNextHop(dummy1, std::numeric_limits<uint8_t>::max() - 1);
901 entry->addNextHop(dummy2, std::numeric_limits<uint8_t>::max() - 2);
902
903 m_referenceEntries.insert(entry);
904 }
905
906 ndn::EncodingBuffer buffer;
907
908 m_face->onReceiveData +=
909 bind(&FibEnumerationPublisherFixture::decodeFibEntryBlock, this, _1);
910
911 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/fib/list"));
912
913 m_manager.onFibRequest(*command);
914 BOOST_REQUIRE(m_finished);
915}
916
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700917BOOST_AUTO_TEST_SUITE_END()
918
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700919} // namespace tests
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700920} // namespace nfd