blob: c1311da089ceb48e7a515295edad441c4dc33904 [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/*
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04003 * Copyright (c) 2014-2019, 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"
27
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040028#include "tests/test-common.hpp"
Davide Pesavento43ff2a92017-05-18 19:50:57 -040029#include "ethernet-fixture.hpp"
30
31namespace nfd {
32namespace face {
33namespace tests {
34
35class EthernetChannelFixture : public EthernetFixture
36{
37protected:
38 unique_ptr<EthernetChannel>
39 makeChannel()
40 {
41 BOOST_ASSERT(netifs.size() > 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -040042 return make_unique<EthernetChannel>(netifs.front(), 2_s);
Davide Pesavento43ff2a92017-05-18 19:50:57 -040043 }
44};
45
46BOOST_AUTO_TEST_SUITE(Face)
47BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture)
48
49BOOST_AUTO_TEST_CASE(Uri)
50{
51 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
52
53 auto channel = makeChannel();
Junxiao Shi84d62cb2017-07-12 16:15:18 +000054 BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName()));
Davide Pesavento43ff2a92017-05-18 19:50:57 -040055}
56
57BOOST_AUTO_TEST_CASE(Listen)
58{
59 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
60
61 auto channel = makeChannel();
62 BOOST_CHECK_EQUAL(channel->isListening(), false);
63
64 channel->listen(nullptr, nullptr);
65 BOOST_CHECK_EQUAL(channel->isListening(), true);
66
67 // listen() is idempotent
68 BOOST_CHECK_NO_THROW(channel->listen(nullptr, nullptr));
69 BOOST_CHECK_EQUAL(channel->isListening(), true);
70}
71
72BOOST_AUTO_TEST_CASE(FaceClosure)
73{
74 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
75
76 auto channel = makeChannel();
77 BOOST_CHECK_EQUAL(channel->size(), 0);
78
79 shared_ptr<nfd::Face> face;
Davide Pesavento15b55052018-01-27 19:09:28 -050080 channel->connect({0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}, {},
Davide Pesavento43ff2a92017-05-18 19:50:57 -040081 [&face] (const shared_ptr<nfd::Face>& newFace) {
82 BOOST_REQUIRE(newFace != nullptr);
83 face = newFace;
84 },
85 [] (uint32_t status, const std::string& reason) {
86 BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]");
87 });
88 BOOST_CHECK_EQUAL(channel->size(), 1);
89 BOOST_REQUIRE(face != nullptr);
90
91 face->close();
92 g_io.poll();
93 BOOST_CHECK_EQUAL(channel->size(), 0);
94}
95
96BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel
97BOOST_AUTO_TEST_SUITE_END() // Face
98
99} // namespace tests
100} // namespace face
101} // namespace nfd