face: Refactor Face as LinkService+Transport
LpFace: new Face implementation
LpFaceWrapper: allows new Face system to work with old Face system
Eventually, LpFace will be renamed to Face and LpFaceWrapper will be removed.
refs #3088 #3179
Change-Id: Ia4ad7c84631e65b444d4f24e1d7593392927c8db
diff --git a/tests/daemon/face/dummy-lp-face.cpp b/tests/daemon/face/dummy-lp-face.cpp
new file mode 100644
index 0000000..20fb20d
--- /dev/null
+++ b/tests/daemon/face/dummy-lp-face.cpp
@@ -0,0 +1,140 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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 "dummy-lp-face.hpp"
+#include "dummy-transport.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+class DummyLpFace::LinkService : public face::LinkService
+{
+public:
+ void
+ receiveInterest(const Interest& interest)
+ {
+ this->face::LinkService::receiveInterest(interest);
+ }
+
+ void
+ receiveData(const Data& data)
+ {
+ this->face::LinkService::receiveData(data);
+ }
+
+ void
+ receiveNack(const lp::Nack& nack)
+ {
+ this->face::LinkService::receiveNack(nack);
+ }
+
+ signal::Signal<LinkService> afterSend;
+
+private:
+ virtual void
+ doSendInterest(const Interest& interest) DECL_OVERRIDE
+ {
+ this->sentInterests.push_back(interest);
+ this->afterSend();
+ }
+
+ virtual void
+ doSendData(const Data& data) DECL_OVERRIDE
+ {
+ this->sentData.push_back(data);
+ this->afterSend();
+ }
+
+ virtual void
+ doSendNack(const lp::Nack& nack) DECL_OVERRIDE
+ {
+ this->sentNacks.push_back(nack);
+ this->afterSend();
+ }
+
+ virtual void
+ doReceivePacket(Transport::Packet&& packet) DECL_OVERRIDE
+ {
+ BOOST_ASSERT(false);
+ }
+
+public:
+ std::vector<Interest> sentInterests;
+ std::vector<Data> sentData;
+ std::vector<lp::Nack> sentNacks;
+};
+
+DummyLpFace::DummyLpFace(const std::string& localUri, const std::string& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::FacePersistency persistency,
+ ndn::nfd::LinkType linkType)
+ : LpFace(make_unique<LinkService>(),
+ make_unique<DummyTransport>(localUri, remoteUri, scope, persistency, linkType))
+ , afterSend(this->getLinkServiceInternal()->afterSend)
+ , sentInterests(this->getLinkServiceInternal()->sentInterests)
+ , sentData(this->getLinkServiceInternal()->sentData)
+ , sentNacks(this->getLinkServiceInternal()->sentNacks)
+{
+}
+
+void
+DummyLpFace::setState(FaceState state)
+{
+ this->getTransportInternal()->setState(state);
+}
+
+void
+DummyLpFace::receiveInterest(const Interest& interest)
+{
+ this->getLinkServiceInternal()->receiveInterest(interest);
+}
+
+void
+DummyLpFace::receiveData(const Data& data)
+{
+ this->getLinkServiceInternal()->receiveData(data);
+}
+
+void
+DummyLpFace::receiveNack(const lp::Nack& nack)
+{
+ this->getLinkServiceInternal()->receiveNack(nack);
+}
+
+DummyLpFace::LinkService*
+DummyLpFace::getLinkServiceInternal()
+{
+ return static_cast<LinkService*>(this->getLinkService());
+}
+
+DummyTransport*
+DummyLpFace::getTransportInternal()
+{
+ return static_cast<DummyTransport*>(this->getTransport());
+}
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/dummy-lp-face.hpp b/tests/daemon/face/dummy-lp-face.hpp
new file mode 100644
index 0000000..588cb59
--- /dev/null
+++ b/tests/daemon/face/dummy-lp-face.hpp
@@ -0,0 +1,99 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
+#define NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
+
+#include "face/lp-face.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+class DummyTransport;
+
+/** \brief a LpFace for unit testing
+ *
+ * The DummyLpFace allows observing outgoing network-layer packets,
+ * and allows incoming network-layer packets to be injected from a test suite.
+ * It's primarily used for forwarding test suites, but can be used in other tests as well.
+ */
+class DummyLpFace : public LpFace
+{
+public:
+ class LinkService;
+
+ DummyLpFace(const std::string& localUri = "dummy://", const std::string& remoteUri = "dummy://",
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+
+ /** \brief changes face state
+ * \pre current state is not CLOSED or FAILED
+ */
+ void
+ setState(FaceState state);
+
+ /** \brief causes the face to receive an Interest
+ */
+ void
+ receiveInterest(const Interest& interest);
+
+ /** \brief causes the face to receive a Data
+ */
+ void
+ receiveData(const Data& data);
+
+ /** \brief causes the face to receive a Nack
+ */
+ void
+ receiveNack(const lp::Nack& nack);
+
+ /** \brief signals after any network-layer packet is sent
+ */
+ signal::Signal<LinkService>& afterSend;
+
+private:
+ LinkService*
+ getLinkServiceInternal();
+
+ DummyTransport*
+ getTransportInternal();
+
+public:
+ std::vector<Interest>& sentInterests;
+ std::vector<Data>& sentData;
+ std::vector<lp::Nack>& sentNacks;
+};
+
+} // namespace tests
+} // namespace face
+
+namespace tests {
+using nfd::face::tests::DummyLpFace;
+} // namespace tests
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
diff --git a/tests/daemon/face/dummy-transport.hpp b/tests/daemon/face/dummy-transport.hpp
new file mode 100644
index 0000000..df8fa54
--- /dev/null
+++ b/tests/daemon/face/dummy-transport.hpp
@@ -0,0 +1,96 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
+#define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
+
+#include "common.hpp"
+
+#include "face/transport.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+/** \brief dummy Transport used in unit tests
+ */
+class DummyTransport : public Transport
+{
+public:
+ DummyTransport(const std::string& localUri = "dummy://",
+ const std::string& remoteUri = "dummy://",
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT)
+ : isClosed(false)
+ {
+ this->setLocalUri(FaceUri(localUri));
+ this->setRemoteUri(FaceUri(remoteUri));
+ this->setScope(scope);
+ this->setPersistency(persistency);
+ this->setLinkType(linkType);
+ }
+
+ void
+ setState(FaceState state)
+ {
+ this->Transport::setState(state);
+ }
+
+ void
+ receivePacket(Packet&& packet)
+ {
+ this->receive(std::move(packet));
+ }
+
+ void
+ receivePacket(Block block)
+ {
+ this->receive(Packet(std::move(block)));
+ }
+
+private:
+ virtual void
+ doClose() DECL_OVERRIDE
+ {
+ isClosed = true;
+ }
+
+ virtual void
+ doSend(Packet&& packet) DECL_OVERRIDE
+ {
+ sentPackets.push_back(std::move(packet));
+ }
+
+public:
+ bool isClosed;
+ std::vector<Packet> sentPackets;
+};
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
new file mode 100644
index 0000000..a918b26
--- /dev/null
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -0,0 +1,285 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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 "face/generic-link-service.hpp"
+#include "face/lp-face.hpp"
+#include "dummy-transport.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Face)
+
+class GenericLinkServiceFixture : public BaseFixture
+{
+protected:
+ GenericLinkServiceFixture()
+ : service(nullptr)
+ , transport(nullptr)
+ {
+ this->initialize();
+ // By default, GenericLinkService is created with default options.
+ // Test cases may invoke .initialize with alternate options.
+ }
+
+ void
+ initialize()
+ {
+ // TODO#3104 add GenericLinkService::Options parameter,
+ // and create GenericLinkService with options
+ face.reset(new LpFace(make_unique<GenericLinkService>(),
+ make_unique<DummyTransport>()));
+ service = static_cast<GenericLinkService*>(face->getLinkService());
+ transport = static_cast<DummyTransport*>(face->getTransport());
+
+ face->afterReceiveInterest.connect(
+ [this] (const Interest& interest) { receivedInterests.push_back(interest); });
+ face->afterReceiveData.connect(
+ [this] (const Data& data) { receivedData.push_back(data); });
+ face->afterReceiveNack.connect(
+ [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); });
+ }
+
+protected:
+ unique_ptr<LpFace> face;
+ GenericLinkService* service;
+ DummyTransport* transport;
+ std::vector<Interest> receivedInterests;
+ std::vector<Data> receivedData;
+ std::vector<lp::Nack> receivedNacks;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
+
+
+BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
+
+BOOST_AUTO_TEST_CASE(SendInterest)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Interest> interest1 = makeInterest("/localhost/test");
+
+ face->sendInterest(*interest1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ BOOST_CHECK(transport->sentPackets.back().packet == interest1->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(SendData)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Data> data1 = makeData("/localhost/test");
+
+ face->sendData(*data1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ BOOST_CHECK(transport->sentPackets.back().packet == data1->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(SendNack)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
+
+ face->sendNack(nack1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ lp::Packet nack1pkt;
+ BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet));
+ BOOST_CHECK_EQUAL(nack1pkt.has<lp::NackField>(), true);
+ BOOST_CHECK_EQUAL(nack1pkt.has<lp::FragmentField>(), true);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
+
+ transport->receivePacket(interest1->wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveInterest)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ interest1->wireEncode().begin(), interest1->wireEncode().end()));
+ lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveBareData)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Data> data1 = makeData("/12345678");
+
+ transport->receivePacket(data1->wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK_EQUAL(receivedData.back(), *data1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveData)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ shared_ptr<Data> data1 = makeData("/12345689");
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ data1->wireEncode().begin(), data1->wireEncode().end()));
+ lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK_EQUAL(receivedData.back(), *data1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNack)
+{
+ // TODO#3104 initialize with Options that disables all services
+
+ lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
+ lpPacket.set<lp::NackField>(nack1.getHeader());
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
+
+
+BOOST_AUTO_TEST_SUITE(LocalFields)
+
+BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 send Interest with IncomingFaceId
+ // expect transport->sentPackets.back() has IncomingFaceId field
+}
+
+BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
+{
+ // TODO#3104 initialize with Options that disables local fields
+ // TODO#3104 send Interest with IncomingFaceId
+ // expect transport->sentPackets.back() has no IncomingFaceId field
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnore)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Interest with IncomingFaceId
+ // expect receivedInterests.back() has no IncomingFaceId tag
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Interest with NextHopFaceId
+ // expect receivedInterests.back() has NextHopFaceId tag
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
+{
+ // TODO#3104 initialize with Options that disables local fields
+ // TODO#3104 receive Interest with NextHopFaceId
+ // expect receivedInterests.empty()
+ // or, expect receivedInterests.back() has no NextHopFaceId tag
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Data with NextHopFaceId
+ // expect receivedData.empty()
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Nack with NextHopFaceId
+ // expect receivedNacks.empty()
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControl)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Data with CacheControl
+ // expect receivedData.back() has CacheControl tag
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDisabled)
+{
+ // TODO#3104 initialize with Options that disables local fields
+ // TODO#3104 receive Data with CacheControl
+ // expect receivedData.back() has no CacheControl tag
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropInterest)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Interest with CacheControl
+ // expect receivedInterests.empty()
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropNack)
+{
+ // TODO#3104 initialize with Options that enables local fields
+ // TODO#3104 receive Nack with CacheControl
+ // expect receivedNacks.empty()
+}
+
+BOOST_AUTO_TEST_SUITE_END() // LocalFields
+
+
+BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/lp-face-wrapper.t.cpp b/tests/daemon/face/lp-face-wrapper.t.cpp
new file mode 100644
index 0000000..182d2fc
--- /dev/null
+++ b/tests/daemon/face/lp-face-wrapper.t.cpp
@@ -0,0 +1,173 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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 "face/lp-face-wrapper.hpp"
+#include "fw/forwarder.hpp"
+
+#include "tests/test-common.hpp"
+#include "dummy-lp-face.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestLpFaceWrapper, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(SetId)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ BOOST_CHECK_EQUAL(face1->getId(), nfd::face::INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1w->getId(), nfd::INVALID_FACEID);
+
+ forwarder.addFace(face1w);
+
+ BOOST_CHECK_NE(face1->getId(), nfd::face::INVALID_FACEID);
+ BOOST_CHECK_NE(face1w->getId(), nfd::INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1->getId(), static_cast<face::FaceId>(face1w->getId()));
+}
+
+BOOST_AUTO_TEST_CASE(SetPersistency)
+{
+ unique_ptr<LpFace> face1u = make_unique<DummyLpFace>();
+ face1u->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+
+ auto face1w = make_shared<face::LpFaceWrapper>(std::move(face1u));
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+
+ face1w->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+
+ BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+}
+
+BOOST_AUTO_TEST_CASE(FailSignal)
+{
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ bool isFailed = false;
+ face1w->onFail.connect(bind([&isFailed] { isFailed = true; }));
+
+ face1->setState(FaceState::DOWN);
+ BOOST_CHECK(!isFailed);
+
+ face1->setState(FaceState::FAILED);
+ BOOST_CHECK(!isFailed);
+
+ face1->setState(FaceState::CLOSED);
+ BOOST_CHECK(isFailed);
+}
+
+BOOST_AUTO_TEST_CASE(SendReceive)
+{
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ const size_t nInInterests = 192;
+ const size_t nInData = 91;
+ const size_t nInNacks = 29;
+ const size_t nOutInterests = 202;
+ const size_t nOutData = 128;
+ const size_t nOutNacks = 84;
+
+ size_t nReceivedInterests = 0;
+ size_t nReceivedData = 0;
+ size_t nReceivedNacks = 0;
+ face1w->onReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
+ face1w->onReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
+ face1w->onReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
+
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), 0);
+ // There's no counters for NACK for now.
+
+ for (size_t i = 0; i < nInInterests; ++i) {
+ shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
+ face1->receiveInterest(*interest);
+ }
+
+ for (size_t i = 0; i < nInData; ++i) {
+ shared_ptr<Data> data = makeData("/hT8FDigWn1");
+ face1->receiveData(*data);
+ }
+
+ for (size_t i = 0; i < nInNacks; ++i) {
+ lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
+ face1->receiveNack(nack);
+ }
+
+ for (size_t i = 0; i < nOutInterests; ++i) {
+ shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
+ face1w->sendInterest(*interest);
+ }
+
+ for (size_t i = 0; i < nOutData; ++i) {
+ shared_ptr<Data> data = makeData("/GigPEtPH6");
+ face1w->sendData(*data);
+ }
+
+ for (size_t i = 0; i < nOutNacks; ++i) {
+ lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
+ face1w->sendNack(nack);
+ }
+
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), nInInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), nInData);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), nOutData);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), nInInterests);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), nInData);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), nOutData);
+
+ BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
+ BOOST_CHECK_EQUAL(nReceivedData, nInData);
+ BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
+ BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
+ BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index 784ee2d..c7b7c36 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -135,9 +135,13 @@
};
inline shared_ptr<Interest>
-makeInterest(const Name& name)
+makeInterest(const Name& name, uint32_t nonce = 0)
{
- return make_shared<Interest>(name);
+ auto interest = make_shared<Interest>(name);
+ if (nonce != 0) {
+ interest->setNonce(nonce);
+ }
+ return interest;
}
inline shared_ptr<Data>
@@ -166,6 +170,16 @@
return link;
}
+inline lp::Nack
+makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
+{
+ Interest interest(name);
+ interest.setNonce(nonce);
+ lp::Nack nack(std::move(interest));
+ nack.setReason(reason);
+ return nack;
+}
+
} // namespace tests
} // namespace nfd