blob: 1898d507cf8ab827db2d30b967c9667eedc94cd6 [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 Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, 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()) {
61 netif = const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
62 }
Davide Pesavento35120ea2015-11-17 21:13:18 +010063 }
64
Junxiao Shi84d62cb2017-07-12 16:15:18 +000065 /** \brief create a UnicastEthernetTransport
66 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040067 void
Davide Pesavento1816d4b2017-07-02 12:20:48 -040068 initializeUnicast(ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
69 ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040070 {
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000071 BOOST_ASSERT(netif != nullptr);
72 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040073 remoteEp = remoteAddr;
Davide Pesavento14e71f02019-03-28 17:35:25 -040074 transport = make_unique<UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040075 }
76
Junxiao Shi84d62cb2017-07-12 16:15:18 +000077 /** \brief create a MulticastEthernetTransport
78 */
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040079 void
Davide Pesavento1816d4b2017-07-02 12:20:48 -040080 initializeMulticast(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
81 ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040082 {
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000083 BOOST_ASSERT(netif != nullptr);
84 localEp = netif->getName();
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040085 remoteEp = mcastGroup;
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000086 transport = make_unique<MulticastEthernetTransport>(*netif, remoteEp, linkType);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040087 }
88
Davide Pesavento35120ea2015-11-17 21:13:18 +010089protected:
Davide Pesavento1816d4b2017-07-02 12:20:48 -040090 LimitedIo limitedIo;
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040091
Junxiao Shi7003c602017-01-10 13:35:28 +000092 /** \brief EthernetTransport-capable network interfaces
93 */
Junxiao Shi84d62cb2017-07-12 16:15:18 +000094 std::vector<shared_ptr<const ndn::net::NetworkInterface>> netifs;
95
Junxiao Shifbdd5ce2018-11-26 15:10:51 +000096 shared_ptr<ndn::net::NetworkInterface> netif;
Junxiao Shi84d62cb2017-07-12 16:15:18 +000097 unique_ptr<EthernetTransport> transport;
98 std::string localEp;
99 ethernet::Address remoteEp;
Davide Pesavento35120ea2015-11-17 21:13:18 +0100100};
101
Junxiao Shi7003c602017-01-10 13:35:28 +0000102#define SKIP_IF_ETHERNET_NETIF_COUNT_LT(n) \
103 do { \
104 if (this->netifs.size() < (n)) { \
105 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
106 " or more EthernetTransport-capable network interfaces"); \
107 return; \
108 } \
Davide Pesavento35120ea2015-11-17 21:13:18 +0100109 } while (false)
110
111} // namespace tests
Eric Newberry8717e872015-11-23 12:41:50 -0700112} // namespace face
Davide Pesavento35120ea2015-11-17 21:13:18 +0100113} // namespace nfd
114
Junxiao Shi7003c602017-01-10 13:35:28 +0000115#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP