tests: forwarding with Link objects test suite

Fw/TestLinkForwarding is an end-to-end test suite that verifies
the proper forwarding rules for Interest with Link objects.
It replaces Fw/TestStrategy/LookupFib test suite.

refs #3893

Change-Id: I6dd3fe7988f8be6d55dd5dc589f7953c4d18f2ee
diff --git a/daemon/face/generic-link-service.hpp b/daemon/face/generic-link-service.hpp
index 08ed9e1..b675ae2 100644
--- a/daemon/face/generic-link-service.hpp
+++ b/daemon/face/generic-link-service.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -75,9 +75,10 @@
 
 /** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol
  *  \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
+ *  \todo #3941 declare GenericLinkServiceCounters as virtual inheritance
  */
 class GenericLinkService : public LinkService
-                         , protected virtual GenericLinkServiceCounters
+                         , protected GenericLinkServiceCounters
 {
 public:
   /** \brief Options that control the behavior of GenericLinkService
@@ -111,7 +112,7 @@
 
   /** \brief counters provided by GenericLinkService
    */
-  typedef GenericLinkServiceCounters Counters;
+  using Counters = GenericLinkServiceCounters;
 
   explicit
   GenericLinkService(const Options& options = Options());
@@ -126,10 +127,10 @@
   void
   setOptions(const Options& options);
 
-  virtual const Counters&
+  const Counters&
   getCounters() const override;
 
-private: // send path
+PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path
   /** \brief send Interest
    */
   void
@@ -145,6 +146,7 @@
   void
   doSendNack(const ndn::lp::Nack& nack) override;
 
+private:
   /** \brief encode link protocol fields from tags onto an outgoing LpPacket
    *  \param netPkt network-layer packet to extract tags from
    *  \param lpPacket LpPacket to add link protocol fields to
diff --git a/tests/daemon/fw/link-forwarding.t.cpp b/tests/daemon/fw/link-forwarding.t.cpp
new file mode 100644
index 0000000..864d598
--- /dev/null
+++ b/tests/daemon/fw/link-forwarding.t.cpp
@@ -0,0 +1,202 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * 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.
+ *
+ * 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/>.
+ */
+
+#include "fw/best-route-strategy2.hpp"
+
+#include "topology-tester.hpp"
+
+namespace nfd {
+namespace fw {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_AUTO_TEST_SUITE(TestLinkForwarding)
+
+/**
+ *      /arizona/cs/avenir
+ *              |
+ *              v
+ *      /arizona/cs/hobo
+ *      |              |
+ *      v              v
+ *  /telia/terabits    /ucsd/caida/click
+ *        |                 |
+ *        v                 v
+ *  /net/ndnsim        /ucla/cs/spurs
+ *   (serverP)              |
+ *                          v
+ *                     /net/ndnsim
+ *                      (serverQ)
+ */
+class NdnsimTeliaUclaTopologyFixture : public UnitTestTimeFixture
+{
+public:
+  NdnsimTeliaUclaTopologyFixture()
+  {
+    topo.enablePcap();
+
+    nodeA = topo.addForwarder("avenir");
+    nodeH = topo.addForwarder("hobo");
+    nodeT = topo.addForwarder("terabits");
+    nodeP = topo.addForwarder("serverP");
+    nodeC = topo.addForwarder("click");
+    nodeS = topo.addForwarder("spurs");
+    nodeQ = topo.addForwarder("serverQ");
+    for (TopologyNode node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) {
+      topo.setStrategy<BestRouteStrategy2>(node);
+    }
+
+    topo.getForwarder(nodeA).getNetworkRegionTable().insert("/arizona/cs/avenir");
+    topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
+    topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
+    topo.getForwarder(nodeP).getNetworkRegionTable().insert("/telia/terabits/serverP");
+    topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
+    topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
+    topo.getForwarder(nodeQ).getNetworkRegionTable().insert("/ucla/cs/serverQ");
+
+    linkAH = topo.addLink("AH", time::milliseconds(10), {nodeA, nodeH});
+    linkHT = topo.addLink("HT", time::milliseconds(10), {nodeH, nodeT});
+    linkTP = topo.addLink("TP", time::milliseconds(10), {nodeT, nodeP});
+    linkHC = topo.addLink("HC", time::milliseconds(10), {nodeH, nodeC});
+    linkCS = topo.addLink("CS", time::milliseconds(10), {nodeC, nodeS});
+    linkSQ = topo.addLink("SQ", time::milliseconds(10), {nodeS, nodeQ});
+    consumerA = topo.addAppFace("avenir", nodeA);
+    producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim");
+    producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim");
+
+    topo.addEchoProducer(producerP->getClientFace());
+    topo.addEchoProducer(producerQ->getClientFace());
+
+    topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10);
+    topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10);
+    topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10);
+    topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20);
+    topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10);
+    topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10);
+
+    linkObject = makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}});
+  }
+
+  /** \brief express an Interest with Link object from consumerA
+   */
+  void
+  consumerExpressInterest(int seq)
+  {
+    auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
+    interest->setLink(linkObject->wireEncode());
+    consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
+  }
+
+public:
+  TopologyTester topo;
+  TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
+  shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
+  shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
+  shared_ptr<Link> linkObject;
+};
+
+BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
+
+BOOST_AUTO_TEST_CASE(FetchTelia)
+{
+  this->consumerExpressInterest(1);
+  this->advanceClocks(time::milliseconds(11), 20);
+
+  // A forwards Interest according to default route, no change to Link and SelectedDelegation
+  BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
+  const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
+
+  // H prefers T, and sets SelectedDelegation
+  BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
+  const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestHT.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestHT.hasSelectedDelegation(), true);
+  BOOST_CHECK_EQUAL(interestHT.getSelectedDelegation(), "/telia/terabits");
+
+  // T forwards to P, no change to Link and SelectedDelegation
+  BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
+  const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestTP.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestTP.hasSelectedDelegation(), true);
+  BOOST_CHECK_EQUAL(interestTP.getSelectedDelegation(), "/telia/terabits");
+
+  // Data is served by P and reaches A
+  BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
+  BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
+}
+
+BOOST_AUTO_TEST_CASE(FetchUcla)
+{
+  // disconnect H-T and delete FIB entry
+  linkHT->fail();
+  topo.getForwarder(nodeH).getFib().erase("/telia");
+
+  this->consumerExpressInterest(1);
+  this->advanceClocks(time::milliseconds(11), 20);
+
+  // A forwards Interest according to default route, no change to Link and SelectedDelegation
+  BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
+  const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
+
+  // H forwards to C, and sets SelectedDelegation
+  BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
+  const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestHC.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestHC.hasSelectedDelegation(), true);
+  BOOST_CHECK_EQUAL(interestHC.getSelectedDelegation(), "/ucla/cs");
+
+  // C forwards to S, no change to Link and SelectedDelegation
+  BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
+  const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestCS.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestCS.hasSelectedDelegation(), true);
+  BOOST_CHECK_EQUAL(interestCS.getSelectedDelegation(), "/ucla/cs");
+
+  // S forwards to Q, no change to Link and SelectedDelegation
+  BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
+  const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
+  BOOST_CHECK_EQUAL(interestSQ.hasLink(), true);
+  BOOST_CHECK_EQUAL(interestSQ.hasSelectedDelegation(), true);
+  BOOST_CHECK_EQUAL(interestSQ.getSelectedDelegation(), "/ucla/cs");
+
+  // Data is served by Q and reaches A
+  BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
+  BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
+
+BOOST_AUTO_TEST_SUITE_END() // TestLinkForwarding
+BOOST_AUTO_TEST_SUITE_END() // Fw
+
+} // namespace tests
+} // namespace fw
+} // namespace nfd
diff --git a/tests/daemon/fw/strategy.t.cpp b/tests/daemon/fw/strategy.t.cpp
index 72d43b4..11f3f38 100644
--- a/tests/daemon/fw/strategy.t.cpp
+++ b/tests/daemon/fw/strategy.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -100,147 +100,7 @@
   BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
 }
 
-class LookupFibFixture : public BaseFixture
-{
-protected:
-  class TestStrategy : public DummyStrategy
-  {
-  public:
-    explicit
-    TestStrategy(Forwarder& forwarder)
-      : DummyStrategy(forwarder)
-    {
-    }
-
-    const fib::Entry&
-    lookupFib(const pit::Entry& pitEntry) const
-    {
-      return this->Strategy::lookupFib(pitEntry);
-    }
-  };
-
-  LookupFibFixture()
-    : strategy(forwarder)
-    , fib(forwarder.getFib())
-    , pit(forwarder.getPit())
-    , nrt(forwarder.getNetworkRegionTable())
-    , inFace(make_shared<DummyFace>())
-    , outFace(make_shared<DummyFace>())
-    , link(makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}}))
-  {
-    forwarder.addFace(inFace);
-    forwarder.addFace(outFace);
-  }
-
-  const fib::Entry&
-  lookupFib(Interest& interest)
-  {
-    shared_ptr<pit::Entry> pitEntry = pit.insert(interest).first;
-    pitEntry->insertOrUpdateInRecord(*inFace, interest);
-    return strategy.lookupFib(*pitEntry);
-  }
-
-protected:
-  Forwarder forwarder;
-  TestStrategy strategy;
-  Fib& fib;
-  Pit& pit;
-  NetworkRegionTable& nrt;
-
-  shared_ptr<Face> inFace;
-  shared_ptr<Face> outFace;
-  shared_ptr<Link> link;
-};
-
-BOOST_FIXTURE_TEST_SUITE(LookupFib, LookupFibFixture)
-
-BOOST_AUTO_TEST_CASE(NoLink)
-{
-  fib.insert("/net/ndnsim").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/net/ndnsim");
-  BOOST_CHECK_EQUAL(interest->hasSelectedDelegation(), false);
-}
-
-BOOST_AUTO_TEST_CASE(ConsumerRegion)
-{
-  nrt.insert("/arizona/cs/avenir");
-  fib.insert("/").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  interest->setLink(link->wireEncode());
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/");
-  BOOST_CHECK_EQUAL(interest->hasSelectedDelegation(), false);
-}
-
-BOOST_AUTO_TEST_CASE(DefaultFreeFirstDelegation)
-{
-  nrt.insert("/arizona/cs/hobo");
-  fib.insert("/telia").first->addNextHop(*outFace, 20);
-  fib.insert("/ucla").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  interest->setLink(link->wireEncode());
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/telia");
-  BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/telia/terabits");
-}
-
-BOOST_AUTO_TEST_CASE(DefaultFreeSecondDelegation)
-{
-  nrt.insert("/arizona/cs/hobo");
-  fib.insert("/ucla").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  interest->setLink(link->wireEncode());
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/ucla");
-  BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
-}
-
-BOOST_AUTO_TEST_CASE(DefaultFreeHasSelectedDelegation)
-{
-  nrt.insert("/ucsd/caida/click");
-  fib.insert("/telia").first->addNextHop(*outFace, 10);
-  fib.insert("/ucla").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  interest->setLink(link->wireEncode());
-  interest->setSelectedDelegation("/ucla/cs");
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/ucla");
-  BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
-}
-
-BOOST_AUTO_TEST_CASE(ProducerRegion)
-{
-  nrt.insert("/ucla/cs/spurs");
-  fib.insert("/").first->addNextHop(*outFace, 10);
-  fib.insert("/ucla").first->addNextHop(*outFace, 10);
-  fib.insert("/net/ndnsim").first->addNextHop(*outFace, 10);
-
-  auto interest = makeInterest("/net/ndnsim/www/index.html");
-  interest->setLink(link->wireEncode());
-  interest->setSelectedDelegation("/ucla/cs");
-  const fib::Entry& fibEntry = this->lookupFib(*interest);
-
-  BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/net/ndnsim");
-  BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
-  BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
-}
-
-BOOST_AUTO_TEST_SUITE_END() // LookupFib
+// LookupFib is tested in Fw/TestLinkForwarding test suite.
 
 BOOST_AUTO_TEST_SUITE_END() // TestStrategy
 BOOST_AUTO_TEST_SUITE_END() // Fw
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
index 5742592..ad68447 100644
--- a/tests/daemon/fw/topology-tester.cpp
+++ b/tests/daemon/fw/topology-tester.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -114,6 +114,37 @@
   m_clientTransport->connectToForwarder(m_forwarderTransport);
 }
 
+class TopologyPcapLinkService : public GenericLinkService
+                              , public TopologyPcap
+{
+private:
+  ///\todo #3941 call GenericLinkServiceCounters constructor in TopologyPcapLinkService constructor
+
+  void
+  doSendInterest(const Interest& interest) override
+  {
+    this->sentInterests.push_back(interest);
+    this->sentInterests.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now()));
+    this->GenericLinkService::doSendInterest(interest);
+  }
+
+  void
+  doSendData(const Data& data) override
+  {
+    this->sentData.push_back(data);
+    this->sentData.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now()));
+    this->GenericLinkService::doSendData(data);
+  }
+
+  void
+  doSendNack(const lp::Nack& nack) override
+  {
+    this->sentNacks.push_back(nack);
+    this->sentNacks.back().setTag(std::make_shared<TopologyPcapTimestamp>(time::steady_clock::now()));
+    this->GenericLinkService::doSendNack(nack);
+  }
+};
+
 TopologyNode
 TopologyTester::addForwarder(const std::string& label)
 {
@@ -139,7 +170,8 @@
     Forwarder& forwarder = this->getForwarder(i);
     FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/" + label);
 
-    auto service = make_unique<GenericLinkService>();
+    unique_ptr<GenericLinkService> service = m_wantPcap ? make_unique<TopologyPcapLinkService>() :
+                                                          make_unique<GenericLinkService>();
     auto transport = make_unique<InternalForwarderTransport>(localUri, remoteUri,
                      ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType);
     auto face = make_shared<Face>(std::move(service), std::move(transport));
@@ -159,7 +191,8 @@
   FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/local/" + label);
   FaceUri remoteUri("topology://" + m_forwarderLabels.at(i) + "/app/" + label);
 
-  auto service = make_unique<GenericLinkService>();
+  unique_ptr<GenericLinkService> service = m_wantPcap ? make_unique<TopologyPcapLinkService>() :
+                                                        make_unique<GenericLinkService>();
   auto transport = make_unique<InternalForwarderTransport>(localUri, remoteUri,
                    ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LINK_TYPE_POINT_TO_POINT);
   auto face = make_shared<Face>(std::move(service), std::move(transport));
@@ -180,6 +213,18 @@
 }
 
 void
+TopologyTester::enablePcap(bool isEnabled)
+{
+  m_wantPcap = isEnabled;
+}
+
+TopologyPcap&
+TopologyTester::getPcap(const Face& face)
+{
+  return dynamic_cast<TopologyPcapLinkService&>(*face.getLinkService());
+}
+
+void
 TopologyTester::registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost)
 {
   Forwarder& forwarder = this->getForwarder(i);
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index ec122b6..9f97413 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -157,6 +157,20 @@
   shared_ptr<ndn::Face> m_client;
 };
 
+/** \brief captured packets on a face
+ */
+class TopologyPcap : noncopyable
+{
+public:
+  std::vector<Interest> sentInterests;
+  std::vector<Data> sentData;
+  std::vector<lp::Nack> sentNacks;
+};
+
+/** \brief captured packet timestamp tag
+ */
+using TopologyPcapTimestamp = ndn::SimpleTag<time::steady_clock::TimePoint, 0>;
+
 /** \brief builds a topology for forwarding tests
  */
 class TopologyTester : noncopyable
@@ -209,6 +223,17 @@
   shared_ptr<TopologyAppLink>
   addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost = 0);
 
+  /** \brief enables packet capture on every forwarder face
+   */
+  void
+  enablePcap(bool isEnabled = true);
+
+  /** \return captured packets on a forwarder face
+   *  \pre enablePcap(true) is in effect when the face was created
+   */
+  TopologyPcap&
+  getPcap(const Face& face);
+
   /** \brief registers a prefix on a forwarder face
    */
   void
@@ -227,6 +252,7 @@
                       const time::nanoseconds& interval, size_t n);
 
 private:
+  bool m_wantPcap = false;
   std::vector<unique_ptr<Forwarder>> m_forwarders;
   std::vector<std::string> m_forwarderLabels;
   std::vector<shared_ptr<TopologyLink>> m_links;