blob: 0930374317baf4ac098c236f06083db8c4bb74a6 [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()
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) {
Yanbiao Li73860e32015-08-19 16:30:16 -070099 m_responses.pop_back();
100 }
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101
Yanbiao Li73860e32015-08-19 16:30:16 -0700102 return face;
103 }
104
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105private:
106 template<typename T>
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400107 static void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700108 randomizeCounter(const T& counter)
109 {
Davide Pesavento5f47aa62016-10-07 22:09:09 +0200110 static std::uniform_int_distribution<typename T::rep> dist;
Davide Pesaventob8bd5ee2019-02-03 22:53:40 -0500111 const_cast<T&>(counter).set(dist(ndn::random::getRandomNumberEngine()));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700112 }
113
Yanbiao Li73860e32015-08-19 16:30:16 -0700114protected:
Junxiao Shiea47bde2017-01-26 17:49:16 +0000115 FaceSystem m_faceSystem;
Yanbiao Li73860e32015-08-19 16:30:16 -0700116 FaceManager m_manager;
117};
118
Davide Pesavento97210d52016-10-14 15:45:48 +0200119BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700120BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700121
122BOOST_AUTO_TEST_SUITE(DestroyFace)
123
124BOOST_AUTO_TEST_CASE(Existing)
125{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700126 auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
Yanbiao Li73860e32015-08-19 16:30:16 -0700127
128 auto parameters = ControlParameters().setFaceId(addedFace->getId());
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000129 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
130 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700131
132 BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
133 // notification is already tested, so ignore it
134
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000135 BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700136 CheckResponseResult::OK);
137
Junxiao Shicde37ad2015-12-24 01:02:05 -0700138 BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
Yanbiao Li73860e32015-08-19 16:30:16 -0700139}
140
141BOOST_AUTO_TEST_CASE(NonExisting)
142{
143 auto parameters = ControlParameters().setFaceId(65535);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000144 auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
145 receiveInterest(req);
Yanbiao Li73860e32015-08-19 16:30:16 -0700146
147 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000148 BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", parameters)),
Yanbiao Li73860e32015-08-19 16:30:16 -0700149 CheckResponseResult::OK);
150}
151
152BOOST_AUTO_TEST_SUITE_END() // DestroyFace
153
Davide Pesavento97210d52016-10-14 15:45:48 +0200154BOOST_AUTO_TEST_SUITE(Datasets)
Yanbiao Li73860e32015-08-19 16:30:16 -0700155
156BOOST_AUTO_TEST_CASE(FaceDataset)
157{
Davide Pesavento28181322018-11-08 16:44:50 -0500158 const size_t nEntries = 32;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700159 for (size_t i = 0; i < nEntries; ++i) {
160 addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
Yanbiao Li73860e32015-08-19 16:30:16 -0700161 }
162
Davide Pesavento28181322018-11-08 16:44:50 -0500163 receiveInterest(Interest("/localhost/nfd/faces/list").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700164
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400165 Block content = concatenateResponses();
166 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700167 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
168
Yanbiao Li73860e32015-08-19 16:30:16 -0700169 std::set<FaceId> faceIds;
170 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400171 ndn::nfd::FaceStatus decodedStatus(content.elements()[idx]);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700172 BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700173 faceIds.insert(decodedStatus.getFaceId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700174 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700175 BOOST_CHECK_EQUAL(faceIds.size(), nEntries);
Davide Pesavento28181322018-11-08 16:44:50 -0500176
177 ndn::nfd::FaceStatus status(content.elements().front());
178 const Face* face = m_faceTable.get(status.getFaceId());
179 BOOST_REQUIRE(face != nullptr);
180
181 // check face properties
182 BOOST_CHECK_EQUAL(status.getRemoteUri(), face->getRemoteUri().toString());
183 BOOST_CHECK_EQUAL(status.getLocalUri(), face->getLocalUri().toString());
184 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(),
185 face->getExpirationTime() != time::steady_clock::time_point::max());
186 BOOST_CHECK_EQUAL(status.getFaceScope(), face->getScope());
187 BOOST_CHECK_EQUAL(status.getFacePersistency(), face->getPersistency());
188 BOOST_CHECK_EQUAL(status.getLinkType(), face->getLinkType());
189
190 // check link service properties
191 BOOST_CHECK_EQUAL(status.hasBaseCongestionMarkingInterval(), false);
192 BOOST_CHECK_EQUAL(status.hasDefaultCongestionThreshold(), false);
193 BOOST_CHECK_EQUAL(status.getFlags(), 0);
194
195 // check transport properties
196 BOOST_CHECK_EQUAL(status.hasMtu(), true);
197 BOOST_CHECK_EQUAL(status.getMtu(), ndn::MAX_NDN_PACKET_SIZE);
198
199 // check counters
200 BOOST_CHECK_EQUAL(status.getNInInterests(), face->getCounters().nInInterests);
201 BOOST_CHECK_EQUAL(status.getNInData(), face->getCounters().nInData);
202 BOOST_CHECK_EQUAL(status.getNInNacks(), face->getCounters().nInNacks);
203 BOOST_CHECK_EQUAL(status.getNOutInterests(), face->getCounters().nOutInterests);
204 BOOST_CHECK_EQUAL(status.getNOutData(), face->getCounters().nOutData);
205 BOOST_CHECK_EQUAL(status.getNOutNacks(), face->getCounters().nOutNacks);
206 BOOST_CHECK_EQUAL(status.getNInBytes(), face->getCounters().nInBytes);
207 BOOST_CHECK_EQUAL(status.getNOutBytes(), face->getCounters().nOutBytes);
Yanbiao Li73860e32015-08-19 16:30:16 -0700208}
209
210BOOST_AUTO_TEST_CASE(FaceQuery)
211{
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400212 using ndn::nfd::FaceQueryFilter;
213
Junxiao Shicde37ad2015-12-24 01:02:05 -0700214 auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
215 auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
216 auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
Yanbiao Li73860e32015-08-19 16:30:16 -0700217
Davide Pesavento28181322018-11-08 16:44:50 -0500218 auto generateQuery = [] (const FaceQueryFilter& filter) {
219 return Interest(Name("/localhost/nfd/faces/query").append(filter.wireEncode()))
220 .setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700221 };
222
Davide Pesavento28181322018-11-08 16:44:50 -0500223 auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy"));
224 auto idQuery = generateQuery(FaceQueryFilter().setFaceId(face1->getId()));
225 auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL));
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400226 auto invalidQueryName = Name("/localhost/nfd/faces/query")
227 .append(ndn::makeStringBlock(tlv::Content, "invalid"));
Davide Pesavento28181322018-11-08 16:44:50 -0500228 auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true);
Yanbiao Li73860e32015-08-19 16:30:16 -0700229
Davide Pesavento28181322018-11-08 16:44:50 -0500230 receiveInterest(schemeQuery); // face1 and face2 expected
231 receiveInterest(idQuery); // face1 expected
232 receiveInterest(scopeQuery); // face1 and face3 expected
233 receiveInterest(invalidQuery); // nack expected
Yanbiao Li73860e32015-08-19 16:30:16 -0700234
235 BOOST_REQUIRE_EQUAL(m_responses.size(), 4);
236
237 Block content;
238 ndn::nfd::FaceStatus status;
239
240 content = m_responses[0].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400241 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700242 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400243 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700244 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400245 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700246 BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId());
247
248 content = m_responses[1].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400249 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700250 BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400251 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700252 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
253
254 content = m_responses[2].getContent();
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400255 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700256 BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400257 status.wireDecode(content.elements()[0]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700258 BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId());
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400259 status.wireDecode(content.elements()[1]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700260 BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId());
261
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200262 ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter
Yanbiao Li73860e32015-08-19 16:30:16 -0700263 BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack),
264 CheckResponseResult::OK);
265}
266
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400267class TestChannel : public face::Channel
Yanbiao Li73860e32015-08-19 16:30:16 -0700268{
269public:
Davide Pesavento97210d52016-10-14 15:45:48 +0200270 explicit
Yanbiao Li73860e32015-08-19 16:30:16 -0700271 TestChannel(const std::string& uri)
272 {
273 setUri(FaceUri(uri));
274 }
Davide Pesaventoc19408d2017-04-08 00:42:55 -0400275
276 bool
277 isListening() const final
278 {
279 return false;
280 }
281
282 size_t
283 size() const final
284 {
285 return 0;
286 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700287};
288
Davide Pesaventoe5eebad2017-04-06 20:23:26 -0400289class TestProtocolFactory : public face::ProtocolFactory
Yanbiao Li73860e32015-08-19 16:30:16 -0700290{
291public:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500292 using ProtocolFactory::ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000293
Yanbiao Li73860e32015-08-19 16:30:16 -0700294 shared_ptr<TestChannel>
295 addChannel(const std::string& channelUri)
296 {
297 auto channel = make_shared<TestChannel>(channelUri);
298 m_channels.push_back(channel);
299 return channel;
300 }
301
302private:
Davide Pesaventod27841b2018-11-13 00:22:24 -0500303 std::vector<shared_ptr<const face::Channel>>
304 doGetChannels() const final
305 {
306 return m_channels;
307 }
308
309private:
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400310 std::vector<shared_ptr<const face::Channel>> m_channels;
Yanbiao Li73860e32015-08-19 16:30:16 -0700311};
312
313BOOST_AUTO_TEST_CASE(ChannelDataset)
314{
Davide Pesavento28181322018-11-08 16:44:50 -0500315 m_faceSystem.m_factories["test"] = make_unique<TestProtocolFactory>(m_faceSystem.makePFCtorParams());
Davide Pesaventob5eee202017-09-21 23:59:22 -0400316 auto factory = static_cast<TestProtocolFactory*>(m_faceSystem.getFactoryById("test"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700317
Davide Pesavento28181322018-11-08 16:44:50 -0500318 const size_t nEntries = 42;
Yanbiao Li73860e32015-08-19 16:30:16 -0700319 std::map<std::string, shared_ptr<TestChannel>> addedChannels;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700320 for (size_t i = 0; i < nEntries; i++) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400321 auto channel = factory->addChannel("test" + to_string(i) + "://");
Yanbiao Li73860e32015-08-19 16:30:16 -0700322 addedChannels[channel->getUri().toString()] = channel;
323 }
324
Davide Pesavento28181322018-11-08 16:44:50 -0500325 receiveInterest(Interest("/localhost/nfd/faces/channels").setCanBePrefix(true));
Yanbiao Li73860e32015-08-19 16:30:16 -0700326
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400327 Block content = concatenateResponses();
328 content.parse();
Yanbiao Li73860e32015-08-19 16:30:16 -0700329 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
330
331 for (size_t idx = 0; idx < nEntries; ++idx) {
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400332 ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]);
Yanbiao Li73860e32015-08-19 16:30:16 -0700333 BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end());
334 }
335}
336
Davide Pesavento97210d52016-10-14 15:45:48 +0200337BOOST_AUTO_TEST_SUITE_END() // Datasets
338
339BOOST_AUTO_TEST_SUITE(Notifications)
340
Eric Newberry1b4ba052016-10-07 23:04:07 -0700341BOOST_AUTO_TEST_CASE(FaceEventCreated)
Davide Pesavento97210d52016-10-14 15:45:48 +0200342{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700343 auto face = addFace(); // trigger FACE_EVENT_CREATED notification
344 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
345 FaceId faceId = face->getId();
346
347 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
Davide Pesavento97210d52016-10-14 15:45:48 +0200348
349 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700350 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400351 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700352 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400353 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700354 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_CREATED);
355 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
356 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
357 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
358 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
359 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
360 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400361 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700362}
Davide Pesavento97210d52016-10-14 15:45:48 +0200363
Eric Newberry1b4ba052016-10-07 23:04:07 -0700364BOOST_AUTO_TEST_CASE(FaceEventDownUp)
365{
366 auto face = addFace();
367 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
368 FaceId faceId = face->getId();
369
370 // trigger FACE_EVENT_DOWN notification
371 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::DOWN);
Davide Pesavento28181322018-11-08 16:44:50 -0500372 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700373 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200374
375 // check notification
376 {
Davide Pesavento97210d52016-10-14 15:45:48 +0200377 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400378 Block payload = m_responses.back().getContent().blockFromValue();
Davide Pesavento97210d52016-10-14 15:45:48 +0200379 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400380 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700381 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DOWN);
Davide Pesavento97210d52016-10-14 15:45:48 +0200382 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700383 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
384 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
Davide Pesavento97210d52016-10-14 15:45:48 +0200385 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
386 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
387 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400388 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200389 }
Eric Newberry1b4ba052016-10-07 23:04:07 -0700390
391 // trigger FACE_EVENT_UP notification
392 dynamic_cast<face::tests::DummyTransport*>(face->getTransport())->setState(face::FaceState::UP);
Davide Pesavento28181322018-11-08 16:44:50 -0500393 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700394 BOOST_CHECK_EQUAL(face->getState(), face::FaceState::UP);
395
396 // check notification
397 {
Eric Newberry1b4ba052016-10-07 23:04:07 -0700398 BOOST_REQUIRE_EQUAL(m_responses.size(), 3);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400399 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700400 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400401 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700402 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_UP);
403 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
404 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
405 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
406 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
407 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
408 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400409 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700410 }
411}
412
413BOOST_AUTO_TEST_CASE(FaceEventDestroyed)
414{
415 auto face = addFace();
416 BOOST_CHECK_NE(face->getId(), face::INVALID_FACEID);
417 FaceId faceId = face->getId();
418
419 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 1);
420
421 face->close(); // trigger FaceDestroy FACE_EVENT_DESTROYED
Davide Pesavento28181322018-11-08 16:44:50 -0500422 advanceClocks(1_ms, 10);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700423
424 // check notification
Eric Newberry1b4ba052016-10-07 23:04:07 -0700425 BOOST_REQUIRE_EQUAL(m_responses.size(), 2);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400426 Block payload = m_responses.back().getContent().blockFromValue();
Eric Newberry1b4ba052016-10-07 23:04:07 -0700427 BOOST_CHECK_EQUAL(payload.type(), ndn::tlv::nfd::FaceEventNotification);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400428 ndn::nfd::FaceEventNotification notification(payload);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700429 BOOST_CHECK_EQUAL(notification.getKind(), ndn::nfd::FACE_EVENT_DESTROYED);
430 BOOST_CHECK_EQUAL(notification.getFaceId(), faceId);
431 BOOST_CHECK_EQUAL(notification.getRemoteUri(), face->getRemoteUri().toString());
432 BOOST_CHECK_EQUAL(notification.getLocalUri(), face->getLocalUri().toString());
433 BOOST_CHECK_EQUAL(notification.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
434 BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
435 BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
Davide Pesavento6837d4f2017-07-15 13:01:03 -0400436 BOOST_CHECK_EQUAL(notification.getFlags(), 0);
Eric Newberry1b4ba052016-10-07 23:04:07 -0700437
438 BOOST_CHECK_EQUAL(face->getId(), face::INVALID_FACEID);
439 BOOST_CHECK_EQUAL(m_manager.m_faceStateChangeConn.count(faceId), 0);
Davide Pesavento97210d52016-10-14 15:45:48 +0200440}
441
442BOOST_AUTO_TEST_SUITE_END() // Notifications
443
Yanbiao Li73860e32015-08-19 16:30:16 -0700444BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
445BOOST_AUTO_TEST_SUITE_END() // Mgmt
446
447} // namespace tests
448} // namespace nfd