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> |
| 34 | #include <ndn-cxx/management/nfd-channel-status.hpp> |
| 35 | #include <ndn-cxx/management/nfd-face-event-notification.hpp> |
| 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()) |
| 47 | , m_manager(m_faceTable, m_dispatcher, m_validator) |
| 48 | { |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 49 | setPrivilege("faces"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | public: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 53 | enum AddFaceFlags { |
| 54 | REMOVE_LAST_NOTIFICATION = 1 << 0, |
| 55 | SET_SCOPE_LOCAL = 1 << 1, |
| 56 | SET_URI_TEST = 1 << 2, |
| 57 | RANDOMIZE_COUNTERS = 1 << 3 |
| 58 | }; |
| 59 | |
| 60 | /** \brief adds a face to the FaceTable |
| 61 | * \param options bitwise OR'ed AddFaceFlags |
| 62 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 63 | shared_ptr<Face> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 64 | addFace(int flags = 0) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 65 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 66 | std::string uri = "dummy://"; |
| 67 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL; |
| 68 | |
| 69 | if ((flags & SET_SCOPE_LOCAL) != 0) { |
| 70 | scope = ndn::nfd::FACE_SCOPE_LOCAL; |
| 71 | } |
| 72 | if ((flags & SET_URI_TEST) != 0) { |
| 73 | uri = "test://"; |
| 74 | } |
| 75 | |
| 76 | auto face = make_shared<DummyFace>(uri, uri, scope); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 77 | m_faceTable.add(face); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 78 | |
| 79 | if ((flags & RANDOMIZE_COUNTERS) != 0) { |
| 80 | const face::FaceCounters& counters = face->getCounters(); |
| 81 | randomizeCounter(counters.nInInterests); |
| 82 | randomizeCounter(counters.nOutInterests); |
| 83 | randomizeCounter(counters.nInData); |
| 84 | randomizeCounter(counters.nOutData); |
| 85 | randomizeCounter(counters.nInNacks); |
| 86 | randomizeCounter(counters.nOutNacks); |
| 87 | randomizeCounter(counters.nInPackets); |
| 88 | randomizeCounter(counters.nOutPackets); |
| 89 | randomizeCounter(counters.nInBytes); |
| 90 | randomizeCounter(counters.nOutBytes); |
| 91 | } |
| 92 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 93 | advanceClocks(time::milliseconds(1), 10); // wait for notification posted |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 94 | if ((flags & REMOVE_LAST_NOTIFICATION) != 0) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 95 | m_responses.pop_back(); |
| 96 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 97 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 98 | return face; |
| 99 | } |
| 100 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 101 | private: |
| 102 | template<typename T> |
| 103 | static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type |
| 104 | randomizeCounter(const T& counter) |
| 105 | { |
| 106 | const_cast<T&>(counter).set(ndn::random::generateWord64()); |
| 107 | } |
| 108 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 109 | protected: |
| 110 | FaceTable& m_faceTable; |
| 111 | FaceManager m_manager; |
| 112 | }; |
| 113 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 114 | BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 115 | |
| 116 | BOOST_AUTO_TEST_SUITE(DestroyFace) |
| 117 | |
| 118 | BOOST_AUTO_TEST_CASE(Existing) |
| 119 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 120 | 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] | 121 | |
| 122 | auto parameters = ControlParameters().setFaceId(addedFace->getId()); |
| 123 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 124 | |
| 125 | receiveInterest(command); |
| 126 | |
| 127 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification |
| 128 | // notification is already tested, so ignore it |
| 129 | |
| 130 | BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)), |
| 131 | CheckResponseResult::OK); |
| 132 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 133 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(NonExisting) |
| 137 | { |
| 138 | auto parameters = ControlParameters().setFaceId(65535); |
| 139 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 140 | |
| 141 | receiveInterest(command); |
| 142 | |
| 143 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 144 | |
| 145 | BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)), |
| 146 | CheckResponseResult::OK); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_SUITE_END() // DestroyFace |
| 150 | |
| 151 | BOOST_AUTO_TEST_CASE(FaceEvents) |
| 152 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 153 | auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 154 | BOOST_CHECK_NE(addedFace->getId(), -1); |
| 155 | int64_t faceId = addedFace->getId(); |
| 156 | |
| 157 | // check notification |
| 158 | { |
| 159 | Block payload; |
| 160 | ndn::nfd::FaceEventNotification notification; |
| 161 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 162 | BOOST_CHECK_NO_THROW(payload = m_responses[0].getContent().blockFromValue()); |
| 163 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 164 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 165 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED); |
| 166 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 167 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 168 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 169 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 170 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 171 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 172 | } |
| 173 | |
| 174 | addedFace->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED |
| 175 | advanceClocks(time::milliseconds(1), 10); |
| 176 | |
| 177 | // check notification |
| 178 | { |
| 179 | Block payload; |
| 180 | ndn::nfd::FaceEventNotification notification; |
| 181 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
| 182 | BOOST_CHECK_NO_THROW(payload = m_responses[1].getContent().blockFromValue()); |
| 183 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 184 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 185 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED); |
| 186 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 187 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 188 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 189 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 190 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 191 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 192 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 196 | // @todo Refactor when ndn::nfd::FaceStatus implementes operator!= and operator<< |
| 197 | class FaceStatus : public ndn::nfd::FaceStatus |
| 198 | { |
| 199 | public: |
| 200 | FaceStatus(const ndn::nfd::FaceStatus& s) |
| 201 | : ndn::nfd::FaceStatus(s) |
| 202 | { |
| 203 | } |
| 204 | }; |
| 205 | |
| 206 | bool |
| 207 | operator!=(const FaceStatus& left, const FaceStatus& right) |
| 208 | { |
| 209 | return left.getRemoteUri() != right.getRemoteUri() || |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 210 | left.getLocalUri() != right.getLocalUri() || |
| 211 | left.getFaceScope() != right.getFaceScope() || |
| 212 | left.getFacePersistency() != right.getFacePersistency() || |
| 213 | left.getLinkType() != right.getLinkType() || |
| 214 | left.getNInInterests() != right.getNInInterests() || |
| 215 | left.getNInDatas() != right.getNInDatas() || |
| 216 | left.getNOutInterests() != right.getNOutInterests() || |
| 217 | left.getNOutDatas() != right.getNOutDatas() || |
| 218 | left.getNInBytes() != right.getNInBytes() || |
| 219 | left.getNOutBytes() != right.getNOutBytes(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | std::ostream& |
| 223 | operator<<(std::ostream &os, const FaceStatus& status) |
| 224 | { |
| 225 | os << "[" << status.getRemoteUri() << ", " |
| 226 | << status.getLocalUri() << ", " |
| 227 | << status.getFacePersistency() << ", " |
| 228 | << status.getLinkType() << ", " |
| 229 | << status.getNInInterests() << ", " |
| 230 | << status.getNInDatas() << ", " |
| 231 | << status.getNOutInterests() << ", " |
| 232 | << status.getNOutDatas() << ", " |
| 233 | << status.getNInBytes() << ", " |
| 234 | << status.getNOutBytes() << "]"; |
| 235 | return os; |
| 236 | } |
| 237 | |
| 238 | BOOST_AUTO_TEST_CASE(FaceDataset) |
| 239 | { |
| 240 | size_t nEntries = 303; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 241 | for (size_t i = 0; i < nEntries; ++i) { |
| 242 | addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | receiveInterest(makeInterest("/localhost/nfd/faces/list")); |
| 246 | |
| 247 | Block content; |
| 248 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 249 | BOOST_CHECK_NO_THROW(content.parse()); |
| 250 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 251 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 252 | std::set<FaceId> faceIds; |
| 253 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 254 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 255 | |
| 256 | ndn::nfd::FaceStatus decodedStatus; |
| 257 | BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 258 | BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 259 | faceIds.insert(decodedStatus.getFaceId()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | BOOST_CHECK_EQUAL(faceIds.size(), nEntries); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 263 | // TODO#3325 check dataset contents including counter values |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | BOOST_AUTO_TEST_CASE(FaceQuery) |
| 267 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 268 | auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// |
| 269 | auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local |
| 270 | auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 271 | |
| 272 | auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) { |
| 273 | return Name("/localhost/nfd/faces/query").append(filter.wireEncode()); |
| 274 | }; |
| 275 | |
| 276 | auto querySchemeName = |
| 277 | generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy")); |
| 278 | auto queryIdName = |
| 279 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId())); |
| 280 | auto queryScopeName = |
| 281 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)); |
| 282 | auto invalidQueryName = |
| 283 | Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid")); |
| 284 | |
| 285 | receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected |
| 286 | receiveInterest(makeInterest(queryIdName)); // face1 expected |
| 287 | receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected |
| 288 | receiveInterest(makeInterest(invalidQueryName)); // nack expected |
| 289 | |
| 290 | BOOST_REQUIRE_EQUAL(m_responses.size(), 4); |
| 291 | |
| 292 | Block content; |
| 293 | ndn::nfd::FaceStatus status; |
| 294 | |
| 295 | content = m_responses[0].getContent(); |
| 296 | BOOST_CHECK_NO_THROW(content.parse()); |
| 297 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2 |
| 298 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 299 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 300 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 301 | BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId()); |
| 302 | |
| 303 | content = m_responses[1].getContent(); |
| 304 | BOOST_CHECK_NO_THROW(content.parse()); |
| 305 | BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1 |
| 306 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 307 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 308 | |
| 309 | content = m_responses[2].getContent(); |
| 310 | BOOST_CHECK_NO_THROW(content.parse()); |
| 311 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3 |
| 312 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 313 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 314 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 315 | BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId()); |
| 316 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 317 | ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 318 | BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack), |
| 319 | CheckResponseResult::OK); |
| 320 | } |
| 321 | |
| 322 | class TestChannel : public Channel |
| 323 | { |
| 324 | public: |
| 325 | TestChannel(const std::string& uri) |
| 326 | { |
| 327 | setUri(FaceUri(uri)); |
| 328 | } |
| 329 | }; |
| 330 | |
| 331 | class TestProtocolFactory : public ProtocolFactory |
| 332 | { |
| 333 | public: |
| 334 | virtual void |
| 335 | createFace(const FaceUri& uri, |
| 336 | ndn::nfd::FacePersistency persistency, |
| 337 | const FaceCreatedCallback& onCreated, |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 338 | const FaceCreationFailedCallback& onConnectFailed) DECL_OVERRIDE |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 339 | { |
| 340 | } |
| 341 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 342 | virtual std::vector<shared_ptr<const Channel>> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 343 | getChannels() const DECL_OVERRIDE |
| 344 | { |
| 345 | return m_channels; |
| 346 | } |
| 347 | |
| 348 | public: |
| 349 | shared_ptr<TestChannel> |
| 350 | addChannel(const std::string& channelUri) |
| 351 | { |
| 352 | auto channel = make_shared<TestChannel>(channelUri); |
| 353 | m_channels.push_back(channel); |
| 354 | return channel; |
| 355 | } |
| 356 | |
| 357 | private: |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 358 | std::vector<shared_ptr<const Channel>> m_channels; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | BOOST_AUTO_TEST_CASE(ChannelDataset) |
| 362 | { |
| 363 | auto factory = make_shared<TestProtocolFactory>(); |
| 364 | m_manager.m_factories["test"] = factory; |
| 365 | |
| 366 | std::map<std::string, shared_ptr<TestChannel>> addedChannels; |
| 367 | size_t nEntries = 404; |
| 368 | for (size_t i = 0 ; i < nEntries ; i ++) { |
| 369 | auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://"); |
| 370 | addedChannels[channel->getUri().toString()] = channel; |
| 371 | } |
| 372 | |
| 373 | receiveInterest(makeInterest("/localhost/nfd/faces/channels")); |
| 374 | |
| 375 | Block content; |
| 376 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 377 | BOOST_CHECK_NO_THROW(content.parse()); |
| 378 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 379 | |
| 380 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 381 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 382 | |
| 383 | ndn::nfd::ChannelStatus decodedStatus; |
| 384 | BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
| 385 | BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end()); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 390 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 391 | |
| 392 | } // namespace tests |
| 393 | } // namespace nfd |