management: NACK counters

refs #3174

Change-Id: I647cddc777e079dce4b7c7574ec2cccb04da6630
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index 77533df..eff0f54 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -72,8 +72,10 @@
   // ForwarderStatus and FaceStatus counters
   NInInterests  = 144,
   NInDatas      = 145,
+  NInNacks      = 151,
   NOutInterests = 146,
   NOutDatas     = 147,
+  NOutNacks     = 152,
   NInBytes      = 148,
   NOutBytes     = 149,
 
diff --git a/src/management/nfd-face-status.cpp b/src/management/nfd-face-status.cpp
index 30af9fb..ca24a99 100644
--- a/src/management/nfd-face-status.cpp
+++ b/src/management/nfd-face-status.cpp
@@ -37,8 +37,10 @@
   : m_hasExpirationPeriod(false)
   , m_nInInterests(0)
   , m_nInDatas(0)
+  , m_nInNacks(0)
   , m_nOutInterests(0)
   , m_nOutDatas(0)
+  , m_nOutNacks(0)
   , m_nInBytes(0)
   , m_nOutBytes(0)
 {
@@ -60,10 +62,14 @@
   totalLength += prependNonNegativeIntegerBlock(encoder,
                  tlv::nfd::NInBytes, m_nInBytes);
   totalLength += prependNonNegativeIntegerBlock(encoder,
+                 tlv::nfd::NOutNacks, m_nOutNacks);
+  totalLength += prependNonNegativeIntegerBlock(encoder,
                  tlv::nfd::NOutDatas, m_nOutDatas);
   totalLength += prependNonNegativeIntegerBlock(encoder,
                  tlv::nfd::NOutInterests, m_nOutInterests);
   totalLength += prependNonNegativeIntegerBlock(encoder,
+                 tlv::nfd::NInNacks, m_nInNacks);
+  totalLength += prependNonNegativeIntegerBlock(encoder,
                  tlv::nfd::NInDatas, m_nInDatas);
   totalLength += prependNonNegativeIntegerBlock(encoder,
                  tlv::nfd::NInInterests, m_nInInterests);
@@ -195,6 +201,14 @@
     BOOST_THROW_EXCEPTION(Error("missing required NInDatas field"));
   }
 
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
+    m_nInNacks = readNonNegativeInteger(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
+  }
+
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
     m_nOutInterests = readNonNegativeInteger(*val);
     ++val;
@@ -211,6 +225,14 @@
     BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field"));
   }
 
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
+    m_nOutNacks = readNonNegativeInteger(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field"));
+  }
+
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInBytes) {
     m_nInBytes = readNonNegativeInteger(*val);
     ++val;
@@ -254,6 +276,14 @@
 }
 
 FaceStatus&
+FaceStatus::setNInNacks(uint64_t nInNacks)
+{
+  m_wire.reset();
+  m_nInNacks = nInNacks;
+  return *this;
+}
+
+FaceStatus&
 FaceStatus::setNOutInterests(uint64_t nOutInterests)
 {
   m_wire.reset();
@@ -270,6 +300,14 @@
 }
 
 FaceStatus&
+FaceStatus::setNOutNacks(uint64_t nOutNacks)
+{
+  m_wire.reset();
+  m_nOutNacks = nOutNacks;
+  return *this;
+}
+
+FaceStatus&
 FaceStatus::setNInBytes(uint64_t nInBytes)
 {
   m_wire.reset();
@@ -313,6 +351,8 @@
      << "out: " << status.getNOutInterests() << "},\n"
      << "            Data: {in: " << status.getNInDatas() << ", "
      << "out: " << status.getNOutDatas() << "},\n"
+     << "            Nack: {in: " << status.getNInNacks() << ", "
+     << "out: " << status.getNOutNacks() << "},\n"
      << "            bytes: {in: " << status.getNInBytes() << ", "
      << "out: " << status.getNOutBytes() << "} }\n"
      << ")";
diff --git a/src/management/nfd-face-status.hpp b/src/management/nfd-face-status.hpp
index f29b568..521f3d3 100644
--- a/src/management/nfd-face-status.hpp
+++ b/src/management/nfd-face-status.hpp
@@ -94,6 +94,15 @@
   setNInDatas(uint64_t nInDatas);
 
   uint64_t
+  getNInNacks() const
+  {
+    return m_nInNacks;
+  }
+
+  FaceStatus&
+  setNInNacks(uint64_t nInNacks);
+
+  uint64_t
   getNOutInterests() const
   {
     return m_nOutInterests;
@@ -112,6 +121,15 @@
   setNOutDatas(uint64_t nOutDatas);
 
   uint64_t
+  getNOutNacks() const
+  {
+    return m_nOutNacks;
+  }
+
+  FaceStatus&
+  setNOutNacks(uint64_t nOutNacks);
+
+  uint64_t
   getNInBytes() const
   {
     return m_nInBytes;
@@ -138,8 +156,10 @@
   bool m_hasExpirationPeriod;
   uint64_t m_nInInterests;
   uint64_t m_nInDatas;
+  uint64_t m_nInNacks;
   uint64_t m_nOutInterests;
   uint64_t m_nOutDatas;
+  uint64_t m_nOutNacks;
   uint64_t m_nInBytes;
   uint64_t m_nOutBytes;
 
diff --git a/src/management/nfd-forwarder-status.cpp b/src/management/nfd-forwarder-status.cpp
index 81b3bb9..8292f19 100644
--- a/src/management/nfd-forwarder-status.cpp
+++ b/src/management/nfd-forwarder-status.cpp
@@ -43,8 +43,10 @@
   , m_nCsEntries(0)
   , m_nInInterests(0)
   , m_nInDatas(0)
+  , m_nInNacks(0)
   , m_nOutInterests(0)
   , m_nOutDatas(0)
+  , m_nOutNacks(0)
 {
 }
 
@@ -59,10 +61,14 @@
 {
   size_t totalLength = 0;
 
+  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutNacks,
+                                                m_nOutNacks);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutDatas,
                                                 m_nOutDatas);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests,
                                                 m_nOutInterests);
+  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInNacks,
+                                                m_nInNacks);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInDatas,
                                                 m_nInDatas);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests,
@@ -202,6 +208,14 @@
     BOOST_THROW_EXCEPTION(Error("missing required NInDatas field"));
   }
 
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
+    m_nInNacks = static_cast<uint64_t>(readNonNegativeInteger(*val));
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
+  }
+
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
     m_nOutInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
     ++val;
@@ -217,6 +231,14 @@
   else {
     BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field"));
   }
+
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
+    m_nOutNacks = static_cast<uint64_t>(readNonNegativeInteger(*val));
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
+  }
 }
 
 ForwarderStatus&
@@ -300,6 +322,14 @@
 }
 
 ForwarderStatus&
+ForwarderStatus::setNInNacks(uint64_t nInNacks)
+{
+  m_wire.reset();
+  m_nInNacks = nInNacks;
+  return *this;
+}
+
+ForwarderStatus&
 ForwarderStatus::setNOutInterests(uint64_t nOutInterests)
 {
   m_wire.reset();
@@ -315,5 +345,13 @@
   return *this;
 }
 
+ForwarderStatus&
+ForwarderStatus::setNOutNacks(uint64_t nOutNacks)
+{
+  m_wire.reset();
+  m_nOutNacks = nOutNacks;
+  return *this;
+}
+
 } // namespace nfd
 } // namespace ndn
diff --git a/src/management/nfd-forwarder-status.hpp b/src/management/nfd-forwarder-status.hpp
index 11f59e1..7083cb6 100644
--- a/src/management/nfd-forwarder-status.hpp
+++ b/src/management/nfd-forwarder-status.hpp
@@ -165,6 +165,15 @@
   setNInDatas(uint64_t nInDatas);
 
   uint64_t
+  getNInNacks() const
+  {
+    return m_nInNacks;
+  }
+
+  ForwarderStatus&
+  setNInNacks(uint64_t nInNacks);
+
+  uint64_t
   getNOutInterests() const
   {
     return m_nOutInterests;
@@ -182,6 +191,15 @@
   ForwarderStatus&
   setNOutDatas(uint64_t nOutDatas);
 
+  uint64_t
+  getNOutNacks() const
+  {
+    return m_nOutNacks;
+  }
+
+  ForwarderStatus&
+  setNOutNacks(uint64_t nOutNacks);
+
 private:
   std::string m_nfdVersion;
   time::system_clock::TimePoint m_startTimestamp;
@@ -193,8 +211,10 @@
   size_t m_nCsEntries;
   uint64_t m_nInInterests;
   uint64_t m_nInDatas;
+  uint64_t m_nInNacks;
   uint64_t m_nOutInterests;
   uint64_t m_nOutDatas;
+  uint64_t m_nOutNacks;
 
   mutable Block m_wire;
 };
diff --git a/tests/unit-tests/management/nfd-face-status.t.cpp b/tests/unit-tests/management/nfd-face-status.t.cpp
index f502f13..8afb0cc 100644
--- a/tests/unit-tests/management/nfd-face-status.t.cpp
+++ b/tests/unit-tests/management/nfd-face-status.t.cpp
@@ -41,8 +41,10 @@
          .setExpirationPeriod(time::seconds(10))
          .setNInInterests(10)
          .setNInDatas(200)
+         .setNInNacks(1)
          .setNOutInterests(3000)
          .setNOutDatas(4)
+         .setNOutNacks(2)
          .setNInBytes(1329719163)
          .setNOutBytes(999110448);
 
@@ -55,15 +57,16 @@
   //  printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
-    0x80, 0x58, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
+    0x80, 0x5e, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
     0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e,
     0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16,
     0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
     0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35, 0x35, 0x35,
     0x35, 0x35, 0x6d, 0x02, 0x27, 0x10, 0x84, 0x01, 0x01, 0x85,
     0x01, 0x01, 0x86, 0x01, 0x01, 0x90, 0x01, 0x0a, 0x91, 0x01,
-    0xc8, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04, 0x94, 0x04,
-    0x4f, 0x41, 0xe7, 0x7b, 0x95, 0x04, 0x3b, 0x8d, 0x37, 0x30,
+    0xc8, 0x97, 0x01, 0x01, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01,
+    0x04, 0x98, 0x01, 0x02, 0x94, 0x04, 0x4f, 0x41, 0xe7, 0x7b,
+    0x95, 0x04, 0x3b, 0x8d, 0x37, 0x30,
   };
   BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
                                 wire.begin(), wire.end());
@@ -78,8 +81,10 @@
   BOOST_CHECK_EQUAL(status1.getLinkType(), status2.getLinkType());
   BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
   BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
+  BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks());
   BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
   BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+  BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks());
   BOOST_CHECK_EQUAL(status1.getNInBytes(), status2.getNInBytes());
   BOOST_CHECK_EQUAL(status1.getNOutBytes(), status2.getNOutBytes());
 
@@ -94,6 +99,7 @@
                               "LinkType: multi-access,\n"
                               "Counters: { Interests: {in: 10, out: 3000},\n"
                               "            Data: {in: 200, out: 4},\n"
+                              "            Nack: {in: 1, out: 2},\n"
                               "            bytes: {in: 1329719163, out: 999110448} }\n"
                               ")");
 }
diff --git a/tests/unit-tests/management/nfd-forwarder-status.t.cpp b/tests/unit-tests/management/nfd-forwarder-status.t.cpp
index c313791..6adc1d9 100644
--- a/tests/unit-tests/management/nfd-forwarder-status.t.cpp
+++ b/tests/unit-tests/management/nfd-forwarder-status.t.cpp
@@ -43,8 +43,10 @@
   status1.setNCsEntries(1264968688);
   status1.setNInInterests(612811615);
   status1.setNInDatas(1843576050);
+  status1.setNInNacks(1234);
   status1.setNOutInterests(952144445);
   status1.setNOutDatas(138198826);
+  status1.setNOutNacks(4321);
 
   Block wire;
   BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
@@ -55,14 +57,15 @@
   //  printf("0x%02x, ", *it);
   //}
   static const uint8_t expected[] = {
-    0x15, 0x5d, 0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35,
+    0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35,
     0x2d, 0x67, 0x37, 0x35, 0x61, 0x62, 0x36, 0x62, 0x37, 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
+    0x04, 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x97,
+    0x02, 0x04, 0xd2, 0x92, 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08,
+    0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1,
   };
   BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
                                   wire.begin(), wire.end());
@@ -82,8 +85,10 @@
   BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
   BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
   BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
+  BOOST_CHECK_EQUAL(status1.getNInNacks(), status2.getNInNacks());
   BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
   BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+  BOOST_CHECK_EQUAL(status1.getNOutNacks(), status2.getNOutNacks());
 }
 
 BOOST_AUTO_TEST_SUITE_END()