blob: 8afb0ccd5371d7040da7b57a5a29fb380ef5f6ce [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -07002/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 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
22#include "management/nfd-face-status.hpp"
23
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070025
26namespace ndn {
27namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070029
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030BOOST_AUTO_TEST_SUITE(ManagementNfdFaceStatus)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070031
32BOOST_AUTO_TEST_CASE(Encode)
33{
34 FaceStatus status1;
35 status1.setFaceId(100)
36 .setRemoteUri("tcp4://192.0.2.1:6363")
37 .setLocalUri("tcp4://192.0.2.2:55555")
Chengyu Fan36dca992014-09-25 13:42:03 -060038 .setFaceScope(FACE_SCOPE_LOCAL)
39 .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
40 .setLinkType(LINK_TYPE_MULTI_ACCESS)
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070041 .setExpirationPeriod(time::seconds(10))
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070042 .setNInInterests(10)
43 .setNInDatas(200)
Eric Newberry95bd96a2015-09-04 23:34:22 -070044 .setNInNacks(1)
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070045 .setNOutInterests(3000)
Junxiao Shi13e637f2014-07-16 19:20:40 -070046 .setNOutDatas(4)
Eric Newberry95bd96a2015-09-04 23:34:22 -070047 .setNOutNacks(2)
Junxiao Shi13e637f2014-07-16 19:20:40 -070048 .setNInBytes(1329719163)
49 .setNOutBytes(999110448);
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070050
51 Block wire;
52 BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
53
54 // These octets are obtained by the snippet below.
55 // This check is intended to detect unexpected encoding change in the future.
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070056 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070057 // printf("0x%02x, ", *it);
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070058 // }
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070059 static const uint8_t expected[] = {
Eric Newberry95bd96a2015-09-04 23:34:22 -070060 0x80, 0x5e, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
Chengyu Fan36dca992014-09-25 13:42:03 -060061 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e,
62 0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16,
63 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
64 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35,
65 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85,
66 0x01, 0x01, 0x86, 0x01, 0x01, 0x90, 0x01, 0x0a, 0x91, 0x01,
Eric Newberry95bd96a2015-09-04 23:34:22 -070067 0xc8, 0x97, 0x01, 0x01, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01,
68 0x04, 0x98, 0x01, 0x02, 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b,
69 0x95, 0x04, 0x3b, 0x8d, 0x37, 0x30,
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070070 };
Junxiao Shi13e637f2014-07-16 19:20:40 -070071 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
72 wire.begin(), wire.end());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070073
74 BOOST_REQUIRE_NO_THROW(FaceStatus(wire));
75 FaceStatus status2(wire);
76 BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId());
77 BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri());
78 BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
Chengyu Fan36dca992014-09-25 13:42:03 -060079 BOOST_CHECK_EQUAL(status1.getFaceScope(), status2.getFaceScope());
80 BOOST_CHECK_EQUAL(status1.getFacePersistency(), status2.getFacePersistency());
81 BOOST_CHECK_EQUAL(status1.getLinkType(), status2.getLinkType());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070082 BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
83 BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
Eric Newberry95bd96a2015-09-04 23:34:22 -070084 BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070085 BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
86 BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
Eric Newberry95bd96a2015-09-04 23:34:22 -070087 BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks());
Junxiao Shi13e637f2014-07-16 19:20:40 -070088 BOOST_CHECK_EQUAL(status1.getNInBytes(), status2.getNInBytes());
89 BOOST_CHECK_EQUAL(status1.getNOutBytes(), status2.getNOutBytes());
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070090
91 std::ostringstream os;
92 os << status2;
Junxiao Shi13e637f2014-07-16 19:20:40 -070093 BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100,\n"
94 "RemoteUri: tcp4://192.0.2.1:6363,\n"
95 "LocalUri: tcp4://192.0.2.2:55555,\n"
96 "ExpirationPeriod: 10000 milliseconds,\n"
Chengyu Fan36dca992014-09-25 13:42:03 -060097 "FaceScope: local,\n"
98 "FacePersistency: on-demand,\n"
99 "LinkType: multi-access,\n"
Junxiao Shi13e637f2014-07-16 19:20:40 -0700100 "Counters: { Interests: {in: 10, out: 3000},\n"
101 " Data: {in: 200, out: 4},\n"
Eric Newberry95bd96a2015-09-04 23:34:22 -0700102 " Nack: {in: 1, out: 2},\n"
Junxiao Shi13e637f2014-07-16 19:20:40 -0700103 " bytes: {in: 1329719163, out: 999110448} }\n"
104 ")");
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700105}
106
107BOOST_AUTO_TEST_SUITE_END()
108
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800109} // namespace tests
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700110} // namespace nfd
111} // namespace ndn