blob: ac1e33c7e7c11f7f35d4b2e67accdb63d93a8aaa [file] [log] [blame]
Junxiao Shi13546112015-10-14 19:33:07 -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
Eric Newberry8717e872015-11-23 12:41:50 -070026#include "transport-test-common.hpp"
Junxiao Shi13546112015-10-14 19:33:07 -070027
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070028#include "multicast-udp-transport-fixture.hpp"
29
Junxiao Shi13546112015-10-14 19:33:07 -070030namespace nfd {
31namespace face {
32namespace tests {
33
Junxiao Shi13546112015-10-14 19:33:07 -070034BOOST_AUTO_TEST_SUITE(Face)
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070035BOOST_FIXTURE_TEST_SUITE(TestMulticastUdpTransport, MulticastUdpTransportFixture)
Junxiao Shi13546112015-10-14 19:33:07 -070036
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070037BOOST_AUTO_TEST_CASE(StaticPropertiesNonLocalIpv4)
Junxiao Shi13546112015-10-14 19:33:07 -070038{
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070039 SKIP_IF_IP_UNAVAILABLE(defaultAddr);
40 initialize(defaultAddr);
Junxiao Shi13546112015-10-14 19:33:07 -070041
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070042 checkStaticPropertiesInitialized(*transport);
Junxiao Shi13546112015-10-14 19:33:07 -070043
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070044 BOOST_CHECK_EQUAL(transport->getLocalUri(),
45 FaceUri("udp4://" + defaultAddr.to_string() + ":" + to_string(localEp.port())));
46 BOOST_CHECK_EQUAL(transport->getRemoteUri(),
47 FaceUri("udp4://" + multicastEp.address().to_string() + ":" + to_string(multicastEp.port())));
48 BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
49 BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
50 BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
51 BOOST_CHECK_EQUAL(transport->getMtu(), 65535 - 60 - 8);
52}
Junxiao Shi13546112015-10-14 19:33:07 -070053
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070054BOOST_AUTO_TEST_CASE(ReceiveMultipleRemoteEndpoints)
55{
56 SKIP_IF_IP_UNAVAILABLE(defaultAddr);
57 initialize(defaultAddr);
58
59 // remoteSockRx2 unnecessary for this test case - only remoteSockTx2 is needed
60 udp::socket remoteSockTx2(g_io);
61 remoteSockTx2.open(udp::v4());
62 remoteSockTx2.set_option(udp::socket::reuse_address(true));
63 remoteSockTx2.set_option(ip::multicast::enable_loopback(true));
64 remoteSockTx2.bind(udp::endpoint(ip::address_v4::any(), 7071));
65
66 Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
67 ndn::Buffer buf1(pkt1.begin(), pkt1.end());
68 remoteWrite(buf1);
69
70 Block pkt2 = ndn::encoding::makeStringBlock(301, "world");
71 ndn::Buffer buf2(pkt2.begin(), pkt2.end());
72 remoteWrite(buf2);
73
74 BOOST_CHECK_EQUAL(transport->getCounters().nInPackets, 2);
75 BOOST_CHECK_EQUAL(transport->getCounters().nInBytes, buf1.size() + buf2.size());
76 BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
77
78 BOOST_REQUIRE_EQUAL(receivedPackets->size(), 2);
79 BOOST_CHECK_EQUAL(receivedPackets->at(0).remoteEndpoint,
80 receivedPackets->at(1).remoteEndpoint);
81
82 udp::endpoint destEp(multicastEp.address(), localEp.port());
83 remoteSockTx2.async_send_to(boost::asio::buffer(buf1), destEp,
84 [] (const boost::system::error_code& error, size_t) {
85 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
86 });
87 remoteSockTx2.async_send_to(boost::asio::buffer(buf2), destEp,
88 [] (const boost::system::error_code& error, size_t) {
89 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
90 });
91 limitedIo.defer(time::seconds(1));
92
93 BOOST_CHECK_EQUAL(transport->getCounters().nInPackets, 4);
94 BOOST_CHECK_EQUAL(transport->getCounters().nInBytes, 2 * buf1.size() + 2 * buf2.size());
95 BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
96
97 BOOST_REQUIRE_EQUAL(receivedPackets->size(), 4);
98 BOOST_CHECK_EQUAL(receivedPackets->at(2).remoteEndpoint,
99 receivedPackets->at(3).remoteEndpoint);
100 BOOST_CHECK_NE(receivedPackets->at(0).remoteEndpoint,
101 receivedPackets->at(2).remoteEndpoint);
Junxiao Shi13546112015-10-14 19:33:07 -0700102}
103
104BOOST_AUTO_TEST_SUITE_END() // TestMulticastUdpTransport
105BOOST_AUTO_TEST_SUITE_END() // Face
106
107} // namespace tests
108} // namespace face
109} // namespace nfd