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" |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 27 | #include "core/random.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 28 | #include "face/tcp-factory.hpp" |
| 29 | #include "face/udp-factory.hpp" |
| 30 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 31 | #include "nfd-manager-common-fixture.hpp" |
| 32 | #include "../face/dummy-face.hpp" |
| 33 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/encoding/tlv.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/mgmt/nfd/channel-status.hpp> |
| 36 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 37 | |
| 38 | namespace nfd { |
| 39 | namespace tests { |
| 40 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 41 | class FaceManagerFixture : public NfdManagerCommonFixture |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
| 44 | FaceManagerFixture() |
| 45 | : m_faceTable(m_forwarder.getFaceTable()) |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 46 | , m_manager(m_faceTable, m_dispatcher, *m_authenticator) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 47 | { |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 48 | setTopPrefix(); |
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 | { |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 106 | static std::uniform_int_distribution<typename T::rep> dist; |
| 107 | const_cast<T&>(counter).set(dist(getGlobalRng())); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 115 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 116 | BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 117 | |
| 118 | BOOST_AUTO_TEST_SUITE(DestroyFace) |
| 119 | |
| 120 | BOOST_AUTO_TEST_CASE(Existing) |
| 121 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 122 | 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] | 123 | |
| 124 | auto parameters = ControlParameters().setFaceId(addedFace->getId()); |
| 125 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 126 | |
| 127 | receiveInterest(command); |
| 128 | |
| 129 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification |
| 130 | // notification is already tested, so ignore it |
| 131 | |
| 132 | BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)), |
| 133 | CheckResponseResult::OK); |
| 134 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 135 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | BOOST_AUTO_TEST_CASE(NonExisting) |
| 139 | { |
| 140 | auto parameters = ControlParameters().setFaceId(65535); |
| 141 | auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); |
| 142 | |
| 143 | receiveInterest(command); |
| 144 | |
| 145 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 146 | |
| 147 | BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)), |
| 148 | CheckResponseResult::OK); |
| 149 | } |
| 150 | |
| 151 | BOOST_AUTO_TEST_SUITE_END() // DestroyFace |
| 152 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 153 | BOOST_AUTO_TEST_SUITE(Datasets) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 154 | |
| 155 | BOOST_AUTO_TEST_CASE(FaceDataset) |
| 156 | { |
| 157 | size_t nEntries = 303; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 158 | for (size_t i = 0; i < nEntries; ++i) { |
| 159 | addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | receiveInterest(makeInterest("/localhost/nfd/faces/list")); |
| 163 | |
| 164 | Block content; |
| 165 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 166 | BOOST_CHECK_NO_THROW(content.parse()); |
| 167 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 168 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 169 | std::set<FaceId> faceIds; |
| 170 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 171 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 172 | |
| 173 | ndn::nfd::FaceStatus decodedStatus; |
| 174 | BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 175 | BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 176 | faceIds.insert(decodedStatus.getFaceId()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | BOOST_CHECK_EQUAL(faceIds.size(), nEntries); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 180 | // TODO#3325 check dataset contents including counter values |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | BOOST_AUTO_TEST_CASE(FaceQuery) |
| 184 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 185 | auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// |
| 186 | auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local |
| 187 | auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 188 | |
| 189 | auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) { |
| 190 | return Name("/localhost/nfd/faces/query").append(filter.wireEncode()); |
| 191 | }; |
| 192 | |
| 193 | auto querySchemeName = |
| 194 | generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy")); |
| 195 | auto queryIdName = |
| 196 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId())); |
| 197 | auto queryScopeName = |
| 198 | generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)); |
| 199 | auto invalidQueryName = |
| 200 | Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid")); |
| 201 | |
| 202 | receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected |
| 203 | receiveInterest(makeInterest(queryIdName)); // face1 expected |
| 204 | receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected |
| 205 | receiveInterest(makeInterest(invalidQueryName)); // nack expected |
| 206 | |
| 207 | BOOST_REQUIRE_EQUAL(m_responses.size(), 4); |
| 208 | |
| 209 | Block content; |
| 210 | ndn::nfd::FaceStatus status; |
| 211 | |
| 212 | content = m_responses[0].getContent(); |
| 213 | BOOST_CHECK_NO_THROW(content.parse()); |
| 214 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2 |
| 215 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 216 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 217 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 218 | BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId()); |
| 219 | |
| 220 | content = m_responses[1].getContent(); |
| 221 | BOOST_CHECK_NO_THROW(content.parse()); |
| 222 | BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1 |
| 223 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 224 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 225 | |
| 226 | content = m_responses[2].getContent(); |
| 227 | BOOST_CHECK_NO_THROW(content.parse()); |
| 228 | BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3 |
| 229 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0])); |
| 230 | BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); |
| 231 | BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1])); |
| 232 | BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId()); |
| 233 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 234 | ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack), |
| 236 | CheckResponseResult::OK); |
| 237 | } |
| 238 | |
| 239 | class TestChannel : public Channel |
| 240 | { |
| 241 | public: |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 242 | explicit |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 243 | TestChannel(const std::string& uri) |
| 244 | { |
| 245 | setUri(FaceUri(uri)); |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | class TestProtocolFactory : public ProtocolFactory |
| 250 | { |
| 251 | public: |
| 252 | virtual void |
| 253 | createFace(const FaceUri& uri, |
| 254 | ndn::nfd::FacePersistency persistency, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 255 | bool wantLocalFieldsEnabled, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 256 | const FaceCreatedCallback& onCreated, |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 257 | const FaceCreationFailedCallback& onConnectFailed) final |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 258 | { |
| 259 | } |
| 260 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 261 | virtual std::vector<shared_ptr<const Channel>> |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 262 | getChannels() const final |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 263 | { |
| 264 | return m_channels; |
| 265 | } |
| 266 | |
| 267 | public: |
| 268 | shared_ptr<TestChannel> |
| 269 | addChannel(const std::string& channelUri) |
| 270 | { |
| 271 | auto channel = make_shared<TestChannel>(channelUri); |
| 272 | m_channels.push_back(channel); |
| 273 | return channel; |
| 274 | } |
| 275 | |
| 276 | private: |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 277 | std::vector<shared_ptr<const Channel>> m_channels; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | BOOST_AUTO_TEST_CASE(ChannelDataset) |
| 281 | { |
| 282 | auto factory = make_shared<TestProtocolFactory>(); |
| 283 | m_manager.m_factories["test"] = factory; |
| 284 | |
| 285 | std::map<std::string, shared_ptr<TestChannel>> addedChannels; |
| 286 | size_t nEntries = 404; |
| 287 | for (size_t i = 0 ; i < nEntries ; i ++) { |
| 288 | auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://"); |
| 289 | addedChannels[channel->getUri().toString()] = channel; |
| 290 | } |
| 291 | |
| 292 | receiveInterest(makeInterest("/localhost/nfd/faces/channels")); |
| 293 | |
| 294 | Block content; |
| 295 | BOOST_CHECK_NO_THROW(content = concatenateResponses()); |
| 296 | BOOST_CHECK_NO_THROW(content.parse()); |
| 297 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 298 | |
| 299 | for (size_t idx = 0; idx < nEntries; ++idx) { |
| 300 | BOOST_TEST_MESSAGE("processing element: " << idx); |
| 301 | |
| 302 | ndn::nfd::ChannelStatus decodedStatus; |
| 303 | BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx])); |
| 304 | BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end()); |
| 305 | } |
| 306 | } |
| 307 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 308 | BOOST_AUTO_TEST_SUITE_END() // Datasets |
| 309 | |
| 310 | BOOST_AUTO_TEST_SUITE(Notifications) |
| 311 | |
| 312 | BOOST_AUTO_TEST_CASE(FaceEventNotification) |
| 313 | { |
| 314 | auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification |
| 315 | BOOST_CHECK_NE(addedFace->getId(), -1); |
| 316 | int64_t faceId = addedFace->getId(); |
| 317 | |
| 318 | // check notification |
| 319 | { |
| 320 | Block payload; |
| 321 | ndn::nfd::FaceEventNotification notification; |
| 322 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
| 323 | BOOST_CHECK_NO_THROW(payload = m_responses[0].getContent().blockFromValue()); |
| 324 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 325 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 326 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED); |
| 327 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 328 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 329 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 330 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 331 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 332 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 333 | } |
| 334 | |
| 335 | addedFace->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED |
| 336 | advanceClocks(time::milliseconds(1), 10); |
| 337 | |
| 338 | // check notification |
| 339 | { |
| 340 | Block payload; |
| 341 | ndn::nfd::FaceEventNotification notification; |
| 342 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
| 343 | BOOST_CHECK_NO_THROW(payload = m_responses[1].getContent().blockFromValue()); |
| 344 | BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification); |
| 345 | BOOST_CHECK_NO_THROW(notification.wireDecode(payload)); |
| 346 | BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED); |
| 347 | BOOST_CHECK_EQUAL(notification.getFaceId(), faceId); |
| 348 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), addedFace->getRemoteUri().toString()); |
| 349 | BOOST_CHECK_EQUAL(notification.getLocalUri(), addedFace->getLocalUri().toString()); |
| 350 | BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 351 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 352 | BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); |
| 353 | } |
| 354 | BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); |
| 355 | } |
| 356 | |
| 357 | BOOST_AUTO_TEST_SUITE_END() // Notifications |
| 358 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 359 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 360 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 361 | |
| 362 | } // namespace tests |
| 363 | } // namespace nfd |