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

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

namespace nfd {

namespace measurements {
class Entry;
} // namespace measurements
namespace pit {
class Entry;
} // namespace pit

namespace fib {

/** \brief represents the Forwarding Information Base (FIB)
 */
class Fib : noncopyable
{
public:
  explicit
  Fib(NameTree& nameTree);

  ~Fib();

  size_t
  size() const;

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 inserts a FIB entry for prefix
   *
   *  If an entry for exact same prefix exists, that entry is returned.
   *  \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 removes the NextHop record for face in all entries
   *
   *  This is usually invoked when face is destroyed.
   *  Removing the last NextHop in a FIB entry will erase the FIB entry.
   *
   *  \todo change parameter type to Face&
   */
  void
  removeNextHopFromAllEntries(const Face& face);

public: // enumeration
  class const_iterator;

  /** \brief returns an iterator pointing to the first FIB entry
   *  \note Iteration order is implementation-specific and is undefined
   *  \note The returned iterator may get invalidated if FIB or another NameTree-based
   *        table is modified
   */
  const_iterator
  begin() const;

  /** \brief returns an iterator referring to the past-the-end FIB entry
   *  \note The returned iterator may get invalidated if FIB or another NameTree-based
   *        table is modified
   */
  const_iterator
  end() const;

  class const_iterator : public std::iterator<std::forward_iterator_tag, const Entry>
  {
  public:
    const_iterator() = default;

    explicit
    const_iterator(const NameTree::const_iterator& it);

    ~const_iterator();

    const Entry&
    operator*() const;

    const Entry*
    operator->() const;

    const_iterator&
    operator++();

    const_iterator
    operator++(int);

    bool
    operator==(const const_iterator& other) const;

    bool
    operator!=(const const_iterator& other) const;

  private:
    NameTree::const_iterator m_nameTreeIterator;
  };

private:
  const Entry&
  findLongestPrefixMatch(shared_ptr<name_tree::Entry> nte) const;

  void
  erase(shared_ptr<name_tree::Entry> nameTreeEntry);

private:
  NameTree& m_nameTree;
  size_t m_nItems;

  /** \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;
};

inline size_t
Fib::size() const
{
  return m_nItems;
}

inline Fib::const_iterator
Fib::end() const
{
  return const_iterator(m_nameTree.end());
}

inline
Fib::const_iterator::const_iterator(const NameTree::const_iterator& it)
  : m_nameTreeIterator(it)
{
}

inline
Fib::const_iterator::~const_iterator()
{
}

inline
Fib::const_iterator
Fib::const_iterator::operator++(int)
{
  const_iterator temp(*this);
  ++(*this);
  return temp;
}

inline Fib::const_iterator&
Fib::const_iterator::operator++()
{
  ++m_nameTreeIterator;
  return *this;
}

inline const Entry&
Fib::const_iterator::operator*() const
{
  return *m_nameTreeIterator->getFibEntry();
}

inline const Entry*
Fib::const_iterator::operator->() const
{
  return m_nameTreeIterator->getFibEntry();
}

inline bool
Fib::const_iterator::operator==(const const_iterator& other) const
{
  return m_nameTreeIterator == other.m_nameTreeIterator;
}

inline bool
Fib::const_iterator::operator!=(const const_iterator& other) const
{
  return m_nameTreeIterator != other.m_nameTreeIterator;
}

} // namespace fib

using fib::Fib;

} // namespace nfd

#endif // NFD_DAEMON_TABLE_FIB_HPP
