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