blob: 249cd63ebe3408b9e34407b67a50d635e9290c7e [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -07002/**
Davide Pesavento88eb7482017-02-18 19:25:58 -05003 * Copyright (c) 2013-2017 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
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#include "mgmt/nfd/face-event-notification.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070023
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Davide Pesavento88eb7482017-02-18 19:25:58 -050025#include <boost/lexical_cast.hpp>
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070026
27namespace ndn {
28namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace tests {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070030
Junxiao Shi7357ef22016-09-07 02:39:37 +000031BOOST_AUTO_TEST_SUITE(Mgmt)
32BOOST_AUTO_TEST_SUITE(Nfd)
33BOOST_AUTO_TEST_SUITE(TestFaceEventNotification)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070034
Chengyu Fan36dca992014-09-25 13:42:03 -060035BOOST_AUTO_TEST_CASE(Traits)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070036{
37 FaceEventNotification notification;
Chengyu Fan36dca992014-09-25 13:42:03 -060038 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_NON_LOCAL);
39 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
40 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070041
Chengyu Fan36dca992014-09-25 13:42:03 -060042 notification.setFaceScope(FACE_SCOPE_LOCAL);
43 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
44 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT);
45 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070046
Chengyu Fan36dca992014-09-25 13:42:03 -060047 notification.setFacePersistency(FACE_PERSISTENCY_ON_DEMAND);
48 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
49 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_ON_DEMAND);
50 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070051
Chengyu Fan36dca992014-09-25 13:42:03 -060052 notification.setFacePersistency(FACE_PERSISTENCY_PERMANENT);
53 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
54 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
55 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_POINT_TO_POINT);
56
57 notification.setLinkType(LINK_TYPE_MULTI_ACCESS);
58 BOOST_CHECK_EQUAL(notification.getFaceScope(), FACE_SCOPE_LOCAL);
59 BOOST_CHECK_EQUAL(notification.getFacePersistency(), FACE_PERSISTENCY_PERMANENT);
60 BOOST_CHECK_EQUAL(notification.getLinkType(), LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070061}
62
Davide Pesavento88eb7482017-02-18 19:25:58 -050063BOOST_AUTO_TEST_CASE(Created)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070064{
65 FaceEventNotification notification1;
66 notification1.setKind(FACE_EVENT_CREATED)
67 .setFaceId(20)
68 .setRemoteUri("tcp4://192.0.2.1:55555")
69 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -060070 .setFaceScope(FACE_SCOPE_LOCAL)
71 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070072 .setLinkType(LINK_TYPE_MULTI_ACCESS)
73 .setFlags(0x3);
Davide Pesavento88eb7482017-02-18 19:25:58 -050074 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070075
76 // These octets are obtained by the snippet below.
77 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -060078 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
79 // printf("0x%02x, ", *it);
80 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070081 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070082 0xc0, 0x41, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -060083 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
84 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
85 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
86 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
87 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070088 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x03,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070089 };
Davide Pesavento88eb7482017-02-18 19:25:58 -050090 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
91 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070092
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070093 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -050094 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070095
Davide Pesavento88eb7482017-02-18 19:25:58 -050096 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
97 "FaceEvent(Kind: created,\n"
98 " FaceId: 20,\n"
99 " RemoteUri: tcp4://192.0.2.1:55555,\n"
100 " LocalUri: tcp4://192.0.2.2:6363,\n"
101 " FaceScope: local,\n"
102 " FacePersistency: on-demand,\n"
103 " LinkType: multi-access,\n"
104 " Flags: 0x3\n"
105 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700106}
107
Davide Pesavento88eb7482017-02-18 19:25:58 -0500108BOOST_AUTO_TEST_CASE(Destroyed)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700109{
110 FaceEventNotification notification1;
111 notification1.setKind(FACE_EVENT_DESTROYED)
112 .setFaceId(20)
113 .setRemoteUri("tcp4://192.0.2.1:55555")
114 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600115 .setFaceScope(FACE_SCOPE_LOCAL)
116 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700117 .setLinkType(LINK_TYPE_MULTI_ACCESS)
118 .setFlags(0x4);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500119 Block wire = notification1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700120
121 // These octets are obtained by the snippet below.
122 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -0600123 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
124 // printf("0x%02x, ", *it);
125 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700126 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700127 0xc0, 0x41, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -0600128 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
129 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
130 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
131 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
132 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700133 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x04,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700134 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500135 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
136 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700137
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700138 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500139 BOOST_CHECK_EQUAL(notification1, notification2);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700140
Davide Pesavento88eb7482017-02-18 19:25:58 -0500141 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
142 "FaceEvent(Kind: destroyed,\n"
143 " FaceId: 20,\n"
144 " RemoteUri: tcp4://192.0.2.1:55555,\n"
145 " LocalUri: tcp4://192.0.2.2:6363,\n"
146 " FaceScope: local,\n"
147 " FacePersistency: on-demand,\n"
148 " LinkType: multi-access,\n"
149 " Flags: 0x4\n"
150 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700151}
152
Davide Pesavento88eb7482017-02-18 19:25:58 -0500153BOOST_AUTO_TEST_CASE(Up)
Eric Newberryf767eba2016-10-07 13:37:02 -0700154{
155 FaceEventNotification notification1;
156 notification1.setKind(FACE_EVENT_UP)
157 .setFaceId(20)
158 .setRemoteUri("tcp4://192.0.2.1:55555")
159 .setLocalUri("tcp4://192.0.2.2:6363")
160 .setFaceScope(FACE_SCOPE_LOCAL)
161 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700162 .setLinkType(LINK_TYPE_MULTI_ACCESS)
163 .setFlags(0x05);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500164 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700165
166 // These octets are obtained by the snippet below.
167 // This check is intended to detect unexpected encoding change in the future.
168 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
169 // printf("0x%02x, ", *it);
170 // }
171 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700172 0xc0, 0x41, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700173 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
174 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
175 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
176 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
177 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700178 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x05,
Eric Newberryf767eba2016-10-07 13:37:02 -0700179 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500180 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
181 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700182
Eric Newberryf767eba2016-10-07 13:37:02 -0700183 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500184 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700185
Davide Pesavento88eb7482017-02-18 19:25:58 -0500186 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
187 "FaceEvent(Kind: up,\n"
188 " FaceId: 20,\n"
189 " RemoteUri: tcp4://192.0.2.1:55555,\n"
190 " LocalUri: tcp4://192.0.2.2:6363,\n"
191 " FaceScope: local,\n"
192 " FacePersistency: on-demand,\n"
193 " LinkType: multi-access,\n"
194 " Flags: 0x5\n"
195 " )");
Eric Newberryf767eba2016-10-07 13:37:02 -0700196}
197
Davide Pesavento88eb7482017-02-18 19:25:58 -0500198BOOST_AUTO_TEST_CASE(Down)
Eric Newberryf767eba2016-10-07 13:37:02 -0700199{
200 FaceEventNotification notification1;
201 notification1.setKind(FACE_EVENT_DOWN)
202 .setFaceId(20)
203 .setRemoteUri("tcp4://192.0.2.1:55555")
204 .setLocalUri("tcp4://192.0.2.2:6363")
205 .setFaceScope(FACE_SCOPE_LOCAL)
206 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700207 .setLinkType(LINK_TYPE_MULTI_ACCESS)
208 .setFlags(0x06);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500209 Block wire = notification1.wireEncode();
Eric Newberryf767eba2016-10-07 13:37:02 -0700210
211 // These octets are obtained by the snippet below.
212 // This check is intended to detect unexpected encoding change in the future.
213 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
214 // printf("0x%02x, ", *it);
215 // }
216 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700217 0xc0, 0x41, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700218 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
219 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
220 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
221 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
222 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700223 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x06,
Eric Newberryf767eba2016-10-07 13:37:02 -0700224 };
Davide Pesavento88eb7482017-02-18 19:25:58 -0500225 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
226 wire.begin(), wire.end());
Eric Newberryf767eba2016-10-07 13:37:02 -0700227
Eric Newberryf767eba2016-10-07 13:37:02 -0700228 FaceEventNotification notification2(wire);
Davide Pesavento88eb7482017-02-18 19:25:58 -0500229 BOOST_CHECK_EQUAL(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700230
Davide Pesavento88eb7482017-02-18 19:25:58 -0500231 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(notification2),
232 "FaceEvent(Kind: down,\n"
233 " FaceId: 20,\n"
234 " RemoteUri: tcp4://192.0.2.1:55555,\n"
235 " LocalUri: tcp4://192.0.2.2:6363,\n"
236 " FaceScope: local,\n"
237 " FacePersistency: on-demand,\n"
238 " LinkType: multi-access,\n"
239 " Flags: 0x6\n"
240 " )");
241}
242
243BOOST_AUTO_TEST_CASE(Equality)
244{
245 FaceEventNotification notification1, notification2;
246 BOOST_CHECK_EQUAL(notification1, notification2);
247
248 notification1.setKind(FACE_EVENT_CREATED)
249 .setFaceId(123)
250 .setRemoteUri("tcp4://192.0.2.1:55555")
251 .setLocalUri("tcp4://192.0.2.2:6363");
252 notification2 = notification1;
253 BOOST_CHECK_EQUAL(notification1, notification2);
254
255 notification2.setFaceId(42);
256 BOOST_CHECK_NE(notification1, notification2);
257
258 notification2 = notification1;
259 notification2.setKind(FACE_EVENT_DESTROYED);
260 BOOST_CHECK_NE(notification1, notification2);
Eric Newberryf767eba2016-10-07 13:37:02 -0700261}
262
Junxiao Shi7357ef22016-09-07 02:39:37 +0000263BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
264BOOST_AUTO_TEST_SUITE_END() // Nfd
265BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700266
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800267} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700268} // namespace nfd
269} // namespace ndn