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