face: declare face counters
refs #1280
Change-Id: Ia1c50ab2b31d6131728489b3b038dc6f7608266f
diff --git a/daemon/face/face-counter.cpp b/daemon/face/face-counter.cpp
new file mode 100644
index 0000000..3597ff1
--- /dev/null
+++ b/daemon/face/face-counter.cpp
@@ -0,0 +1,19 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "face-counter.hpp"
+
+namespace nfd {
+
+FaceCounters::FaceCounters()
+ : m_inInterest(0)
+ , m_inData(0)
+ , m_outInterest(0)
+ , m_outData(0)
+{
+}
+
+} //namespace nfd
diff --git a/daemon/face/face-counter.hpp b/daemon/face/face-counter.hpp
new file mode 100644
index 0000000..e5809eb
--- /dev/null
+++ b/daemon/face/face-counter.hpp
@@ -0,0 +1,114 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_FACE_FACE_COUNTER_HPP
+#define NFD_FACE_FACE_COUNTER_HPP
+
+#include "common.hpp"
+
+namespace nfd {
+
+/** \class FaceCounter
+ * \brief represents a counter on face
+ */
+typedef uint64_t FaceCounter;
+
+
+/** \brief contains counters on face
+ */
+class FaceCounters
+{
+public:
+ FaceCounters();
+
+ /// incoming Interest (total packets since Face establishment)
+ const FaceCounter&
+ getInInterest() const;
+
+ FaceCounter&
+ getInInterest();
+
+ /// incoming Data (total packets since Face establishment)
+ const FaceCounter&
+ getInData() const;
+
+ FaceCounter&
+ getInData();
+
+ /// outgoing Interest (total packets since Face establishment)
+ const FaceCounter&
+ getOutInterest() const;
+
+ FaceCounter&
+ getOutInterest();
+
+ /// outgoing Data (total packets since Face establishment)
+ const FaceCounter&
+ getOutData() const;
+
+ FaceCounter&
+ getOutData();
+
+private:
+ FaceCounter m_inInterest;
+ FaceCounter m_inData;
+ FaceCounter m_outInterest;
+ FaceCounter m_outData;
+};
+
+
+inline const FaceCounter&
+FaceCounters::getInInterest() const
+{
+ return m_inInterest;
+}
+
+inline FaceCounter&
+FaceCounters::getInInterest()
+{
+ return m_inInterest;
+}
+
+inline const FaceCounter&
+FaceCounters::getInData() const
+{
+ return m_inData;
+}
+
+inline FaceCounter&
+FaceCounters::getInData()
+{
+ return m_inData;
+}
+
+inline const FaceCounter&
+FaceCounters::getOutInterest() const
+{
+ return m_outInterest;
+}
+
+inline FaceCounter&
+FaceCounters::getOutInterest()
+{
+ return m_outInterest;
+}
+
+inline const FaceCounter&
+FaceCounters::getOutData() const
+{
+ return m_outData;
+}
+
+inline FaceCounter&
+FaceCounters::getOutData()
+{
+ return m_outData;
+}
+
+
+} // namespace nfd
+
+#endif // NFD_FACE_FACE_COUNTER_HPP
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index f3c5d40..45cde49 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -9,6 +9,7 @@
#include "common.hpp"
#include "core/event-emitter.hpp"
+#include "face-counter.hpp"
namespace nfd {
@@ -82,7 +83,7 @@
*/
bool
isLocal() const;
-
+
/** \brief Set the description
*
* This is typically invoked by mgmt on set description command
@@ -101,6 +102,9 @@
virtual bool
isMultiAccess() const;
+ const FaceCounters&
+ getCounters() const;
+
protected:
void
setLocal(bool isLocal);
@@ -109,6 +113,9 @@
bool
decodeAndDispatchInput(const Block& element);
+ FaceCounters&
+ getMutableCounters();
+
private:
void
setId(FaceId faceId);
@@ -117,11 +124,25 @@
FaceId m_id;
std::string m_description;
bool m_isLocal; // for scoping purposes
-
+ FaceCounters m_counters;
+
// allow setting FaceId
friend class Forwarder;
};
+
+inline const FaceCounters&
+Face::getCounters() const
+{
+ return m_counters;
+}
+
+inline FaceCounters&
+Face::getMutableCounters()
+{
+ return m_counters;
+}
+
} // namespace nfd
#endif // NFD_FACE_FACE_HPP
diff --git a/tests/face/face.cpp b/tests/face/face.cpp
index 3fb4ea4..5f8ab6e 100644
--- a/tests/face/face.cpp
+++ b/tests/face/face.cpp
@@ -40,6 +40,16 @@
LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID), false);
}
+BOOST_AUTO_TEST_CASE(Counters)
+{
+ DummyFace face;
+ const FaceCounters& counters = face.getCounters();
+ BOOST_CHECK_EQUAL(counters.getInInterest() , 0);
+ BOOST_CHECK_EQUAL(counters.getInData() , 0);
+ BOOST_CHECK_EQUAL(counters.getOutInterest(), 0);
+ BOOST_CHECK_EQUAL(counters.getOutData() , 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace nfd