blob: c1f2b8efe032539365eb1471d702842e20fff56d [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/*
Junxiao Shi7003c602017-01-10 13:35:28 +00003 * Copyright (c) 2014-2017, 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
29#include "core/network-interface.hpp"
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040030#include "face/multicast-ethernet-transport.hpp"
31#include "face/unicast-ethernet-transport.hpp"
Davide Pesavento35120ea2015-11-17 21:13:18 +010032
Davide Pesavento1816d4b2017-07-02 12:20:48 -040033#include "tests/limited-io.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
41class EthernetFixture : public virtual BaseFixture
Davide Pesavento35120ea2015-11-17 21:13:18 +010042{
43protected:
Junxiao Shi7003c602017-01-10 13:35:28 +000044 EthernetFixture()
Davide Pesavento35120ea2015-11-17 21:13:18 +010045 {
46 for (const auto& netif : listNetworkInterfaces()) {
47 if (!netif.isLoopback() && netif.isUp()) {
48 try {
Junxiao Shi0d82d042017-07-07 06:15:27 +000049 MulticastEthernetTransport transport(*netif.asNetworkInterface(),
50 ethernet::getBroadcastAddress(),
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040051 ndn::nfd::LINK_TYPE_MULTI_ACCESS);
Junxiao Shi7003c602017-01-10 13:35:28 +000052 netifs.push_back(netif);
Davide Pesavento35120ea2015-11-17 21:13:18 +010053 }
Junxiao Shi7003c602017-01-10 13:35:28 +000054 catch (const EthernetTransport::Error&) {
55 // ignore
Davide Pesavento35120ea2015-11-17 21:13:18 +010056 }
57 }
58 }
59 }
60
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040061 void
Davide Pesavento1816d4b2017-07-02 12:20:48 -040062 initializeUnicast(ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
63 ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040064 {
65 BOOST_ASSERT(netifs.size() > 0);
66 localEp = netifs.front().name;
67 remoteEp = remoteAddr;
Junxiao Shi0d82d042017-07-07 06:15:27 +000068 transport = make_unique<UnicastEthernetTransport>(*netifs.front().asNetworkInterface(),
69 remoteEp, persistency, time::seconds(2));
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040070 }
71
72 void
Davide Pesavento1816d4b2017-07-02 12:20:48 -040073 initializeMulticast(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
74 ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040075 {
76 BOOST_ASSERT(netifs.size() > 0);
77 localEp = netifs.front().name;
78 remoteEp = mcastGroup;
Junxiao Shi0d82d042017-07-07 06:15:27 +000079 transport = make_unique<MulticastEthernetTransport>(*netifs.front().asNetworkInterface(),
80 remoteEp, linkType);
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040081 }
82
Davide Pesavento35120ea2015-11-17 21:13:18 +010083protected:
Davide Pesavento1816d4b2017-07-02 12:20:48 -040084 LimitedIo limitedIo;
Davide Pesavento6bd6d0b2017-03-25 15:16:40 -040085 unique_ptr<EthernetTransport> transport;
86 std::string localEp;
87 ethernet::Address remoteEp;
88
Junxiao Shi7003c602017-01-10 13:35:28 +000089 /** \brief EthernetTransport-capable network interfaces
90 */
91 std::vector<NetworkInterfaceInfo> netifs;
Davide Pesavento35120ea2015-11-17 21:13:18 +010092};
93
Junxiao Shi7003c602017-01-10 13:35:28 +000094#define SKIP_IF_ETHERNET_NETIF_COUNT_LT(n) \
95 do { \
96 if (this->netifs.size() < (n)) { \
97 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
98 " or more EthernetTransport-capable network interfaces"); \
99 return; \
100 } \
Davide Pesavento35120ea2015-11-17 21:13:18 +0100101 } while (false)
102
103} // namespace tests
Eric Newberry8717e872015-11-23 12:41:50 -0700104} // namespace face
Davide Pesavento35120ea2015-11-17 21:13:18 +0100105} // namespace nfd
106
Junxiao Shi7003c602017-01-10 13:35:28 +0000107#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP