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 | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 2 | /** |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "mgmt/nfd/face-status.hpp" |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 31 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 32 | BOOST_AUTO_TEST_SUITE(TestFaceStatus) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Encode) |
| 35 | { |
| 36 | FaceStatus status1; |
| 37 | status1.setFaceId(100) |
| 38 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 39 | .setLocalUri("tcp4://192.0.2.2:55555") |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 40 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 41 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 42 | .setLinkType(LINK_TYPE_MULTI_ACCESS) |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 43 | .setExpirationPeriod(time::seconds(10)) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 44 | .setNInInterests(10) |
| 45 | .setNInDatas(200) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 46 | .setNInNacks(1) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 47 | .setNOutInterests(3000) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 48 | .setNOutDatas(4) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 49 | .setNOutNacks(2) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 50 | .setNInBytes(1329719163) |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 51 | .setNOutBytes(999110448) |
| 52 | .setFlags(0x7); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 53 | |
| 54 | Block wire; |
| 55 | BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode()); |
| 56 | |
| 57 | // These octets are obtained by the snippet below. |
| 58 | // This check is intended to detect unexpected encoding change in the future. |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 59 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 60 | // printf("0x%02x, ", *it); |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 61 | // } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 62 | static const uint8_t expected[] = { |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 63 | 0x80, 0x61, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 64 | 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, |
| 65 | 0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, |
| 66 | 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, |
| 67 | 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35, |
| 68 | 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85, |
| 69 | 0x01, 0x01, 0x86, 0x01, 0x01, 0x90, 0x01, 0x0a, 0x91, 0x01, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 70 | 0xc8, 0x97, 0x01, 0x01, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, |
| 71 | 0x04, 0x98, 0x01, 0x02, 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b, |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 72 | 0x95, 0x04, 0x3b, 0x8d, 0x37, 0x30, 0x6c, 0x01, 0x07, |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 73 | }; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 75 | wire.begin(), wire.end()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 76 | |
| 77 | BOOST_REQUIRE_NO_THROW(FaceStatus(wire)); |
| 78 | FaceStatus status2(wire); |
| 79 | BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId()); |
| 80 | BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri()); |
| 81 | BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri()); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(status1.getFaceScope(), status2.getFaceScope()); |
| 83 | BOOST_CHECK_EQUAL(status1.getFacePersistency(), status2.getFacePersistency()); |
| 84 | BOOST_CHECK_EQUAL(status1.getLinkType(), status2.getLinkType()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 85 | BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests()); |
| 86 | BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas()); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 88 | BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests()); |
| 89 | BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas()); |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks()); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 91 | BOOST_CHECK_EQUAL(status1.getNInBytes(), status2.getNInBytes()); |
| 92 | BOOST_CHECK_EQUAL(status1.getNOutBytes(), status2.getNOutBytes()); |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(status1.getFlags(), status2.getFlags()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 94 | |
| 95 | std::ostringstream os; |
| 96 | os << status2; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100,\n" |
| 98 | "RemoteUri: tcp4://192.0.2.1:6363,\n" |
| 99 | "LocalUri: tcp4://192.0.2.2:55555,\n" |
| 100 | "ExpirationPeriod: 10000 milliseconds,\n" |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 101 | "FaceScope: local,\n" |
| 102 | "FacePersistency: on-demand,\n" |
| 103 | "LinkType: multi-access,\n" |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 104 | "Flags: 0x7,\n" |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 105 | "Counters: { Interests: {in: 10, out: 3000},\n" |
| 106 | " Data: {in: 200, out: 4},\n" |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 107 | " Nack: {in: 1, out: 2},\n" |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 108 | " bytes: {in: 1329719163, out: 999110448} }\n" |
| 109 | ")"); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 112 | BOOST_AUTO_TEST_CASE(FlagBit) |
| 113 | { |
| 114 | FaceStatus status; |
| 115 | status.setFlags(0x7); |
| 116 | BOOST_CHECK_EQUAL(status.getFlags(), 0x7); |
| 117 | |
| 118 | BOOST_CHECK(status.getFlagBit(0)); |
| 119 | BOOST_CHECK(status.getFlagBit(1)); |
| 120 | BOOST_CHECK(status.getFlagBit(2)); |
| 121 | BOOST_CHECK(!status.getFlagBit(3)); |
| 122 | |
| 123 | status.setFlagBit(3, true); |
| 124 | BOOST_CHECK_EQUAL(status.getFlags(), 0xf); |
| 125 | BOOST_CHECK(status.getFlagBit(3)); |
| 126 | |
| 127 | status.setFlagBit(1, false); |
| 128 | BOOST_CHECK_EQUAL(status.getFlags(), 0xd); |
| 129 | BOOST_CHECK(!status.getFlagBit(1)); |
| 130 | } |
| 131 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 132 | BOOST_AUTO_TEST_SUITE_END() // TestFaceStatus |
| 133 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 134 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 135 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 136 | } // namespace tests |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 137 | } // namespace nfd |
| 138 | } // namespace ndn |