blob: c35660380404c6178495dbcb9fb524d85b7e2a67 [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/**
Junxiao Shi7357ef22016-09-07 02:39:37 +00003 * Copyright (c) 2013-2016 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"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070025
26namespace ndn {
27namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070029
Junxiao Shi7357ef22016-09-07 02:39:37 +000030BOOST_AUTO_TEST_SUITE(Mgmt)
31BOOST_AUTO_TEST_SUITE(Nfd)
32BOOST_AUTO_TEST_SUITE(TestFaceEventNotification)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070033
Chengyu Fan36dca992014-09-25 13:42:03 -060034BOOST_AUTO_TEST_CASE(Traits)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070035{
36 FaceEventNotification notification;
37
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
63BOOST_AUTO_TEST_CASE(EncodeCreated)
64{
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)
72 .setLinkType(LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070073 Block wire;
74 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
75
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[] = {
Chengyu Fan36dca992014-09-25 13:42:03 -060082 0xc0, 0x3e, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x14, 0x72, 0x16,
83 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,
88 0x01, 0x86, 0x01, 0x01,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070089 };
90 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
91 wire.begin(), wire.end());
92
93 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
94 FaceEventNotification notification2(wire);
95 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
96 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
97 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
98 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -060099 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
100 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
101 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700102
103 std::ostringstream os;
104 os << notification2;
105 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
106 "Kind: created, "
107 "FaceID: 20, "
108 "RemoteUri: tcp4://192.0.2.1:55555, "
109 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600110 "FaceScope: local, "
111 "FacePersistency: on-demand, "
112 "LinkType: multi-access)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700113}
114
115BOOST_AUTO_TEST_CASE(EncodeDestroyed)
116{
117 FaceEventNotification notification1;
118 notification1.setKind(FACE_EVENT_DESTROYED)
119 .setFaceId(20)
120 .setRemoteUri("tcp4://192.0.2.1:55555")
121 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600122 .setFaceScope(FACE_SCOPE_LOCAL)
123 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
124 .setLinkType(LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700125 Block wire;
126 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
127
128 // These octets are obtained by the snippet below.
129 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -0600130 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
131 // printf("0x%02x, ", *it);
132 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700133 static const uint8_t expected[] = {
Chengyu Fan36dca992014-09-25 13:42:03 -0600134 0xc0, 0x3e, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
135 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
136 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
137 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
138 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
139 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
140 0x01, 0x86, 0x01, 0x01,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700141 };
142 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
143 wire.begin(), wire.end());
144
145 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
146 FaceEventNotification notification2(wire);
147 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
148 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
149 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
150 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -0600151 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
152 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
153 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700154
155 std::ostringstream os;
156 os << notification2;
157 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
158 "Kind: destroyed, "
159 "FaceID: 20, "
160 "RemoteUri: tcp4://192.0.2.1:55555, "
161 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600162 "FaceScope: local, "
163 "FacePersistency: on-demand, "
164 "LinkType: multi-access)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700165}
166
Eric Newberryf767eba2016-10-07 13:37:02 -0700167BOOST_AUTO_TEST_CASE(EncodeUp)
168{
169 FaceEventNotification notification1;
170 notification1.setKind(FACE_EVENT_UP)
171 .setFaceId(20)
172 .setRemoteUri("tcp4://192.0.2.1:55555")
173 .setLocalUri("tcp4://192.0.2.2:6363")
174 .setFaceScope(FACE_SCOPE_LOCAL)
175 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
176 .setLinkType(LINK_TYPE_MULTI_ACCESS);
177 Block wire;
178 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
179
180 // These octets are obtained by the snippet below.
181 // This check is intended to detect unexpected encoding change in the future.
182 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
183 // printf("0x%02x, ", *it);
184 // }
185 static const uint8_t expected[] = {
186 0xc0, 0x3e, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
187 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
188 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
189 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
190 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
191 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
192 0x01, 0x86, 0x01, 0x01,
193 };
194 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
195 wire.begin(), wire.end());
196
197 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
198 FaceEventNotification notification2(wire);
199 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
200 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
201 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
202 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
203 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
204 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
205 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
206
207 std::ostringstream os;
208 os << notification2;
209 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
210 "Kind: up, "
211 "FaceID: 20, "
212 "RemoteUri: tcp4://192.0.2.1:55555, "
213 "LocalUri: tcp4://192.0.2.2:6363, "
214 "FaceScope: local, "
215 "FacePersistency: on-demand, "
216 "LinkType: multi-access)");
217}
218
219BOOST_AUTO_TEST_CASE(EncodeDown)
220{
221 FaceEventNotification notification1;
222 notification1.setKind(FACE_EVENT_DOWN)
223 .setFaceId(20)
224 .setRemoteUri("tcp4://192.0.2.1:55555")
225 .setLocalUri("tcp4://192.0.2.2:6363")
226 .setFaceScope(FACE_SCOPE_LOCAL)
227 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
228 .setLinkType(LINK_TYPE_MULTI_ACCESS);
229 Block wire;
230 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
231
232 // These octets are obtained by the snippet below.
233 // This check is intended to detect unexpected encoding change in the future.
234 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
235 // printf("0x%02x, ", *it);
236 // }
237 static const uint8_t expected[] = {
238 0xc0, 0x3e, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
239 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
240 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
241 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
242 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
243 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
244 0x01, 0x86, 0x01, 0x01,
245 };
246 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
247 wire.begin(), wire.end());
248
249 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
250 FaceEventNotification notification2(wire);
251 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
252 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
253 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
254 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
255 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
256 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
257 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
258
259 std::ostringstream os;
260 os << notification2;
261 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
262 "Kind: down, "
263 "FaceID: 20, "
264 "RemoteUri: tcp4://192.0.2.1:55555, "
265 "LocalUri: tcp4://192.0.2.2:6363, "
266 "FaceScope: local, "
267 "FacePersistency: on-demand, "
268 "LinkType: multi-access)");
269}
270
Junxiao Shi7357ef22016-09-07 02:39:37 +0000271BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
272BOOST_AUTO_TEST_SUITE_END() // Nfd
273BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700274
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800275} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700276} // namespace nfd
277} // namespace ndn