Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/fib-manager.hpp" |
| 8 | #include "fw/forwarder.hpp" |
| 9 | #include "table/fib.hpp" |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 10 | #include "table/fib-nexthop.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 11 | #include "face/face.hpp" |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 12 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 13 | #include "../face/dummy-face.hpp" |
| 14 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 15 | #include <algorithm> |
| 16 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 17 | #include <ndn-cpp-dev/management/fib-management-options.hpp> |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 18 | #include <ndn-cpp-dev/management/control-response.hpp> |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 19 | |
| 20 | #include <boost/test/unit_test.hpp> |
| 21 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 22 | namespace nfd { |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 23 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 24 | NFD_LOG_INIT("FibManagerTest"); |
| 25 | |
| 26 | class FibManagerFixture |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 27 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 28 | public: |
| 29 | |
| 30 | shared_ptr<Face> |
| 31 | getFace(FaceId id) |
| 32 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 33 | if (id > 0 && id <= m_faces.size()) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 34 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 35 | return m_faces[id-1]; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 36 | } |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 37 | NFD_LOG_DEBUG("No face found returning NULL"); |
| 38 | return shared_ptr<DummyFace>(); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | addFace(shared_ptr<Face> face) |
| 43 | { |
| 44 | m_faces.push_back(face); |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | std::vector<shared_ptr<Face> > m_faces; |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | BOOST_AUTO_TEST_SUITE(MgmtFibManager) |
| 53 | |
| 54 | void |
| 55 | validateControlResponse(const Data& response, |
| 56 | uint32_t expectedCode, |
| 57 | const std::string& expectedText) |
| 58 | { |
| 59 | Block controlRaw = response.getContent().blockFromValue(); |
| 60 | |
| 61 | ndn::ControlResponse control; |
| 62 | control.wireDecode(controlRaw); |
| 63 | |
| 64 | NFD_LOG_DEBUG("received control response" |
| 65 | << " Name: " << response.getName() |
| 66 | << " code: " << control.getCode() |
| 67 | << " text: " << control.getText()); |
| 68 | |
| 69 | BOOST_REQUIRE(control.getCode() == expectedCode); |
| 70 | BOOST_REQUIRE(control.getText() == expectedText); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 73 | bool |
| 74 | foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next) |
| 75 | { |
| 76 | return id == next.getFace()->getId() && next.getCost() == cost; |
| 77 | } |
| 78 | |
| 79 | bool |
| 80 | addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost) |
| 81 | { |
| 82 | shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch(prefix); |
| 83 | |
| 84 | if (entry) |
| 85 | { |
| 86 | const fib::NextHopList& hops = entry->getNextHops(); |
| 87 | return hops.size() == oldSize + 1 && |
| 88 | std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end(); |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | BOOST_AUTO_TEST_CASE(TestFireInterestFilter) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 94 | { |
| 95 | FibManagerFixture fixture; |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 96 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 97 | Fib fib; |
| 98 | FibManager manager(fib, |
| 99 | bind(&FibManagerFixture::getFace, |
| 100 | &fixture, _1), |
| 101 | face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 102 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 103 | face->onReceiveData += |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 104 | bind(&validateControlResponse, _1, 400, "MALFORMED"); |
| 105 | |
| 106 | Interest command("/localhost/nfd/fib"); |
| 107 | face->sendInterest(command); |
| 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(MalformedCommmand) |
| 111 | { |
| 112 | FibManagerFixture fixture; |
| 113 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 114 | Fib fib; |
| 115 | FibManager manager(fib, |
| 116 | bind(&FibManagerFixture::getFace, |
| 117 | &fixture, _1), |
| 118 | face); |
| 119 | |
| 120 | face->onReceiveData += |
| 121 | bind(&validateControlResponse, _1, 400, "MALFORMED"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 122 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 123 | Interest command("/localhost/nfd/fib"); |
| 124 | manager.onFibRequest(command); |
| 125 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 126 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(UnsupportedVerb) |
| 128 | { |
| 129 | FibManagerFixture fixture; |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 130 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 131 | Fib fib; |
| 132 | FibManager manager(fib, |
| 133 | bind(&FibManagerFixture::getFace, |
| 134 | &fixture, _1), |
| 135 | face); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 136 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 137 | face->onReceiveData += |
| 138 | bind(&validateControlResponse, _1, 404, "UNSUPPORTED"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 139 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 140 | ndn::FibManagementOptions options; |
| 141 | options.setName("/hello"); |
| 142 | options.setFaceId(1); |
| 143 | options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 144 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 145 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 146 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 147 | Name commandName("/localhost/nfd/fib"); |
| 148 | commandName.append("unsupported"); |
| 149 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 150 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 151 | Interest command(commandName); |
| 152 | manager.onFibRequest(command); |
| 153 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 154 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 155 | BOOST_AUTO_TEST_CASE(UnsignedCommand) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 156 | { |
| 157 | FibManagerFixture fixture; |
| 158 | fixture.addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 159 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 160 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 161 | Fib fib; |
| 162 | FibManager manager(fib, |
| 163 | bind(&FibManagerFixture::getFace, |
| 164 | &fixture, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 165 | face); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 166 | face->onReceiveData += |
| 167 | bind(&validateControlResponse, _1, 200, "OK"); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 168 | /// \todo enable once sig checking implement |
| 169 | // bind(&validateControlResponse, _1, 401, "SIGREG"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 170 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 171 | ndn::FibManagementOptions options; |
| 172 | options.setName("/hello"); |
| 173 | options.setFaceId(1); |
| 174 | options.setCost(101); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 175 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 176 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 177 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 178 | Name commandName("/localhost/nfd/fib"); |
| 179 | commandName.append("add-nexthop"); |
| 180 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 181 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 182 | Interest command(commandName); |
| 183 | manager.onFibRequest(command); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 184 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 185 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101)); |
| 186 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 187 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 188 | BOOST_AUTO_TEST_CASE(UnauthorizedCommand) |
| 189 | { |
| 190 | FibManagerFixture fixture; |
| 191 | fixture.addFace(make_shared<DummyFace>()); |
| 192 | |
| 193 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 194 | Fib fib; |
| 195 | FibManager manager(fib, |
| 196 | bind(&FibManagerFixture::getFace, |
| 197 | &fixture, _1), |
| 198 | face); |
| 199 | face->onReceiveData += |
| 200 | bind(&validateControlResponse, _1, 200, "OK"); |
| 201 | /// \todo enable once sig checking implement |
| 202 | // bind(&validateControlResponse, _1, 403, "UNAUTHORIZED"); |
| 203 | |
| 204 | ndn::FibManagementOptions options; |
| 205 | options.setName("/hello"); |
| 206 | options.setFaceId(1); |
| 207 | options.setCost(101); |
| 208 | |
| 209 | Block encodedOptions(options.wireEncode()); |
| 210 | |
| 211 | Name commandName("/localhost/nfd/fib"); |
| 212 | commandName.append("add-nexthop"); |
| 213 | commandName.append(encodedOptions); |
| 214 | |
| 215 | Interest command(commandName); |
| 216 | manager.onFibRequest(command); |
| 217 | |
| 218 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101)); |
| 219 | } |
| 220 | |
| 221 | BOOST_AUTO_TEST_CASE(BadOptionParse) |
| 222 | { |
| 223 | FibManagerFixture fixture; |
| 224 | fixture.addFace(make_shared<DummyFace>()); |
| 225 | |
| 226 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 227 | Fib fib; |
| 228 | FibManager manager(fib, |
| 229 | bind(&FibManagerFixture::getFace, |
| 230 | &fixture, _1), |
| 231 | face); |
| 232 | |
| 233 | face->onReceiveData += |
| 234 | bind(&validateControlResponse, _1, 400, "MALFORMED"); |
| 235 | |
| 236 | Name commandName("/localhost/nfd/fib"); |
| 237 | commandName.append("add-nexthop"); |
| 238 | commandName.append("NotReallyOptions"); |
| 239 | |
| 240 | Interest command(commandName); |
| 241 | manager.onFibRequest(command); |
| 242 | } |
| 243 | |
| 244 | BOOST_AUTO_TEST_CASE(UnknownFaceId) |
| 245 | { |
| 246 | FibManagerFixture fixture; |
| 247 | fixture.addFace(make_shared<DummyFace>()); |
| 248 | |
| 249 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 250 | Fib fib; |
| 251 | FibManager manager(fib, |
| 252 | bind(&FibManagerFixture::getFace, |
| 253 | &fixture, _1), |
| 254 | face); |
| 255 | |
| 256 | face->onReceiveData += |
| 257 | bind(&validateControlResponse, _1, 400, "MALFORMED"); |
| 258 | |
| 259 | ndn::FibManagementOptions options; |
| 260 | options.setName("/hello"); |
| 261 | options.setFaceId(1000); |
| 262 | options.setCost(101); |
| 263 | |
| 264 | Block encodedOptions(options.wireEncode()); |
| 265 | |
| 266 | Name commandName("/localhost/nfd/fib"); |
| 267 | commandName.append("add-nexthop"); |
| 268 | commandName.append(encodedOptions); |
| 269 | |
| 270 | Interest command(commandName); |
| 271 | manager.onFibRequest(command); |
| 272 | |
| 273 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101) == false); |
| 274 | } |
| 275 | |
| 276 | BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd) |
| 277 | { |
| 278 | FibManagerFixture fixture; |
| 279 | fixture.addFace(make_shared<DummyFace>()); |
| 280 | |
| 281 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 282 | Fib fib; |
| 283 | FibManager manager(fib, |
| 284 | bind(&FibManagerFixture::getFace, |
| 285 | &fixture, _1), |
| 286 | face); |
| 287 | face->onReceiveData += |
| 288 | bind(&validateControlResponse, _1, 200, "OK"); |
| 289 | |
| 290 | ndn::FibManagementOptions options; |
| 291 | options.setName("/hello"); |
| 292 | options.setFaceId(1); |
| 293 | options.setCost(101); |
| 294 | |
| 295 | Block encodedOptions(options.wireEncode()); |
| 296 | |
| 297 | Name commandName("/localhost/nfd/fib"); |
| 298 | commandName.append("add-nexthop"); |
| 299 | commandName.append(encodedOptions); |
| 300 | |
| 301 | Interest command(commandName); |
| 302 | manager.onFibRequest(command); |
| 303 | |
| 304 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 305 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 306 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 307 | BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting) |
| 308 | { |
| 309 | FibManagerFixture fixture; |
| 310 | fixture.addFace(make_shared<DummyFace>()); |
| 311 | fixture.addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 312 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 313 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 314 | Fib fib; |
| 315 | FibManager manager(fib, |
| 316 | bind(&FibManagerFixture::getFace, |
| 317 | &fixture, _1), |
| 318 | face); |
| 319 | face->onReceiveData += |
| 320 | bind(&validateControlResponse, _1, 200, "OK"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 321 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 322 | // Add faces with cost == FaceID for the name /hello |
| 323 | // This test assumes: |
| 324 | // FaceIDs are -1 because we don't add them to a forwarder |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 325 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 326 | for (int i = 1; i <= 2; i++) |
| 327 | { |
| 328 | ndn::FibManagementOptions options; |
| 329 | options.setName("/hello"); |
| 330 | options.setFaceId(i); |
| 331 | options.setCost(100 + i); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 332 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 333 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 334 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 335 | Name commandName("/localhost/nfd/fib"); |
| 336 | commandName.append("add-nexthop"); |
| 337 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 338 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 339 | Interest command(commandName); |
| 340 | manager.onFibRequest(command); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 341 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 342 | shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 343 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 344 | if (entry) |
| 345 | { |
| 346 | const fib::NextHopList& hops = entry->getNextHops(); |
| 347 | for (int j = 1; j <= i; j++) |
| 348 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 349 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", i - 1, 100 + j)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | BOOST_FAIL("Failed to find expected fib entry"); |
| 355 | } |
| 356 | } |
| 357 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 358 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 359 | BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost) |
| 360 | { |
| 361 | FibManagerFixture fixture; |
| 362 | fixture.addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 363 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame^] | 364 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 365 | Fib fib; |
| 366 | FibManager manager(fib, |
| 367 | bind(&FibManagerFixture::getFace, |
| 368 | &fixture, _1), |
| 369 | face); |
| 370 | face->onReceiveData += |
| 371 | bind(&validateControlResponse, _1, 200, "OK"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 372 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 373 | ndn::FibManagementOptions options; |
| 374 | options.setName("/hello"); |
| 375 | options.setFaceId(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 376 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 377 | { |
| 378 | options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 379 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 380 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 381 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 382 | Name commandName("/localhost/nfd/fib"); |
| 383 | commandName.append("add-nexthop"); |
| 384 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 385 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 386 | Interest command(commandName); |
| 387 | manager.onFibRequest(command); |
| 388 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 389 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 390 | { |
| 391 | options.setCost(102); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 392 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 393 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 394 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 395 | Name commandName("/localhost/nfd/fib"); |
| 396 | commandName.append("add-nexthop"); |
| 397 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 398 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 399 | Interest command(commandName); |
| 400 | manager.onFibRequest(command); |
| 401 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 402 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 403 | shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 404 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 405 | // Add faces with cost == FaceID for the name /hello |
| 406 | // This test assumes: |
| 407 | // FaceIDs are -1 because we don't add them to a forwarder |
| 408 | if (entry) |
| 409 | { |
| 410 | const fib::NextHopList& hops = entry->getNextHops(); |
| 411 | BOOST_REQUIRE(hops.size() == 1); |
| 412 | BOOST_REQUIRE(std::find_if(hops.begin(), |
| 413 | hops.end(), |
| 414 | bind(&foundNextHop, -1, 102, _1)) != hops.end()); |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | BOOST_FAIL("Failed to find expected fib entry"); |
| 419 | } |
| 420 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 421 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 422 | BOOST_AUTO_TEST_SUITE_END() |
| 423 | |
| 424 | } // namespace nfd |