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 | /* |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, 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 | |
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(); |
| 96 | BOOST_CHECK_EQUAL(transport->getMtu(), netif->getMtu()); |
| 97 | |
| 98 | // netif changes MTU from initial value to 1024 |
| 99 | netif->setMtu(1024); |
| 100 | BOOST_CHECK_EQUAL(transport->getMtu(), 1024); |
| 101 | |
| 102 | // netif changes MTU from 1024 to 4000 |
| 103 | netif->setMtu(4000); |
| 104 | BOOST_CHECK_EQUAL(transport->getMtu(), 4000); |
| 105 | |
| 106 | // netif changes MTU from 4000 to 0 |
| 107 | netif->setMtu(0); |
| 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 | { |
| 113 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 114 | initializeMulticast(); |
| 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 | |
| 143 | } // namespace tests |
| 144 | } // namespace face |
| 145 | } // namespace nfd |