blob: 97b300053bd3cc0db82c62ea2a6320c61d3b4687 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Davide Pesavento152ef442023-04-22 02:02:29 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070020 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/mgmt/nfd/face-event-notification.hpp"
Davide Pesavento152ef442023-04-22 02:02:29 -040023#include "ndn-cxx/util/concepts.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "tests/boost-test.hpp"
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050026
Davide Pesavento88eb7482017-02-18 19:25:58 -050027#include <boost/lexical_cast.hpp>
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070028
29namespace ndn {
30namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080031namespace tests {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070032
Davide Pesavento152ef442023-04-22 02:02:29 -040033BOOST_CONCEPT_ASSERT((NotificationStreamItem<FaceEventNotification>));
34
Junxiao Shi7357ef22016-09-07 02:39:37 +000035BOOST_AUTO_TEST_SUITE(Mgmt)
36BOOST_AUTO_TEST_SUITE(Nfd)
37BOOST_AUTO_TEST_SUITE(TestFaceEventNotification)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070038
Chengyu Fan36dca992014-09-25 13:42:03 -060039BOOST_AUTO_TEST_CASE(Traits)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070040{
41 FaceEventNotification notification;
Chengyu Fan36dca992014-09-25 13:42:03 -060042 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_NON_LOCAL);
43 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
44 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070045
Chengyu Fan36dca992014-09-25 13:42:03 -060046 notification.setFaceScope(FACE_SCOPE_LOCAL);
47 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
48 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
49 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070050
Chengyu Fan36dca992014-09-25 13:42:03 -060051 notification.setFacePersistency(FACE_PERSISTENCY_ON_DEMAND);
52 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
53 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_ON_DEMAND);
54 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070055
Chengyu Fan36dca992014-09-25 13:42:03 -060056 notification.setFacePersistency(FACE_PERSISTENCY_PERMANENT);
57 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
58 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
59 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
60
61 notification.setLinkType(LINK_TYPE_MULTI_ACCESS);
62 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
63 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
64 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070065}
66
Davide Pesavento88eb7482017-02-18 19:25:58 -050067BOOST_AUTO_TEST_CASE(Created)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070068{
69 FaceEventNotification notification1;
70 notification1.setKind(FACE_EVENT_CREATED)
71 .setFaceId(20)
72 .setRemoteUri("tcp4://192.0.2.1:55555")
73 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -060074 .setFaceScope(FACE_SCOPE_LOCAL)
75 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070076 .setLinkType(LINK_TYPE_MULTI_ACCESS)
77 .setFlags(0x3);
Davide Pesavento88eb7482017-02-18 19:25:58 -050078 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070079
80 // These octets are obtained by the snippet below.
81 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050082 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Chengyu Fan36dca992014-09-25 13:42:03 -060083 // printf("0x%02x, ", *it);
84 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070085 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070086 0xc0, 0x41, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -060087 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
88 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
89 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
90 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
91 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070092 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x03,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070093 };
Davide Pesavento88eb7482017-02-18 19:25:58 -050094 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
95 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070096
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070097 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -050098 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070099
Davide Pesavento88eb7482017-02-18 19:25:58 -0500100 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
101 "FaceEvent(Kind: created,\n"
102 " FaceId: 20,\n"
103 " RemoteUri: tcp4://192.0.2.1:55555,\n"
104 " LocalUri: tcp4://192.0.2.2:6363,\n"
105 " FaceScope: local,\n"
106 " FacePersistency: on-demand,\n"
107 " LinkType: multi-access,\n"
108 " Flags: 0x3\n"
109 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700110}
111
Davide Pesavento88eb7482017-02-18 19:25:58 -0500112BOOST_AUTO_TEST_CASE(Destroyed)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700113{
114 FaceEventNotification notification1;
115 notification1.setKind(FACE_EVENT_DESTROYED)
116 .setFaceId(20)
117 .setRemoteUri("tcp4://192.0.2.1:55555")
118 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600119 .setFaceScope(FACE_SCOPE_LOCAL)
120 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700121 .setLinkType(LINK_TYPE_MULTI_ACCESS)
122 .setFlags(0x4);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500123 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700124
125 // These octets are obtained by the snippet below.
126 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500127 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Chengyu Fan36dca992014-09-25 13:42:03 -0600128 // printf("0x%02x, ", *it);
129 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700130 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700131 0xc0, 0x41, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -0600132 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
133 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
134 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
135 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
136 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700137 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x04,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700138 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500139 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
140 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700141
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700142 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500143 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700144
Davide Pesavento88eb7482017-02-18 19:25:58 -0500145 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
146 "FaceEvent(Kind: destroyed,\n"
147 " FaceId: 20,\n"
148 " RemoteUri: tcp4://192.0.2.1:55555,\n"
149 " LocalUri: tcp4://192.0.2.2:6363,\n"
150 " FaceScope: local,\n"
151 " FacePersistency: on-demand,\n"
152 " LinkType: multi-access,\n"
153 " Flags: 0x4\n"
154 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700155}
156
Davide Pesavento88eb7482017-02-18 19:25:58 -0500157BOOST_AUTO_TEST_CASE(Up)
Eric Newberryf767eba2016-10-07 13:37:02 -0700158{
159 FaceEventNotification notification1;
160 notification1.setKind(FACE_EVENT_UP)
161 .setFaceId(20)
162 .setRemoteUri("tcp4://192.0.2.1:55555")
163 .setLocalUri("tcp4://192.0.2.2:6363")
164 .setFaceScope(FACE_SCOPE_LOCAL)
165 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700166 .setLinkType(LINK_TYPE_MULTI_ACCESS)
167 .setFlags(0x05);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500168 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700169
170 // These octets are obtained by the snippet below.
171 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500172 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Eric Newberryf767eba2016-10-07 13:37:02 -0700173 // printf("0x%02x, ", *it);
174 // }
175 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700176 0xc0, 0x41, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700177 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
178 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
179 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
180 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
181 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700182 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x05,
Eric Newberryf767eba2016-10-07 13:37:02 -0700183 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500184 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
185 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700186
Eric Newberryf767eba2016-10-07 13:37:02 -0700187 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500188 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700189
Davide Pesavento88eb7482017-02-18 19:25:58 -0500190 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
191 "FaceEvent(Kind: up,\n"
192 " FaceId: 20,\n"
193 " RemoteUri: tcp4://192.0.2.1:55555,\n"
194 " LocalUri: tcp4://192.0.2.2:6363,\n"
195 " FaceScope: local,\n"
196 " FacePersistency: on-demand,\n"
197 " LinkType: multi-access,\n"
198 " Flags: 0x5\n"
199 " )");
Eric Newberryf767eba2016-10-07 13:37:02 -0700200}
201
Davide Pesavento88eb7482017-02-18 19:25:58 -0500202BOOST_AUTO_TEST_CASE(Down)
Eric Newberryf767eba2016-10-07 13:37:02 -0700203{
204 FaceEventNotification notification1;
205 notification1.setKind(FACE_EVENT_DOWN)
206 .setFaceId(20)
207 .setRemoteUri("tcp4://192.0.2.1:55555")
208 .setLocalUri("tcp4://192.0.2.2:6363")
209 .setFaceScope(FACE_SCOPE_LOCAL)
210 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700211 .setLinkType(LINK_TYPE_MULTI_ACCESS)
212 .setFlags(0x06);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500213 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700214
215 // These octets are obtained by the snippet below.
216 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500217 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Eric Newberryf767eba2016-10-07 13:37:02 -0700218 // printf("0x%02x, ", *it);
219 // }
220 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700221 0xc0, 0x41, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700222 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
223 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
224 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
225 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
226 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700227 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x06,
Eric Newberryf767eba2016-10-07 13:37:02 -0700228 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500229 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
230 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700231
Eric Newberryf767eba2016-10-07 13:37:02 -0700232 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500233 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700234
Davide Pesavento88eb7482017-02-18 19:25:58 -0500235 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
236 "FaceEvent(Kind: down,\n"
237 " FaceId: 20,\n"
238 " RemoteUri: tcp4://192.0.2.1:55555,\n"
239 " LocalUri: tcp4://192.0.2.2:6363,\n"
240 " FaceScope: local,\n"
241 " FacePersistency: on-demand,\n"
242 " LinkType: multi-access,\n"
243 " Flags: 0x6\n"
244 " )");
245}
246
247BOOST_AUTO_TEST_CASE(Equality)
248{
249 FaceEventNotification notification1, notification2;
250 BOOST_CHECK_EQUAL(notification1, notification2);
251
252 notification1.setKind(FACE_EVENT_CREATED)
253 .setFaceId(123)
254 .setRemoteUri("tcp4://192.0.2.1:55555")
255 .setLocalUri("tcp4://192.0.2.2:6363");
256 notification2 = notification1;
257 BOOST_CHECK_EQUAL(notification1, notification2);
258
259 notification2.setFaceId(42);
260 BOOST_CHECK_NE(notification1, notification2);
261
262 notification2 = notification1;
263 notification2.setKind(FACE_EVENT_DESTROYED);
264 BOOST_CHECK_NE(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700265}
266
Junxiao Shi7357ef22016-09-07 02:39:37 +0000267BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
268BOOST_AUTO_TEST_SUITE_END() // Nfd
269BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700270
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800271} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700272} // namespace nfd
273} // namespace ndn