blob: 0e43944ece9b02aabae7dfc91e9801fa35a4c113 [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 Pesavento28181322018-11-08 16:44:50 -0500219 auto generateQuery = [] (const FaceQueryFilter& filter) {
Davide Pesaventoa599d2a2022-02-16 18:52:43 -0500220 return Interest(Name("/localhost/nfd/faces/query")
221 .append(filter.wireEncode().begin(), filter.wireEncode().end()))
Davide Pesavento28181322018-11-08 16:44:50 -0500222 .setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700223 };
224
Davide Pesavento28181322018-11-08 16:44:50 -0500225 auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy"));
226 auto idQuery = generateQuery(FaceQueryFilter().setFaceId(face1->getId()));
227 auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
Davide Pesaventoa599d2a2022-02-16 18:52:43 -0500228 auto invalidContent = ndn::makeStringBlock(tlv::Content, "invalid");
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400229 auto invalidQueryName = Name("/localhost/nfd/faces/query")
Davide Pesaventoa599d2a2022-02-16 18:52:43 -0500230 .append(invalidContent.begin(), invalidContent.end());
Davide Pesavento28181322018-11-08 16:44:50 -0500231 auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700232
Davide Pesavento28181322018-11-08 16:44:50 -0500233 receiveInterest(schemeQuery); // face1 and face2 expected
234 receiveInterest(idQuery); // face1 expected
235 receiveInterest(scopeQuery); // face1 and face3 expected
236 receiveInterest(invalidQuery); // nack expected
Yanbiao Li73860e32015-08-19 16:30:16 -0700237
238 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
239
240 Block content;
241 ndn::nfd::FaceStatus status;
242
243 content = m_responses[0].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400244 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700245 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400246 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700247 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400248 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700249 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
250
251 content = m_responses[1].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400252 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700253 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400254 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700255 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
256
257 content = m_responses[2].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400258 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700259 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400260 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700261 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400262 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700263 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
264
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200265 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700266 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
267 CheckResponseResult::OK);
268}
269
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400270class TestChannel : public face::Channel
Yanbiao Li73860e32015-08-19 16:30:16 -0700271{
272public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200273 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700274 TestChannel(const std::string& uri)
275 {
276 setUri(FaceUri(uri));
277 }
Davide Pesaventoc19408d2017-04-08 00:42:55 -0400278
279 bool
280 isListening() const final
281 {
282 return false;
283 }
284
285 size_t
286 size() const final
287 {
288 return 0;
289 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700290};
291
Davide Pesaventoe5eebad2017-04-06 20:23:26 -0400292class TestProtocolFactory : public face::ProtocolFactory
Yanbiao Li73860e32015-08-19 16:30:16 -0700293{
294public:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500295 using ProtocolFactory::ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000296
Yanbiao Li73860e32015-08-19 16:30:16 -0700297 shared_ptr<TestChannel>
298 addChannel(const std::string& channelUri)
299 {
300 auto channel = make_shared<TestChannel>(channelUri);
301 m_channels.push_back(channel);
302 return channel;
303 }
304
305private:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500306 std::vector<shared_ptr<const face::Channel>>
307 doGetChannels() const final
308 {
309 return m_channels;
310 }
311
312private:
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400313 std::vector<shared_ptr<const face::Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700314};
315
316BOOST_AUTO_TEST_CASE(ChannelDataset)
317{
Davide Pesavento28181322018-11-08 16:44:50 -0500318 m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>(m_faceSystem.makePFCtorParams());
Davide Pesaventob5eee202017-09-21 23:59:22 -0400319 auto factory = static_cast<TestProtocolFactory*>(m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700320
Davide Pesavento28181322018-11-08 16:44:50 -0500321 const size_t nEntries = 42;
Yanbiao Li73860e32015-08-19 16:30:16 -0700322 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700323 for (size_t i = 0; i < nEntries; i++) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400324 auto channel = factory->addChannel("test" + to_string(i) + "://");
Yanbiao Li73860e32015-08-19 16:30:16 -0700325 addedChannels[channel->getUri().toString()] = channel;
326 }
327
Davide Pesavento28181322018-11-08 16:44:50 -0500328 receiveInterest(Interest("/localhost/nfd/faces/channels").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700329
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400330 Block content = concatenateResponses();
331 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700332 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
333
334 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400335 ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700336 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
337 }
338}
339
Davide Pesavento97210d52016-10-14 15:45:48 +0200340BOOST_AUTO_TEST_SUITE_END() // Datasets
341
342BOOST_AUTO_TEST_SUITE(Notifications)
343
Eric Newberry1b4ba052016-10-07 23:04:07 -0700344BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200345{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700346 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
347 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
348 FaceId faceId = face->getId();
349
350 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200351
352 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700353 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400354 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700355 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400356 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700357 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
358 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
359 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
360 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
361 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
362 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
363 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400364 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700365}
Davide Pesavento97210d52016-10-14 15:45:48 +0200366
Eric Newberry1b4ba052016-10-07 23:04:07 -0700367BOOST_AUTO_TEST_CASE(FaceEventDownUp)
368{
369 auto face = addFace();
370 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
371 FaceId faceId = face->getId();
372
373 // trigger FACE_EVENT_DOWN notification
374 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento28181322018-11-08 16:44:50 -0500375 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700376 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200377
378 // check notification
379 {
Davide Pesavento97210d52016-10-14 15:45:48 +0200380 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400381 Block payload = m_responses.back().getContent().blockFromValue();
Davide Pesavento97210d52016-10-14 15:45:48 +0200382 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400383 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700384 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200385 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700386 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
387 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200388 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
389 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
390 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400391 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200392 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700393
394 // trigger FACE_EVENT_UP notification
395 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
Davide Pesavento28181322018-11-08 16:44:50 -0500396 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700397 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
398
399 // check notification
400 {
Eric Newberry1b4ba052016-10-07 23:04:07 -0700401 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400402 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700403 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400404 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700405 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
406 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
407 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
408 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
409 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
410 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
411 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400412 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700413 }
414}
415
416BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
417{
418 auto face = addFace();
419 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
420 FaceId faceId = face->getId();
421
422 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
423
424 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
Davide Pesavento28181322018-11-08 16:44:50 -0500425 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700426
427 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700428 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400429 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700430 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400431 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700432 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
433 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
434 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
435 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
436 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
437 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
438 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400439 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700440
441 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
442 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200443}
444
445BOOST_AUTO_TEST_SUITE_END() // Notifications
446
Yanbiao Li73860e32015-08-19 16:30:16 -0700447BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
448BOOST_AUTO_TEST_SUITE_END() // Mgmt
449
450} // namespace tests
451} // namespace nfd