blob: 8dde05fc21d0cfc19e7a28982f476e4fc1be784e [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 Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, 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
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040030#include "common/global.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060031
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040032namespace nfd {
33namespace face {
34namespace tests {
35
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{
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 Pesaventob3a23ca2019-05-04 20:40:21 -040071 getScheduler().schedule(10_ms, [this] { netif->setState(ndn::net::InterfaceState::DOWN); });
72 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
80 // simulate 'ip link set IFNAME up'
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040081 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 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
Davide Pesavento1816d4b2017-07-02 12:20:48 -040092BOOST_AUTO_TEST_CASE(Close)
93{
94 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
95 initializeMulticast();
96
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040097 transport->afterStateChange.connectSingleShot([] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -040098 BOOST_CHECK_EQUAL(oldState, TransportState::UP);
99 BOOST_CHECK_EQUAL(newState, TransportState::CLOSING);
100 });
101
102 transport->close();
103
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400104 transport->afterStateChange.connectSingleShot([this] (auto oldState, auto newState) {
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400105 BOOST_CHECK_EQUAL(oldState, TransportState::CLOSING);
106 BOOST_CHECK_EQUAL(newState, TransportState::CLOSED);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400107 this->limitedIo.afterOp();
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400108 });
109
Davide Pesavento14e71f02019-03-28 17:35:25 -0400110 BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400111}
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400112
Eric Newberryb49313d2017-12-24 20:22:27 -0700113BOOST_AUTO_TEST_CASE(SendQueueLength)
114{
115 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
116 initializeMulticast();
117
118 BOOST_CHECK_EQUAL(transport->getSendQueueLength(), QUEUE_UNSUPPORTED);
119}
120
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400121BOOST_AUTO_TEST_SUITE_END() // TestMulticastEthernetTransport
122BOOST_AUTO_TEST_SUITE_END() // Face
123
124} // namespace tests
125} // namespace face
126} // namespace nfd