blob: 03bdd78e2f7b2542acbce5b66908e46de463df79 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0ba6d642017-07-17 00:53:22 +00002/*
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>
Junxiao Shi0ba6d642017-07-17 00:53:22 +000037#include <ndn-cxx/net/network-monitor-stub.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,
Davide Pesavento6837d4f2017-07-15 13:01:03 -040059 RANDOMIZE_COUNTERS = 1 << 3,
Junxiao Shicde37ad2015-12-24 01:02:05 -070060 };
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>
Davide Pesavento6837d4f2017-07-15 13:01:03 -040066 addFace(unsigned 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>
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400105 static void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700106 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());
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000128 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
129 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700130
131 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
132 // notification is already tested, so ignore it
133
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000134 BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700135 CheckResponseResult::OK);
136
Junxiao Shicde37ad2015-12-24 01:02:05 -0700137 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700138}
139
140BOOST_AUTO_TEST_CASE(NonExisting)
141{
142 auto parameters = ControlParameters().setFaceId(65535);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000143 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
144 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700145
146 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000147 BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700148 CheckResponseResult::OK);
149}
150
151BOOST_AUTO_TEST_SUITE_END() // DestroyFace
152
Davide Pesavento97210d52016-10-14 15:45:48 +0200153BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700154
155BOOST_AUTO_TEST_CASE(FaceDataset)
156{
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400157 const size_t nEntries = 303;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700158 for (size_t i = 0; i < nEntries; ++i) {
159 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700160 }
161
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000162 receiveInterest(Interest("/localhost/nfd/faces/list"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700163
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400164 Block content = concatenateResponses();
165 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700166 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
167
Yanbiao Li73860e32015-08-19 16:30:16 -0700168 std::set<FaceId> faceIds;
169 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400170 ndn::nfd::FaceStatus decodedStatus(content.elements()[idx]);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700171 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700172 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700173 }
174
175 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700176 // TODO#3325 check dataset contents including counter values
Yanbiao Li73860e32015-08-19 16:30:16 -0700177}
178
179BOOST_AUTO_TEST_CASE(FaceQuery)
180{
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400181 using ndn::nfd::FaceQueryFilter;
182
Junxiao Shicde37ad2015-12-24 01:02:05 -0700183 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
184 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
185 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700186
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400187 auto generateQueryName = [] (const FaceQueryFilter& filter) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700188 return Name("/localhost/nfd/faces/query").append(filter.wireEncode());
189 };
190
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400191 auto querySchemeName = generateQueryName(FaceQueryFilter().setUriScheme("dummy"));
192 auto queryIdName = generateQueryName(FaceQueryFilter().setFaceId(face1->getId()));
193 auto queryScopeName = generateQueryName(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
194 auto invalidQueryName = Name("/localhost/nfd/faces/query")
195 .append(ndn::makeStringBlock(tlv::Content, "invalid"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700196
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000197 receiveInterest(Interest(querySchemeName)); // face1 and face2 expected
198 receiveInterest(Interest(queryIdName)); // face1 expected
199 receiveInterest(Interest(queryScopeName)); // face1 and face3 expected
200 receiveInterest(Interest(invalidQueryName)); // nack expected
Yanbiao Li73860e32015-08-19 16:30:16 -0700201
202 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
203
204 Block content;
205 ndn::nfd::FaceStatus status;
206
207 content = m_responses[0].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400208 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700209 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400210 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700211 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400212 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700213 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
214
215 content = m_responses[1].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400216 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700217 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400218 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700219 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
220
221 content = m_responses[2].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400222 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700223 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400224 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700225 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400226 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700227 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
228
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200229 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700230 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
231 CheckResponseResult::OK);
232}
233
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400234class TestChannel : public face::Channel
Yanbiao Li73860e32015-08-19 16:30:16 -0700235{
236public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200237 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700238 TestChannel(const std::string& uri)
239 {
240 setUri(FaceUri(uri));
241 }
Davide Pesaventoc19408d2017-04-08 00:42:55 -0400242
243 bool
244 isListening() const final
245 {
246 return false;
247 }
248
249 size_t
250 size() const final
251 {
252 return 0;
253 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700254};
255
Davide Pesaventoe5eebad2017-04-06 20:23:26 -0400256class TestProtocolFactory : public face::ProtocolFactory
Yanbiao Li73860e32015-08-19 16:30:16 -0700257{
258public:
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000259 TestProtocolFactory(const CtorParams& params)
260 : ProtocolFactory(params)
261 {
262 }
263
Junxiao Shic3443042017-01-26 17:21:35 +0000264 void
265 processConfig(OptionalConfigSection configSection,
266 FaceSystem::ConfigContext& context) final
267 {
268 }
269
270 void
Eric Newberry944f38b2017-07-20 20:54:22 -0400271 createFace(const CreateFaceParams& params,
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400272 const face::FaceCreatedCallback& onCreated,
273 const face::FaceCreationFailedCallback& onConnectFailed) final
Yanbiao Li73860e32015-08-19 16:30:16 -0700274 {
275 }
276
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400277 std::vector<shared_ptr<const face::Channel>>
Davide Pesavento97210d52016-10-14 15:45:48 +0200278 getChannels() const final
Yanbiao Li73860e32015-08-19 16:30:16 -0700279 {
280 return m_channels;
281 }
282
283public:
284 shared_ptr<TestChannel>
285 addChannel(const std::string& channelUri)
286 {
287 auto channel = make_shared<TestChannel>(channelUri);
288 m_channels.push_back(channel);
289 return channel;
290 }
291
292private:
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400293 std::vector<shared_ptr<const face::Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700294};
295
296BOOST_AUTO_TEST_CASE(ChannelDataset)
297{
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000298 m_manager.m_faceSystem.m_factories["test"] =
299 make_unique<TestProtocolFactory>(m_faceSystem.makePFCtorParams());
Junxiao Shib47247d2017-01-24 15:09:16 +0000300 auto factory = static_cast<TestProtocolFactory*>(m_manager.m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700301
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400302 const size_t nEntries = 404;
Yanbiao Li73860e32015-08-19 16:30:16 -0700303 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700304 for (size_t i = 0; i < nEntries; i++) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400305 auto channel = factory->addChannel("test" + to_string(i) + "://");
Yanbiao Li73860e32015-08-19 16:30:16 -0700306 addedChannels[channel->getUri().toString()] = channel;
307 }
308
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000309 receiveInterest(Interest("/localhost/nfd/faces/channels"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700310
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400311 Block content = concatenateResponses();
312 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700313 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
314
315 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400316 ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700317 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
318 }
319}
320
Davide Pesavento97210d52016-10-14 15:45:48 +0200321BOOST_AUTO_TEST_SUITE_END() // Datasets
322
323BOOST_AUTO_TEST_SUITE(Notifications)
324
Eric Newberry1b4ba052016-10-07 23:04:07 -0700325BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200326{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700327 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
328 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
329 FaceId faceId = face->getId();
330
331 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200332
333 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700334 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400335 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700336 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400337 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700338 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
339 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
340 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
341 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
342 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
343 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
344 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400345 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700346}
Davide Pesavento97210d52016-10-14 15:45:48 +0200347
Eric Newberry1b4ba052016-10-07 23:04:07 -0700348BOOST_AUTO_TEST_CASE(FaceEventDownUp)
349{
350 auto face = addFace();
351 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
352 FaceId faceId = face->getId();
353
354 // trigger FACE_EVENT_DOWN notification
355 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200356 advanceClocks(time::milliseconds(1), 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700357 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200358
359 // check notification
360 {
Davide Pesavento97210d52016-10-14 15:45:48 +0200361 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400362 Block payload = m_responses.back().getContent().blockFromValue();
Davide Pesavento97210d52016-10-14 15:45:48 +0200363 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400364 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700365 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200366 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700367 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
368 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200369 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
370 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
371 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400372 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200373 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700374
375 // trigger FACE_EVENT_UP notification
376 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
377 advanceClocks(time::milliseconds(1), 10);
378 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
379
380 // check notification
381 {
Eric Newberry1b4ba052016-10-07 23:04:07 -0700382 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400383 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700384 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400385 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700386 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);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400393 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700394 }
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
Eric Newberry1b4ba052016-10-07 23:04:07 -0700409 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400410 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700411 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400412 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700413 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
414 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
415 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
416 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
417 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
418 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
419 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400420 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700421
422 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
423 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200424}
425
426BOOST_AUTO_TEST_SUITE_END() // Notifications
427
Yanbiao Li73860e32015-08-19 16:30:16 -0700428BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
429BOOST_AUTO_TEST_SUITE_END() // Mgmt
430
431} // namespace tests
432} // namespace nfd