blob: 0c98c7209fb97d18946b036cde31f72f8edaef73 [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/*
Eric Newberryfeeb9182020-03-29 00:28:41 -07003 * Copyright (c) 2014-2020, 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
35namespace nfd {
Eric Newberry8717e872015-11-23 12:41:50 -070036namespace face {
Davide Pesavento35120ea2015-11-17 21:13:18 +010037namespace tests {
38
Davide Pesavento1816d4b2017-07-02 12:20:48 -040039using namespace nfd::tests;
40
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041/** \brief Fixture providing a list of EthernetTransport-capable network interfaces.
Junxiao Shi84d62cb2017-07-12 16:15:18 +000042 */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040043class EthernetFixture : public virtual GlobalIoFixture
Davide Pesavento35120ea2015-11-17 21:13:18 +010044{
45protected:
Junxiao Shi7003c602017-01-10 13:35:28 +000046 EthernetFixture()
Davide Pesavento35120ea2015-11-17 21:13:18 +010047 {
Junxiao Shi84d62cb2017-07-12 16:15:18 +000048 for (const auto& netif : collectNetworkInterfaces()) {
49 if (!netif->isLoopback() && netif->isUp()) {
Davide Pesavento35120ea2015-11-17 21:13:18 +010050 try {
Junxiao Shi84d62cb2017-07-12 16:15:18 +000051 MulticastEthernetTransport transport(*netif, ethernet::getBroadcastAddress(),
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040052 ndn::nfd::LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7003c602017-01-10 13:35:28 +000053 netifs.push_back(netif);
Davide Pesavento35120ea2015-11-17 21:13:18 +010054 }
Junxiao Shi7003c602017-01-10 13:35:28 +000055 catch (const EthernetTransport::Error&) {
56 // ignore
Davide Pesavento35120ea2015-11-17 21:13:18 +010057 }
58 }
59 }
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000060 if (!netifs.empty()) {
Eric Newberryfeeb9182020-03-29 00:28:41 -070061 defaultNetif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000062 }
Davide Pesavento35120ea2015-11-17 21:13:18 +010063 }
64
Eric Newberryfeeb9182020-03-29 00:28:41 -070065 /** \brief returns the first running interface
66 */
67 shared_ptr<ndn::net::NetworkInterface>
68 getRunningNetif() const
69 {
70 for (const auto& netif : netifs) {
71 if (netif->getState() == ndn::net::InterfaceState::RUNNING) {
72 return const_pointer_cast<ndn::net::NetworkInterface>(netif);
73 }
74 }
75
76 return nullptr;
77 }
78
Junxiao Shi84d62cb2017-07-12 16:15:18 +000079 /** \brief create a UnicastEthernetTransport
80 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040081 void
Eric Newberryfeeb9182020-03-29 00:28:41 -070082 initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
83 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesavento1816d4b2017-07-02 12:20:48 -040084 ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040085 {
Eric Newberryfeeb9182020-03-29 00:28:41 -070086 if (!netif) {
87 netif = defaultNetif;
88 }
89
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000090 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040091 remoteEp = remoteAddr;
Davide Pesavento14e71f02019-03-28 17:35:25 -040092 transport = make_unique<UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040093 }
94
Junxiao Shi84d62cb2017-07-12 16:15:18 +000095 /** \brief create a MulticastEthernetTransport
96 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040097 void
Eric Newberryfeeb9182020-03-29 00:28:41 -070098 initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
99 ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400100 ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400101 {
Eric Newberryfeeb9182020-03-29 00:28:41 -0700102 if (!netif) {
103 netif = defaultNetif;
104 }
105
Junxiao Shifbdd5ce2018-11-26 15:10:51 +0000106 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400107 remoteEp = mcastGroup;
Junxiao Shifbdd5ce2018-11-26 15:10:51 +0000108 transport = make_unique<MulticastEthernetTransport>(*netif, remoteEp, linkType);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400109 }
110
Davide Pesavento35120ea2015-11-17 21:13:18 +0100111protected:
Davide Pesavento1816d4b2017-07-02 12:20:48 -0400112 LimitedIo limitedIo;
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -0400113
Junxiao Shi7003c602017-01-10 13:35:28 +0000114 /** \brief EthernetTransport-capable network interfaces
115 */
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000116 std::vector<shared_ptr<const ndn::net::NetworkInterface>> netifs;
117
Eric Newberryfeeb9182020-03-29 00:28:41 -0700118 shared_ptr<ndn::net::NetworkInterface> defaultNetif;
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000119 unique_ptr<EthernetTransport> transport;
120 std::string localEp;
121 ethernet::Address remoteEp;
Davide Pesavento35120ea2015-11-17 21:13:18 +0100122};
123
Junxiao Shi7003c602017-01-10 13:35:28 +0000124#define SKIP_IF_ETHERNET_NETIF_COUNT_LT(n) \
125 do { \
126 if (this->netifs.size() < (n)) { \
127 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
128 " or more EthernetTransport-capable network interfaces"); \
129 return; \
130 } \
Davide Pesavento35120ea2015-11-17 21:13:18 +0100131 } while (false)
132
Eric Newberryfeeb9182020-03-29 00:28:41 -0700133#define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \
134 do { \
135 if (!this->getRunningNetif()) { \
136 BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \
137 "EthernetTransport-capable network interface"); \
138 return; \
139 } \
140 } while (false)
141
Davide Pesavento35120ea2015-11-17 21:13:18 +0100142} // namespace tests
Eric Newberry8717e872015-11-23 12:41:50 -0700143} // namespace face
Davide Pesavento35120ea2015-11-17 21:13:18 +0100144} // namespace nfd
145
Junxiao Shi7003c602017-01-10 13:35:28 +0000146#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP