mgmt: expose link layer counters in Face Dataset
refs #1767
Change-Id: If0b66ead4c2f2741c83396f251cce9a0d83c1520
diff --git a/daemon/face/face-counters.hpp b/daemon/face/face-counters.hpp
index 05303b5..6dc1d6a 100644
--- a/daemon/face/face-counters.hpp
+++ b/daemon/face/face-counters.hpp
@@ -67,7 +67,6 @@
rep m_value;
};
-
/** \brief represents a counter of number of bytes
*/
// ByteCounter is noncopyable, because increment should be called on the counter,
@@ -104,7 +103,6 @@
rep m_value;
};
-
/** \brief contains network layer packet counters
*/
class NetworkLayerCounters : noncopyable
@@ -162,6 +160,20 @@
return m_nOutDatas;
}
+protected:
+ /** \brief copy current obseverations to a struct
+ * \param recipient an object with set methods for counters
+ */
+ template<typename R>
+ void
+ copyTo(R& recipient) const
+ {
+ recipient.setNInInterests(this->getNInInterests());
+ recipient.setNInDatas(this->getNInDatas());
+ recipient.setNOutInterests(this->getNOutInterests());
+ recipient.setNOutDatas(this->getNOutDatas());
+ }
+
private:
PacketCounter m_nInInterests;
PacketCounter m_nInDatas;
@@ -169,7 +181,6 @@
PacketCounter m_nOutDatas;
};
-
/** \brief contains link layer byte counters
*/
class LinkLayerCounters : noncopyable
@@ -201,16 +212,38 @@
return m_nOutBytes;
}
+protected:
+ /** \brief copy current obseverations to a struct
+ * \param recipient an object with set methods for counters
+ */
+ template<typename R>
+ void
+ copyTo(R& recipient) const
+ {
+ recipient.setNInBytes(this->getNInBytes());
+ recipient.setNOutBytes(this->getNOutBytes());
+ }
+
private:
ByteCounter m_nInBytes;
ByteCounter m_nOutBytes;
};
-
/** \brief contains counters on face
*/
class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
{
+public:
+ /** \brief copy current obseverations to a struct
+ * \param recipient an object with set methods for counters
+ */
+ template<typename R>
+ void
+ copyTo(R& recipient) const
+ {
+ this->NetworkLayerCounters::copyTo(recipient);
+ this->LinkLayerCounters::copyTo(recipient);
+ }
};
} // namespace nfd
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 4197aa5..385f0a9 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -128,17 +128,13 @@
ndn::nfd::FaceStatus
Face::getFaceStatus() const
{
- const FaceCounters& counters = getCounters();
-
ndn::nfd::FaceStatus status;
status.setFaceId(getId())
.setRemoteUri(getRemoteUri().toString())
.setLocalUri(getLocalUri().toString())
- .setFlags(getFaceFlags(*this))
- .setNInInterests(counters.getNInInterests())
- .setNInDatas(counters.getNInDatas())
- .setNOutInterests(counters.getNOutInterests())
- .setNOutDatas(counters.getNOutDatas());
+ .setFlags(getFaceFlags(*this));
+
+ this->getCounters().copyTo(status);
return status;
}
diff --git a/daemon/fw/forwarder-counters.hpp b/daemon/fw/forwarder-counters.hpp
index 7af679a..ba3b57c 100644
--- a/daemon/fw/forwarder-counters.hpp
+++ b/daemon/fw/forwarder-counters.hpp
@@ -34,9 +34,18 @@
*/
class ForwarderCounters : public NetworkLayerCounters
{
+public:
+ /** \brief copy current obseverations to a struct
+ * \param recipient an object with set methods for counters
+ */
+ template<typename R>
+ void
+ copyTo(R& recipient) const
+ {
+ this->NetworkLayerCounters::copyTo(recipient);
+ }
};
-
} // namespace nfd
#endif // NFD_DAEMON_FW_FORWARDER_COUNTERS_HPP
diff --git a/daemon/mgmt/status-server.cpp b/daemon/mgmt/status-server.cpp
index 148061c..51faca4 100644
--- a/daemon/mgmt/status-server.cpp
+++ b/daemon/mgmt/status-server.cpp
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
#include "status-server.hpp"
#include "fw/forwarder.hpp"
@@ -71,11 +72,7 @@
status->setNMeasurementsEntries(m_forwarder.getMeasurements().size());
status->setNCsEntries(m_forwarder.getCs().size());
- const ForwarderCounters& counters = m_forwarder.getCounters();
- status->setNInInterests(counters.getNInInterests());
- status->setNInDatas(counters.getNInDatas());
- status->setNOutInterests(counters.getNOutInterests());
- status->setNOutDatas(counters.getNOutDatas());
+ m_forwarder.getCounters().copyTo(*status);
return status;
}
diff --git a/tests/daemon/mgmt/face-manager.cpp b/tests/daemon/mgmt/face-manager.cpp
index 602db76..482330d 100644
--- a/tests/daemon/mgmt/face-manager.cpp
+++ b/tests/daemon/mgmt/face-manager.cpp
@@ -1694,26 +1694,14 @@
Name commandName("/localhost/nfd/faces/list");
shared_ptr<Interest> command(make_shared<Interest>(commandName));
- // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
- // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
- // to force a FaceStatus to span Data packets
- for (int i = 0; i < 79; i++)
+ // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
+ // use 59 FaceStatuses to force a FaceStatus to span Data packets
+ for (int i = 0; i < 59; i++)
{
shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
- dummy->setCounters(filler, filler, filler, filler);
-
- m_referenceFaces.push_back(dummy);
-
- add(dummy);
- }
-
- for (int i = 0; i < 2; i++)
- {
- shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
- uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
- dummy->setCounters(filler, filler, filler, filler);
+ dummy->setCounters(filler, filler, filler, filler, filler, filler);
m_referenceFaces.push_back(dummy);
diff --git a/tests/daemon/mgmt/face-status-publisher-common.hpp b/tests/daemon/mgmt/face-status-publisher-common.hpp
index 0779997..3d4ff52 100644
--- a/tests/daemon/mgmt/face-status-publisher-common.hpp
+++ b/tests/daemon/mgmt/face-status-publisher-common.hpp
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
#ifndef NFD_TESTS_NFD_MGMT_FACE_STATUS_PUBLISHER_COMMON_HPP
#define NFD_TESTS_NFD_MGMT_FACE_STATUS_PUBLISHER_COMMON_HPP
@@ -56,13 +57,17 @@
setCounters(PacketCounter::rep nInInterests,
PacketCounter::rep nInDatas,
PacketCounter::rep nOutInterests,
- PacketCounter::rep nOutDatas)
+ PacketCounter::rep nOutDatas,
+ ByteCounter::rep nInBytes,
+ ByteCounter::rep nOutBytes)
{
FaceCounters& counters = getMutableCounters();
counters.getNInInterests().set(nInInterests);
counters.getNInDatas().set(nInDatas);
counters.getNOutInterests().set(nOutInterests);
counters.getNOutDatas().set(nOutDatas);
+ counters.getNInBytes().set(nInBytes);
+ counters.getNOutBytes().set(nOutBytes);
}
@@ -135,6 +140,8 @@
BOOST_CHECK_EQUAL(status.getNInDatas(), counters.getNInDatas());
BOOST_CHECK_EQUAL(status.getNOutInterests(), counters.getNOutInterests());
BOOST_CHECK_EQUAL(status.getNOutDatas(), counters.getNOutDatas());
+ BOOST_CHECK_EQUAL(status.getNInBytes(), counters.getNInBytes());
+ BOOST_CHECK_EQUAL(status.getNOutBytes(), counters.getNOutBytes());
}
void
diff --git a/tests/daemon/mgmt/face-status-publisher.cpp b/tests/daemon/mgmt/face-status-publisher.cpp
index 836ea2d..145fe0e 100644
--- a/tests/daemon/mgmt/face-status-publisher.cpp
+++ b/tests/daemon/mgmt/face-status-publisher.cpp
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
#include "face-status-publisher-common.hpp"
@@ -36,26 +37,14 @@
Name commandName("/localhost/nfd/faces/list");
shared_ptr<Interest> command(make_shared<Interest>(commandName));
- // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55
- // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones
- // to force a FaceStatus to span Data packets
- for (int i = 0; i < 79; i++)
+ // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75
+ // use 59 FaceStatuses to force a FaceStatus to span Data packets
+ for (int i = 0; i < 59; i++)
{
shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
uint64_t filler = std::numeric_limits<uint64_t>::max() - 1;
- dummy->setCounters(filler, filler, filler, filler);
-
- m_referenceFaces.push_back(dummy);
-
- add(dummy);
- }
-
- for (int i = 0; i < 2; i++)
- {
- shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>());
- uint64_t filler = std::numeric_limits<uint32_t>::max() - 1;
- dummy->setCounters(filler, filler, filler, filler);
+ dummy->setCounters(filler, filler, filler, filler, filler, filler);
m_referenceFaces.push_back(dummy);