Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 4 | * 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 Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 27 | #include "face/face.hpp" |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 28 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 30 | #include "ethernet-fixture.hpp" |
| 31 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 32 | namespace nfd::tests { |
| 33 | |
| 34 | using face::EthernetChannel; |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 35 | |
| 36 | class EthernetChannelFixture : public EthernetFixture |
| 37 | { |
| 38 | protected: |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 39 | shared_ptr<EthernetChannel> |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 40 | makeChannel() |
| 41 | { |
| 42 | BOOST_ASSERT(netifs.size() > 0); |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 43 | return std::make_shared<EthernetChannel>(netifs.front(), 2_s); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 44 | } |
| 45 | }; |
| 46 | |
| 47 | BOOST_AUTO_TEST_SUITE(Face) |
| 48 | BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture) |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE(Uri) |
| 51 | { |
| 52 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 53 | |
| 54 | auto channel = makeChannel(); |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName())); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | BOOST_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 | |
| 73 | BOOST_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 Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 81 | channel->connect({0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}, {}, |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 82 | [&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 Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(face->getChannel().lock(), channel); |
| 93 | |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 94 | face->close(); |
| 95 | g_io.poll(); |
| 96 | BOOST_CHECK_EQUAL(channel->size(), 0); |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel |
| 100 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 101 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 102 | } // namespace nfd::tests |