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" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 8 | #include "table/fib.hpp" |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 9 | #include "table/fib-nexthop.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 10 | #include "face/face.hpp" |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 11 | #include "mgmt/internal-face.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 12 | #include "tests/face/dummy-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 13 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 14 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 15 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 16 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 17 | namespace tests { |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 18 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 19 | NFD_LOG_INIT("FibManagerTest"); |
| 20 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 21 | class FibManagerFixture : protected BaseFixture |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 22 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 23 | public: |
| 24 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 25 | FibManagerFixture() |
| 26 | : m_callbackFired(false) |
| 27 | { |
| 28 | |
| 29 | } |
| 30 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 31 | shared_ptr<Face> |
| 32 | getFace(FaceId id) |
| 33 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | if (id > 0 && static_cast<size_t>(id) <= m_faces.size()) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 35 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 36 | return m_faces[id - 1]; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 37 | } |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 38 | NFD_LOG_DEBUG("No face found returning NULL"); |
| 39 | return shared_ptr<DummyFace>(); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void |
| 43 | addFace(shared_ptr<Face> face) |
| 44 | { |
| 45 | m_faces.push_back(face); |
| 46 | } |
| 47 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 48 | void |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 49 | validateControlResponseCommon(const Data& response, |
| 50 | const Name& expectedName, |
| 51 | uint32_t expectedCode, |
| 52 | const std::string& expectedText, |
| 53 | ControlResponse& control) |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 54 | { |
| 55 | m_callbackFired = true; |
| 56 | Block controlRaw = response.getContent().blockFromValue(); |
| 57 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 58 | control.wireDecode(controlRaw); |
| 59 | |
| 60 | NFD_LOG_DEBUG("received control response" |
| 61 | << " Name: " << response.getName() |
| 62 | << " code: " << control.getCode() |
| 63 | << " text: " << control.getText()); |
| 64 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 66 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 67 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 70 | void |
| 71 | validateControlResponse(const Data& response, |
| 72 | const Name& expectedName, |
| 73 | uint32_t expectedCode, |
| 74 | const std::string& expectedText) |
| 75 | { |
| 76 | ControlResponse control; |
| 77 | validateControlResponseCommon(response, expectedName, |
| 78 | expectedCode, expectedText, control); |
| 79 | |
| 80 | if (!control.getBody().empty()) |
| 81 | { |
| 82 | BOOST_FAIL("found unexpected control response body"); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | validateControlResponse(const Data& response, |
| 88 | const Name& expectedName, |
| 89 | uint32_t expectedCode, |
| 90 | const std::string& expectedText, |
| 91 | const Block& expectedBody) |
| 92 | { |
| 93 | ControlResponse control; |
| 94 | validateControlResponseCommon(response, expectedName, |
| 95 | expectedCode, expectedText, control); |
| 96 | |
| 97 | BOOST_REQUIRE(!control.getBody().empty()); |
| 98 | BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size()); |
| 99 | |
| 100 | BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(), |
| 101 | expectedBody.value_size()) == 0); |
| 102 | |
| 103 | } |
| 104 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 105 | bool |
| 106 | didCallbackFire() |
| 107 | { |
| 108 | return m_callbackFired; |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | resetCallbackFired() |
| 113 | { |
| 114 | m_callbackFired = false; |
| 115 | } |
| 116 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 117 | private: |
| 118 | std::vector<shared_ptr<Face> > m_faces; |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 119 | bool m_callbackFired; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 122 | BOOST_FIXTURE_TEST_SUITE(MgmtFibManager, FibManagerFixture) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 123 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 124 | bool |
| 125 | foundNextHop(FaceId id, uint32_t cost, const fib::NextHop& next) |
| 126 | { |
| 127 | return id == next.getFace()->getId() && next.getCost() == cost; |
| 128 | } |
| 129 | |
| 130 | bool |
| 131 | addedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost) |
| 132 | { |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 133 | shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 134 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 135 | if (static_cast<bool>(entry)) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 136 | { |
| 137 | const fib::NextHopList& hops = entry->getNextHops(); |
| 138 | return hops.size() == oldSize + 1 && |
| 139 | std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end(); |
| 140 | } |
| 141 | return false; |
| 142 | } |
| 143 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 144 | bool |
| 145 | foundNextHopWithFace(FaceId id, uint32_t cost, |
| 146 | shared_ptr<Face> face, const fib::NextHop& next) |
| 147 | { |
| 148 | return id == next.getFace()->getId() && next.getCost() == cost && face == next.getFace(); |
| 149 | } |
| 150 | |
| 151 | bool |
| 152 | addedNextHopWithFace(const Fib& fib, const Name& prefix, size_t oldSize, |
| 153 | uint32_t cost, shared_ptr<Face> face) |
| 154 | { |
| 155 | shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix); |
| 156 | |
| 157 | if (static_cast<bool>(entry)) |
| 158 | { |
| 159 | const fib::NextHopList& hops = entry->getNextHops(); |
| 160 | return hops.size() == oldSize + 1 && |
| 161 | std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) != hops.end(); |
| 162 | } |
| 163 | return false; |
| 164 | } |
| 165 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 166 | BOOST_AUTO_TEST_CASE(TestFireInterestFilter) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 167 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 168 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 169 | Fib fib; |
| 170 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 171 | bind(&FibManagerFixture::getFace, this, _1), |
| 172 | face); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 173 | |
| 174 | Interest command("/localhost/nfd/fib"); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 175 | |
| 176 | face->onReceiveData += |
| 177 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 178 | command.getName(), 400, "Malformed command"); |
| 179 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 180 | face->sendInterest(command); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 181 | |
| 182 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 185 | BOOST_AUTO_TEST_CASE(MalformedCommmand) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 186 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 187 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 188 | Fib fib; |
| 189 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 190 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 191 | face); |
| 192 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 193 | BOOST_REQUIRE(didCallbackFire() == false); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 194 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 195 | Interest command("/localhost/nfd/fib"); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 196 | |
| 197 | face->onReceiveData += |
| 198 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 199 | command.getName(), 400, "Malformed command"); |
| 200 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 201 | manager.onFibRequest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 202 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 203 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 204 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 205 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 206 | BOOST_AUTO_TEST_CASE(UnsupportedVerb) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 207 | { |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 208 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 209 | Fib fib; |
| 210 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 211 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 212 | face); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 213 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 214 | FibManagementOptions options; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 215 | options.setName("/hello"); |
| 216 | options.setFaceId(1); |
| 217 | options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 218 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 219 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 220 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 221 | Name commandName("/localhost/nfd/fib"); |
| 222 | commandName.append("unsupported"); |
| 223 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 224 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 225 | face->onReceiveData += |
| 226 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 227 | commandName, 501, "Unsupported command"); |
| 228 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 229 | Interest command(commandName); |
| 230 | manager.onFibRequest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 231 | |
| 232 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 233 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 234 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 235 | BOOST_AUTO_TEST_CASE(UnsignedCommand) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 236 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 237 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 238 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 239 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 240 | Fib fib; |
| 241 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 242 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 243 | face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 244 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 245 | FibManagementOptions options; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 246 | options.setName("/hello"); |
| 247 | options.setFaceId(1); |
| 248 | options.setCost(101); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 249 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 250 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 251 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 252 | Name commandName("/localhost/nfd/fib"); |
| 253 | commandName.append("add-nexthop"); |
| 254 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 255 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 256 | face->onReceiveData += |
| 257 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 258 | commandName, 404, "Prefix not found"); |
| 259 | /// \todo enable once sig checking implemented |
| 260 | // bind(&FibManagerFixture::validateControlResponse, this, _1, 401, "Signature required"); |
| 261 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 262 | Interest command(commandName); |
| 263 | manager.onFibRequest(command); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 264 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 265 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 266 | BOOST_REQUIRE(!addedNextHopWithCost(fib, "/hello", 0, 101)); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 267 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 268 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 269 | BOOST_AUTO_TEST_CASE(UnauthorizedCommand) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 270 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 271 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 272 | |
| 273 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 274 | Fib fib; |
| 275 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 276 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 277 | face); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 278 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 279 | FibManagementOptions options; |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 280 | options.setName("/hello"); |
| 281 | options.setFaceId(1); |
| 282 | options.setCost(101); |
| 283 | |
| 284 | Block encodedOptions(options.wireEncode()); |
| 285 | |
| 286 | Name commandName("/localhost/nfd/fib"); |
| 287 | commandName.append("add-nexthop"); |
| 288 | commandName.append(encodedOptions); |
| 289 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 290 | face->onReceiveData += |
| 291 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 292 | commandName, 404, "Prefix not found"); |
| 293 | /// \todo enable once sig checking implemented |
| 294 | // bind(&FibManagerFixture::validateControlResponse, this, _1, 403, "Unauthorized command"); |
| 295 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 296 | Interest command(commandName); |
| 297 | manager.onFibRequest(command); |
| 298 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 299 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 300 | BOOST_REQUIRE(!addedNextHopWithCost(fib, "/hello", 0, 101)); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 303 | BOOST_AUTO_TEST_CASE(BadOptionParse) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 304 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 305 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 306 | |
| 307 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 308 | Fib fib; |
| 309 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 310 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 311 | face); |
| 312 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 313 | Name commandName("/localhost/nfd/fib"); |
| 314 | commandName.append("add-nexthop"); |
| 315 | commandName.append("NotReallyOptions"); |
| 316 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 317 | face->onReceiveData += |
| 318 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 319 | commandName, 400, "Malformed command"); |
| 320 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 321 | Interest command(commandName); |
| 322 | manager.onFibRequest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 323 | |
| 324 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 327 | BOOST_AUTO_TEST_CASE(UnknownFaceId) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 328 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 329 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 330 | |
| 331 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 332 | Fib fib; |
| 333 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 334 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 335 | face); |
| 336 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 337 | FibManagementOptions options; |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 338 | options.setName("/hello"); |
| 339 | options.setFaceId(1000); |
| 340 | options.setCost(101); |
| 341 | |
| 342 | Block encodedOptions(options.wireEncode()); |
| 343 | |
| 344 | Name commandName("/localhost/nfd/fib"); |
| 345 | commandName.append("add-nexthop"); |
| 346 | commandName.append(encodedOptions); |
| 347 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 348 | face->onReceiveData += |
| 349 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 350 | commandName, 404, "Face not found"); |
| 351 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 352 | Interest command(commandName); |
| 353 | manager.onFibRequest(command); |
| 354 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 355 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 356 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101) == false); |
| 357 | } |
| 358 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 359 | BOOST_AUTO_TEST_CASE(TestImplicitFaceId) |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 360 | { |
| 361 | addFace(make_shared<DummyFace>()); |
| 362 | |
| 363 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 364 | Fib fib; |
| 365 | FibManager manager(fib, |
| 366 | bind(&FibManagerFixture::getFace, this, _1), |
| 367 | face); |
| 368 | |
| 369 | FibManagementOptions options; |
| 370 | options.setName("/hello"); |
| 371 | options.setFaceId(0); |
| 372 | options.setCost(101); |
| 373 | |
| 374 | Block encodedOptions(options.wireEncode()); |
| 375 | |
| 376 | Name commandName("/localhost/nfd/fib"); |
| 377 | commandName.append("add-nexthop"); |
| 378 | commandName.append(encodedOptions); |
| 379 | |
| 380 | FibManagementOptions expectedOptions; |
| 381 | expectedOptions.setName("/hello"); |
| 382 | expectedOptions.setFaceId(1); |
| 383 | expectedOptions.setCost(101); |
| 384 | |
| 385 | Block encodedExpectedOptions(expectedOptions.wireEncode()); |
| 386 | |
| 387 | face->onReceiveData += |
| 388 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 389 | commandName, 200, "Success", encodedExpectedOptions); |
| 390 | |
| 391 | fib.insert("/hello"); |
| 392 | |
| 393 | Interest command(commandName); |
| 394 | command.setIncomingFaceId(1); |
| 395 | manager.onFibRequest(command); |
| 396 | |
| 397 | BOOST_REQUIRE(didCallbackFire()); |
| 398 | BOOST_REQUIRE(addedNextHopWithFace(fib, "/hello", 0, 101, getFace(1))); |
| 399 | } |
| 400 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 401 | BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd) |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 402 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 403 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 404 | |
| 405 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 406 | Fib fib; |
| 407 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 408 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 409 | face); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 410 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 411 | FibManagementOptions options; |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 412 | options.setName("/hello"); |
| 413 | options.setFaceId(1); |
| 414 | options.setCost(101); |
| 415 | |
| 416 | Block encodedOptions(options.wireEncode()); |
| 417 | |
| 418 | Name commandName("/localhost/nfd/fib"); |
| 419 | commandName.append("add-nexthop"); |
| 420 | commandName.append(encodedOptions); |
| 421 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 422 | face->onReceiveData += |
| 423 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 424 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 425 | |
| 426 | fib.insert("/hello"); |
| 427 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 428 | Interest command(commandName); |
| 429 | manager.onFibRequest(command); |
| 430 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 431 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 432 | BOOST_REQUIRE(addedNextHopWithCost(fib, "/hello", 0, 101)); |
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 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 435 | BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 436 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 437 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 438 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 439 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 440 | Fib fib; |
| 441 | FibManager manager(fib, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 442 | bind(&FibManagerFixture::getFace, this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 443 | face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 444 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 445 | fib.insert("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 446 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 447 | for (int i = 1; i <= 2; i++) |
| 448 | { |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 449 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 450 | FibManagementOptions options; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 451 | options.setName("/hello"); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 452 | options.setFaceId(1); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 453 | options.setCost(100 + i); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 454 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 455 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 456 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 457 | Name commandName("/localhost/nfd/fib"); |
| 458 | commandName.append("add-nexthop"); |
| 459 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 460 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 461 | face->onReceiveData += |
| 462 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 463 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 464 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 465 | Interest command(commandName); |
| 466 | manager.onFibRequest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 467 | BOOST_REQUIRE(didCallbackFire()); |
| 468 | resetCallbackFired(); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 469 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 470 | shared_ptr<fib::Entry> entry = fib.findExactMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 471 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 472 | if (static_cast<bool>(entry)) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 473 | { |
| 474 | const fib::NextHopList& hops = entry->getNextHops(); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 475 | BOOST_REQUIRE(hops.size() == 1); |
| 476 | BOOST_REQUIRE(std::find_if(hops.begin(), hops.end(), |
| 477 | bind(&foundNextHop, -1, 100 + i, _1)) != hops.end()); |
| 478 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 479 | } |
| 480 | else |
| 481 | { |
| 482 | BOOST_FAIL("Failed to find expected fib entry"); |
| 483 | } |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 484 | |
| 485 | face->onReceiveData.clear(); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 488 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 489 | BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 490 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 491 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 492 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 493 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 494 | Fib fib; |
| 495 | FibManager manager(fib, |
| 496 | bind(&FibManagerFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 497 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 498 | face); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 499 | |
| 500 | fib.insert("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 501 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 502 | FibManagementOptions options; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 503 | options.setName("/hello"); |
| 504 | options.setFaceId(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 505 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 506 | { |
| 507 | options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 508 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 509 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 510 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 511 | Name commandName("/localhost/nfd/fib"); |
| 512 | commandName.append("add-nexthop"); |
| 513 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 514 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 515 | face->onReceiveData += |
| 516 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 517 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 518 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 519 | Interest command(commandName); |
| 520 | manager.onFibRequest(command); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 521 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 522 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 523 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 524 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 525 | resetCallbackFired(); |
| 526 | face->onReceiveData.clear(); |
| 527 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 528 | { |
| 529 | options.setCost(102); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 530 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 531 | Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 532 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 533 | Name commandName("/localhost/nfd/fib"); |
| 534 | commandName.append("add-nexthop"); |
| 535 | commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 536 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 537 | face->onReceiveData += |
| 538 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 539 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 540 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 541 | Interest command(commandName); |
| 542 | manager.onFibRequest(command); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 543 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 544 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 545 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 546 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 547 | shared_ptr<fib::Entry> entry = fib.findExactMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 548 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 549 | // Add faces with cost == FaceID for the name /hello |
| 550 | // This test assumes: |
| 551 | // FaceIDs are -1 because we don't add them to a forwarder |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 552 | if (static_cast<bool>(entry)) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 553 | { |
| 554 | const fib::NextHopList& hops = entry->getNextHops(); |
| 555 | BOOST_REQUIRE(hops.size() == 1); |
| 556 | BOOST_REQUIRE(std::find_if(hops.begin(), |
| 557 | hops.end(), |
| 558 | bind(&foundNextHop, -1, 102, _1)) != hops.end()); |
| 559 | } |
| 560 | else |
| 561 | { |
| 562 | BOOST_FAIL("Failed to find expected fib entry"); |
| 563 | } |
| 564 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 565 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 566 | BOOST_AUTO_TEST_CASE(Insert) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 567 | { |
| 568 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 569 | Fib fib; |
| 570 | FibManager manager(fib, |
| 571 | bind(&FibManagerFixture::getFace, this, _1), |
| 572 | face); |
| 573 | |
| 574 | { |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 575 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 576 | options.setName("/hello"); |
| 577 | |
| 578 | Block encodedOptions(options.wireEncode()); |
| 579 | |
| 580 | Name commandName("/localhost/nfd/fib"); |
| 581 | commandName.append("insert"); |
| 582 | commandName.append(encodedOptions); |
| 583 | |
| 584 | face->onReceiveData += |
| 585 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 586 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 587 | |
| 588 | Interest command(commandName); |
| 589 | manager.onFibRequest(command); |
| 590 | } |
| 591 | |
| 592 | BOOST_REQUIRE(didCallbackFire()); |
| 593 | |
| 594 | shared_ptr<fib::Entry> entry = fib.findExactMatch("/hello"); |
| 595 | if (static_cast<bool>(entry)) |
| 596 | { |
| 597 | const fib::NextHopList& hops = entry->getNextHops(); |
| 598 | BOOST_CHECK_EQUAL(hops.size(), 0); |
| 599 | } |
| 600 | |
| 601 | resetCallbackFired(); |
| 602 | |
| 603 | { |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 604 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 605 | options.setName("/hello"); |
| 606 | |
| 607 | Block encodedOptions(options.wireEncode()); |
| 608 | |
| 609 | Name commandName("/localhost/nfd/fib"); |
| 610 | commandName.append("insert"); |
| 611 | commandName.append(encodedOptions); |
| 612 | |
| 613 | face->onReceiveData += |
| 614 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 615 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 616 | |
| 617 | Interest command(commandName); |
| 618 | manager.onFibRequest(command); |
| 619 | } |
| 620 | |
| 621 | BOOST_REQUIRE(didCallbackFire()); |
| 622 | |
| 623 | entry = fib.findExactMatch("/hello"); |
| 624 | if (static_cast<bool>(entry)) |
| 625 | { |
| 626 | const fib::NextHopList& hops = entry->getNextHops(); |
| 627 | BOOST_CHECK_EQUAL(hops.size(), 0); |
| 628 | } |
| 629 | |
| 630 | } |
| 631 | |
| 632 | void |
| 633 | testRemove(FibManagerFixture* fixture, |
| 634 | FibManager& manager, |
| 635 | Fib& fib, |
| 636 | shared_ptr<Face> face, |
| 637 | const Name& target) |
| 638 | { |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 639 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 640 | options.setName(target); |
| 641 | |
| 642 | Block encodedOptions(options.wireEncode()); |
| 643 | |
| 644 | Name commandName("/localhost/nfd/fib"); |
| 645 | commandName.append("delete"); |
| 646 | commandName.append(encodedOptions); |
| 647 | |
| 648 | face->onReceiveData += |
| 649 | bind(&FibManagerFixture::validateControlResponse, fixture, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 650 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 651 | |
| 652 | Interest command(commandName); |
| 653 | manager.onFibRequest(command); |
| 654 | |
| 655 | BOOST_REQUIRE(fixture->didCallbackFire()); |
| 656 | |
| 657 | if (static_cast<bool>(fib.findExactMatch(target))) |
| 658 | { |
| 659 | BOOST_FAIL("Found \"removed\" prefix"); |
| 660 | } |
| 661 | face->onReceiveData.clear(); |
| 662 | } |
| 663 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 664 | BOOST_AUTO_TEST_CASE(Delete) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 665 | { |
| 666 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 667 | Fib fib; |
| 668 | FibManager manager(fib, |
| 669 | bind(&FibManagerFixture::getFace, this, _1), |
| 670 | face); |
| 671 | |
| 672 | fib.insert("/a"); |
| 673 | fib.insert("/a/b"); |
| 674 | fib.insert("/a/b/c"); |
| 675 | |
| 676 | testRemove(this, manager, fib, face, "/"); |
| 677 | |
| 678 | if (!static_cast<bool>(fib.findExactMatch("/a")) || |
| 679 | !static_cast<bool>(fib.findExactMatch("/a/b")) || |
| 680 | !static_cast<bool>(fib.findExactMatch("/a/b/c"))) |
| 681 | { |
| 682 | BOOST_FAIL("Removed incorrect entry"); |
| 683 | } |
| 684 | |
| 685 | testRemove(this, manager, fib, face, "/a/b"); |
| 686 | |
| 687 | if (!static_cast<bool>(fib.findExactMatch("/a")) || |
| 688 | !static_cast<bool>(fib.findExactMatch("/a/b/c"))) |
| 689 | { |
| 690 | BOOST_FAIL("Removed incorrect entry"); |
| 691 | } |
| 692 | |
| 693 | testRemove(this, manager, fib, face, "/a/b/c"); |
| 694 | |
| 695 | if (!static_cast<bool>(fib.findExactMatch("/a"))) |
| 696 | { |
| 697 | BOOST_FAIL("Removed incorrect entry"); |
| 698 | } |
| 699 | |
| 700 | testRemove(this, manager, fib, face, "/a"); |
| 701 | |
| 702 | testRemove(this, manager, fib, face, "/does/not/exist"); |
| 703 | } |
| 704 | |
| 705 | bool |
| 706 | removedNextHopWithCost(const Fib& fib, const Name& prefix, size_t oldSize, uint32_t cost) |
| 707 | { |
| 708 | shared_ptr<fib::Entry> entry = fib.findExactMatch(prefix); |
| 709 | |
| 710 | if (static_cast<bool>(entry)) |
| 711 | { |
| 712 | const fib::NextHopList& hops = entry->getNextHops(); |
| 713 | return hops.size() == oldSize - 1 && |
| 714 | std::find_if(hops.begin(), hops.end(), bind(&foundNextHop, -1, cost, _1)) == hops.end(); |
| 715 | } |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | void |
| 720 | testRemoveNextHop(FibManagerFixture* fixture, |
| 721 | FibManager& manager, |
| 722 | Fib& fib, |
| 723 | shared_ptr<Face> face, |
| 724 | const Name& targetName, |
| 725 | FaceId targetFace) |
| 726 | { |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 727 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 728 | options.setName(targetName); |
| 729 | options.setFaceId(targetFace); |
| 730 | |
| 731 | Block encodedOptions(options.wireEncode()); |
| 732 | |
| 733 | Name commandName("/localhost/nfd/fib"); |
| 734 | commandName.append("remove-nexthop"); |
| 735 | commandName.append(encodedOptions); |
| 736 | |
| 737 | face->onReceiveData += |
| 738 | bind(&FibManagerFixture::validateControlResponse, fixture, _1, |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 739 | commandName, 200, "Success", encodedOptions); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 740 | |
| 741 | Interest command(commandName); |
| 742 | manager.onFibRequest(command); |
| 743 | |
| 744 | BOOST_REQUIRE(fixture->didCallbackFire()); |
| 745 | |
| 746 | fixture->resetCallbackFired(); |
| 747 | face->onReceiveData.clear(); |
| 748 | } |
| 749 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 750 | BOOST_AUTO_TEST_CASE(RemoveNextHop) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 751 | { |
| 752 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 753 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
| 754 | shared_ptr<Face> face3 = make_shared<DummyFace>(); |
| 755 | |
| 756 | addFace(face1); |
| 757 | addFace(face2); |
| 758 | addFace(face3); |
| 759 | |
| 760 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 761 | Fib fib; |
| 762 | FibManager manager(fib, |
| 763 | bind(&FibManagerFixture::getFace, this, _1), |
| 764 | face); |
| 765 | |
| 766 | shared_ptr<fib::Entry> entry = fib.insert("/hello").first; |
| 767 | |
| 768 | entry->addNextHop(face1, 101); |
| 769 | entry->addNextHop(face2, 202); |
| 770 | entry->addNextHop(face3, 303); |
| 771 | |
| 772 | testRemoveNextHop(this, manager, fib, face, "/hello", 2); |
| 773 | BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 3, 202)); |
| 774 | |
| 775 | testRemoveNextHop(this, manager, fib, face, "/hello", 3); |
| 776 | BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 2, 303)); |
| 777 | |
| 778 | testRemoveNextHop(this, manager, fib, face, "/hello", 1); |
| 779 | BOOST_REQUIRE(removedNextHopWithCost(fib, "/hello", 1, 101)); |
| 780 | |
| 781 | if (!static_cast<bool>(fib.findExactMatch("/hello"))) |
| 782 | { |
| 783 | BOOST_FAIL("removed entry after removing all next hops"); |
| 784 | } |
| 785 | |
| 786 | } |
| 787 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 788 | BOOST_AUTO_TEST_CASE(RemoveNoFace) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 789 | { |
| 790 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 791 | Fib fib; |
| 792 | FibManager manager(fib, |
| 793 | bind(&FibManagerFixture::getFace, this, _1), |
| 794 | face); |
| 795 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 796 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 797 | options.setName("/hello"); |
| 798 | options.setFaceId(1); |
| 799 | |
| 800 | Block encodedOptions(options.wireEncode()); |
| 801 | |
| 802 | Name commandName("/localhost/nfd/fib"); |
| 803 | commandName.append("remove-nexthop"); |
| 804 | commandName.append(encodedOptions); |
| 805 | |
| 806 | face->onReceiveData += |
| 807 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 808 | commandName, 404, "Face not found"); |
| 809 | |
| 810 | Interest command(commandName); |
| 811 | manager.onFibRequest(command); |
| 812 | |
| 813 | BOOST_REQUIRE(didCallbackFire()); |
| 814 | } |
| 815 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 816 | BOOST_AUTO_TEST_CASE(RemoveNoPrefix) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 817 | { |
| 818 | addFace(make_shared<DummyFace>()); |
| 819 | |
| 820 | shared_ptr<InternalFace> face(make_shared<InternalFace>()); |
| 821 | Fib fib; |
| 822 | FibManager manager(fib, |
| 823 | bind(&FibManagerFixture::getFace, this, _1), |
| 824 | face); |
| 825 | |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 826 | FibManagementOptions options; |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 827 | options.setName("/hello"); |
| 828 | options.setFaceId(1); |
| 829 | |
| 830 | Block encodedOptions(options.wireEncode()); |
| 831 | |
| 832 | Name commandName("/localhost/nfd/fib"); |
| 833 | commandName.append("remove-nexthop"); |
| 834 | commandName.append(encodedOptions); |
| 835 | |
| 836 | face->onReceiveData += |
| 837 | bind(&FibManagerFixture::validateControlResponse, this, _1, |
| 838 | commandName, 404, "Prefix not found"); |
| 839 | |
| 840 | Interest command(commandName); |
| 841 | manager.onFibRequest(command); |
| 842 | |
| 843 | BOOST_REQUIRE(didCallbackFire()); |
| 844 | } |
| 845 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 846 | BOOST_AUTO_TEST_SUITE_END() |
| 847 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 848 | } // namespace tests |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 849 | } // namespace nfd |