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 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 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 | |
| 22 | #include "management/nfd-forwarder-status.hpp" |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 23 | #include "data.hpp" |
| 24 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 25 | #include "boost-test.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 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(ManagementNfdForwarderStatus) |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 32 | |
| 33 | BOOST_AUTO_TEST_CASE(Encode) |
| 34 | { |
| 35 | ForwarderStatus status1; |
Hila Ben Abraham | 23f9e78 | 2014-12-02 02:21:34 -0600 | [diff] [blame] | 36 | status1.setNfdVersion("0.2.0-65-g75ab6b7"); |
Alexander Afanasyev | 0bb9aae | 2014-04-21 18:08:18 -0700 | [diff] [blame] | 37 | status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325LL))); |
| 38 | status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272LL))); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 39 | status1.setNNameTreeEntries(1849943160); |
| 40 | status1.setNFibEntries(621739748); |
| 41 | status1.setNPitEntries(482129741); |
| 42 | status1.setNMeasurementsEntries(1771725298); |
| 43 | status1.setNCsEntries(1264968688); |
| 44 | status1.setNInInterests(612811615); |
| 45 | status1.setNInDatas(1843576050); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 46 | status1.setNInNacks(1234); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 47 | status1.setNOutInterests(952144445); |
| 48 | status1.setNOutDatas(138198826); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 49 | status1.setNOutNacks(4321); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 51 | Block wire; |
| 52 | BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode()); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 53 | |
| 54 | // These octets are obtained by the snippet below. |
| 55 | // This check is intended to detect unexpected encoding change in the future. |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 56 | //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 57 | // printf("0x%02x, ", *it); |
| 58 | //} |
| 59 | static const uint8_t expected[] = { |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 60 | 0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35, |
Hila Ben Abraham | 23f9e78 | 2014-12-02 02:21:34 -0600 | [diff] [blame] | 61 | 0x2d, 0x67, 0x37, 0x35, 0x61, 0x62, 0x36, 0x62, 0x37, 0x81, 0x08, 0x00, |
| 62 | 0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00, |
| 63 | 0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84, |
| 64 | 0x04, 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86, |
| 65 | 0x04, 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 66 | 0x04, 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x97, |
| 67 | 0x02, 0x04, 0xd2, 0x92, 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, |
| 68 | 0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1, |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 69 | }; |
| 70 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 71 | wire.begin(), wire.end()); |
| 72 | |
| 73 | Data data; |
| 74 | data.setContent(wire); |
| 75 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 76 | BOOST_REQUIRE_NO_THROW(ForwarderStatus(data.getContent())); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 77 | ForwarderStatus status2(data.getContent()); |
| 78 | BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion()); |
| 79 | BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp()); |
| 80 | BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp()); |
| 81 | BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries()); |
| 82 | BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries()); |
| 83 | BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries()); |
| 84 | BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries()); |
| 85 | BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries()); |
| 86 | BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests()); |
| 87 | BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas()); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 88 | BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks()); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests()); |
| 90 | BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas()); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame^] | 91 | BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks()); |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | BOOST_AUTO_TEST_SUITE_END() |
| 95 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 96 | } // namespace tests |
Junxiao Shi | 5109dee | 2014-03-27 19:40:30 -0700 | [diff] [blame] | 97 | } // namespace nfd |
| 98 | } // namespace ndn |