blob: 24be329c15d61a3fc87a41d75735cd4e1461caea [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0f830802018-01-16 23:58:58 -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-status.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 Pesavento4ec7a5a2017-02-07 23:13:39 -050027#include <boost/lexical_cast.hpp>
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070028
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040029namespace ndn::tests {
30
31using namespace ndn::nfd;
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070032
Davide Pesavento152ef442023-04-22 02:02:29 -040033BOOST_CONCEPT_ASSERT((StatusDatasetItem<FaceStatus>));
34
Junxiao Shi7357ef22016-09-07 02:39:37 +000035BOOST_AUTO_TEST_SUITE(Mgmt)
36BOOST_AUTO_TEST_SUITE(Nfd)
37BOOST_AUTO_TEST_SUITE(TestFaceStatus)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070038
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050039static FaceStatus
40makeFaceStatus()
41{
42 return FaceStatus()
43 .setFaceId(100)
44 .setRemoteUri("tcp4://192.0.2.1:6363")
45 .setLocalUri("tcp4://192.0.2.2:55555")
46 .setFaceScope(FACE_SCOPE_LOCAL)
47 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
48 .setLinkType(LINK_TYPE_MULTI_ACCESS)
Davide Pesavento0f830802018-01-16 23:58:58 -050049 .setExpirationPeriod(10_s)
Eric Newberry07d05c92018-01-22 16:08:01 -070050 .setBaseCongestionMarkingInterval(5_ns)
51 .setDefaultCongestionThreshold(7)
Eric Newberry3c9bc042018-06-02 17:58:10 -070052 .setMtu(9)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050053 .setNInInterests(10)
Junxiao Shi9a53d782017-04-04 20:09:57 +000054 .setNInData(200)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050055 .setNInNacks(1)
56 .setNOutInterests(3000)
Junxiao Shi9a53d782017-04-04 20:09:57 +000057 .setNOutData(4)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050058 .setNOutNacks(2)
59 .setNInBytes(1329719163)
60 .setNOutBytes(999110448)
61 .setFlags(0x7);
62}
63
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070064BOOST_AUTO_TEST_CASE(Encode)
65{
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050066 FaceStatus status1 = makeFaceStatus();
67 Block wire = status1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070068
69 // These octets are obtained by the snippet below.
70 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050071 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050072 // printf("0x%02x, ", *it);
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070073 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070074 static const uint8_t expected[] = {
Eric Newberry3c9bc042018-06-02 17:58:10 -070075 0x80, 0x6a, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
Chengyu Fan36dca992014-09-25 13:42:03 -060076 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e,
77 0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16,
78 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
79 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35,
80 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85,
Eric Newberry07d05c92018-01-22 16:08:01 -070081 0x01, 0x01, 0x86, 0x01, 0x01, 0x87, 0x01, 0x05, 0x88, 0x01,
Eric Newberry3c9bc042018-06-02 17:58:10 -070082 0x07, 0x89, 0x01, 0x09, 0x90, 0x01, 0x0a, 0x91, 0x01, 0xc8,
83 0x97, 0x01, 0x01, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04,
84 0x98, 0x01, 0x02, 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b, 0x95,
85 0x04, 0x3b, 0x8d, 0x37, 0x30, 0x6c, 0x01, 0x07,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070086 };
Junxiao Shi13e637f2014-07-16 19:20:40 -070087 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
88 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070089
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070090 FaceStatus status2(wire);
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050091 BOOST_CHECK_EQUAL(status1, status2);
92}
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070093
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050094BOOST_AUTO_TEST_CASE(Equality)
95{
96 FaceStatus status1, status2;
97
98 status1 = makeFaceStatus();
99 status2 = status1;
100 BOOST_CHECK_EQUAL(status1, status2);
101
102 status2.setFaceId(42);
103 BOOST_CHECK_NE(status1, status2);
104}
105
106BOOST_AUTO_TEST_CASE(Print)
107{
108 FaceStatus status;
109 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
110 "Face(FaceId: 0,\n"
111 " RemoteUri: ,\n"
112 " LocalUri: ,\n"
113 " ExpirationPeriod: infinite,\n"
114 " FaceScope: non-local,\n"
115 " FacePersistency: persistent,\n"
116 " LinkType: point-to-point,\n"
117 " Flags: 0x0,\n"
118 " Counters: {Interests: {in: 0, out: 0},\n"
119 " Data: {in: 0, out: 0},\n"
120 " Nacks: {in: 0, out: 0},\n"
121 " bytes: {in: 0, out: 0}}\n"
122 " )");
123
124 status = makeFaceStatus();
125 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
126 "Face(FaceId: 100,\n"
127 " RemoteUri: tcp4://192.0.2.1:6363,\n"
128 " LocalUri: tcp4://192.0.2.2:55555,\n"
129 " ExpirationPeriod: 10000 milliseconds,\n"
130 " FaceScope: local,\n"
131 " FacePersistency: on-demand,\n"
132 " LinkType: multi-access,\n"
Eric Newberry07d05c92018-01-22 16:08:01 -0700133 " BaseCongestionMarkingInterval: 5 nanoseconds,\n"
134 " DefaultCongestionThreshold: 7 bytes,\n"
Eric Newberry3c9bc042018-06-02 17:58:10 -0700135 " Mtu: 9 bytes,\n"
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -0500136 " Flags: 0x7,\n"
137 " Counters: {Interests: {in: 10, out: 3000},\n"
138 " Data: {in: 200, out: 4},\n"
139 " Nacks: {in: 1, out: 2},\n"
140 " bytes: {in: 1329719163, out: 999110448}}\n"
141 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700142}
143
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400144BOOST_AUTO_TEST_CASE(ExpirationPeriod)
145{
146 FaceStatus status;
147 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false);
148
Davide Pesavento0f830802018-01-16 23:58:58 -0500149 status.setExpirationPeriod(1_min);
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400150 BOOST_REQUIRE_EQUAL(status.hasExpirationPeriod(), true);
Davide Pesavento0f830802018-01-16 23:58:58 -0500151 BOOST_CHECK_EQUAL(status.getExpirationPeriod(), 1_min);
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400152
153 status.unsetExpirationPeriod();
154 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false);
155}
156
Eric Newberry1ce8ab22016-09-24 11:57:21 -0700157BOOST_AUTO_TEST_CASE(FlagBit)
158{
159 FaceStatus status;
160 status.setFlags(0x7);
161 BOOST_CHECK_EQUAL(status.getFlags(), 0x7);
162
163 BOOST_CHECK(status.getFlagBit(0));
164 BOOST_CHECK(status.getFlagBit(1));
165 BOOST_CHECK(status.getFlagBit(2));
166 BOOST_CHECK(!status.getFlagBit(3));
167
168 status.setFlagBit(3, true);
169 BOOST_CHECK_EQUAL(status.getFlags(), 0xf);
170 BOOST_CHECK(status.getFlagBit(3));
171
172 status.setFlagBit(1, false);
173 BOOST_CHECK_EQUAL(status.getFlags(), 0xd);
174 BOOST_CHECK(!status.getFlagBit(1));
175}
176
Junxiao Shi7357ef22016-09-07 02:39:37 +0000177BOOST_AUTO_TEST_SUITE_END() // TestFaceStatus
178BOOST_AUTO_TEST_SUITE_END() // Nfd
179BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700180
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400181} // namespace ndn::tests