blob: 828325f74e5a6ffd482b11a9689be7e0358c3bd0 [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/*
Davide Pesaventoa599d2a2022-02-16 18:52:43 -05003 * Copyright (c) 2014-2022, 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"
Junxiao Shiea47bde2017-01-26 17:49:16 +000027#include "face/protocol-factory.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070028
Davide Pesavento78ddcab2019-02-28 22:00:03 -050029#include "manager-common-fixture.hpp"
30#include "tests/daemon/face/dummy-face.hpp"
31#include "tests/daemon/face/dummy-transport.hpp"
Davide Pesavento97210d52016-10-14 15:45:48 +020032
Yanbiao Li73860e32015-08-19 16:30:16 -070033#include <ndn-cxx/encoding/tlv.hpp>
Davide Pesavento7a294d42017-02-21 21:46:44 -050034#include <ndn-cxx/encoding/tlv-nfd.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000035#include <ndn-cxx/mgmt/nfd/channel-status.hpp>
Davide Pesavento28181322018-11-08 16:44:50 -050036#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
37#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
38#include <ndn-cxx/mgmt/nfd/face-status.hpp>
Junxiao Shi0ba6d642017-07-17 00:53:22 +000039#include <ndn-cxx/net/network-monitor-stub.hpp>
Davide Pesaventob8bd5ee2019-02-03 22:53:40 -050040#include <ndn-cxx/util/random.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070041
42namespace nfd {
43namespace tests {
44
Davide Pesavento78ddcab2019-02-28 22:00:03 -050045class FaceManagerFixture : public ManagerFixtureWithAuthenticator
Yanbiao Li73860e32015-08-19 16:30:16 -070046{
47public:
48 FaceManagerFixture()
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040049 : m_faceSystem(m_faceTable, make_shared<ndn::net::NetworkMonitorStub>(0))
Junxiao Shiea47bde2017-01-26 17:49:16 +000050 , m_manager(m_faceSystem, m_dispatcher, *m_authenticator)
Yanbiao Li73860e32015-08-19 16:30:16 -070051 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000052 setTopPrefix();
Yanbiao Lidf846e52016-01-30 21:53:47 -080053 setPrivilege("faces");
Yanbiao Li73860e32015-08-19 16:30:16 -070054 }
55
56public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070057 enum AddFaceFlags {
58 REMOVE_LAST_NOTIFICATION = 1 << 0,
59 SET_SCOPE_LOCAL = 1 << 1,
60 SET_URI_TEST = 1 << 2,
Davide Pesavento6837d4f2017-07-15 13:01:03 -040061 RANDOMIZE_COUNTERS = 1 << 3,
Junxiao Shicde37ad2015-12-24 01:02:05 -070062 };
63
64 /** \brief adds a face to the FaceTable
65 * \param options bitwise OR'ed AddFaceFlags
66 */
Yanbiao Li73860e32015-08-19 16:30:16 -070067 shared_ptr<Face>
Davide Pesavento6837d4f2017-07-15 13:01:03 -040068 addFace(unsigned int flags = 0)
Yanbiao Li73860e32015-08-19 16:30:16 -070069 {
Junxiao Shicde37ad2015-12-24 01:02:05 -070070 std::string uri = "dummy://";
71 ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL;
72
Davide Pesavento28181322018-11-08 16:44:50 -050073 if (flags & SET_SCOPE_LOCAL) {
Junxiao Shicde37ad2015-12-24 01:02:05 -070074 scope = ndn::nfd::FACE_SCOPE_LOCAL;
75 }
Davide Pesavento28181322018-11-08 16:44:50 -050076 if (flags & SET_URI_TEST) {
Junxiao Shicde37ad2015-12-24 01:02:05 -070077 uri = "test://";
78 }
79
80 auto face = make_shared<DummyFace>(uri, uri, scope);
Yanbiao Li73860e32015-08-19 16:30:16 -070081 m_faceTable.add(face);
Junxiao Shicde37ad2015-12-24 01:02:05 -070082
Davide Pesavento28181322018-11-08 16:44:50 -050083 if (flags & RANDOMIZE_COUNTERS) {
84 const auto& counters = face->getCounters();
Junxiao Shicde37ad2015-12-24 01:02:05 -070085 randomizeCounter(counters.nInInterests);
86 randomizeCounter(counters.nOutInterests);
87 randomizeCounter(counters.nInData);
88 randomizeCounter(counters.nOutData);
89 randomizeCounter(counters.nInNacks);
90 randomizeCounter(counters.nOutNacks);
91 randomizeCounter(counters.nInPackets);
92 randomizeCounter(counters.nOutPackets);
93 randomizeCounter(counters.nInBytes);
94 randomizeCounter(counters.nOutBytes);
95 }
96
Davide Pesavento28181322018-11-08 16:44:50 -050097 advanceClocks(1_ms, 10); // wait for notification posted
98 if (flags & REMOVE_LAST_NOTIFICATION) {
Davide Pesaventob93fb6c2020-04-12 14:10:45 -040099 BOOST_REQUIRE(!m_responses.empty());
Yanbiao Li73860e32015-08-19 16:30:16 -0700100 m_responses.pop_back();
101 }
Junxiao Shicde37ad2015-12-24 01:02:05 -0700102
Yanbiao Li73860e32015-08-19 16:30:16 -0700103 return face;
104 }
105
Junxiao Shicde37ad2015-12-24 01:02:05 -0700106private:
107 template<typename T>
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400108 static void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700109 randomizeCounter(const T& counter)
110 {
Davide Pesavento5f47aa62016-10-07 22:09:09 +0200111 static std::uniform_int_distribution<typename T::rep> dist;
Davide Pesaventob8bd5ee2019-02-03 22:53:40 -0500112 const_cast<T&>(counter).set(dist(ndn::random::getRandomNumberEngine()));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700113 }
114
Yanbiao Li73860e32015-08-19 16:30:16 -0700115protected:
Junxiao Shiea47bde2017-01-26 17:49:16 +0000116 FaceSystem m_faceSystem;
Yanbiao Li73860e32015-08-19 16:30:16 -0700117 FaceManager m_manager;
118};
119
Davide Pesavento97210d52016-10-14 15:45:48 +0200120BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700121BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700122
123BOOST_AUTO_TEST_SUITE(DestroyFace)
124
125BOOST_AUTO_TEST_CASE(Existing)
126{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
Yanbiao Li73860e32015-08-19 16:30:16 -0700128
129 auto parameters = ControlParameters().setFaceId(addedFace->getId());
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000130 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
131 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700132
133 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
134 // notification is already tested, so ignore it
135
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000136 BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700137 CheckResponseResult::OK);
138
Junxiao Shicde37ad2015-12-24 01:02:05 -0700139 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700140}
141
142BOOST_AUTO_TEST_CASE(NonExisting)
143{
144 auto parameters = ControlParameters().setFaceId(65535);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000145 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
146 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700147
148 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000149 BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700150 CheckResponseResult::OK);
151}
152
153BOOST_AUTO_TEST_SUITE_END() // DestroyFace
154
Davide Pesavento97210d52016-10-14 15:45:48 +0200155BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700156
157BOOST_AUTO_TEST_CASE(FaceDataset)
158{
Davide Pesavento28181322018-11-08 16:44:50 -0500159 const size_t nEntries = 32;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700160 for (size_t i = 0; i < nEntries; ++i) {
161 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700162 }
163
Davide Pesavento28181322018-11-08 16:44:50 -0500164 receiveInterest(Interest("/localhost/nfd/faces/list").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700165
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400166 Block content = concatenateResponses();
167 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700168 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) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400172 ndn::nfd::FaceStatus decodedStatus(content.elements()[idx]);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700173 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700174 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700175 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700176 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Davide Pesavento28181322018-11-08 16:44:50 -0500177
178 ndn::nfd::FaceStatus status(content.elements().front());
179 const Face* face = m_faceTable.get(status.getFaceId());
180 BOOST_REQUIRE(face != nullptr);
181
182 // check face properties
183 BOOST_CHECK_EQUAL(status.getRemoteUri(), face->getRemoteUri().toString());
184 BOOST_CHECK_EQUAL(status.getLocalUri(), face->getLocalUri().toString());
185 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(),
186 face->getExpirationTime() != time::steady_clock::time_point::max());
187 BOOST_CHECK_EQUAL(status.getFaceScope(), face->getScope());
188 BOOST_CHECK_EQUAL(status.getFacePersistency(), face->getPersistency());
189 BOOST_CHECK_EQUAL(status.getLinkType(), face->getLinkType());
190
191 // check link service properties
192 BOOST_CHECK_EQUAL(status.hasBaseCongestionMarkingInterval(), false);
193 BOOST_CHECK_EQUAL(status.hasDefaultCongestionThreshold(), false);
194 BOOST_CHECK_EQUAL(status.getFlags(), 0);
195
196 // check transport properties
197 BOOST_CHECK_EQUAL(status.hasMtu(), true);
198 BOOST_CHECK_EQUAL(status.getMtu(), ndn::MAX_NDN_PACKET_SIZE);
199
200 // check counters
201 BOOST_CHECK_EQUAL(status.getNInInterests(), face->getCounters().nInInterests);
202 BOOST_CHECK_EQUAL(status.getNInData(), face->getCounters().nInData);
203 BOOST_CHECK_EQUAL(status.getNInNacks(), face->getCounters().nInNacks);
204 BOOST_CHECK_EQUAL(status.getNOutInterests(), face->getCounters().nOutInterests);
205 BOOST_CHECK_EQUAL(status.getNOutData(), face->getCounters().nOutData);
206 BOOST_CHECK_EQUAL(status.getNOutNacks(), face->getCounters().nOutNacks);
207 BOOST_CHECK_EQUAL(status.getNInBytes(), face->getCounters().nInBytes);
208 BOOST_CHECK_EQUAL(status.getNOutBytes(), face->getCounters().nOutBytes);
Yanbiao Li73860e32015-08-19 16:30:16 -0700209}
210
211BOOST_AUTO_TEST_CASE(FaceQuery)
212{
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400213 using ndn::nfd::FaceQueryFilter;
214
Junxiao Shicde37ad2015-12-24 01:02:05 -0700215 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
216 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
217 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700218
Davide Pesaventodeb54272022-03-11 18:51:05 -0500219 auto generateQuery = [] (const auto& filter) {
220 return Interest(Name("/localhost/nfd/faces/query").append(tlv::GenericNameComponent, filter.wireEncode()))
Davide Pesavento28181322018-11-08 16:44:50 -0500221 .setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700222 };
223
Davide Pesavento28181322018-11-08 16:44:50 -0500224 auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy"));
225 auto idQuery = generateQuery(FaceQueryFilter().setFaceId(face1->getId()));
226 auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400227 auto invalidQueryName = Name("/localhost/nfd/faces/query")
Davide Pesaventodeb54272022-03-11 18:51:05 -0500228 .append(tlv::GenericNameComponent, ndn::makeStringBlock(tlv::Content, "invalid"));
Davide Pesavento28181322018-11-08 16:44:50 -0500229 auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700230
Davide Pesavento28181322018-11-08 16:44:50 -0500231 receiveInterest(schemeQuery); // face1 and face2 expected
232 receiveInterest(idQuery); // face1 expected
233 receiveInterest(scopeQuery); // face1 and face3 expected
234 receiveInterest(invalidQuery); // nack expected
Yanbiao Li73860e32015-08-19 16:30:16 -0700235
236 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
237
238 Block content;
239 ndn::nfd::FaceStatus status;
240
241 content = m_responses[0].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400242 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700243 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400244 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700245 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400246 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700247 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
248
249 content = m_responses[1].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400250 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700251 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400252 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700253 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
254
255 content = m_responses[2].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400256 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700257 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400258 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700259 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400260 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700261 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
262
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200263 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700264 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
265 CheckResponseResult::OK);
266}
267
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400268class TestChannel : public face::Channel
Yanbiao Li73860e32015-08-19 16:30:16 -0700269{
270public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200271 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700272 TestChannel(const std::string& uri)
273 {
274 setUri(FaceUri(uri));
275 }
Davide Pesaventoc19408d2017-04-08 00:42:55 -0400276
277 bool
278 isListening() const final
279 {
280 return false;
281 }
282
283 size_t
284 size() const final
285 {
286 return 0;
287 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700288};
289
Davide Pesaventoe5eebad2017-04-06 20:23:26 -0400290class TestProtocolFactory : public face::ProtocolFactory
Yanbiao Li73860e32015-08-19 16:30:16 -0700291{
292public:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500293 using ProtocolFactory::ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000294
Yanbiao Li73860e32015-08-19 16:30:16 -0700295 shared_ptr<TestChannel>
296 addChannel(const std::string& channelUri)
297 {
298 auto channel = make_shared<TestChannel>(channelUri);
299 m_channels.push_back(channel);
300 return channel;
301 }
302
303private:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500304 std::vector<shared_ptr<const face::Channel>>
305 doGetChannels() const final
306 {
307 return m_channels;
308 }
309
310private:
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400311 std::vector<shared_ptr<const face::Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700312};
313
314BOOST_AUTO_TEST_CASE(ChannelDataset)
315{
Davide Pesavento28181322018-11-08 16:44:50 -0500316 m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>(m_faceSystem.makePFCtorParams());
Davide Pesaventob5eee202017-09-21 23:59:22 -0400317 auto factory = static_cast<TestProtocolFactory*>(m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700318
Davide Pesavento28181322018-11-08 16:44:50 -0500319 const size_t nEntries = 42;
Yanbiao Li73860e32015-08-19 16:30:16 -0700320 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700321 for (size_t i = 0; i < nEntries; i++) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400322 auto channel = factory->addChannel("test" + to_string(i) + "://");
Yanbiao Li73860e32015-08-19 16:30:16 -0700323 addedChannels[channel->getUri().toString()] = channel;
324 }
325
Davide Pesavento28181322018-11-08 16:44:50 -0500326 receiveInterest(Interest("/localhost/nfd/faces/channels").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700327
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400328 Block content = concatenateResponses();
329 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700330 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
331
332 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400333 ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700334 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
335 }
336}
337
Davide Pesavento97210d52016-10-14 15:45:48 +0200338BOOST_AUTO_TEST_SUITE_END() // Datasets
339
340BOOST_AUTO_TEST_SUITE(Notifications)
341
Eric Newberry1b4ba052016-10-07 23:04:07 -0700342BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200343{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700344 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
345 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
346 FaceId faceId = face->getId();
347
348 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200349
350 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700351 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400352 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700353 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400354 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700355 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
356 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
357 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
358 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
359 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
360 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
361 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400362 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700363}
Davide Pesavento97210d52016-10-14 15:45:48 +0200364
Eric Newberry1b4ba052016-10-07 23:04:07 -0700365BOOST_AUTO_TEST_CASE(FaceEventDownUp)
366{
367 auto face = addFace();
368 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
369 FaceId faceId = face->getId();
370
371 // trigger FACE_EVENT_DOWN notification
372 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento28181322018-11-08 16:44:50 -0500373 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700374 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200375
376 // check notification
377 {
Davide Pesavento97210d52016-10-14 15:45:48 +0200378 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400379 Block payload = m_responses.back().getContent().blockFromValue();
Davide Pesavento97210d52016-10-14 15:45:48 +0200380 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400381 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700382 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200383 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700384 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
385 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200386 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
387 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
388 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400389 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200390 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700391
392 // trigger FACE_EVENT_UP notification
393 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
Davide Pesavento28181322018-11-08 16:44:50 -0500394 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700395 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
396
397 // check notification
398 {
Eric Newberry1b4ba052016-10-07 23:04:07 -0700399 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400400 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700401 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400402 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700403 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
404 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
405 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
406 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
407 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
408 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
409 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400410 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700411 }
412}
413
414BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
415{
416 auto face = addFace();
417 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
418 FaceId faceId = face->getId();
419
420 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
421
422 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
Davide Pesavento28181322018-11-08 16:44:50 -0500423 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700424
425 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700426 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400427 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700428 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400429 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700430 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
431 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
432 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
433 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
434 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
435 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
436 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400437 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700438
439 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
440 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200441}
442
443BOOST_AUTO_TEST_SUITE_END() // Notifications
444
Yanbiao Li73860e32015-08-19 16:30:16 -0700445BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
446BOOST_AUTO_TEST_SUITE_END() // Mgmt
447
448} // namespace tests
449} // namespace nfd