blob: f899ce9414d81d6e45ee4c73c7853b90fd047f8a [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ju Pandca56ea2018-10-24 06:20:44 +00002/*
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 Shi5109dee2014-03-27 19:40:30 -070020 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/mgmt/nfd/forwarder-status.hpp"
Junxiao Shi5109dee2014-03-27 19:40:30 -070023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050025#include <boost/lexical_cast.hpp>
Junxiao Shi5109dee2014-03-27 19:40:30 -070026
27namespace ndn {
28namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace tests {
Junxiao Shi5109dee2014-03-27 19:40:30 -070030
Junxiao Shi7357ef22016-09-07 02:39:37 +000031BOOST_AUTO_TEST_SUITE(Mgmt)
32BOOST_AUTO_TEST_SUITE(Nfd)
33BOOST_AUTO_TEST_SUITE(TestForwarderStatus)
Junxiao Shi5109dee2014-03-27 19:40:30 -070034
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050035static ForwarderStatus
36makeForwarderStatus()
37{
38 return ForwarderStatus()
39 .setNfdVersion("0.5.1-14-g05dd444")
40 .setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325LL)))
41 .setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272LL)))
42 .setNNameTreeEntries(1849943160)
43 .setNFibEntries(621739748)
44 .setNPitEntries(482129741)
45 .setNMeasurementsEntries(1771725298)
46 .setNCsEntries(1264968688)
47 .setNInInterests(612811615)
Junxiao Shi9a53d782017-04-04 20:09:57 +000048 .setNInData(1843576050)
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050049 .setNInNacks(1234)
50 .setNOutInterests(952144445)
Junxiao Shi9a53d782017-04-04 20:09:57 +000051 .setNOutData(138198826)
Ju Pandca56ea2018-10-24 06:20:44 +000052 .setNOutNacks(4321)
53 .setNSatisfiedInterests(961020)
54 .setNUnsatisfiedInterests(941024);
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050055}
56
Junxiao Shi5109dee2014-03-27 19:40:30 -070057BOOST_AUTO_TEST_CASE(Encode)
58{
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050059 ForwarderStatus status1 = makeForwarderStatus();
60 Block wire = status1.wireEncode();
Junxiao Shi5109dee2014-03-27 19:40:30 -070061
62 // These octets are obtained by the snippet below.
63 // This check is intended to detect unexpected encoding change in the future.
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050064 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
65 // printf("0x%02x, ", *it);
66 // }
Junxiao Shi5109dee2014-03-27 19:40:30 -070067 static const uint8_t expected[] = {
Ju Pandca56ea2018-10-24 06:20:44 +000068 0x15, 0x71, 0x80, 0x11, 0x30, 0x2e, 0x35, 0x2e, 0x31, 0x2d, 0x31, 0x34,
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050069 0x2d, 0x67, 0x30, 0x35, 0x64, 0x64, 0x34, 0x34, 0x34, 0x81, 0x08, 0x00,
Hila Ben Abraham23f9e782014-12-02 02:21:34 -060070 0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00,
71 0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84,
72 0x04, 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86,
73 0x04, 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90,
Eric Newberry95bd96a2015-09-04 23:34:22 -070074 0x04, 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x97,
75 0x02, 0x04, 0xd2, 0x92, 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08,
Ju Pandca56ea2018-10-24 06:20:44 +000076 0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1, 0x99, 0x04, 0x00, 0x0e, 0xa9,
77 0xfc, 0x9a, 0x04, 0x00, 0x0e, 0x5b, 0xe0,
Junxiao Shi5109dee2014-03-27 19:40:30 -070078 };
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050079 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
80 wire.begin(), wire.end());
Junxiao Shi5109dee2014-03-27 19:40:30 -070081
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050082 ForwarderStatus status2(wire);
83 BOOST_CHECK_EQUAL(status1, status2);
84}
Junxiao Shi5109dee2014-03-27 19:40:30 -070085
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050086BOOST_AUTO_TEST_CASE(Equality)
87{
88 ForwarderStatus status1, status2;
89
90 status1 = makeForwarderStatus();
91 status2 = status1;
92 BOOST_CHECK_EQUAL(status1, status2);
93
94 status2.setNPitEntries(42);
95 BOOST_CHECK_NE(status1, status2);
96}
97
98BOOST_AUTO_TEST_CASE(Print)
99{
100 ForwarderStatus status;
101 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
102 "GeneralStatus(NfdVersion: ,\n"
103 " StartTimestamp: 0 nanoseconds since Jan 1, 1970,\n"
104 " CurrentTimestamp: 0 nanoseconds since Jan 1, 1970,\n"
105 " Counters: {NameTreeEntries: 0,\n"
106 " FibEntries: 0,\n"
107 " PitEntries: 0,\n"
108 " MeasurementsEntries: 0,\n"
109 " CsEntries: 0,\n"
110 " Interests: {in: 0, out: 0},\n"
111 " Data: {in: 0, out: 0},\n"
Ju Pandca56ea2018-10-24 06:20:44 +0000112 " Nacks: {in: 0, out: 0},\n"
113 " SatisfiedInterests: 0,\n"
114 " UnsatisfiedInterests: 0}\n"
Davide Pesavento25e3d8c2017-02-08 22:17:46 -0500115 " )");
116
117 status = makeForwarderStatus();
118 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
119 "GeneralStatus(NfdVersion: 0.5.1-14-g05dd444,\n"
120 " StartTimestamp: 375193249325000000 nanoseconds since Jan 1, 1970,\n"
121 " CurrentTimestamp: 886109034272000000 nanoseconds since Jan 1, 1970,\n"
122 " Counters: {NameTreeEntries: 1849943160,\n"
123 " FibEntries: 621739748,\n"
124 " PitEntries: 482129741,\n"
125 " MeasurementsEntries: 1771725298,\n"
126 " CsEntries: 1264968688,\n"
127 " Interests: {in: 612811615, out: 952144445},\n"
128 " Data: {in: 1843576050, out: 138198826},\n"
Ju Pandca56ea2018-10-24 06:20:44 +0000129 " Nacks: {in: 1234, out: 4321},\n"
130 " SatisfiedInterests: 961020,\n"
131 " UnsatisfiedInterests: 941024}\n"
Davide Pesavento25e3d8c2017-02-08 22:17:46 -0500132 " )");
Junxiao Shi5109dee2014-03-27 19:40:30 -0700133}
134
Junxiao Shi7357ef22016-09-07 02:39:37 +0000135BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatus
136BOOST_AUTO_TEST_SUITE_END() // Nfd
137BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi5109dee2014-03-27 19:40:30 -0700138
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800139} // namespace tests
Junxiao Shi5109dee2014-03-27 19:40:30 -0700140} // namespace nfd
141} // namespace ndn