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

#include "core/common.hpp"

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>

namespace nfd {

/** \brief Represents the Dead Nonce List
 *
 *  The Dead Nonce List is a global table that supplements PIT for loop detection.
 *  When a Nonce is erased (dead) from PIT entry, the Nonce and the Interest Name is added to
 *  Dead Nonce List, and kept for a duration in which most loops are expected to have occured.
 *
 *  To reduce memory usage, the Interest Name and Nonce are stored as a 64-bit hash.
 *  There could be false positives (non-looping Interest could be considered looping),
 *  but the probability is small, and the error is recoverable when consumer retransmits
 *  with a different Nonce.
 *
 *  To reduce memory usage, entries do not have associated timestamps. Instead,
 *  lifetime of entries is controlled by dynamically adjusting the capacity of the container.
 *  At fixed intervals, the MARK, an entry with a special value, is inserted into the container.
 *  The number of MARKs stored in the container reflects the lifetime of entries,
 *  because MARKs are inserted at fixed intervals.
 */
class DeadNonceList : noncopyable
{
public:
  /** \brief Constructs the Dead Nonce List
   *  \param lifetime duration of the expected lifetime of each nonce,
   *         must be no less than MIN_LIFETIME.
   *         This should be set to the duration in which most loops would have occured.
   *         A loop cannot be detected if delay of the cycle is greater than lifetime.
   *  \throw std::invalid_argument if lifetime is less than MIN_LIFETIME
   */
  explicit
  DeadNonceList(time::nanoseconds lifetime = DEFAULT_LIFETIME);

  ~DeadNonceList();

  /** \brief Determines if name+nonce exists
   *  \return true if name+nonce exists, false otherwise
   */
  bool
  has(const Name& name, Interest::Nonce nonce) const;

  /** \brief Records name+nonce
   */
  void
  add(const Name& name, Interest::Nonce nonce);

  /** \return number of stored Nonces
   *  \note The return value does not contain non-Nonce entries in the index, if any.
   */
  size_t
  size() const;

  /** \return expected lifetime
   */
  time::nanoseconds
  getLifetime() const
  {
    return m_lifetime;
  }

private: // Entry and Index
  typedef uint64_t Entry;

  static Entry
  makeEntry(const Name& name, Interest::Nonce nonce);

  typedef boost::multi_index_container<
    Entry,
    boost::multi_index::indexed_by<
      boost::multi_index::sequenced<>,
      boost::multi_index::hashed_non_unique<
        boost::multi_index::identity<Entry>
      >
    >
  > Index;

  typedef Index::nth_index<0>::type Queue;
  typedef Index::nth_index<1>::type Hashtable;

private: // actual lifetime estimation and capacity control
  /** \brief Return the number of MARKs in the index
   */
  size_t
  countMarks() const;

  /** \brief Add a MARK, then record number of MARKs in m_actualMarkCounts
   */
  void
  mark();

  /** \brief Adjust capacity according to m_actualMarkCounts
   *
   *  If all counts are above EXPECTED_MARK_COUNT, reduce capacity to m_capacity * CAPACITY_DOWN.
   *  If all counts are below EXPECTED_MARK_COUNT, increase capacity to m_capacity * CAPACITY_UP.
   */
  void
  adjustCapacity();

  /** \brief Evict some entries if index is over capacity
   */
  void
  evictEntries();

public:
  /// Default entry lifetime
  static const time::nanoseconds DEFAULT_LIFETIME;
  /// Minimum entry lifetime
  static const time::nanoseconds MIN_LIFETIME;

private:
  time::nanoseconds m_lifetime;
  Index m_index;
  Queue& m_queue;
  Hashtable& m_ht;

NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // actual lifetime estimation and capacity control

  // ---- current capacity and hard limits

  /** \brief Current capacity of index
   *
   *  The index size is maintained to be near this capacity.
   *
   *  The capacity is adjusted so that every Entry is expected to be kept for m_lifetime.
   *  This is achieved by mark() and adjustCapacity().
   */
  size_t m_capacity;

  static const size_t INITIAL_CAPACITY;

  /** \brief Minimum capacity
   *
   *  This is to ensure correct algorithm operations.
   */
  static const size_t MIN_CAPACITY;

  /** \brief Maximum capacity
   *
   *  This is to limit memory usage.
   */
  static const size_t MAX_CAPACITY;

  // ---- actual entry lifetime estimation

  /** \brief The MARK for capacity
   *
   *  The MARK doesn't have a distinct type.
   *  Entry is a hash. The hash function should have non-invertible property,
   *  so it's unlikely for a usual Entry to have collision with the MARK.
   */
  static const Entry MARK;

  /** \brief Expected number of MARKs in the index
   */
  static const size_t EXPECTED_MARK_COUNT;

  /** \brief Number of MARKs in the index after each MARK insertion
   *
   *  adjustCapacity() uses this to determine whether and how to adjust capcity,
   *  and then clears this list.
   */
  std::multiset<size_t> m_actualMarkCounts;

  time::nanoseconds m_markInterval;
  scheduler::EventId m_markEvent;

  // ---- capacity adjustments

  static const double CAPACITY_UP;
  static const double CAPACITY_DOWN;
  time::nanoseconds m_adjustCapacityInterval;
  scheduler::EventId m_adjustCapacityEvent;

  /// Maximum number of entries to evict at each operation if index is over capacity
  static const size_t EVICT_LIMIT;
};

} // namespace nfd

#endif // NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
