Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 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" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 25 | #include <boost/lexical_cast.hpp> |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -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 | 7b1ba1a | 2014-03-29 01:01:56 -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(TestFaceStatus) |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 35 | static FaceStatus |
| 36 | makeFaceStatus() |
| 37 | { |
| 38 | return FaceStatus() |
| 39 | .setFaceId(100) |
| 40 | .setRemoteUri("tcp4://192.0.2.1:6363") |
| 41 | .setLocalUri("tcp4://192.0.2.2:55555") |
| 42 | .setFaceScope(FACE_SCOPE_LOCAL) |
| 43 | .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND) |
| 44 | .setLinkType(LINK_TYPE_MULTI_ACCESS) |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 45 | .setExpirationPeriod(10_s) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 46 | .setBaseCongestionMarkingInterval(5_ns) |
| 47 | .setDefaultCongestionThreshold(7) |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 48 | .setNInInterests(10) |
Junxiao Shi | 9a53d78 | 2017-04-04 20:09:57 +0000 | [diff] [blame] | 49 | .setNInData(200) |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 50 | .setNInNacks(1) |
| 51 | .setNOutInterests(3000) |
Junxiao Shi | 9a53d78 | 2017-04-04 20:09:57 +0000 | [diff] [blame] | 52 | .setNOutData(4) |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 53 | .setNOutNacks(2) |
| 54 | .setNInBytes(1329719163) |
| 55 | .setNOutBytes(999110448) |
| 56 | .setFlags(0x7); |
| 57 | } |
| 58 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 59 | BOOST_AUTO_TEST_CASE(Encode) |
| 60 | { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 61 | FaceStatus status1 = makeFaceStatus(); |
| 62 | Block wire = status1.wireEncode(); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 63 | |
| 64 | // These octets are obtained by the snippet below. |
| 65 | // This check is intended to detect unexpected encoding change in the future. |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 66 | // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 67 | // printf("0x%02x, ", *it); |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 68 | // } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 69 | static const uint8_t expected[] = { |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 70 | 0x80, 0x67, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 71 | 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, |
| 72 | 0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16, |
| 73 | 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, |
| 74 | 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35, |
| 75 | 0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85, |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 76 | 0x01, 0x01, 0x86, 0x01, 0x01, 0x87, 0x01, 0x05, 0x88, 0x01, |
| 77 | 0x07, 0x90, 0x01, 0x0a, 0x91, 0x01, 0xc8, 0x97, 0x01, 0x01, |
| 78 | 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04, 0x98, 0x01, 0x02, |
| 79 | 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b, 0x95, 0x04, 0x3b, 0x8d, |
| 80 | 0x37, 0x30, 0x6c, 0x01, 0x07, |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 81 | }; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 83 | wire.begin(), wire.end()); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 84 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 85 | FaceStatus status2(wire); |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(status1, status2); |
| 87 | } |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 88 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 89 | BOOST_AUTO_TEST_CASE(Equality) |
| 90 | { |
| 91 | FaceStatus status1, status2; |
| 92 | |
| 93 | status1 = makeFaceStatus(); |
| 94 | status2 = status1; |
| 95 | BOOST_CHECK_EQUAL(status1, status2); |
| 96 | |
| 97 | status2.setFaceId(42); |
| 98 | BOOST_CHECK_NE(status1, status2); |
| 99 | } |
| 100 | |
| 101 | BOOST_AUTO_TEST_CASE(Print) |
| 102 | { |
| 103 | FaceStatus status; |
| 104 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
| 105 | "Face(FaceId: 0,\n" |
| 106 | " RemoteUri: ,\n" |
| 107 | " LocalUri: ,\n" |
| 108 | " ExpirationPeriod: infinite,\n" |
| 109 | " FaceScope: non-local,\n" |
| 110 | " FacePersistency: persistent,\n" |
| 111 | " LinkType: point-to-point,\n" |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 112 | " BaseCongestionMarkingInterval: 0 nanoseconds,\n" |
| 113 | " DefaultCongestionThreshold: 0 bytes,\n" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 114 | " Flags: 0x0,\n" |
| 115 | " Counters: {Interests: {in: 0, out: 0},\n" |
| 116 | " Data: {in: 0, out: 0},\n" |
| 117 | " Nacks: {in: 0, out: 0},\n" |
| 118 | " bytes: {in: 0, out: 0}}\n" |
| 119 | " )"); |
| 120 | |
| 121 | status = makeFaceStatus(); |
| 122 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
| 123 | "Face(FaceId: 100,\n" |
| 124 | " RemoteUri: tcp4://192.0.2.1:6363,\n" |
| 125 | " LocalUri: tcp4://192.0.2.2:55555,\n" |
| 126 | " ExpirationPeriod: 10000 milliseconds,\n" |
| 127 | " FaceScope: local,\n" |
| 128 | " FacePersistency: on-demand,\n" |
| 129 | " LinkType: multi-access,\n" |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 130 | " BaseCongestionMarkingInterval: 5 nanoseconds,\n" |
| 131 | " DefaultCongestionThreshold: 7 bytes,\n" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame] | 132 | " Flags: 0x7,\n" |
| 133 | " Counters: {Interests: {in: 10, out: 3000},\n" |
| 134 | " Data: {in: 200, out: 4},\n" |
| 135 | " Nacks: {in: 1, out: 2},\n" |
| 136 | " bytes: {in: 1329719163, out: 999110448}}\n" |
| 137 | " )"); |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Davide Pesavento | 156c1ea | 2017-03-19 16:09:33 -0400 | [diff] [blame] | 140 | BOOST_AUTO_TEST_CASE(ExpirationPeriod) |
| 141 | { |
| 142 | FaceStatus status; |
| 143 | BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false); |
| 144 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 145 | status.setExpirationPeriod(1_min); |
Davide Pesavento | 156c1ea | 2017-03-19 16:09:33 -0400 | [diff] [blame] | 146 | BOOST_REQUIRE_EQUAL(status.hasExpirationPeriod(), true); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 147 | BOOST_CHECK_EQUAL(status.getExpirationPeriod(), 1_min); |
Davide Pesavento | 156c1ea | 2017-03-19 16:09:33 -0400 | [diff] [blame] | 148 | |
| 149 | status.unsetExpirationPeriod(); |
| 150 | BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), false); |
| 151 | } |
| 152 | |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 153 | BOOST_AUTO_TEST_CASE(FlagBit) |
| 154 | { |
| 155 | FaceStatus status; |
| 156 | status.setFlags(0x7); |
| 157 | BOOST_CHECK_EQUAL(status.getFlags(), 0x7); |
| 158 | |
| 159 | BOOST_CHECK(status.getFlagBit(0)); |
| 160 | BOOST_CHECK(status.getFlagBit(1)); |
| 161 | BOOST_CHECK(status.getFlagBit(2)); |
| 162 | BOOST_CHECK(!status.getFlagBit(3)); |
| 163 | |
| 164 | status.setFlagBit(3, true); |
| 165 | BOOST_CHECK_EQUAL(status.getFlags(), 0xf); |
| 166 | BOOST_CHECK(status.getFlagBit(3)); |
| 167 | |
| 168 | status.setFlagBit(1, false); |
| 169 | BOOST_CHECK_EQUAL(status.getFlags(), 0xd); |
| 170 | BOOST_CHECK(!status.getFlagBit(1)); |
| 171 | } |
| 172 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 173 | BOOST_AUTO_TEST_SUITE_END() // TestFaceStatus |
| 174 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 175 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 176 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 177 | } // namespace tests |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 178 | } // namespace nfd |
| 179 | } // namespace ndn |