/* -*- 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_TABLE_FIB_HPP
#define NFD_DAEMON_TABLE_FIB_HPP

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

#include <boost/range/adaptor/transformed.hpp>

namespace nfd {

namespace measurements {
class Entry;
} // namespace measurements

namespace pit {
class Entry;
} // namespace pit

namespace fib {

/**
 * \brief Represents the Forwarding Information Base (FIB).
 * \sa fib::Entry
 */
class Fib : noncopyable
{
public:
  explicit
  Fib(NameTree& nameTree);

  size_t
  size() const noexcept
  {
    return m_nItems;
  }

public: // lookup
  /** \brief Performs a longest prefix match.
   */
  const Entry&
  findLongestPrefixMatch(const Name& prefix) const;

  /** \brief Performs a longest prefix match.
   *
   *  This is equivalent to `findLongestPrefixMatch(pitEntry.getName())`
   */
  const Entry&
  findLongestPrefixMatch(const pit::Entry& pitEntry) const;

  /** \brief Performs a longest prefix match.
   *
   *  This is equivalent to `findLongestPrefixMatch(measurementsEntry.getName())`
   */
  const Entry&
  findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;

  /** \brief Performs an exact match lookup.
   */
  Entry*
  findExactMatch(const Name& prefix);

public: // mutation
  /** \brief Maximum number of components in a FIB entry prefix.
   */
  static constexpr size_t
  getMaxDepth()
  {
    return NameTree::getMaxDepth();
  }

  /** \brief Find or insert a FIB entry.
   *  \param prefix FIB entry name; it must not have more than \c getMaxDepth() components.
   *  \return the entry, and true for new entry or false for existing entry
   */
  std::pair<Entry*, bool>
  insert(const Name& prefix);

  void
  erase(const Name& prefix);

  void
  erase(const Entry& entry);

  /** \brief Add a NextHop record.
   *
   *  If a NextHop record for \p face already exists in \p entry, its cost is set to \p cost.
   */
  void
  addOrUpdateNextHop(Entry& entry, Face& face, uint64_t cost);

  enum class RemoveNextHopResult {
    NO_SUCH_NEXTHOP, ///< the nexthop is not found
    NEXTHOP_REMOVED, ///< the nexthop is removed and the fib entry stays
    FIB_ENTRY_REMOVED ///< the nexthop is removed and the fib entry is removed
  };

  /** \brief Remove the NextHop record for \p face from \p entry.
   */
  RemoveNextHopResult
  removeNextHop(Entry& entry, const Face& face);

public: // enumeration
  using Range = boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range>;
  using const_iterator = boost::range_iterator<Range>::type;

  /** \return an iterator to the beginning
   *  \note The iteration order is implementation-defined.
   *  \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
   *           is inserted or erased during iteration.
   */
  const_iterator
  begin() const
  {
    return this->getRange().begin();
  }

  /** \return an iterator to the end
   *  \sa begin()
   */
  const_iterator
  end() const
  {
    return this->getRange().end();
  }

public: // signal
  /** \brief Signals on Fib entry nexthop creation.
   */
  signal::Signal<Fib, Name, NextHop> afterNewNextHop;

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

  void
  erase(name_tree::Entry* nte, bool canDeleteNte = true);

  Range
  getRange() const;

private:
  NameTree& m_nameTree;
  size_t m_nItems = 0;

  /** \brief The empty FIB entry.
   *
   *  This entry has no nexthops.
   *  It is returned by findLongestPrefixMatch if nothing is matched.
   */
  static const unique_ptr<Entry> s_emptyEntry;
};

} // namespace fib

using fib::Fib;

} // namespace nfd

#endif // NFD_DAEMON_TABLE_FIB_HPP
