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 | |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 30 | #include "common/global.hpp" |
| 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(TestUnicastEthernetTransport, EthernetFixture) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(StaticProperties) |
| 40 | { |
| 41 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 42 | initializeUnicast(); |
| 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_PERSISTENT); |
| 50 | BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_CASE(PersistencyChange) |
| 54 | { |
| 55 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 56 | initializeUnicast(); |
| 57 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), true); |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 59 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), true); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true); |
| 61 | } |
| 62 | |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 63 | BOOST_AUTO_TEST_CASE(NetifStateChange) |
| 64 | { |
| 65 | SKIP_IF_NO_RUNNING_ETHERNET_NETIF(); |
| 66 | auto netif = getRunningNetif(); |
| 67 | initializeUnicast(netif); |
| 68 | |
| 69 | // Simulate setting interface administratively down |
| 70 | getScheduler().schedule(10_ms, [netif] { netif->setState(ndn::net::InterfaceState::DOWN); }); |
| 71 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
| 72 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 73 | BOOST_CHECK_EQUAL(newState, TransportState::DOWN); |
| 74 | this->limitedIo.afterOp(); |
| 75 | }); |
| 76 | BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
| 77 | BOOST_CHECK_EQUAL(transport->getState(), TransportState::DOWN); |
| 78 | |
| 79 | // Simulate setting interface administratively up |
| 80 | getScheduler().schedule(10_ms, [netif] { netif->setState(ndn::net::InterfaceState::NO_CARRIER); }); |
| 81 | getScheduler().schedule(80_ms, [netif] { netif->setState(ndn::net::InterfaceState::RUNNING); }); |
| 82 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
| 83 | BOOST_CHECK_EQUAL(oldState, TransportState::DOWN); |
| 84 | BOOST_CHECK_EQUAL(newState, TransportState::UP); |
| 85 | this->limitedIo.afterOp(); |
| 86 | }); |
| 87 | BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
| 88 | BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP); |
| 89 | } |
| 90 | |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 91 | BOOST_AUTO_TEST_CASE(NetifMtuChange) |
| 92 | { |
| 93 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 94 | initializeUnicast(); |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 95 | BOOST_CHECK_EQUAL(transport->getMtu(), defaultNetif->getMtu()); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 96 | |
| 97 | // netif changes MTU from initial value to 1024 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 98 | defaultNetif->setMtu(1024); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(transport->getMtu(), 1024); |
| 100 | |
| 101 | // netif changes MTU from 1024 to 4000 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 102 | defaultNetif->setMtu(4000); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 103 | BOOST_CHECK_EQUAL(transport->getMtu(), 4000); |
| 104 | |
| 105 | // netif changes MTU from 4000 to 0 |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 106 | defaultNetif->setMtu(0); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(transport->getMtu(), 0); |
| 108 | } |
| 109 | |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 110 | BOOST_AUTO_TEST_CASE(ExpirationTime) |
| 111 | { |
| 112 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 113 | initializeUnicast(nullptr, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 114 | BOOST_CHECK_NE(transport->getExpirationTime(), time::steady_clock::TimePoint::max()); |
| 115 | |
| 116 | transport->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 117 | BOOST_CHECK_EQUAL(transport->getExpirationTime(), time::steady_clock::TimePoint::max()); |
| 118 | |
| 119 | transport->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 120 | BOOST_CHECK_NE(transport->getExpirationTime(), time::steady_clock::TimePoint::max()); |
| 121 | } |
| 122 | |
| 123 | BOOST_AUTO_TEST_CASE(Close) |
| 124 | { |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 125 | SKIP_IF_NO_RUNNING_ETHERNET_NETIF(); |
| 126 | initializeUnicast(getRunningNetif()); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 127 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 128 | transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 130 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 131 | }); |
| 132 | |
| 133 | transport->close(); |
| 134 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 135 | transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 136 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 137 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 138 | this->limitedIo.afterOp(); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 139 | }); |
| 140 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 141 | BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | BOOST_AUTO_TEST_CASE(IdleClose) |
| 145 | { |
Eric Newberry | feeb918 | 2020-03-29 00:28:41 -0700 | [diff] [blame^] | 146 | SKIP_IF_NO_RUNNING_ETHERNET_NETIF(); |
| 147 | initializeUnicast(getRunningNetif(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 148 | |
| 149 | int nStateChanges = 0; |
| 150 | transport->afterStateChange.connect( |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 151 | [this, &nStateChanges] (auto oldState, auto newState) { |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 152 | switch (nStateChanges) { |
| 153 | case 0: |
| 154 | BOOST_CHECK_EQUAL(oldState, TransportState::UP); |
| 155 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSING); |
| 156 | break; |
| 157 | case 1: |
| 158 | BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING); |
| 159 | BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); |
| 160 | break; |
| 161 | default: |
| 162 | BOOST_CHECK(false); |
| 163 | } |
| 164 | nStateChanges++; |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 165 | this->limitedIo.afterOp(); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 166 | }); |
| 167 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 168 | BOOST_REQUIRE_EQUAL(limitedIo.run(2, 5_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | 1816d4b | 2017-07-02 12:20:48 -0400 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(nStateChanges, 2); |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 172 | BOOST_AUTO_TEST_CASE(SendQueueLength) |
| 173 | { |
| 174 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 175 | initializeUnicast(); |
| 176 | |
| 177 | BOOST_CHECK_EQUAL(transport->getSendQueueLength(), QUEUE_UNSUPPORTED); |
| 178 | } |
| 179 | |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 180 | BOOST_AUTO_TEST_SUITE_END() // TestUnicastEthernetTransport |
| 181 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 182 | |
| 183 | } // namespace tests |
| 184 | } // namespace face |
| 185 | } // namespace nfd |