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 | d7083a5 | 2023-10-19 17:51:16 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, 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 | |
Davide Pesavento | d7083a5 | 2023-10-19 17:51:16 -0400 | [diff] [blame^] | 26 | #include "ethernet-transport-fixture.hpp" |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 27 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 28 | #include "common/global.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 29 | |
Davide Pesavento | 279af1c | 2022-08-29 20:18:32 -0400 | [diff] [blame] | 30 | #include "tests/daemon/face/transport-test-common.hpp" |
| 31 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 32 | namespace nfd::tests { |
| 33 | |
| 34 | using namespace nfd::face; |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_SUITE(Face) |
Davide Pesavento | d7083a5 | 2023-10-19 17:51:16 -0400 | [diff] [blame^] | 37 | BOOST_FIXTURE_TEST_SUITE(TestMulticastEthernetTransport, EthernetTransportFixture) |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 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 | { |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 66 | SKIP_IF_NO_RUNNING_ETHERNET_NETIF(); |
| 67 | auto netif = getRunningNetif(); |
| 68 | initializeMulticast(netif); |
Junxiao Shi | fbdd5ce | 2018-11-26 15:10:51 +0000 | [diff] [blame] | 69 | |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 70 | // Simulate setting interface administratively down |
| 71 | getScheduler().schedule(10_ms, [netif] { netif->setState(ndn::net::InterfaceState::DOWN); }); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 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 | |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 80 | // Simulate setting interface administratively up |
| 81 | getScheduler().schedule(10_ms, [netif] { netif->setState(ndn::net::InterfaceState::NO_CARRIER); }); |
| 82 | getScheduler().schedule(80_ms, [netif] { netif->setState(ndn::net::InterfaceState::RUNNING); }); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 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 | |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(NetifMtuChange) |
| 93 | { |
| 94 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 95 | initializeMulticast(); |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 96 | BOOST_CHECK_EQUAL(transport->getMtu(), defaultNetif->getMtu()); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 97 | |
| 98 | // netif changes MTU from initial value to 1024 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 99 | defaultNetif->setMtu(1024); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(transport->getMtu(), 1024); |
| 101 | |
| 102 | // netif changes MTU from 1024 to 4000 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 103 | defaultNetif->setMtu(4000); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(transport->getMtu(), 4000); |
| 105 | |
| 106 | // netif changes MTU from 4000 to 0 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 107 | defaultNetif->setMtu(0); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 108 | BOOST_CHECK_EQUAL(transport->getMtu(), 0); |
| 109 | } |
| 110 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(Close) |
| 112 | { |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame] | 113 | SKIP_IF_NO_RUNNING_ETHERNET_NETIF(); |
| 114 | initializeMulticast(getRunningNetif()); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 115 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 116 | transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 118 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 119 | }); |
| 120 | |
| 121 | transport->close(); |
| 122 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 123 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 125 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 126 | this->limitedIo.afterOp(); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 127 | }); |
| 128 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 129 | BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 130 | } |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 131 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 132 | BOOST_AUTO_TEST_CASE(SendQueueLength) |
| 133 | { |
| 134 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 135 | initializeMulticast(); |
| 136 | |
| 137 | BOOST_CHECK_EQUAL(transport->getSendQueueLength(), QUEUE_UNSUPPORTED); |
| 138 | } |
| 139 | |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 140 | BOOST_AUTO_TEST_SUITE_END() // TestMulticastEthernetTransport |
| 141 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 142 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 143 | } // namespace nfd::tests |