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