blob: 79a0f380c635fa25a9aceb4d445cb6d5d24656e2 [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/*
Eric Newberryf3ee8082020-01-28 13:44:18 -08003 * Copyright (c) 2014-2020, 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
26#include "transport-test-common.hpp"
27
28#include "ethernet-fixture.hpp"
29
Eric Newberryfeeb9182020-03-29 00:28:41 -070030#include "common/global.hpp"
31
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040032namespace nfd {
33namespace face {
34namespace tests {
35
36BOOST_AUTO_TEST_SUITE(Face)
37BOOST_FIXTURE_TEST_SUITE(TestUnicastEthernetTransport, EthernetFixture)
38
39BOOST_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
53BOOST_AUTO_TEST_CASE(PersistencyChange)
54{
55 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
56 initializeUnicast();
57
Davide Pesavento1816d4b2017-07-02 12:20:48 -040058 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), true);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040059 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), true);
Davide Pesavento1816d4b2017-07-02 12:20:48 -040060 BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true);
61}
62
Eric Newberryfeeb9182020-03-29 00:28:41 -070063BOOST_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 Newberryf3ee8082020-01-28 13:44:18 -080091BOOST_AUTO_TEST_CASE(NetifMtuChange)
92{
93 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
94 initializeUnicast();
Eric Newberryfeeb9182020-03-29 00:28:41 -070095 BOOST_CHECK_EQUAL(transport->getMtu(), defaultNetif->getMtu());
Eric Newberryf3ee8082020-01-28 13:44:18 -080096
97 // netif changes MTU from initial value to 1024
Eric Newberryfeeb9182020-03-29 00:28:41 -070098 defaultNetif->setMtu(1024);
Eric Newberryf3ee8082020-01-28 13:44:18 -080099 BOOST_CHECK_EQUAL(transport->getMtu(), 1024);
100
101 // netif changes MTU from 1024 to 4000
Eric Newberryfeeb9182020-03-29 00:28:41 -0700102 defaultNetif->setMtu(4000);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800103 BOOST_CHECK_EQUAL(transport->getMtu(), 4000);
104
105 // netif changes MTU from 4000 to 0
Eric Newberryfeeb9182020-03-29 00:28:41 -0700106 defaultNetif->setMtu(0);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800107 BOOST_CHECK_EQUAL(transport->getMtu(), 0);
108}
109
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400110BOOST_AUTO_TEST_CASE(ExpirationTime)
111{
112 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
Eric Newberryfeeb9182020-03-29 00:28:41 -0700113 initializeUnicast(nullptr, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400114 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
123BOOST_AUTO_TEST_CASE(Close)
124{
Eric Newberryfeeb9182020-03-29 00:28:41 -0700125 SKIP_IF_NO_RUNNING_ETHERNET_NETIF();
126 initializeUnicast(getRunningNetif());
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400127
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400128 transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400129 BOOST_CHECK_EQUAL(oldState, TransportState::UP);
130 BOOST_CHECK_EQUAL(newState, TransportState::CLOSING);
131 });
132
133 transport->close();
134
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400135 transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400136 BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING);
137 BOOST_CHECK_EQUAL(newState, TransportState::CLOSED);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400138 this->limitedIo.afterOp();
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400139 });
140
Davide Pesavento14e71f02019-03-28 17:35:25 -0400141 BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400142}
143
144BOOST_AUTO_TEST_CASE(IdleClose)
145{
Eric Newberryfeeb9182020-03-29 00:28:41 -0700146 SKIP_IF_NO_RUNNING_ETHERNET_NETIF();
147 initializeUnicast(getRunningNetif(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400148
149 int nStateChanges = 0;
150 transport->afterStateChange.connect(
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400151 [this, &nStateChanges] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400152 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 Pesaventob3a23ca2019-05-04 20:40:21 -0400165 this->limitedIo.afterOp();
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400166 });
167
Davide Pesavento14e71f02019-03-28 17:35:25 -0400168 BOOST_REQUIRE_EQUAL(limitedIo.run(2, 5_s), LimitedIo::EXCEED_OPS);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400169 BOOST_CHECK_EQUAL(nStateChanges, 2);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400170}
171
Eric Newberryb49313d2017-12-24 20:22:27 -0700172BOOST_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 Pesavento6bd6d0b2017-03-25 15:16:40 -0400180BOOST_AUTO_TEST_SUITE_END() // TestUnicastEthernetTransport
181BOOST_AUTO_TEST_SUITE_END() // Face
182
183} // namespace tests
184} // namespace face
185} // namespace nfd