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