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-channel-status.cpp b/src/management/nfd-channel-status.cpp
new file mode 100644
index 0000000..771b8d3
--- /dev/null
+++ b/src/management/nfd-channel-status.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "nfd-channel-status.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
+
+namespace ndn {
+namespace nfd {
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ChannelStatus>));
+BOOST_CONCEPT_ASSERT((WireEncodable<ChannelStatus>));
+BOOST_CONCEPT_ASSERT((WireDecodable<ChannelStatus>));
+static_assert(std::is_base_of<tlv::Error, ChannelStatus::Error>::value,
+ "ChannelStatus::Error must inherit from tlv::Error");
+
+ChannelStatus::ChannelStatus()
+{
+}
+
+ChannelStatus::ChannelStatus(const Block& payload)
+{
+ this->wireDecode(payload);
+}
+
+template<bool T>
+size_t
+ChannelStatus::wireEncode(EncodingImpl<T>& encoder) const
+{
+ size_t totalLength = 0;
+
+ totalLength += prependByteArrayBlock(encoder, tlv::nfd::LocalUri,
+ reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
+
+ totalLength += encoder.prependVarNumber(totalLength);
+ totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus);
+ return totalLength;
+}
+
+template size_t
+ChannelStatus::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+ChannelStatus::wireEncode<false>(EncodingImpl<false>& block) const;
+
+const Block&
+ChannelStatus::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;
+}
+
+void
+ChannelStatus::wireDecode(const Block& block)
+{
+ if (block.type() != tlv::nfd::ChannelStatus) {
+ throw Error("expecting ChannelStatus block");
+ }
+ 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::LocalUri) {
+ m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
+ ++val;
+ }
+ else {
+ throw Error("missing required LocalUri field");
+ }
+}
+
+ChannelStatus&
+ChannelStatus::setLocalUri(const std::string localUri)
+{
+ m_wire.reset();
+ m_localUri = localUri;
+ return *this;
+}
+
+} // namespace nfd
+} // namespace ndn
diff --git a/src/management/nfd-channel-status.hpp b/src/management/nfd-channel-status.hpp
index 78a2066..4bb2707 100644
--- a/src/management/nfd-channel-status.hpp
+++ b/src/management/nfd-channel-status.hpp
@@ -22,11 +22,7 @@
#ifndef NDN_MANAGEMENT_NFD_CHANNEL_STATUS_HPP
#define NDN_MANAGEMENT_NFD_CHANNEL_STATUS_HPP
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/block-helpers.hpp"
-
-#include "../util/time.hpp"
+#include "../encoding/block.hpp"
namespace ndn {
namespace nfd {
@@ -49,15 +45,10 @@
}
};
- ChannelStatus()
- {
- }
+ ChannelStatus();
explicit
- ChannelStatus(const Block& payload)
- {
- this->wireDecode(payload);
- }
+ ChannelStatus(const Block& payload);
template<bool T>
size_t
@@ -77,12 +68,7 @@
}
ChannelStatus&
- setLocalUri(const std::string localUri)
- {
- m_wire.reset();
- m_localUri = localUri;
- return *this;
- }
+ setLocalUri(const std::string localUri);
private:
std::string m_localUri;
@@ -90,56 +76,6 @@
mutable Block m_wire;
};
-
-template<bool T>
-inline size_t
-ChannelStatus::wireEncode(EncodingImpl<T>& encoder) const
-{
- size_t totalLength = 0;
-
- totalLength += prependByteArrayBlock(encoder, tlv::nfd::LocalUri,
- reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
-
- totalLength += encoder.prependVarNumber(totalLength);
- totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus);
- return totalLength;
-}
-
-inline const Block&
-ChannelStatus::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
-ChannelStatus::wireDecode(const Block& block)
-{
- if (block.type() != tlv::nfd::ChannelStatus) {
- throw Error("expecting ChannelStatus block");
- }
- 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::LocalUri) {
- m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
- ++val;
- }
- else {
- throw Error("missing required LocalUri field");
- }
-}
-
} // namespace nfd
} // namespace ndn
diff --git a/src/management/nfd-control-parameters.cpp b/src/management/nfd-control-parameters.cpp
index 257dcb6..773d65a 100644
--- a/src/management/nfd-control-parameters.cpp
+++ b/src/management/nfd-control-parameters.cpp
@@ -20,10 +20,19 @@
*/
#include "nfd-control-parameters.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlParameters>));
+BOOST_CONCEPT_ASSERT((WireEncodable<ControlParameters>));
+BOOST_CONCEPT_ASSERT((WireDecodable<ControlParameters>));
+static_assert(std::is_base_of<tlv::Error, ControlParameters::Error>::value,
+ "ControlParameters::Error must inherit from tlv::Error");
+
ControlParameters::ControlParameters()
: m_hasFields(CONTROL_PARAMETER_UBOUND)
{
diff --git a/src/management/nfd-control-parameters.hpp b/src/management/nfd-control-parameters.hpp
index 61381cb..faa7c3a 100644
--- a/src/management/nfd-control-parameters.hpp
+++ b/src/management/nfd-control-parameters.hpp
@@ -22,9 +22,8 @@
#ifndef NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
#define NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
+#include "../encoding/nfd-constants.hpp"
#include "../name.hpp"
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/block-helpers.hpp"
#include "../util/time.hpp"
namespace ndn {
diff --git a/src/management/nfd-control-response.cpp b/src/management/nfd-control-response.cpp
index 568dace..6de873f 100644
--- a/src/management/nfd-control-response.cpp
+++ b/src/management/nfd-control-response.cpp
@@ -20,10 +20,19 @@
*/
#include "nfd-control-response.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
+BOOST_CONCEPT_ASSERT((WireEncodable<ControlResponse>));
+BOOST_CONCEPT_ASSERT((WireDecodable<ControlResponse>));
+static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
+ "ControlResponse::Error must inherit from tlv::Error");
+
ControlResponse::ControlResponse()
: m_code(200)
{
diff --git a/src/management/nfd-control-response.hpp b/src/management/nfd-control-response.hpp
index 2ad94e5..42ffd3d 100644
--- a/src/management/nfd-control-response.hpp
+++ b/src/management/nfd-control-response.hpp
@@ -23,8 +23,6 @@
#define NDN_MANAGEMENT_CONTROL_RESPONSE_HPP
#include "../encoding/block.hpp"
-#include "../encoding/block-helpers.hpp"
-#include "../encoding/tlv-nfd.hpp"
namespace ndn {
namespace nfd {
diff --git a/src/management/nfd-face-event-notification.cpp b/src/management/nfd-face-event-notification.cpp
index d459de4..18b12d1 100644
--- a/src/management/nfd-face-event-notification.cpp
+++ b/src/management/nfd-face-event-notification.cpp
@@ -20,12 +20,21 @@
*/
#include "nfd-face-event-notification.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceEventNotification>));
+BOOST_CONCEPT_ASSERT((WireEncodable<FaceEventNotification>));
+BOOST_CONCEPT_ASSERT((WireDecodable<FaceEventNotification>));
+static_assert(std::is_base_of<tlv::Error, FaceEventNotification::Error>::value,
+ "FaceEventNotification::Error must inherit from tlv::Error");
+
FaceEventNotification::FaceEventNotification()
- : FaceTraits()
- , m_kind(static_cast<FaceEventKind>(0))
+ : m_kind(static_cast<FaceEventKind>(0))
{
}
diff --git a/src/management/nfd-face-event-notification.hpp b/src/management/nfd-face-event-notification.hpp
index 94870d9..f101f25 100644
--- a/src/management/nfd-face-event-notification.hpp
+++ b/src/management/nfd-face-event-notification.hpp
@@ -22,8 +22,8 @@
#ifndef NDN_MANAGEMENT_NFD_FACE_EVENT_NOTIFICATION_HPP
#define NDN_MANAGEMENT_NFD_FACE_EVENT_NOTIFICATION_HPP
-// This include must be kept as the first one, to ensure nfd-face-flags.hpp compiles on its own.
#include "nfd-face-traits.hpp"
+#include "../encoding/block.hpp"
namespace ndn {
namespace nfd {
diff --git a/src/management/nfd-face-query-filter.cpp b/src/management/nfd-face-query-filter.cpp
index 39c5240..d0ca150 100644
--- a/src/management/nfd-face-query-filter.cpp
+++ b/src/management/nfd-face-query-filter.cpp
@@ -20,10 +20,19 @@
*/
#include "nfd-face-query-filter.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceQueryFilter>));
+BOOST_CONCEPT_ASSERT((WireEncodable<FaceQueryFilter>));
+BOOST_CONCEPT_ASSERT((WireDecodable<FaceQueryFilter>));
+static_assert(std::is_base_of<tlv::Error, FaceQueryFilter::Error>::value,
+ "FaceQueryFilter::Error must inherit from tlv::Error");
+
FaceQueryFilter::FaceQueryFilter()
: m_hasFaceId(false)
, m_hasUriScheme(false)
diff --git a/src/management/nfd-face-query-filter.hpp b/src/management/nfd-face-query-filter.hpp
index 5de02fe..5833d1f 100644
--- a/src/management/nfd-face-query-filter.hpp
+++ b/src/management/nfd-face-query-filter.hpp
@@ -22,7 +22,8 @@
#ifndef NDN_MANAGEMENT_NFD_FACE_QUERY_FILTER_HPP
#define NDN_MANAGEMENT_NFD_FACE_QUERY_FILTER_HPP
-#include "nfd-face-traits.hpp"
+#include "../encoding/block.hpp"
+#include "../encoding/nfd-constants.hpp"
namespace ndn {
namespace nfd {
diff --git a/src/management/nfd-face-status.cpp b/src/management/nfd-face-status.cpp
index 17145bd..8a08825 100644
--- a/src/management/nfd-face-status.cpp
+++ b/src/management/nfd-face-status.cpp
@@ -20,13 +20,21 @@
*/
#include "nfd-face-status.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceStatus>));
+BOOST_CONCEPT_ASSERT((WireEncodable<FaceStatus>));
+BOOST_CONCEPT_ASSERT((WireDecodable<FaceStatus>));
+static_assert(std::is_base_of<tlv::Error, FaceStatus::Error>::value,
+ "FaceStatus::Error must inherit from tlv::Error");
+
FaceStatus::FaceStatus()
- : FaceTraits()
- , m_hasExpirationPeriod(false)
+ : m_hasExpirationPeriod(false)
, m_nInInterests(0)
, m_nInDatas(0)
, m_nOutInterests(0)
diff --git a/src/management/nfd-face-status.hpp b/src/management/nfd-face-status.hpp
index 237b3f1..5b70ce2 100644
--- a/src/management/nfd-face-status.hpp
+++ b/src/management/nfd-face-status.hpp
@@ -22,9 +22,8 @@
#ifndef NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
#define NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
-// This include must be kept as the first one, to ensure nfd-face-flags.hpp compiles on its own.
-#include "nfd-face-traits.hpp"
-
+#include "nfd-face-traits.hpp" // include this first, to ensure it compiles on its own.
+#include "../encoding/block.hpp"
#include "../util/time.hpp"
namespace ndn {
diff --git a/src/management/nfd-face-traits.cpp b/src/management/nfd-face-traits.cpp
deleted file mode 100644
index 5556046..0000000
--- a/src/management/nfd-face-traits.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2014 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "nfd-face-traits.hpp"
-
-namespace ndn {
-namespace nfd {
-
-std::ostream&
-operator<<(std::ostream& os, FaceScope faceScope)
-{
- switch (faceScope) {
- case FACE_SCOPE_NON_LOCAL:
- os << "non-local";
- break;
- case FACE_SCOPE_LOCAL:
- os << "local";
- break;
- default:
- os << "unknown";
- break;
- }
- return os;
-}
-
-std::ostream&
-operator<<(std::ostream& os, FacePersistency facePersistency)
-{
- switch (facePersistency) {
- case FACE_PERSISTENCY_PERSISTENT:
- os << "persistent";
- break;
- case FACE_PERSISTENCY_ON_DEMAND:
- os << "on-demand";
- break;
- case FACE_PERSISTENCY_PERMANENT:
- os << "permanent";
- break;
- default:
- os << "unknown";
- break;
- }
- return os;
-}
-
-std::ostream&
-operator<<(std::ostream& os, LinkType linkType)
-{
- switch (linkType) {
- case LINK_TYPE_POINT_TO_POINT:
- os << "point-to-point";
- break;
- case LINK_TYPE_MULTI_ACCESS:
- os << "multi-access";
- break;
- default:
- os << "unknown";
- break;
- }
- return os;
-}
-
-} // namespace nfd
-} // namespace ndn
diff --git a/src/management/nfd-face-traits.hpp b/src/management/nfd-face-traits.hpp
index 0160af1..f473d8a 100644
--- a/src/management/nfd-face-traits.hpp
+++ b/src/management/nfd-face-traits.hpp
@@ -23,63 +23,10 @@
#define NDN_MANAGEMENT_NFD_FACE_TRAITS_HPP
#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/block-helpers.hpp"
namespace ndn {
namespace nfd {
-/**
- * \ingroup management
- * \brief provides additional information about a faceScope
- */
-enum FaceScope {
- /** \brief face is non-local
- */
- FACE_SCOPE_NON_LOCAL = 0,
- /** \brief face is local
- */
- FACE_SCOPE_LOCAL = 1
-};
-
-std::ostream&
-operator<<(std::ostream& os, FaceScope faceScope);
-
-/**
- * \ingroup management
- * \brief provides additional information about a facePersistency
- */
-enum FacePersistency {
- /** \brief face is persistent
- */
- FACE_PERSISTENCY_PERSISTENT = 0,
- /** \brief face is on-demand
- */
- FACE_PERSISTENCY_ON_DEMAND = 1,
- /** \brief face is permanent
- */
- FACE_PERSISTENCY_PERMANENT = 2
-};
-
-std::ostream&
-operator<<(std::ostream& os, FacePersistency facePersistency);
-
-/**
- * \ingroup management
- * \brief provides additional information about a linkType
- */
-enum LinkType {
- /** \brief link is point-to-point
- */
- LINK_TYPE_POINT_TO_POINT = 0,
- /** \brief link is multi-access
- */
- LINK_TYPE_MULTI_ACCESS = 1
-};
-
-std::ostream&
-operator<<(std::ostream& os, LinkType linkType);
-
/** \ingroup management
* \brief providers getters and setters of face information fields
* \tparam C the concrete class; it must provide .wireReset() method
diff --git a/src/management/nfd-fib-entry.cpp b/src/management/nfd-fib-entry.cpp
new file mode 100644
index 0000000..73b5f42
--- /dev/null
+++ b/src/management/nfd-fib-entry.cpp
@@ -0,0 +1,268 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "nfd-fib-entry.hpp"
+#include <sstream>
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
+
+namespace ndn {
+namespace nfd {
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<NextHopRecord>));
+BOOST_CONCEPT_ASSERT((WireEncodable<NextHopRecord>));
+BOOST_CONCEPT_ASSERT((WireDecodable<NextHopRecord>));
+static_assert(std::is_base_of<tlv::Error, NextHopRecord::Error>::value,
+ "NextHopRecord::Error must inherit from tlv::Error");
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FibEntry>));
+BOOST_CONCEPT_ASSERT((WireEncodable<FibEntry>));
+BOOST_CONCEPT_ASSERT((WireDecodable<FibEntry>));
+static_assert(std::is_base_of<tlv::Error, FibEntry::Error>::value,
+ "FibEntry::Error must inherit from tlv::Error");
+
+// NextHopRecord := NEXT-HOP-RECORD TLV-LENGTH
+// FaceId
+// Cost
+
+NextHopRecord::NextHopRecord()
+ : m_faceId(std::numeric_limits<uint64_t>::max())
+ , m_cost(0)
+{
+}
+
+NextHopRecord::NextHopRecord(const Block& block)
+{
+ this->wireDecode(block);
+}
+
+NextHopRecord&
+NextHopRecord::setFaceId(uint64_t faceId)
+{
+ m_faceId = faceId;
+ m_wire.reset();
+ return *this;
+}
+
+NextHopRecord&
+NextHopRecord::setCost(uint64_t cost)
+{
+ m_cost = cost;
+ m_wire.reset();
+ return *this;
+}
+
+template<bool T>
+size_t
+NextHopRecord::wireEncode(EncodingImpl<T>& block) const
+{
+ size_t totalLength = 0;
+ totalLength += prependNonNegativeIntegerBlock(block,
+ ndn::tlv::nfd::Cost,
+ m_cost);
+
+ totalLength += prependNonNegativeIntegerBlock(block,
+ ndn::tlv::nfd::FaceId,
+ m_faceId);
+
+ totalLength += block.prependVarNumber(totalLength);
+ totalLength += block.prependVarNumber(ndn::tlv::nfd::NextHopRecord);
+ return totalLength;
+}
+
+template size_t
+NextHopRecord::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+NextHopRecord::wireEncode<false>(EncodingImpl<false>& block) const;
+
+const Block&
+NextHopRecord::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;
+}
+
+void
+NextHopRecord::wireDecode(const Block& wire)
+{
+ m_faceId = std::numeric_limits<uint64_t>::max();
+ m_cost = 0;
+
+ m_wire = wire;
+
+ if (m_wire.type() != tlv::nfd::NextHopRecord) {
+ std::stringstream error;
+ error << "Requested decoding of NextHopRecord, but Block is of a different type: #"
+ << m_wire.type();
+ throw Error(error.str());
+ }
+ m_wire.parse();
+
+ Block::element_const_iterator val = m_wire.elements_begin();
+ if (val == m_wire.elements_end()) {
+ throw Error("Unexpected end of NextHopRecord");
+ }
+ else if (val->type() != tlv::nfd::FaceId) {
+ std::stringstream error;
+ error << "Expected FaceId, but Block is of a different type: #"
+ << val->type();
+ throw Error(error.str());
+ }
+ m_faceId = readNonNegativeInteger(*val);
+ ++val;
+
+ if (val == m_wire.elements_end()) {
+ throw Error("Unexpected end of NextHopRecord");
+ }
+ else if (val->type() != tlv::nfd::Cost) {
+ std::stringstream error;
+ error << "Expected Cost, but Block is of a different type: #"
+ << m_wire.type();
+ throw Error(error.str());
+ }
+ m_cost = readNonNegativeInteger(*val);
+}
+
+// FibEntry := FIB-ENTRY-TYPE TLV-LENGTH
+// Name
+// NextHopRecord*
+
+FibEntry::FibEntry()
+{
+}
+
+FibEntry::FibEntry(const Block& block)
+{
+ this->wireDecode(block);
+}
+
+FibEntry&
+FibEntry::setPrefix(const Name& prefix)
+{
+ m_prefix = prefix;
+ m_wire.reset();
+ return *this;
+}
+
+FibEntry&
+FibEntry::addNextHopRecord(const NextHopRecord& nextHopRecord)
+{
+ m_nextHopRecords.push_back(nextHopRecord);
+ m_wire.reset();
+ return *this;
+}
+
+template<bool T>
+size_t
+FibEntry::wireEncode(EncodingImpl<T>& block) const
+{
+ size_t totalLength = 0;
+
+ for (auto i = m_nextHopRecords.rbegin(); i != m_nextHopRecords.rend(); ++i) {
+ totalLength += i->wireEncode(block);
+ }
+
+ totalLength += m_prefix.wireEncode(block);
+ totalLength += block.prependVarNumber(totalLength);
+ totalLength += block.prependVarNumber(tlv::nfd::FibEntry);
+
+ return totalLength;
+}
+
+template size_t
+FibEntry::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+FibEntry::wireEncode<false>(EncodingImpl<false>& block) const;
+
+const Block&
+FibEntry::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;
+}
+
+void
+FibEntry::wireDecode(const Block& wire)
+{
+ m_prefix.clear();
+ m_nextHopRecords.clear();
+
+ m_wire = wire;
+
+ if (m_wire.type() != tlv::nfd::FibEntry) {
+ std::stringstream error;
+ error << "Requested decoding of FibEntry, but Block is of a different type: #"
+ << m_wire.type();
+ throw Error(error.str());
+ }
+
+ m_wire.parse();
+
+ Block::element_const_iterator val = m_wire.elements_begin();
+ if (val == m_wire.elements_end()) {
+ throw Error("Unexpected end of FibEntry");
+ }
+ else if (val->type() != tlv::Name) {
+ std::stringstream error;
+ error << "Expected Name, but Block is of a different type: #"
+ << val->type();
+ throw Error(error.str());
+ }
+ m_prefix.wireDecode(*val);
+ ++val;
+
+ for (; val != m_wire.elements_end(); ++val) {
+ if (val->type() != tlv::nfd::NextHopRecord) {
+ std::stringstream error;
+ error << "Expected NextHopRecords, but Block is of a different type: #"
+ << val->type();
+ throw Error(error.str());
+ }
+ m_nextHopRecords.push_back(NextHopRecord(*val));
+ }
+}
+
+} // namespace nfd
+} // namespace ndn
diff --git a/src/management/nfd-fib-entry.hpp b/src/management/nfd-fib-entry.hpp
index 015beba..0e7bb59 100644
--- a/src/management/nfd-fib-entry.hpp
+++ b/src/management/nfd-fib-entry.hpp
@@ -23,23 +23,13 @@
#define NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP
#include "../encoding/block.hpp"
-#include "../encoding/block-helpers.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/tlv-nfd.hpp"
#include "../name.hpp"
-
#include <list>
-#include <sstream>
namespace ndn {
namespace nfd {
-// NextHopRecord := NEXT-HOP-RECORD TLV-LENGTH
-// FaceId
-// Cost
-
-/**
- * @ingroup management
+/** @ingroup management
*/
class NextHopRecord
{
@@ -47,20 +37,17 @@
class Error : public tlv::Error
{
public:
- Error(const std::string& what) : tlv::Error(what) {}
+ explicit
+ Error(const std::string& what)
+ : tlv::Error(what)
+ {
+ }
};
- NextHopRecord()
- : m_faceId(std::numeric_limits<uint64_t>::max())
- , m_cost(0)
- {
- }
+ NextHopRecord();
explicit
- NextHopRecord(const Block& block)
- {
- wireDecode(block);
- }
+ NextHopRecord(const Block& block);
uint64_t
getFaceId() const
@@ -69,12 +56,7 @@
}
NextHopRecord&
- setFaceId(uint64_t faceId)
- {
- m_faceId = faceId;
- m_wire.reset();
- return *this;
- }
+ setFaceId(uint64_t faceId);
uint64_t
getCost() const
@@ -83,95 +65,17 @@
}
NextHopRecord&
- setCost(uint64_t cost)
- {
- m_cost = cost;
- m_wire.reset();
- return *this;
- }
+ setCost(uint64_t cost);
template<bool T>
size_t
- wireEncode(EncodingImpl<T>& block) const
- {
- size_t totalLength = 0;
- totalLength += prependNonNegativeIntegerBlock(block,
- ndn::tlv::nfd::Cost,
- m_cost);
-
- totalLength += prependNonNegativeIntegerBlock(block,
- ndn::tlv::nfd::FaceId,
- m_faceId);
-
- totalLength += block.prependVarNumber(totalLength);
- totalLength += block.prependVarNumber(ndn::tlv::nfd::NextHopRecord);
- return totalLength;
- }
+ wireEncode(EncodingImpl<T>& block) const;
const Block&
- 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;
- }
+ wireEncode() const;
void
- wireDecode(const Block& wire)
- {
- m_faceId = std::numeric_limits<uint64_t>::max();
- m_cost = 0;
-
- m_wire = wire;
-
- if (m_wire.type() != tlv::nfd::NextHopRecord)
- {
- std::stringstream error;
- error << "Requested decoding of NextHopRecord, but Block is of a different type: #"
- << m_wire.type();
- throw Error(error.str());
- }
- m_wire.parse();
-
- Block::element_const_iterator val = m_wire.elements_begin();
- if (val == m_wire.elements_end())
- {
- throw Error("Unexpected end of NextHopRecord");
- }
- else if (val->type() != tlv::nfd::FaceId)
- {
- std::stringstream error;
- error << "Expected FaceId, but Block is of a different type: #"
- << val->type();
- throw Error(error.str());
- }
- m_faceId = readNonNegativeInteger(*val);
- ++val;
-
- if (val == m_wire.elements_end())
- {
- throw Error("Unexpected end of NextHopRecord");
- }
- else if (val->type() != tlv::nfd::Cost)
- {
- std::stringstream error;
- error << "Expected Cost, but Block is of a different type: #"
- << m_wire.type();
- throw Error(error.str());
- }
- m_cost = readNonNegativeInteger(*val);
- }
-
+ wireDecode(const Block& wire);
private:
uint64_t m_faceId;
@@ -180,34 +84,25 @@
mutable Block m_wire;
};
-
-// FibEntry := FIB-ENTRY-TYPE TLV-LENGTH
-// Name
-// NextHopRecord*
-
-/**
- * @ingroup management
+/** @ingroup management
*/
class FibEntry
{
public:
- class Error : public tlv::Error
- {
- public:
- Error(const std::string& what) : tlv::Error(what)
- {
- }
- };
-
- FibEntry()
+ class Error : public tlv::Error
{
- }
+ public:
+ explicit
+ Error(const std::string& what)
+ : tlv::Error(what)
+ {
+ }
+ };
+
+ FibEntry();
explicit
- FibEntry(const Block& block)
- {
- wireDecode(block);
- }
+ FibEntry(const Block& block);
const Name&
getPrefix() const
@@ -216,12 +111,7 @@
}
FibEntry&
- setPrefix(const Name& prefix)
- {
- m_prefix = prefix;
- m_wire.reset();
- return *this;
- }
+ setPrefix(const Name& prefix);
const std::list<NextHopRecord>&
getNextHopRecords() const
@@ -230,12 +120,7 @@
}
FibEntry&
- addNextHopRecord(const NextHopRecord& nextHopRecord)
- {
- m_nextHopRecords.push_back(nextHopRecord);
- m_wire.reset();
- return *this;
- }
+ addNextHopRecord(const NextHopRecord& nextHopRecord);
template<typename T>
FibEntry&
@@ -249,88 +134,13 @@
template<bool T>
size_t
- wireEncode(EncodingImpl<T>& block) const
- {
- size_t totalLength = 0;
-
- for (std::list<NextHopRecord>::const_reverse_iterator i = m_nextHopRecords.rbegin();
- i != m_nextHopRecords.rend();
- ++i)
- {
- totalLength += i->wireEncode(block);
- }
-
- totalLength += m_prefix.wireEncode(block);
- totalLength += block.prependVarNumber(totalLength);
- totalLength += block.prependVarNumber(tlv::nfd::FibEntry);
-
- return totalLength;
- }
+ wireEncode(EncodingImpl<T>& block) const;
const Block&
- 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;
- }
+ wireEncode() const;
void
- wireDecode(const Block& wire)
- {
- m_prefix.clear();
- m_nextHopRecords.clear();
-
- m_wire = wire;
-
- if (m_wire.type() != tlv::nfd::FibEntry)
- {
- std::stringstream error;
- error << "Requested decoding of FibEntry, but Block is of a different type: #"
- << m_wire.type();
- throw Error(error.str());
- }
-
- m_wire.parse();
-
- Block::element_const_iterator val = m_wire.elements_begin();
- if (val == m_wire.elements_end())
- {
- throw Error("Unexpected end of FibEntry");
- }
- else if (val->type() != tlv::Name)
- {
- std::stringstream error;
- error << "Expected Name, but Block is of a different type: #"
- << val->type();
- throw Error(error.str());
- }
- m_prefix.wireDecode(*val);
- ++val;
-
- for (; val != m_wire.elements_end(); ++val)
- {
- if (val->type() != tlv::nfd::NextHopRecord)
- {
- std::stringstream error;
- error << "Expected NextHopRecords, but Block is of a different type: #"
- << val->type();
- throw Error(error.str());
- }
- m_nextHopRecords.push_back(NextHopRecord(*val));
- }
- }
+ wireDecode(const Block& wire);
private:
Name m_prefix;
diff --git a/src/management/nfd-forwarder-status.cpp b/src/management/nfd-forwarder-status.cpp
new file mode 100644
index 0000000..457c673
--- /dev/null
+++ b/src/management/nfd-forwarder-status.cpp
@@ -0,0 +1,319 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "nfd-forwarder-status.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.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");
+
+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)
+{
+}
+
+ForwarderStatus::ForwarderStatus(const Block& payload)
+{
+ this->wireDecode(payload);
+}
+
+template<bool T>
+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;
+}
+
+template size_t
+ForwarderStatus::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+ForwarderStatus::wireEncode<false>(EncodingImpl<false>& block) const;
+
+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;
+}
+
+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");
+ }
+}
+
+ForwarderStatus&
+ForwarderStatus::setNfdVersion(int nfdVersion)
+{
+ m_wire.reset();
+ m_nfdVersion = nfdVersion;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setStartTimestamp(const time::system_clock::TimePoint& startTimestamp)
+{
+ m_wire.reset();
+ m_startTimestamp = startTimestamp;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp)
+{
+ m_wire.reset();
+ m_currentTimestamp = currentTimestamp;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNNameTreeEntries(size_t nNameTreeEntries)
+{
+ m_wire.reset();
+ m_nNameTreeEntries = nNameTreeEntries;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNFibEntries(size_t nFibEntries)
+{
+ m_wire.reset();
+ m_nFibEntries = nFibEntries;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNPitEntries(size_t nPitEntries)
+{
+ m_wire.reset();
+ m_nPitEntries = nPitEntries;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNMeasurementsEntries(size_t nMeasurementsEntries)
+{
+ m_wire.reset();
+ m_nMeasurementsEntries = nMeasurementsEntries;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNCsEntries(size_t nCsEntries)
+{
+ m_wire.reset();
+ m_nCsEntries = nCsEntries;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNInInterests(uint64_t nInInterests)
+{
+ m_wire.reset();
+ m_nInInterests = nInInterests;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNInDatas(uint64_t nInDatas)
+{
+ m_wire.reset();
+ m_nInDatas = nInDatas;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNOutInterests(uint64_t nOutInterests)
+{
+ m_wire.reset();
+ m_nOutInterests = nOutInterests;
+ return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNOutDatas(uint64_t nOutDatas)
+{
+ m_wire.reset();
+ m_nOutDatas = nOutDatas;
+ return *this;
+}
+
+} // namespace nfd
+} // namespace ndn
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
diff --git a/src/management/nfd-rib-entry.cpp b/src/management/nfd-rib-entry.cpp
index f97fa66..9fc7fd9 100644
--- a/src/management/nfd-rib-entry.cpp
+++ b/src/management/nfd-rib-entry.cpp
@@ -20,12 +20,25 @@
*/
#include "nfd-rib-entry.hpp"
-
-#include "management/nfd-control-command.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
namespace ndn {
namespace nfd {
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Route>));
+BOOST_CONCEPT_ASSERT((WireEncodable<Route>));
+BOOST_CONCEPT_ASSERT((WireDecodable<Route>));
+static_assert(std::is_base_of<tlv::Error, Route::Error>::value,
+ "Route::Error must inherit from tlv::Error");
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<RibEntry>));
+BOOST_CONCEPT_ASSERT((WireEncodable<RibEntry>));
+BOOST_CONCEPT_ASSERT((WireDecodable<RibEntry>));
+static_assert(std::is_base_of<tlv::Error, RibEntry::Error>::value,
+ "RibEntry::Error must inherit from tlv::Error");
+
const time::milliseconds Route::INFINITE_EXPIRATION_PERIOD(time::milliseconds::max());
Route::Route()
diff --git a/src/management/nfd-rib-entry.hpp b/src/management/nfd-rib-entry.hpp
index dcdfe50..8fa1704 100644
--- a/src/management/nfd-rib-entry.hpp
+++ b/src/management/nfd-rib-entry.hpp
@@ -22,11 +22,7 @@
#ifndef NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
#define NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
-#include "nfd-rib-flags.hpp"
-
-#include "../encoding/block.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/tlv-nfd.hpp"
+#include "nfd-rib-flags.hpp" // include this first, to ensure it compiles on its own.
#include "../name.hpp"
#include "../util/time.hpp"
@@ -89,6 +85,9 @@
return m_origin;
}
+ /** @brief set Origin
+ * @param origin a code defined in ndn::nfd::RouteOrigin
+ */
Route&
setOrigin(uint64_t origin)
{
@@ -117,6 +116,9 @@
return m_flags;
}
+ /** @brief set route inheritance flags
+ * @param flags a bitwise OR'ed code from ndn::nfd::RouteFlags
+ */
Route&
setFlags(uint64_t flags)
{
diff --git a/src/management/nfd-rib-flags.hpp b/src/management/nfd-rib-flags.hpp
index 73feaa7..07e36d1 100644
--- a/src/management/nfd-rib-flags.hpp
+++ b/src/management/nfd-rib-flags.hpp
@@ -22,22 +22,13 @@
#ifndef NDN_MANAGEMENT_NFD_RIB_FLAGS_HPP
#define NDN_MANAGEMENT_NFD_RIB_FLAGS_HPP
+#include "../encoding/nfd-constants.hpp"
+
namespace ndn {
namespace nfd {
/**
* \ingroup management
- * \brief provides additional information about a RIB entry
- */
-enum RibFlags {
- RIB_CHILD_INHERIT = 1,
- RIB_CAPTURE = 2
- // RIB_? = 4
- // RIB_? = 8
-};
-
-/**
- * \ingroup management
* \brief implements getters to each RIB flag
*
* \tparam T class containing a RibFlags field and implements
@@ -50,13 +41,13 @@
bool
isChildInherit() const
{
- return static_cast<const T*>(this)->getFlags() & RIB_CHILD_INHERIT;
+ return static_cast<const T*>(this)->getFlags() & ROUTE_FLAG_CHILD_INHERIT;
}
bool
isRibCapture() const
{
- return static_cast<const T*>(this)->getFlags() & RIB_CAPTURE;
+ return static_cast<const T*>(this)->getFlags() & ROUTE_FLAG_CAPTURE;
}
};
diff --git a/src/management/nfd-strategy-choice.cpp b/src/management/nfd-strategy-choice.cpp
new file mode 100644
index 0000000..9296954
--- /dev/null
+++ b/src/management/nfd-strategy-choice.cpp
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "nfd-strategy-choice.hpp"
+#include "encoding/tlv-nfd.hpp"
+#include "encoding/block-helpers.hpp"
+#include "util/concepts.hpp"
+
+namespace ndn {
+namespace nfd {
+
+//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<StrategyChoice>));
+BOOST_CONCEPT_ASSERT((WireEncodable<StrategyChoice>));
+BOOST_CONCEPT_ASSERT((WireDecodable<StrategyChoice>));
+static_assert(std::is_base_of<tlv::Error, StrategyChoice::Error>::value,
+ "StrategyChoice::Error must inherit from tlv::Error");
+
+StrategyChoice::StrategyChoice()
+{
+}
+
+StrategyChoice::StrategyChoice(const Block& payload)
+{
+ this->wireDecode(payload);
+}
+
+template<bool T>
+size_t
+StrategyChoice::wireEncode(EncodingImpl<T>& encoder) const
+{
+ size_t totalLength = 0;
+
+ totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
+ totalLength += m_name.wireEncode(encoder);
+
+ totalLength += encoder.prependVarNumber(totalLength);
+ totalLength += encoder.prependVarNumber(tlv::nfd::StrategyChoice);
+ return totalLength;
+}
+
+template size_t
+StrategyChoice::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+StrategyChoice::wireEncode<false>(EncodingImpl<false>& block) const;
+
+const Block&
+StrategyChoice::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;
+}
+
+void
+StrategyChoice::wireDecode(const Block& block)
+{
+ if (block.type() != tlv::nfd::StrategyChoice) {
+ throw Error("expecting StrategyChoice block");
+ }
+ m_wire = block;
+ m_wire.parse();
+ Block::element_const_iterator val = m_wire.elements_begin();
+
+ if (val != m_wire.elements_end() && val->type() == tlv::Name) {
+ m_name.wireDecode(*val);
+ ++val;
+ }
+ else {
+ throw Error("missing required Name field");
+ }
+
+ if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
+ val->parse();
+ if (val->elements().empty()) {
+ throw Error("expecting Strategy/Name");
+ }
+ else {
+ m_strategy.wireDecode(*val->elements_begin());
+ }
+ ++val;
+ }
+ else {
+ throw Error("missing required Strategy field");
+ }
+}
+
+StrategyChoice&
+StrategyChoice::setName(const Name& name)
+{
+ m_wire.reset();
+ m_name = name;
+ return *this;
+}
+
+StrategyChoice&
+StrategyChoice::setStrategy(const Name& strategy)
+{
+ m_wire.reset();
+ m_strategy = strategy;
+ return *this;
+}
+
+} // namespace nfd
+} // namespace ndn
diff --git a/src/management/nfd-strategy-choice.hpp b/src/management/nfd-strategy-choice.hpp
index 2d9bbd5..6fc2f18 100644
--- a/src/management/nfd-strategy-choice.hpp
+++ b/src/management/nfd-strategy-choice.hpp
@@ -22,9 +22,7 @@
#ifndef NDN_MANAGEMENT_NFD_STRATEGY_CHOICE_HPP
#define NDN_MANAGEMENT_NFD_STRATEGY_CHOICE_HPP
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/block-helpers.hpp"
+#include "../encoding/block.hpp"
#include "../name.hpp"
namespace ndn {
@@ -48,15 +46,10 @@
}
};
- StrategyChoice()
- {
- }
+ StrategyChoice();
explicit
- StrategyChoice(const Block& payload)
- {
- this->wireDecode(payload);
- }
+ StrategyChoice(const Block& payload);
template<bool T>
size_t
@@ -76,12 +69,7 @@
}
StrategyChoice&
- setName(const Name& name)
- {
- m_wire.reset();
- m_name = name;
- return *this;
- }
+ setName(const Name& name);
const Name&
getStrategy() const
@@ -90,12 +78,7 @@
}
StrategyChoice&
- setStrategy(const Name& strategy)
- {
- m_wire.reset();
- m_strategy = strategy;
- return *this;
- }
+ setStrategy(const Name& strategy);
private:
Name m_name; // namespace
@@ -104,70 +87,6 @@
mutable Block m_wire;
};
-
-template<bool T>
-inline size_t
-StrategyChoice::wireEncode(EncodingImpl<T>& encoder) const
-{
- size_t totalLength = 0;
-
- totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
- totalLength += m_name.wireEncode(encoder);
-
- totalLength += encoder.prependVarNumber(totalLength);
- totalLength += encoder.prependVarNumber(tlv::nfd::StrategyChoice);
- return totalLength;
-}
-
-inline const Block&
-StrategyChoice::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
-StrategyChoice::wireDecode(const Block& block)
-{
- if (block.type() != tlv::nfd::StrategyChoice) {
- throw Error("expecting StrategyChoice block");
- }
- m_wire = block;
- m_wire.parse();
- Block::element_const_iterator val = m_wire.elements_begin();
-
- if (val != m_wire.elements_end() && val->type() == tlv::Name) {
- m_name.wireDecode(*val);
- ++val;
- }
- else {
- throw Error("missing required Name field");
- }
-
- if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
- val->parse();
- if (val->elements().empty()) {
- throw Error("expecting Strategy/Name");
- }
- else {
- m_strategy.wireDecode(*val->elements_begin());
- }
- ++val;
- }
- else {
- throw Error("missing required Strategy field");
- }
-}
-
} // namespace nfd
} // namespace ndn