management: ensure Element::Error inherits from tlv::Error
Add static asserts to ensure ndn::nfd::*::Error are subclasses of tlv::Error.
Add WireEncodable and WireDecodable concept checks to
ndn::nfd::* classes that represent TLV abstraction.
Move definition of ChannelStatus, FibEntry, ForwarderStatus,
StrategyChoice methods into .cpp.
Move declaration of FaceScope, FacePersistency, LinkType
into encoding/nfd-constants.hpp.
Eliminate duplicate RibFlags declaration.
refs #1983
Change-Id: I207bae479aa6da54a581a7cca5b2a13743827ff0
diff --git a/src/management/nfd-forwarder-status.hpp b/src/management/nfd-forwarder-status.hpp
index 9ac58c4..90ec7a5 100644
--- a/src/management/nfd-forwarder-status.hpp
+++ b/src/management/nfd-forwarder-status.hpp
@@ -22,10 +22,7 @@
#ifndef NDN_MANAGEMENT_NFD_FORWARDER_STATUS_HPP
#define NDN_MANAGEMENT_NFD_FORWARDER_STATUS_HPP
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/block-helpers.hpp"
-
+#include "../encoding/block.hpp"
#include "../util/time.hpp"
namespace ndn {
@@ -52,10 +49,7 @@
ForwarderStatus();
explicit
- ForwarderStatus(const Block& payload)
- {
- this->wireDecode(payload);
- }
+ ForwarderStatus(const Block& payload);
/** \brief prepend ForwarderStatus as a Content block to the encoder
*
@@ -87,12 +81,7 @@
}
ForwarderStatus&
- setNfdVersion(int nfdVersion)
- {
- m_wire.reset();
- m_nfdVersion = nfdVersion;
- return *this;
- }
+ setNfdVersion(int nfdVersion);
const time::system_clock::TimePoint&
getStartTimestamp() const
@@ -101,12 +90,7 @@
}
ForwarderStatus&
- setStartTimestamp(const time::system_clock::TimePoint& startTimestamp)
- {
- m_wire.reset();
- m_startTimestamp = startTimestamp;
- return *this;
- }
+ setStartTimestamp(const time::system_clock::TimePoint& startTimestamp);
const time::system_clock::TimePoint&
getCurrentTimestamp() const
@@ -115,12 +99,7 @@
}
ForwarderStatus&
- setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp)
- {
- m_wire.reset();
- m_currentTimestamp = currentTimestamp;
- return *this;
- }
+ setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp);
size_t
getNNameTreeEntries() const
@@ -129,12 +108,7 @@
}
ForwarderStatus&
- setNNameTreeEntries(size_t nNameTreeEntries)
- {
- m_wire.reset();
- m_nNameTreeEntries = nNameTreeEntries;
- return *this;
- }
+ setNNameTreeEntries(size_t nNameTreeEntries);
size_t
getNFibEntries() const
@@ -143,12 +117,7 @@
}
ForwarderStatus&
- setNFibEntries(size_t nFibEntries)
- {
- m_wire.reset();
- m_nFibEntries = nFibEntries;
- return *this;
- }
+ setNFibEntries(size_t nFibEntries);
size_t
getNPitEntries() const
@@ -157,12 +126,7 @@
}
ForwarderStatus&
- setNPitEntries(size_t nPitEntries)
- {
- m_wire.reset();
- m_nPitEntries = nPitEntries;
- return *this;
- }
+ setNPitEntries(size_t nPitEntries);
size_t
getNMeasurementsEntries() const
@@ -171,12 +135,7 @@
}
ForwarderStatus&
- setNMeasurementsEntries(size_t nMeasurementsEntries)
- {
- m_wire.reset();
- m_nMeasurementsEntries = nMeasurementsEntries;
- return *this;
- }
+ setNMeasurementsEntries(size_t nMeasurementsEntries);
size_t
getNCsEntries() const
@@ -185,12 +144,7 @@
}
ForwarderStatus&
- setNCsEntries(size_t nCsEntries)
- {
- m_wire.reset();
- m_nCsEntries = nCsEntries;
- return *this;
- }
+ setNCsEntries(size_t nCsEntries);
uint64_t
getNInInterests() const
@@ -199,12 +153,7 @@
}
ForwarderStatus&
- setNInInterests(uint64_t nInInterests)
- {
- m_wire.reset();
- m_nInInterests = nInInterests;
- return *this;
- }
+ setNInInterests(uint64_t nInInterests);
uint64_t
getNInDatas() const
@@ -213,12 +162,7 @@
}
ForwarderStatus&
- setNInDatas(uint64_t nInDatas)
- {
- m_wire.reset();
- m_nInDatas = nInDatas;
- return *this;
- }
+ setNInDatas(uint64_t nInDatas);
uint64_t
getNOutInterests() const
@@ -227,12 +171,7 @@
}
ForwarderStatus&
- setNOutInterests(uint64_t nOutInterests)
- {
- m_wire.reset();
- m_nOutInterests = nOutInterests;
- return *this;
- }
+ setNOutInterests(uint64_t nOutInterests);
uint64_t
getNOutDatas() const
@@ -241,12 +180,7 @@
}
ForwarderStatus&
- setNOutDatas(uint64_t nOutDatas)
- {
- m_wire.reset();
- m_nOutDatas = nOutDatas;
- return *this;
- }
+ setNOutDatas(uint64_t nOutDatas);
private:
int m_nfdVersion;
@@ -265,182 +199,6 @@
mutable Block m_wire;
};
-inline
-ForwarderStatus::ForwarderStatus()
- : m_nfdVersion(0)
- , m_startTimestamp(time::system_clock::TimePoint::min())
- , m_currentTimestamp(time::system_clock::TimePoint::min())
- , m_nNameTreeEntries(0)
- , m_nFibEntries(0)
- , m_nPitEntries(0)
- , m_nMeasurementsEntries(0)
- , m_nCsEntries(0)
- , m_nInInterests(0)
- , m_nInDatas(0)
- , m_nOutInterests(0)
- , m_nOutDatas(0)
-{
-}
-
-template<bool T>
-inline size_t
-ForwarderStatus::wireEncode(EncodingImpl<T>& encoder) const
-{
- size_t totalLength = 0;
-
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutDatas,
- m_nOutDatas);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests,
- m_nOutInterests);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInDatas,
- m_nInDatas);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests,
- m_nInInterests);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NCsEntries,
- m_nCsEntries);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NMeasurementsEntries,
- m_nMeasurementsEntries);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NPitEntries,
- m_nPitEntries);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NFibEntries,
- m_nFibEntries);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NNameTreeEntries,
- m_nNameTreeEntries);
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::CurrentTimestamp,
- time::toUnixTimestamp(m_currentTimestamp).count());
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::StartTimestamp,
- time::toUnixTimestamp(m_startTimestamp).count());
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NfdVersion,
- m_nfdVersion);
-
- totalLength += encoder.prependVarNumber(totalLength);
- totalLength += encoder.prependVarNumber(tlv::Content);
- return totalLength;
-}
-
-inline const Block&
-ForwarderStatus::wireEncode() const
-{
- if (m_wire.hasWire())
- return m_wire;
-
- EncodingEstimator estimator;
- size_t estimatedSize = wireEncode(estimator);
-
- EncodingBuffer buffer(estimatedSize, 0);
- wireEncode(buffer);
-
- m_wire = buffer.block();
- return m_wire;
-}
-
-inline void
-ForwarderStatus::wireDecode(const Block& block)
-{
- if (block.type() != tlv::Content) {
- throw Error("expecting Content block for Status payload");
- }
- m_wire = block;
- m_wire.parse();
- Block::element_const_iterator val = m_wire.elements_begin();
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NfdVersion) {
- m_nfdVersion = static_cast<int>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NfdVersion field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::StartTimestamp) {
- m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
- ++val;
- }
- else {
- throw Error("missing required StartTimestamp field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::CurrentTimestamp) {
- m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
- ++val;
- }
- else {
- throw Error("missing required CurrentTimestamp field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NNameTreeEntries) {
- m_nNameTreeEntries = static_cast<size_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NNameTreeEntries field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NFibEntries) {
- m_nFibEntries = static_cast<size_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NFibEntries field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NPitEntries) {
- m_nPitEntries = static_cast<size_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NPitEntries field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NMeasurementsEntries) {
- m_nMeasurementsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NMeasurementsEntries field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NCsEntries) {
- m_nCsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NCsEntries field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
- m_nInInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NInInterests field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) {
- m_nInDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NInDatas field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
- m_nOutInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NOutInterests field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) {
- m_nOutDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
- ++val;
- }
- else {
- throw Error("missing required NOutDatas field");
- }
-}
-
} // namespace nfd
} // namespace ndn