blob: de6d30f94964d6ddd2c94d30d5a55dc19c9288a7 [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/*
Eric Newberryb49313d2017-12-24 20:22:27 -07003 * Copyright (c) 2014-2018, 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
Davide Pesavento22fba352017-10-17 15:53:51 -040030#include <boost/mpl/vector.hpp>
31
Junxiao Shi13546112015-10-14 19:33:07 -070032namespace nfd {
33namespace face {
34namespace tests {
35
Junxiao Shi13546112015-10-14 19:33:07 -070036BOOST_AUTO_TEST_SUITE(Face)
Junxiao Shi13546112015-10-14 19:33:07 -070037
Davide Pesavento22fba352017-10-17 15:53:51 -040038using MulticastUdpTransportFixtureWithAddress =
39 // TODO: change to AddressFamily::Any after IPv6 support is implemented
40 IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4,
41 AddressScope::Global, MulticastInterface::Yes>;
42
43BOOST_FIXTURE_TEST_SUITE(TestMulticastUdpTransport, MulticastUdpTransportFixtureWithAddress)
44
45using MulticastUdpTransportFixtures = boost::mpl::vector<
46 IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V4, AddressScope::Global, MulticastInterface::Yes>
47 // TODO: IPv6 not supported yet
48 //IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::LinkLocal, MulticastInterface::Yes>,
49 //IpTransportFixture<MulticastUdpTransportFixture, AddressFamily::V6, AddressScope::Global, MulticastInterface::Yes>
50>;
51
52BOOST_FIXTURE_TEST_CASE_TEMPLATE(StaticProperties, T, MulticastUdpTransportFixtures, T)
Junxiao Shi13546112015-10-14 19:33:07 -070053{
Davide Pesavento22fba352017-10-17 15:53:51 -040054 TRANSPORT_TEST_INIT();
Junxiao Shi13546112015-10-14 19:33:07 -070055
Davide Pesavento22fba352017-10-17 15:53:51 -040056 checkStaticPropertiesInitialized(*this->transport);
Junxiao Shi13546112015-10-14 19:33:07 -070057
Davide Pesavento22fba352017-10-17 15:53:51 -040058 BOOST_CHECK_EQUAL(this->transport->getLocalUri(), FaceUri(udp::endpoint(this->address, this->localEp.port())));
59 BOOST_CHECK_EQUAL(this->transport->getRemoteUri(), FaceUri(this->multicastEp));
60 BOOST_CHECK_EQUAL(this->transport->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
61 BOOST_CHECK_EQUAL(this->transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
62 BOOST_CHECK_EQUAL(this->transport->getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
63 BOOST_CHECK_EQUAL(this->transport->getMtu(),
64 this->addressFamily == AddressFamily::V4 ? (65535 - 60 - 8) : (65535 - 8));
Eric Newberryb49313d2017-12-24 20:22:27 -070065 BOOST_CHECK_GT(this->transport->getSendQueueCapacity(), 0);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070066}
Junxiao Shi13546112015-10-14 19:33:07 -070067
Davide Pesavento32065652017-01-15 01:52:21 -050068BOOST_AUTO_TEST_CASE(PersistencyChange)
69{
Davide Pesavento22fba352017-10-17 15:53:51 -040070 TRANSPORT_TEST_INIT();
Davide Pesavento32065652017-01-15 01:52:21 -050071
72 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), false);
73 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false);
74 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true);
75}
76
Davide Pesavento22fba352017-10-17 15:53:51 -040077BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveMultipleRemoteEndpoints, T, MulticastUdpTransportFixtures, T)
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070078{
Davide Pesavento22fba352017-10-17 15:53:51 -040079 TRANSPORT_TEST_INIT();
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070080
81 // remoteSockRx2 unnecessary for this test case - only remoteSockTx2 is needed
Davide Pesavento22fba352017-10-17 15:53:51 -040082 udp::socket remoteSockTx2(this->g_io);
Davide Pesavento8215a3a2017-12-25 19:14:33 -050083 MulticastUdpTransport::openTxSocket(remoteSockTx2, udp::endpoint(udp::v4(), 7071), true);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070084
85 Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
86 ndn::Buffer buf1(pkt1.begin(), pkt1.end());
Davide Pesavento22fba352017-10-17 15:53:51 -040087 this->remoteWrite(buf1);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070088
89 Block pkt2 = ndn::encoding::makeStringBlock(301, "world");
90 ndn::Buffer buf2(pkt2.begin(), pkt2.end());
Davide Pesavento22fba352017-10-17 15:53:51 -040091 this->remoteWrite(buf2);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070092
Davide Pesavento22fba352017-10-17 15:53:51 -040093 BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 2);
94 BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, buf1.size() + buf2.size());
95 BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -070096
Davide Pesavento22fba352017-10-17 15:53:51 -040097 BOOST_REQUIRE_EQUAL(this->receivedPackets->size(), 2);
98 BOOST_CHECK_EQUAL(this->receivedPackets->at(0).remoteEndpoint,
99 this->receivedPackets->at(1).remoteEndpoint);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700100
Davide Pesavento22fba352017-10-17 15:53:51 -0400101 udp::endpoint destEp(this->multicastEp.address(), this->localEp.port());
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700102 remoteSockTx2.async_send_to(boost::asio::buffer(buf1), destEp,
103 [] (const boost::system::error_code& error, size_t) {
104 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
105 });
106 remoteSockTx2.async_send_to(boost::asio::buffer(buf2), destEp,
107 [] (const boost::system::error_code& error, size_t) {
108 BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
109 });
Davide Pesavento22fba352017-10-17 15:53:51 -0400110 this->limitedIo.defer(time::seconds(1));
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700111
Davide Pesavento22fba352017-10-17 15:53:51 -0400112 BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 4);
113 BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, 2 * buf1.size() + 2 * buf2.size());
114 BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP);
Eric Newberry6d8ee7a2015-12-21 16:37:52 -0700115
Davide Pesavento22fba352017-10-17 15:53:51 -0400116 BOOST_REQUIRE_EQUAL(this->receivedPackets->size(), 4);
117 BOOST_CHECK_EQUAL(this->receivedPackets->at(2).remoteEndpoint,
118 this->receivedPackets->at(3).remoteEndpoint);
119 BOOST_CHECK_NE(this->receivedPackets->at(0).remoteEndpoint,
120 this->receivedPackets->at(2).remoteEndpoint);
Junxiao Shi13546112015-10-14 19:33:07 -0700121}
122
123BOOST_AUTO_TEST_SUITE_END() // TestMulticastUdpTransport
124BOOST_AUTO_TEST_SUITE_END() // Face
125
126} // namespace tests
127} // namespace face
128} // namespace nfd