/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2023,  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_FACTORY_HPP
#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP

#include "protocol-factory.hpp"
#include "ethernet-channel.hpp"
#include "network-predicate.hpp"

namespace nfd::face {

/**
 * \brief Protocol factory for Ethernet.
 */
class EthernetFactory final : public ProtocolFactory
{
public:
  static const std::string&
  getId() noexcept;

  explicit
  EthernetFactory(const CtorParams& params);

  /**
   * \brief Create Ethernet-based channel on the specified network interface.
   *
   * If this method is called twice with the same endpoint, only one channel
   * will be created. The second call will just return the existing channel.
   *
   * \return Always a valid pointer to a EthernetChannel object, an exception
   *         is thrown if it cannot be created.
   * \throw PcapHelper::Error channel creation failed
   */
  shared_ptr<EthernetChannel>
  createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
                time::nanoseconds idleTimeout);

  /**
   * \brief Create a face to communicate on the given Ethernet multicast group.
   *
   * If this method is called twice with the same arguments, only one face
   * will be created. The second call will just return the existing face.
   *
   * \param localEndpoint local network interface
   * \param group multicast group address
   *
   * \throw std::runtime_error %Face creation failed
   */
  shared_ptr<Face>
  createMulticastFace(const ndn::net::NetworkInterface& localEndpoint,
                      const ethernet::Address& group);

private:
  void
  doProcessConfig(OptionalConfigSection configSection,
                  FaceSystem::ConfigContext& context) final;

  void
  doCreateFace(const CreateFaceRequest& req,
               const FaceCreatedCallback& onCreated,
               const FaceCreationFailedCallback& onFailure) final;

  std::vector<shared_ptr<const Channel>>
  doGetChannels() const final;

  /**
   * \brief Create EthernetChannel on \p netif if requested by \p m_unicastConfig.
   * \return New or existing channel, or nullptr if no channel should be created.
   */
  shared_ptr<EthernetChannel>
  applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif);

  /**
   * \brief Create Ethernet multicast face on \p netif if requested by \p m_mcastConfig.
   * \return New or existing face, or nullptr if no face should be created.
   */
  shared_ptr<Face>
  applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif);

  void
  applyConfig(const FaceSystem::ConfigContext& context);

private:
  // ifname => channel
  std::map<std::string, shared_ptr<EthernetChannel>> m_channels;

  struct UnicastConfig
  {
    bool isEnabled = false;
    bool wantListen = false;
    time::nanoseconds idleTimeout = 10_min;
  };
  UnicastConfig m_unicastConfig;

  struct MulticastConfig
  {
    bool isEnabled = false;
    ethernet::Address group = ethernet::getDefaultMulticastAddress();
    ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS;
    NetworkInterfacePredicate netifPredicate;
  };
  MulticastConfig m_mcastConfig;

  // [ifname, group] => face
  std::map<std::pair<std::string, ethernet::Address>, shared_ptr<Face>> m_mcastFaces;

  signal::ScopedConnection m_netifAddConn;
};

} // namespace nfd::face

#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
