Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "mgmt/face-manager.hpp" |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 27 | #include "nfd-manager-common-fixture.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 28 | #include "../face/dummy-face.hpp" |
| 29 | #include "face/tcp-factory.hpp" |
| 30 | #include "face/udp-factory.hpp" |
| 31 | |
| 32 | #include <ndn-cxx/util/random.hpp> |
| 33 | #include <ndn-cxx/encoding/tlv.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame^] | 34 | #include <ndn-cxx/mgmt/nfd/channel-status.hpp> |
| 35 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 36 | |
| 37 | namespace nfd { |
| 38 | namespace tests { |
| 39 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 40 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 41 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 42 | class FaceManagerFixture : public NfdManagerCommonFixture |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | FaceManagerFixture() |
| 46 | : m_faceTable(m_forwarder.getFaceTable()) |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 47 | , m_manager(m_faceTable, m_dispatcher, *m_authenticator) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 48 | { |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 49 | setTopPrefix(); |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 50 | setPrivilege("faces"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 54 | enum AddFaceFlags { |
| 55 | REMOVE_LAST_NOTIFICATION = 1 << 0, |
| 56 | SET_SCOPE_LOCAL = 1 << 1, |
| 57 | SET_URI_TEST = 1 << 2, |
| 58 | RANDOMIZE_COUNTERS = 1 << 3 |
| 59 | }; |
| 60 | |
| 61 | /** \brief adds a face to the FaceTable |
| 62 | * \param options bitwise OR'ed AddFaceFlags |
| 63 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 64 | shared_ptr<Face> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 65 | addFace(int flags = 0) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 66 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 67 | std::string uri = "dummy://"; |
| 68 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL; |
| 69 | |
| 70 | if ((flags & SET_SCOPE_LOCAL) != 0) { |
| 71 | scope = ndn::nfd::FACE_SCOPE_LOCAL; |
| 72 | } |
| 73 | if ((flags & SET_URI_TEST) != 0) { |
| 74 | uri = "test://"; |
| 75 | } |
| 76 | |
| 77 | auto face = make_shared<DummyFace>(uri, uri, scope); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 78 | m_faceTable.add(face); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 79 | |
| 80 | if ((flags & RANDOMIZE_COUNTERS) != 0) { |
| 81 | const face::FaceCounters& counters = face->getCounters(); |
| 82 | randomizeCounter(counters.nInInterests); |
| 83 | randomizeCounter(counters.nOutInterests); |
| 84 | randomizeCounter(counters.nInData); |
| 85 | randomizeCounter(counters.nOutData); |
| 86 | randomizeCounter(counters.nInNacks); |
| 87 | randomizeCounter(counters.nOutNacks); |
| 88 | randomizeCounter(counters.nInPackets); |
| 89 | randomizeCounter(counters.nOutPackets); |
| 90 | randomizeCounter(counters.nInBytes); |
| 91 | randomizeCounter(counters.nOutBytes); |
| 92 | } |
| 93 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 94 | advanceClocks(time::milliseconds(1), 10); // wait for notification posted |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 95 | if ((flags & REMOVE_LAST_NOTIFICATION) != 0) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 96 | m_responses.pop_back(); |
| 97 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 98 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 99 | return face; |
| 100 | } |
| 101 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 102 | private: |
| 103 | template<typename T> |
| 104 | static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type |
| 105 | randomizeCounter(const T& counter) |
| 106 | { |
| 107 | const_cast<T&>(counter).set(ndn::random::generateWord64()); |
| 108 | } |
| 109 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 110 | protected: |
| 111 | FaceTable& m_faceTable; |
| 112 | FaceManager m_manager; |
| 113 | }; |
| 114 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 115 | BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 116 | |
| 117 | BOOST_AUTO_TEST_SUITE(DestroyFace) |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(Existing) |
| 120 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 121 | auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 122 | |
| 123 | auto parameters = ControlParameters().setFaceId(addedFace->getId()); |
| 124 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 125 | |
| 126 | receiveInterest(command); |
| 127 | |
| 128 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification |
| 129 | // notification is already tested, so ignore it |
| 130 | |
| 131 | BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)), |
| 132 | CheckResponseResult::OK); |
| 133 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 134 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | BOOST_AUTO_TEST_CASE(NonExisting) |
| 138 | { |
| 139 | auto parameters = ControlParameters().setFaceId(65535); |
| 140 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 141 | |
| 142 | receiveInterest(command); |
| 143 | |
| 144 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 145 | |
| 146 | BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)), |
| 147 | CheckResponseResult::OK); |
| 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_SUITE_END() // DestroyFace |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(FaceEvents) |
| 153 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 154 | auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 155 | BOOST_CHECK_NE(addedFace->getId(), -1); |
| 156 | int64_t faceId = addedFace->getId(); |
| 157 | |
| 158 | // check notification |
| 159 | { |
| 160 | Block payload; |
| 161 | ndn::nfd::FaceEventNotification notification; |
| 162 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 163 | BOOST_CHECK_NO_THROW(payload = m_responses[0].getContent().blockFromValue()); |
| 164 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 165 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 166 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED); |
| 167 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 168 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 169 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 170 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 171 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 172 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 173 | } |
| 174 | |
| 175 | addedFace->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED |
| 176 | advanceClocks(time::milliseconds(1), 10); |
| 177 | |
| 178 | // check notification |
| 179 | { |
| 180 | Block payload; |
| 181 | ndn::nfd::FaceEventNotification notification; |
| 182 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
| 183 | BOOST_CHECK_NO_THROW(payload = m_responses[1].getContent().blockFromValue()); |
| 184 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 185 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 186 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED); |
| 187 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 188 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 189 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 190 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 191 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 192 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 193 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 197 | // @todo Refactor when ndn::nfd::FaceStatus implementes operator!= and operator<< |
| 198 | class FaceStatus : public ndn::nfd::FaceStatus |
| 199 | { |
| 200 | public: |
| 201 | FaceStatus(const ndn::nfd::FaceStatus& s) |
| 202 | : ndn::nfd::FaceStatus(s) |
| 203 | { |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | bool |
| 208 | operator!=(const FaceStatus& left, const FaceStatus& right) |
| 209 | { |
| 210 | return left.getRemoteUri() != right.getRemoteUri() || |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 211 | left.getLocalUri() != right.getLocalUri() || |
| 212 | left.getFaceScope() != right.getFaceScope() || |
| 213 | left.getFacePersistency() != right.getFacePersistency() || |
| 214 | left.getLinkType() != right.getLinkType() || |
| 215 | left.getNInInterests() != right.getNInInterests() || |
| 216 | left.getNInDatas() != right.getNInDatas() || |
| 217 | left.getNOutInterests() != right.getNOutInterests() || |
| 218 | left.getNOutDatas() != right.getNOutDatas() || |
| 219 | left.getNInBytes() != right.getNInBytes() || |
| 220 | left.getNOutBytes() != right.getNOutBytes(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | std::ostream& |
| 224 | operator<<(std::ostream &os, const FaceStatus& status) |
| 225 | { |
| 226 | os << "[" << status.getRemoteUri() << ", " |
| 227 | << status.getLocalUri() << ", " |
| 228 | << status.getFacePersistency() << ", " |
| 229 | << status.getLinkType() << ", " |
| 230 | << status.getNInInterests() << ", " |
| 231 | << status.getNInDatas() << ", " |
| 232 | << status.getNOutInterests() << ", " |
| 233 | << status.getNOutDatas() << ", " |
| 234 | << status.getNInBytes() << ", " |
| 235 | << status.getNOutBytes() << "]"; |
| 236 | return os; |
| 237 | } |
| 238 | |
| 239 | BOOST_AUTO_TEST_CASE(FaceDataset) |
| 240 | { |
| 241 | size_t nEntries = 303; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 242 | for (size_t i = 0; i < nEntries; ++i) { |
| 243 | addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | receiveInterest(makeInterest("/localhost/nfd/faces/list")); |
| 247 | |
| 248 | Block content; |
| 249 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 250 | BOOST_CHECK_NO_THROW(content.parse()); |
| 251 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 252 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 253 | std::set<FaceId> faceIds; |
| 254 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 255 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 256 | |
| 257 | ndn::nfd::FaceStatus decodedStatus; |
| 258 | BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 259 | BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 260 | faceIds.insert(decodedStatus.getFaceId()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | BOOST_CHECK_EQUAL(faceIds.size(), nEntries); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 264 | // TODO#3325 check dataset contents including counter values |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | BOOST_AUTO_TEST_CASE(FaceQuery) |
| 268 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 269 | auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// |
| 270 | auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local |
| 271 | auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 272 | |
| 273 | auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) { |
| 274 | return Name("/localhost/nfd/faces/query").append(filter.wireEncode()); |
| 275 | }; |
| 276 | |
| 277 | auto querySchemeName = |
| 278 | generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy")); |
| 279 | auto queryIdName = |
| 280 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId())); |
| 281 | auto queryScopeName = |
| 282 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)); |
| 283 | auto invalidQueryName = |
| 284 | Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid")); |
| 285 | |
| 286 | receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected |
| 287 | receiveInterest(makeInterest(queryIdName)); // face1 expected |
| 288 | receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected |
| 289 | receiveInterest(makeInterest(invalidQueryName)); // nack expected |
| 290 | |
| 291 | BOOST_REQUIRE_EQUAL(m_responses.size(), 4); |
| 292 | |
| 293 | Block content; |
| 294 | ndn::nfd::FaceStatus status; |
| 295 | |
| 296 | content = m_responses[0].getContent(); |
| 297 | BOOST_CHECK_NO_THROW(content.parse()); |
| 298 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2 |
| 299 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 300 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 301 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 302 | BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId()); |
| 303 | |
| 304 | content = m_responses[1].getContent(); |
| 305 | BOOST_CHECK_NO_THROW(content.parse()); |
| 306 | BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1 |
| 307 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 308 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 309 | |
| 310 | content = m_responses[2].getContent(); |
| 311 | BOOST_CHECK_NO_THROW(content.parse()); |
| 312 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3 |
| 313 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 314 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 315 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 316 | BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId()); |
| 317 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 318 | ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack), |
| 320 | CheckResponseResult::OK); |
| 321 | } |
| 322 | |
| 323 | class TestChannel : public Channel |
| 324 | { |
| 325 | public: |
| 326 | TestChannel(const std::string& uri) |
| 327 | { |
| 328 | setUri(FaceUri(uri)); |
| 329 | } |
| 330 | }; |
| 331 | |
| 332 | class TestProtocolFactory : public ProtocolFactory |
| 333 | { |
| 334 | public: |
| 335 | virtual void |
| 336 | createFace(const FaceUri& uri, |
| 337 | ndn::nfd::FacePersistency persistency, |
| 338 | const FaceCreatedCallback& onCreated, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 339 | const FaceCreationFailedCallback& onConnectFailed) override |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 340 | { |
| 341 | } |
| 342 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 343 | virtual std::vector<shared_ptr<const Channel>> |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 344 | getChannels() const override |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 345 | { |
| 346 | return m_channels; |
| 347 | } |
| 348 | |
| 349 | public: |
| 350 | shared_ptr<TestChannel> |
| 351 | addChannel(const std::string& channelUri) |
| 352 | { |
| 353 | auto channel = make_shared<TestChannel>(channelUri); |
| 354 | m_channels.push_back(channel); |
| 355 | return channel; |
| 356 | } |
| 357 | |
| 358 | private: |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 359 | std::vector<shared_ptr<const Channel>> m_channels; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | BOOST_AUTO_TEST_CASE(ChannelDataset) |
| 363 | { |
| 364 | auto factory = make_shared<TestProtocolFactory>(); |
| 365 | m_manager.m_factories["test"] = factory; |
| 366 | |
| 367 | std::map<std::string, shared_ptr<TestChannel>> addedChannels; |
| 368 | size_t nEntries = 404; |
| 369 | for (size_t i = 0 ; i < nEntries ; i ++) { |
| 370 | auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://"); |
| 371 | addedChannels[channel->getUri().toString()] = channel; |
| 372 | } |
| 373 | |
| 374 | receiveInterest(makeInterest("/localhost/nfd/faces/channels")); |
| 375 | |
| 376 | Block content; |
| 377 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 378 | BOOST_CHECK_NO_THROW(content.parse()); |
| 379 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 380 | |
| 381 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 382 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 383 | |
| 384 | ndn::nfd::ChannelStatus decodedStatus; |
| 385 | BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
| 386 | BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end()); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 391 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 392 | |
| 393 | } // namespace tests |
| 394 | } // namespace nfd |