/* -*- 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_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
#define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP

#include "ethernet-protocol.hpp"
#include "pcap-helper.hpp"
#include "transport.hpp"

#include <boost/asio/posix/stream_descriptor.hpp>
#include <ndn-cxx/net/network-interface.hpp>

namespace nfd::face {

/**
 * @brief Base class for Ethernet-based Transports.
 */
class EthernetTransport : public Transport
{
public:
  class Error : public std::runtime_error
  {
  public:
    using std::runtime_error::runtime_error;
  };

  /**
   * @brief Processes the payload of an incoming frame.
   * @param payload Payload bytes, starting from the first byte after the Ethernet header
   * @param sender Sender address
   */
  void
  receivePayload(span<const uint8_t> payload, const ethernet::Address& sender);

protected:
  EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                    const ethernet::Address& remoteEndpoint);

  void
  doClose() final;

  bool
  hasRecentlyReceived() const
  {
    return m_hasRecentlyReceived;
  }

  void
  resetRecentlyReceived()
  {
    m_hasRecentlyReceived = false;
  }

private:
  void
  handleNetifStateChange(ndn::net::InterfaceState netifState);

  void
  doSend(const Block& packet) final;

  /**
   * @brief Sends the specified TLV block on the network wrapped in an Ethernet frame.
   */
  void
  sendPacket(const ndn::Block& block);

  void
  asyncRead();

  void
  handleRead(const boost::system::error_code& error);

  void
  handleError(const std::string& errorMessage);

protected:
  boost::asio::posix::stream_descriptor m_socket;
  PcapHelper m_pcap;
  ethernet::Address m_srcAddress;
  ethernet::Address m_destAddress;
  std::string m_interfaceName;

private:
  signal::ScopedConnection m_netifStateChangedConn;
  signal::ScopedConnection m_netifMtuChangedConn;
  bool m_hasRecentlyReceived = false;
#ifndef NDEBUG
  /// Number of frames dropped by the kernel, as reported by libpcap
  size_t m_nDropped = 0;
#endif
};

} // namespace nfd::face

#endif // NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
