face: link layer byte counts in FaceCounters

This commit declares the counters, but does not increment the new counters.

refs #1729

Change-Id: I9cd136fc65955192a92d567629a9aba2df8090f3
diff --git a/daemon/face/face-counter.hpp b/daemon/face/face-counter.hpp
deleted file mode 100644
index 152c5a1..0000000
--- a/daemon/face/face-counter.hpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/* -*- 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
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * 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_DAEMON_FACE_FACE_COUNTER_HPP
-#define NFD_DAEMON_FACE_FACE_COUNTER_HPP
-
-#include "common.hpp"
-
-namespace nfd {
-
-/** \class FaceCounter
- *  \brief represents a counter on face
- *
- *  \todo This class should be noncopyable
- */
-typedef uint64_t FaceCounter;
-
-
-/** \brief contains counters on face
- */
-class FaceCounters : noncopyable
-{
-public:
-  FaceCounters();
-
-  /// incoming Interest (total packets since Face establishment)
-  const FaceCounter&
-  getNInInterests() const;
-
-  FaceCounter&
-  getNInInterests();
-
-  /// incoming Data (total packets since Face establishment)
-  const FaceCounter&
-  getNInDatas() const;
-
-  FaceCounter&
-  getNInDatas();
-
-  /// outgoing Interest (total packets since Face establishment)
-  const FaceCounter&
-  getNOutInterests() const;
-
-  FaceCounter&
-  getNOutInterests();
-
-  /// outgoing Data (total packets since Face establishment)
-  const FaceCounter&
-  getNOutDatas() const;
-
-  FaceCounter&
-  getNOutDatas();
-
-private:
-  FaceCounter m_nInInterests;
-  FaceCounter m_nInDatas;
-  FaceCounter m_outInterests;
-  FaceCounter m_outDatas;
-};
-
-inline
-FaceCounters::FaceCounters()
-  : m_nInInterests(0)
-  , m_nInDatas(0)
-  , m_outInterests(0)
-  , m_outDatas(0)
-{
-}
-
-inline const FaceCounter&
-FaceCounters::getNInInterests() const
-{
-  return m_nInInterests;
-}
-
-inline FaceCounter&
-FaceCounters::getNInInterests()
-{
-  return m_nInInterests;
-}
-
-inline const FaceCounter&
-FaceCounters::getNInDatas() const
-{
-  return m_nInDatas;
-}
-
-inline FaceCounter&
-FaceCounters::getNInDatas()
-{
-  return m_nInDatas;
-}
-
-inline const FaceCounter&
-FaceCounters::getNOutInterests() const
-{
-  return m_outInterests;
-}
-
-inline FaceCounter&
-FaceCounters::getNOutInterests()
-{
-  return m_outInterests;
-}
-
-inline const FaceCounter&
-FaceCounters::getNOutDatas() const
-{
-  return m_outDatas;
-}
-
-inline FaceCounter&
-FaceCounters::getNOutDatas()
-{
-  return m_outDatas;
-}
-
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_FACE_COUNTER_HPP
diff --git a/daemon/face/face-counters.hpp b/daemon/face/face-counters.hpp
new file mode 100644
index 0000000..05303b5
--- /dev/null
+++ b/daemon/face/face-counters.hpp
@@ -0,0 +1,218 @@
+/* -*- 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,
+ *                      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.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * 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_DAEMON_FACE_FACE_COUNTERS_HPP
+#define NFD_DAEMON_FACE_FACE_COUNTERS_HPP
+
+#include "common.hpp"
+
+namespace nfd {
+
+/** \brief represents a counter of number of packets
+ */
+// PacketCounter is noncopyable, because increment should be called on the counter,
+// not a copy of it; it's implicitly convertible to uint64_t to be observed
+class PacketCounter : noncopyable
+{
+public:
+  typedef uint64_t rep;
+
+  PacketCounter()
+    : m_value(0)
+  {
+  }
+
+  operator rep() const
+  {
+    return m_value;
+  }
+
+  PacketCounter&
+  operator++()
+  {
+    ++m_value;
+    return *this;
+  }
+  // postfix ++ operator is not provided because it's not needed
+
+  void
+  set(rep value)
+  {
+    m_value = value;
+  }
+
+private:
+  rep m_value;
+};
+
+
+/** \brief represents a counter of number of bytes
+ */
+// ByteCounter is noncopyable, because increment should be called on the counter,
+// not a copy of it; it's implicitly convertible to uint64_t to be observed
+class ByteCounter : noncopyable
+{
+public:
+  typedef uint64_t rep;
+
+  ByteCounter()
+    : m_value(0)
+  {
+  }
+
+  operator rep() const
+  {
+    return m_value;
+  }
+
+  ByteCounter&
+  operator+=(rep n)
+  {
+    m_value += n;
+    return *this;
+  }
+
+  void
+  set(rep value)
+  {
+    m_value = value;
+  }
+
+private:
+  rep m_value;
+};
+
+
+/** \brief contains network layer packet counters
+ */
+class NetworkLayerCounters : noncopyable
+{
+public:
+  /// incoming Interest
+  const PacketCounter&
+  getNInInterests() const
+  {
+    return m_nInInterests;
+  }
+
+  PacketCounter&
+  getNInInterests()
+  {
+    return m_nInInterests;
+  }
+
+  /// incoming Data
+  const PacketCounter&
+  getNInDatas() const
+  {
+    return m_nInDatas;
+  }
+
+  PacketCounter&
+  getNInDatas()
+  {
+    return m_nInDatas;
+  }
+
+  /// outgoing Interest
+  const PacketCounter&
+  getNOutInterests() const
+  {
+    return m_nOutInterests;
+  }
+
+  PacketCounter&
+  getNOutInterests()
+  {
+    return m_nOutInterests;
+  }
+
+  /// outgoing Data
+  const PacketCounter&
+  getNOutDatas() const
+  {
+    return m_nOutDatas;
+  }
+
+  PacketCounter&
+  getNOutDatas()
+  {
+    return m_nOutDatas;
+  }
+
+private:
+  PacketCounter m_nInInterests;
+  PacketCounter m_nInDatas;
+  PacketCounter m_nOutInterests;
+  PacketCounter m_nOutDatas;
+};
+
+
+/** \brief contains link layer byte counters
+ */
+class LinkLayerCounters : noncopyable
+{
+public:
+  /// received bytes
+  const ByteCounter&
+  getNInBytes() const
+  {
+    return m_nInBytes;
+  }
+
+  ByteCounter&
+  getNInBytes()
+  {
+    return m_nInBytes;
+  }
+
+  /// sent bytes
+  const ByteCounter&
+  getNOutBytes() const
+  {
+    return m_nOutBytes;
+  }
+
+  ByteCounter&
+  getNOutBytes()
+  {
+    return m_nOutBytes;
+  }
+
+private:
+  ByteCounter m_nInBytes;
+  ByteCounter m_nOutBytes;
+};
+
+
+/** \brief contains counters on face
+ */
+class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
+{
+};
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 2c81a9a..4197aa5 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -29,12 +29,6 @@
 
 namespace nfd {
 
-static inline void
-increaseCounter(FaceCounter& counter)
-{
-  ++counter;
-}
-
 Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
   : m_id(INVALID_FACEID)
   , m_isLocal(isLocal)
@@ -43,10 +37,10 @@
   , m_isOnDemand(false)
   , m_isFailed(false)
 {
-  onReceiveInterest += bind(&increaseCounter, ref(m_counters.getNInInterests()));
-  onReceiveData     += bind(&increaseCounter, ref(m_counters.getNInDatas()));
-  onSendInterest    += bind(&increaseCounter, ref(m_counters.getNOutInterests()));
-  onSendData        += bind(&increaseCounter, ref(m_counters.getNOutDatas()));
+  onReceiveInterest += bind(&PacketCounter::operator++, &m_counters.getNInInterests());
+  onReceiveData     += bind(&PacketCounter::operator++, &m_counters.getNInDatas());
+  onSendInterest    += bind(&PacketCounter::operator++, &m_counters.getNOutInterests());
+  onSendData        += bind(&PacketCounter::operator++, &m_counters.getNOutDatas());
 }
 
 Face::~Face()
@@ -59,7 +53,7 @@
   return m_id;
 }
 
-// this method is private and should be used only by the Forwarder
+// this method is private and should be used only by the FaceTable
 void
 Face::setId(FaceId faceId)
 {
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 2660045..2db2c6a 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -21,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_DAEMON_FACE_FACE_HPP
 #define NFD_DAEMON_FACE_FACE_HPP
@@ -29,7 +29,7 @@
 #include "common.hpp"
 #include "core/event-emitter.hpp"
 #include "core/face-uri.hpp"
-#include "face-counter.hpp"
+#include "face-counters.hpp"
 
 #include <ndn-cxx/management/nfd-face-status.hpp>
 
diff --git a/daemon/fw/forwarder-counter.hpp b/daemon/fw/forwarder-counter.hpp
deleted file mode 100644
index be74928..0000000
--- a/daemon/fw/forwarder-counter.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- 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
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * 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_DAEMON_FW_FORWARDER_COUNTER_HPP
-#define NFD_DAEMON_FW_FORWARDER_COUNTER_HPP
-
-#include "face/face-counter.hpp"
-
-namespace nfd {
-
-/** \class ForwarderCounter
- *  \brief represents a counter on forwarder
- *
- *  \todo This class should be noncopyable
- */
-typedef uint64_t ForwarderCounter;
-
-
-/** \brief contains counters on forwarder
- */
-class ForwarderCounters : public FaceCounters
-{
-};
-
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FW_FORWARDER_COUNTER_HPP
diff --git a/daemon/fw/forwarder-counters.hpp b/daemon/fw/forwarder-counters.hpp
new file mode 100644
index 0000000..7af679a
--- /dev/null
+++ b/daemon/fw/forwarder-counters.hpp
@@ -0,0 +1,42 @@
+/* -*- 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,
+ *                      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.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * 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_DAEMON_FW_FORWARDER_COUNTERS_HPP
+#define NFD_DAEMON_FW_FORWARDER_COUNTERS_HPP
+
+#include "face/face-counters.hpp"
+
+namespace nfd {
+
+/** \brief contains counters on forwarder
+ */
+class ForwarderCounters : public NetworkLayerCounters
+{
+};
+
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_FW_FORWARDER_COUNTERS_HPP
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 0e2f0d2..a57a756 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -59,7 +59,7 @@
   NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                 " interest=" << interest.getName());
   const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
-  m_counters.getNInInterests() ++;
+  ++m_counters.getNInInterests();
 
   // /localhost scope control
   bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -187,7 +187,7 @@
 
   // send Interest
   outFace.sendInterest(*interest);
-  m_counters.getNOutInterests() ++;
+  ++m_counters.getNOutInterests();
 }
 
 void
@@ -227,7 +227,7 @@
   // receive Data
   NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName());
   const_cast<Data&>(data).setIncomingFaceId(inFace.getId());
-  m_counters.getNInDatas() ++;
+  ++m_counters.getNInDatas();
 
   // /localhost scope control
   bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -331,7 +331,7 @@
 
   // send Data
   outFace.sendData(data);
-  m_counters.getNOutDatas() ++;
+  ++m_counters.getNOutDatas();
 }
 
 static inline bool
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index acb0451..8c5ed79 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -27,7 +27,7 @@
 
 #include "common.hpp"
 #include "core/scheduler.hpp"
-#include "forwarder-counter.hpp"
+#include "forwarder-counters.hpp"
 #include "face-table.hpp"
 #include "table/fib.hpp"
 #include "table/pit.hpp"