/* -*- 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/>.
 */

#ifndef NFD_DAEMON_FW_PROCESS_NACK_TRAITS_HPP
#define NFD_DAEMON_FW_PROCESS_NACK_TRAITS_HPP

#include "strategy.hpp"

namespace nfd::fw {

/** \brief Provides a common procedure for processing Nacks
 *
 *  This procedure works as follows:
 *  1. If Nacks have been received from all upstream faces, return a Nack with least severe reason
 *     to downstream faces.
 *  2. If there are more than one upstream face, Nacks have been received from all but one of
 *     them, and that face is also a downstream, return a Nack to that face. This is to address a
 *     specific "live deadlock" scenario where two hosts are waiting for each other to return the
 *     Nack.
 *  3. Otherwise, wait for the arrival of more Nacks or Data.
 *
 *  To use this helper, the strategy should inherit from ProcessNackTraits<MyStrategy>,
 *  and declare that specialization as a friend class.
 *  Then, invoke processNack() from the Strategy::afterReceiveNack() trigger.
 */
class ProcessNackTraitsBase : noncopyable
{
protected:
  virtual
  ~ProcessNackTraitsBase() = default;

  void
  processNack(const lp::Nack& nack, const Face& inFace,
              const shared_ptr<pit::Entry>& pitEntry);

private:
  virtual void
  sendNackForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
                               const lp::NackHeader& header) = 0;

  virtual void
  sendNacksForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry,
                                const lp::NackHeader& header) = 0;
};

template<typename S>
class ProcessNackTraits : public ProcessNackTraitsBase
{
protected:
  explicit
  ProcessNackTraits(S* strategy)
    : m_strategy(strategy)
  {
  }

private:
  void
  sendNackForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
                               const lp::NackHeader& header) override
  {
    m_strategy->sendNack(header, outFace, pitEntry);
  }

  void
  sendNacksForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry,
                                const lp::NackHeader& header) override
  {
    m_strategy->sendNacks(header, pitEntry);
  }

private:
  S* m_strategy;
};

} // namespace nfd::fw

#endif // NFD_DAEMON_FW_PROCESS_NACK_TRAITS_HPP
