/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP
#define NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP

#include "face/multicast-ethernet-transport.hpp"
#include "face/unicast-ethernet-transport.hpp"

#include "tests/daemon/limited-io.hpp"
#include "ethernet-fixture.hpp"

namespace nfd::tests {

class EthernetTransportFixture : public EthernetFixture
{
protected:
  EthernetTransportFixture()
  {
    if (!netifs.empty()) {
      defaultNetif = std::const_pointer_cast<ndn::net::NetworkInterface>(netifs.front());
    }
  }

  /**
   * \brief Returns the first running interface.
   */
  shared_ptr<ndn::net::NetworkInterface>
  getRunningNetif() const
  {
    for (const auto& netif : netifs) {
      if (netif->getState() == ndn::net::InterfaceState::RUNNING) {
        return std::const_pointer_cast<ndn::net::NetworkInterface>(netif);
      }
    }

    return nullptr;
  }

  /**
   * \brief Create a UnicastEthernetTransport.
   */
  void
  initializeUnicast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
                    ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
                    ethernet::Address remoteAddr = {0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e})
  {
    if (!netif) {
      netif = defaultNetif;
    }

    localEp = netif->getName();
    remoteEp = remoteAddr;
    transport = make_unique<face::UnicastEthernetTransport>(*netif, remoteEp, persistency, 2_s);
  }

  /**
   * \brief Create a MulticastEthernetTransport.
   */
  void
  initializeMulticast(shared_ptr<ndn::net::NetworkInterface> netif = nullptr,
                      ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS,
                      ethernet::Address mcastGroup = {0x01, 0x00, 0x5e, 0x90, 0x10, 0x5e})
  {
    if (!netif) {
      netif = defaultNetif;
    }

    localEp = netif->getName();
    remoteEp = mcastGroup;
    transport = make_unique<face::MulticastEthernetTransport>(*netif, remoteEp, linkType);
  }

protected:
  LimitedIo limitedIo;
  shared_ptr<ndn::net::NetworkInterface> defaultNetif;
  unique_ptr<face::EthernetTransport> transport;
  std::string localEp;
  ethernet::Address remoteEp;
};

} // namespace nfd::tests

#define SKIP_IF_NO_RUNNING_ETHERNET_NETIF() \
  do { \
    if (!this->getRunningNetif()) { \
      BOOST_WARN_MESSAGE(false, "skipping assertions that require a running " \
                                "EthernetTransport-capable network interface"); \
      return; \
    } \
  } while (false)

#endif // NFD_TESTS_DAEMON_FACE_ETHERNET_TRANSPORT_FIXTURE_HPP
