Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 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 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 26 | #ifndef NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 28 | |
| 29 | #include "core/network-interface.hpp" |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 30 | #include "face/multicast-ethernet-transport.hpp" |
| 31 | #include "face/unicast-ethernet-transport.hpp" |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 32 | |
| 33 | #include "test-common.hpp" |
| 34 | |
| 35 | namespace nfd { |
Eric Newberry | 8717e87 | 2015-11-23 12:41:50 -0700 | [diff] [blame] | 36 | namespace face { |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 37 | namespace tests { |
| 38 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 39 | class EthernetFixture : public virtual nfd::tests::BaseFixture |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 40 | { |
| 41 | protected: |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 42 | EthernetFixture() |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 43 | { |
| 44 | for (const auto& netif : listNetworkInterfaces()) { |
| 45 | if (!netif.isLoopback() && netif.isUp()) { |
| 46 | try { |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 47 | MulticastEthernetTransport transport(netif, ethernet::getBroadcastAddress(), |
| 48 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 49 | netifs.push_back(netif); |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 50 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 51 | catch (const EthernetTransport::Error&) { |
| 52 | // ignore |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 58 | void |
| 59 | initializeUnicast(ethernet::Address remoteAddr = {0x0A, 0x01, 0x23, 0x45, 0x67, 0x89}, |
| 60 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 61 | { |
| 62 | BOOST_ASSERT(netifs.size() > 0); |
| 63 | localEp = netifs.front().name; |
| 64 | remoteEp = remoteAddr; |
| 65 | transport = make_unique<UnicastEthernetTransport>(netifs.front(), remoteEp, |
| 66 | persistency, time::seconds(5)); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | initializeMulticast(ethernet::Address mcastGroup = ethernet::getDefaultMulticastAddress(), |
| 71 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) |
| 72 | { |
| 73 | BOOST_ASSERT(netifs.size() > 0); |
| 74 | localEp = netifs.front().name; |
| 75 | remoteEp = mcastGroup; |
| 76 | transport = make_unique<MulticastEthernetTransport>(netifs.front(), remoteEp, linkType); |
| 77 | } |
| 78 | |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 79 | protected: |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 80 | unique_ptr<EthernetTransport> transport; |
| 81 | std::string localEp; |
| 82 | ethernet::Address remoteEp; |
| 83 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 84 | /** \brief EthernetTransport-capable network interfaces |
| 85 | */ |
| 86 | std::vector<NetworkInterfaceInfo> netifs; |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 89 | #define SKIP_IF_ETHERNET_NETIF_COUNT_LT(n) \ |
| 90 | do { \ |
| 91 | if (this->netifs.size() < (n)) { \ |
| 92 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \ |
| 93 | " or more EthernetTransport-capable network interfaces"); \ |
| 94 | return; \ |
| 95 | } \ |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 96 | } while (false) |
| 97 | |
| 98 | } // namespace tests |
Eric Newberry | 8717e87 | 2015-11-23 12:41:50 -0700 | [diff] [blame] | 99 | } // namespace face |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 100 | } // namespace nfd |
| 101 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 102 | #endif // NFD_TESTS_DAEMON_FACE_ETHERNET_FIXTURE_HPP |