Davide Pesavento | d7083a5 | 2023-10-19 17:51:16 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
| 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 | #ifndef NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP |
| 28 | |
| 29 | #include "face/multicast-ethernet-transport.hpp" |
| 30 | #include "face/unicast-ethernet-transport.hpp" |
| 31 | |
| 32 | #include "tests/daemon/limited-io.hpp" |
| 33 | #include "ethernet-fixture.hpp" |
| 34 | |
| 35 | namespace nfd::tests { |
| 36 | |
| 37 | class EthernetTransportFixture : public EthernetFixture |
| 38 | { |
| 39 | protected: |
| 40 | EthernetTransportFixture() |
| 41 | { |
| 42 | if (!netifs.empty()) { |
| 43 | defaultNetif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * \brief Returns the first running interface. |
| 49 | */ |
| 50 | shared_ptr<ndn::net::NetworkInterface> |
| 51 | getRunningNetif() const |
| 52 | { |
| 53 | for (const auto& netif : netifs) { |
| 54 | if (netif->getState() == ndn::net::InterfaceState::RUNNING) { |
| 55 | return const_pointer_cast<ndn::net::NetworkInterface>(netif); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return nullptr; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * \brief Create a UnicastEthernetTransport. |
| 64 | */ |
| 65 | void |
| 66 | initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr, |
| 67 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 68 | ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}) |
| 69 | { |
| 70 | if (!netif) { |
| 71 | netif = defaultNetif; |
| 72 | } |
| 73 | |
| 74 | localEp = netif->getName(); |
| 75 | remoteEp = remoteAddr; |
| 76 | transport = make_unique<face::UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * \brief Create a MulticastEthernetTransport. |
| 81 | */ |
| 82 | void |
| 83 | initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr, |
| 84 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS, |
| 85 | ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e}) |
| 86 | { |
| 87 | if (!netif) { |
| 88 | netif = defaultNetif; |
| 89 | } |
| 90 | |
| 91 | localEp = netif->getName(); |
| 92 | remoteEp = mcastGroup; |
| 93 | transport = make_unique<face::MulticastEthernetTransport>(*netif, remoteEp, linkType); |
| 94 | } |
| 95 | |
| 96 | protected: |
| 97 | LimitedIo limitedIo; |
| 98 | shared_ptr<ndn::net::NetworkInterface> defaultNetif; |
| 99 | unique_ptr<face::EthernetTransport> transport; |
| 100 | std::string localEp; |
| 101 | ethernet::Address remoteEp; |
| 102 | }; |
| 103 | |
| 104 | } // namespace nfd::tests |
| 105 | |
| 106 | #define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \ |
| 107 | do { \ |
| 108 | if (!this->getRunningNetif()) { \ |
| 109 | BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \ |
| 110 | "EthernetTransport-capable network interface"); \ |
| 111 | return; \ |
| 112 | } \ |
| 113 | } while (false) |
| 114 | |
| 115 | #endif // NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP |