blob: c584538bd000f27d4a86ce0c1d331e34a2752143 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi38b24c72017-01-05 02:59:31 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -07004 * 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 Pesavento5f47aa62016-10-07 22:09:09 +020027#include "core/random.hpp"
Junxiao Shiea47bde2017-01-26 17:49:16 +000028#include "face/protocol-factory.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070029
Davide Pesavento97210d52016-10-14 15:45:48 +020030#include "nfd-manager-common-fixture.hpp"
31#include "../face/dummy-face.hpp"
Eric Newberry1b4ba052016-10-07 23:04:07 -070032#include "../face/dummy-transport.hpp"
Davide Pesavento97210d52016-10-14 15:45:48 +020033
Yanbiao Li73860e32015-08-19 16:30:16 -070034#include <ndn-cxx/encoding/tlv.hpp>
Davide Pesavento7a294d42017-02-21 21:46:44 -050035#include <ndn-cxx/encoding/tlv-nfd.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000036#include <ndn-cxx/mgmt/nfd/channel-status.hpp>
37#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070038
39namespace nfd {
40namespace tests {
41
Yanbiao Lidf846e52016-01-30 21:53:47 -080042class FaceManagerFixture : public NfdManagerCommonFixture
Yanbiao Li73860e32015-08-19 16:30:16 -070043{
44public:
45 FaceManagerFixture()
46 : m_faceTable(m_forwarder.getFaceTable())
Junxiao Shiea47bde2017-01-26 17:49:16 +000047 , m_faceSystem(m_faceTable)
48 , m_manager(m_faceSystem, m_dispatcher, *m_authenticator)
Yanbiao Li73860e32015-08-19 16:30:16 -070049 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000050 setTopPrefix();
Yanbiao Lidf846e52016-01-30 21:53:47 -080051 setPrivilege("faces");
Yanbiao Li73860e32015-08-19 16:30:16 -070052 }
53
54public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070055 enum AddFaceFlags {
56 REMOVE_LAST_NOTIFICATION = 1 << 0,
57 SET_SCOPE_LOCAL = 1 << 1,
58 SET_URI_TEST = 1 << 2,
59 RANDOMIZE_COUNTERS = 1 << 3
60 };
61
62 /** \brief adds a face to the FaceTable
63 * \param options bitwise OR'ed AddFaceFlags
64 */
Yanbiao Li73860e32015-08-19 16:30:16 -070065 shared_ptr<Face>
Junxiao Shicde37ad2015-12-24 01:02:05 -070066 addFace(int flags = 0)
Yanbiao Li73860e32015-08-19 16:30:16 -070067 {
Junxiao Shicde37ad2015-12-24 01:02:05 -070068 std::string uri = "dummy://";
69 ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL;
70
71 if ((flags & SET_SCOPE_LOCAL) != 0) {
72 scope = ndn::nfd::FACE_SCOPE_LOCAL;
73 }
74 if ((flags & SET_URI_TEST) != 0) {
75 uri = "test://";
76 }
77
78 auto face = make_shared<DummyFace>(uri, uri, scope);
Yanbiao Li73860e32015-08-19 16:30:16 -070079 m_faceTable.add(face);
Junxiao Shicde37ad2015-12-24 01:02:05 -070080
81 if ((flags & RANDOMIZE_COUNTERS) != 0) {
82 const face::FaceCounters& counters = face->getCounters();
83 randomizeCounter(counters.nInInterests);
84 randomizeCounter(counters.nOutInterests);
85 randomizeCounter(counters.nInData);
86 randomizeCounter(counters.nOutData);
87 randomizeCounter(counters.nInNacks);
88 randomizeCounter(counters.nOutNacks);
89 randomizeCounter(counters.nInPackets);
90 randomizeCounter(counters.nOutPackets);
91 randomizeCounter(counters.nInBytes);
92 randomizeCounter(counters.nOutBytes);
93 }
94
Yanbiao Li73860e32015-08-19 16:30:16 -070095 advanceClocks(time::milliseconds(1), 10); // wait for notification posted
Junxiao Shicde37ad2015-12-24 01:02:05 -070096 if ((flags & REMOVE_LAST_NOTIFICATION) != 0) {
Yanbiao Li73860e32015-08-19 16:30:16 -070097 m_responses.pop_back();
98 }
Junxiao Shicde37ad2015-12-24 01:02:05 -070099
Yanbiao Li73860e32015-08-19 16:30:16 -0700100 return face;
101 }
102
Junxiao Shicde37ad2015-12-24 01:02:05 -0700103private:
104 template<typename T>
105 static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type
106 randomizeCounter(const T& counter)
107 {
Davide Pesavento5f47aa62016-10-07 22:09:09 +0200108 static std::uniform_int_distribution<typename T::rep> dist;
109 const_cast<T&>(counter).set(dist(getGlobalRng()));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700110 }
111
Yanbiao Li73860e32015-08-19 16:30:16 -0700112protected:
113 FaceTable& m_faceTable;
Junxiao Shiea47bde2017-01-26 17:49:16 +0000114 FaceSystem m_faceSystem;
Yanbiao Li73860e32015-08-19 16:30:16 -0700115 FaceManager m_manager;
116};
117
Davide Pesavento97210d52016-10-14 15:45:48 +0200118BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700119BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700120
121BOOST_AUTO_TEST_SUITE(DestroyFace)
122
123BOOST_AUTO_TEST_CASE(Existing)
124{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700125 auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
Yanbiao Li73860e32015-08-19 16:30:16 -0700126
127 auto parameters = ControlParameters().setFaceId(addedFace->getId());
128 auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
129
130 receiveInterest(command);
131
132 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
133 // notification is already tested, so ignore it
134
135 BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)),
136 CheckResponseResult::OK);
137
Junxiao Shicde37ad2015-12-24 01:02:05 -0700138 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700139}
140
141BOOST_AUTO_TEST_CASE(NonExisting)
142{
143 auto parameters = ControlParameters().setFaceId(65535);
144 auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
145
146 receiveInterest(command);
147
148 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
149
150 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)),
151 CheckResponseResult::OK);
152}
153
154BOOST_AUTO_TEST_SUITE_END() // DestroyFace
155
Davide Pesavento97210d52016-10-14 15:45:48 +0200156BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700157
158BOOST_AUTO_TEST_CASE(FaceDataset)
159{
160 size_t nEntries = 303;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700161 for (size_t i = 0; i < nEntries; ++i) {
162 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700163 }
164
165 receiveInterest(makeInterest("/localhost/nfd/faces/list"));
166
167 Block content;
168 BOOST_CHECK_NO_THROW(content = concatenateResponses());
169 BOOST_CHECK_NO_THROW(content.parse());
170 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
171
Yanbiao Li73860e32015-08-19 16:30:16 -0700172 std::set<FaceId> faceIds;
173 for (size_t idx = 0; idx < nEntries; ++idx) {
174 BOOST_TEST_MESSAGE("processing element: " << idx);
175
176 ndn::nfd::FaceStatus decodedStatus;
177 BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx]));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700178 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700179 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700180 }
181
182 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700183 // TODO#3325 check dataset contents including counter values
Yanbiao Li73860e32015-08-19 16:30:16 -0700184}
185
186BOOST_AUTO_TEST_CASE(FaceQuery)
187{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700188 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
189 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
190 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700191
192 auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) {
193 return Name("/localhost/nfd/faces/query").append(filter.wireEncode());
194 };
195
196 auto querySchemeName =
197 generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy"));
198 auto queryIdName =
199 generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId()));
200 auto queryScopeName =
201 generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
202 auto invalidQueryName =
203 Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid"));
204
205 receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected
206 receiveInterest(makeInterest(queryIdName)); // face1 expected
207 receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected
208 receiveInterest(makeInterest(invalidQueryName)); // nack expected
209
210 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
211
212 Block content;
213 ndn::nfd::FaceStatus status;
214
215 content = m_responses[0].getContent();
216 BOOST_CHECK_NO_THROW(content.parse());
217 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
218 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
219 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
220 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1]));
221 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
222
223 content = m_responses[1].getContent();
224 BOOST_CHECK_NO_THROW(content.parse());
225 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
226 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
227 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
228
229 content = m_responses[2].getContent();
230 BOOST_CHECK_NO_THROW(content.parse());
231 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
232 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
233 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
234 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1]));
235 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
236
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200237 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700238 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
239 CheckResponseResult::OK);
240}
241
242class TestChannel : public Channel
243{
244public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200245 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700246 TestChannel(const std::string& uri)
247 {
248 setUri(FaceUri(uri));
249 }
250};
251
252class TestProtocolFactory : public ProtocolFactory
253{
254public:
Junxiao Shic3443042017-01-26 17:21:35 +0000255 void
256 processConfig(OptionalConfigSection configSection,
257 FaceSystem::ConfigContext& context) final
258 {
259 }
260
261 void
Eric Newberry78e32b02017-04-01 14:34:44 +0000262 createFace(const FaceUri& remoteUri,
263 const ndn::optional<FaceUri>& localUri,
Yanbiao Li73860e32015-08-19 16:30:16 -0700264 ndn::nfd::FacePersistency persistency,
Eric Newberryf40551a2016-09-05 15:41:16 -0700265 bool wantLocalFieldsEnabled,
Yanbiao Li73860e32015-08-19 16:30:16 -0700266 const FaceCreatedCallback& onCreated,
Davide Pesavento97210d52016-10-14 15:45:48 +0200267 const FaceCreationFailedCallback& onConnectFailed) final
Yanbiao Li73860e32015-08-19 16:30:16 -0700268 {
269 }
270
Junxiao Shic3443042017-01-26 17:21:35 +0000271 std::vector<shared_ptr<const Channel>>
Davide Pesavento97210d52016-10-14 15:45:48 +0200272 getChannels() const final
Yanbiao Li73860e32015-08-19 16:30:16 -0700273 {
274 return m_channels;
275 }
276
277public:
278 shared_ptr<TestChannel>
279 addChannel(const std::string& channelUri)
280 {
281 auto channel = make_shared<TestChannel>(channelUri);
282 m_channels.push_back(channel);
283 return channel;
284 }
285
286private:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200287 std::vector<shared_ptr<const Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700288};
289
290BOOST_AUTO_TEST_CASE(ChannelDataset)
291{
Junxiao Shib47247d2017-01-24 15:09:16 +0000292 m_manager.m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>();
293 auto factory = static_cast<TestProtocolFactory*>(m_manager.m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700294
295 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
296 size_t nEntries = 404;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700297 for (size_t i = 0; i < nEntries; i++) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700298 auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://");
299 addedChannels[channel->getUri().toString()] = channel;
300 }
301
302 receiveInterest(makeInterest("/localhost/nfd/faces/channels"));
303
304 Block content;
305 BOOST_CHECK_NO_THROW(content = concatenateResponses());
306 BOOST_CHECK_NO_THROW(content.parse());
307 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
308
309 for (size_t idx = 0; idx < nEntries; ++idx) {
310 BOOST_TEST_MESSAGE("processing element: " << idx);
311
312 ndn::nfd::ChannelStatus decodedStatus;
313 BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx]));
314 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
315 }
316}
317
Davide Pesavento97210d52016-10-14 15:45:48 +0200318BOOST_AUTO_TEST_SUITE_END() // Datasets
319
320BOOST_AUTO_TEST_SUITE(Notifications)
321
Eric Newberry1b4ba052016-10-07 23:04:07 -0700322BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200323{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700324 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
325 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
326 FaceId faceId = face->getId();
327
328 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200329
330 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700331 Block payload;
332 ndn::nfd::FaceEventNotification notification;
333 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
334 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
335 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
336 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
337 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
338 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
339 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
340 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
341 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
342 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
343 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
344 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
345}
Davide Pesavento97210d52016-10-14 15:45:48 +0200346
Eric Newberry1b4ba052016-10-07 23:04:07 -0700347BOOST_AUTO_TEST_CASE(FaceEventDownUp)
348{
349 auto face = addFace();
350 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
351 FaceId faceId = face->getId();
352
353 // trigger FACE_EVENT_DOWN notification
354 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200355 advanceClocks(time::milliseconds(1), 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700356 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200357
358 // check notification
359 {
360 Block payload;
361 ndn::nfd::FaceEventNotification notification;
362 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700363 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
Davide Pesavento97210d52016-10-14 15:45:48 +0200364 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
365 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
Eric Newberry1b4ba052016-10-07 23:04:07 -0700366 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200367 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700368 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
369 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200370 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
371 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
372 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700373 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200374 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700375
376 // trigger FACE_EVENT_UP notification
377 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
378 advanceClocks(time::milliseconds(1), 10);
379 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
380
381 // check notification
382 {
383 Block payload;
384 ndn::nfd::FaceEventNotification notification;
385 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
386 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
387 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
388 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
389 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
390 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
391 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
392 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
393 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
394 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
395 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
396 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
397 }
398}
399
400BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
401{
402 auto face = addFace();
403 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
404 FaceId faceId = face->getId();
405
406 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
407
408 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
409 advanceClocks(time::milliseconds(1), 10);
410
411 // check notification
412 Block payload;
413 ndn::nfd::FaceEventNotification notification;
414 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
415 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
416 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
417 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
418 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
419 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
420 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
421 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
422 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
423 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
424 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
425 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
426
427 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
428 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200429}
430
431BOOST_AUTO_TEST_SUITE_END() // Notifications
432
Yanbiao Li73860e32015-08-19 16:30:16 -0700433BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
434BOOST_AUTO_TEST_SUITE_END() // Mgmt
435
436} // namespace tests
437} // namespace nfd