blob: 753f36ad3fe5f5c4810937ed53d534333c402d7f [file] [log] [blame]
Davide Pesavento43ff2a92017-05-18 19:50:57 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0d82d042017-07-07 06:15:27 +00002/*
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -04003 * Copyright (c) 2014-2020, Regents of the University of California,
Davide Pesavento43ff2a92017-05-18 19:50:57 -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 "face/ethernet-channel.hpp"
Davide Pesaventocb425e82019-07-14 21:48:22 -040027#include "face/face.hpp"
Davide Pesavento43ff2a92017-05-18 19:50:57 -040028
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/test-common.hpp"
Davide Pesavento43ff2a92017-05-18 19:50:57 -040030#include "ethernet-fixture.hpp"
31
32namespace nfd {
33namespace face {
34namespace tests {
35
36class EthernetChannelFixture : public EthernetFixture
37{
38protected:
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040039 shared_ptr<EthernetChannel>
Davide Pesavento43ff2a92017-05-18 19:50:57 -040040 makeChannel()
41 {
42 BOOST_ASSERT(netifs.size() > 0);
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040043 return std::make_shared<EthernetChannel>(netifs.front(), 2_s);
Davide Pesavento43ff2a92017-05-18 19:50:57 -040044 }
45};
46
47BOOST_AUTO_TEST_SUITE(Face)
48BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture)
49
50BOOST_AUTO_TEST_CASE(Uri)
51{
52 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
53
54 auto channel = makeChannel();
Junxiao Shi84d62cb2017-07-12 16:15:18 +000055 BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName()));
Davide Pesavento43ff2a92017-05-18 19:50:57 -040056}
57
58BOOST_AUTO_TEST_CASE(Listen)
59{
60 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
61
62 auto channel = makeChannel();
63 BOOST_CHECK_EQUAL(channel->isListening(), false);
64
65 channel->listen(nullptr, nullptr);
66 BOOST_CHECK_EQUAL(channel->isListening(), true);
67
68 // listen() is idempotent
69 BOOST_CHECK_NO_THROW(channel->listen(nullptr, nullptr));
70 BOOST_CHECK_EQUAL(channel->isListening(), true);
71}
72
73BOOST_AUTO_TEST_CASE(FaceClosure)
74{
75 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
76
77 auto channel = makeChannel();
78 BOOST_CHECK_EQUAL(channel->size(), 0);
79
80 shared_ptr<nfd::Face> face;
Davide Pesavento15b55052018-01-27 19:09:28 -050081 channel->connect({0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}, {},
Davide Pesavento43ff2a92017-05-18 19:50:57 -040082 [&face] (const shared_ptr<nfd::Face>& newFace) {
83 BOOST_REQUIRE(newFace != nullptr);
84 face = newFace;
85 },
86 [] (uint32_t status, const std::string& reason) {
87 BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]");
88 });
89 BOOST_CHECK_EQUAL(channel->size(), 1);
90 BOOST_REQUIRE(face != nullptr);
91
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040092 BOOST_CHECK_EQUAL(face->getChannel().lock(), channel);
93
Davide Pesavento43ff2a92017-05-18 19:50:57 -040094 face->close();
95 g_io.poll();
96 BOOST_CHECK_EQUAL(channel->size(), 0);
97}
98
99BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel
100BOOST_AUTO_TEST_SUITE_END() // Face
101
102} // namespace tests
103} // namespace face
104} // namespace nfd