fw: Forwarder provides CS hit/miss counters
refs #4219
Change-Id: I7058c43bac4a5508d4b9907f6e684663b8953656
diff --git a/daemon/fw/forwarder-counters.hpp b/daemon/fw/forwarder-counters.hpp
index 3f8c751e..5a63406 100644
--- a/daemon/fw/forwarder-counters.hpp
+++ b/daemon/fw/forwarder-counters.hpp
@@ -1,12 +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,
- * The University of Memphis
+/*
+ * Copyright (c) 2014-2017, 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.
@@ -41,6 +41,9 @@
PacketCounter nOutData;
PacketCounter nInNacks;
PacketCounter nOutNacks;
+
+ PacketCounter nCsHits;
+ PacketCounter nCsMisses;
};
} // namespace nfd
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 9e0b8bb..69a93de 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -164,6 +164,7 @@
const Interest& interest)
{
NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
+ ++m_counters.nCsMisses;
// insert in-record
pitEntry->insertOrUpdateInRecord(const_cast<Face&>(inFace), interest);
@@ -195,6 +196,7 @@
const Interest& interest, const Data& data)
{
NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
+ ++m_counters.nCsHits;
data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
// XXX should we lookup PIT for other Interests that also match csMatch?
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index c01859f..55f51f7 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -24,12 +24,13 @@
*/
#include "fw/forwarder.hpp"
-#include "tests/daemon/face/dummy-face.hpp"
-#include "dummy-strategy.hpp"
-#include "choose-strategy.hpp"
-#include <ndn-cxx/lp/tags.hpp>
#include "tests/test-common.hpp"
+#include "tests/daemon/face/dummy-face.hpp"
+#include "choose-strategy.hpp"
+#include "dummy-strategy.hpp"
+
+#include <ndn-cxx/lp/tags.hpp>
namespace nfd {
namespace tests {
@@ -55,6 +56,8 @@
BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 0);
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0);
face1->receiveInterest(*interestAB);
this->advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
@@ -63,6 +66,8 @@
BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId());
BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1);
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 1);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 1);
BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 0);
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0);
@@ -101,10 +106,14 @@
Cs& cs = forwarder.getCs();
cs.insert(*dataA);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0);
face1->receiveInterest(*interestA);
this->advanceClocks(time::milliseconds(1), time::milliseconds(5));
// Interest matching ContentStore should not be forwarded
BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 1);
+ BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0);
BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
// IncomingFaceId field should be reset to represent CS