blob: d672ab7c4f05d51444ccb3e5224740d2cc34b4ef [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);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700231 g_io.run_one();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700232
233 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700234}
235
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700236BOOST_AUTO_TEST_CASE(MalformedCommmand)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700237{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700238 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700239
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700240 BOOST_REQUIRE(didCallbackFire() == false);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700241
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700242 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 DiBenedetto2c2b8892014-02-27 11:46:48 -0700248 getFibManager().onFibRequest(command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700249
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700250 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700251}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700252
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700253BOOST_AUTO_TEST_CASE(UnsupportedVerb)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700254{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700255 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700256
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600257 ControlParameters parameters;
258 parameters.setName("/hello");
259 parameters.setFaceId(1);
260 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700261
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600262 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700263
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700264 Name commandName("/localhost/nfd/fib");
265 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600266 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700267
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700268 shared_ptr<Interest> command(make_shared<Interest>(commandName));
269 generateCommand(*command);
270
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700271 face->onReceiveData +=
272 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700273 command->getName(), 501, "Unsupported command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700274
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700275 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700276
277 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700278}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700279
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700280BOOST_AUTO_TEST_CASE(UnsignedCommand)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700281{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700282 addFace(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700283
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700284 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700285
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600286 ControlParameters parameters;
287 parameters.setName("/hello");
288 parameters.setFaceId(1);
289 parameters.setCost(101);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700290
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600291 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700292
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700293 Name commandName("/localhost/nfd/fib");
294 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600295 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700296
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700297 Interest command(commandName);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700298
299 face->onReceiveData +=
300 bind(&FibManagerFixture::validateControlResponse,
301 this, _1, command.getName(), 401, "Signature required");
302
303
304 getFibManager().onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700305
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700306 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700307 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700308}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700309
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700310BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FibManagerFixture>)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700311{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700312 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700313
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700314 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700315
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600316 ControlParameters parameters;
317 parameters.setName("/hello");
318 parameters.setFaceId(1);
319 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700320
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600321 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700322
323 Name commandName("/localhost/nfd/fib");
324 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600325 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700326
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700327 shared_ptr<Interest> command(make_shared<Interest>(commandName));
328 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700329
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700330 face->onReceiveData +=
331 bind(&FibManagerFixture::validateControlResponse,
332 this, _1, command->getName(), 403, "Unauthorized command");
333
334 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700335
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700336 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700337 BOOST_REQUIRE(!addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700338}
339
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700340BOOST_AUTO_TEST_CASE(BadOptionParse)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700341{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700342 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700343
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700344 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700345
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700346 Name commandName("/localhost/nfd/fib");
347 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600348 commandName.append("NotReallyParameters");
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700349
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700350 shared_ptr<Interest> command(make_shared<Interest>(commandName));
351 generateCommand(*command);
352
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700353 face->onReceiveData +=
354 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700355 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700356
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700357 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700358
359 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700360}
361
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700362BOOST_AUTO_TEST_CASE(UnknownFaceId)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700363{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700364 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700365
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700366 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700367
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600368 ControlParameters parameters;
369 parameters.setName("/hello");
370 parameters.setFaceId(1000);
371 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700372
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600373 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700374
375 Name commandName("/localhost/nfd/fib");
376 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600377 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700378
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700379 shared_ptr<Interest> command(make_shared<Interest>(commandName));
380 generateCommand(*command);
381
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700382 face->onReceiveData +=
383 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600384 command->getName(), 410, "Face not found");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700385
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700386 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700387
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700388 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700389 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101) == false);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700390}
391
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700392BOOST_AUTO_TEST_CASE(TestImplicitFaceId)
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700393{
394 addFace(make_shared<DummyFace>());
395
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700396 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700397
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600398 ControlParameters parameters;
399 parameters.setName("/hello");
400 parameters.setFaceId(0);
401 parameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700402
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600403 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700404
405 Name commandName("/localhost/nfd/fib");
406 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600407 commandName.append(encodedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700408
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600409 ControlParameters expectedParameters;
410 expectedParameters.setName("/hello");
411 expectedParameters.setFaceId(1);
412 expectedParameters.setCost(101);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700413
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600414 Block encodedExpectedParameters(expectedParameters.wireEncode());
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700415
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700416 shared_ptr<Interest> command(make_shared<Interest>(commandName));
417 command->setIncomingFaceId(1);
418 generateCommand(*command);
419
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700420 face->onReceiveData +=
421 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600422 command->getName(), 200, "Success", encodedExpectedParameters);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700423
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700424 getFibManager().onFibRequest(*command);
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700425
426 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700427 BOOST_REQUIRE(addedNextHopWithFace(getFib(), "/hello", 0, 101, getFace(1)));
Steve DiBenedetto2693db92014-02-10 15:58:36 -0700428}
429
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700430BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700431{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700432 addFace(make_shared<DummyFace>());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700433
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700434 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700435
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600436 ControlParameters parameters;
437 parameters.setName("/hello");
438 parameters.setFaceId(1);
439 parameters.setCost(101);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700440
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600441 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700442
443 Name commandName("/localhost/nfd/fib");
444 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600445 commandName.append(encodedParameters);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700446
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700447 shared_ptr<Interest> command(make_shared<Interest>(commandName));
448 generateCommand(*command);
449
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700450 face->onReceiveData +=
451 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600452 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700453
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700454 getFibManager().onFibRequest(*command);
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700455
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700456 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700457 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 101));
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700458}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700459
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600460BOOST_AUTO_TEST_CASE(AddNextHopVerbImplicitCost)
461{
462 addFace(make_shared<DummyFace>());
463
464 shared_ptr<InternalFace> face = getInternalFace();
465
466 ControlParameters parameters;
467 parameters.setName("/hello");
468 parameters.setFaceId(1);
469
470 Block encodedParameters(parameters.wireEncode());
471
472 Name commandName("/localhost/nfd/fib");
473 commandName.append("add-nexthop");
474 commandName.append(encodedParameters);
475
476 shared_ptr<Interest> command(make_shared<Interest>(commandName));
477 generateCommand(*command);
478
479 ControlParameters resultParameters;
480 resultParameters.setName("/hello");
481 resultParameters.setFaceId(1);
482 resultParameters.setCost(0);
483
484 face->onReceiveData +=
485 bind(&FibManagerFixture::validateControlResponse, this, _1,
486 command->getName(), 200, "Success", resultParameters.wireEncode());
487
488 getFibManager().onFibRequest(*command);
489
490 BOOST_REQUIRE(didCallbackFire());
491 BOOST_REQUIRE(addedNextHopWithCost(getFib(), "/hello", 0, 0));
492}
493
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700494BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700495{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700496 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700497 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700498
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700499 for (int i = 1; i <= 2; i++)
500 {
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700501
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600502 ControlParameters parameters;
503 parameters.setName("/hello");
504 parameters.setFaceId(1);
505 parameters.setCost(100 + i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700506
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600507 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700508
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700509 Name commandName("/localhost/nfd/fib");
510 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600511 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700512
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700513 shared_ptr<Interest> command(make_shared<Interest>(commandName));
514 generateCommand(*command);
515
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700516 face->onReceiveData +=
517 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600518 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700519
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700520 getFibManager().onFibRequest(*command);
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700521 BOOST_REQUIRE(didCallbackFire());
522 resetCallbackFired();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700523
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700524 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700525
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700526 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700527 {
528 const fib::NextHopList& hops = entry->getNextHops();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700529 BOOST_REQUIRE(hops.size() == 1);
530 BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(),
531 bind(&foundNextHop, -1, 100 + i, _1)) != hops.end());
532
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700533 }
534 else
535 {
536 BOOST_FAIL("Failed to find expected fib entry");
537 }
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700538
539 face->onReceiveData.clear();
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700540 }
541}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700542
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700543BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700544{
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700545 addFace(make_shared<DummyFace>());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700546 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700547
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600548 ControlParameters parameters;
549 parameters.setName("/hello");
550 parameters.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700551
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700552 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600553 parameters.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700554
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600555 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700556
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700557 Name commandName("/localhost/nfd/fib");
558 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600559 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700560
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700561 shared_ptr<Interest> command(make_shared<Interest>(commandName));
562 generateCommand(*command);
563
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700564 face->onReceiveData +=
565 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600566 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700567
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700568 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700569
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700570 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700571 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700572
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700573 resetCallbackFired();
574 face->onReceiveData.clear();
575
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700576 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600577 parameters.setCost(102);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700578
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600579 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700580
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700581 Name commandName("/localhost/nfd/fib");
582 commandName.append("add-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600583 commandName.append(encodedParameters);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700584
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700585 shared_ptr<Interest> command(make_shared<Interest>(commandName));
586 generateCommand(*command);
587
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700588 face->onReceiveData +=
589 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600590 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700591
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700592 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700593
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700594 BOOST_REQUIRE(didCallbackFire());
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700595 }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700596
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700597 shared_ptr<fib::Entry> entry = getFib().findExactMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700598
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700599 // Add faces with cost == FaceID for the name /hello
600 // This test assumes:
601 // FaceIDs are -1 because we don't add them to a forwarder
Steve DiBenedettobdedce92014-02-02 22:49:39 -0700602 if (static_cast<bool>(entry))
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700603 {
604 const fib::NextHopList& hops = entry->getNextHops();
605 BOOST_REQUIRE(hops.size() == 1);
606 BOOST_REQUIRE(std::find_if(hops.begin(),
607 hops.end(),
608 bind(&foundNextHop, -1, 102, _1)) != hops.end());
609 }
610 else
611 {
612 BOOST_FAIL("Failed to find expected fib entry");
613 }
614}
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700615
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600616BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingPrefix)
617{
618 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700619
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600620 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700621
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600622 ControlParameters parameters;
623 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700624
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600625 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700626
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600627 Name commandName("/localhost/nfd/fib");
628 commandName.append("add-nexthop");
629 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700630
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600631 shared_ptr<Interest> command(make_shared<Interest>(commandName));
632 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700633
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600634 face->onReceiveData +=
635 bind(&FibManagerFixture::validateControlResponse, this, _1,
636 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700637
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600638 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700639
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600640 BOOST_REQUIRE(didCallbackFire());
641}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700642
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600643BOOST_AUTO_TEST_CASE(AddNextHopVerbMissingFaceId)
644{
645 addFace(make_shared<DummyFace>());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700646
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600647 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700648
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600649 ControlParameters parameters;
650 parameters.setName("/hello");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700651
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600652 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700653
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600654 Name commandName("/localhost/nfd/fib");
655 commandName.append("add-nexthop");
656 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700657
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600658 shared_ptr<Interest> command(make_shared<Interest>(commandName));
659 generateCommand(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700660
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600661 face->onReceiveData +=
662 bind(&FibManagerFixture::validateControlResponse, this, _1,
663 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700664
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600665 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700666
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600667 BOOST_REQUIRE(didCallbackFire());
668}
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700669
670bool
671removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost)
672{
673 shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix);
674
675 if (static_cast<bool>(entry))
676 {
677 const fib::NextHopList& hops = entry->getNextHops();
678 return hops.size() == oldSize - 1 &&
679 std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end();
680 }
681 return false;
682}
683
684void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700685testRemoveNextHop(CommandFixture<FibManagerFixture>* fixture,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700686 FibManager& manager,
687 Fib& fib,
688 shared_ptr<Face> face,
689 const Name& targetName,
690 FaceId targetFace)
691{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600692 ControlParameters parameters;
693 parameters.setName(targetName);
694 parameters.setFaceId(targetFace);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700695
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600696 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700697
698 Name commandName("/localhost/nfd/fib");
699 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600700 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700701
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700702 shared_ptr<Interest> command(make_shared<Interest>(commandName));
703 fixture->generateCommand(*command);
704
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700705 face->onReceiveData +=
706 bind(&FibManagerFixture::validateControlResponse, fixture, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600707 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700708
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700709 manager.onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700710
711 BOOST_REQUIRE(fixture->didCallbackFire());
712
713 fixture->resetCallbackFired();
714 face->onReceiveData.clear();
715}
716
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700717BOOST_AUTO_TEST_CASE(RemoveNextHop)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700718{
719 shared_ptr<Face> face1 = make_shared<DummyFace>();
720 shared_ptr<Face> face2 = make_shared<DummyFace>();
721 shared_ptr<Face> face3 = make_shared<DummyFace>();
722
723 addFace(face1);
724 addFace(face2);
725 addFace(face3);
726
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700727 shared_ptr<InternalFace> face = getInternalFace();
728 FibManager& manager = getFibManager();
729 Fib& fib = getFib();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700730
731 shared_ptr<fib::Entry> entry = fib.insert("/hello").first;
732
733 entry->addNextHop(face1, 101);
734 entry->addNextHop(face2, 202);
735 entry->addNextHop(face3, 303);
736
737 testRemoveNextHop(this, manager, fib, face, "/hello", 2);
738 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202));
739
740 testRemoveNextHop(this, manager, fib, face, "/hello", 3);
741 BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303));
742
743 testRemoveNextHop(this, manager, fib, face, "/hello", 1);
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600744 // BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700745
Steve DiBenedettod030cfc2014-03-10 20:04:47 -0600746 BOOST_CHECK(!static_cast<bool>(getFib().findExactMatch("/hello")));
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700747}
748
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600749BOOST_AUTO_TEST_CASE(RemoveFaceNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700750{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700751 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700752
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600753 ControlParameters parameters;
754 parameters.setName("/hello");
755 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700756
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600757 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700758
759 Name commandName("/localhost/nfd/fib");
760 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600761 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700762
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700763 shared_ptr<Interest> command(make_shared<Interest>(commandName));
764 generateCommand(*command);
765
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700766 face->onReceiveData +=
767 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600768 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700769
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700770 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700771
772 BOOST_REQUIRE(didCallbackFire());
773}
774
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600775BOOST_AUTO_TEST_CASE(RemovePrefixNotFound)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700776{
777 addFace(make_shared<DummyFace>());
778
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700779 shared_ptr<InternalFace> face = getInternalFace();
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700780
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600781 ControlParameters parameters;
782 parameters.setName("/hello");
783 parameters.setFaceId(1);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700784
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600785 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700786
787 Name commandName("/localhost/nfd/fib");
788 commandName.append("remove-nexthop");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600789 commandName.append(encodedParameters);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700790
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700791 shared_ptr<Interest> command(make_shared<Interest>(commandName));
792 generateCommand(*command);
793
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700794 face->onReceiveData +=
795 bind(&FibManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600796 command->getName(), 200, "Success", encodedParameters);
797
798 getFibManager().onFibRequest(*command);
799
800 BOOST_REQUIRE(didCallbackFire());
801}
802
803BOOST_AUTO_TEST_CASE(RemoveMissingPrefix)
804{
805 addFace(make_shared<DummyFace>());
806
807 shared_ptr<InternalFace> face = getInternalFace();
808
809 ControlParameters parameters;
810 parameters.setFaceId(1);
811
812 Block encodedParameters(parameters.wireEncode());
813
814 Name commandName("/localhost/nfd/fib");
815 commandName.append("remove-nexthop");
816 commandName.append(encodedParameters);
817
818 shared_ptr<Interest> command(make_shared<Interest>(commandName));
819 generateCommand(*command);
820
821 face->onReceiveData +=
822 bind(&FibManagerFixture::validateControlResponse, this, _1,
823 command->getName(), 400, "Malformed command");
824
825 getFibManager().onFibRequest(*command);
826
827 BOOST_REQUIRE(didCallbackFire());
828}
829
830BOOST_AUTO_TEST_CASE(RemoveMissingFaceId)
831{
832 addFace(make_shared<DummyFace>());
833
834 shared_ptr<InternalFace> face = getInternalFace();
835
836 ControlParameters parameters;
837 parameters.setName("/hello");
838
839 Block encodedParameters(parameters.wireEncode());
840
841 Name commandName("/localhost/nfd/fib");
842 commandName.append("remove-nexthop");
843 commandName.append(encodedParameters);
844
845 shared_ptr<Interest> command(make_shared<Interest>(commandName));
846 generateCommand(*command);
847
848 face->onReceiveData +=
849 bind(&FibManagerFixture::validateControlResponse, this, _1,
850 command->getName(), 400, "Malformed command");
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700851
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700852 getFibManager().onFibRequest(*command);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -0700853
854 BOOST_REQUIRE(didCallbackFire());
855}
856
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600857BOOST_FIXTURE_TEST_CASE(TestFibEnumerationRequest, FibManagerFixture)
858{
859 for (int i = 0; i < 87; i++)
860 {
861 Name prefix("/test");
862 prefix.appendSegment(i);
863
864 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
865 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
866
867 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
868 entry->addNextHop(dummy1, std::numeric_limits<uint64_t>::max() - 1);
869 entry->addNextHop(dummy2, std::numeric_limits<uint64_t>::max() - 2);
870
871 m_referenceEntries.insert(entry);
872 }
873 for (int i = 0; i < 2; i++)
874 {
875 Name prefix("/test2");
876 prefix.appendSegment(i);
877
878 shared_ptr<DummyFace> dummy1(make_shared<DummyFace>());
879 shared_ptr<DummyFace> dummy2(make_shared<DummyFace>());
880
881 shared_ptr<fib::Entry> entry = m_fib.insert(prefix).first;
882 entry->addNextHop(dummy1, std::numeric_limits<uint8_t>::max() - 1);
883 entry->addNextHop(dummy2, std::numeric_limits<uint8_t>::max() - 2);
884
885 m_referenceEntries.insert(entry);
886 }
887
888 ndn::EncodingBuffer buffer;
889
890 m_face->onReceiveData +=
891 bind(&FibEnumerationPublisherFixture::decodeFibEntryBlock, this, _1);
892
893 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/fib/list"));
894
895 m_manager.onFibRequest(*command);
896 BOOST_REQUIRE(m_finished);
897}
898
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700899BOOST_AUTO_TEST_SUITE_END()
900
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700901} // namespace tests
Steve DiBenedetto43cd0372014-02-01 17:05:07 -0700902} // namespace nfd