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

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
