face: face refactoring completion
* delete old Face
* rename LpFace as Face
* eliminate LpFaceWrapper and use new Face
refs #3172
Change-Id: I08c3a5dfb4cc1b9834b30cccd9ab634535d0608c
diff --git a/tests/daemon/face/dummy-lp-face.cpp b/tests/daemon/face/dummy-face.cpp
similarity index 77%
rename from tests/daemon/face/dummy-lp-face.cpp
rename to tests/daemon/face/dummy-face.cpp
index 20fb20d..c4f6154 100644
--- a/tests/daemon/face/dummy-lp-face.cpp
+++ b/tests/daemon/face/dummy-face.cpp
@@ -23,14 +23,14 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "dummy-lp-face.hpp"
+#include "dummy-face.hpp"
#include "dummy-transport.hpp"
namespace nfd {
namespace face {
namespace tests {
-class DummyLpFace::LinkService : public face::LinkService
+class DummyFace::LinkService : public face::LinkService
{
public:
void
@@ -51,28 +51,28 @@
this->face::LinkService::receiveNack(nack);
}
- signal::Signal<LinkService> afterSend;
+ signal::Signal<LinkService, uint32_t> afterSend;
private:
virtual void
doSendInterest(const Interest& interest) DECL_OVERRIDE
{
this->sentInterests.push_back(interest);
- this->afterSend();
+ this->afterSend(tlv::Interest);
}
virtual void
doSendData(const Data& data) DECL_OVERRIDE
{
this->sentData.push_back(data);
- this->afterSend();
+ this->afterSend(tlv::Data);
}
virtual void
doSendNack(const lp::Nack& nack) DECL_OVERRIDE
{
this->sentNacks.push_back(nack);
- this->afterSend();
+ this->afterSend(lp::tlv::Nack);
}
virtual void
@@ -87,11 +87,11 @@
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))
+DummyFace::DummyFace(const std::string& localUri, const std::string& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::FacePersistency persistency,
+ ndn::nfd::LinkType linkType)
+ : Face(make_unique<LinkService>(),
+ make_unique<DummyTransport>(localUri, remoteUri, scope, persistency, linkType))
, afterSend(this->getLinkServiceInternal()->afterSend)
, sentInterests(this->getLinkServiceInternal()->sentInterests)
, sentData(this->getLinkServiceInternal()->sentData)
@@ -100,37 +100,37 @@
}
void
-DummyLpFace::setState(FaceState state)
+DummyFace::setState(FaceState state)
{
this->getTransportInternal()->setState(state);
}
void
-DummyLpFace::receiveInterest(const Interest& interest)
+DummyFace::receiveInterest(const Interest& interest)
{
this->getLinkServiceInternal()->receiveInterest(interest);
}
void
-DummyLpFace::receiveData(const Data& data)
+DummyFace::receiveData(const Data& data)
{
this->getLinkServiceInternal()->receiveData(data);
}
void
-DummyLpFace::receiveNack(const lp::Nack& nack)
+DummyFace::receiveNack(const lp::Nack& nack)
{
this->getLinkServiceInternal()->receiveNack(nack);
}
-DummyLpFace::LinkService*
-DummyLpFace::getLinkServiceInternal()
+DummyFace::LinkService*
+DummyFace::getLinkServiceInternal()
{
return static_cast<LinkService*>(this->getLinkService());
}
DummyTransport*
-DummyLpFace::getTransportInternal()
+DummyFace::getTransportInternal()
{
return static_cast<DummyTransport*>(this->getTransport());
}
diff --git a/tests/daemon/face/dummy-face.hpp b/tests/daemon/face/dummy-face.hpp
index 6ed7d46..34f2d09 100644
--- a/tests/daemon/face/dummy-face.hpp
+++ b/tests/daemon/face/dummy-face.hpp
@@ -29,71 +29,78 @@
#include "face/face.hpp"
namespace nfd {
+namespace face {
namespace tests {
+class DummyTransport;
+
/** \brief a Face for unit testing
+ *
+ * The DummyFace has no underlying transport, but allows observing outgoing packets
+ * and injecting incoming packets at network layer.
+ * It's primarily used for forwarding test suites, but can be used in other tests as well.
+ *
+ * Outgoing network-layer packets sent through the DummyFace are recorded in sent* vectors,
+ * which can be observed in test cases.
+ * Incoming network-layer packets can be injected from test cases through receive* method.
*/
class DummyFace : public Face
{
public:
- explicit
- DummyFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://",
- bool isLocal = false)
- : Face(FaceUri(remoteUri), FaceUri(localUri), isLocal)
- {
- }
+ class LinkService;
+ DummyFace(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
- sendInterest(const Interest& interest) DECL_OVERRIDE
- {
- this->emitSignal(onSendInterest, interest);
- m_sentInterests.push_back(interest);
- this->afterSend();
- }
+ setState(FaceState state);
+ /** \brief causes the face to receive an Interest
+ */
void
- sendData(const Data& data) DECL_OVERRIDE
- {
- this->emitSignal(onSendData, data);
- m_sentDatas.push_back(data);
- this->afterSend();
- }
+ receiveInterest(const Interest& interest);
+ /** \brief causes the face to receive a Data
+ */
void
- close() DECL_OVERRIDE
- {
- this->fail("close");
- }
+ receiveData(const Data& data);
+ /** \brief causes the face to receive a Nack
+ */
void
- receiveInterest(const Interest& interest)
- {
- this->emitSignal(onReceiveInterest, interest);
- }
+ receiveNack(const lp::Nack& nack);
- void
- receiveData(const Data& data)
- {
- this->emitSignal(onReceiveData, data);
- }
+ /** \brief signals after any network-layer packet is sent
+ *
+ * The network-layer packet type is indicated as an argument,
+ * which is either of tlv::Interest, tlv::Data, or lp::tlv::Nack.
+ * The callback may retrieve the packet from sentInterests.back(), sentData.back(), or sentNacks.back().
+ */
+ signal::Signal<LinkService, uint32_t>& afterSend;
- signal::Signal<DummyFace> afterSend;
+private:
+ LinkService*
+ getLinkServiceInternal();
+
+ DummyTransport*
+ getTransportInternal();
public:
- std::vector<Interest> m_sentInterests;
- std::vector<Data> m_sentDatas;
+ std::vector<Interest>& sentInterests;
+ std::vector<Data>& sentData;
+ std::vector<lp::Nack>& sentNacks;
};
-class DummyLocalFace : public DummyFace
-{
-public:
- explicit
- DummyLocalFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://")
- : DummyFace(remoteUri, localUri, true)
- {
- }
-};
+} // namespace tests
+} // namespace face
+namespace tests {
+using nfd::face::tests::DummyFace;
} // namespace tests
} // namespace nfd
diff --git a/tests/daemon/face/dummy-lp-face.hpp b/tests/daemon/face/dummy-lp-face.hpp
deleted file mode 100644
index 588cb59..0000000
--- a/tests/daemon/face/dummy-lp-face.hpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- 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-stream-sender.hpp b/tests/daemon/face/dummy-stream-sender.hpp
deleted file mode 100644
index 7cbb4e2..0000000
--- a/tests/daemon/face/dummy-stream-sender.hpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- 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
- *
- * 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_STREAM_SENDER_HPP
-#define NFD_TESTS_DAEMON_FACE_DUMMY_STREAM_SENDER_HPP
-
-#include "core/scheduler.hpp"
-#include "core/global-io.hpp"
-
-namespace nfd {
-namespace tests {
-
-
-template<class Protocol, class Dataset>
-class DummyStreamSender : public Dataset
-{
-public:
- typedef typename Protocol::endpoint Endpoint;
- typedef typename Protocol::socket Socket;
-
- class Error : public std::runtime_error
- {
- public:
- explicit
- Error(const std::string& what)
- : std::runtime_error(what)
- {
- }
- };
-
- DummyStreamSender()
- : socket(getGlobalIoService())
- {
- }
-
- void
- start(const Endpoint& endpoint)
- {
- socket.async_connect(endpoint,
- bind(&DummyStreamSender::onSuccessfullConnect, this, _1));
- }
-
- void
- onSuccessfullConnect(const boost::system::error_code& error)
- {
- if (error)
- {
- BOOST_THROW_EXCEPTION(Error("Connection aborted"));
- }
-
- // This value may need to be adjusted if some dataset exceeds 100k
- socket.set_option(boost::asio::socket_base::send_buffer_size(100000));
-
- for (typename Dataset::Container::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- socket.async_send(boost::asio::buffer(*i),
- bind(&DummyStreamSender::onSendFinished, this, _1, false));
- }
-
- socket.async_send(boost::asio::buffer(static_cast<const uint8_t*>(0), 0),
- bind(&DummyStreamSender::onSendFinished, this, _1, true));
- }
-
- void
- onSendFinished(const boost::system::error_code& error, bool isFinal)
- {
- if (error) {
- BOOST_THROW_EXCEPTION(Error("Connection aborted"));
- }
-
- if (isFinal) {
- scheduler::schedule(ndn::time::seconds(1),
- bind(&DummyStreamSender::stop, this));
- }
- }
-
- void
- stop()
- {
- // Terminate test
- boost::system::error_code error;
- socket.shutdown(Socket::shutdown_both, error);
- socket.close(error);
- }
-
-public:
- Socket socket;
-};
-
-} // namespace tests
-} // namespace nfd
-
-#endif // NFD_TESTS_DAEMON_FACE_DUMMY_STREAM_SENDER_HPP
diff --git a/tests/daemon/face/dummy-transport.hpp b/tests/daemon/face/dummy-transport.hpp
index ce2833b..f957e1e 100644
--- a/tests/daemon/face/dummy-transport.hpp
+++ b/tests/daemon/face/dummy-transport.hpp
@@ -91,6 +91,7 @@
doClose() DECL_OVERRIDE
{
isClosed = true;
+ this->setState(TransportState::CLOSED);
}
virtual void
diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp
new file mode 100644
index 0000000..6148b3b
--- /dev/null
+++ b/tests/daemon/face/ethernet-factory.t.cpp
@@ -0,0 +1,91 @@
+/* -*- 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/ethernet-factory.hpp"
+
+#include "network-interface-fixture.hpp"
+
+namespace nfd {
+namespace tests {
+
+using nfd::face::tests::NetworkInterfaceFixture;
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, NetworkInterfaceFixture)
+
+BOOST_AUTO_TEST_CASE(GetChannels)
+{
+ EthernetFactory factory;
+
+ auto channels = factory.getChannels();
+ BOOST_CHECK_EQUAL(channels.empty(), true);
+}
+
+BOOST_AUTO_TEST_CASE(MulticastFacesMap)
+{
+ SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1);
+
+ EthernetFactory factory;
+ auto face1 = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress());
+ auto face1bis = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress());
+ BOOST_CHECK_EQUAL(face1, face1bis);
+
+ auto face2 = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress());
+ BOOST_CHECK_NE(face1, face2);
+
+ SKIP_IF_NETWORK_INTERFACE_COUNT_LT(2);
+
+ auto face3 = factory.createMulticastFace(m_interfaces.back(), ethernet::getBroadcastAddress());
+ BOOST_CHECK_NE(face1, face3);
+}
+
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
+{
+ EthernetFactory factory;
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/ethernet-transport.t.cpp b/tests/daemon/face/ethernet-transport.t.cpp
index 1e02173..f7948a2 100644
--- a/tests/daemon/face/ethernet-transport.t.cpp
+++ b/tests/daemon/face/ethernet-transport.t.cpp
@@ -52,6 +52,10 @@
BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
}
+// TODO add the equivalent of these test cases from ethernet.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c
+// SendPacket
+// ProcessIncomingPacket
+
BOOST_AUTO_TEST_SUITE_END() // TestEthernetTransport
BOOST_AUTO_TEST_SUITE_END() // Face
diff --git a/tests/daemon/face/ethernet.t.cpp b/tests/daemon/face/ethernet.t.cpp
deleted file mode 100644
index 2b1d2de..0000000
--- a/tests/daemon/face/ethernet.t.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/* -*- 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/ethernet-factory.hpp"
-#include "face/ethernet-transport.hpp"
-
-#include "face/lp-face-wrapper.hpp"
-#include "network-interface-fixture.hpp"
-
-#include <pcap/pcap.h>
-
-namespace nfd {
-namespace tests {
-
-using nfd::face::tests::NetworkInterfaceFixture;
-
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestEthernet, NetworkInterfaceFixture)
-
-using nfd::Face;
-
-BOOST_AUTO_TEST_CASE(GetChannels)
-{
- EthernetFactory factory;
-
- auto channels = factory.getChannels();
- BOOST_CHECK_EQUAL(channels.empty(), true);
-}
-
-BOOST_AUTO_TEST_CASE(MulticastFacesMap)
-{
- SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1);
-
- EthernetFactory factory;
- auto face1 = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress());
- auto face1bis = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress());
- BOOST_CHECK_EQUAL(face1, face1bis);
-
- auto face2 = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress());
- BOOST_CHECK_NE(face1, face2);
-
- SKIP_IF_NETWORK_INTERFACE_COUNT_LT(2);
-
- auto face3 = factory.createMulticastFace(m_interfaces.back(), ethernet::getBroadcastAddress());
- BOOST_CHECK_NE(face1, face3);
-}
-
-BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
-{
- EthernetFactory factory;
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
- ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-}
-
-BOOST_AUTO_TEST_CASE(SendPacket)
-{
- SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1);
-
- EthernetFactory factory;
- auto face = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress());
-
- BOOST_REQUIRE(static_cast<bool>(face));
- BOOST_CHECK_EQUAL(face->isLocal(), false);
- BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
- BOOST_CHECK_EQUAL(face->isMultiAccess(), true);
- BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
- "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]");
- BOOST_CHECK_EQUAL(face->getLocalUri().toString(),
- "dev://" + m_interfaces.front().name);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0);
- BOOST_CHECK_EQUAL(face->getCounters().nOutBytes, 0);
-
- face->onFail.connect([] (const std::string& reason) { BOOST_FAIL(reason); });
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- face->sendInterest(*interest1);
- face->sendData (*data1 );
- face->sendInterest(*interest2);
- face->sendData (*data2 );
-
- BOOST_CHECK_EQUAL(face->getCounters().nOutBytes,
- interest1->wireEncode().size() +
- data1->wireEncode().size() +
- interest2->wireEncode().size() +
- data2->wireEncode().size());
-}
-
-BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
-{
- SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1);
-
- EthernetFactory factory;
- auto face = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress());
- BOOST_REQUIRE(static_cast<bool>(face));
-
- auto transport = dynamic_cast<face::EthernetTransport*>(face->getLpFace()->getTransport());
- BOOST_REQUIRE(transport != nullptr);
-
- std::vector<Interest> recInterests;
- std::vector<Data> recDatas;
-
- face->onFail.connect([] (const std::string& reason) { BOOST_FAIL(reason); });
- face->onReceiveInterest.connect(
- [&recInterests] (const Interest& i) { recInterests.push_back(i); });
- face->onReceiveData.connect([&recDatas] (const Data& d) { recDatas.push_back(d); });
-
- // check that packet data is not accessed if pcap didn't capture anything (caplen == 0)
- static const pcap_pkthdr zeroHeader{};
- transport->processIncomingPacket(&zeroHeader, nullptr);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0);
- BOOST_CHECK_EQUAL(recInterests.size(), 0);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-
- // runt frame (too short)
- pcap_pkthdr runtHeader{};
- runtHeader.caplen = ethernet::HDR_LEN + 6;
- static const uint8_t packet2[ethernet::HDR_LEN + 6]{};
- transport->processIncomingPacket(&runtHeader, packet2);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0);
- BOOST_CHECK_EQUAL(recInterests.size(), 0);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-
- // valid frame, but TLV block has invalid length
- pcap_pkthdr validHeader{};
- validHeader.caplen = ethernet::HDR_LEN + ethernet::MIN_DATA_LEN;
- static const uint8_t packet3[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{
- 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address
- 0x86, 0x24, // NDN ethertype
- tlv::Interest, // TLV type
- 0xfd, 0xff, 0xff // TLV length (invalid because greater than buffer size)
- };
- transport->processIncomingPacket(&validHeader, packet3);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0);
- BOOST_CHECK_EQUAL(recInterests.size(), 0);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-
- // valid frame, but TLV block has invalid type
- static const uint8_t packet4[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{
- 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address
- 0x86, 0x24, // NDN ethertype
- 0x00, // TLV type (invalid)
- 0x00 // TLV length
- };
- transport->processIncomingPacket(&validHeader, packet4);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 2);
- BOOST_CHECK_EQUAL(recInterests.size(), 0);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-
- // valid frame and valid NDNLPv2 packet, but invalid network-layer packet
- static const uint8_t packet5[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{
- 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address
- 0x86, 0x24, // NDN ethertype
- lp::tlv::LpPacket, 0x04, // start of NDNLPv2 packet
- lp::tlv::Fragment, 0x02, // single fragment
- 0x00, // TLV type (invalid)
- 0x00 // TLV length
- };
- transport->processIncomingPacket(&validHeader, packet5);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 8);
- BOOST_CHECK_EQUAL(recInterests.size(), 0);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-
- // valid frame, valid NDNLPv2 packet, and valid NDN (interest) packet
- static const uint8_t packet6[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{
- 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address
- 0x86, 0x24, // NDN ethertype
- lp::tlv::LpPacket, 0x1a, // start of NDNLPv2 packet
- lp::tlv::Fragment, 0x18, // single fragment
- tlv::Interest, 0x16, // start of NDN packet
- 0x07, 0x0e, 0x08, 0x07, 0x65, 0x78, // payload
- 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x08,
- 0x03, 0x66, 0x6f, 0x6f, 0x0a, 0x04,
- 0x03, 0xef, 0xe9, 0x7c
- };
- transport->processIncomingPacket(&validHeader, packet6);
- BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 36);
- BOOST_CHECK_EQUAL(recInterests.size(), 1);
- BOOST_CHECK_EQUAL(recDatas.size(), 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestEthernet
-BOOST_AUTO_TEST_SUITE_END() // Face
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/face/face-history.hpp b/tests/daemon/face/face-history.hpp
deleted file mode 100644
index 263a23a..0000000
--- a/tests/daemon/face/face-history.hpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- 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_FACE_HISTORY_HPP
-#define NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP
-
-#include "face/face.hpp"
-
-namespace nfd {
-namespace tests {
-
-/** \brief captures signals from Face
- */
-class FaceHistory : noncopyable
-{
-public:
- explicit
- FaceHistory(Face& face)
- : m_limitedIo(nullptr)
- {
- this->construct(face);
- }
-
- FaceHistory(Face& face, LimitedIo& limitedIo)
- : m_limitedIo(&limitedIo)
- {
- this->construct(face);
- }
-
-private:
- void
- construct(Face& face)
- {
- m_receiveInterestConn = face.onReceiveInterest.connect([this] (const Interest& interest) {
- this->receivedInterests.push_back(interest);
- this->afterOp();
- });
- m_receiveDataConn = face.onReceiveData.connect([this] (const Data& data) {
- this->receivedData.push_back(data);
- this->afterOp();
- });
- m_failConn = face.onFail.connect([this] (const std::string& reason) {
- this->failures.push_back(reason);
- this->afterOp();
- });
- }
-
- void
- afterOp()
- {
- if (m_limitedIo != nullptr) {
- m_limitedIo->afterOp();
- }
- }
-
-public:
- std::vector<Interest> receivedInterests;
- std::vector<Data> receivedData;
- std::vector<std::string> failures;
-
-private:
- LimitedIo* m_limitedIo;
- signal::ScopedConnection m_receiveInterestConn;
- signal::ScopedConnection m_receiveDataConn;
- signal::ScopedConnection m_failConn;
-};
-
-} // namespace tests
-} // namespace nfd
-
-#endif // NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP
diff --git a/tests/daemon/face/face.t.cpp b/tests/daemon/face/face.t.cpp
index 4a94a58..7d0dba0 100644
--- a/tests/daemon/face/face.t.cpp
+++ b/tests/daemon/face/face.t.cpp
@@ -24,60 +24,89 @@
*/
#include "face/face.hpp"
-#include "dummy-face.hpp"
#include "tests/test-common.hpp"
+#include "dummy-face.hpp"
namespace nfd {
+namespace face {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(FaceFace, BaseFixture)
+using namespace nfd::tests;
-BOOST_AUTO_TEST_CASE(Description)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestFace, BaseFixture)
+
+// TODO add test cases for getLinkService, getTransport
+// TODO add a test case for static properties
+// TODO add a test case for getState
+
+BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
{
- DummyFace face;
- face.setDescription("3pFsKrvWr");
- BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr");
+ auto face1 = make_shared<DummyFace>();
+
+ 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;
+ face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
+ face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
+ face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
+
+ 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");
+ face1->sendInterest(*interest);
+ }
+
+ for (size_t i = 0; i < nOutData; ++i) {
+ shared_ptr<Data> data = makeData("/GigPEtPH6");
+ face1->sendData(*data);
+ }
+
+ for (size_t i = 0; i < nOutNacks; ++i) {
+ lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
+ face1->sendNack(nack);
+ }
+
+ BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
+ BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
+ BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
+ BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
+
+ 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);
}
-class FaceFailTestFace : public DummyFace
-{
-public:
- FaceFailTestFace()
- : failCount(0)
- {
- this->onFail.connect(bind(&FaceFailTestFace::failHandler, this, _1));
- }
-
- void
- failOnce()
- {
- this->fail("reason");
- }
-
-private:
- void
- failHandler(const std::string& reason)
- {
- BOOST_CHECK_EQUAL(reason, "reason");
- ++this->failCount;
- }
-
-public:
- int failCount;
-};
-
-BOOST_AUTO_TEST_CASE(FailTwice)
-{
- FaceFailTestFace face;
- BOOST_CHECK_EQUAL(face.failCount, 0);
- face.failOnce();
- BOOST_CHECK_EQUAL(face.failCount, 1);
- face.failOnce();
- BOOST_CHECK_EQUAL(face.failCount, 1);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestFace
+BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
+} // namespace face
} // namespace nfd
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
index 70e078d..888c222 100644
--- a/tests/daemon/face/generic-link-service.t.cpp
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -24,7 +24,7 @@
*/
#include "face/generic-link-service.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-transport.hpp"
#include "tests/test-common.hpp"
@@ -37,6 +37,8 @@
BOOST_AUTO_TEST_SUITE(Face)
+using nfd::Face;
+
class GenericLinkServiceFixture : public BaseFixture
{
protected:
@@ -52,8 +54,8 @@
void
initialize(const GenericLinkService::Options& options)
{
- face.reset(new LpFace(make_unique<GenericLinkService>(options),
- make_unique<DummyTransport>()));
+ face.reset(new Face(make_unique<GenericLinkService>(options),
+ make_unique<DummyTransport>()));
service = static_cast<GenericLinkService*>(face->getLinkService());
transport = static_cast<DummyTransport*>(face->getTransport());
@@ -66,7 +68,7 @@
}
protected:
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
GenericLinkService* service;
DummyTransport* transport;
std::vector<Interest> receivedInterests;
diff --git a/tests/daemon/face/internal-face.t.cpp b/tests/daemon/face/internal-face.t.cpp
index cca385e..4371317 100644
--- a/tests/daemon/face/internal-face.t.cpp
+++ b/tests/daemon/face/internal-face.t.cpp
@@ -24,9 +24,8 @@
*/
#include "face/internal-face.hpp"
-#include "face/lp-face-wrapper.hpp"
-#include "transport-test-common.hpp"
+#include "transport-test-common.hpp"
#include "tests/identity-management-fixture.hpp"
namespace nfd {
@@ -43,9 +42,7 @@
public:
InternalFaceFixture()
{
- std::tie(forwarderFaceW, clientFace) = makeInternalFace(m_keyChain);;
- forwarderFace = static_pointer_cast<LpFaceWrapper>(forwarderFaceW)->getLpFace();
- // TODO#3172 eliminate wrapper
+ std::tie(forwarderFace, clientFace) = makeInternalFace(m_keyChain);;
forwarderFace->afterReceiveInterest.connect(
[this] (const Interest& interest) { receivedInterests.push_back(interest); } );
@@ -56,8 +53,7 @@
}
protected:
- shared_ptr<nfd::Face> forwarderFaceW;
- LpFace* forwarderFace;
+ shared_ptr<nfd::Face> forwarderFace;
shared_ptr<ndn::Face> clientFace;
std::vector<Interest> receivedInterests;
@@ -199,7 +195,7 @@
forwarderFace->close();
this->advanceClocks(time::milliseconds(1), 10);
BOOST_CHECK_EQUAL(forwarderFace->getState(), FaceState::CLOSED);
- forwarderFaceW.reset();
+ forwarderFace.reset();
shared_ptr<Interest> interest = makeInterest("/zpHsVesu0B");
interest->setInterestLifetime(time::milliseconds(100));
diff --git a/tests/daemon/face/lp-face-wrapper.t.cpp b/tests/daemon/face/lp-face-wrapper.t.cpp
deleted file mode 100644
index 8217d77..0000000
--- a/tests/daemon/face/lp-face-wrapper.t.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- 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(Counters)
-{
- auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
- auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
-
- BOOST_CHECK(&face1->getCounters() == &face1w->getCounters());
-}
-
-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; }));
-
- 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(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/daemon/face/lp-face.t.cpp b/tests/daemon/face/lp-face.t.cpp
deleted file mode 100644
index 92a3755..0000000
--- a/tests/daemon/face/lp-face.t.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- 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.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(TestLpFace, BaseFixture)
-
-BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
-{
- auto face1 = make_shared<DummyLpFace>();
-
- 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;
- face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
- face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
- face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
-
- 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");
- face1->sendInterest(*interest);
- }
-
- for (size_t i = 0; i < nOutData; ++i) {
- shared_ptr<Data> data = makeData("/GigPEtPH6");
- face1->sendData(*data);
- }
-
- for (size_t i = 0; i < nOutNacks; ++i) {
- lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
- face1->sendNack(nack);
- }
-
- BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
- BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
- BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
- BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
- BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
- BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
-
- 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/daemon/face/null-face.t.cpp b/tests/daemon/face/null-face.t.cpp
index 16d1a11..4075245 100644
--- a/tests/daemon/face/null-face.t.cpp
+++ b/tests/daemon/face/null-face.t.cpp
@@ -24,7 +24,7 @@
*/
#include "face/null-face.hpp"
-#include "face/lp-face-wrapper.hpp"
+
#include "transport-test-common.hpp"
namespace nfd {
@@ -40,8 +40,7 @@
BOOST_AUTO_TEST_CASE(StaticProperties)
{
- shared_ptr<Face> faceW = makeNullFace(FaceUri("testnull://hhppt12sy"));
- LpFace* face = static_pointer_cast<LpFaceWrapper>(faceW)->getLpFace();
+ shared_ptr<Face> face = makeNullFace(FaceUri("testnull://hhppt12sy"));
checkStaticPropertiesInitialized(*face->getTransport());
BOOST_CHECK_EQUAL(face->getLocalUri(), FaceUri("testnull://hhppt12sy"));
diff --git a/tests/daemon/face/packet-datasets.cpp b/tests/daemon/face/packet-datasets.cpp
deleted file mode 100644
index 196fa86..0000000
--- a/tests/daemon/face/packet-datasets.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- 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
- *
- * 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 "packet-datasets.hpp"
-#include "tests/test-common.hpp"
-
-#include <boost/foreach.hpp>
-
-namespace nfd {
-namespace tests {
-
-BOOST_FIXTURE_TEST_SUITE(Datasets, BaseFixture)
-
-BOOST_AUTO_TEST_CASE(Corrupted)
-{
- {
- typedef CorruptedInterest Dataset;
- Dataset dataset;
-
- BOOST_FOREACH(Dataset::Container::value_type& data, dataset.data)
- {
- Block block(data.buf(), data.size());
-
- BOOST_CHECK_THROW((Interest(block)), tlv::Error);
- }
- }
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/face/packet-datasets.hpp b/tests/daemon/face/packet-datasets.hpp
deleted file mode 100644
index 95639c1..0000000
--- a/tests/daemon/face/packet-datasets.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- 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
- *
- * 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_PACKET_DATASETS_HPP
-#define NFD_TESTS_DAEMON_FACE_PACKET_DATASETS_HPP
-
-#include "tests/test-common.hpp"
-
-namespace nfd {
-namespace tests {
-
-class CorruptedInterest
-{
-public:
- typedef std::vector<ndn::Buffer> Container;
-
- static std::string
- getName()
- {
- return "CorruptedInterest";
- }
-
- CorruptedInterest()
- {
- static const uint8_t interest[] = {
- 0x05, 0x1d, 0x07, 0x84, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
- 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x01,
- 0x01
- };
-
- data.push_back(ndn::Buffer(interest, sizeof(interest)));
- }
-public:
- Container data;
-};
-
-typedef boost::mpl::vector<CorruptedInterest> CorruptedPackets;
-
-} // namespace tests
-} // namespace nfd
-
-#endif // NFD_TESTS_DAEMON_FACE_PACKET_DATASETS_HPP
diff --git a/tests/daemon/face/tcp-channel.t.cpp b/tests/daemon/face/tcp-channel.t.cpp
new file mode 100644
index 0000000..816761d
--- /dev/null
+++ b/tests/daemon/face/tcp-channel.t.cpp
@@ -0,0 +1,44 @@
+/* -*- 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/tcp-channel.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestTcpChannel, BaseFixture)
+
+// TODO add the equivalent of these test cases from tcp.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c
+// MultipleAccepts
+// FaceClosing
+
+BOOST_AUTO_TEST_SUITE_END() // TestTcpChannel
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp
new file mode 100644
index 0000000..ee796ab
--- /dev/null
+++ b/tests/daemon/face/tcp-factory.t.cpp
@@ -0,0 +1,258 @@
+/* -*- 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/tcp-factory.hpp"
+
+#include "core/network-interface.hpp"
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, BaseFixture)
+
+using nfd::Face;
+
+BOOST_AUTO_TEST_CASE(ChannelMap)
+{
+ TcpFactory factory;
+
+ shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
+ shared_ptr<TcpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
+ BOOST_CHECK_EQUAL(channel1, channel1a);
+ BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070");
+
+ shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
+ BOOST_CHECK_NE(channel1, channel2);
+
+ shared_ptr<TcpChannel> channel3 = factory.createChannel("::1", "20071");
+ BOOST_CHECK_NE(channel2, channel3);
+ BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071");
+}
+
+BOOST_AUTO_TEST_CASE(GetChannels)
+{
+ TcpFactory factory;
+ BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
+
+ std::vector<shared_ptr<const Channel>> expectedChannels;
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
+ expectedChannels.push_back(factory.createChannel("::1", "20071"));
+
+ for (const auto& ch : factory.getChannels()) {
+ auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch);
+ BOOST_REQUIRE(pos != expectedChannels.end());
+ expectedChannels.erase(pos);
+ }
+ BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
+}
+
+class FaceCreateFixture : public BaseFixture
+{
+public:
+ void
+ checkError(const std::string& errorActual, const std::string& errorExpected)
+ {
+ BOOST_CHECK_EQUAL(errorActual, errorExpected);
+ }
+
+ void
+ failIfError(const std::string& errorActual)
+ {
+ BOOST_FAIL("No error expected, but got: [" << errorActual << "]");
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture)
+{
+ TcpFactory factory;
+
+ factory.createFace(FaceUri("tcp4://127.0.0.1:6363"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::checkError, this, _1,
+ "No channels available to connect to 127.0.0.1:6363"));
+
+ factory.createChannel("127.0.0.1", "20071");
+
+ factory.createFace(FaceUri("tcp4://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::failIfError, this, _1));
+}
+
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
+{
+ TcpFactory factory;
+
+ factory.createChannel("127.0.0.1", "20070");
+ factory.createChannel("127.0.0.1", "20071");
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20071"),
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+}
+
+class FaceCreateTimeoutFixture : public BaseFixture
+{
+public:
+ void
+ onFaceCreated(const shared_ptr<Face>& newFace)
+ {
+ BOOST_CHECK_MESSAGE(false, "Timeout expected");
+ BOOST_CHECK(!static_cast<bool>(face1));
+ face1 = newFace;
+
+ limitedIo.afterOp();
+ }
+
+ void
+ onConnectFailed(const std::string& reason)
+ {
+ BOOST_CHECK_MESSAGE(true, reason);
+
+ limitedIo.afterOp();
+ }
+
+public:
+ LimitedIo limitedIo;
+
+ shared_ptr<Face> face1;
+};
+
+BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture)
+{
+ TcpFactory factory;
+ shared_ptr<TcpChannel> channel = factory.createChannel("0.0.0.0", "20070");
+
+ factory.createFace(FaceUri("tcp4://192.0.2.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1),
+ bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _1));
+
+ BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(10)) == LimitedIo::EXCEED_OPS,
+ "TcpChannel error: cannot connect or cannot accept connection");
+
+ BOOST_CHECK_EQUAL(static_cast<bool>(face1), false);
+}
+
+class FakeNetworkInterfaceFixture : public BaseFixture
+{
+public:
+ FakeNetworkInterfaceFixture()
+ {
+ using namespace boost::asio::ip;
+
+ auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
+
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {0, "eth0",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("0.0.0.0")},
+ {address_v6::from_string("::")},
+ address_v4(),
+ IFF_UP});
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {1, "eth0",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
+ {},
+ address_v4::from_string("192.168.2.255"),
+ 0});
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {2, "eth1",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("198.51.100.1")},
+ {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
+ address_v4::from_string("198.51.100.255"),
+ IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
+
+ setDebugNetworkInterfaces(fakeInterfaces);
+ }
+
+ ~FakeNetworkInterfaceFixture()
+ {
+ setDebugNetworkInterfaces(nullptr);
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
+{
+ using namespace boost::asio::ip;
+
+ TcpFactory factory;
+ factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<tcp::Endpoint> {
+ tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<tcp::Endpoint> {
+ tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(tcp::Endpoint(address_v4(), 1024));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 4);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<tcp::Endpoint> {
+ tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
+ tcp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
+ tcp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
+ tcp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(tcp::Endpoint(address_v6(), 2048));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<tcp::Endpoint> {
+ tcp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
+ tcp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
+ tcp::Endpoint(address_v6::from_string("::"), 2048)
+ }));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/tcp-transport-fixture.hpp b/tests/daemon/face/tcp-transport-fixture.hpp
index 38be67b..e68eff9 100644
--- a/tests/daemon/face/tcp-transport-fixture.hpp
+++ b/tests/daemon/face/tcp-transport-fixture.hpp
@@ -27,7 +27,7 @@
#define NFD_TESTS_DAEMON_FACE_TCP_TRANSPORT_FIXTURE_HPP
#include "face/tcp-transport.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
@@ -73,9 +73,9 @@
BOOST_REQUIRE_EQUAL(limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS);
localEp = sock.local_endpoint();
- face = make_unique<LpFace>(make_unique<DummyReceiveLinkService>(),
- make_unique<TcpTransport>(std::move(sock),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT));
+ face = make_unique<Face>(make_unique<DummyReceiveLinkService>(),
+ make_unique<TcpTransport>(std::move(sock),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT));
transport = static_cast<TcpTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
@@ -103,7 +103,7 @@
private:
tcp::acceptor acceptor;
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
};
} // namespace tests
diff --git a/tests/daemon/face/tcp.t.cpp b/tests/daemon/face/tcp.t.cpp
deleted file mode 100644
index 6d5fe19..0000000
--- a/tests/daemon/face/tcp.t.cpp
+++ /dev/null
@@ -1,758 +0,0 @@
-/* -*- 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/tcp-channel.hpp"
-#include "face/tcp-factory.hpp"
-
-#include "core/network-interface.hpp"
-#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
-#include "dummy-stream-sender.hpp"
-#include "packet-datasets.hpp"
-
-namespace nfd {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestTcp, BaseFixture)
-
-using nfd::Face;
-
-BOOST_AUTO_TEST_CASE(ChannelMap)
-{
- TcpFactory factory;
-
- shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
- shared_ptr<TcpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
- BOOST_CHECK_EQUAL(channel1, channel1a);
- BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070");
-
- shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
- BOOST_CHECK_NE(channel1, channel2);
-
- shared_ptr<TcpChannel> channel3 = factory.createChannel("::1", "20071");
- BOOST_CHECK_NE(channel2, channel3);
- BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071");
-}
-
-BOOST_AUTO_TEST_CASE(GetChannels)
-{
- TcpFactory factory;
- BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
-
- std::vector<shared_ptr<const Channel>> expectedChannels;
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
- expectedChannels.push_back(factory.createChannel("::1", "20071"));
-
- for (const auto& ch : factory.getChannels()) {
- auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch);
- BOOST_REQUIRE(pos != expectedChannels.end());
- expectedChannels.erase(pos);
- }
- BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
-}
-
-class FaceCreateFixture : protected BaseFixture
-{
-public:
- void
- checkError(const std::string& errorActual, const std::string& errorExpected)
- {
- BOOST_CHECK_EQUAL(errorActual, errorExpected);
- }
-
- void
- failIfError(const std::string& errorActual)
- {
- BOOST_FAIL("No error expected, but got: [" << errorActual << "]");
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture)
-{
- TcpFactory factory;
-
- factory.createFace(FaceUri("tcp4://127.0.0.1:6363"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind(&FaceCreateFixture::checkError, this, _1,
- "No channels available to connect to 127.0.0.1:6363"));
-
- factory.createChannel("127.0.0.1", "20071");
-
- factory.createFace(FaceUri("tcp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind(&FaceCreateFixture::failIfError, this, _1));
-}
-
-BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
-{
- TcpFactory factory;
-
- factory.createChannel("127.0.0.1", "20070");
- factory.createChannel("127.0.0.1", "20071");
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20071"),
- ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-}
-
-class EndToEndFixture : protected BaseFixture
-{
-public:
- void
- channel1_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- BOOST_CHECK(!static_cast<bool>(face1));
- face1 = newFace;
- face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
- face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
- face1->onFail.connect(bind(&EndToEndFixture::face1_onFail, this));
-
- limitedIo.afterOp();
- }
-
- void
- channel1_onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveInterest(const Interest& interest)
- {
- face1_receivedInterests.push_back(interest);
-
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveData(const Data& data)
- {
- face1_receivedDatas.push_back(data);
-
- limitedIo.afterOp();
- }
-
- void
- face1_onFail()
- {
- g_io.post([this] {
- face1.reset();
- limitedIo.afterOp();
- });
- }
-
- void
- channel2_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- BOOST_CHECK(!static_cast<bool>(face2));
- face2 = newFace;
- face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
- face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
- face2->onFail.connect(bind(&EndToEndFixture::face2_onFail, this));
-
- limitedIo.afterOp();
- }
-
- void
- channel2_onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- void
- face2_onReceiveInterest(const Interest& interest)
- {
- face2_receivedInterests.push_back(interest);
-
- limitedIo.afterOp();
- }
-
- void
- face2_onReceiveData(const Data& data)
- {
- face2_receivedDatas.push_back(data);
-
- limitedIo.afterOp();
- }
-
- void
- face2_onFail()
- {
- g_io.post([this] {
- face2.reset();
- limitedIo.afterOp();
- });
- }
-
- void
- channel_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- faces.push_back(newFace);
- limitedIo.afterOp();
- }
-
- void
- channel_onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- void
- checkFaceList(size_t shouldBe)
- {
- BOOST_CHECK_EQUAL(faces.size(), shouldBe);
- }
-
- void
- connect(const shared_ptr<TcpChannel>& channel,
- const std::string& remoteHost,
- const std::string& remotePort)
- {
- channel->connect(tcp::Endpoint(boost::asio::ip::address::from_string(remoteHost),
- boost::lexical_cast<uint16_t>(remotePort)),
- bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
- }
-
-public:
- LimitedIo limitedIo;
-
- shared_ptr<Face> face1;
- std::vector<Interest> face1_receivedInterests;
- std::vector<Data> face1_receivedDatas;
- shared_ptr<Face> face2;
- std::vector<Interest> face2_receivedInterests;
- std::vector<Data> face2_receivedDatas;
-
- std::list<shared_ptr<Face>> faces;
-};
-
-BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
-{
- TcpFactory factory1;
-
- shared_ptr<TcpChannel> channel1 = factory1.createChannel("127.0.0.1", "20070");
- factory1.createChannel("127.0.0.1", "20071");
-
- BOOST_CHECK_EQUAL(channel1->isListening(), false);
-
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
- BOOST_CHECK_EQUAL(channel1->isListening(), true);
-
- TcpFactory factory2;
-
- shared_ptr<TcpChannel> channel2 = factory2.createChannel("127.0.0.2", "20070");
- factory2.createChannel("127.0.0.2", "20071");
-
- factory2.createFace(FaceUri("tcp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_REQUIRE(static_cast<bool>(face2));
-
- BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
- BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
- BOOST_CHECK_EQUAL(face2->isMultiAccess(), false);
-
- BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp4://127.0.0.1:20070");
- BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp4://127.0.0.1:20070");
- // face1 has an unknown remoteUri, since the source port is automatically chosen by OS
-
- BOOST_CHECK_EQUAL(face1->isLocal(), true);
- BOOST_CHECK_EQUAL(face2->isLocal(), true);
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- face1->sendInterest(*interest1);
- face1->sendInterest(*interest1);
- face1->sendInterest(*interest1);
- face1->sendData (*data1 );
- size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size();
- face2->sendInterest(*interest2);
- face2->sendData (*data2 );
- face2->sendData (*data2 );
- face2->sendData (*data2 );
-
- BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot send or receive Interest/Data packets");
-
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
- BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
- BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
-
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
- BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
- BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
-
- // needed to ensure NOutBytes counters are accurate
- limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1));
-
- const face::FaceCounters& counters1 = face1->getCounters();
- BOOST_CHECK_EQUAL(counters1.nInInterests, 1);
- BOOST_CHECK_EQUAL(counters1.nInData, 3);
- BOOST_CHECK_EQUAL(counters1.nOutInterests, 3);
- BOOST_CHECK_EQUAL(counters1.nOutData, 1);
- BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1);
-
- const face::FaceCounters& counters2 = face2->getCounters();
- BOOST_CHECK_EQUAL(counters2.nInInterests, 3);
- BOOST_CHECK_EQUAL(counters2.nInData, 1);
- BOOST_CHECK_EQUAL(counters2.nOutInterests, 1);
- BOOST_CHECK_EQUAL(counters2.nOutData, 3);
- BOOST_CHECK_EQUAL(counters2.nInBytes, nBytesSent1);
-}
-
-BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture)
-{
- TcpFactory factory1;
-
- shared_ptr<TcpChannel> channel1 = factory1.createChannel("::1", "20070");
- shared_ptr<TcpChannel> channel2 = factory1.createChannel("::1", "20071");
-
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
- TcpFactory factory2;
-
- factory2.createChannel("::2", "20070");
-
- factory2.createFace(FaceUri("tcp6://[::1]:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_REQUIRE(static_cast<bool>(face2));
-
- BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp6://[::1]:20070");
- BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp6://[::1]:20070");
- // face1 has an unknown remoteUri, since the source port is automatically chosen by OS
-
- BOOST_CHECK_EQUAL(face1->isLocal(), true);
- BOOST_CHECK_EQUAL(face2->isLocal(), true);
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- face1->sendInterest(*interest1);
- face1->sendData (*data1 );
- face2->sendInterest(*interest2);
- face2->sendData (*data2 );
-
- BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot send or receive Interest/Data packets");
-
-
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
- BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
-
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
- BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
- BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
-}
-
-BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
-{
- TcpFactory factory;
-
- shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
- shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
-
- channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
-
- using namespace boost::asio;
- channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
- bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel_onConnectFailed, this, _1),
- time::seconds(4)); // very short timeout
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
-
- BOOST_CHECK_EQUAL(faces.size(), 2);
-
- shared_ptr<TcpChannel> channel3 = factory.createChannel("127.0.0.1", "20072");
- channel3->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
- bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel_onConnectFailed, this, _1),
- time::seconds(4)); // very short timeout
-
-
- shared_ptr<TcpChannel> channel4 = factory.createChannel("127.0.0.1", "20073");
-
- BOOST_CHECK_NE(channel3, channel4);
-
- scheduler::schedule(time::seconds(1),
- bind(&EndToEndFixture::connect, this, channel4, "127.0.0.1", "20070"));
-
- scheduler::schedule(time::milliseconds(500),
- bind(&EndToEndFixture::checkFaceList, this, 4));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(4,// 2 connects and 2 accepts
- time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept multiple connections");
-
- BOOST_CHECK_EQUAL(faces.size(), 6);
-}
-
-BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
-{
- TcpFactory factory;
-
- shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
- shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
-
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
- using namespace boost::asio;
- channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
- bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel2_onConnectFailed, this, _1),
- time::seconds(4)); // very short timeout
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
- BOOST_CHECK_EQUAL(channel1->size(), 1);
- BOOST_CHECK_EQUAL(channel2->size(), 1);
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_CHECK(static_cast<bool>(face2));
-
- // Face::close must be invoked during io run to be counted as an op
- scheduler::schedule(time::milliseconds(100), bind(&Face::close, face1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "FaceClosing error: cannot properly close faces");
-
- // both faces should get closed
- BOOST_CHECK(!static_cast<bool>(face1));
- BOOST_CHECK(!static_cast<bool>(face2));
-
- BOOST_CHECK_EQUAL(channel1->size(), 0);
- BOOST_CHECK_EQUAL(channel2->size(), 0);
-}
-
-class SimpleEndToEndFixture : protected BaseFixture
-{
-public:
- void
- onFaceCreated(const shared_ptr<Face>& face)
- {
- face->onReceiveInterest.connect(bind(&SimpleEndToEndFixture::onReceiveInterest, this, _1));
- face->onReceiveData.connect(bind(&SimpleEndToEndFixture::onReceiveData, this, _1));
- face->onFail.connect(bind(&SimpleEndToEndFixture::onFail, this, face));
-
- limitedIo.afterOp();
- }
-
- void
- onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- void
- onReceiveInterest(const Interest& interest)
- {
- receivedInterests.push_back(interest);
-
- limitedIo.afterOp();
- }
-
- void
- onReceiveData(const Data& data)
- {
- receivedDatas.push_back(data);
-
- limitedIo.afterOp();
- }
-
- void
- onFail(const shared_ptr<Face>& face)
- {
- limitedIo.afterOp();
- }
-
-public:
- LimitedIo limitedIo;
-
- std::vector<Interest> receivedInterests;
- std::vector<Data> receivedDatas;
-};
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(FaceCorruptedInput, Dataset,
- CorruptedPackets, SimpleEndToEndFixture)
-{
- // test with non-local Face
- boost::asio::ip::address_v4 someIpv4Address;
- for (const auto& netif : listNetworkInterfaces()) {
- if (!netif.isLoopback() && netif.isUp() && !netif.ipv4Addresses.empty()) {
- someIpv4Address = netif.ipv4Addresses.front();
- break;
- }
- }
- if (someIpv4Address.is_unspecified()) {
- BOOST_TEST_MESSAGE("Test with non-local Face cannot be run "
- "(no non-loopback interface with IPv4 address found)");
- return;
- }
-
- TcpFactory factory;
- tcp::Endpoint endpoint(someIpv4Address, 20070);
-
- shared_ptr<TcpChannel> channel = factory.createChannel(endpoint);
- channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1),
- bind(&SimpleEndToEndFixture::onConnectFailed, this, _1));
- BOOST_REQUIRE_EQUAL(channel->isListening(), true);
-
- DummyStreamSender<boost::asio::ip::tcp, Dataset> sender;
- sender.start(endpoint);
-
- BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS,
- time::seconds(1)) == LimitedIo::EXCEED_TIME,
- "Exception thrown for " + Dataset::getName());
-}
-
-class FaceCreateTimeoutFixture : protected BaseFixture
-{
-public:
- void
- onFaceCreated(const shared_ptr<Face>& newFace)
- {
- BOOST_CHECK_MESSAGE(false, "Timeout expected");
- BOOST_CHECK(!static_cast<bool>(face1));
- face1 = newFace;
-
- limitedIo.afterOp();
- }
-
- void
- onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(true, reason);
-
- limitedIo.afterOp();
- }
-
-public:
- LimitedIo limitedIo;
-
- shared_ptr<Face> face1;
-};
-
-BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture)
-{
- TcpFactory factory;
- shared_ptr<TcpChannel> channel = factory.createChannel("0.0.0.0", "20070");
-
- factory.createFace(FaceUri("tcp4://192.0.2.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1),
- bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
- BOOST_CHECK_EQUAL(static_cast<bool>(face1), false);
-}
-
-BOOST_FIXTURE_TEST_CASE(Bug1856, EndToEndFixture)
-{
- TcpFactory factory1;
-
- shared_ptr<TcpChannel> channel1 = factory1.createChannel("127.0.0.1", "20070");
- factory1.createChannel("127.0.0.1", "20071");
-
- BOOST_CHECK_EQUAL(channel1->isListening(), false);
-
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
- BOOST_CHECK_EQUAL(channel1->isListening(), true);
-
- TcpFactory factory2;
-
- shared_ptr<TcpChannel> channel2 = factory2.createChannel("127.0.0.2", "20070");
- factory2.createChannel("127.0.0.2", "20071");
-
- factory2.createFace(FaceUri("tcp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "TcpChannel error: cannot connect or cannot accept connection");
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_REQUIRE(static_cast<bool>(face2));
-
- std::ostringstream hugeName;
- hugeName << "/huge-name/";
- for (size_t i = 0; i < ndn::MAX_NDN_PACKET_SIZE; i++)
- hugeName << 'a';
-
- shared_ptr<Interest> interest = makeInterest("ndn:/KfczhUqVix");
- shared_ptr<Interest> hugeInterest = makeInterest(hugeName.str());
-
- face1->sendInterest(*hugeInterest);
- face2->sendInterest(*interest);
- face2->sendInterest(*interest);
-
- limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1));
- BOOST_TEST_MESSAGE("Unexpected assertion test passed");
-}
-
-class FakeNetworkInterfaceFixture : public BaseFixture
-{
-public:
- FakeNetworkInterfaceFixture()
- {
- using namespace boost::asio::ip;
-
- auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
-
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {0, "eth0",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("0.0.0.0")},
- {address_v6::from_string("::")},
- address_v4(),
- IFF_UP});
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {1, "eth0",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
- {},
- address_v4::from_string("192.168.2.255"),
- 0});
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {2, "eth1",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("198.51.100.1")},
- {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
- address_v4::from_string("198.51.100.255"),
- IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
-
- setDebugNetworkInterfaces(fakeInterfaces);
- }
-
- ~FakeNetworkInterfaceFixture()
- {
- setDebugNetworkInterfaces(nullptr);
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
-{
- using namespace boost::asio::ip;
-
- TcpFactory factory;
- factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<tcp::Endpoint> {
- tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<tcp::Endpoint> {
- tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(tcp::Endpoint(address_v4(), 1024));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 4);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<tcp::Endpoint> {
- tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
- tcp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
- tcp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
- tcp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(tcp::Endpoint(address_v6(), 2048));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<tcp::Endpoint> {
- tcp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
- tcp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
- tcp::Endpoint(address_v6::from_string("::"), 2048)
- }));
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestTcp
-BOOST_AUTO_TEST_SUITE_END() // Face
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/face/transport.t.cpp b/tests/daemon/face/transport.t.cpp
index 8189859..9a59491 100644
--- a/tests/daemon/face/transport.t.cpp
+++ b/tests/daemon/face/transport.t.cpp
@@ -24,7 +24,7 @@
*/
#include "face/transport.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-transport.hpp"
#include "dummy-receive-link-service.hpp"
#include "transport-test-common.hpp"
@@ -45,6 +45,8 @@
BOOST_AUTO_TEST_SUITE(Face)
+using nfd::Face;
+
class DummyTransportFixture : public BaseFixture
{
public:
@@ -60,14 +62,14 @@
void
initialize(unique_ptr<DummyTransport> transport = make_unique<DummyTransport>())
{
- this->face = make_unique<LpFace>(make_unique<DummyReceiveLinkService>(), std::move(transport));
+ this->face = make_unique<Face>(make_unique<DummyReceiveLinkService>(), std::move(transport));
this->transport = static_cast<DummyTransport*>(face->getTransport());
this->sentPackets = &this->transport->sentPackets;
this->receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
}
public:
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
DummyTransport* transport;
std::vector<Transport::Packet>* sentPackets;
std::vector<Transport::Packet>* receivedPackets;
diff --git a/tests/daemon/face/udp-channel.t.cpp b/tests/daemon/face/udp-channel.t.cpp
new file mode 100644
index 0000000..447ec0d
--- /dev/null
+++ b/tests/daemon/face/udp-channel.t.cpp
@@ -0,0 +1,47 @@
+/* -*- 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/udp-channel.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUdpChannel, BaseFixture)
+
+using nfd::Face;
+
+// TODO add the equivalent of these test cases from udp.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c
+// MultipleAccepts
+// ManualClose
+// IdleClose
+
+BOOST_AUTO_TEST_SUITE_END() // TestUdpChannel
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
new file mode 100644
index 0000000..837262c
--- /dev/null
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -0,0 +1,335 @@
+/* -*- 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/udp-factory.hpp"
+
+#include "core/network-interface.hpp"
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, BaseFixture)
+
+using nfd::Face;
+
+BOOST_AUTO_TEST_CASE(GetChannels)
+{
+ UdpFactory factory;
+ BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
+
+ std::vector<shared_ptr<const Channel>> expectedChannels;
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
+ expectedChannels.push_back(factory.createChannel("::1", "20071"));
+
+ for (const auto& i : factory.getChannels()) {
+ auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i);
+ BOOST_REQUIRE(pos != expectedChannels.end());
+ expectedChannels.erase(pos);
+ }
+
+ BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
+}
+
+class FactoryErrorCheck : public BaseFixture
+{
+public:
+ bool
+ isTheSameMulticastEndpoint(const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create the requested UDP unicast channel, local "
+ "endpoint is already allocated for a UDP multicast face") == 0;
+ }
+
+ bool
+ isNotMulticastAddress(const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create the requested UDP multicast face, "
+ "the multicast group given as input is not a multicast address") == 0;
+ }
+
+ bool
+ isTheSameUnicastEndpoint(const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create the requested UDP multicast face, local "
+ "endpoint is already allocated for a UDP unicast channel") == 0;
+ }
+
+ bool
+ isLocalEndpointOnDifferentGroup(const UdpFactory::Error& e) {
+ return strcmp(e.what(),
+ "Cannot create the requested UDP multicast face, local "
+ "endpoint is already allocated for a UDP multicast face "
+ "on a different multicast group") == 0;
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck)
+{
+ using boost::asio::ip::udp;
+
+ UdpFactory factory = UdpFactory();
+
+ //to instantiate multicast face on a specific ip address, change interfaceIp
+ std::string interfaceIp = "0.0.0.0";
+
+ shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
+ shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
+ BOOST_CHECK_EQUAL(channel1, channel1a);
+ BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
+
+ shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
+ BOOST_CHECK_NE(channel1, channel2);
+
+ shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070");
+
+ shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071");
+ BOOST_CHECK_NE(channel2, channel4);
+ BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071");
+
+ //same endpoint of a unicast channel
+ BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.1", "20070"),
+ UdpFactory::Error, isTheSameUnicastEndpoint);
+
+ auto multicastFace1 = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
+ auto multicastFace1a = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
+ BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
+
+ //same endpoint of a multicast face
+ BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"),
+ UdpFactory::Error, isTheSameMulticastEndpoint);
+
+ //same multicast endpoint, different group
+ BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.42", "20072"),
+ UdpFactory::Error, isLocalEndpointOnDifferentGroup);
+
+ BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "192.168.10.15", "20025"),
+ UdpFactory::Error, isNotMulticastAddress);
+
+
+// //Test commented because it required to be run in a machine that can resolve ipv6 query
+// shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1",
+// "fe80::5e96:9dff:fe7d:9c8d%en1",
+// //"fe80::aa54:b2ff:fe08:27b8%wlan0",
+// "20070");
+//
+// //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of
+// //an available network interface (different from the first one used)
+// shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17",
+// "224.0.0.1",
+// "20073");
+// BOOST_CHECK_NE(multicastFace1, multicastFace2);
+//
+//
+// //ipv6 - work in progress
+// shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1",
+// "FF01:0:0:0:0:0:0:2",
+// "20073");
+//
+// shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
+// "FF01:0:0:0:0:0:0:2",
+// "20073");
+//
+// BOOST_CHECK_EQUAL(multicastFace3, multicastFace4);
+//
+// shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1",
+// "FF01:0:0:0:0:0:0:2",
+// "20073");
+//
+// BOOST_CHECK_NE(multicastFace3, multicastFace5);
+//
+// //same local ipv6 endpoint for a different multicast group
+// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
+// "FE01:0:0:0:0:0:0:2",
+// "20073"),
+// UdpFactory::Error);
+//
+// //same local ipv6 (expect for th port number) endpoint for a different multicast group
+// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
+// "FE01:0:0:0:0:0:0:2",
+// "20075"),
+// UdpFactory::Error);
+//
+// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
+// "FE12:0:0:0:0:0:0:2",
+// "20075"),
+// UdpFactory::Error);
+//
+// //not a multicast ipv6
+// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
+// "A112:0:0:0:0:0:0:2",
+// "20075"),
+// UdpFactory::Error);
+}
+
+class FaceCreateFixture : protected BaseFixture
+{
+public:
+ void
+ checkError(const std::string& errorActual, const std::string& errorExpected)
+ {
+ BOOST_CHECK_EQUAL(errorActual, errorExpected);
+ }
+
+ void
+ failIfError(const std::string& errorActual)
+ {
+ BOOST_FAIL("No error expected, but got: [" << errorActual << "]");
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture)
+{
+ UdpFactory factory = UdpFactory();
+
+ factory.createFace(FaceUri("udp4://127.0.0.1:6363"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::checkError, this, _1,
+ "No channels available to connect to 127.0.0.1:6363"));
+
+ factory.createChannel("127.0.0.1", "20071");
+
+ factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::failIfError, this, _1));
+ //test the upgrade
+ factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::failIfError, this, _1));
+
+ factory.createFace(FaceUri("udp4://127.0.0.1:20072"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind(&FaceCreateFixture::failIfError, this, _1));
+}
+
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
+{
+ UdpFactory factory;
+
+ factory.createChannel("127.0.0.1", "20070");
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+}
+
+class FakeNetworkInterfaceFixture : public BaseFixture
+{
+public:
+ FakeNetworkInterfaceFixture()
+ {
+ using namespace boost::asio::ip;
+
+ auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
+
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {0, "eth0",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("0.0.0.0")},
+ {address_v6::from_string("::")},
+ address_v4(),
+ IFF_UP});
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {1, "eth0",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
+ {},
+ address_v4::from_string("192.168.2.255"),
+ 0});
+ fakeInterfaces->push_back(
+ NetworkInterfaceInfo {2, "eth1",
+ ethernet::Address::fromString("3e:15:c2:8b:65:00"),
+ {address_v4::from_string("198.51.100.1")},
+ {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
+ address_v4::from_string("198.51.100.255"),
+ IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
+
+ setDebugNetworkInterfaces(fakeInterfaces);
+ }
+
+ ~FakeNetworkInterfaceFixture()
+ {
+ setDebugNetworkInterfaces(nullptr);
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
+{
+ using namespace boost::asio::ip;
+
+ UdpFactory factory;
+ factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<udp::Endpoint> {
+ udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<udp::Endpoint> {
+ udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048),
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<udp::Endpoint> {
+ udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
+ udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
+ udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
+ udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024),
+ udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024),
+ udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
+ }));
+
+ factory.m_prohibitedEndpoints.clear();
+ factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048));
+ BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
+ BOOST_CHECK((factory.m_prohibitedEndpoints ==
+ std::set<udp::Endpoint> {
+ udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
+ udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
+ udp::Endpoint(address_v6::from_string("::"), 2048),
+ }));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/udp.t.cpp b/tests/daemon/face/udp.t.cpp
deleted file mode 100644
index d38c908..0000000
--- a/tests/daemon/face/udp.t.cpp
+++ /dev/null
@@ -1,704 +0,0 @@
-/* -*- 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/udp-channel.hpp"
-#include "face/udp-factory.hpp"
-
-#include "core/network-interface.hpp"
-#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
-#include "face-history.hpp"
-
-namespace nfd {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUdp, BaseFixture)
-
-using nfd::Face;
-
-BOOST_AUTO_TEST_CASE(GetChannels)
-{
- UdpFactory factory;
- BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
-
- std::vector<shared_ptr<const Channel>> expectedChannels;
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
- expectedChannels.push_back(factory.createChannel("::1", "20071"));
-
- for (const auto& i : factory.getChannels()) {
- auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i);
- BOOST_REQUIRE(pos != expectedChannels.end());
- expectedChannels.erase(pos);
- }
-
- BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
-}
-
-class FactoryErrorCheck : protected BaseFixture
-{
-public:
- bool
- isTheSameMulticastEndpoint(const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "Cannot create the requested UDP unicast channel, local "
- "endpoint is already allocated for a UDP multicast face") == 0;
- }
-
- bool
- isNotMulticastAddress(const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "Cannot create the requested UDP multicast face, "
- "the multicast group given as input is not a multicast address") == 0;
- }
-
- bool
- isTheSameUnicastEndpoint(const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP unicast channel") == 0;
- }
-
- bool
- isLocalEndpointOnDifferentGroup(const UdpFactory::Error& e) {
- return strcmp(e.what(),
- "Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP multicast face "
- "on a different multicast group") == 0;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck)
-{
- using boost::asio::ip::udp;
-
- UdpFactory factory = UdpFactory();
-
- //to instantiate multicast face on a specific ip address, change interfaceIp
- std::string interfaceIp = "0.0.0.0";
-
- shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
- shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
- BOOST_CHECK_EQUAL(channel1, channel1a);
- BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
-
- shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
- BOOST_CHECK_NE(channel1, channel2);
-
- shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070");
-
- shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071");
- BOOST_CHECK_NE(channel2, channel4);
- BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071");
-
- //same endpoint of a unicast channel
- BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.1", "20070"),
- UdpFactory::Error, isTheSameUnicastEndpoint);
-
- auto multicastFace1 = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
- auto multicastFace1a = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
- BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
- BOOST_CHECK_EQUAL(multicastFace1->isLocal(), false);
- BOOST_CHECK_EQUAL(multicastFace1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
- BOOST_CHECK_EQUAL(multicastFace1->isMultiAccess(), true);
-
- //same endpoint of a multicast face
- BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"),
- UdpFactory::Error, isTheSameMulticastEndpoint);
-
- //same multicast endpoint, different group
- BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.42", "20072"),
- UdpFactory::Error, isLocalEndpointOnDifferentGroup);
-
- BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "192.168.10.15", "20025"),
- UdpFactory::Error, isNotMulticastAddress);
-
-
-// //Test commented because it required to be run in a machine that can resolve ipv6 query
-// shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1",
-// "fe80::5e96:9dff:fe7d:9c8d%en1",
-// //"fe80::aa54:b2ff:fe08:27b8%wlan0",
-// "20070");
-//
-// //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of
-// //an available network interface (different from the first one used)
-// shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17",
-// "224.0.0.1",
-// "20073");
-// BOOST_CHECK_NE(multicastFace1, multicastFace2);
-//
-//
-// //ipv6 - work in progress
-// shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1",
-// "FF01:0:0:0:0:0:0:2",
-// "20073");
-//
-// shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
-// "FF01:0:0:0:0:0:0:2",
-// "20073");
-//
-// BOOST_CHECK_EQUAL(multicastFace3, multicastFace4);
-//
-// shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1",
-// "FF01:0:0:0:0:0:0:2",
-// "20073");
-//
-// BOOST_CHECK_NE(multicastFace3, multicastFace5);
-//
-// //same local ipv6 endpoint for a different multicast group
-// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
-// "FE01:0:0:0:0:0:0:2",
-// "20073"),
-// UdpFactory::Error);
-//
-// //same local ipv6 (expect for th port number) endpoint for a different multicast group
-// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
-// "FE01:0:0:0:0:0:0:2",
-// "20075"),
-// UdpFactory::Error);
-//
-// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
-// "FE12:0:0:0:0:0:0:2",
-// "20075"),
-// UdpFactory::Error);
-//
-// //not a multicast ipv6
-// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
-// "A112:0:0:0:0:0:0:2",
-// "20075"),
-// UdpFactory::Error);
-}
-
-class FaceCreateFixture : protected BaseFixture
-{
-public:
- void
- checkError(const std::string& errorActual, const std::string& errorExpected)
- {
- BOOST_CHECK_EQUAL(errorActual, errorExpected);
- }
-
- void
- failIfError(const std::string& errorActual)
- {
- BOOST_FAIL("No error expected, but got: [" << errorActual << "]");
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture)
-{
- UdpFactory factory = UdpFactory();
-
- factory.createFace(FaceUri("udp4://127.0.0.1:6363"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind(&FaceCreateFixture::checkError, this, _1,
- "No channels available to connect to 127.0.0.1:6363"));
-
- factory.createChannel("127.0.0.1", "20071");
-
- factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind(&FaceCreateFixture::failIfError, this, _1));
- //test the upgrade
- factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind(&FaceCreateFixture::failIfError, this, _1));
-
- factory.createFace(FaceUri("udp4://127.0.0.1:20072"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind(&FaceCreateFixture::failIfError, this, _1));
-}
-
-BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
-{
- UdpFactory factory;
-
- factory.createChannel("127.0.0.1", "20070");
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-}
-
-class EndToEndIpv4
-{
-public:
- static const std::string
- getScheme()
- {
- return "udp4";
- }
-
- static const std::string
- getLocalIp()
- {
- return "127.0.0.1";
- }
-
- static const std::string
- getPort1()
- {
- return "20071";
- }
-
- static const std::string
- getPort2()
- {
- return "20072";
- }
-
- static const std::string
- getPort3()
- {
- return "20073";
- }
-
- static const FaceUri
- getFaceUri1()
- {
- return FaceUri("udp4://127.0.0.1:20071");
- }
-
- static const FaceUri
- getFaceUri2()
- {
- return FaceUri("udp4://127.0.0.1:20072");
- }
-
- static const FaceUri
- getFaceUri3()
- {
- return FaceUri("udp4://127.0.0.1:20073");
- }
-};
-
-class EndToEndIpv6
-{
-public:
- static const std::string
- getScheme()
- {
- return "udp6";
- }
-
- static const std::string
- getLocalIp()
- {
- return "::1";
- }
-
- static const std::string
- getPort1()
- {
- return "20071";
- }
-
- static const std::string
- getPort2()
- {
- return "20072";
- }
-
- static const std::string
- getPort3()
- {
- return "20073";
- }
-
- static const FaceUri
- getFaceUri1()
- {
- return FaceUri("udp6://[::1]:20071");
- }
-
- static const FaceUri
- getFaceUri2()
- {
- return FaceUri("udp6://[::1]:20072");
- }
-
- static const FaceUri
- getFaceUri3()
- {
- return FaceUri("udp6://[::1]:20073");
- }
-};
-
-typedef boost::mpl::list<EndToEndIpv4, EndToEndIpv6> EndToEndAddresses;
-
-// end to end communication
-BOOST_AUTO_TEST_CASE_TEMPLATE(EndToEnd, A, EndToEndAddresses)
-{
- LimitedIo limitedIo;
- UdpFactory factory;
-
- shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1());
-
- // face1 (on channel1) connects to face2 (on channel2, to be created)
- shared_ptr<Face> face1;
- unique_ptr<FaceHistory> history1;
- factory.createFace(A::getFaceUri2(),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- [&] (shared_ptr<Face> newFace) {
- face1 = newFace;
- history1.reset(new FaceHistory(*face1, limitedIo));
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::seconds(1));
- BOOST_REQUIRE(face1 != nullptr);
- BOOST_CHECK_EQUAL(face1->getRemoteUri(), A::getFaceUri2());
- BOOST_CHECK_EQUAL(face1->getLocalUri(), A::getFaceUri1());
- BOOST_CHECK_EQUAL(face1->isLocal(), false); // UdpFace is never local
- BOOST_CHECK_EQUAL(face1->getCounters().nInBytes, 0);
- BOOST_CHECK_EQUAL(face1->getCounters().nOutBytes, 0);
-
- // channel2 creation must be after face1 creation,
- // otherwise channel2's endpoint would be prohibited
- shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2());
- shared_ptr<Face> face2;
- unique_ptr<FaceHistory> history2;
- channel2->listen([&] (shared_ptr<Face> newFace) {
- BOOST_CHECK(face2 == nullptr);
- face2 = newFace;
- history2.reset(new FaceHistory(*face2, limitedIo));
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::seconds(1));
- BOOST_CHECK(face2 == nullptr); // face2 shouldn't be created until face1 sends something
-
- shared_ptr<Interest> interest1 = makeInterest("/I1");
- shared_ptr<Interest> interest2 = makeInterest("/I2");
- shared_ptr<Data> data1 = makeData("/D1");
- shared_ptr<Data> data2 = makeData("/D2");
-
- // face1 sends to channel2, creates face2
- face1->sendInterest(*interest1);
- face1->sendData(*data1);
- face1->sendData(*data1);
- face1->sendData(*data1);
- size_t nBytesSent1 = interest1->wireEncode().size() + 3 * data1->wireEncode().size();
-
- limitedIo.run(5, time::seconds(1)); // 1 accept, 4 receives
-
- BOOST_REQUIRE(face2 != nullptr);
- BOOST_CHECK_EQUAL(face2->getRemoteUri(), A::getFaceUri1());
- BOOST_CHECK_EQUAL(face2->getLocalUri(), A::getFaceUri2());
- BOOST_CHECK_EQUAL(face2->isLocal(), false); // UdpFace is never local
- BOOST_CHECK_EQUAL(face2->getCounters().nInBytes, nBytesSent1);
- BOOST_CHECK_EQUAL(face2->getCounters().nOutBytes, 0);
-
- BOOST_REQUIRE_EQUAL(history2->receivedInterests.size(), 1);
- BOOST_CHECK_EQUAL(history2->receivedInterests.front().getName(), interest1->getName());
- BOOST_REQUIRE_EQUAL(history2->receivedData.size(), 3);
- BOOST_CHECK_EQUAL(history2->receivedData.front().getName(), data1->getName());
-
- // face2 sends to face1
- face2->sendInterest(*interest2);
- face2->sendInterest(*interest2);
- face2->sendInterest(*interest2);
- face2->sendData(*data2);
- size_t nBytesSent2 = 3 * interest2->wireEncode().size() + data2->wireEncode().size();
-
- limitedIo.run(4, time::seconds(1)); // 4 receives
-
- BOOST_REQUIRE_EQUAL(history1->receivedInterests.size(), 3);
- BOOST_CHECK_EQUAL(history1->receivedInterests.front().getName(), interest2->getName());
- BOOST_REQUIRE_EQUAL(history1->receivedData.size(), 1);
- BOOST_CHECK_EQUAL(history1->receivedData.front().getName(), data2->getName());
-
- // counters
- const face::FaceCounters& counters1 = face1->getCounters();
- BOOST_CHECK_EQUAL(counters1.nInInterests, 3);
- BOOST_CHECK_EQUAL(counters1.nInData, 1);
- BOOST_CHECK_EQUAL(counters1.nOutInterests, 1);
- BOOST_CHECK_EQUAL(counters1.nOutData, 3);
- BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2);
- BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1);
-
- const face::FaceCounters& counters2 = face2->getCounters();
- BOOST_CHECK_EQUAL(counters2.nInInterests, 1);
- BOOST_CHECK_EQUAL(counters2.nInData, 3);
- BOOST_CHECK_EQUAL(counters2.nOutInterests, 3);
- BOOST_CHECK_EQUAL(counters2.nOutData, 1);
- BOOST_CHECK_EQUAL(counters2.nInBytes, nBytesSent1);
- BOOST_CHECK_EQUAL(counters2.nOutBytes, nBytesSent2);
-}
-
-// channel accepting multiple incoming connections
-BOOST_AUTO_TEST_CASE_TEMPLATE(MultipleAccepts, A, EndToEndAddresses)
-{
- LimitedIo limitedIo;
- UdpFactory factory;
-
- // channel1 is listening
- shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1());
- std::vector<shared_ptr<Face>> faces1;
- channel1->listen([&] (shared_ptr<Face> newFace) {
- faces1.push_back(newFace);
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- // face2 (on channel2) connects to channel1
- shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2());
- BOOST_CHECK_NE(channel1, channel2);
- shared_ptr<Face> face2;
- boost::asio::ip::address ipAddress2 = boost::asio::ip::address::from_string(A::getLocalIp());
- udp::Endpoint endpoint2(ipAddress2, boost::lexical_cast<uint16_t>(A::getPort1()));
- channel2->connect(endpoint2,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- [&] (shared_ptr<Face> newFace) {
- face2 = newFace;
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::seconds(1)); // 1 create (on channel2)
- BOOST_REQUIRE(face2 != nullptr);
- BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face2 sends something
-
- // face3 (on channel3) connects to channel1
- shared_ptr<UdpChannel> channel3 = factory.createChannel(A::getLocalIp(), A::getPort3());
- BOOST_CHECK_NE(channel1, channel3);
- shared_ptr<Face> face3;
- boost::asio::ip::address ipAddress3 = boost::asio::ip::address::from_string(A::getLocalIp());
- udp::Endpoint endpoint3(ipAddress3, boost::lexical_cast<uint16_t>(A::getPort1()));
- channel3->connect(endpoint3,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- [&] (shared_ptr<Face> newFace) {
- face3 = newFace;
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::seconds(1)); // 1 create (on channel3)
- BOOST_REQUIRE(face3 != nullptr);
- BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face3 sends something
-
- // face2 sends to channel1
- shared_ptr<Interest> interest2 = makeInterest("/I2");
- face2->sendInterest(*interest2);
- limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1)
- BOOST_REQUIRE_EQUAL(faces1.size(), 1);
- BOOST_CHECK_EQUAL(channel1->size(), 1);
- BOOST_CHECK_EQUAL(faces1.at(0)->getRemoteUri(), A::getFaceUri2());
-
- // face3 sends to channel1
- shared_ptr<Data> data3 = makeData("/D3");
- face3->sendData(*data3);
- limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1)
- BOOST_REQUIRE_EQUAL(faces1.size(), 2);
- BOOST_CHECK_EQUAL(channel1->size(), 2);
- BOOST_CHECK_EQUAL(faces1.at(1)->getRemoteUri(), A::getFaceUri3());
-}
-
-// manually close a face
-BOOST_AUTO_TEST_CASE_TEMPLATE(ManualClose, A, EndToEndAddresses)
-{
- LimitedIo limitedIo;
- UdpFactory factory;
-
- shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1());
- shared_ptr<Face> face1;
- unique_ptr<FaceHistory> history1;
- factory.createFace(A::getFaceUri2(),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- [&] (shared_ptr<Face> newFace) {
- face1 = newFace;
- history1.reset(new FaceHistory(*face1, limitedIo));
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::milliseconds(100));
- BOOST_REQUIRE(face1 != nullptr);
- BOOST_CHECK_EQUAL(channel1->size(), 1);
-
- face1->close();
- getGlobalIoService().poll();
- BOOST_CHECK_EQUAL(history1->failures.size(), 1);
- BOOST_CHECK_EQUAL(channel1->size(), 0);
-}
-
-// automatically close an idle incoming face
-BOOST_AUTO_TEST_CASE_TEMPLATE(IdleClose, A, EndToEndAddresses)
-{
- LimitedIo limitedIo;
- UdpFactory factory;
-
- // channel1 is listening
- shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1(),
- time::seconds(2));
- shared_ptr<Face> face1;
- unique_ptr<FaceHistory> history1;
- channel1->listen([&] (shared_ptr<Face> newFace) {
- BOOST_CHECK(face1 == nullptr);
- face1 = newFace;
- history1.reset(new FaceHistory(*face1, limitedIo));
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- // face2 (on channel2) connects to channel1
- shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2(),
- time::seconds(2));
- shared_ptr<Face> face2;
- unique_ptr<FaceHistory> history2;
- boost::asio::ip::address ipAddress = boost::asio::ip::address::from_string(A::getLocalIp());
- udp::Endpoint endpoint(ipAddress, boost::lexical_cast<uint16_t>(A::getPort1()));
- channel2->connect(endpoint,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- [&] (shared_ptr<Face> newFace) {
- face2 = newFace;
- history2.reset(new FaceHistory(*face2, limitedIo));
- limitedIo.afterOp();
- },
- [] (const std::string& reason) { BOOST_ERROR(reason); });
-
- limitedIo.run(1, time::milliseconds(100)); // 1 create (on channel2)
- BOOST_REQUIRE(face2 != nullptr);
- BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
- BOOST_CHECK_EQUAL(face2->isMultiAccess(), false);
-
- // face2 sends to channel1, creates face1
- shared_ptr<Interest> interest2 = makeInterest("/I2");
- face2->sendInterest(*interest2);
-
- limitedIo.run(2, time::seconds(1)); // 1 accept (on channel1), 1 receive (on face1)
- BOOST_CHECK_EQUAL(channel1->size(), 1);
- BOOST_REQUIRE(face1 != nullptr);
- BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
- BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
-
- limitedIo.defer(time::seconds(1));
- BOOST_CHECK_EQUAL(history1->failures.size(), 0); // face1 is not idle
- BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed
-
- limitedIo.defer(time::seconds(4));
- BOOST_CHECK_EQUAL(history1->failures.size(), 1); // face1 is idle and automatically closed
- BOOST_CHECK_EQUAL(channel1->size(), 0);
- BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed
-}
-
-class FakeNetworkInterfaceFixture : public BaseFixture
-{
-public:
- FakeNetworkInterfaceFixture()
- {
- using namespace boost::asio::ip;
-
- auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
-
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {0, "eth0",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("0.0.0.0")},
- {address_v6::from_string("::")},
- address_v4(),
- IFF_UP});
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {1, "eth0",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
- {},
- address_v4::from_string("192.168.2.255"),
- 0});
- fakeInterfaces->push_back(
- NetworkInterfaceInfo {2, "eth1",
- ethernet::Address::fromString("3e:15:c2:8b:65:00"),
- {address_v4::from_string("198.51.100.1")},
- {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
- address_v4::from_string("198.51.100.255"),
- IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
-
- setDebugNetworkInterfaces(fakeInterfaces);
- }
-
- ~FakeNetworkInterfaceFixture()
- {
- setDebugNetworkInterfaces(nullptr);
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
-{
- using namespace boost::asio::ip;
-
- UdpFactory factory;
- factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<udp::Endpoint> {
- udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<udp::Endpoint> {
- udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048),
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<udp::Endpoint> {
- udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
- udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
- udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
- udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024),
- udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024),
- udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
- }));
-
- factory.m_prohibitedEndpoints.clear();
- factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048));
- BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
- BOOST_CHECK((factory.m_prohibitedEndpoints ==
- std::set<udp::Endpoint> {
- udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
- udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
- udp::Endpoint(address_v6::from_string("::"), 2048),
- }));
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestUdp
-BOOST_AUTO_TEST_SUITE_END() // Face
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/face/unicast-udp-transport-fixture.hpp b/tests/daemon/face/unicast-udp-transport-fixture.hpp
index 6dd836a..1ec37b0 100644
--- a/tests/daemon/face/unicast-udp-transport-fixture.hpp
+++ b/tests/daemon/face/unicast-udp-transport-fixture.hpp
@@ -27,7 +27,7 @@
#define NFD_TESTS_DAEMON_FACE_UNICAST_UDP_TRANSPORT_FIXTURE_HPP
#include "face/unicast-udp-transport.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
@@ -60,9 +60,9 @@
remoteConnect(address);
- face = make_unique<LpFace>(make_unique<DummyReceiveLinkService>(),
- make_unique<UnicastUdpTransport>(std::move(sock), persistency,
- time::seconds(3)));
+ face = make_unique<Face>(
+ make_unique<DummyReceiveLinkService>(),
+ make_unique<UnicastUdpTransport>(std::move(sock), persistency, time::seconds(3)));
transport = static_cast<UnicastUdpTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
@@ -99,7 +99,7 @@
std::vector<Transport::Packet>* receivedPackets;
private:
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
};
} // namespace tests
diff --git a/tests/daemon/face/unix-stream-channel.t.cpp b/tests/daemon/face/unix-stream-channel.t.cpp
new file mode 100644
index 0000000..86caa8d
--- /dev/null
+++ b/tests/daemon/face/unix-stream-channel.t.cpp
@@ -0,0 +1,45 @@
+/* -*- 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/unix-stream-channel.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUnixStreamChannel, BaseFixture)
+
+// TODO add the equivalent of these test cases from unix-stream.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c
+// MultipleAccepts
+
+// TODO add a test case to check a failed face is removed from the channel
+
+BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamChannel
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/unix-stream-factory.t.cpp b/tests/daemon/face/unix-stream-factory.t.cpp
new file mode 100644
index 0000000..2be2536
--- /dev/null
+++ b/tests/daemon/face/unix-stream-factory.t.cpp
@@ -0,0 +1,103 @@
+/* -*- 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/unix-stream-factory.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+
+namespace nfd {
+namespace tests {
+
+#define CHANNEL_PATH1 "unix-stream-test.1.sock"
+#define CHANNEL_PATH2 "unix-stream-test.2.sock"
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, BaseFixture)
+
+using nfd::Face;
+
+BOOST_AUTO_TEST_CASE(ChannelMap)
+{
+ UnixStreamFactory factory;
+
+ shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
+ shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
+ BOOST_CHECK_EQUAL(channel1, channel1a);
+ std::string channel1uri = channel1->getUri().toString();
+ BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
+ BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
+ channel1uri.size() - std::string(CHANNEL_PATH1).size());
+
+ shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
+ BOOST_CHECK_NE(channel1, channel2);
+}
+
+BOOST_AUTO_TEST_CASE(GetChannels)
+{
+ UnixStreamFactory factory;
+ BOOST_CHECK(factory.getChannels().empty());
+
+ std::vector<shared_ptr<const Channel>> expectedChannels;
+ expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1));
+ expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2));
+
+ for (const auto& channel : factory.getChannels()) {
+ auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel);
+ BOOST_REQUIRE(pos != expectedChannels.end());
+ expectedChannels.erase(pos);
+ }
+
+ BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
+{
+ UnixStreamFactory factory;
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/unix-stream-transport-fixture.hpp b/tests/daemon/face/unix-stream-transport-fixture.hpp
index 38c9b5f..0101f10 100644
--- a/tests/daemon/face/unix-stream-transport-fixture.hpp
+++ b/tests/daemon/face/unix-stream-transport-fixture.hpp
@@ -27,7 +27,7 @@
#define NFD_TESTS_DAEMON_FACE_UNIX_STREAM_TRANSPORT_FIXTURE_HPP
#include "face/unix-stream-transport.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
@@ -105,8 +105,8 @@
BOOST_REQUIRE_EQUAL(limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS);
localEp = sock.local_endpoint();
- face = make_unique<LpFace>(make_unique<DummyReceiveLinkService>(),
- make_unique<UnixStreamTransport>(std::move(sock)));
+ face = make_unique<Face>(make_unique<DummyReceiveLinkService>(),
+ make_unique<UnixStreamTransport>(std::move(sock)));
transport = static_cast<UnixStreamTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
@@ -134,7 +134,7 @@
private:
AcceptorWithCleanup acceptor;
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
};
} // namespace tests
diff --git a/tests/daemon/face/unix-stream.t.cpp b/tests/daemon/face/unix-stream.t.cpp
deleted file mode 100644
index fc528c2..0000000
--- a/tests/daemon/face/unix-stream.t.cpp
+++ /dev/null
@@ -1,347 +0,0 @@
-/* -*- 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/unix-stream-channel.hpp"
-#include "face/unix-stream-factory.hpp"
-#include "face/unix-stream-transport.hpp"
-
-#include "face/generic-link-service.hpp"
-#include "face/lp-face-wrapper.hpp"
-
-#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
-#include "dummy-stream-sender.hpp"
-#include "packet-datasets.hpp"
-
-namespace nfd {
-namespace tests {
-
-#define CHANNEL_PATH1 "unix-stream-test.1.sock"
-#define CHANNEL_PATH2 "unix-stream-test.2.sock"
-
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUnixStream, BaseFixture)
-
-using nfd::Face;
-using face::LpFaceWrapper;
-using face::UnixStreamTransport;
-
-BOOST_AUTO_TEST_CASE(ChannelMap)
-{
- UnixStreamFactory factory;
-
- shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
- shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
- BOOST_CHECK_EQUAL(channel1, channel1a);
- std::string channel1uri = channel1->getUri().toString();
- BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
- BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
- channel1uri.size() - std::string(CHANNEL_PATH1).size());
-
- shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
- BOOST_CHECK_NE(channel1, channel2);
-}
-
-BOOST_AUTO_TEST_CASE(GetChannels)
-{
- UnixStreamFactory factory;
- BOOST_CHECK(factory.getChannels().empty());
-
- std::vector<shared_ptr<const Channel>> expectedChannels;
- expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1));
- expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2));
-
- for (const auto& channel : factory.getChannels()) {
- auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel);
- BOOST_REQUIRE(pos != expectedChannels.end());
- expectedChannels.erase(pos);
- }
-
- BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
-}
-
-BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
-{
- UnixStreamFactory factory;
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
- ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-}
-
-class EndToEndFixture : protected BaseFixture
-{
-public:
- void
- client_onConnect(const boost::system::error_code& error)
- {
- BOOST_CHECK_MESSAGE(!error, error.message());
-
- limitedIo.afterOp();
- }
-
- void
- channel1_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- BOOST_CHECK(!static_cast<bool>(face1));
- face1 = static_pointer_cast<LpFaceWrapper>(newFace);
- face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
- face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
-
- limitedIo.afterOp();
- }
-
- void
- channel1_onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveInterest(const Interest& interest)
- {
- face1_receivedInterests.push_back(interest);
-
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveData(const Data& data)
- {
- face1_receivedDatas.push_back(data);
-
- limitedIo.afterOp();
- }
-
- void
- face2_onReceiveInterest(const Interest& interest)
- {
- face2_receivedInterests.push_back(interest);
-
- limitedIo.afterOp();
- }
-
- void
- face2_onReceiveData(const Data& data)
- {
- face2_receivedDatas.push_back(data);
-
- limitedIo.afterOp();
- }
-
- void
- channel_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- faces.push_back(static_pointer_cast<LpFaceWrapper>(newFace));
-
- limitedIo.afterOp();
- }
-
- void
- channel_onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
-
- limitedIo.afterOp();
- }
-
- shared_ptr<LpFaceWrapper>
- makeFace(UnixStreamTransport::protocol::socket&& socket)
- {
- auto linkService = make_unique<face::GenericLinkService>();
- auto transport = make_unique<UnixStreamTransport>(std::move(socket));
- auto lpFace = make_unique<LpFace>(std::move(linkService), std::move(transport));
- return make_shared<LpFaceWrapper>(std::move(lpFace));
- }
-
-protected:
- LimitedIo limitedIo;
-
- shared_ptr<LpFaceWrapper> face1;
- std::vector<Interest> face1_receivedInterests;
- std::vector<Data> face1_receivedDatas;
- shared_ptr<LpFaceWrapper> face2;
- std::vector<Interest> face2_receivedInterests;
- std::vector<Data> face2_receivedDatas;
-
- std::list<shared_ptr<LpFaceWrapper>> faces;
-};
-
-
-BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
-{
- UnixStreamFactory factory;
-
- shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
- UnixStreamTransport::protocol::socket client(g_io);
- client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
- bind(&EndToEndFixture::client_onConnect, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_CHECK_EQUAL(face1->isLocal(), true);
- BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
- BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
- BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd");
- BOOST_CHECK_NO_THROW(std::stoi(face1->getRemoteUri().getHost()));
- std::string face1localUri = face1->getLocalUri().toString();
- BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator
- BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1),
- face1localUri.size() - std::string(CHANNEL_PATH1).size());
-
- face2 = makeFace(std::move(client));
- face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
- face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- face1->sendInterest(*interest1);
- face1->sendInterest(*interest1);
- face1->sendInterest(*interest1);
- face1->sendData (*data1 );
- size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size();
- face2->sendInterest(*interest2);
- face2->sendData (*data2 );
- face2->sendData (*data2 );
- face2->sendData (*data2 );
- size_t nBytesSent2 = interest2->wireEncode().size() + data2->wireEncode().size() * 3;
-
- BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive");
-
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
- BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
- BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
-
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
- BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
- BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
-
- // needed to ensure NOutBytes counters are accurate
- limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1));
-
- const face::FaceCounters& counters1 = face1->getCounters();
- BOOST_CHECK_EQUAL(counters1.nInInterests, 1);
- BOOST_CHECK_EQUAL(counters1.nInData, 3);
- BOOST_CHECK_EQUAL(counters1.nOutInterests, 3);
- BOOST_CHECK_EQUAL(counters1.nOutData, 1);
- BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2);
- BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1);
-
- const face::FaceCounters& counters2 = face2->getCounters();
- BOOST_CHECK_EQUAL(counters2.nInInterests, 3);
- BOOST_CHECK_EQUAL(counters2.nInData, 1);
- BOOST_CHECK_EQUAL(counters2.nOutInterests, 1);
- BOOST_CHECK_EQUAL(counters2.nOutData, 3);
-}
-
-BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
-{
- UnixStreamFactory factory;
-
- shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
- channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
-
- UnixStreamTransport::protocol::socket client1(g_io);
- client1.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
- bind(&EndToEndFixture::client_onConnect, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "First connect");
-
- BOOST_CHECK_EQUAL(faces.size(), 1);
-
- UnixStreamTransport::protocol::socket client2(g_io);
- client2.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
- bind(&EndToEndFixture::client_onConnect, this, _1));
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Second connect");
-
- BOOST_CHECK_EQUAL(faces.size(), 2);
-
- // now close one of the faces
- faces.front()->close();
-
- // we should still be able to send/receive with the other one
- face1 = faces.back();
- face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
- face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
-
- face2 = makeFace(std::move(client2));
- face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
- face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- face1->sendInterest(*interest1);
- face1->sendData (*data1 );
- face2->sendInterest(*interest2);
- face2->sendData (*data2 );
-
- BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive");
-
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
- BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
-
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
- BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
- BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestUnixStream
-BOOST_AUTO_TEST_SUITE_END() // Face
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/face/websocket-channel.t.cpp b/tests/daemon/face/websocket-channel.t.cpp
new file mode 100644
index 0000000..9e10239
--- /dev/null
+++ b/tests/daemon/face/websocket-channel.t.cpp
@@ -0,0 +1,44 @@
+/* -*- 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/websocket-channel.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestWebSocketChannel, BaseFixture)
+
+// TODO add a test case to accept multiple incoming connections on a channel
+
+// TODO add a test case to check a failed face is removed from the channel
+
+BOOST_AUTO_TEST_SUITE_END() // TestWebSocketChannel
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/websocket-factory.t.cpp b/tests/daemon/face/websocket-factory.t.cpp
new file mode 100644
index 0000000..9e469e8
--- /dev/null
+++ b/tests/daemon/face/websocket-factory.t.cpp
@@ -0,0 +1,85 @@
+/* -*- 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/websocket-factory.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, BaseFixture)
+
+using nfd::Face;
+
+BOOST_AUTO_TEST_CASE(GetChannels)
+{
+ WebSocketFactory factory;
+ BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
+
+ std::vector<shared_ptr<const Channel>> expectedChannels;
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
+ expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
+ expectedChannels.push_back(factory.createChannel("::1", "20071"));
+
+ for (const auto& i : factory.getChannels()) {
+ auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i);
+ BOOST_REQUIRE(pos != expectedChannels.end());
+ expectedChannels.erase(pos);
+ }
+
+ BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
+{
+ WebSocketFactory factory;
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERMANENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+
+ BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ bind([]{}),
+ bind([]{})),
+ ProtocolFactory::Error);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestWebSocketFactory
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/websocket-transport.t.cpp b/tests/daemon/face/websocket-transport.t.cpp
index ca9bd72..edee799 100644
--- a/tests/daemon/face/websocket-transport.t.cpp
+++ b/tests/daemon/face/websocket-transport.t.cpp
@@ -24,7 +24,7 @@
*/
#include "face/websocket-transport.hpp"
-#include "face/lp-face.hpp"
+#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "transport-test-common.hpp"
@@ -39,6 +39,8 @@
BOOST_AUTO_TEST_SUITE(Face)
+using nfd::Face;
+
/** \brief a fixture that accepts a single WebSocket connection from a client
*/
class SingleWebSocketFixture : public BaseFixture
@@ -97,7 +99,7 @@
void
makeFace(const time::milliseconds& pingInterval = time::milliseconds(10000))
{
- face = make_unique<LpFace>(
+ face = make_unique<Face>(
make_unique<DummyReceiveLinkService>(),
make_unique<WebSocketTransport>(serverHdl, ref(server), pingInterval));
transport = static_cast<WebSocketTransport*>(face->getTransport());
@@ -197,7 +199,7 @@
websocket::Server server;
websocketpp::connection_hdl serverHdl;
- unique_ptr<LpFace> face;
+ unique_ptr<Face> face;
WebSocketTransport* transport;
std::vector<Transport::Packet>* serverReceivedPackets;
diff --git a/tests/daemon/face/websocket.t.cpp b/tests/daemon/face/websocket.t.cpp
deleted file mode 100644
index 3811635..0000000
--- a/tests/daemon/face/websocket.t.cpp
+++ /dev/null
@@ -1,306 +0,0 @@
-/* -*- 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/websocket-channel.hpp"
-#include "face/websocket-factory.hpp"
-#include "face/websocketpp.hpp"
-
-#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
-
-namespace nfd {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestWebSocket, BaseFixture)
-
-using nfd::Face;
-
-BOOST_AUTO_TEST_CASE(GetChannels)
-{
- WebSocketFactory factory;
- BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
-
- std::vector<shared_ptr<const Channel>> expectedChannels;
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
- expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
- expectedChannels.push_back(factory.createChannel("::1", "20071"));
-
- for (const auto& i : factory.getChannels()) {
- auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i);
- BOOST_REQUIRE(pos != expectedChannels.end());
- expectedChannels.erase(pos);
- }
-
- BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
-}
-
-BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
-{
- WebSocketFactory factory;
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERMANENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-
- BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"),
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- bind([]{}),
- bind([]{})),
- ProtocolFactory::Error);
-}
-
-class EndToEndFixture : protected BaseFixture
-{
-public:
- void
- channel1_onFaceCreated(const shared_ptr<Face>& newFace)
- {
- BOOST_CHECK(!static_cast<bool>(face1));
- face1 = newFace;
- face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
- face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
- face1->onFail.connect(bind(&EndToEndFixture::face1_onFail, this));
-
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveInterest(const Interest& interest)
- {
- face1_receivedInterests.push_back(interest);
- limitedIo.afterOp();
- }
-
- void
- face1_onReceiveData(const Data& data)
- {
- face1_receivedDatas.push_back(data);
- limitedIo.afterOp();
- }
-
- void
- face1_onFail()
- {
- g_io.post([this] {
- face1.reset();
- limitedIo.afterOp();
- });
- }
-
- void
- client1_onOpen(websocketpp::connection_hdl hdl)
- {
- handle = hdl;
- limitedIo.afterOp();
- }
-
- void
- client1_onClose(websocketpp::connection_hdl hdl)
- {
- limitedIo.afterOp();
- }
-
- void
- client1_onFail(websocketpp::connection_hdl hdl)
- {
- limitedIo.afterOp();
- }
-
- bool
- client1_onPing(websocketpp::connection_hdl hdl, std::string msg)
- {
- limitedIo.afterOp();
- // Return false to suppress the pong response,
- // which will cause timeout in the websocket channel
- return false;
- }
-
- void
- client1_sendInterest(const Interest& interest)
- {
- const Block& payload = interest.wireEncode();
- client1.send(handle, payload.wire(), payload.size(), websocketpp::frame::opcode::binary);
- }
-
- void
- client1_sendData(const Data& data)
- {
- const Block& payload = data.wireEncode();
- client1.send(handle, payload.wire(), payload.size(), websocketpp::frame::opcode::binary);
- }
-
- void
- client1_onMessage(websocketpp::connection_hdl hdl,
- websocketpp::config::asio_client::message_type::ptr msg)
- {
- bool isOk = false;
- Block element;
- const std::string& payload = msg->get_payload();
- std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(payload.c_str()),
- payload.size());
- if (isOk)
- {
- try {
- if (element.type() == tlv::Interest)
- {
- shared_ptr<Interest> i = make_shared<Interest>();
- i->wireDecode(element);
- client1_onReceiveInterest(*i);
- }
- else if (element.type() == tlv::Data)
- {
- shared_ptr<Data> d = make_shared<Data>();
- d->wireDecode(element);
- client1_onReceiveData(*d);
- }
- }
- catch (tlv::Error&) {
- // Do something?
- }
- }
- limitedIo.afterOp();
- }
-
- void
- client1_onReceiveInterest(const Interest& interest)
- {
- client1_receivedInterests.push_back(interest);
- limitedIo.afterOp();
- }
-
- void
- client1_onReceiveData(const Data& data)
- {
- client1_receivedDatas.push_back(data);
- limitedIo.afterOp();
- }
-
-public:
- LimitedIo limitedIo;
-
- shared_ptr<Face> face1;
- std::vector<Interest> face1_receivedInterests;
- std::vector<Data> face1_receivedDatas;
- websocket::Client client1;
- websocketpp::connection_hdl handle;
- std::vector<Interest> client1_receivedInterests;
- std::vector<Data> client1_receivedDatas;
-};
-
-BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
-{
- WebSocketFactory factory1;
-
- shared_ptr<WebSocketChannel> channel1 = factory1.createChannel("127.0.0.1", "20070");
- channel1->setPingInterval(time::milliseconds(3000));
- channel1->setPongTimeout(time::milliseconds(1000));
-
- BOOST_CHECK_EQUAL(channel1->isListening(), false);
-
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1));
-
- BOOST_CHECK_EQUAL(channel1->isListening(), true);
-
- // Clear all logging info from websocketpp library
- client1.clear_access_channels(websocketpp::log::alevel::all);
-
- client1.init_asio(&getGlobalIoService());
- client1.set_open_handler(bind(&EndToEndFixture::client1_onOpen, this, _1));
- client1.set_close_handler(bind(&EndToEndFixture::client1_onClose, this, _1));
- client1.set_fail_handler(bind(&EndToEndFixture::client1_onFail, this, _1));
- client1.set_message_handler(bind(&EndToEndFixture::client1_onMessage, this, _1, _2));
- client1.set_ping_handler(bind(&EndToEndFixture::client1_onPing, this, _1, _2));
-
- websocketpp::lib::error_code ec;
- auto con = client1.get_connection("ws://127.0.0.1:20070", ec);
- client1.connect(con);
-
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "WebSocketChannel error: cannot connect or cannot accept connection");
-
- BOOST_CHECK_EQUAL(channel1->size(), 1);
-
- BOOST_REQUIRE(static_cast<bool>(face1));
- BOOST_CHECK_EQUAL(face1->isLocal(), true);
- BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
- BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
- BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "ws://127.0.0.1:20070");
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
- shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
-
- client1_sendInterest(*interest1);
- client1_sendInterest(*interest1);
- client1_sendInterest(*interest1);
- face1->sendData (*data1);
- face1->sendInterest (*interest2);
- client1_sendData (*data2);
- client1_sendData (*data2);
- client1_sendData (*data2);
-
- size_t nBytesSent = data1->wireEncode().size() + interest2->wireEncode().size();
- size_t nBytesReceived = interest1->wireEncode().size() * 3 + data2->wireEncode().size() * 3;
-
- BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(10)) == LimitedIo::EXCEED_OPS,
- "WebSocketChannel error: cannot send or receive Interest/Data packets");
-
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 3);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
- BOOST_REQUIRE_EQUAL(client1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(client1_receivedDatas .size(), 1);
-
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest1->getName());
- BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
- BOOST_CHECK_EQUAL(client1_receivedInterests[0].getName(), interest2->getName());
- BOOST_CHECK_EQUAL(client1_receivedDatas [0].getName(), data1->getName());
-
- const face::FaceCounters& counters1 = face1->getCounters();
- BOOST_CHECK_EQUAL(counters1.nInInterests, 3);
- BOOST_CHECK_EQUAL(counters1.nInData, 3);
- BOOST_CHECK_EQUAL(counters1.nOutInterests, 1);
- BOOST_CHECK_EQUAL(counters1.nOutData, 1);
- BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesReceived);
- BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent);
-
- limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(8));
- BOOST_CHECK_EQUAL(channel1->size(), 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestWebSocket
-BOOST_AUTO_TEST_SUITE_END() // Face
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp
index 8f0870b..e180ec9 100644
--- a/tests/daemon/fw/client-control-strategy.t.cpp
+++ b/tests/daemon/fw/client-control-strategy.t.cpp
@@ -44,10 +44,10 @@
typedef StrategyTester<fw::ClientControlStrategy> ClientControlStrategyTester;
ClientControlStrategyTester strategy(forwarder);
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
- shared_ptr<DummyLocalFace> face4 = make_shared<DummyLocalFace>();
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>();
+ auto face4 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
diff --git a/tests/daemon/fw/face-table.t.cpp b/tests/daemon/fw/face-table.t.cpp
index 6610034..59bb7c8 100644
--- a/tests/daemon/fw/face-table.t.cpp
+++ b/tests/daemon/fw/face-table.t.cpp
@@ -32,52 +32,49 @@
namespace nfd {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(FwFaceTable, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestFaceTable, BaseFixture)
BOOST_AUTO_TEST_CASE(AddRemove)
{
Forwarder forwarder;
FaceTable& faceTable = forwarder.getFaceTable();
- std::vector<FaceId> onAddHistory;
- std::vector<FaceId> onRemoveHistory;
- faceTable.onAdd.connect([&] (shared_ptr<Face> face) {
- onAddHistory.push_back(face->getId());
- });
- faceTable.onRemove.connect([&] (shared_ptr<Face> face) {
- onRemoveHistory.push_back(face->getId());
- });
+ std::vector<FaceId> addHistory;
+ std::vector<FaceId> removeHistory;
+ faceTable.afterAdd.connect([&] (shared_ptr<Face> face) { addHistory.push_back(face->getId()); });
+ faceTable.beforeRemove.connect([&] (shared_ptr<Face> face) { removeHistory.push_back(face->getId()); });
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);
+ BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face2->getId(), face::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(), face::INVALID_FACEID);
+ BOOST_CHECK_NE(face2->getId(), face::INVALID_FACEID);
BOOST_CHECK_NE(face1->getId(), face2->getId());
- BOOST_CHECK_GT(face1->getId(), FACEID_RESERVED_MAX);
- BOOST_CHECK_GT(face2->getId(), FACEID_RESERVED_MAX);
+ BOOST_CHECK_GT(face1->getId(), face::FACEID_RESERVED_MAX);
+ BOOST_CHECK_GT(face2->getId(), face::FACEID_RESERVED_MAX);
FaceId oldId1 = face1->getId();
faceTable.add(face1);
BOOST_CHECK_EQUAL(face1->getId(), oldId1);
BOOST_CHECK_EQUAL(faceTable.size(), 2);
- BOOST_REQUIRE_EQUAL(onAddHistory.size(), 2);
- BOOST_CHECK_EQUAL(onAddHistory[0], face1->getId());
- BOOST_CHECK_EQUAL(onAddHistory[1], face2->getId());
+ BOOST_REQUIRE_EQUAL(addHistory.size(), 2);
+ BOOST_CHECK_EQUAL(addHistory[0], face1->getId());
+ BOOST_CHECK_EQUAL(addHistory[1], face2->getId());
face1->close();
- BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID);
- BOOST_REQUIRE_EQUAL(onRemoveHistory.size(), 1);
- BOOST_CHECK_EQUAL(onRemoveHistory[0], onAddHistory[0]);
+ BOOST_REQUIRE_EQUAL(removeHistory.size(), 1);
+ BOOST_CHECK_EQUAL(removeHistory[0], addHistory[0]);
}
BOOST_AUTO_TEST_CASE(AddReserved)
@@ -86,7 +83,7 @@
FaceTable& faceTable = forwarder.getFaceTable();
shared_ptr<Face> face1 = make_shared<DummyFace>();
- BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID);
faceTable.addReserved(face1, 5);
BOOST_CHECK_EQUAL(face1->getId(), 5);
@@ -146,7 +143,8 @@
BOOST_CHECK(hasFace2);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestFaceTable
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace nfd
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index 67bce49..cfa5f71 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -25,8 +25,6 @@
#include "fw/forwarder.hpp"
#include "tests/daemon/face/dummy-face.hpp"
-#include "tests/daemon/face/dummy-lp-face.hpp"
-#include "face/lp-face-wrapper.hpp"
#include "dummy-strategy.hpp"
#include "tests/test-common.hpp"
@@ -51,10 +49,10 @@
interestAB->setInterestLifetime(time::seconds(4));
shared_ptr<Data> dataABC = makeData(nameABC);
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- face1->afterSend.connect(afterOp);
- face2->afterSend.connect(afterOp);
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ face1->afterSend.connect(bind(afterOp));
+ face2->afterSend.connect(bind(afterOp));
forwarder.addFace(face1);
forwarder.addFace(face2);
@@ -66,10 +64,10 @@
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0);
g_io.post([&] { face1->receiveInterest(*interestAB); });
BOOST_CHECK_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
- BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1);
- BOOST_CHECK_EQUAL(face2->m_sentInterests[0].getName(), nameAB);
- BOOST_REQUIRE(face2->m_sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
- BOOST_CHECK_EQUAL(*face2->m_sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId());
+ BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), nameAB);
+ BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
+ 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);
@@ -77,10 +75,10 @@
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0);
g_io.post([&] { face2->receiveData(*dataABC); });
BOOST_CHECK_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
- BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
- BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getName(), nameABC);
- BOOST_REQUIRE(face1->m_sentDatas[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
- BOOST_CHECK_EQUAL(*face1->m_sentDatas[0].getTag<lp::IncomingFaceIdTag>(), face2->getId());
+ BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentData[0].getName(), nameABC);
+ BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
+ BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId());
BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1);
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 1);
}
@@ -90,9 +88,9 @@
LimitedIo limitedIo;
Forwarder forwarder;
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>();
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
@@ -115,12 +113,12 @@
face1->receiveInterest(*interestA);
limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
// Interest matching ContentStore should not be forwarded
- BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 0);
+ BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0);
- BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
+ BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
// IncomingFaceId field should be reset to represent CS
- BOOST_REQUIRE(face1->m_sentDatas[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
- BOOST_CHECK_EQUAL(*face1->m_sentDatas[0].getTag<lp::IncomingFaceIdTag>(), FACEID_CONTENT_STORE);
+ BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
+ BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face::FACEID_CONTENT_STORE);
limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(500));
// PIT entry should not be left behind
@@ -155,8 +153,8 @@
BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
{
ScopeLocalhostIncomingTestForwarder forwarder;
- shared_ptr<Face> face1 = make_shared<DummyLocalFace>();
- shared_ptr<Face> face2 = make_shared<DummyFace>();
+ auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
+ auto face2 = make_shared<DummyFace>();
forwarder.addFace(face1);
forwarder.addFace(face2);
@@ -212,9 +210,9 @@
BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing)
{
Forwarder forwarder;
- shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<Face> face3 = make_shared<DummyLocalFace>();
+ auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
@@ -224,62 +222,62 @@
shared_ptr<Interest> interestA1 = makeInterest("/localhost/A1");
shared_ptr<pit::Entry> pitA1 = pit.insert(*interestA1).first;
pitA1->insertOrUpdateInRecord(face3, *interestA1);
- face1->m_sentInterests.clear();
+ face1->sentInterests.clear();
forwarder.onOutgoingInterest(pitA1, *face1);
- BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1);
// non-local face, /localhost: violate
shared_ptr<Interest> interestA2 = makeInterest("/localhost/A2");
shared_ptr<pit::Entry> pitA2 = pit.insert(*interestA2).first;
pitA2->insertOrUpdateInRecord(face3, *interestA2);
- face2->m_sentInterests.clear();
+ face2->sentInterests.clear();
forwarder.onOutgoingInterest(pitA2, *face2);
- BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face2->sentInterests.size(), 0);
// local face, non-/localhost: OK
shared_ptr<Interest> interestA3 = makeInterest("/A3");
shared_ptr<pit::Entry> pitA3 = pit.insert(*interestA3).first;
pitA3->insertOrUpdateInRecord(face3, *interestA3);
- face1->m_sentInterests.clear();
+ face1->sentInterests.clear();
forwarder.onOutgoingInterest(pitA3, *face1);
- BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1);
// non-local face, non-/localhost: OK
shared_ptr<Interest> interestA4 = makeInterest("/A4");
shared_ptr<pit::Entry> pitA4 = pit.insert(*interestA4).first;
pitA4->insertOrUpdateInRecord(face3, *interestA4);
- face2->m_sentInterests.clear();
+ face2->sentInterests.clear();
forwarder.onOutgoingInterest(pitA4, *face2);
- BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1);
// local face, /localhost: OK
- face1->m_sentDatas.clear();
+ face1->sentData.clear();
forwarder.onOutgoingData(Data("/localhost/B1"), *face1);
- BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentData.size(), 1);
// non-local face, /localhost: OK
- face2->m_sentDatas.clear();
+ face2->sentData.clear();
forwarder.onOutgoingData(Data("/localhost/B2"), *face2);
- BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 0);
+ BOOST_CHECK_EQUAL(face2->sentData.size(), 0);
// local face, non-/localhost: OK
- face1->m_sentDatas.clear();
+ face1->sentData.clear();
forwarder.onOutgoingData(Data("/B3"), *face1);
- BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentData.size(), 1);
// non-local face, non-/localhost: OK
- face2->m_sentDatas.clear();
+ face2->sentData.clear();
forwarder.onOutgoingData(Data("/B4"), *face2);
- BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentData.size(), 1);
}
BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing)
{
Forwarder forwarder;
- shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyLocalFace> face3 = make_shared<DummyLocalFace>();
- shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
+ auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
+ auto face4 = make_shared<DummyFace>();
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
@@ -290,59 +288,59 @@
shared_ptr<Interest> interest1 = makeInterest("/localhop/1");
shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
pit1->insertOrUpdateInRecord(face1, *interest1);
- face3->m_sentInterests.clear();
+ face3->sentInterests.clear();
forwarder.onOutgoingInterest(pit1, *face3);
- BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1);
// from non-local face, to local face: OK
shared_ptr<Interest> interest2 = makeInterest("/localhop/2");
shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
pit2->insertOrUpdateInRecord(face2, *interest2);
- face3->m_sentInterests.clear();
+ face3->sentInterests.clear();
forwarder.onOutgoingInterest(pit2, *face3);
- BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1);
// from local face, to non-local face: OK
shared_ptr<Interest> interest3 = makeInterest("/localhop/3");
shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first;
pit3->insertOrUpdateInRecord(face1, *interest3);
- face4->m_sentInterests.clear();
+ face4->sentInterests.clear();
forwarder.onOutgoingInterest(pit3, *face4);
- BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1);
// from non-local face, to non-local face: violate
shared_ptr<Interest> interest4 = makeInterest("/localhop/4");
shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
pit4->insertOrUpdateInRecord(face2, *interest4);
- face4->m_sentInterests.clear();
+ face4->sentInterests.clear();
forwarder.onOutgoingInterest(pit4, *face4);
- BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face4->sentInterests.size(), 0);
// from local face and non-local face, to local face: OK
shared_ptr<Interest> interest5 = makeInterest("/localhop/5");
shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first;
pit5->insertOrUpdateInRecord(face1, *interest5);
pit5->insertOrUpdateInRecord(face2, *interest5);
- face3->m_sentInterests.clear();
+ face3->sentInterests.clear();
forwarder.onOutgoingInterest(pit5, *face3);
- BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1);
// from local face and non-local face, to non-local face: OK
shared_ptr<Interest> interest6 = makeInterest("/localhop/6");
shared_ptr<pit::Entry> pit6 = pit.insert(*interest6).first;
pit6->insertOrUpdateInRecord(face1, *interest6);
pit6->insertOrUpdateInRecord(face2, *interest6);
- face4->m_sentInterests.clear();
+ face4->sentInterests.clear();
forwarder.onOutgoingInterest(pit6, *face4);
- BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1);
}
BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch)
{
LimitedIo limitedIo;
Forwarder forwarder;
- shared_ptr<Face> face1 = make_shared<DummyFace>();
- shared_ptr<Face> face2 = make_shared<DummyFace>();
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
forwarder.addFace(face1);
forwarder.addFace(face2);
@@ -398,10 +396,10 @@
{
LimitedIo limitedIo;
Forwarder forwarder;
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>();
+ auto face4 = make_shared<DummyFace>();
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
@@ -424,10 +422,10 @@
forwarder.onIncomingData(*face3, *dataD);
limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
- BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
- BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
- BOOST_CHECK_EQUAL(face3->m_sentDatas.size(), 0);
- BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentData.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentData.size(), 1);
+ BOOST_CHECK_EQUAL(face3->sentData.size(), 0);
+ BOOST_CHECK_EQUAL(face4->sentData.size(), 1);
}
BOOST_AUTO_TEST_CASE(IncomingNack)
@@ -435,11 +433,10 @@
Forwarder forwarder;
auto face1 = make_shared<DummyFace>();
auto face2 = make_shared<DummyFace>();
- auto face3 = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
- "dummy://", "dummy://",
- ndn::nfd::FACE_SCOPE_NON_LOCAL,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ auto face3 = make_shared<DummyFace>("dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS);
forwarder.addFace(face1);
forwarder.addFace(face2);
forwarder.addFace(face3);
@@ -524,20 +521,15 @@
BOOST_AUTO_TEST_CASE(OutgoingNack)
{
Forwarder forwarder;
- auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
- auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
- auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
- auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
- auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
- "dummy://", "dummy://",
- ndn::nfd::FACE_SCOPE_NON_LOCAL,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- ndn::nfd::LINK_TYPE_MULTI_ACCESS));
- auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
- forwarder.addFace(face1w);
- forwarder.addFace(face2w);
- forwarder.addFace(face3w);
- // TODO#3172 eliminate wrapper
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>("dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
Pit& pit = forwarder.getPit();
@@ -547,68 +539,63 @@
// don't send Nack if there's no in-record
shared_ptr<Interest> interest1 = makeInterest("/fM5IVEtC", 719);
shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
- pit1->insertOrUpdateInRecord(face1w, *interest1);
+ pit1->insertOrUpdateInRecord(face1, *interest1);
face2->sentNacks.clear();
- forwarder.onOutgoingNack(pit1, *face2w, nackHeader);
+ forwarder.onOutgoingNack(pit1, *face2, nackHeader);
BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0);
// send Nack with correct Nonce
shared_ptr<Interest> interest2a = makeInterest("/Vi8tRm9MG3", 152);
shared_ptr<pit::Entry> pit2 = pit.insert(*interest2a).first;
- pit2->insertOrUpdateInRecord(face1w, *interest2a);
+ pit2->insertOrUpdateInRecord(face1, *interest2a);
shared_ptr<Interest> interest2b = makeInterest("/Vi8tRm9MG3", 808);
- pit2->insertOrUpdateInRecord(face2w, *interest2b);
+ pit2->insertOrUpdateInRecord(face2, *interest2b);
face1->sentNacks.clear();
- forwarder.onOutgoingNack(pit2, *face1w, nackHeader);
+ forwarder.onOutgoingNack(pit2, *face1, nackHeader);
BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152);
// erase in-record
- pit::InRecordCollection::const_iterator inRecord2a = pit2->getInRecord(*face1w);
+ pit::InRecordCollection::const_iterator inRecord2a = pit2->getInRecord(*face1);
BOOST_CHECK(inRecord2a == pit2->getInRecords().end());
// send Nack with correct Nonce
face2->sentNacks.clear();
- forwarder.onOutgoingNack(pit2, *face2w, nackHeader);
+ forwarder.onOutgoingNack(pit2, *face2, nackHeader);
BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808);
// erase in-record
- pit::InRecordCollection::const_iterator inRecord2b = pit2->getInRecord(*face1w);
+ pit::InRecordCollection::const_iterator inRecord2b = pit2->getInRecord(*face1);
BOOST_CHECK(inRecord2b == pit2->getInRecords().end());
// don't send Nack to multi-access face
shared_ptr<Interest> interest2c = makeInterest("/Vi8tRm9MG3", 228);
- pit2->insertOrUpdateInRecord(face3w, *interest2c);
+ pit2->insertOrUpdateInRecord(face3, *interest2c);
face3->sentNacks.clear();
- forwarder.onOutgoingNack(pit1, *face3w, nackHeader);
+ forwarder.onOutgoingNack(pit1, *face3, nackHeader);
BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0);
}
BOOST_AUTO_TEST_CASE(InterestLoopNack)
{
Forwarder forwarder;
- auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
- auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
- auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
- auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
- auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
- "dummy://", "dummy://",
- ndn::nfd::FACE_SCOPE_NON_LOCAL,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- ndn::nfd::LINK_TYPE_MULTI_ACCESS));
- auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<DummyFace>("dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS);
auto face4 = make_shared<DummyFace>();
- forwarder.addFace(face1w);
- forwarder.addFace(face2w);
- forwarder.addFace(face3w);
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
forwarder.addFace(face4);
- // TODO#3172 eliminate wrapper
Fib& fib = forwarder.getFib();
shared_ptr<fib::Entry> fibEntry = fib.insert(Name("/zT4XwK0Hnx")).first;
@@ -658,8 +645,11 @@
forwarder.addFace(face2);
// cause an Interest sent out of face2 to loop back into face1 after a delay
- face2->onSendInterest.connect([&face1] (const Interest& interest) {
- scheduler::schedule(time::milliseconds(170), [&] { face1->receiveInterest(interest); });
+ face2->afterSend.connect([face1, face2] (uint32_t pktType) {
+ if (pktType == tlv::Interest) {
+ auto interest = make_shared<Interest>(face2->sentInterests.back());
+ scheduler::schedule(time::milliseconds(170), [face1, interest] { face1->receiveInterest(*interest); });
+ }
});
Fib& fib = forwarder.getFib();
@@ -676,7 +666,7 @@
BOOST_ASSERT(time::milliseconds(25) * 40 < forwarder.getDeadNonceList().getLifetime());
this->advanceClocks(time::milliseconds(25), 40);
- BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1);
// It's unnecessary to check that Interest with duplicate Nonce can be forwarded again
// after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List
diff --git a/tests/daemon/fw/strategy.t.cpp b/tests/daemon/fw/strategy.t.cpp
index 44fead2..90654d7 100644
--- a/tests/daemon/fw/strategy.t.cpp
+++ b/tests/daemon/fw/strategy.t.cpp
@@ -36,7 +36,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwStrategy, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestStrategy, BaseFixture)
class FaceTableAccessTestStrategy : public DummyStrategy
{
@@ -58,7 +59,7 @@
{
auto enumerable = this->getFaceTable() |
boost::adaptors::filtered([] (shared_ptr<Face> face) {
- return face->isLocal();
+ return face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL;
});
std::vector<FaceId> results;
@@ -79,7 +80,7 @@
FaceTableAccessTestStrategy strategy(forwarder);
auto face1 = make_shared<DummyFace>();
- auto face2 = make_shared<DummyLocalFace>();
+ auto face2 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
forwarder.addFace(face1);
forwarder.addFace(face2);
FaceId id1 = face1->getId();
@@ -94,7 +95,8 @@
BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
index 8b94abc..f1e54bb 100644
--- a/tests/daemon/fw/topology-tester.cpp
+++ b/tests/daemon/fw/topology-tester.cpp
@@ -34,7 +34,6 @@
using face::InternalTransportBase;
using face::InternalForwarderTransport;
using face::InternalClientTransport;
-using face::LpFaceWrapper;
using face::GenericLinkService;
TopologyLink::TopologyLink(const time::nanoseconds& delay)
@@ -46,9 +45,9 @@
}
void
-TopologyLink::addFace(TopologyNode i, shared_ptr<LpFaceWrapper> face)
+TopologyLink::addFace(TopologyNode i, shared_ptr<Face> face)
{
- this->attachTransport(i, dynamic_cast<InternalTransportBase*>(face->getLpFace()->getTransport()));
+ this->attachTransport(i, dynamic_cast<InternalTransportBase*>(face->getTransport()));
m_faces[i] = face;
}
@@ -87,9 +86,9 @@
});
}
-TopologyAppLink::TopologyAppLink(shared_ptr<LpFaceWrapper> forwarderFace)
+TopologyAppLink::TopologyAppLink(shared_ptr<Face> forwarderFace)
: m_face(forwarderFace)
- , m_forwarderTransport(static_cast<InternalForwarderTransport*>(forwarderFace->getLpFace()->getTransport()))
+ , m_forwarderTransport(static_cast<InternalForwarderTransport*>(forwarderFace->getTransport()))
, m_clientTransport(make_shared<InternalClientTransport>())
, m_client(make_shared<ndn::Face>(m_clientTransport, getGlobalIoService()))
{
@@ -136,11 +135,10 @@
auto service = make_unique<GenericLinkService>();
auto transport = make_unique<InternalForwarderTransport>(localUri, remoteUri,
ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType);
- auto face = make_unique<LpFace>(std::move(service), std::move(transport));
- auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+ auto face = make_shared<Face>(std::move(service), std::move(transport));
- forwarder.addFace(faceW);
- link->addFace(i, faceW);
+ forwarder.addFace(face);
+ link->addFace(i, face);
}
m_links.push_back(link); // keep a shared_ptr so callers don't have to
@@ -157,12 +155,11 @@
auto service = 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_unique<LpFace>(std::move(service), std::move(transport));
- auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+ auto face = make_shared<Face>(std::move(service), std::move(transport));
- forwarder.addFace(faceW);
+ forwarder.addFace(face);
- auto al = make_shared<TopologyAppLink>(faceW);
+ auto al = make_shared<TopologyAppLink>(face);
m_appLinks.push_back(al); // keep a shared_ptr so callers don't have to
return al;
}
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index 9a10ad7..88d73da 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -32,7 +32,7 @@
#include <ndn-cxx/face.hpp>
#include "face/internal-transport.hpp"
-#include "face/lp-face-wrapper.hpp"
+#include "face/face.hpp"
#include "fw/strategy.hpp"
#include "tests/test-common.hpp"
@@ -70,8 +70,12 @@
m_isUp = true;
}
+ /** \brief attach a face to the link
+ * \param i forwarder index
+ * \param face a Face with InternalForwarderTransport
+ */
void
- addFace(TopologyNode i, shared_ptr<face::LpFaceWrapper> face);
+ addFace(TopologyNode i, shared_ptr<Face> face);
/** \return a face of forwarder \p i which is attached to this link
*/
@@ -98,7 +102,7 @@
bool m_isUp;
time::nanoseconds m_delay;
std::unordered_map<TopologyNode, face::InternalTransportBase*> m_transports;
- std::unordered_map<TopologyNode, shared_ptr<face::LpFaceWrapper>> m_faces;
+ std::unordered_map<TopologyNode, shared_ptr<Face>> m_faces;
};
/** \brief represents a link to a local application
@@ -106,8 +110,11 @@
class TopologyAppLink : noncopyable
{
public:
+ /** \brief constructor
+ * \param forwarderFace a Face with InternalForwarderTransport
+ */
explicit
- TopologyAppLink(shared_ptr<face::LpFaceWrapper> forwarderFace);
+ TopologyAppLink(shared_ptr<Face> forwarderFace);
/** \brief fail the link, cause packets to be dropped silently
*/
diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp
index 02bcd78..a8f3015 100644
--- a/tests/daemon/mgmt/face-manager.t.cpp
+++ b/tests/daemon/mgmt/face-manager.t.cpp
@@ -37,6 +37,9 @@
namespace nfd {
namespace tests {
+BOOST_AUTO_TEST_SUITE(Mgmt)
+
+
class FaceManagerFixture : public ManagerCommonFixture
{
public:
@@ -48,32 +51,74 @@
}
public:
- template<typename Face>
+ enum AddFaceFlags {
+ REMOVE_LAST_NOTIFICATION = 1 << 0,
+ SET_SCOPE_LOCAL = 1 << 1,
+ SET_URI_TEST = 1 << 2,
+ RANDOMIZE_COUNTERS = 1 << 3
+ };
+
+ /** \brief adds a face to the FaceTable
+ * \param options bitwise OR'ed AddFaceFlags
+ */
shared_ptr<Face>
- addFace(bool wantRemoveLastNotification = false)
+ addFace(int flags = 0)
{
- auto face = make_shared<Face>();
+ std::string uri = "dummy://";
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL;
+
+ if ((flags & SET_SCOPE_LOCAL) != 0) {
+ scope = ndn::nfd::FACE_SCOPE_LOCAL;
+ }
+ if ((flags & SET_URI_TEST) != 0) {
+ uri = "test://";
+ }
+
+ auto face = make_shared<DummyFace>(uri, uri, scope);
m_faceTable.add(face);
+
+ if ((flags & RANDOMIZE_COUNTERS) != 0) {
+ const face::FaceCounters& counters = face->getCounters();
+ randomizeCounter(counters.nInInterests);
+ randomizeCounter(counters.nOutInterests);
+ randomizeCounter(counters.nInData);
+ randomizeCounter(counters.nOutData);
+ randomizeCounter(counters.nInNacks);
+ randomizeCounter(counters.nOutNacks);
+ randomizeCounter(counters.nInPackets);
+ randomizeCounter(counters.nOutPackets);
+ randomizeCounter(counters.nInBytes);
+ randomizeCounter(counters.nOutBytes);
+ }
+
advanceClocks(time::milliseconds(1), 10); // wait for notification posted
- if (wantRemoveLastNotification) {
+ if ((flags & REMOVE_LAST_NOTIFICATION) != 0) {
m_responses.pop_back();
}
+
return face;
}
+private:
+ template<typename T>
+ static typename std::enable_if<std::is_base_of<SimpleCounter, T>::value>::type
+ randomizeCounter(const T& counter)
+ {
+ const_cast<T&>(counter).set(ndn::random::generateWord64());
+ }
+
protected:
FaceTable& m_faceTable;
FaceManager m_manager;
};
-BOOST_FIXTURE_TEST_SUITE(Mgmt, FaceManagerFixture)
-BOOST_AUTO_TEST_SUITE(TestFaceManager)
+BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture)
BOOST_AUTO_TEST_SUITE(DestroyFace)
BOOST_AUTO_TEST_CASE(Existing)
{
- auto addedFace = addFace<DummyFace>(true); // clear notification for creation
+ auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation
auto parameters = ControlParameters().setFaceId(addedFace->getId());
auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
@@ -86,7 +131,7 @@
BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)),
CheckResponseResult::OK);
- BOOST_CHECK_EQUAL(addedFace->getId(), -1);
+ BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
}
BOOST_AUTO_TEST_CASE(NonExisting)
@@ -106,7 +151,7 @@
BOOST_AUTO_TEST_CASE(FaceEvents)
{
- auto addedFace = addFace<DummyFace>(); // trigger FACE_EVENT_CREATED notification
+ auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification
BOOST_CHECK_NE(addedFace->getId(), -1);
int64_t faceId = addedFace->getId();
@@ -146,25 +191,9 @@
BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT);
}
- BOOST_CHECK_EQUAL(addedFace->getId(), -1);
+ BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID);
}
-class TestFace : public DummyFace
-{
-public:
- explicit
- TestFace(const std::string& uri = "test://")
- : DummyFace(uri, uri)
- {
- getMutableCounters().getNInInterests().set(ndn::random::generateWord64());
- getMutableCounters().getNInDatas().set(ndn::random::generateWord64());
- getMutableCounters().getNOutInterests().set(ndn::random::generateWord64());
- getMutableCounters().getNOutDatas().set(ndn::random::generateWord64());
- getMutableCounters().getNInBytes().set(ndn::random::generateWord64());
- getMutableCounters().getNOutBytes().set(ndn::random::generateWord64());
- }
-};
-
// @todo Refactor when ndn::nfd::FaceStatus implementes operator!= and operator<<
class FaceStatus : public ndn::nfd::FaceStatus
{
@@ -179,16 +208,16 @@
operator!=(const FaceStatus& left, const FaceStatus& right)
{
return left.getRemoteUri() != right.getRemoteUri() ||
- left.getLocalUri() != right.getLocalUri() ||
- left.getFaceScope() != right.getFaceScope() ||
- left.getFacePersistency() != right.getFacePersistency() ||
- left.getLinkType() != right.getLinkType() ||
- left.getNInInterests() != right.getNInInterests() ||
- left.getNInDatas() != right.getNInDatas() ||
- left.getNOutInterests() != right.getNOutInterests() ||
- left.getNOutDatas() != right.getNOutDatas() ||
- left.getNInBytes() != right.getNInBytes() ||
- left.getNOutBytes() != right.getNOutBytes();
+ left.getLocalUri() != right.getLocalUri() ||
+ left.getFaceScope() != right.getFaceScope() ||
+ left.getFacePersistency() != right.getFacePersistency() ||
+ left.getLinkType() != right.getLinkType() ||
+ left.getNInInterests() != right.getNInInterests() ||
+ left.getNInDatas() != right.getNInDatas() ||
+ left.getNOutInterests() != right.getNOutInterests() ||
+ left.getNOutDatas() != right.getNOutDatas() ||
+ left.getNInBytes() != right.getNInBytes() ||
+ left.getNOutBytes() != right.getNOutBytes();
}
std::ostream&
@@ -210,8 +239,8 @@
BOOST_AUTO_TEST_CASE(FaceDataset)
{
size_t nEntries = 303;
- for (size_t i = 0 ; i < nEntries ; i ++) {
- addFace<TestFace>(true);
+ for (size_t i = 0; i < nEntries; ++i) {
+ addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS);
}
receiveInterest(makeInterest("/localhost/nfd/faces/list"));
@@ -237,9 +266,9 @@
BOOST_AUTO_TEST_CASE(FaceQuery)
{
- auto face1 = addFace<DummyFace>(true); // dummy://
- auto face2 = addFace<DummyLocalFace>(true); // dummy://, local
- auto face3 = addFace<TestFace>(true); // test://
+ auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy://
+ auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local
+ auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test://
auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) {
return Name("/localhost/nfd/faces/query").append(filter.wireEncode());
diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp
index 945a07e..87856ed 100644
--- a/tests/daemon/mgmt/fib-manager.t.cpp
+++ b/tests/daemon/mgmt/fib-manager.t.cpp
@@ -80,7 +80,7 @@
* @brief check whether the nexthop record is added / removed properly
*
* @param expectedNNextHops use -1 to skip this check
- * @param faceId use FACEID_NULL to skip NextHopRecord checks
+ * @param faceId use face::FACEID_NULL to skip NextHopRecord checks
* @param expectedCost use -1 to skip this check
*
* @retval OK FIB entry is found by exact match and has the expected number of nexthops;
@@ -92,7 +92,7 @@
*/
CheckNextHopResult
checkNextHop(const Name& prefix, ssize_t expectedNNextHops = -1,
- FaceId faceId = FACEID_NULL, int32_t expectedCost = -1)
+ FaceId faceId = face::FACEID_NULL, int32_t expectedCost = -1)
{
auto entry = m_fib.findExactMatch(prefix);
if (!static_cast<bool>(entry)) {
@@ -104,7 +104,7 @@
return CheckNextHopResult::WRONG_N_NEXTHOPS;
}
- if (faceId != FACEID_NULL) {
+ if (faceId != face::FACEID_NULL) {
for (auto&& record : nextHops) {
if (record.getFace()->getId() == faceId) {
return expectedCost != -1 && record.getCost() != static_cast<uint32_t>(expectedCost) ?
@@ -158,7 +158,7 @@
BOOST_AUTO_TEST_CASE(UnknownFaceId)
{
auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop",
- makeParameters("hello", FACEID_NULL, 101));
+ makeParameters("hello", face::FACEID_NULL, 101));
receiveInterest(command);
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
@@ -167,14 +167,15 @@
CheckResponseResult::OK);
// double check that the next hop was not added
- BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, FACEID_NULL, 101), CheckNextHopResult::NO_FIB_ENTRY);
+ BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, face::FACEID_NULL, 101), CheckNextHopResult::NO_FIB_ENTRY);
}
BOOST_AUTO_TEST_CASE(ImplicitFaceId)
{
auto face1 = addFace();
auto face2 = addFace();
- BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID);
+ BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
+ BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Name expectedName;
ControlResponse expectedResponse;
@@ -203,7 +204,7 @@
BOOST_AUTO_TEST_CASE(InitialAdd)
{
FaceId addedFaceId = addFace();
- BOOST_REQUIRE(addedFaceId != INVALID_FACEID);
+ BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
auto parameters = makeParameters("hello", addedFaceId, 101);
auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
@@ -218,7 +219,7 @@
BOOST_AUTO_TEST_CASE(ImplicitCost)
{
FaceId addedFaceId = addFace();
- BOOST_REQUIRE(addedFaceId != INVALID_FACEID);
+ BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
auto originalParameters = ControlParameters().setName("/hello").setFaceId(addedFaceId);
auto parameters = makeParameters("/hello", addedFaceId, 0);
@@ -234,7 +235,7 @@
BOOST_AUTO_TEST_CASE(AddToExisting)
{
FaceId face = addFace();
- BOOST_CHECK(face != INVALID_FACEID);
+ BOOST_REQUIRE_NE(face, face::INVALID_FACEID);
Name expectedName;
ControlResponse expectedResponse;
@@ -280,7 +281,9 @@
FaceId face1 = addFace();
FaceId face2 = addFace();
FaceId face3 = addFace();
- BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID && face3 != INVALID_FACEID);
+ BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
+ BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
+ BOOST_REQUIRE_NE(face3, face::INVALID_FACEID);
shared_ptr<fib::Entry> entry = m_fib.insert("/hello").first;
entry->addNextHop(m_faceTable.get(face1), 101);
@@ -306,7 +309,7 @@
BOOST_AUTO_TEST_CASE(PrefixNotFound)
{
FaceId addedFaceId = addFace();
- BOOST_CHECK(addedFaceId != INVALID_FACEID);
+ BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
auto parameters = makeParameters("hello", addedFaceId);
auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
@@ -321,7 +324,8 @@
{
auto face1 = addFace();
auto face2 = addFace();
- BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID);
+ BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
+ BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Name expectedName;
ControlResponse expectedResponse;
@@ -355,7 +359,8 @@
{
auto face1 = addFace();
auto face2 = addFace();
- BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID);
+ BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
+ BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Name expectedName;
ControlResponse expectedResponse;