blob: 8a418e57f4c220bb41655d8b6269795890ecf8f1 [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 Pesaventob8bd5ee2019-02-03 22:53:40 -05003 * Copyright (c) 2014-2019, 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()
49 : m_faceTable(m_forwarder.getFaceTable())
Davide Pesaventob5eee202017-09-21 23:59:22 -040050 , m_faceSystem(m_faceTable, make_shared<ndn::net::NetworkMonitorStub>(0))
Junxiao Shiea47bde2017-01-26 17:49:16 +000051 , m_manager(m_faceSystem, m_dispatcher, *m_authenticator)
Yanbiao Li73860e32015-08-19 16:30:16 -070052 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000053 setTopPrefix();
Yanbiao Lidf846e52016-01-30 21:53:47 -080054 setPrivilege("faces");
Yanbiao Li73860e32015-08-19 16:30:16 -070055 }
56
57public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070058 enum AddFaceFlags {
59 REMOVE_LAST_NOTIFICATION = 1 << 0,
60 SET_SCOPE_LOCAL = 1 << 1,
61 SET_URI_TEST = 1 << 2,
Davide Pesavento6837d4f2017-07-15 13:01:03 -040062 RANDOMIZE_COUNTERS = 1 << 3,
Junxiao Shicde37ad2015-12-24 01:02:05 -070063 };
64
65 /** \brief adds a face to the FaceTable
66 * \param options bitwise OR'ed AddFaceFlags
67 */
Yanbiao Li73860e32015-08-19 16:30:16 -070068 shared_ptr<Face>
Davide Pesavento6837d4f2017-07-15 13:01:03 -040069 addFace(unsigned int flags = 0)
Yanbiao Li73860e32015-08-19 16:30:16 -070070 {
Junxiao Shicde37ad2015-12-24 01:02:05 -070071 std::string uri = "dummy://";
72 ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL;
73
Davide Pesavento28181322018-11-08 16:44:50 -050074 if (flags & SET_SCOPE_LOCAL) {
Junxiao Shicde37ad2015-12-24 01:02:05 -070075 scope = ndn::nfd::FACE_SCOPE_LOCAL;
76 }
Davide Pesavento28181322018-11-08 16:44:50 -050077 if (flags & SET_URI_TEST) {
Junxiao Shicde37ad2015-12-24 01:02:05 -070078 uri = "test://";
79 }
80
81 auto face = make_shared<DummyFace>(uri, uri, scope);
Yanbiao Li73860e32015-08-19 16:30:16 -070082 m_faceTable.add(face);
Junxiao Shicde37ad2015-12-24 01:02:05 -070083
Davide Pesavento28181322018-11-08 16:44:50 -050084 if (flags & RANDOMIZE_COUNTERS) {
85 const auto& counters = face->getCounters();
Junxiao Shicde37ad2015-12-24 01:02:05 -070086 randomizeCounter(counters.nInInterests);
87 randomizeCounter(counters.nOutInterests);
88 randomizeCounter(counters.nInData);
89 randomizeCounter(counters.nOutData);
90 randomizeCounter(counters.nInNacks);
91 randomizeCounter(counters.nOutNacks);
92 randomizeCounter(counters.nInPackets);
93 randomizeCounter(counters.nOutPackets);
94 randomizeCounter(counters.nInBytes);
95 randomizeCounter(counters.nOutBytes);
96 }
97
Davide Pesavento28181322018-11-08 16:44:50 -050098 advanceClocks(1_ms, 10); // wait for notification posted
99 if (flags & REMOVE_LAST_NOTIFICATION) {
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:
116 FaceTable& m_faceTable;
Junxiao Shiea47bde2017-01-26 17:49:16 +0000117 FaceSystem m_faceSystem;
Yanbiao Li73860e32015-08-19 16:30:16 -0700118 FaceManager m_manager;
119};
120
Davide Pesavento97210d52016-10-14 15:45:48 +0200121BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700122BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700123
124BOOST_AUTO_TEST_SUITE(DestroyFace)
125
126BOOST_AUTO_TEST_CASE(Existing)
127{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700128 auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
Yanbiao Li73860e32015-08-19 16:30:16 -0700129
130 auto parameters = ControlParameters().setFaceId(addedFace->getId());
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000131 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
132 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700133
134 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
135 // notification is already tested, so ignore it
136
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000137 BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700138 CheckResponseResult::OK);
139
Junxiao Shicde37ad2015-12-24 01:02:05 -0700140 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700141}
142
143BOOST_AUTO_TEST_CASE(NonExisting)
144{
145 auto parameters = ControlParameters().setFaceId(65535);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000146 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
147 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700148
149 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000150 BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700151 CheckResponseResult::OK);
152}
153
154BOOST_AUTO_TEST_SUITE_END() // DestroyFace
155
Davide Pesavento97210d52016-10-14 15:45:48 +0200156BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700157
158BOOST_AUTO_TEST_CASE(FaceDataset)
159{
Davide Pesavento28181322018-11-08 16:44:50 -0500160 const size_t nEntries = 32;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700161 for (size_t i = 0; i < nEntries; ++i) {
162 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700163 }
164
Davide Pesavento28181322018-11-08 16:44:50 -0500165 receiveInterest(Interest("/localhost/nfd/faces/list").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700166
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400167 Block content = concatenateResponses();
168 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700169 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
170
Yanbiao Li73860e32015-08-19 16:30:16 -0700171 std::set<FaceId> faceIds;
172 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400173 ndn::nfd::FaceStatus decodedStatus(content.elements()[idx]);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700174 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700175 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700176 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700177 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Davide Pesavento28181322018-11-08 16:44:50 -0500178
179 ndn::nfd::FaceStatus status(content.elements().front());
180 const Face* face = m_faceTable.get(status.getFaceId());
181 BOOST_REQUIRE(face != nullptr);
182
183 // check face properties
184 BOOST_CHECK_EQUAL(status.getRemoteUri(), face->getRemoteUri().toString());
185 BOOST_CHECK_EQUAL(status.getLocalUri(), face->getLocalUri().toString());
186 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(),
187 face->getExpirationTime() != time::steady_clock::time_point::max());
188 BOOST_CHECK_EQUAL(status.getFaceScope(), face->getScope());
189 BOOST_CHECK_EQUAL(status.getFacePersistency(), face->getPersistency());
190 BOOST_CHECK_EQUAL(status.getLinkType(), face->getLinkType());
191
192 // check link service properties
193 BOOST_CHECK_EQUAL(status.hasBaseCongestionMarkingInterval(), false);
194 BOOST_CHECK_EQUAL(status.hasDefaultCongestionThreshold(), false);
195 BOOST_CHECK_EQUAL(status.getFlags(), 0);
196
197 // check transport properties
198 BOOST_CHECK_EQUAL(status.hasMtu(), true);
199 BOOST_CHECK_EQUAL(status.getMtu(), ndn::MAX_NDN_PACKET_SIZE);
200
201 // check counters
202 BOOST_CHECK_EQUAL(status.getNInInterests(), face->getCounters().nInInterests);
203 BOOST_CHECK_EQUAL(status.getNInData(), face->getCounters().nInData);
204 BOOST_CHECK_EQUAL(status.getNInNacks(), face->getCounters().nInNacks);
205 BOOST_CHECK_EQUAL(status.getNOutInterests(), face->getCounters().nOutInterests);
206 BOOST_CHECK_EQUAL(status.getNOutData(), face->getCounters().nOutData);
207 BOOST_CHECK_EQUAL(status.getNOutNacks(), face->getCounters().nOutNacks);
208 BOOST_CHECK_EQUAL(status.getNInBytes(), face->getCounters().nInBytes);
209 BOOST_CHECK_EQUAL(status.getNOutBytes(), face->getCounters().nOutBytes);
Yanbiao Li73860e32015-08-19 16:30:16 -0700210}
211
212BOOST_AUTO_TEST_CASE(FaceQuery)
213{
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400214 using ndn::nfd::FaceQueryFilter;
215
Junxiao Shicde37ad2015-12-24 01:02:05 -0700216 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
217 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
218 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700219
Davide Pesavento28181322018-11-08 16:44:50 -0500220 auto generateQuery = [] (const FaceQueryFilter& filter) {
221 return Interest(Name("/localhost/nfd/faces/query").append(filter.wireEncode()))
222 .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 Pesavento6837d4f2017-07-15 13:01:03 -0400228 auto invalidQueryName = Name("/localhost/nfd/faces/query")
229 .append(ndn::makeStringBlock(tlv::Content, "invalid"));
Davide Pesavento28181322018-11-08 16:44:50 -0500230 auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700231
Davide Pesavento28181322018-11-08 16:44:50 -0500232 receiveInterest(schemeQuery); // face1 and face2 expected
233 receiveInterest(idQuery); // face1 expected
234 receiveInterest(scopeQuery); // face1 and face3 expected
235 receiveInterest(invalidQuery); // nack expected
Yanbiao Li73860e32015-08-19 16:30:16 -0700236
237 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
238
239 Block content;
240 ndn::nfd::FaceStatus status;
241
242 content = m_responses[0].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400243 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700244 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400245 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700246 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400247 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700248 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
249
250 content = m_responses[1].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400251 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700252 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400253 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700254 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
255
256 content = m_responses[2].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400257 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700258 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400259 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700260 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400261 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700262 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
263
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200264 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700265 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
266 CheckResponseResult::OK);
267}
268
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400269class TestChannel : public face::Channel
Yanbiao Li73860e32015-08-19 16:30:16 -0700270{
271public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200272 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700273 TestChannel(const std::string& uri)
274 {
275 setUri(FaceUri(uri));
276 }
Davide Pesaventoc19408d2017-04-08 00:42:55 -0400277
278 bool
279 isListening() const final
280 {
281 return false;
282 }
283
284 size_t
285 size() const final
286 {
287 return 0;
288 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700289};
290
Davide Pesaventoe5eebad2017-04-06 20:23:26 -0400291class TestProtocolFactory : public face::ProtocolFactory
Yanbiao Li73860e32015-08-19 16:30:16 -0700292{
293public:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500294 using ProtocolFactory::ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000295
Yanbiao Li73860e32015-08-19 16:30:16 -0700296 shared_ptr<TestChannel>
297 addChannel(const std::string& channelUri)
298 {
299 auto channel = make_shared<TestChannel>(channelUri);
300 m_channels.push_back(channel);
301 return channel;
302 }
303
304private:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500305 std::vector<shared_ptr<const face::Channel>>
306 doGetChannels() const final
307 {
308 return m_channels;
309 }
310
311private:
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400312 std::vector<shared_ptr<const face::Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700313};
314
315BOOST_AUTO_TEST_CASE(ChannelDataset)
316{
Davide Pesavento28181322018-11-08 16:44:50 -0500317 m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>(m_faceSystem.makePFCtorParams());
Davide Pesaventob5eee202017-09-21 23:59:22 -0400318 auto factory = static_cast<TestProtocolFactory*>(m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700319
Davide Pesavento28181322018-11-08 16:44:50 -0500320 const size_t nEntries = 42;
Yanbiao Li73860e32015-08-19 16:30:16 -0700321 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700322 for (size_t i = 0; i < nEntries; i++) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400323 auto channel = factory->addChannel("test" + to_string(i) + "://");
Yanbiao Li73860e32015-08-19 16:30:16 -0700324 addedChannels[channel->getUri().toString()] = channel;
325 }
326
Davide Pesavento28181322018-11-08 16:44:50 -0500327 receiveInterest(Interest("/localhost/nfd/faces/channels").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700328
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400329 Block content = concatenateResponses();
330 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700331 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
332
333 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400334 ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700335 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
336 }
337}
338
Davide Pesavento97210d52016-10-14 15:45:48 +0200339BOOST_AUTO_TEST_SUITE_END() // Datasets
340
341BOOST_AUTO_TEST_SUITE(Notifications)
342
Eric Newberry1b4ba052016-10-07 23:04:07 -0700343BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200344{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700345 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
346 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
347 FaceId faceId = face->getId();
348
349 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200350
351 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700352 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400353 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700354 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400355 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700356 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
357 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
358 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
359 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
360 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
361 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
362 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400363 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700364}
Davide Pesavento97210d52016-10-14 15:45:48 +0200365
Eric Newberry1b4ba052016-10-07 23:04:07 -0700366BOOST_AUTO_TEST_CASE(FaceEventDownUp)
367{
368 auto face = addFace();
369 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
370 FaceId faceId = face->getId();
371
372 // trigger FACE_EVENT_DOWN notification
373 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento28181322018-11-08 16:44:50 -0500374 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700375 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200376
377 // check notification
378 {
Davide Pesavento97210d52016-10-14 15:45:48 +0200379 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400380 Block payload = m_responses.back().getContent().blockFromValue();
Davide Pesavento97210d52016-10-14 15:45:48 +0200381 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400382 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700383 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200384 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700385 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
386 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200387 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
388 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
389 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400390 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200391 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700392
393 // trigger FACE_EVENT_UP notification
394 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
Davide Pesavento28181322018-11-08 16:44:50 -0500395 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700396 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
397
398 // check notification
399 {
Eric Newberry1b4ba052016-10-07 23:04:07 -0700400 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400401 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700402 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400403 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700404 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
405 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
406 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
407 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
408 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
409 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
410 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400411 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700412 }
413}
414
415BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
416{
417 auto face = addFace();
418 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
419 FaceId faceId = face->getId();
420
421 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
422
423 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
Davide Pesavento28181322018-11-08 16:44:50 -0500424 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700425
426 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700427 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400428 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700429 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400430 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700431 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
432 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
433 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
434 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
435 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
436 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
437 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400438 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700439
440 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
441 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200442}
443
444BOOST_AUTO_TEST_SUITE_END() // Notifications
445
Yanbiao Li73860e32015-08-19 16:30:16 -0700446BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
447BOOST_AUTO_TEST_SUITE_END() // Mgmt
448
449} // namespace tests
450} // namespace nfd