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

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
