blob: 2791ca795da6287528887a8c291b346f5477e6b5 [file] [log] [blame]
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberryb49313d2017-12-24 20:22:27 -07002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -04004 * 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 Pesavento6bd6d0b2017-03-25 15:16:40 -040026#include "ethernet-fixture.hpp"
27
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040028#include "common/global.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060029
Davide Pesavento279af1c2022-08-29 20:18:32 -040030#include "tests/daemon/face/transport-test-common.hpp"
31
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::tests {
33
34using namespace nfd::face;
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040035
36BOOST_AUTO_TEST_SUITE(Face)
37BOOST_FIXTURE_TEST_SUITE(TestMulticastEthernetTransport, EthernetFixture)
38
39BOOST_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 Newberryb49313d2017-12-24 20:22:27 -070051 BOOST_CHECK_EQUAL(transport->getSendQueueCapacity(), QUEUE_UNSUPPORTED);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040052}
53
54BOOST_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 Shifbdd5ce2018-11-26 15:10:51 +000064BOOST_AUTO_TEST_CASE(NetifStateChange)
65{
Eric Newberryfeeb9182020-03-29 00:28:41 -070066 SKIP_IF_NO_RUNNING_ETHERNET_NETIF();
67 auto netif = getRunningNetif();
68 initializeMulticast(netif);
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000069
Eric Newberryfeeb9182020-03-29 00:28:41 -070070 // Simulate setting interface administratively down
71 getScheduler().schedule(10_ms, [netif] { netif->setState(ndn::net::InterfaceState::DOWN); });
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040072 transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) {
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000073 BOOST_CHECK_EQUAL(oldState, TransportState::UP);
74 BOOST_CHECK_EQUAL(newState, TransportState::DOWN);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040075 this->limitedIo.afterOp();
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000076 });
77 BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
78 BOOST_CHECK_EQUAL(transport->getState(), TransportState::DOWN);
79
Eric Newberryfeeb9182020-03-29 00:28:41 -070080 // 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 Pesaventob3a23ca2019-05-04 20:40:21 -040083 transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) {
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000084 BOOST_CHECK_EQUAL(oldState, TransportState::DOWN);
85 BOOST_CHECK_EQUAL(newState, TransportState::UP);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040086 this->limitedIo.afterOp();
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000087 });
88 BOOST_CHECK_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
89 BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
90}
91
Eric Newberryf3ee8082020-01-28 13:44:18 -080092BOOST_AUTO_TEST_CASE(NetifMtuChange)
93{
94 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
95 initializeMulticast();
Eric Newberryfeeb9182020-03-29 00:28:41 -070096 BOOST_CHECK_EQUAL(transport->getMtu(), defaultNetif->getMtu());
Eric Newberryf3ee8082020-01-28 13:44:18 -080097
98 // netif changes MTU from initial value to 1024
Eric Newberryfeeb9182020-03-29 00:28:41 -070099 defaultNetif->setMtu(1024);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800100 BOOST_CHECK_EQUAL(transport->getMtu(), 1024);
101
102 // netif changes MTU from 1024 to 4000
Eric Newberryfeeb9182020-03-29 00:28:41 -0700103 defaultNetif->setMtu(4000);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800104 BOOST_CHECK_EQUAL(transport->getMtu(), 4000);
105
106 // netif changes MTU from 4000 to 0
Eric Newberryfeeb9182020-03-29 00:28:41 -0700107 defaultNetif->setMtu(0);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800108 BOOST_CHECK_EQUAL(transport->getMtu(), 0);
109}
110
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400111BOOST_AUTO_TEST_CASE(Close)
112{
Eric Newberryfeeb9182020-03-29 00:28:41 -0700113 SKIP_IF_NO_RUNNING_ETHERNET_NETIF();
114 initializeMulticast(getRunningNetif());
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400115
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400116 transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400117 BOOST_CHECK_EQUAL(oldState, TransportState::UP);
118 BOOST_CHECK_EQUAL(newState, TransportState::CLOSING);
119 });
120
121 transport->close();
122
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400123 transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400124 BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING);
125 BOOST_CHECK_EQUAL(newState, TransportState::CLOSED);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400126 this->limitedIo.afterOp();
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400127 });
128
Davide Pesavento14e71f02019-03-28 17:35:25 -0400129 BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400130}
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400131
Eric Newberryb49313d2017-12-24 20:22:27 -0700132BOOST_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 Pesavento6bd6d0b2017-03-25 15:16:40 -0400140BOOST_AUTO_TEST_SUITE_END() // TestMulticastEthernetTransport
141BOOST_AUTO_TEST_SUITE_END() // Face
142
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400143} // namespace nfd::tests