management: nfd::ForwarderStatus

nfd::Status is renamed to ForwarderStatus.
Fields are swapped according to new Management protocol.

ForwarderStatus::wireEncode uses Content as outermost element.

refs #1422

Change-Id: I388d5eb56eed2a9958a27e51e010c696e9608ca9
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index e2aee99..6888526 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -49,7 +49,7 @@
   FaceEventKind                = 193,
   FaceFlags                    = 194,
 
-  // Forwarder status
+  // ForwarderStatus
   NfdVersion           = 128,
   StartTimestamp       = 129,
   CurrentTimestamp     = 130,
@@ -58,10 +58,10 @@
   NPitEntries          = 133,
   NMeasurementsEntries = 134,
   NCsEntries           = 135,
-  NInInterests         = TotalIncomingInterestCounter,
-  NOutInterests        = TotalOutgoingInterestCounter,
-  NInDatas             = TotalIncomingDataCounter,
-  NOutDatas            = TotalOutgoingDataCounter
+  NInInterests         = 144,
+  NInDatas             = 145,
+  NOutInterests        = 146,
+  NOutDatas            = 147
 };
 
 enum {
diff --git a/src/management/nfd-forwarder-status.hpp b/src/management/nfd-forwarder-status.hpp
new file mode 100644
index 0000000..de8a93b
--- /dev/null
+++ b/src/management/nfd-forwarder-status.hpp
@@ -0,0 +1,441 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_MANAGEMENT_NFD_FORWARDER_STATUS_HPP
+#define NDN_MANAGEMENT_NFD_FORWARDER_STATUS_HPP
+
+#include "../encoding/tlv-nfd.hpp"
+#include "../encoding/tlv.hpp"
+#include "../encoding/encoding-buffer.hpp"
+
+namespace ndn {
+namespace nfd {
+
+/** \brief represents NFD Forwarder Status
+ *  \sa http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
+ */
+class ForwarderStatus
+{
+public:
+  class Error : public Tlv::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : Tlv::Error(what)
+    {
+    }
+  };
+
+  ForwarderStatus();
+
+  explicit
+  ForwarderStatus(const Block& payload)
+  {
+    this->wireDecode(payload);
+  }
+
+  /** \brief prepend ForwarderStatus as a Content block to the encoder
+   *
+   *  The outermost Content element isn't part of ForwardStatus structure.
+   */
+  template<bool T>
+  size_t
+  wireEncode(EncodingImpl<T>& encoder) const;
+
+  /** \brief encode ForwarderStatus as a Content block
+   *
+   *  The outermost Content element isn't part of ForwardStatus structure.
+   */
+  const Block&
+  wireEncode() const;
+
+  /** \brief decode ForwarderStatus from a Content block
+   *
+   *  The outermost Content element isn't part of ForwardStatus structure.
+   */
+  void
+  wireDecode(const Block& wire);
+
+public: // getters & setters
+  int
+  getNfdVersion() const
+  {
+    return m_nfdVersion;
+  }
+
+  ForwarderStatus&
+  setNfdVersion(int nfdVersion)
+  {
+    m_wire.reset();
+    m_nfdVersion = nfdVersion;
+    return *this;
+  }
+
+  const time::system_clock::TimePoint&
+  getStartTimestamp() const
+  {
+    return m_startTimestamp;
+  }
+
+  ForwarderStatus&
+  setStartTimestamp(const time::system_clock::TimePoint& startTimestamp)
+  {
+    m_wire.reset();
+    m_startTimestamp = startTimestamp;
+    return *this;
+  }
+
+  const time::system_clock::TimePoint&
+  getCurrentTimestamp() const
+  {
+    return m_currentTimestamp;
+  }
+
+  ForwarderStatus&
+  setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp)
+  {
+    m_wire.reset();
+    m_currentTimestamp = currentTimestamp;
+    return *this;
+  }
+
+  size_t
+  getNNameTreeEntries() const
+  {
+    return m_nNameTreeEntries;
+  }
+
+  ForwarderStatus&
+  setNNameTreeEntries(size_t nNameTreeEntries)
+  {
+    m_wire.reset();
+    m_nNameTreeEntries = nNameTreeEntries;
+    return *this;
+  }
+
+  size_t
+  getNFibEntries() const
+  {
+    return m_nFibEntries;
+  }
+
+  ForwarderStatus&
+  setNFibEntries(size_t nFibEntries)
+  {
+    m_wire.reset();
+    m_nFibEntries = nFibEntries;
+    return *this;
+  }
+
+  size_t
+  getNPitEntries() const
+  {
+    return m_nPitEntries;
+  }
+
+  ForwarderStatus&
+  setNPitEntries(size_t nPitEntries)
+  {
+    m_wire.reset();
+    m_nPitEntries = nPitEntries;
+    return *this;
+  }
+
+  size_t
+  getNMeasurementsEntries() const
+  {
+    return m_nMeasurementsEntries;
+  }
+
+  ForwarderStatus&
+  setNMeasurementsEntries(size_t nMeasurementsEntries)
+  {
+    m_wire.reset();
+    m_nMeasurementsEntries = nMeasurementsEntries;
+    return *this;
+  }
+
+  size_t
+  getNCsEntries() const
+  {
+    return m_nCsEntries;
+  }
+
+  ForwarderStatus&
+  setNCsEntries(size_t nCsEntries)
+  {
+    m_wire.reset();
+    m_nCsEntries = nCsEntries;
+    return *this;
+  }
+
+  uint64_t
+  getNInInterests() const
+  {
+    return m_nInInterests;
+  }
+
+  ForwarderStatus&
+  setNInInterests(uint64_t nInInterests)
+  {
+    m_wire.reset();
+    m_nInInterests = nInInterests;
+    return *this;
+  }
+
+  uint64_t
+  getNInDatas() const
+  {
+    return m_nInDatas;
+  }
+
+  ForwarderStatus&
+  setNInDatas(uint64_t nInDatas)
+  {
+    m_wire.reset();
+    m_nInDatas = nInDatas;
+    return *this;
+  }
+
+  uint64_t
+  getNOutInterests() const
+  {
+    return m_nOutInterests;
+  }
+
+  ForwarderStatus&
+  setNOutInterests(uint64_t nOutInterests)
+  {
+    m_wire.reset();
+    m_nOutInterests = nOutInterests;
+    return *this;
+  }
+
+  uint64_t
+  getNOutDatas() const
+  {
+    return m_nOutDatas;
+  }
+
+  ForwarderStatus&
+  setNOutDatas(uint64_t nOutDatas)
+  {
+    m_wire.reset();
+    m_nOutDatas = nOutDatas;
+    return *this;
+  }
+
+private:
+  int m_nfdVersion;
+  time::system_clock::TimePoint m_startTimestamp;
+  time::system_clock::TimePoint m_currentTimestamp;
+  size_t m_nNameTreeEntries;
+  size_t m_nFibEntries;
+  size_t m_nPitEntries;
+  size_t m_nMeasurementsEntries;
+  size_t m_nCsEntries;
+  uint64_t m_nInInterests;
+  uint64_t m_nInDatas;
+  uint64_t m_nOutInterests;
+  uint64_t m_nOutDatas;
+
+  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)
+{
+  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;
+
+  if (block.type() != Tlv::Content) {
+    throw Error("Requested decoding of Status Payload, but block is not Content");
+  }
+  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
+
+#endif // NDN_MANAGEMENT_NFD_FORWARDER_STATUS_HPP
diff --git a/src/management/nfd-status.hpp b/src/management/nfd-status.hpp
index e00c705..4725a66 100644
--- a/src/management/nfd-status.hpp
+++ b/src/management/nfd-status.hpp
@@ -7,336 +7,14 @@
 #ifndef NDN_MANAGEMENT_NFD_STATUS_HPP
 #define NDN_MANAGEMENT_NFD_STATUS_HPP
 
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/tlv.hpp"
-#include "../encoding/encoding-buffer.hpp"
-#include <boost/chrono/include.hpp>
+#include "nfd-forwarder-status.hpp"
 
 namespace ndn {
 namespace nfd {
 
-class Status {
-public:
-  struct Error : public Tlv::Error
-  {
-    Error(const std::string& what)
-      : Tlv::Error(what)
-    {
-    }
-  };
-
-  Status();
-
-  explicit
-  Status(const Block& payload)
-  {
-    this->wireDecode(payload);
-  }
-
-  // Status is encoded as a series of blocks within Data Payload, not a single block.
-  // Thus there is no "const Block& wireEncode() const" method.
-
-  template<bool T>
-  size_t
-  wireEncode(EncodingImpl<T>& encoder) const;
-
-  void
-  wireDecode(const Block& payload);
-
-public:
-  int
-  getNfdVersion() const
-  {
-    return m_nfdVersion;
-  }
-
-  void
-  setNfdVersion(int nfdVersion)
-  {
-    m_nfdVersion = nfdVersion;
-  }
-
-  const time::system_clock::TimePoint&
-  getStartTimestamp() const
-  {
-    return m_startTimestamp;
-  }
-
-  void
-  setStartTimestamp(const time::system_clock::TimePoint& startTimestamp)
-  {
-    m_startTimestamp = startTimestamp;
-  }
-
-  const time::system_clock::TimePoint&
-  getCurrentTimestamp() const
-  {
-    return m_currentTimestamp;
-  }
-
-  void
-  setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp)
-  {
-    m_currentTimestamp = currentTimestamp;
-  }
-
-  size_t
-  getNNameTreeEntries() const
-  {
-    return m_nNameTreeEntries;
-  }
-
-  void
-  setNNameTreeEntries(size_t nNameTreeEntries)
-  {
-    m_nNameTreeEntries = nNameTreeEntries;
-  }
-
-  size_t
-  getNFibEntries() const
-  {
-    return m_nFibEntries;
-  }
-
-  void
-  setNFibEntries(size_t nFibEntries)
-  {
-    m_nFibEntries = nFibEntries;
-  }
-
-  size_t
-  getNPitEntries() const
-  {
-    return m_nPitEntries;
-  }
-
-  void
-  setNPitEntries(size_t nPitEntries)
-  {
-    m_nPitEntries = nPitEntries;
-  }
-
-  size_t
-  getNMeasurementsEntries() const
-  {
-    return m_nMeasurementsEntries;
-  }
-
-  void
-  setNMeasurementsEntries(size_t nMeasurementsEntries)
-  {
-    m_nMeasurementsEntries = nMeasurementsEntries;
-  }
-
-  size_t
-  getNCsEntries() const
-  {
-    return m_nCsEntries;
-  }
-
-  void
-  setNCsEntries(size_t nCsEntries)
-  {
-    m_nCsEntries = nCsEntries;
-  }
-
-  int
-  getNInInterests() const
-  {
-    return m_nInInterests;
-  }
-
-  void
-  setNInInterests(int nInInterests)
-  {
-    m_nInInterests = nInInterests;
-  }
-
-  int
-  getNOutInterests() const
-  {
-    return m_nOutInterests;
-  }
-
-  void
-  setNOutInterests(int nOutInterests)
-  {
-    m_nOutInterests = nOutInterests;
-  }
-
-  int
-  getNInDatas() const
-  {
-    return m_nInDatas;
-  }
-
-  void
-  setNInDatas(int nInDatas)
-  {
-    m_nInDatas = nInDatas;
-  }
-
-  int
-  getNOutDatas() const
-  {
-    return m_nOutDatas;
-  }
-
-  void
-  setNOutDatas(int nOutDatas)
-  {
-    m_nOutDatas = nOutDatas;
-  }
-
-private:
-  int       m_nfdVersion;
-  time::system_clock::TimePoint m_startTimestamp;
-  time::system_clock::TimePoint m_currentTimestamp;
-  size_t    m_nNameTreeEntries;
-  size_t    m_nFibEntries;
-  size_t    m_nPitEntries;
-  size_t    m_nMeasurementsEntries;
-  size_t    m_nCsEntries;
-  int       m_nInInterests;
-  int       m_nOutInterests;
-  int       m_nInDatas;
-  int       m_nOutDatas;
-};
-
-inline
-Status::Status()
-  : 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_nOutInterests(0)
-  , m_nInDatas(0)
-  , m_nOutDatas(0)
-  {
-  }
-
-template<bool T>
-inline size_t
-Status::wireEncode(EncodingImpl<T>& encoder) const
-{
-  size_t total_len = 0;
-
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutDatas,
-                                              m_nOutDatas);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInDatas,
-                                              m_nInDatas);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests,
-                                              m_nOutInterests);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests,
-                                              m_nInInterests);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NCsEntries,
-                                              m_nCsEntries);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NMeasurementsEntries,
-                                              m_nMeasurementsEntries);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NPitEntries,
-                                              m_nPitEntries);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NFibEntries,
-                                              m_nFibEntries);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NNameTreeEntries,
-                                              m_nNameTreeEntries);
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::CurrentTimestamp,
-                                              time::toUnixTimestamp(m_currentTimestamp).count());
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::StartTimestamp,
-                                              time::toUnixTimestamp(m_startTimestamp).count());
-  total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NfdVersion,
-                                              m_nfdVersion);
-
-  return total_len;
-}
-
-inline void
-Status::wireDecode(const Block& payload)
-{
-  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_nOutInterests = 0;
-  m_nInDatas = 0;
-  m_nOutDatas = 0;
-
-  if (payload.type() != Tlv::Content) {
-    throw Error("Requested decoding of Status Payload, but block is not Content");
-  }
-  payload.parse();
-
-  Block::element_const_iterator val;
-
-  val = payload.find(tlv::nfd::NfdVersion);
-  if (val != payload.elements_end()) {
-    m_nfdVersion = static_cast<int>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::StartTimestamp);
-  if (val != payload.elements_end()) {
-    m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
-  }
-
-  val = payload.find(tlv::nfd::CurrentTimestamp);
-  if (val != payload.elements_end()) {
-    m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
-  }
-
-  val = payload.find(tlv::nfd::NNameTreeEntries);
-  if (val != payload.elements_end()) {
-    m_nNameTreeEntries = static_cast<size_t>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NFibEntries);
-  if (val != payload.elements_end()) {
-    m_nFibEntries = static_cast<size_t>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NPitEntries);
-  if (val != payload.elements_end()) {
-    m_nPitEntries = static_cast<size_t>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NMeasurementsEntries);
-  if (val != payload.elements_end()) {
-    m_nMeasurementsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NCsEntries);
-  if (val != payload.elements_end()) {
-    m_nCsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NInInterests);
-  if (val != payload.elements_end()) {
-    m_nInInterests = static_cast<int>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NOutInterests);
-  if (val != payload.elements_end()) {
-    m_nOutInterests = static_cast<int>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NInDatas);
-  if (val != payload.elements_end()) {
-    m_nInDatas = static_cast<int>(readNonNegativeInteger(*val));
-  }
-
-  val = payload.find(tlv::nfd::NOutDatas);
-  if (val != payload.elements_end()) {
-    m_nOutDatas = static_cast<int>(readNonNegativeInteger(*val));
-  }
-}
+/** \deprecated use ForwarderStatus instead
+ */
+typedef ForwarderStatus Status;
 
 } // namespace nfd
 } // namespace ndn
diff --git a/tests/management/nfd-forwarder-status.cpp b/tests/management/nfd-forwarder-status.cpp
new file mode 100644
index 0000000..123459e
--- /dev/null
+++ b/tests/management/nfd-forwarder-status.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "management/nfd-forwarder-status.hpp"
+// Having a separate compilation unit is necessary to ensure .hpp can compile on its own.
+#include "data.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace ndn {
+namespace nfd {
+
+BOOST_AUTO_TEST_SUITE(NfdForwarderStatus)
+
+BOOST_AUTO_TEST_CASE(Encode)
+{
+  ForwarderStatus status1;
+  status1.setNfdVersion(1014210635);
+  status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325)));
+  status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272)));
+  status1.setNNameTreeEntries(1849943160);
+  status1.setNFibEntries(621739748);
+  status1.setNPitEntries(482129741);
+  status1.setNMeasurementsEntries(1771725298);
+  status1.setNCsEntries(1264968688);
+  status1.setNInInterests(612811615);
+  status1.setNInDatas(1843576050);
+  status1.setNOutInterests(952144445);
+  status1.setNOutDatas(138198826);
+
+  EncodingBuffer buffer;
+  status1.wireEncode(buffer);
+  Block wire = buffer.block();
+
+  // These octets are obtained by the snippet below.
+  // This check is intended to detect unexpected encoding change in the future.
+  //for (Buffer::iterator it = buffer.begin(); it != buffer.end(); ++it) {
+  //  printf("0x%02x, ", *it);
+  //}
+  static const uint8_t expected[] = {
+    0x15, 0x50, 0x80, 0x04, 0x3c, 0x73, 0xa0, 0x4b, 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, 0x04,
+    0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, 0x04,
+    0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x92, 0x04,
+    0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, 0x3c, 0xbf, 0x2a
+  };
+  BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+                                  wire.begin(), wire.end());
+
+  Data data;
+  data.setContent(wire);
+
+  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.getNOutInterests(), status2.getNOutInterests());
+  BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace nfd
+} // namespace ndn
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index de9a1bb..6e3de4d 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -9,8 +9,6 @@
 #include "management/nfd-face-management-options.hpp"
 #include "management/nfd-face-event-notification.hpp"
 #include "management/nfd-face-status.hpp"
-#include "management/nfd-status.hpp"
-#include "data.hpp"
 
 #include <boost/test/unit_test.hpp>
 #include <boost/test/output_test_stream.hpp>
@@ -228,43 +226,6 @@
   }
 }
 
-BOOST_AUTO_TEST_CASE(NfdStatusEncode)
-{
-  Status status1;
-  status1.setNfdVersion(1014210635);
-  status1.setStartTimestamp(time::fromUnixTimestamp(time::seconds(375193249)));
-  status1.setCurrentTimestamp(time::fromUnixTimestamp(time::seconds(1886109034)));
-  status1.setNNameTreeEntries(1849943160);
-  status1.setNFibEntries(621739748);
-  status1.setNPitEntries(482129741);
-  status1.setNMeasurementsEntries(1771725298);
-  status1.setNCsEntries(1264968688);
-  status1.setNInInterests(612811615);
-  status1.setNOutInterests(952144445);
-  status1.setNInDatas(1843576050);
-  status1.setNOutDatas(138198826);
-
-  EncodingBuffer buffer;
-  status1.wireEncode(buffer);
-
-  Data data;
-  data.setContent(buffer.buf(), buffer.size());
-
-  Status 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.getNOutInterests(), status2.getNOutInterests());
-  BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
-  BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
-}
-
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace nfd
diff --git a/tests/security/identity-fixture.cpp b/tests/security/identity-fixture.cpp
index 2cc7e4f..1c286e2 100644
--- a/tests/security/identity-fixture.cpp
+++ b/tests/security/identity-fixture.cpp
@@ -19,7 +19,13 @@
   IdentityFixture()
   {
     // save the old default identity
-    m_oldDefaultIdentity = m_keyChain.getDefaultIdentity();
+    try {
+      m_oldDefaultIdentity = m_keyChain.getDefaultIdentity();
+      m_hasOldDefaultIdentity = true;
+    }
+    catch (SecPublicInfo::Error& e) {
+      m_hasOldDefaultIdentity = false;
+    }
 
     m_newIdentity.set("/ndn-cpp-dev-test-identity");
     m_newIdentity.appendVersion();
@@ -35,14 +41,19 @@
   ~IdentityFixture()
   {
     // recover the old default setting
-    m_keyChain.setDefaultIdentity(m_oldDefaultIdentity);
+    if (m_hasOldDefaultIdentity) {
+      m_keyChain.setDefaultIdentity(m_oldDefaultIdentity);
+    }
 
     // remove the temporarily created identity and certificates
+    // XXX This has no effect if oldDefaultIdentity doesn't exist.
+    //     newIdentity would be kept as default.
     m_keyChain.deleteIdentity(m_newIdentity);
   }
 
 private:
   KeyChain m_keyChain;
+  bool m_hasOldDefaultIdentity;
   Name m_oldDefaultIdentity;
   Name m_newIdentity;
 };