fw: integrate forwarder, strategy, tables

refs #1131, #1136

Change-Id: Ica58341cdc1ea1dc421693a87f35fc50177a707d
diff --git a/tests/face/dummy-face.hpp b/tests/face/dummy-face.hpp
index a58a3ee..c7b5d76 100644
--- a/tests/face/dummy-face.hpp
+++ b/tests/face/dummy-face.hpp
@@ -18,18 +18,17 @@
 class DummyFace : public Face
 {
 public:
-  DummyFace(FaceId id)
-    : Face(id)
+  DummyFace()
   {
   }
   
   virtual void
-  sendInterest(const Interest &interest)
+  sendInterest(const Interest& interest)
   {
   }
   
   virtual void
-  sendData(const Data &data)
+  sendData(const Data& data)
   {
   }
 };
diff --git a/tests/face/face.cpp b/tests/face/face.cpp
index dced528..5245f51 100644
--- a/tests/face/face.cpp
+++ b/tests/face/face.cpp
@@ -15,7 +15,7 @@
 
 BOOST_AUTO_TEST_CASE(Description)
 {
-  DummyFace face(1);
+  DummyFace face;
   face.setDescription("3pFsKrvWr");
   BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr");
 }
diff --git a/tests/fw/forwarder.cpp b/tests/fw/forwarder.cpp
new file mode 100644
index 0000000..cf5115f
--- /dev/null
+++ b/tests/fw/forwarder.cpp
@@ -0,0 +1,120 @@
+/* -*- 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 "fw/forwarder.hpp"
+#include "../face/dummy-face.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace nfd {
+
+class ForwarderTestFace : public Face {
+public:
+  ForwarderTestFace(boost::asio::io_service& ioService)
+    : m_ioService(ioService)
+  {
+  }
+  
+  virtual void
+  sendInterest(const Interest& interest)
+  {
+    m_sentInterests.push_back(interest);
+    m_ioService.stop();
+  }
+  
+  virtual void
+  sendData(const Data& data)
+  {
+    m_sentDatas.push_back(data);
+    m_ioService.stop();
+  }
+
+  void
+  receiveInterest(const Interest& interest)
+  {
+    onReceiveInterest(interest);
+  }
+  
+  void
+  receiveData(const Data& data)
+  {
+    onReceiveData(data);
+  }
+
+public:
+  std::vector<Interest> m_sentInterests;
+  std::vector<Data> m_sentDatas;
+
+private:
+  boost::asio::io_service& m_ioService;
+};
+
+BOOST_AUTO_TEST_SUITE(FwForwarder)
+
+BOOST_AUTO_TEST_CASE(AddRemoveFace)
+{
+  boost::asio::io_service io;
+  Forwarder forwarder(io);
+  
+  shared_ptr<Face> face1 = make_shared<DummyFace>();
+  shared_ptr<Face> face2 = make_shared<DummyFace>();
+  
+  BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
+  BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID);
+  
+  forwarder.addFace(face1);
+  forwarder.addFace(face2);
+
+  BOOST_CHECK_NE(face1->getId(), INVALID_FACEID);
+  BOOST_CHECK_NE(face2->getId(), INVALID_FACEID);
+  BOOST_CHECK_NE(face1->getId(), face2->getId());
+
+  forwarder.removeFace(face1);
+  forwarder.removeFace(face2);
+
+  BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
+  BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID);
+}
+
+BOOST_AUTO_TEST_CASE(SimpleExchange)
+{
+  Name nameA  ("ndn:/A");
+  Name nameAB ("ndn:/A/B");
+  Name nameABC("ndn:/A/B/C");
+  Interest interestAB(nameAB);
+  interestAB.setInterestLifetime(4000);
+  Data dataABC(nameABC);
+  
+  boost::asio::io_service io;
+  Forwarder forwarder(io);
+
+  shared_ptr<ForwarderTestFace> face1 = make_shared<ForwarderTestFace>(boost::ref(io));
+  shared_ptr<ForwarderTestFace> face2 = make_shared<ForwarderTestFace>(boost::ref(io));
+  forwarder.addFace(face1);
+  forwarder.addFace(face2);
+  
+  Fib& fib = forwarder.getFib();
+  std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult =
+    fib.insert(Name("ndn:/A"));
+  shared_ptr<fib::Entry> fibEntry = fibInsertResult.first;
+  fibEntry->addNextHop(face2, 0);
+  
+  face1->receiveInterest(interestAB);
+  io.run();
+  io.reset();
+  BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1);
+  BOOST_CHECK(face2->m_sentInterests[0].getName().equals(nameAB));
+  
+  face2->receiveData(dataABC);
+  io.run();
+  io.reset();
+  BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
+  BOOST_CHECK(face1->m_sentDatas[0].getName().equals(nameABC));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace nfd
diff --git a/tests/table/fib.cpp b/tests/table/fib.cpp
index ceba1da..d4dc463 100644
--- a/tests/table/fib.cpp
+++ b/tests/table/fib.cpp
@@ -16,8 +16,8 @@
 BOOST_AUTO_TEST_CASE(Entry)
 {
   Name prefix("ndn:/pxWhfFza");
-  shared_ptr<Face> face1 = make_shared<DummyFace>(1);
-  shared_ptr<Face> face2 = make_shared<DummyFace>(2);
+  shared_ptr<Face> face1 = make_shared<DummyFace>();
+  shared_ptr<Face> face2 = make_shared<DummyFace>();
   
   fib::Entry entry(prefix);
   BOOST_CHECK(entry.getPrefix().equals(prefix));
@@ -166,8 +166,8 @@
 
 BOOST_AUTO_TEST_CASE(RemoveNextHopFromAllEntries)
 {
-  shared_ptr<Face> face1 = make_shared<DummyFace>(1);
-  shared_ptr<Face> face2 = make_shared<DummyFace>(2);
+  shared_ptr<Face> face1 = make_shared<DummyFace>();
+  shared_ptr<Face> face2 = make_shared<DummyFace>();
   Name nameA("ndn:/A");
   Name nameB("ndn:/B");
   
diff --git a/tests/table/pit.cpp b/tests/table/pit.cpp
index 3d81c72..5fc50cd 100644
--- a/tests/table/pit.cpp
+++ b/tests/table/pit.cpp
@@ -15,8 +15,8 @@
 
 BOOST_AUTO_TEST_CASE(EntryInOutRecords)
 {
-  shared_ptr<Face> face1 = make_shared<DummyFace>(1);
-  shared_ptr<Face> face2 = make_shared<DummyFace>(2);
+  shared_ptr<Face> face1 = make_shared<DummyFace>();
+  shared_ptr<Face> face2 = make_shared<DummyFace>();
   Name name("ndn:/KuYfjtRq");
   Interest interest(name);
   Interest interest1(name, static_cast<ndn::Milliseconds>(2528));