mgmt: augment ForwarderStatus with counters for satisfied and unsatisfied Interests

refs: #4720

Change-Id: I9413aef59a9f4669beaaa214abd93c4bb40e622f
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index dcaed7e..6eff057 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -75,14 +75,16 @@
   FaceEventKind                 = 193,
 
   // ForwarderStatus and FaceStatus counters
-  NInInterests  = 144,
-  NInData       = 145,
-  NInNacks      = 151,
-  NOutInterests = 146,
-  NOutData      = 147,
-  NOutNacks     = 152,
-  NInBytes      = 148,
-  NOutBytes     = 149,
+  NInInterests          = 144,
+  NInData               = 145,
+  NInNacks              = 151,
+  NOutInterests         = 146,
+  NOutData              = 147,
+  NOutNacks             = 152,
+  NInBytes              = 148,
+  NOutBytes             = 149,
+  NSatisfiedInterests   = 153,
+  NUnsatisfiedInterests = 154,
 
   // Content Store Management
   CsInfo  = 128,
diff --git a/src/mgmt/nfd/forwarder-status.cpp b/src/mgmt/nfd/forwarder-status.cpp
index 1661aa7..fb583d8 100644
--- a/src/mgmt/nfd/forwarder-status.cpp
+++ b/src/mgmt/nfd/forwarder-status.cpp
@@ -42,6 +42,8 @@
   , m_nOutInterests(0)
   , m_nOutData(0)
   , m_nOutNacks(0)
+  , m_nSatisfiedInterests(0)
+  , m_nUnsatisfiedInterests(0)
 {
 }
 
@@ -56,6 +58,8 @@
 {
   size_t totalLength = 0;
 
+  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NUnsatisfiedInterests, m_nUnsatisfiedInterests);
+  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NSatisfiedInterests, m_nSatisfiedInterests);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutNacks, m_nOutNacks);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutData, m_nOutData);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests, m_nOutInterests);
@@ -217,6 +221,22 @@
   else {
     BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field"));
   }
+
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NSatisfiedInterests) {
+    m_nSatisfiedInterests = readNonNegativeInteger(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NSatisfiedInterests field"));
+  }
+
+  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NUnsatisfiedInterests) {
+    m_nUnsatisfiedInterests = readNonNegativeInteger(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("missing required NUnsatisfiedInterests field"));
+  }
 }
 
 ForwarderStatus&
@@ -331,6 +351,22 @@
   return *this;
 }
 
+ForwarderStatus&
+ForwarderStatus::setNSatisfiedInterests(uint64_t nSatisfiedInterests)
+{
+  m_wire.reset();
+  m_nSatisfiedInterests = nSatisfiedInterests;
+  return *this;
+}
+
+ForwarderStatus&
+ForwarderStatus::setNUnsatisfiedInterests(uint64_t nUnsatisfiedInterests)
+{
+  m_wire.reset();
+  m_nUnsatisfiedInterests = nUnsatisfiedInterests;
+  return *this;
+}
+
 bool
 operator==(const ForwarderStatus& a, const ForwarderStatus& b)
 {
@@ -347,7 +383,9 @@
       a.getNInNacks() == b.getNInNacks() &&
       a.getNOutInterests() == b.getNOutInterests() &&
       a.getNOutData() == b.getNOutData() &&
-      a.getNOutNacks() == b.getNOutNacks();
+      a.getNOutNacks() == b.getNOutNacks() &&
+      a.getNSatisfiedInterests() == b.getNSatisfiedInterests() &&
+      a.getNUnsatisfiedInterests() == b.getNUnsatisfiedInterests();
 }
 
 std::ostream&
@@ -366,7 +404,9 @@
      << "                         Data: {in: " << status.getNInData() << ", "
      << "out: " << status.getNOutData() << "},\n"
      << "                         Nacks: {in: " << status.getNInNacks() << ", "
-     << "out: " << status.getNOutNacks() << "}}\n"
+     << "out: " << status.getNOutNacks() << "},\n"
+     << "                         SatisfiedInterests: " << status.getNSatisfiedInterests() << ",\n"
+     << "                         UnsatisfiedInterests: " << status.getNUnsatisfiedInterests() << "}\n"
      << "              )";
 
   return os;
diff --git a/src/mgmt/nfd/forwarder-status.hpp b/src/mgmt/nfd/forwarder-status.hpp
index f222f80..0991e6c 100644
--- a/src/mgmt/nfd/forwarder-status.hpp
+++ b/src/mgmt/nfd/forwarder-status.hpp
@@ -196,6 +196,24 @@
   ForwarderStatus&
   setNOutNacks(uint64_t nOutNacks);
 
+  uint64_t
+  getNSatisfiedInterests() const
+  {
+    return m_nSatisfiedInterests;
+  }
+
+  ForwarderStatus&
+  setNSatisfiedInterests(uint64_t nSatisfiedInterests);
+
+  uint64_t
+  getNUnsatisfiedInterests() const
+  {
+    return m_nUnsatisfiedInterests;
+  }
+
+  ForwarderStatus&
+  setNUnsatisfiedInterests(uint64_t nUnsatisfiedInterests);
+
 private:
   std::string m_nfdVersion;
   time::system_clock::TimePoint m_startTimestamp;
@@ -211,6 +229,8 @@
   uint64_t m_nOutInterests;
   uint64_t m_nOutData;
   uint64_t m_nOutNacks;
+  uint64_t m_nSatisfiedInterests;
+  uint64_t m_nUnsatisfiedInterests;
 
   mutable Block m_wire;
 };
diff --git a/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp b/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
index 3d91b30..b2c3d48 100644
--- a/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/forwarder-status.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -49,7 +49,9 @@
       .setNInNacks(1234)
       .setNOutInterests(952144445)
       .setNOutData(138198826)
-      .setNOutNacks(4321);
+      .setNOutNacks(4321)
+      .setNSatisfiedInterests(961020)
+      .setNUnsatisfiedInterests(941024);
 }
 
 BOOST_AUTO_TEST_CASE(Encode)
@@ -63,7 +65,7 @@
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
-    0x15, 0x65, 0x80, 0x11, 0x30, 0x2e, 0x35, 0x2e, 0x31, 0x2d, 0x31, 0x34,
+    0x15, 0x71, 0x80, 0x11, 0x30, 0x2e, 0x35, 0x2e, 0x31, 0x2d, 0x31, 0x34,
     0x2d, 0x67, 0x30, 0x35, 0x64, 0x64, 0x34, 0x34, 0x34, 0x81, 0x08, 0x00,
     0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00,
     0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84,
@@ -71,7 +73,8 @@
     0x04, 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90,
     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,
+    0x3c, 0xbf, 0x2a, 0x98, 0x02, 0x10, 0xe1, 0x99, 0x04, 0x00, 0x0e, 0xa9,
+    0xfc, 0x9a, 0x04, 0x00, 0x0e, 0x5b, 0xe0,
   };
   BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
                                 wire.begin(), wire.end());
@@ -106,7 +109,9 @@
                     "                         CsEntries: 0,\n"
                     "                         Interests: {in: 0, out: 0},\n"
                     "                         Data: {in: 0, out: 0},\n"
-                    "                         Nacks: {in: 0, out: 0}}\n"
+                    "                         Nacks: {in: 0, out: 0},\n"
+                    "                         SatisfiedInterests: 0,\n"
+                    "                         UnsatisfiedInterests: 0}\n"
                     "              )");
 
   status = makeForwarderStatus();
@@ -121,7 +126,9 @@
                     "                         CsEntries: 1264968688,\n"
                     "                         Interests: {in: 612811615, out: 952144445},\n"
                     "                         Data: {in: 1843576050, out: 138198826},\n"
-                    "                         Nacks: {in: 1234, out: 4321}}\n"
+                    "                         Nacks: {in: 1234, out: 4321},\n"
+                    "                         SatisfiedInterests: 961020,\n"
+                    "                         UnsatisfiedInterests: 941024}\n"
                     "              )");
 }