blob: 09f024bd7fae3680ed0d88f7f5f9ec8f406c6e82 [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)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -070072 .setLinkType(LINK_TYPE_MULTI_ACCESS)
73 .setFlags(0x3);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070074 Block wire;
75 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
76
77 // These octets are obtained by the snippet below.
78 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -060079 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
80 // 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 };
91 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
92 wire.begin(), wire.end());
93
94 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
95 FaceEventNotification notification2(wire);
96 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
97 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
98 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
99 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -0600100 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
101 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
102 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700103 BOOST_CHECK_EQUAL(notification1.getFlags(), notification2.getFlags());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700104
105 std::ostringstream os;
106 os << notification2;
107 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
108 "Kind: created, "
109 "FaceID: 20, "
110 "RemoteUri: tcp4://192.0.2.1:55555, "
111 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600112 "FaceScope: local, "
113 "FacePersistency: on-demand, "
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700114 "LinkType: multi-access, "
115 "Flags: 0x3)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700116}
117
118BOOST_AUTO_TEST_CASE(EncodeDestroyed)
119{
120 FaceEventNotification notification1;
121 notification1.setKind(FACE_EVENT_DESTROYED)
122 .setFaceId(20)
123 .setRemoteUri("tcp4://192.0.2.1:55555")
124 .setLocalUri("tcp4://192.0.2.2:6363")
Chengyu Fan36dca992014-09-25 13:42:03 -0600125 .setFaceScope(FACE_SCOPE_LOCAL)
126 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700127 .setLinkType(LINK_TYPE_MULTI_ACCESS)
128 .setFlags(0x4);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700129 Block wire;
130 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
131
132 // These octets are obtained by the snippet below.
133 // This check is intended to detect unexpected encoding change in the future.
Chengyu Fan36dca992014-09-25 13:42:03 -0600134 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
135 // printf("0x%02x, ", *it);
136 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700137 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700138 0xc0, 0x41, 0xc1, 0x01, 0x02, 0x69, 0x01, 0x14, 0x72, 0x16,
Chengyu Fan36dca992014-09-25 13:42:03 -0600139 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
140 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
141 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
142 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
143 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700144 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x04,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700145 };
146 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
147 wire.begin(), wire.end());
148
149 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
150 FaceEventNotification notification2(wire);
151 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
152 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
153 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
154 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -0600155 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
156 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
157 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700158 BOOST_CHECK_EQUAL(notification1.getFlags(), notification2.getFlags());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700159
160 std::ostringstream os;
161 os << notification2;
162 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
163 "Kind: destroyed, "
164 "FaceID: 20, "
165 "RemoteUri: tcp4://192.0.2.1:55555, "
166 "LocalUri: tcp4://192.0.2.2:6363, "
Chengyu Fan36dca992014-09-25 13:42:03 -0600167 "FaceScope: local, "
168 "FacePersistency: on-demand, "
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700169 "LinkType: multi-access, "
170 "Flags: 0x4)");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700171}
172
Eric Newberryf767eba2016-10-07 13:37:02 -0700173BOOST_AUTO_TEST_CASE(EncodeUp)
174{
175 FaceEventNotification notification1;
176 notification1.setKind(FACE_EVENT_UP)
177 .setFaceId(20)
178 .setRemoteUri("tcp4://192.0.2.1:55555")
179 .setLocalUri("tcp4://192.0.2.2:6363")
180 .setFaceScope(FACE_SCOPE_LOCAL)
181 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700182 .setLinkType(LINK_TYPE_MULTI_ACCESS)
183 .setFlags(0x05);
Eric Newberryf767eba2016-10-07 13:37:02 -0700184 Block wire;
185 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
186
187 // These octets are obtained by the snippet below.
188 // This check is intended to detect unexpected encoding change in the future.
189 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
190 // printf("0x%02x, ", *it);
191 // }
192 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700193 0xc0, 0x41, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700194 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
195 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
196 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
197 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
198 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700199 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x05,
Eric Newberryf767eba2016-10-07 13:37:02 -0700200 };
201 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
202 wire.begin(), wire.end());
203
204 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
205 FaceEventNotification notification2(wire);
206 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
207 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
208 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
209 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
210 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
211 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
212 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
213
214 std::ostringstream os;
215 os << notification2;
216 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
217 "Kind: up, "
218 "FaceID: 20, "
219 "RemoteUri: tcp4://192.0.2.1:55555, "
220 "LocalUri: tcp4://192.0.2.2:6363, "
221 "FaceScope: local, "
222 "FacePersistency: on-demand, "
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700223 "LinkType: multi-access, "
224 "Flags: 0x5)");
Eric Newberryf767eba2016-10-07 13:37:02 -0700225}
226
227BOOST_AUTO_TEST_CASE(EncodeDown)
228{
229 FaceEventNotification notification1;
230 notification1.setKind(FACE_EVENT_DOWN)
231 .setFaceId(20)
232 .setRemoteUri("tcp4://192.0.2.1:55555")
233 .setLocalUri("tcp4://192.0.2.2:6363")
234 .setFaceScope(FACE_SCOPE_LOCAL)
235 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700236 .setLinkType(LINK_TYPE_MULTI_ACCESS)
237 .setFlags(0x06);
Eric Newberryf767eba2016-10-07 13:37:02 -0700238 Block wire;
239 BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
240
241 // These octets are obtained by the snippet below.
242 // This check is intended to detect unexpected encoding change in the future.
243 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
244 // printf("0x%02x, ", *it);
245 // }
246 static const uint8_t expected[] = {
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700247 0xc0, 0x41, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
Eric Newberryf767eba2016-10-07 13:37:02 -0700248 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
249 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
250 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
251 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
252 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700253 0x01, 0x86, 0x01, 0x01, 0x6c, 0x01, 0x06,
Eric Newberryf767eba2016-10-07 13:37:02 -0700254 };
255 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
256 wire.begin(), wire.end());
257
258 BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
259 FaceEventNotification notification2(wire);
260 BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
261 BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
262 BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
263 BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
264 BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
265 BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
266 BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
267
268 std::ostringstream os;
269 os << notification2;
270 BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
271 "Kind: down, "
272 "FaceID: 20, "
273 "RemoteUri: tcp4://192.0.2.1:55555, "
274 "LocalUri: tcp4://192.0.2.2:6363, "
275 "FaceScope: local, "
276 "FacePersistency: on-demand, "
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700277 "LinkType: multi-access, "
278 "Flags: 0x6)");
Eric Newberryf767eba2016-10-07 13:37:02 -0700279}
280
Junxiao Shi7357ef22016-09-07 02:39:37 +0000281BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
282BOOST_AUTO_TEST_SUITE_END() // Nfd
283BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700284
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800285} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700286} // namespace nfd
287} // namespace ndn