/* -*- 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/>.
 */

#include "rib/route.hpp"

#include "tests/test-common.hpp"
#include "tests/daemon/global-io-fixture.hpp"

#include <boost/lexical_cast.hpp>

namespace nfd::tests {

using rib::Route;

BOOST_FIXTURE_TEST_SUITE(TestRoute, GlobalIoTimeFixture)

BOOST_AUTO_TEST_SUITE(CreateFromAnnouncement)

BOOST_AUTO_TEST_CASE(NoValidity)
{
  auto pa = makePrefixAnn("/A", 212_s);
  Route route(pa, 1815);
  BOOST_CHECK_EQUAL(route.faceId, 1815);
  BOOST_CHECK_EQUAL(route.origin, ndn::nfd::ROUTE_ORIGIN_PREFIXANN);
  BOOST_CHECK_EQUAL(route.cost, 2048);
  BOOST_CHECK_EQUAL(route.flags, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
  BOOST_REQUIRE(route.expires);
  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
}

BOOST_AUTO_TEST_CASE(BeforeNotBefore)
{
  auto pa = makePrefixAnn("/A", 212_s, {10_s, 80_s});
  Route route(pa, 1053);
  BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
  BOOST_REQUIRE(route.expires);
  BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
}

BOOST_AUTO_TEST_CASE(AfterNotAfter)
{
  auto pa = makePrefixAnn("/A", 212_s, {-80_s, -10_s});
  Route route(pa, 2972);
  BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
  BOOST_REQUIRE(route.expires);
  BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
}

BOOST_AUTO_TEST_CASE(ExpirationLtValidity)
{
  auto pa = makePrefixAnn("/A", 212_s, {-100_s, 300_s});
  Route route(pa, 7804);
  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
  BOOST_REQUIRE(route.expires);
  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
}

BOOST_AUTO_TEST_CASE(ValidityLtExpiration)
{
  auto pa = makePrefixAnn("/A", 212_s, {-100_s, 200_s});
  Route route(pa, 7804);
  BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 200_s);
  BOOST_REQUIRE(route.expires);
  BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
}

BOOST_AUTO_TEST_SUITE_END() // CreateFromAnnouncement

BOOST_AUTO_TEST_CASE(Equality)
{
  Route a;
  Route b;
  BOOST_CHECK_EQUAL(a, b);

  a.faceId = b.faceId = 15404;
  a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
  a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
  a.cost = b.cost = 28826;
  a.expires = b.expires = time::steady_clock::now() + 26782232_ms;
  BOOST_CHECK_EQUAL(a, b);

  b.faceId = 18559;
  BOOST_CHECK_NE(a, b);
  a.faceId = 18559;

  b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
  BOOST_CHECK_NE(a, b);
  a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;

  b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
  BOOST_CHECK_NE(a, b);
  a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;

  b.cost = 103;
  BOOST_CHECK_NE(a, b);
  a.cost = 103;

  b.expires = std::nullopt;
  BOOST_CHECK_NE(a, b);
  a.expires = std::nullopt;

  BOOST_CHECK_EQUAL(a, b);
}

BOOST_AUTO_TEST_CASE(EqualityAnn)
{
  auto ann1 = makePrefixAnn("/ann", 1_h);
  auto ann2 = makePrefixAnn("/ann", 2_h);
  BOOST_CHECK_EQUAL(Route(ann1, 7001), Route(ann1, 7001));
  BOOST_CHECK_NE(Route(ann1, 7001), Route(ann1, 7002));
  BOOST_CHECK_NE(Route(ann1, 7001), Route(ann2, 7001));
}

BOOST_AUTO_TEST_CASE(Output)
{
  Route r;
  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
                    "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)");

  r.faceId = 4980;
  r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
  r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
  r.cost = 2312;
  r.expires = time::steady_clock::now() + 791214234_ms;
  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
                    "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: "
                    "791214234 milliseconds)");

  r.expires = std::nullopt;
  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
                    "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");

  r = Route(makePrefixAnn("/ann", 1_h), 3247);
  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
                    "Route(faceid: 3247, origin: prefixann, cost: 2048, flags: 0x1, expires in: "
                    "3600000 milliseconds, announcement: (/ann expires=3600000 milliseconds))");
}

BOOST_AUTO_TEST_SUITE_END() // TestRoute

} // namespace nfd::tests
