blob: a9d2fe10cdbb44b7aca70ab3e0076c3ed0a28f79 [file] [log] [blame]
Yukai Tu16aabbc2015-10-06 05:08:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/tcp-transport.hpp"
27#include "transport-properties.hpp"
28
29#include "tests/test-common.hpp"
30
31namespace nfd {
32namespace face {
33namespace tests {
34
35using namespace nfd::tests;
36namespace ip = boost::asio::ip;
37using ip::tcp;
38
39BOOST_AUTO_TEST_SUITE(Face)
40BOOST_FIXTURE_TEST_SUITE(TestTcpTransport, BaseFixture)
41
42BOOST_AUTO_TEST_CASE(StaticPropertiesIpv4)
43{
44 tcp::endpoint ep(ip::address_v4::loopback(), 7002);
45 tcp::acceptor acceptor(g_io, ep);
46
47 tcp::socket sock(g_io, tcp::endpoint(ip::address_v4::loopback(), 7001));
48 sock.connect(ep);
49 TcpTransport transport(std::move(sock), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
50 checkStaticPropertiesInitialized(transport);
51
52 BOOST_CHECK_EQUAL(transport.getLocalUri(), FaceUri("tcp4://127.0.0.1:7001"));
53 BOOST_CHECK_EQUAL(transport.getRemoteUri(), FaceUri("tcp4://127.0.0.1:7002"));
54 BOOST_CHECK_EQUAL(transport.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
55 BOOST_CHECK_EQUAL(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
56 BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
57 BOOST_CHECK_EQUAL(transport.getMtu(), MTU_UNLIMITED);
58}
59
60BOOST_AUTO_TEST_CASE(StaticPropertiesIpv6)
61{
62 tcp::endpoint ep(ip::address_v6::loopback(), 7002);
63 tcp::acceptor acceptor(g_io, ep);
64
65 tcp::socket sock(g_io, tcp::endpoint(ip::address_v6::loopback(), 7001));
66 sock.connect(ep);
67 TcpTransport transport(std::move(sock), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
68 checkStaticPropertiesInitialized(transport);
69
70 BOOST_CHECK_EQUAL(transport.getLocalUri(), FaceUri("tcp6://[::1]:7001"));
71 BOOST_CHECK_EQUAL(transport.getRemoteUri(), FaceUri("tcp6://[::1]:7002"));
72 BOOST_CHECK_EQUAL(transport.getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
73 BOOST_CHECK_EQUAL(transport.getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
74 BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
75 BOOST_CHECK_EQUAL(transport.getMtu(), MTU_UNLIMITED);
76}
77
78BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport
79BOOST_AUTO_TEST_SUITE_END() // Face
80
81} // namespace tests
82} // namespace face
83} // namespace nfd