blob: f1dfc3858f9922e1cc532e3fec4eb37d215792f8 [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 Pesaventodf8fd8a2022-02-21 20:04:21 -05003 * Copyright (c) 2013-2022 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"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050025
Davide Pesavento88eb7482017-02-18 19:25:58 -050026#include <boost/lexical_cast.hpp>
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070027
28namespace ndn {
29namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030namespace tests {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070031
Junxiao Shi7357ef22016-09-07 02:39:37 +000032BOOST_AUTO_TEST_SUITE(Mgmt)
33BOOST_AUTO_TEST_SUITE(Nfd)
34BOOST_AUTO_TEST_SUITE(TestFaceEventNotification)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070035
Chengyu Fan36dca992014-09-25 13:42:03 -060036BOOST_AUTO_TEST_CASE(Traits)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070037{
38 FaceEventNotification notification;
Chengyu Fan36dca992014-09-25 13:42:03 -060039 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_NON_LOCAL);
40 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
41 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070042
Chengyu Fan36dca992014-09-25 13:42:03 -060043 notification.setFaceScope(FACE_SCOPE_LOCAL);
44 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
45 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
46 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070047
Chengyu Fan36dca992014-09-25 13:42:03 -060048 notification.setFacePersistency(FACE_PERSISTENCY_ON_DEMAND);
49 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
50 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_ON_DEMAND);
51 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070052
Chengyu Fan36dca992014-09-25 13:42:03 -060053 notification.setFacePersistency(FACE_PERSISTENCY_PERMANENT);
54 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
55 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
56 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
57
58 notification.setLinkType(LINK_TYPE_MULTI_ACCESS);
59 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
60 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
61 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070062}
63
Davide Pesavento88eb7482017-02-18 19:25:58 -050064BOOST_AUTO_TEST_CASE(Created)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070065{
66 FaceEventNotification notification1;
67 notification1.setKind(FACE_EVENT_CREATED)
68 .setFaceId(20)
69 .setRemoteUri("tcp4://192.0.2.1:55555")
70 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -060071 .setFaceScope(FACE_SCOPE_LOCAL)
72 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070073 .setLinkType(LINK_TYPE_MULTI_ACCESS)
74 .setFlags(0x3);
Davide Pesavento88eb7482017-02-18 19:25:58 -050075 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070076
77 // These octets are obtained by the snippet below.
78 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050079 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Chengyu Fan36dca992014-09-25 13:42:03 -060080 // printf("0x%02x, ", *it);
81 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070082 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070083 0xc0, 0x41, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -060084 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
85 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
86 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
87 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
88 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070089 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x03,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070090 };
Davide Pesavento88eb7482017-02-18 19:25:58 -050091 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
92 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070093
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070094 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -050095 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070096
Davide Pesavento88eb7482017-02-18 19:25:58 -050097 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
98 "FaceEvent(Kind: created,\n"
99 " FaceId: 20,\n"
100 " RemoteUri: tcp4://192.0.2.1:55555,\n"
101 " LocalUri: tcp4://192.0.2.2:6363,\n"
102 " FaceScope: local,\n"
103 " FacePersistency: on-demand,\n"
104 " LinkType: multi-access,\n"
105 " Flags: 0x3\n"
106 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700107}
108
Davide Pesavento88eb7482017-02-18 19:25:58 -0500109BOOST_AUTO_TEST_CASE(Destroyed)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700110{
111 FaceEventNotification notification1;
112 notification1.setKind(FACE_EVENT_DESTROYED)
113 .setFaceId(20)
114 .setRemoteUri("tcp4://192.0.2.1:55555")
115 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600116 .setFaceScope(FACE_SCOPE_LOCAL)
117 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700118 .setLinkType(LINK_TYPE_MULTI_ACCESS)
119 .setFlags(0x4);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500120 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700121
122 // These octets are obtained by the snippet below.
123 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500124 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Chengyu Fan36dca992014-09-25 13:42:03 -0600125 // printf("0x%02x, ", *it);
126 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700127 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700128 0xc0, 0x41, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -0600129 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
130 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
131 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
132 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
133 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700134 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x04,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700135 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500136 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
137 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700138
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700139 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500140 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700141
Davide Pesavento88eb7482017-02-18 19:25:58 -0500142 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
143 "FaceEvent(Kind: destroyed,\n"
144 " FaceId: 20,\n"
145 " RemoteUri: tcp4://192.0.2.1:55555,\n"
146 " LocalUri: tcp4://192.0.2.2:6363,\n"
147 " FaceScope: local,\n"
148 " FacePersistency: on-demand,\n"
149 " LinkType: multi-access,\n"
150 " Flags: 0x4\n"
151 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700152}
153
Davide Pesavento88eb7482017-02-18 19:25:58 -0500154BOOST_AUTO_TEST_CASE(Up)
Eric Newberryf767eba2016-10-07 13:37:02 -0700155{
156 FaceEventNotification notification1;
157 notification1.setKind(FACE_EVENT_UP)
158 .setFaceId(20)
159 .setRemoteUri("tcp4://192.0.2.1:55555")
160 .setLocalUri("tcp4://192.0.2.2:6363")
161 .setFaceScope(FACE_SCOPE_LOCAL)
162 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700163 .setLinkType(LINK_TYPE_MULTI_ACCESS)
164 .setFlags(0x05);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500165 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700166
167 // These octets are obtained by the snippet below.
168 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500169 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Eric Newberryf767eba2016-10-07 13:37:02 -0700170 // printf("0x%02x, ", *it);
171 // }
172 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700173 0xc0, 0x41, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700174 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
175 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
176 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
177 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
178 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700179 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x05,
Eric Newberryf767eba2016-10-07 13:37:02 -0700180 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500181 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
182 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700183
Eric Newberryf767eba2016-10-07 13:37:02 -0700184 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500185 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700186
Davide Pesavento88eb7482017-02-18 19:25:58 -0500187 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
188 "FaceEvent(Kind: up,\n"
189 " FaceId: 20,\n"
190 " RemoteUri: tcp4://192.0.2.1:55555,\n"
191 " LocalUri: tcp4://192.0.2.2:6363,\n"
192 " FaceScope: local,\n"
193 " FacePersistency: on-demand,\n"
194 " LinkType: multi-access,\n"
195 " Flags: 0x5\n"
196 " )");
Eric Newberryf767eba2016-10-07 13:37:02 -0700197}
198
Davide Pesavento88eb7482017-02-18 19:25:58 -0500199BOOST_AUTO_TEST_CASE(Down)
Eric Newberryf767eba2016-10-07 13:37:02 -0700200{
201 FaceEventNotification notification1;
202 notification1.setKind(FACE_EVENT_DOWN)
203 .setFaceId(20)
204 .setRemoteUri("tcp4://192.0.2.1:55555")
205 .setLocalUri("tcp4://192.0.2.2:6363")
206 .setFaceScope(FACE_SCOPE_LOCAL)
207 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700208 .setLinkType(LINK_TYPE_MULTI_ACCESS)
209 .setFlags(0x06);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500210 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700211
212 // These octets are obtained by the snippet below.
213 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -0500214 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Eric Newberryf767eba2016-10-07 13:37:02 -0700215 // printf("0x%02x, ", *it);
216 // }
217 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700218 0xc0, 0x41, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700219 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
220 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
221 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
222 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
223 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700224 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x06,
Eric Newberryf767eba2016-10-07 13:37:02 -0700225 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500226 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
227 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700228
Eric Newberryf767eba2016-10-07 13:37:02 -0700229 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500230 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700231
Davide Pesavento88eb7482017-02-18 19:25:58 -0500232 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
233 "FaceEvent(Kind: down,\n"
234 " FaceId: 20,\n"
235 " RemoteUri: tcp4://192.0.2.1:55555,\n"
236 " LocalUri: tcp4://192.0.2.2:6363,\n"
237 " FaceScope: local,\n"
238 " FacePersistency: on-demand,\n"
239 " LinkType: multi-access,\n"
240 " Flags: 0x6\n"
241 " )");
242}
243
244BOOST_AUTO_TEST_CASE(Equality)
245{
246 FaceEventNotification notification1, notification2;
247 BOOST_CHECK_EQUAL(notification1, notification2);
248
249 notification1.setKind(FACE_EVENT_CREATED)
250 .setFaceId(123)
251 .setRemoteUri("tcp4://192.0.2.1:55555")
252 .setLocalUri("tcp4://192.0.2.2:6363");
253 notification2 = notification1;
254 BOOST_CHECK_EQUAL(notification1, notification2);
255
256 notification2.setFaceId(42);
257 BOOST_CHECK_NE(notification1, notification2);
258
259 notification2 = notification1;
260 notification2.setKind(FACE_EVENT_DESTROYED);
261 BOOST_CHECK_NE(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700262}
263
Junxiao Shi7357ef22016-09-07 02:39:37 +0000264BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
265BOOST_AUTO_TEST_SUITE_END() // Nfd
266BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700267
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800268} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700269} // namespace nfd
270} // namespace ndn