blob: dfd5615ebf0f38a5748b4ad42e84815239870815 [file] [log] [blame]
Davide Pesavento35120ea2015-11-17 21:13:18 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0d82d042017-07-07 06:15:27 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesavento35120ea2015-11-17 21:13:18 +01004 * 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
Junxiao Shi7003c602017-01-10 13:35:28 +000026#ifndef NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP
27#define NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP
Davide Pesavento35120ea2015-11-17 21:13:18 +010028
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040029#include "face/multicast-ethernet-transport.hpp"
30#include "face/unicast-ethernet-transport.hpp"
Davide Pesavento35120ea2015-11-17 21:13:18 +010031
Davide Pesavento3dade002019-03-19 11:29:56 -060032#include "tests/daemon/limited-io.hpp"
Davide Pesavento22fba352017-10-17 15:53:51 -040033#include "test-netif.hpp"
Davide Pesavento35120ea2015-11-17 21:13:18 +010034
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035namespace nfd::tests {
Davide Pesavento35120ea2015-11-17 21:13:18 +010036
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040037using face::EthernetTransport;
38using face::MulticastEthernetTransport;
39using face::UnicastEthernetTransport;
Davide Pesavento1816d4b2017-07-02 12:20:48 -040040
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040041/**
42 * \brief Fixture providing a list of EthernetTransport-capable network interfaces.
Junxiao Shi84d62cb2017-07-12 16:15:18 +000043 */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040044class EthernetFixture : public virtual GlobalIoFixture
Davide Pesavento35120ea2015-11-17 21:13:18 +010045{
46protected:
Junxiao Shi7003c602017-01-10 13:35:28 +000047 EthernetFixture()
Davide Pesavento35120ea2015-11-17 21:13:18 +010048 {
Junxiao Shi84d62cb2017-07-12 16:15:18 +000049 for (const auto& netif : collectNetworkInterfaces()) {
50 if (!netif->isLoopback() && netif->isUp()) {
Davide Pesavento35120ea2015-11-17 21:13:18 +010051 try {
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040052 MulticastEthernetTransport t(*netif, ethernet::getBroadcastAddress(),
53 ndn::nfd::LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7003c602017-01-10 13:35:28 +000054 netifs.push_back(netif);
Davide Pesavento35120ea2015-11-17 21:13:18 +010055 }
Junxiao Shi7003c602017-01-10 13:35:28 +000056 catch (const EthernetTransport::Error&) {
57 // ignore
Davide Pesavento35120ea2015-11-17 21:13:18 +010058 }
59 }
60 }
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000061 if (!netifs.empty()) {
Eric Newberryfeeb9182020-03-29 00:28:41 -070062 defaultNetif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000063 }
Davide Pesavento35120ea2015-11-17 21:13:18 +010064 }
65
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040066 /** \brief Returns the first running interface.
Eric Newberryfeeb9182020-03-29 00:28:41 -070067 */
68 shared_ptr<ndn::net::NetworkInterface>
69 getRunningNetif() const
70 {
71 for (const auto& netif : netifs) {
72 if (netif->getState() == ndn::net::InterfaceState::RUNNING) {
73 return const_pointer_cast<ndn::net::NetworkInterface>(netif);
74 }
75 }
76
77 return nullptr;
78 }
79
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040080 /** \brief Create a UnicastEthernetTransport.
Junxiao Shi84d62cb2017-07-12 16:15:18 +000081 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040082 void
Eric Newberryfeeb9182020-03-29 00:28:41 -070083 initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
84 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesavento1816d4b2017-07-02 12:20:48 -040085 ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040086 {
Eric Newberryfeeb9182020-03-29 00:28:41 -070087 if (!netif) {
88 netif = defaultNetif;
89 }
90
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000091 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040092 remoteEp = remoteAddr;
Davide Pesavento14e71f02019-03-28 17:35:25 -040093 transport = make_unique<UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040094 }
95
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040096 /** \brief Create a MulticastEthernetTransport.
Junxiao Shi84d62cb2017-07-12 16:15:18 +000097 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040098 void
Eric Newberryfeeb9182020-03-29 00:28:41 -070099 initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
100 ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400101 ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400102 {
Eric Newberryfeeb9182020-03-29 00:28:41 -0700103 if (!netif) {
104 netif = defaultNetif;
105 }
106
Junxiao Shifbdd5ce2018-11-26 15:10:51 +0000107 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400108 remoteEp = mcastGroup;
Junxiao Shifbdd5ce2018-11-26 15:10:51 +0000109 transport = make_unique<MulticastEthernetTransport>(*netif, remoteEp, linkType);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400110 }
111
Davide Pesavento35120ea2015-11-17 21:13:18 +0100112protected:
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400113 LimitedIo limitedIo;
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400114
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400115 /** \brief EthernetTransport-capable network interfaces.
Junxiao Shi7003c602017-01-10 13:35:28 +0000116 */
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000117 std::vector<shared_ptr<const ndn::net::NetworkInterface>> netifs;
118
Eric Newberryfeeb9182020-03-29 00:28:41 -0700119 shared_ptr<ndn::net::NetworkInterface> defaultNetif;
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000120 unique_ptr<EthernetTransport> transport;
121 std::string localEp;
122 ethernet::Address remoteEp;
Davide Pesavento35120ea2015-11-17 21:13:18 +0100123};
124
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400125} // namespace nfd::tests
126
Junxiao Shi7003c602017-01-10 13:35:28 +0000127#define SKIP_IF_ETHERNET_NETIF_COUNT_LT(n) \
128 do { \
129 if (this->netifs.size() < (n)) { \
130 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
131 " or more EthernetTransport-capable network interfaces"); \
132 return; \
133 } \
Davide Pesavento35120ea2015-11-17 21:13:18 +0100134 } while (false)
135
Eric Newberryfeeb9182020-03-29 00:28:41 -0700136#define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \
137 do { \
138 if (!this->getRunningNetif()) { \
139 BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \
140 "EthernetTransport-capable network interface"); \
141 return; \
142 } \
143 } while (false)
144
Junxiao Shi7003c602017-01-10 13:35:28 +0000145#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP