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

#include "measurements-entry.hpp"
#include "name-tree.hpp"

#include <functional>

namespace nfd {

namespace fib {
class Entry;
} // namespace fib

namespace pit {
class Entry;
} // namespace pit

namespace measurements {

/**
 * \brief A predicate that accepts or rejects an entry.
 */
using EntryPredicate = std::function<bool(const Entry&)>;

/**
 * \brief An #EntryPredicate that accepts any entry.
 */
class AnyEntry
{
public:
  constexpr bool
  operator()(const Entry&) const noexcept
  {
    return true;
  }
};

/**
 * \brief An #EntryPredicate that accepts an entry if it has StrategyInfo of type T.
 */
template<typename T>
class EntryWithStrategyInfo
{
public:
  bool
  operator()(const Entry& entry) const
  {
    return entry.getStrategyInfo<T>() != nullptr;
  }
};

/**
 * \brief The %Measurements table.
 *
 * The %Measurements table is a data structure for forwarding strategies to store per name prefix
 * measurements. A strategy can access this table via fw::Strategy::getMeasurements(), and then
 * place any object that derive from StrategyInfo type onto %Measurements entries.
 */
class Measurements : noncopyable
{
public:
  explicit
  Measurements(NameTree& nameTree);

  /** \brief Maximum depth of a %Measurements entry.
   */
  static constexpr size_t
  getMaxDepth()
  {
    return NameTree::getMaxDepth();
  }

  /** \brief Find or insert an entry by name.
   *
   *  An entry name can have at most getMaxDepth() components. If \p name exceeds this limit,
   *  it is truncated to the first getMaxDepth() components.
   */
  Entry&
  get(const Name& name);

  /** \brief Equivalent to `get(fibEntry.getPrefix())`.
   */
  Entry&
  get(const fib::Entry& fibEntry);

  /** \brief Equivalent to `get(pitEntry.getName(), std::min(pitEntry.getName().size(), getMaxDepth()))`.
   */
  Entry&
  get(const pit::Entry& pitEntry);

  /** \brief Find or insert a parent entry.
   *  \retval nullptr child is the root entry
   *  \return get(child.getName().getPrefix(-1))
   */
  Entry*
  getParent(const Entry& child);

  /** \brief Perform a longest prefix match for \p name.
   */
  Entry*
  findLongestPrefixMatch(const Name& name,
                         const EntryPredicate& pred = AnyEntry()) const;

  /** \brief Perform a longest prefix match for `pitEntry.getName()`.
   */
  Entry*
  findLongestPrefixMatch(const pit::Entry& pitEntry,
                         const EntryPredicate& pred = AnyEntry()) const;

  /** \brief Perform an exact match.
   */
  Entry*
  findExactMatch(const Name& name) const;

  static time::nanoseconds
  getInitialLifetime()
  {
    return 4_s;
  }

  /** \brief Extend lifetime of an entry.
   *
   *  The entry will be kept until at least now()+lifetime.
   */
  void
  extendLifetime(Entry& entry, const time::nanoseconds& lifetime);

  size_t
  size() const
  {
    return m_nItems;
  }

private:
  void
  cleanup(Entry& entry);

  Entry&
  get(name_tree::Entry& nte);

  /** \tparam K a parameter acceptable to NameTree::findLongestPrefixMatch()
   */
  template<typename K>
  Entry*
  findLongestPrefixMatchImpl(const K& key, const EntryPredicate& pred) const;

private:
  NameTree& m_nameTree;
  size_t m_nItems = 0;
};

} // namespace measurements

using measurements::Measurements;

} // namespace nfd

#endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP
