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