blob: 2b9407d7e26279c03acc7171951d03d5e4160e98 [file] [log] [blame]
Junxiao Shi13546112015-10-14 19:33:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento32065652017-01-15 01:52:21 -05003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi13546112015-10-14 19:33:07 -07004 * 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
Davide Pesavento32065652017-01-15 01:52:21 -050054BOOST_AUTO_TEST_CASE(PersistencyChange)
55{
56 SKIP_IF_IP_UNAVAILABLE(defaultAddr);
57 initialize(defaultAddr);
58
59 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), false);
60 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false);
61 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true);
62}
63
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070064BOOST_AUTO_TEST_CASE(ReceiveMultipleRemoteEndpoints)
65{
66 SKIP_IF_IP_UNAVAILABLE(defaultAddr);
67 initialize(defaultAddr);
68
69 // remoteSockRx2 unnecessary for this test case - only remoteSockTx2 is needed
70 udp::socket remoteSockTx2(g_io);
71 remoteSockTx2.open(udp::v4());
72 remoteSockTx2.set_option(udp::socket::reuse_address(true));
73 remoteSockTx2.set_option(ip::multicast::enable_loopback(true));
74 remoteSockTx2.bind(udp::endpoint(ip::address_v4::any(), 7071));
75
76 Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
77 ndn::Buffer buf1(pkt1.begin(), pkt1.end());
78 remoteWrite(buf1);
79
80 Block pkt2 = ndn::encoding::makeStringBlock(301, "world");
81 ndn::Buffer buf2(pkt2.begin(), pkt2.end());
82 remoteWrite(buf2);
83
84 BOOST_CHECK_EQUAL(transport->getCounters().nInPackets, 2);
85 BOOST_CHECK_EQUAL(transport->getCounters().nInBytes, buf1.size() + buf2.size());
86 BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
87
88 BOOST_REQUIRE_EQUAL(receivedPackets->size(), 2);
89 BOOST_CHECK_EQUAL(receivedPackets->at(0).remoteEndpoint,
90 receivedPackets->at(1).remoteEndpoint);
91
92 udp::endpoint destEp(multicastEp.address(), localEp.port());
93 remoteSockTx2.async_send_to(boost::asio::buffer(buf1), destEp,
94 [] (const boost::system::error_code& error, size_t) {
95 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
96 });
97 remoteSockTx2.async_send_to(boost::asio::buffer(buf2), destEp,
98 [] (const boost::system::error_code& error, size_t) {
99 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
100 });
101 limitedIo.defer(time::seconds(1));
102
103 BOOST_CHECK_EQUAL(transport->getCounters().nInPackets, 4);
104 BOOST_CHECK_EQUAL(transport->getCounters().nInBytes, 2 * buf1.size() + 2 * buf2.size());
105 BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
106
107 BOOST_REQUIRE_EQUAL(receivedPackets->size(), 4);
108 BOOST_CHECK_EQUAL(receivedPackets->at(2).remoteEndpoint,
109 receivedPackets->at(3).remoteEndpoint);
110 BOOST_CHECK_NE(receivedPackets->at(0).remoteEndpoint,
111 receivedPackets->at(2).remoteEndpoint);
Junxiao Shi13546112015-10-14 19:33:07 -0700112}
113
114BOOST_AUTO_TEST_SUITE_END() // TestMulticastUdpTransport
115BOOST_AUTO_TEST_SUITE_END() // Face
116
117} // namespace tests
118} // namespace face
119} // namespace nfd