blob: 6b54d745315272be114022331b272b5ea10dbd13 [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"
Yanbiao Li73860e32015-08-19 16:30:16 -070028#include "face/tcp-factory.hpp"
29#include "face/udp-factory.hpp"
30
Davide Pesavento97210d52016-10-14 15:45:48 +020031#include "nfd-manager-common-fixture.hpp"
32#include "../face/dummy-face.hpp"
Eric Newberry1b4ba052016-10-07 23:04:07 -070033#include "../face/dummy-transport.hpp"
Davide Pesavento97210d52016-10-14 15:45:48 +020034
Yanbiao Li73860e32015-08-19 16:30:16 -070035#include <ndn-cxx/encoding/tlv.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 Shi9ddf1b52016-08-22 03:58:55 +000047 , m_manager(m_faceTable, m_dispatcher, *m_authenticator)
Yanbiao Li73860e32015-08-19 16:30:16 -070048 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000049 setTopPrefix();
Yanbiao Lidf846e52016-01-30 21:53:47 -080050 setPrivilege("faces");
Yanbiao Li73860e32015-08-19 16:30:16 -070051 }
52
53public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070054 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 Li73860e32015-08-19 16:30:16 -070064 shared_ptr<Face>
Junxiao Shicde37ad2015-12-24 01:02:05 -070065 addFace(int flags = 0)
Yanbiao Li73860e32015-08-19 16:30:16 -070066 {
Junxiao Shicde37ad2015-12-24 01:02:05 -070067 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 Li73860e32015-08-19 16:30:16 -070078 m_faceTable.add(face);
Junxiao Shicde37ad2015-12-24 01:02:05 -070079
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 Li73860e32015-08-19 16:30:16 -070094 advanceClocks(time::milliseconds(1), 10); // wait for notification posted
Junxiao Shicde37ad2015-12-24 01:02:05 -070095 if ((flags & REMOVE_LAST_NOTIFICATION) != 0) {
Yanbiao Li73860e32015-08-19 16:30:16 -070096 m_responses.pop_back();
97 }
Junxiao Shicde37ad2015-12-24 01:02:05 -070098
Yanbiao Li73860e32015-08-19 16:30:16 -070099 return face;
100 }
101
Junxiao Shicde37ad2015-12-24 01:02:05 -0700102private:
103 template<typename T>
104 static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type
105 randomizeCounter(const T& counter)
106 {
Davide Pesavento5f47aa62016-10-07 22:09:09 +0200107 static std::uniform_int_distribution<typename T::rep> dist;
108 const_cast<T&>(counter).set(dist(getGlobalRng()));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700109 }
110
Yanbiao Li73860e32015-08-19 16:30:16 -0700111protected:
112 FaceTable& m_faceTable;
113 FaceManager m_manager;
114};
115
Davide Pesavento97210d52016-10-14 15:45:48 +0200116BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700117BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700118
119BOOST_AUTO_TEST_SUITE(DestroyFace)
120
121BOOST_AUTO_TEST_CASE(Existing)
122{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700123 auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
Yanbiao Li73860e32015-08-19 16:30:16 -0700124
125 auto parameters = ControlParameters().setFaceId(addedFace->getId());
126 auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
127
128 receiveInterest(command);
129
130 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
131 // notification is already tested, so ignore it
132
133 BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)),
134 CheckResponseResult::OK);
135
Junxiao Shicde37ad2015-12-24 01:02:05 -0700136 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700137}
138
139BOOST_AUTO_TEST_CASE(NonExisting)
140{
141 auto parameters = ControlParameters().setFaceId(65535);
142 auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
143
144 receiveInterest(command);
145
146 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
147
148 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "OK", parameters)),
149 CheckResponseResult::OK);
150}
151
152BOOST_AUTO_TEST_SUITE_END() // DestroyFace
153
Davide Pesavento97210d52016-10-14 15:45:48 +0200154BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700155
156BOOST_AUTO_TEST_CASE(FaceDataset)
157{
158 size_t nEntries = 303;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700159 for (size_t i = 0; i < nEntries; ++i) {
160 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700161 }
162
163 receiveInterest(makeInterest("/localhost/nfd/faces/list"));
164
165 Block content;
166 BOOST_CHECK_NO_THROW(content = concatenateResponses());
167 BOOST_CHECK_NO_THROW(content.parse());
168 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
169
Yanbiao Li73860e32015-08-19 16:30:16 -0700170 std::set<FaceId> faceIds;
171 for (size_t idx = 0; idx < nEntries; ++idx) {
172 BOOST_TEST_MESSAGE("processing element: " << idx);
173
174 ndn::nfd::FaceStatus decodedStatus;
175 BOOST_REQUIRE_NO_THROW(decodedStatus.wireDecode(content.elements()[idx]));
Junxiao Shida93f1f2015-11-11 06:13:16 -0700176 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700177 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700178 }
179
180 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700181 // TODO#3325 check dataset contents including counter values
Yanbiao Li73860e32015-08-19 16:30:16 -0700182}
183
184BOOST_AUTO_TEST_CASE(FaceQuery)
185{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700186 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
187 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
188 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700189
190 auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) {
191 return Name("/localhost/nfd/faces/query").append(filter.wireEncode());
192 };
193
194 auto querySchemeName =
195 generateQueryName(ndn::nfd::FaceQueryFilter().setUriScheme("dummy"));
196 auto queryIdName =
197 generateQueryName(ndn::nfd::FaceQueryFilter().setFaceId(face1->getId()));
198 auto queryScopeName =
199 generateQueryName(ndn::nfd::FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
200 auto invalidQueryName =
201 Name("/localhost/nfd/faces/query").append(ndn::makeStringBlock(tlv::Content, "invalid"));
202
203 receiveInterest(makeInterest(querySchemeName)); // face1 and face2 expected
204 receiveInterest(makeInterest(queryIdName)); // face1 expected
205 receiveInterest(makeInterest(queryScopeName)); // face1 and face3 expected
206 receiveInterest(makeInterest(invalidQueryName)); // nack expected
207
208 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
209
210 Block content;
211 ndn::nfd::FaceStatus status;
212
213 content = m_responses[0].getContent();
214 BOOST_CHECK_NO_THROW(content.parse());
215 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
216 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
217 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
218 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1]));
219 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
220
221 content = m_responses[1].getContent();
222 BOOST_CHECK_NO_THROW(content.parse());
223 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
224 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
225 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
226
227 content = m_responses[2].getContent();
228 BOOST_CHECK_NO_THROW(content.parse());
229 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
230 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[0]));
231 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
232 BOOST_CHECK_NO_THROW(status.wireDecode(content.elements()[1]));
233 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
234
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200235 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700236 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
237 CheckResponseResult::OK);
238}
239
240class TestChannel : public Channel
241{
242public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200243 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700244 TestChannel(const std::string& uri)
245 {
246 setUri(FaceUri(uri));
247 }
248};
249
250class TestProtocolFactory : public ProtocolFactory
251{
252public:
Junxiao Shic3443042017-01-26 17:21:35 +0000253 void
254 processConfig(OptionalConfigSection configSection,
255 FaceSystem::ConfigContext& context) final
256 {
257 }
258
259 void
Yanbiao Li73860e32015-08-19 16:30:16 -0700260 createFace(const FaceUri& uri,
261 ndn::nfd::FacePersistency persistency,
Eric Newberryf40551a2016-09-05 15:41:16 -0700262 bool wantLocalFieldsEnabled,
Yanbiao Li73860e32015-08-19 16:30:16 -0700263 const FaceCreatedCallback& onCreated,
Davide Pesavento97210d52016-10-14 15:45:48 +0200264 const FaceCreationFailedCallback& onConnectFailed) final
Yanbiao Li73860e32015-08-19 16:30:16 -0700265 {
266 }
267
Junxiao Shic3443042017-01-26 17:21:35 +0000268 std::vector<shared_ptr<const Channel>>
Davide Pesavento97210d52016-10-14 15:45:48 +0200269 getChannels() const final
Yanbiao Li73860e32015-08-19 16:30:16 -0700270 {
271 return m_channels;
272 }
273
274public:
275 shared_ptr<TestChannel>
276 addChannel(const std::string& channelUri)
277 {
278 auto channel = make_shared<TestChannel>(channelUri);
279 m_channels.push_back(channel);
280 return channel;
281 }
282
283private:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200284 std::vector<shared_ptr<const Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700285};
286
287BOOST_AUTO_TEST_CASE(ChannelDataset)
288{
Junxiao Shib47247d2017-01-24 15:09:16 +0000289 m_manager.m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>();
290 auto factory = static_cast<TestProtocolFactory*>(m_manager.m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700291
292 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
293 size_t nEntries = 404;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700294 for (size_t i = 0; i < nEntries; i++) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700295 auto channel = factory->addChannel("test" + boost::lexical_cast<std::string>(i) + "://");
296 addedChannels[channel->getUri().toString()] = channel;
297 }
298
299 receiveInterest(makeInterest("/localhost/nfd/faces/channels"));
300
301 Block content;
302 BOOST_CHECK_NO_THROW(content = concatenateResponses());
303 BOOST_CHECK_NO_THROW(content.parse());
304 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
305
306 for (size_t idx = 0; idx < nEntries; ++idx) {
307 BOOST_TEST_MESSAGE("processing element: " << idx);
308
309 ndn::nfd::ChannelStatus decodedStatus;
310 BOOST_CHECK_NO_THROW(decodedStatus.wireDecode(content.elements()[idx]));
311 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
312 }
313}
314
Davide Pesavento97210d52016-10-14 15:45:48 +0200315BOOST_AUTO_TEST_SUITE_END() // Datasets
316
317BOOST_AUTO_TEST_SUITE(Notifications)
318
Eric Newberry1b4ba052016-10-07 23:04:07 -0700319BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200320{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700321 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
322 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
323 FaceId faceId = face->getId();
324
325 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200326
327 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700328 Block payload;
329 ndn::nfd::FaceEventNotification notification;
330 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
331 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
332 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
333 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
334 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
335 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
336 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
337 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
338 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
339 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
340 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
341 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
342}
Davide Pesavento97210d52016-10-14 15:45:48 +0200343
Eric Newberry1b4ba052016-10-07 23:04:07 -0700344BOOST_AUTO_TEST_CASE(FaceEventDownUp)
345{
346 auto face = addFace();
347 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
348 FaceId faceId = face->getId();
349
350 // trigger FACE_EVENT_DOWN notification
351 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200352 advanceClocks(time::milliseconds(1), 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700353 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200354
355 // check notification
356 {
357 Block payload;
358 ndn::nfd::FaceEventNotification notification;
359 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700360 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
Davide Pesavento97210d52016-10-14 15:45:48 +0200361 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
362 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
Eric Newberry1b4ba052016-10-07 23:04:07 -0700363 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200364 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700365 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
366 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200367 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
368 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
369 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700370 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200371 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700372
373 // trigger FACE_EVENT_UP notification
374 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
375 advanceClocks(time::milliseconds(1), 10);
376 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
377
378 // check notification
379 {
380 Block payload;
381 ndn::nfd::FaceEventNotification notification;
382 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
383 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
384 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
385 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
386 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
387 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
388 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
389 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
390 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
391 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
392 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
393 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
394 }
395}
396
397BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
398{
399 auto face = addFace();
400 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
401 FaceId faceId = face->getId();
402
403 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
404
405 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
406 advanceClocks(time::milliseconds(1), 10);
407
408 // check notification
409 Block payload;
410 ndn::nfd::FaceEventNotification notification;
411 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
412 BOOST_CHECK_NO_THROW(payload = m_responses.back().getContent().blockFromValue());
413 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
414 BOOST_CHECK_NO_THROW(notification.wireDecode(payload));
415 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
416 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
417 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
418 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
419 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
420 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
421 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
422 BOOST_CHECK_EQUAL(notification.getFlags(), 0x0);
423
424 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
425 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200426}
427
428BOOST_AUTO_TEST_SUITE_END() // Notifications
429
Yanbiao Li73860e32015-08-19 16:30:16 -0700430BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
431BOOST_AUTO_TEST_SUITE_END() // Mgmt
432
433} // namespace tests
434} // namespace nfd