blob: dee1de2a27f99c900fe012be22e8f6356d64ee79 [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/*
3 * Copyright (c) 2013-2018 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-status.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070023
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -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(TestFaceStatus)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070034
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050035static FaceStatus
36makeFaceStatus()
37{
38 return FaceStatus()
39 .setFaceId(100)
40 .setRemoteUri("tcp4://192.0.2.1:6363")
41 .setLocalUri("tcp4://192.0.2.2:55555")
42 .setFaceScope(FACE_SCOPE_LOCAL)
43 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
44 .setLinkType(LINK_TYPE_MULTI_ACCESS)
Davide Pesavento0f830802018-01-16 23:58:58 -050045 .setExpirationPeriod(10_s)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050046 .setNInInterests(10)
Junxiao Shi9a53d782017-04-04 20:09:57 +000047 .setNInData(200)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050048 .setNInNacks(1)
49 .setNOutInterests(3000)
Junxiao Shi9a53d782017-04-04 20:09:57 +000050 .setNOutData(4)
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050051 .setNOutNacks(2)
52 .setNInBytes(1329719163)
53 .setNOutBytes(999110448)
54 .setFlags(0x7);
55}
56
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070057BOOST_AUTO_TEST_CASE(Encode)
58{
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050059 FaceStatus status1 = makeFaceStatus();
60 Block wire = status1.wireEncode();
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070061
62 // These octets are obtained by the snippet below.
63 // This check is intended to detect unexpected encoding change in the future.
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070064 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050065 // printf("0x%02x, ", *it);
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070066 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070067 static const uint8_t expected[] = {
Eric Newberry1ce8ab22016-09-24 11:57:21 -070068 0x80, 0x61, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
Chengyu Fan36dca992014-09-25 13:42:03 -060069 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e,
70 0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16,
71 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
72 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35,
73 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85,
74 0x01, 0x01, 0x86, 0x01, 0x01, 0x90, 0x01, 0x0a, 0x91, 0x01,
Eric Newberry95bd96a2015-09-04 23:34:22 -070075 0xc8, 0x97, 0x01, 0x01, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01,
76 0x04, 0x98, 0x01, 0x02, 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b,
Eric Newberry1ce8ab22016-09-24 11:57:21 -070077 0x95, 0x04, 0x3b, 0x8d, 0x37, 0x30, 0x6c, 0x01, 0x07,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070078 };
Junxiao Shi13e637f2014-07-16 19:20:40 -070079 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
80 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070081
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070082 FaceStatus status2(wire);
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050083 BOOST_CHECK_EQUAL(status1, status2);
84}
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070085
Davide Pesavento4ec7a5a2017-02-07 23:13:39 -050086BOOST_AUTO_TEST_CASE(Equality)
87{
88 FaceStatus status1, status2;
89
90 status1 = makeFaceStatus();
91 status2 = status1;
92 BOOST_CHECK_EQUAL(status1, status2);
93
94 status2.setFaceId(42);
95 BOOST_CHECK_NE(status1, status2);
96}
97
98BOOST_AUTO_TEST_CASE(Print)
99{
100 FaceStatus status;
101 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
102 "Face(FaceId: 0,\n"
103 " RemoteUri: ,\n"
104 " LocalUri: ,\n"
105 " ExpirationPeriod: infinite,\n"
106 " FaceScope: non-local,\n"
107 " FacePersistency: persistent,\n"
108 " LinkType: point-to-point,\n"
109 " Flags: 0x0,\n"
110 " Counters: {Interests: {in: 0, out: 0},\n"
111 " Data: {in: 0, out: 0},\n"
112 " Nacks: {in: 0, out: 0},\n"
113 " bytes: {in: 0, out: 0}}\n"
114 " )");
115
116 status = makeFaceStatus();
117 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
118 "Face(FaceId: 100,\n"
119 " RemoteUri: tcp4://192.0.2.1:6363,\n"
120 " LocalUri: tcp4://192.0.2.2:55555,\n"
121 " ExpirationPeriod: 10000 milliseconds,\n"
122 " FaceScope: local,\n"
123 " FacePersistency: on-demand,\n"
124 " LinkType: multi-access,\n"
125 " Flags: 0x7,\n"
126 " Counters: {Interests: {in: 10, out: 3000},\n"
127 " Data: {in: 200, out: 4},\n"
128 " Nacks: {in: 1, out: 2},\n"
129 " bytes: {in: 1329719163, out: 999110448}}\n"
130 " )");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700131}
132
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400133BOOST_AUTO_TEST_CASE(ExpirationPeriod)
134{
135 FaceStatus status;
136 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false);
137
Davide Pesavento0f830802018-01-16 23:58:58 -0500138 status.setExpirationPeriod(1_min);
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400139 BOOST_REQUIRE_EQUAL(status.hasExpirationPeriod(), true);
Davide Pesavento0f830802018-01-16 23:58:58 -0500140 BOOST_CHECK_EQUAL(status.getExpirationPeriod(), 1_min);
Davide Pesavento156c1ea2017-03-19 16:09:33 -0400141
142 status.unsetExpirationPeriod();
143 BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false);
144}
145
Eric Newberry1ce8ab22016-09-24 11:57:21 -0700146BOOST_AUTO_TEST_CASE(FlagBit)
147{
148 FaceStatus status;
149 status.setFlags(0x7);
150 BOOST_CHECK_EQUAL(status.getFlags(), 0x7);
151
152 BOOST_CHECK(status.getFlagBit(0));
153 BOOST_CHECK(status.getFlagBit(1));
154 BOOST_CHECK(status.getFlagBit(2));
155 BOOST_CHECK(!status.getFlagBit(3));
156
157 status.setFlagBit(3, true);
158 BOOST_CHECK_EQUAL(status.getFlags(), 0xf);
159 BOOST_CHECK(status.getFlagBit(3));
160
161 status.setFlagBit(1, false);
162 BOOST_CHECK_EQUAL(status.getFlags(), 0xd);
163 BOOST_CHECK(!status.getFlagBit(1));
164}
165
Junxiao Shi7357ef22016-09-07 02:39:37 +0000166BOOST_AUTO_TEST_SUITE_END() // TestFaceStatus
167BOOST_AUTO_TEST_SUITE_END() // Nfd
168BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700169
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800170} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700171} // namespace nfd
172} // namespace ndn