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

/** \file
 *  \brief allows testing forwarding in a network topology
 */

#ifndef NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP
#define NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP

#include "face/internal-transport.hpp"
#include "face/face.hpp"
#include "fw/strategy.hpp"
#include "choose-strategy.hpp"
#include "tests/test-common.hpp"

#include <ndn-cxx/face.hpp>

namespace nfd::tests {

/** \brief identifies a node (forwarder) in the topology
 */
typedef size_t TopologyNode;

/** \brief represents a network link in the topology which connects two or more nodes
 */
class TopologyLink : noncopyable
{
public:
  explicit
  TopologyLink(time::nanoseconds delay);

  /** \brief fail the link, cause packets to be dropped silently
   */
  void
  fail()
  {
    m_isUp = false;
  }

  /** \brief recover the link from a failure
   */
  void
  recover()
  {
    m_isUp = true;
  }

  /** \brief block transmission from i to j
   *
   *  Packets transmitted by i would not be delivered to j. Packets from j to i are unaffected.
   *  This can be used to simulate a wireless channel.
   */
  void
  block(TopologyNode i, TopologyNode j);

  /** \brief unblock transmission from i to j
   */
  void
  unblock(TopologyNode i, TopologyNode j);

  /** \brief change the link delay
   *  \param delay link delay, must be positive
   */
  void
  setDelay(time::nanoseconds delay);

  /** \brief attach a face to the link
   *  \param i forwarder index
   *  \param face a Face with InternalForwarderTransport
   */
  void
  addFace(TopologyNode i, shared_ptr<Face> face);

  /** \return a face of forwarder \p i which is attached to this link
   */
  Face&
  getFace(TopologyNode i)
  {
    return *m_transports.at(i).face;
  }

private:
  void
  transmit(TopologyNode i, const Block& packet);

private:
  bool m_isUp = true;
  time::nanoseconds m_delay;

  class ReceiveProxy : public face::InternalTransportBase
  {
  public:
    using Callback = std::function<void(const Block&)>;

    explicit
    ReceiveProxy(Callback cb)
      : m_cb(std::move(cb))
    {
    }

    void
    receivePacket(const Block& packet) final
    {
      m_cb(packet);
    }

  private:
    Callback m_cb;
  };

  class NodeTransport
  {
  public:
    NodeTransport(shared_ptr<Face> face, ReceiveProxy::Callback receiveCallback);

  public:
    shared_ptr<Face> face;
    face::InternalForwarderTransport* transport;
    ReceiveProxy proxy;
    std::set<TopologyNode> blockedDestinations;
  };

  std::unordered_map<TopologyNode, NodeTransport> m_transports;
};

/** \brief represents a link on a single forwarder
 */
class TopologySingleLink : noncopyable
{
public:
  /** \brief constructor
   *  \param forwarderFace a Face with InternalForwarderTransport
   */
  explicit
  TopologySingleLink(shared_ptr<Face> forwarderFace);

  /** \return face on forwarder side
   */
  Face&
  getForwarderFace()
  {
    return *m_face;
  }

protected:
  shared_ptr<Face> m_face;
  face::InternalForwarderTransport* m_forwarderTransport;
};

/** \brief represents a link to a local application
 */
class TopologyAppLink : public TopologySingleLink
{
public:
  /** \brief constructor
   *  \param forwarderFace a Face with InternalForwarderTransport
   */
  explicit
  TopologyAppLink(shared_ptr<Face> forwarderFace);

  /** \brief fail the link, cause packets to be dropped silently
   */
  void
  fail();

  /** \brief recover the link from a failure
   */
  void
  recover();

  /** \return face on application side
   */
  ndn::Face&
  getClientFace()
  {
    return *m_client;
  }

private:
  shared_ptr<face::InternalClientTransport> m_clientTransport;
  shared_ptr<ndn::Face> m_client;
};

/** \brief allows the test case to inject and observe L2 packets on a link
 */
class TopologyBareLink : public TopologySingleLink
{
public:
  /** \brief constructor
   *  \param forwarderFace a Face with InternalForwarderTransport
   */
  explicit
  TopologyBareLink(shared_ptr<Face> forwarderFace);

  void
  receivePacket(const Block& packet);

public:
  std::vector<Block> sentPackets;

private:
  class Observer;
  unique_ptr<Observer> m_observer;
};

/** \brief captured packets on a face
 */
class TopologyPcap : noncopyable
{
public:
  std::vector<Interest> sentInterests;
  std::vector<Data> sentData;
  std::vector<lp::Nack> sentNacks;
};

/** \brief captured packet timestamp tag
 */
using TopologyPcapTimestamp = ndn::SimpleTag<time::steady_clock::time_point, 0>;

/** \brief builds a topology for forwarding tests
 */
class TopologyTester : noncopyable
{
public:
  /** \brief creates a forwarder
   *  \return index of new forwarder
   */
  TopologyNode
  addForwarder(const std::string& label);

  /** \return forwarder instance \p i
   */
  Forwarder&
  getForwarder(TopologyNode i)
  {
    return m_forwarders.at(i)->forwarder;
  }

  /** \brief sets strategy on forwarder \p i
   *  \tparam S the strategy type
   *  \note Test scenario can also access StrategyChoice table directly.
   */
  template<typename S>
  void
  setStrategy(TopologyNode i, Name prefix = Name("ndn:/"),
              Name instanceName = S::getStrategyName())
  {
    Forwarder& forwarder = this->getForwarder(i);
    choose<S>(forwarder, prefix, instanceName);
  }

  /** \brief makes a link that interconnects two or more forwarders
   *  \brief linkType desired link type; LINK_TYPE_NONE to use point-to-point for two forwarders
   *                  and multi-access for more than two forwarders; it's an error to specify
   *                  point-to-point when there are more than two forwarders
   *
   *  A face is created on each of \p forwarders .
   *  When a packet is sent onto one of the faces on this link,
   *  this packet will be received by all other faces on this link after \p delay .
   */
  shared_ptr<TopologyLink>
  addLink(const std::string& label, time::nanoseconds delay,
          std::initializer_list<TopologyNode> forwarders,
          ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_NONE);

  /** \brief makes a link to local application
   */
  shared_ptr<TopologyAppLink>
  addAppFace(const std::string& label, TopologyNode i);

  /** \brief makes a link to local application, and register a prefix
   */
  shared_ptr<TopologyAppLink>
  addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost = 0);

  /** \brief makes a link that allows the test case to inject and observe L2 packets
   */
  shared_ptr<TopologyBareLink>
  addBareLink(const std::string& label, TopologyNode i,
              ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_LOCAL,
              ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);

  /** \brief enables packet capture on every forwarder face
   */
  void
  enablePcap(bool isEnabled = true)
  {
    m_wantPcap = isEnabled;
  }

  /** \return captured packets on a forwarder face
   *  \pre enablePcap(true) is in effect when the face was created
   */
  TopologyPcap&
  getPcap(const Face& face);

  /** \brief registers a prefix on a forwarder face
   */
  void
  registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost = 0);

  /** \brief creates a producer application that answers every Interest with Data of same Name
   */
  void
  addEchoProducer(ndn::Face& face, const Name& prefix = "/", time::nanoseconds replyDelay = 0_ns);

  /** \brief creates a consumer application that sends \p n Interests under \p prefix
   *         at \p interval fixed rate.
   *  \param seq if non-negative, append sequence number instead of timestamp
   */
  void
  addIntervalConsumer(ndn::Face& face, const Name& prefix, time::nanoseconds interval,
                      size_t n, int seq = -1);

private:
  shared_ptr<Face>
  makeFace(TopologyNode i, const FaceUri& localUri, const FaceUri& remoteUri,
           ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType);

private:
  class TopologyForwarder
  {
  public:
    explicit
    TopologyForwarder(const std::string& label)
      : label(label)
    {
    }

  public:
    std::string label;
    FaceTable faceTable;
    Forwarder forwarder{faceTable};
  };

  std::vector<unique_ptr<TopologyForwarder>> m_forwarders;
  std::vector<shared_ptr<TopologyLink>> m_links;
  std::vector<shared_ptr<TopologyAppLink>> m_appLinks;
  std::vector<shared_ptr<TopologyBareLink>> m_bareLinks;
  bool m_wantPcap = false;
};

} // namespace nfd::tests

#endif // NFD_TESTS_DAEMON_FW_TOPOLOGY_TESTER_HPP
