mgmt: ForwarderStatus equality operators and formatted output
Change-Id: I6d814ef427a9db38ef46427888f3b3ba982bf641
Refs: #3903
diff --git a/src/mgmt/nfd/channel-status.cpp b/src/mgmt/nfd/channel-status.cpp
index c2a9b63..f3a7e2b 100644
--- a/src/mgmt/nfd/channel-status.cpp
+++ b/src/mgmt/nfd/channel-status.cpp
@@ -106,9 +106,9 @@
}
std::ostream&
-operator<<(std::ostream& os, const ChannelStatus& cs)
+operator<<(std::ostream& os, const ChannelStatus& status)
{
- return os << "Channel(" << "LocalUri: " << cs.getLocalUri() << ")";
+ return os << "Channel(LocalUri: " << status.getLocalUri() << ")";
}
} // namespace nfd
diff --git a/src/mgmt/nfd/channel-status.hpp b/src/mgmt/nfd/channel-status.hpp
index 16eb419..04b3ed6 100644
--- a/src/mgmt/nfd/channel-status.hpp
+++ b/src/mgmt/nfd/channel-status.hpp
@@ -28,9 +28,9 @@
namespace nfd {
/**
- * @ingroup management
- * @brief represents NFD Channel Status dataset
- * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Channel-Dataset
+ * \ingroup management
+ * \brief represents an item in NFD Channel dataset
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Channel-Dataset
*/
class ChannelStatus
{
@@ -86,7 +86,7 @@
}
std::ostream&
-operator<<(std::ostream& os, const ChannelStatus& cs);
+operator<<(std::ostream& os, const ChannelStatus& status);
} // namespace nfd
} // namespace ndn
diff --git a/src/mgmt/nfd/forwarder-status.cpp b/src/mgmt/nfd/forwarder-status.cpp
index 21fee56..fbb6c73 100644
--- a/src/mgmt/nfd/forwarder-status.cpp
+++ b/src/mgmt/nfd/forwarder-status.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,23 +20,18 @@
*/
#include "forwarder-status.hpp"
-#include "encoding/tlv-nfd.hpp"
#include "encoding/block-helpers.hpp"
+#include "encoding/encoding-buffer.hpp"
+#include "encoding/tlv-nfd.hpp"
#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
-//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ForwarderStatus>));
-BOOST_CONCEPT_ASSERT((WireEncodable<ForwarderStatus>));
-BOOST_CONCEPT_ASSERT((WireDecodable<ForwarderStatus>));
-static_assert(std::is_base_of<tlv::Error, ForwarderStatus::Error>::value,
- "ForwarderStatus::Error must inherit from tlv::Error");
+BOOST_CONCEPT_ASSERT((StatusDatasetItem<ForwarderStatus>));
ForwarderStatus::ForwarderStatus()
- : m_startTimestamp(time::system_clock::TimePoint::min())
- , m_currentTimestamp(time::system_clock::TimePoint::min())
- , m_nNameTreeEntries(0)
+ : m_nNameTreeEntries(0)
, m_nFibEntries(0)
, m_nPitEntries(0)
, m_nMeasurementsEntries(0)
@@ -88,8 +83,8 @@
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::StartTimestamp,
time::toUnixTimestamp(m_startTimestamp).count());
totalLength += encoder.prependByteArrayBlock(tlv::nfd::NfdVersion,
- reinterpret_cast<const uint8_t*>(m_nfdVersion.c_str()),
- m_nfdVersion.size());
+ reinterpret_cast<const uint8_t*>(m_nfdVersion.data()),
+ m_nfdVersion.size());
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(tlv::Content);
@@ -353,5 +348,46 @@
return *this;
}
+bool
+operator==(const ForwarderStatus& a, const ForwarderStatus& b)
+{
+ return a.getNfdVersion() == b.getNfdVersion() &&
+ a.getStartTimestamp() == b.getStartTimestamp() &&
+ a.getCurrentTimestamp() == b.getCurrentTimestamp() &&
+ a.getNNameTreeEntries() == b.getNNameTreeEntries() &&
+ a.getNFibEntries() == b.getNFibEntries() &&
+ a.getNPitEntries() == b.getNPitEntries() &&
+ a.getNMeasurementsEntries() == b.getNMeasurementsEntries() &&
+ a.getNCsEntries() == b.getNCsEntries() &&
+ a.getNInInterests() == b.getNInInterests() &&
+ a.getNInDatas() == b.getNInDatas() &&
+ a.getNInNacks() == b.getNInNacks() &&
+ a.getNOutInterests() == b.getNOutInterests() &&
+ a.getNOutDatas() == b.getNOutDatas() &&
+ a.getNOutNacks() == b.getNOutNacks();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const ForwarderStatus& status)
+{
+ os << "GeneralStatus(NfdVersion: " << status.getNfdVersion() << ",\n"
+ << " StartTimestamp: " << status.getStartTimestamp() << ",\n"
+ << " CurrentTimestamp: " << status.getCurrentTimestamp() << ",\n"
+ << " Counters: {NameTreeEntries: " << status.getNNameTreeEntries() << ",\n"
+ << " FibEntries: " << status.getNFibEntries() << ",\n"
+ << " PitEntries: " << status.getNPitEntries() << ",\n"
+ << " MeasurementsEntries: " << status.getNMeasurementsEntries() << ",\n"
+ << " CsEntries: " << status.getNCsEntries() << ",\n"
+ << " Interests: {in: " << status.getNInInterests() << ", "
+ << "out: " << status.getNOutInterests() << "},\n"
+ << " Data: {in: " << status.getNInDatas() << ", "
+ << "out: " << status.getNOutDatas() << "},\n"
+ << " Nacks: {in: " << status.getNInNacks() << ", "
+ << "out: " << status.getNOutNacks() << "}}\n"
+ << " )";
+
+ return os;
+}
+
} // namespace nfd
} // namespace ndn
diff --git a/src/mgmt/nfd/forwarder-status.hpp b/src/mgmt/nfd/forwarder-status.hpp
index 4601610..7e1b35c 100644
--- a/src/mgmt/nfd/forwarder-status.hpp
+++ b/src/mgmt/nfd/forwarder-status.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -30,8 +30,8 @@
/**
* \ingroup management
- * \brief represents NFD Forwarder Status
- * \sa http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
+ * \brief represents NFD General Status dataset
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus#General-Status-Dataset
*/
class ForwarderStatus
{
@@ -53,7 +53,7 @@
/** \brief prepend ForwarderStatus as a Content block to the encoder
*
- * The outermost Content element isn't part of ForwardStatus structure.
+ * The outermost Content element isn't part of ForwarderStatus structure.
*/
template<encoding::Tag TAG>
size_t
@@ -61,14 +61,14 @@
/** \brief encode ForwarderStatus as a Content block
*
- * The outermost Content element isn't part of ForwardStatus structure.
+ * The outermost Content element isn't part of ForwarderStatus structure.
*/
const Block&
wireEncode() const;
/** \brief decode ForwarderStatus from a Content block
*
- * The outermost Content element isn't part of ForwardStatus structure.
+ * The outermost Content element isn't part of ForwarderStatus structure.
*/
void
wireDecode(const Block& wire);
@@ -219,6 +219,18 @@
mutable Block m_wire;
};
+bool
+operator==(const ForwarderStatus& a, const ForwarderStatus& b);
+
+inline bool
+operator!=(const ForwarderStatus& a, const ForwarderStatus& b)
+{
+ return !(a == b);
+}
+
+std::ostream&
+operator<<(std::ostream& os, const ForwarderStatus& status);
+
} // namespace nfd
} // namespace ndn
diff --git a/src/mgmt/nfd/strategy-choice.hpp b/src/mgmt/nfd/strategy-choice.hpp
index ec46348..ba840f0 100644
--- a/src/mgmt/nfd/strategy-choice.hpp
+++ b/src/mgmt/nfd/strategy-choice.hpp
@@ -29,9 +29,9 @@
namespace nfd {
/**
- * @ingroup management
- * @brief represents NFD StrategyChoice dataset
- * @sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Strategy-Choice-Dataset
+ * \ingroup management
+ * \brief represents an item in NFD StrategyChoice dataset
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Strategy-Choice-Dataset
*/
class StrategyChoice
{
diff --git a/tests/unit-tests/mgmt/nfd/channel-status.t.cpp b/tests/unit-tests/mgmt/nfd/channel-status.t.cpp
index 0ffe2de..7c89533 100644
--- a/tests/unit-tests/mgmt/nfd/channel-status.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/channel-status.t.cpp
@@ -36,44 +36,44 @@
{
ChannelStatus status1;
status1.setLocalUri("udp4://192.168.2.1");
-
- Block wire;
- BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
+ Block wire = status1.wireEncode();
// These octets are obtained by the snippet below.
// This check is intended to detect unexpected encoding change in the future.
// for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
- // printf("0x%02x, ", *it);
+ // printf("0x%02x, ", *it);
// }
static const uint8_t expected[] = {
0x82, 0x14, 0x81, 0x12, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
0x2e, 0x31, 0x36, 0x38, 0x2e, 0x32, 0x2e, 0x31
};
- BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
- wire.begin(), wire.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+ wire.begin(), wire.end());
- BOOST_REQUIRE_NO_THROW(ChannelStatus(wire));
ChannelStatus status2(wire);
- BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
+ BOOST_CHECK_EQUAL(status1, status2);
}
BOOST_AUTO_TEST_CASE(Equality)
{
- ChannelStatus cs1, cs2;
+ ChannelStatus status1, status2;
- cs1.setLocalUri("udp4://127.0.0.1:6363");
- cs2 = cs1;
- BOOST_CHECK_EQUAL(cs1, cs2);
+ status1.setLocalUri("udp4://127.0.0.1:6363");
+ status2 = status1;
+ BOOST_CHECK_EQUAL(status1, status2);
- cs2.setLocalUri("dev://eth0");
- BOOST_CHECK_NE(cs1, cs2);
+ status2.setLocalUri("dev://eth0");
+ BOOST_CHECK_NE(status1, status2);
}
BOOST_AUTO_TEST_CASE(Print)
{
- ChannelStatus cs;
- cs.setLocalUri("udp4://127.0.0.1:6363");
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(cs),
+ ChannelStatus status;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
+ "Channel(LocalUri: )");
+
+ status.setLocalUri("udp4://127.0.0.1:6363");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
"Channel(LocalUri: udp4://127.0.0.1:6363)");
}
diff --git a/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp b/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
index b7aefa0f..075e3ec 100644
--- a/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,9 +20,9 @@
*/
#include "mgmt/nfd/forwarder-status.hpp"
-#include "data.hpp"
#include "boost-test.hpp"
+#include <boost/lexical_cast.hpp>
namespace ndn {
namespace nfd {
@@ -32,35 +32,39 @@
BOOST_AUTO_TEST_SUITE(Nfd)
BOOST_AUTO_TEST_SUITE(TestForwarderStatus)
+static ForwarderStatus
+makeForwarderStatus()
+{
+ return ForwarderStatus()
+ .setNfdVersion("0.5.1-14-g05dd444")
+ .setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325LL)))
+ .setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272LL)))
+ .setNNameTreeEntries(1849943160)
+ .setNFibEntries(621739748)
+ .setNPitEntries(482129741)
+ .setNMeasurementsEntries(1771725298)
+ .setNCsEntries(1264968688)
+ .setNInInterests(612811615)
+ .setNInDatas(1843576050)
+ .setNInNacks(1234)
+ .setNOutInterests(952144445)
+ .setNOutDatas(138198826)
+ .setNOutNacks(4321);
+}
+
BOOST_AUTO_TEST_CASE(Encode)
{
- ForwarderStatus status1;
- status1.setNfdVersion("0.2.0-65-g75ab6b7");
- status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325LL)));
- status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272LL)));
- status1.setNNameTreeEntries(1849943160);
- status1.setNFibEntries(621739748);
- status1.setNPitEntries(482129741);
- status1.setNMeasurementsEntries(1771725298);
- status1.setNCsEntries(1264968688);
- status1.setNInInterests(612811615);
- status1.setNInDatas(1843576050);
- status1.setNInNacks(1234);
- status1.setNOutInterests(952144445);
- status1.setNOutDatas(138198826);
- status1.setNOutNacks(4321);
-
- Block wire;
- BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
+ ForwarderStatus status1 = makeForwarderStatus();
+ Block wire = status1.wireEncode();
// These octets are obtained by the snippet below.
// This check is intended to detect unexpected encoding change in the future.
- //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
- // printf("0x%02x, ", *it);
- //}
+ // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+ // printf("0x%02x, ", *it);
+ // }
static const uint8_t expected[] = {
- 0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35,
- 0x2d, 0x67, 0x37, 0x35, 0x61, 0x62, 0x36, 0x62, 0x37, 0x81, 0x08, 0x00,
+ 0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x35, 0x2e, 0x31, 0x2d, 0x31, 0x34,
+ 0x2d, 0x67, 0x30, 0x35, 0x64, 0x64, 0x34, 0x34, 0x34, 0x81, 0x08, 0x00,
0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00,
0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84,
0x04, 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86,
@@ -69,28 +73,56 @@
0x02, 0x04, 0xd2, 0x92, 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08,
0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1,
};
- BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
- wire.begin(), wire.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+ wire.begin(), wire.end());
- Data data;
- data.setContent(wire);
+ ForwarderStatus status2(wire);
+ BOOST_CHECK_EQUAL(status1, status2);
+}
- BOOST_REQUIRE_NO_THROW(ForwarderStatus(data.getContent()));
- ForwarderStatus status2(data.getContent());
- BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
- BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
- BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp());
- BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries());
- BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries());
- BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries());
- BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries());
- BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
- BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
- BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
- BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks());
- BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
- BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
- BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks());
+BOOST_AUTO_TEST_CASE(Equality)
+{
+ ForwarderStatus status1, status2;
+
+ status1 = makeForwarderStatus();
+ status2 = status1;
+ BOOST_CHECK_EQUAL(status1, status2);
+
+ status2.setNPitEntries(42);
+ BOOST_CHECK_NE(status1, status2);
+}
+
+BOOST_AUTO_TEST_CASE(Print)
+{
+ ForwarderStatus status;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
+ "GeneralStatus(NfdVersion: ,\n"
+ " StartTimestamp: 0 nanoseconds since Jan 1, 1970,\n"
+ " CurrentTimestamp: 0 nanoseconds since Jan 1, 1970,\n"
+ " Counters: {NameTreeEntries: 0,\n"
+ " FibEntries: 0,\n"
+ " PitEntries: 0,\n"
+ " MeasurementsEntries: 0,\n"
+ " CsEntries: 0,\n"
+ " Interests: {in: 0, out: 0},\n"
+ " Data: {in: 0, out: 0},\n"
+ " Nacks: {in: 0, out: 0}}\n"
+ " )");
+
+ status = makeForwarderStatus();
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
+ "GeneralStatus(NfdVersion: 0.5.1-14-g05dd444,\n"
+ " StartTimestamp: 375193249325000000 nanoseconds since Jan 1, 1970,\n"
+ " CurrentTimestamp: 886109034272000000 nanoseconds since Jan 1, 1970,\n"
+ " Counters: {NameTreeEntries: 1849943160,\n"
+ " FibEntries: 621739748,\n"
+ " PitEntries: 482129741,\n"
+ " MeasurementsEntries: 1771725298,\n"
+ " CsEntries: 1264968688,\n"
+ " Interests: {in: 612811615, out: 952144445},\n"
+ " Data: {in: 1843576050, out: 138198826},\n"
+ " Nacks: {in: 1234, out: 4321}}\n"
+ " )");
}
BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatus
diff --git a/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp b/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp
index b02be0c..a623858 100644
--- a/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp
@@ -37,14 +37,12 @@
StrategyChoice sc1;
sc1.setName("/hello/world")
.setStrategy("/some/non/existing/strategy/name");
-
- Block wire;
- BOOST_REQUIRE_NO_THROW(wire = sc1.wireEncode());
+ Block wire = sc1.wireEncode();
// These octets are obtained by the snippet below.
// This check is intended to detect unexpected encoding change in the future.
// for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
- // printf("0x%02x, ", *it);
+ // printf("0x%02x, ", *it);
// }
static const uint8_t expected[] = {
0x80, 0x39, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x08, 0x05, 0x77,
@@ -53,10 +51,9 @@
0x67, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x08, 0x04, 0x6e,
0x61, 0x6d, 0x65
};
- BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
- wire.begin(), wire.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+ wire.begin(), wire.end());
- BOOST_REQUIRE_NO_THROW(StrategyChoice(wire));
StrategyChoice sc2(wire);
BOOST_CHECK_EQUAL(sc1, sc2);
}
@@ -81,6 +78,9 @@
BOOST_AUTO_TEST_CASE(Print)
{
StrategyChoice sc;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),
+ "StrategyChoice(Name: /, Strategy: /)");
+
sc.setName("/A")
.setStrategy("/strategyP");
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),