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

#include "core/scheduler.hpp"

#include <ndn-cxx/encoding/nfd-constants.hpp>
#include <ndn-cxx/mgmt/nfd/route-flags-traits.hpp>
#include <ndn-cxx/prefix-announcement.hpp>

#include <type_traits>

namespace nfd {
namespace rib {

/** \brief represents a route for a name prefix
 */
class Route : public ndn::nfd::RouteFlagsTraits<Route>
{
public:
  /** \brief default constructor
   */
  Route() = default;

  /** \brief construct from a prefix announcement
   *  \param ann a prefix announcement that has passed verification
   *  \param faceId the face on which \p ann arrived
   */
  Route(const ndn::PrefixAnnouncement& ann, uint64_t faceId);

  void
  setExpirationEvent(const scheduler::EventId eid)
  {
    m_expirationEvent = eid;
  }

  const scheduler::EventId&
  getExpirationEvent() const
  {
    return m_expirationEvent;
  }

  std::underlying_type<ndn::nfd::RouteFlags>::type
  getFlags() const
  {
    return flags;
  }

public:
  uint64_t faceId = 0;
  ndn::nfd::RouteOrigin origin = ndn::nfd::ROUTE_ORIGIN_APP;
  uint64_t cost = 0;
  std::underlying_type<ndn::nfd::RouteFlags>::type flags = ndn::nfd::ROUTE_FLAGS_NONE;
  optional<time::steady_clock::TimePoint> expires;

  /** \brief The prefix announcement that caused the creation of this route.
   *
   *  This is nullopt if this route is not created by a prefix announcement.
   */
  optional<ndn::PrefixAnnouncement> announcement;

  /** \brief Expiration time of the prefix announcement.
   *
   *  Valid only if announcement is not nullopt.
   *
   *  If this field is before or equal the current time, it indicates the prefix announcement is
   *  not yet valid or has expired. In this case, the exact value of this field does not matter.
   *  If this field is after the current time, it indicates when the prefix announcement expires.
   */
  time::steady_clock::TimePoint annExpires;

private:
  scheduler::EventId m_expirationEvent;
};

bool
operator==(const Route& lhs, const Route& rhs);

inline bool
operator!=(const Route& lhs, const Route& rhs)
{
  return !(lhs == rhs);
}

inline bool
compareFaceIdAndOrigin(const Route& lhs, const Route& rhs)
{
  return (lhs.faceId == rhs.faceId && lhs.origin == rhs.origin);
}

inline bool
compareFaceId(const Route& route, const uint64_t faceId)
{
  return (route.faceId == faceId);
}

std::ostream&
operator<<(std::ostream& os, const Route& route);

} // namespace rib
} // namespace nfd

#endif // NFD_RIB_ROUTE_HPP
