Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 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 | |
| 26 | #include "transport-test-common.hpp" |
| 27 | |
| 28 | #include "ethernet-fixture.hpp" |
| 29 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 30 | #include "common/global.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 31 | |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | namespace tests { |
| 35 | |
| 36 | BOOST_AUTO_TEST_SUITE(Face) |
| 37 | BOOST_FIXTURE_TEST_SUITE(TestMulticastEthernetTransport, EthernetFixture) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(StaticProperties) |
| 40 | { |
| 41 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 42 | initializeMulticast(); |
| 43 | |
| 44 | checkStaticPropertiesInitialized(*transport); |
| 45 | |
| 46 | BOOST_CHECK_EQUAL(transport->getLocalUri(), FaceUri("dev://" + localEp)); |
| 47 | BOOST_CHECK_EQUAL(transport->getRemoteUri(), FaceUri("ether://[" + remoteEp.toString() + "]")); |
| 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); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(transport->getSendQueueCapacity(), QUEUE_UNSUPPORTED); |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE(PersistencyChange) |
| 55 | { |
| 56 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 57 | initializeMulticast(); |
| 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 | |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 64 | BOOST_AUTO_TEST_CASE(NetifStateChange) |
| 65 | { |
| 66 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 67 | initializeMulticast(); |
| 68 | BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP); |
| 69 | |
| 70 | // simulate 'ip link set IFNAME down' |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 71 | getScheduler().schedule(10_ms, [this] { netif->setState(ndn::net::InterfaceState::DOWN); }); |
| 72 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 74 | BOOST_CHECK_EQUAL(newState, TransportState::DOWN); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 75 | this->limitedIo.afterOp(); |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 76 | }); |
| 77 | BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
| 78 | BOOST_CHECK_EQUAL(transport->getState(), TransportState::DOWN); |
| 79 | |
| 80 | // simulate 'ip link set IFNAME up' |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 81 | getScheduler().schedule(10_ms, [this] { netif->setState(ndn::net::InterfaceState::NO_CARRIER); }); |
| 82 | getScheduler().schedule(80_ms, [this] { netif->setState(ndn::net::InterfaceState::RUNNING); }); |
| 83 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(oldState, TransportState::DOWN); |
| 85 | BOOST_CHECK_EQUAL(newState, TransportState::UP); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 86 | this->limitedIo.afterOp(); |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 87 | }); |
| 88 | BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
| 89 | BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP); |
| 90 | } |
| 91 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(Close) |
| 93 | { |
| 94 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 95 | initializeMulticast(); |
| 96 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 97 | transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 99 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 100 | }); |
| 101 | |
| 102 | transport->close(); |
| 103 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 104 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 105 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 106 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 107 | this->limitedIo.afterOp(); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 108 | }); |
| 109 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 110 | BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 111 | } |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 112 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 113 | BOOST_AUTO_TEST_CASE(SendQueueLength) |
| 114 | { |
| 115 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 116 | initializeMulticast(); |
| 117 | |
| 118 | BOOST_CHECK_EQUAL(transport->getSendQueueLength(), QUEUE_UNSUPPORTED); |
| 119 | } |
| 120 | |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 121 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastEthernetTransport |
| 122 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 123 | |
| 124 | } // namespace tests |
| 125 | } // namespace face |
| 126 | } // namespace nfd |