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

#include "fw/strategy.hpp"

namespace nfd {
namespace tests {

/** \brief strategy for unit testing
 *
 *  Unless otherwise indicated, triggers are recorded but does nothing.
 */
class DummyStrategy : public fw::Strategy
{
public:
  DummyStrategy(Forwarder& forwarder, const Name& name)
    : Strategy(forwarder, name)
    , afterReceiveInterest_count(0)
    , wantAfterReceiveInterestCalls(false)
    , beforeSatisfyInterest_count(0)
    , beforeExpirePendingInterest_count(0)
  {
  }

  /** \brief after receive Interest trigger
   *
   *  If \p interestOutFace is not null, send Interest action is invoked with that face;
   *  otherwise, reject pending Interest action is invoked.
   */
  virtual void
  afterReceiveInterest(const Face& inFace,
                       const Interest& interest,
                       shared_ptr<pit::Entry> pitEntry) override
  {
    ++afterReceiveInterest_count;
    if (wantAfterReceiveInterestCalls) {
      afterReceiveInterestCalls.emplace_back(inFace.getId(), interest, pitEntry);
    }

    if (interestOutFace) {
      this->sendInterest(pitEntry, interestOutFace);
    }
    else {
      this->rejectPendingInterest(pitEntry);
    }
  }

  virtual void
  beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
                        const Face& inFace,
                        const Data& data) override
  {
    ++beforeSatisfyInterest_count;
  }

  virtual void
  beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry) override
  {
    ++beforeExpirePendingInterest_count;
  }

  virtual void
  afterReceiveNack(const Face& inFace,
                   const lp::Nack& nack,
                   shared_ptr<pit::Entry> pitEntry) override
  {
    ++afterReceiveNack_count;
  }

public:
  int afterReceiveInterest_count;
  bool wantAfterReceiveInterestCalls;
  std::vector<std::tuple<FaceId, Interest, shared_ptr<pit::Entry>>> afterReceiveInterestCalls;
  shared_ptr<Face> interestOutFace;

  int beforeSatisfyInterest_count;
  int beforeExpirePendingInterest_count;
  int afterReceiveNack_count;
};

} // namespace tests
} // namespace nfd

#endif // NFD_TESTS_DAEMON_FW_DUMMY_STRATEGY_HPP
