fw: ForwarderCounters
refs #1199
Change-Id: I0664825d7b09b4e7e893876aefc5af10e53b90b1
diff --git a/daemon/fw/forwarder-counter.hpp b/daemon/fw/forwarder-counter.hpp
new file mode 100644
index 0000000..e1461d3
--- /dev/null
+++ b/daemon/fw/forwarder-counter.hpp
@@ -0,0 +1,31 @@
+/* -*- 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_FW_FORWARDER_COUNTER_HPP
+#define NFD_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_FW_FORWARDER_COUNTER_HPP
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 3a8a91f..e6d3438 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -37,6 +37,7 @@
if (interest.getInterestLifetime() < 0) {
const_cast<Interest&>(interest).setInterestLifetime(DEFAULT_INTEREST_LIFETIME);
}
+ m_counters.getInInterest() ++;
// /localhost scope control
bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -154,6 +155,7 @@
// send Interest
outFace.sendInterest(interest);
+ m_counters.getOutInterest() ++;
}
void
@@ -184,6 +186,7 @@
// receive Data
NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName());
const_cast<Data&>(data).setIncomingFaceId(inFace.getId());
+ m_counters.getInData() ++;
// /localhost scope control
bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -279,6 +282,7 @@
// send Data
outFace.sendData(data);
+ m_counters.getOutData() ++;
}
static inline bool
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 8e7c0d2..c6e3529 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -9,6 +9,7 @@
#include "common.hpp"
#include "core/scheduler.hpp"
+#include "forwarder-counter.hpp"
#include "face-table.hpp"
#include "table/fib.hpp"
#include "table/pit.hpp"
@@ -31,6 +32,9 @@
public:
Forwarder();
+ const ForwarderCounters&
+ getCounters() const;
+
public: // faces
FaceTable&
getFaceTable();
@@ -141,6 +145,8 @@
#endif
private:
+ ForwarderCounters m_counters;
+
FaceTable m_faceTable;
// tables
@@ -158,6 +164,12 @@
friend class fw::Strategy;
};
+inline const ForwarderCounters&
+Forwarder::getCounters() const
+{
+ return m_counters;
+}
+
inline FaceTable&
Forwarder::getFaceTable()
{
diff --git a/tests/fw/forwarder.cpp b/tests/fw/forwarder.cpp
index 419a7ba..925ba5b 100644
--- a/tests/fw/forwarder.cpp
+++ b/tests/fw/forwarder.cpp
@@ -40,19 +40,27 @@
shared_ptr<fib::Entry> fibEntry = fibInsertResult.first;
fibEntry->addNextHop(face2, 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getInInterest (), 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getOutInterest(), 0);
face1->receiveInterest(*interestAB);
g_io.run();
g_io.reset();
BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1);
BOOST_CHECK(face2->m_sentInterests[0].getName().equals(nameAB));
BOOST_CHECK_EQUAL(face2->m_sentInterests[0].getIncomingFaceId(), face1->getId());
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getInInterest (), 1);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getOutInterest(), 1);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getInData (), 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getOutData(), 0);
face2->receiveData(*dataABC);
g_io.run();
g_io.reset();
BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
BOOST_CHECK(face1->m_sentDatas[0].getName().equals(nameABC));
BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getIncomingFaceId(), face2->getId());
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getInData (), 1);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().getOutData(), 1);
}
class ScopeLocalhostIncomingTestForwarder : public Forwarder