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