blob: 2457e6d64bd7b1b3dfb3fe4cd7cea70cb81ccf15 [file] [log] [blame]
Junxiao Shi13546112015-10-14 19:33:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento22fba352017-10-17 15:53:51 -04002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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 Newberry6d8ee7a2015-12-21 16:37:52 -070026#include "multicast-udp-transport-fixture.hpp"
27
Davide Pesavento22fba352017-10-17 15:53:51 -040028#include <boost/mpl/vector.hpp>
29
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040030namespace nfd::tests {
31
32using namespace nfd::face;
Junxiao Shi13546112015-10-14 19:33:07 -070033
Junxiao Shi13546112015-10-14 19:33:07 -070034BOOST_AUTO_TEST_SUITE(Face)
Davide Pesavento279af1c2022-08-29 20:18:32 -040035BOOST_AUTO_TEST_SUITE(TestMulticastUdpTransport)
Davide Pesavento22fba352017-10-17 15:53:51 -040036
37using MulticastUdpTransportFixtures = boost::mpl::vector<
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050038 IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>,
39 IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
40 IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
Davide Pesavento22fba352017-10-17 15:53:51 -040041>;
42
43BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, MulticastUdpTransportFixtures, T)
Junxiao Shi13546112015-10-14 19:33:07 -070044{
Davide Pesavento22fba352017-10-17 15:53:51 -040045 TRANSPORT_TEST_INIT();
Junxiao Shi13546112015-10-14 19:33:07 -070046
Davide Pesavento22fba352017-10-17 15:53:51 -040047 checkStaticPropertiesInitialized(*this->transport);
Junxiao Shi13546112015-10-14 19:33:07 -070048
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050049 BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(udp::endpoint(this->address, this->txPort)));
50 BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->mcastEp));
Davide Pesavento22fba352017-10-17 15:53:51 -040051 BOOST_CHECK_EQUAL(this->transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
52 BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
53 BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
54 BOOST_CHECK_EQUAL(this->transport->getMtu(),
55 this->addressFamily == AddressFamily::V4 ? (65535 - 60 - 8) : (65535 - 8));
Eric Newberryb49313d2017-12-24 20:22:27 -070056 BOOST_CHECK_GT(this->transport->getSendQueueCapacity(), 0);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070057}
Junxiao Shi13546112015-10-14 19:33:07 -070058
Davide Pesavento279af1c2022-08-29 20:18:32 -040059using MulticastUdpTransportFixtureWithAddress = IpTransportFixture<MulticastUdpTransportFixture,
60 AddressFamily::Any,
61 AddressScope::LinkLocal,
62 MulticastInterface::Yes>;
63
64BOOST_FIXTURE_TEST_CASE(PersistencyChange, MulticastUdpTransportFixtureWithAddress)
Davide Pesavento32065652017-01-15 01:52:21 -050065{
Davide Pesavento22fba352017-10-17 15:53:51 -040066 TRANSPORT_TEST_INIT();
Davide Pesavento32065652017-01-15 01:52:21 -050067
68 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), false);
69 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false);
70 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true);
71}
72
Teng Liangd94b7b32022-07-10 21:29:37 +080073BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveFromMultipleEndpoints, T, MulticastUdpTransportFixtures, T)
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070074{
Davide Pesavento22fba352017-10-17 15:53:51 -040075 TRANSPORT_TEST_INIT();
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070076
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050077 // we need a second remote tx socket for this test case
Davide Pesavento22fba352017-10-17 15:53:51 -040078 udp::socket remoteSockTx2(this->g_io);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050079 MulticastUdpTransport::openTxSocket(remoteSockTx2, udp::endpoint(this->address, 0), nullptr, true);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070080
81 Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
82 ndn::Buffer buf1(pkt1.begin(), pkt1.end());
Davide Pesavento22fba352017-10-17 15:53:51 -040083 this->remoteWrite(buf1);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070084
85 Block pkt2 = ndn::encoding::makeStringBlock(301, "world");
86 ndn::Buffer buf2(pkt2.begin(), pkt2.end());
Davide Pesavento22fba352017-10-17 15:53:51 -040087 this->remoteWrite(buf2);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070088
Davide Pesavento22fba352017-10-17 15:53:51 -040089 BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 2);
90 BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, buf1.size() + buf2.size());
91 BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070092
Davide Pesavento22fba352017-10-17 15:53:51 -040093 BOOST_REQUIRE_EQUAL(this->receivedPackets->size(), 2);
Teng Liangd94b7b32022-07-10 21:29:37 +080094 BOOST_CHECK(this->receivedPackets->at(0).endpoint == this->receivedPackets->at(1).endpoint);
95 BOOST_CHECK(std::holds_alternative<nfd::udp::Endpoint>(this->receivedPackets->at(0).endpoint));
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070096
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050097 this->sendToGroup(remoteSockTx2, buf1);
98 this->sendToGroup(remoteSockTx2, buf2);
Davide Pesavento14e71f02019-03-28 17:35:25 -040099 this->limitedIo.defer(1_s);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700100
Davide Pesavento22fba352017-10-17 15:53:51 -0400101 BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 4);
102 BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, 2 * buf1.size() + 2 * buf2.size());
103 BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700104
Davide Pesavento22fba352017-10-17 15:53:51 -0400105 BOOST_REQUIRE_EQUAL(this->receivedPackets->size(), 4);
Teng Liangd94b7b32022-07-10 21:29:37 +0800106 EndpointId epId2(remoteSockTx2.local_endpoint());
107 BOOST_CHECK(this->receivedPackets->at(0).endpoint != epId2);
108 BOOST_CHECK(this->receivedPackets->at(1).endpoint != epId2);
109 BOOST_CHECK(this->receivedPackets->at(2).endpoint == epId2);
110 BOOST_CHECK(this->receivedPackets->at(3).endpoint == epId2);
Junxiao Shi13546112015-10-14 19:33:07 -0700111}
112
113BOOST_AUTO_TEST_SUITE_END() // TestMulticastUdpTransport
114BOOST_AUTO_TEST_SUITE_END() // Face
115
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400116} // namespace nfd::tests