face: TcpTransport
Change-Id: I3ff898225ad1b0c1178490f389048944e24a9f1b
Refs: #3166
diff --git a/tests/daemon/face/packet-datasets.cpp b/tests/daemon/face/packet-datasets.cpp
index cf661db..196fa86 100644
--- a/tests/daemon/face/packet-datasets.cpp
+++ b/tests/daemon/face/packet-datasets.cpp
@@ -46,18 +46,6 @@
BOOST_CHECK_THROW((Interest(block)), tlv::Error);
}
}
-
- {
- typedef CorruptedInterestWithLocalControlHeader Dataset;
- Dataset dataset;
-
- BOOST_FOREACH(Dataset::Container::value_type& data, dataset.data)
- {
- Block block(data.buf(), data.size());
-
- BOOST_CHECK_THROW(ndn::nfd::LocalControlHeader::getPayload(block), tlv::Error);
- }
- }
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/daemon/face/packet-datasets.hpp b/tests/daemon/face/packet-datasets.hpp
index 373f4e6..95639c1 100644
--- a/tests/daemon/face/packet-datasets.hpp
+++ b/tests/daemon/face/packet-datasets.hpp
@@ -31,31 +31,6 @@
namespace nfd {
namespace tests {
-class CorruptedInterestWithLocalControlHeader
-{
-public:
- typedef std::vector<ndn::Buffer> Container;
-
- static std::string
- getName()
- {
- return "CorruptedInterestWithLocalControlHeader";
- }
-
- CorruptedInterestWithLocalControlHeader()
- {
- static const uint8_t interest[] = {
- 0x50, 0x22, 0x51, 0x81, 0x0a, 0x05, 0x1d, 0x07, 0x14, 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;
-};
-
class CorruptedInterest
{
public:
@@ -81,9 +56,7 @@
Container data;
};
-
-typedef boost::mpl::vector< CorruptedInterestWithLocalControlHeader,
- CorruptedInterest> CorruptedPackets;
+typedef boost::mpl::vector<CorruptedInterest> CorruptedPackets;
} // namespace tests
} // namespace nfd
diff --git a/tests/daemon/face/tcp-transport.t.cpp b/tests/daemon/face/tcp-transport.t.cpp
new file mode 100644
index 0000000..a9d2fe1
--- /dev/null
+++ b/tests/daemon/face/tcp-transport.t.cpp
@@ -0,0 +1,83 @@
+/* -*- 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-transport.hpp"
+#include "transport-properties.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+using namespace nfd::tests;
+namespace ip = boost::asio::ip;
+using ip::tcp;
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestTcpTransport, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(StaticPropertiesIpv4)
+{
+ tcp::endpoint ep(ip::address_v4::loopback(), 7002);
+ tcp::acceptor acceptor(g_io, ep);
+
+ tcp::socket sock(g_io, tcp::endpoint(ip::address_v4::loopback(), 7001));
+ sock.connect(ep);
+ TcpTransport transport(std::move(sock), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
+ checkStaticPropertiesInitialized(transport);
+
+ BOOST_CHECK_EQUAL(transport.getLocalUri(), FaceUri("tcp4://127.0.0.1:7001"));
+ BOOST_CHECK_EQUAL(transport.getRemoteUri(), FaceUri("tcp4://127.0.0.1:7002"));
+ BOOST_CHECK_EQUAL(transport.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
+ BOOST_CHECK_EQUAL(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
+ BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ BOOST_CHECK_EQUAL(transport.getMtu(), MTU_UNLIMITED);
+}
+
+BOOST_AUTO_TEST_CASE(StaticPropertiesIpv6)
+{
+ tcp::endpoint ep(ip::address_v6::loopback(), 7002);
+ tcp::acceptor acceptor(g_io, ep);
+
+ tcp::socket sock(g_io, tcp::endpoint(ip::address_v6::loopback(), 7001));
+ sock.connect(ep);
+ TcpTransport transport(std::move(sock), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ checkStaticPropertiesInitialized(transport);
+
+ BOOST_CHECK_EQUAL(transport.getLocalUri(), FaceUri("tcp6://[::1]:7001"));
+ BOOST_CHECK_EQUAL(transport.getRemoteUri(), FaceUri("tcp6://[::1]:7002"));
+ BOOST_CHECK_EQUAL(transport.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
+ BOOST_CHECK_EQUAL(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ BOOST_CHECK_EQUAL(transport.getMtu(), MTU_UNLIMITED);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/tcp.t.cpp b/tests/daemon/face/tcp.t.cpp
index bec87e1..cbb3946 100644
--- a/tests/daemon/face/tcp.t.cpp
+++ b/tests/daemon/face/tcp.t.cpp
@@ -24,7 +24,6 @@
*/
#include "face/tcp-channel.hpp"
-#include "face/tcp-face.hpp"
#include "face/tcp-factory.hpp"
#include "core/network-interface.hpp"
@@ -33,12 +32,13 @@
#include "dummy-stream-sender.hpp"
#include "packet-datasets.hpp"
-#include <ndn-cxx/security/key-chain.hpp>
-
namespace nfd {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(FaceTcp, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestTcp, BaseFixture)
+
+using nfd::Face;
BOOST_AUTO_TEST_CASE(ChannelMap)
{
@@ -102,14 +102,14 @@
"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_FIXTURE_TEST_CASE(UnsupportedFaceCreate, FaceCreateFixture)
+BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
TcpFactory factory;
@@ -305,11 +305,6 @@
BOOST_CHECK_EQUAL(face1->isLocal(), true);
BOOST_CHECK_EQUAL(face2->isLocal(), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face1)), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face2)), true);
-
- // integrated tests needs to check that TcpFace for non-loopback fails these tests...
-
shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
@@ -388,11 +383,6 @@
BOOST_CHECK_EQUAL(face1->isLocal(), true);
BOOST_CHECK_EQUAL(face2->isLocal(), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face1)), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face2)), true);
-
- // integrated tests needs to check that TcpFace for non-loopback fails these tests...
-
shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
@@ -464,7 +454,6 @@
BOOST_CHECK_EQUAL(faces.size(), 6);
}
-
BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
{
TcpFactory factory;
@@ -504,7 +493,6 @@
BOOST_CHECK_EQUAL(channel2->size(), 0);
}
-
class SimpleEndToEndFixture : protected BaseFixture
{
public:
@@ -515,14 +503,6 @@
face->onReceiveData.connect(bind(&SimpleEndToEndFixture::onReceiveData, this, _1));
face->onFail.connect(bind(&SimpleEndToEndFixture::onFail, this, face));
- if (static_cast<bool>(dynamic_pointer_cast<LocalFace>(face))) {
- static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
- LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
-
- static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
- LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
- }
-
limitedIo.afterOp();
}
@@ -563,26 +543,6 @@
std::vector<Data> receivedDatas;
};
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalFaceCorruptedInput, Dataset,
- CorruptedPackets, SimpleEndToEndFixture)
-{
- TcpFactory factory;
- tcp::Endpoint endpoint(boost::asio::ip::address_v4::from_string("127.0.0.1"), 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());
-}
-
BOOST_FIXTURE_TEST_CASE_TEMPLATE(FaceCorruptedInput, Dataset,
CorruptedPackets, SimpleEndToEndFixture)
{
@@ -787,7 +747,8 @@
}));
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestTcp
+BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace nfd