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