Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 1 | /* -*- 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 Newberry | 8717e87 | 2015-11-23 12:41:50 -0700 | [diff] [blame] | 26 | #include "transport-test-common.hpp" |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 27 | |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 28 | #include "multicast-udp-transport-fixture.hpp" |
| 29 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 30 | namespace nfd { |
| 31 | namespace face { |
| 32 | namespace tests { |
| 33 | |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(Face) |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TestMulticastUdpTransport, MulticastUdpTransportFixture) |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 36 | |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(StaticPropertiesNonLocalIpv4) |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 38 | { |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 39 | SKIP_IF_IP_UNAVAILABLE(defaultAddr); |
| 40 | initialize(defaultAddr); |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 41 | |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 42 | checkStaticPropertiesInitialized(*transport); |
Junxiao Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 43 | |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 44 | 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 Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 53 | |
Eric Newberry | 6d8ee7a | 2015-12-21 16:37:52 -0700 | [diff] [blame] | 54 | BOOST_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 Shi | 1354611 | 2015-10-14 19:33:07 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastUdpTransport |
| 105 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 106 | |
| 107 | } // namespace tests |
| 108 | } // namespace face |
| 109 | } // namespace nfd |