Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 2 | /** |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * 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 Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "mgmt/nfd/forwarder-status.hpp" |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 25 | #include <boost/lexical_cast.hpp> |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | namespace tests { |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 32 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 33 | BOOST_AUTO_TEST_SUITE(TestForwarderStatus) |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 35 | static ForwarderStatus |
| 36 | makeForwarderStatus() |
| 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 Shi | 9a53d78 | 2017-04-04 20:09:57 +0000 | [diff] [blame] | 48 | .setNInData(1843576050) |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 49 | .setNInNacks(1234) |
| 50 | .setNOutInterests(952144445) |
Junxiao Shi | 9a53d78 | 2017-04-04 20:09:57 +0000 | [diff] [blame] | 51 | .setNOutData(138198826) |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 52 | .setNOutNacks(4321); |
| 53 | } |
| 54 | |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 55 | BOOST_AUTO_TEST_CASE(Encode) |
| 56 | { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 57 | ForwarderStatus status1 = makeForwarderStatus(); |
| 58 | Block wire = status1.wireEncode(); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 59 | |
| 60 | // These octets are obtained by the snippet below. |
| 61 | // This check is intended to detect unexpected encoding change in the future. |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 62 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 63 | // printf("0x%02x, ", *it); |
| 64 | // } |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 65 | static const uint8_t expected[] = { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 66 | 0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x35, 0x2e, 0x31, 0x2d, 0x31, 0x34, |
| 67 | 0x2d, 0x67, 0x30, 0x35, 0x64, 0x64, 0x34, 0x34, 0x34, 0x81, 0x08, 0x00, |
Hila Ben Abraham | 23f9e78 | 2014-12-02 02:21:34 -0600 | [diff] [blame] | 68 | 0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00, |
| 69 | 0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84, |
| 70 | 0x04, 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86, |
| 71 | 0x04, 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 72 | 0x04, 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x97, |
| 73 | 0x02, 0x04, 0xd2, 0x92, 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, |
| 74 | 0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1, |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 75 | }; |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 77 | wire.begin(), wire.end()); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 78 | |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 79 | ForwarderStatus status2(wire); |
| 80 | BOOST_CHECK_EQUAL(status1, status2); |
| 81 | } |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 82 | |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 83 | BOOST_AUTO_TEST_CASE(Equality) |
| 84 | { |
| 85 | ForwarderStatus status1, status2; |
| 86 | |
| 87 | status1 = makeForwarderStatus(); |
| 88 | status2 = status1; |
| 89 | BOOST_CHECK_EQUAL(status1, status2); |
| 90 | |
| 91 | status2.setNPitEntries(42); |
| 92 | BOOST_CHECK_NE(status1, status2); |
| 93 | } |
| 94 | |
| 95 | BOOST_AUTO_TEST_CASE(Print) |
| 96 | { |
| 97 | ForwarderStatus status; |
| 98 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
| 99 | "GeneralStatus(NfdVersion: ,\n" |
| 100 | " StartTimestamp: 0 nanoseconds since Jan 1, 1970,\n" |
| 101 | " CurrentTimestamp: 0 nanoseconds since Jan 1, 1970,\n" |
| 102 | " Counters: {NameTreeEntries: 0,\n" |
| 103 | " FibEntries: 0,\n" |
| 104 | " PitEntries: 0,\n" |
| 105 | " MeasurementsEntries: 0,\n" |
| 106 | " CsEntries: 0,\n" |
| 107 | " Interests: {in: 0, out: 0},\n" |
| 108 | " Data: {in: 0, out: 0},\n" |
| 109 | " Nacks: {in: 0, out: 0}}\n" |
| 110 | " )"); |
| 111 | |
| 112 | status = makeForwarderStatus(); |
| 113 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
| 114 | "GeneralStatus(NfdVersion: 0.5.1-14-g05dd444,\n" |
| 115 | " StartTimestamp: 375193249325000000 nanoseconds since Jan 1, 1970,\n" |
| 116 | " CurrentTimestamp: 886109034272000000 nanoseconds since Jan 1, 1970,\n" |
| 117 | " Counters: {NameTreeEntries: 1849943160,\n" |
| 118 | " FibEntries: 621739748,\n" |
| 119 | " PitEntries: 482129741,\n" |
| 120 | " MeasurementsEntries: 1771725298,\n" |
| 121 | " CsEntries: 1264968688,\n" |
| 122 | " Interests: {in: 612811615, out: 952144445},\n" |
| 123 | " Data: {in: 1843576050, out: 138198826},\n" |
| 124 | " Nacks: {in: 1234, out: 4321}}\n" |
| 125 | " )"); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 128 | BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatus |
| 129 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 130 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 131 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 132 | } // namespace tests |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 133 | } // namespace nfd |
| 134 | } // namespace ndn |