/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  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 "table/pit-entry.hpp"

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

#include <boost/test/data/test_case.hpp>

namespace bdata = boost::unit_test::data;

namespace nfd::tests {

using namespace nfd::pit;

BOOST_AUTO_TEST_SUITE(Table)
BOOST_FIXTURE_TEST_SUITE(TestPitEntry, GlobalIoFixture)

BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CanMatch, 1)
BOOST_AUTO_TEST_CASE(CanMatch)
{
  auto interest0 = makeInterest("/A");
  Entry entry(*interest0);

  auto interest1 = makeInterest("/B");
  BOOST_CHECK_EQUAL(entry.canMatch(*interest1), false);

  auto interest2 = makeInterest("/A", false, std::nullopt, 27956);
  BOOST_CHECK_EQUAL(entry.canMatch(*interest2), true);

  auto interest3 = makeInterest("/A", false, 6210_ms);
  BOOST_CHECK_EQUAL(entry.canMatch(*interest3), true);

  auto interest4 = makeInterest("/A");
  interest4->setForwardingHint({"/telia/terabits", "/ucla/cs"});
  BOOST_CHECK_EQUAL(entry.canMatch(*interest4), false); // expected failure until #3162

  auto interest5 = makeInterest("/A", true);
  BOOST_CHECK_EQUAL(entry.canMatch(*interest5), false);
}

BOOST_AUTO_TEST_CASE(InOutRecords)
{
  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();

  Name name("/KuYfjtRq");
  auto interest = makeInterest(name);
  auto interest1 = makeInterest(name, false, 2528_ms, 25559);
  auto interest2 = makeInterest(name, false, 6464_ms, 19004);
  auto interest3 = makeInterest(name, false, 3585_ms, 24216);
  auto interest4 = makeInterest(name, false, 8795_ms, 17365);

  Entry entry(*interest);

  BOOST_CHECK_EQUAL(entry.getInterest().getName(), name);
  BOOST_CHECK_EQUAL(entry.getName(), name);

  const InRecordCollection& inRecords1 = entry.getInRecords();
  BOOST_CHECK_EQUAL(inRecords1.size(), 0);
  const OutRecordCollection& outRecords1 = entry.getOutRecords();
  BOOST_CHECK_EQUAL(outRecords1.size(), 0);

  // insert in-record
  auto before1 = time::steady_clock::now();
  InRecordCollection::iterator in1 = entry.insertOrUpdateInRecord(*face1, *interest1);
  auto after1 = time::steady_clock::now();
  const InRecordCollection& inRecords2 = entry.getInRecords();
  BOOST_CHECK_EQUAL(inRecords2.size(), 1);
  BOOST_CHECK(in1 == inRecords2.begin());
  BOOST_CHECK_EQUAL(&in1->getFace(), face1.get());
  BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce());
  BOOST_CHECK_GE(in1->getLastRenewed(), before1);
  BOOST_CHECK_LE(in1->getLastRenewed(), after1);
  BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed() - interest1->getInterestLifetime(),
                 after1 - before1);
  BOOST_CHECK(in1 == entry.findInRecord(*face1));

  // insert out-record
  auto before2 = time::steady_clock::now();
  OutRecordCollection::iterator out1 = entry.insertOrUpdateOutRecord(*face1, *interest1);
  auto after2 = time::steady_clock::now();
  const OutRecordCollection& outRecords2 = entry.getOutRecords();
  BOOST_CHECK_EQUAL(outRecords2.size(), 1);
  BOOST_CHECK(out1 == outRecords2.begin());
  BOOST_CHECK_EQUAL(&out1->getFace(), face1.get());
  BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce());
  BOOST_CHECK_GE(out1->getLastRenewed(), before2);
  BOOST_CHECK_LE(out1->getLastRenewed(), after2);
  BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed() - interest1->getInterestLifetime(),
                 after2 - before2);
  BOOST_CHECK(out1 == entry.findOutRecord(*face1));

  // update in-record
  auto before3 = time::steady_clock::now();
  InRecordCollection::iterator in2 = entry.insertOrUpdateInRecord(*face1, *interest2);
  auto after3 = time::steady_clock::now();
  const InRecordCollection& inRecords3 = entry.getInRecords();
  BOOST_CHECK_EQUAL(inRecords3.size(), 1);
  BOOST_CHECK(in2 == inRecords3.begin());
  BOOST_CHECK_EQUAL(&in2->getFace(), face1.get());
  BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce());
  BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed() - interest2->getInterestLifetime(),
                 after3 - before3);

  // insert another in-record
  InRecordCollection::iterator in3 = entry.insertOrUpdateInRecord(*face2, *interest3);
  const InRecordCollection& inRecords4 = entry.getInRecords();
  BOOST_CHECK_EQUAL(inRecords4.size(), 2);
  BOOST_CHECK_EQUAL(&in3->getFace(), face2.get());

  // get in-record
  InRecordCollection::iterator in4 = entry.findInRecord(*face1);
  BOOST_REQUIRE(in4 != entry.in_end());
  BOOST_CHECK_EQUAL(&in4->getFace(), face1.get());

  // delete in-record
  entry.deleteInRecord(in4);
  BOOST_CHECK_EQUAL(entry.getInRecords().size(), 1);
  BOOST_CHECK(entry.findInRecord(*face1) == entry.in_end());

  // clear in-records
  entry.clearInRecords();
  BOOST_CHECK_EQUAL(entry.getInRecords().size(), 0);
  BOOST_CHECK(entry.findInRecord(*face1) == entry.in_end());
  BOOST_CHECK(entry.findInRecord(*face2) == entry.in_end());

  // insert another out-record
  OutRecordCollection::iterator out2 = entry.insertOrUpdateOutRecord(*face2, *interest4);
  const OutRecordCollection& outRecords3 = entry.getOutRecords();
  BOOST_CHECK_EQUAL(outRecords3.size(), 2);
  BOOST_CHECK_EQUAL(&out2->getFace(), face2.get());

  // get out-record
  OutRecordCollection::iterator out3 = entry.findOutRecord(*face1);
  BOOST_REQUIRE(out3 != entry.out_end());
  BOOST_CHECK_EQUAL(&out3->getFace(), face1.get());

  // delete out-record
  entry.deleteOutRecord(*face2);
  const OutRecordCollection& outRecords4 = entry.getOutRecords();
  BOOST_REQUIRE_EQUAL(outRecords4.size(), 1);
  BOOST_CHECK_EQUAL(&outRecords4.begin()->getFace(), face1.get());
  BOOST_CHECK(entry.findOutRecord(*face2) == entry.out_end());
}

const time::milliseconds lifetimes[] = {
  -1_ms, // unset
  1_ms,
  ndn::DEFAULT_INTEREST_LIFETIME,
  8624_ms,
  86400_s,
  time::milliseconds(std::numeric_limits<time::milliseconds::rep>::max()),
};

BOOST_DATA_TEST_CASE(Lifetime, bdata::make(lifetimes), lifetime)
{
  auto interest = makeInterest("/7oIEurbgy6");
  if (lifetime >= 0_ms) {
    interest->setInterestLifetime(lifetime);
  }

  auto expectedLifetime = lifetime;
  if (lifetime < 0_ms) {
    expectedLifetime = ndn::DEFAULT_INTEREST_LIFETIME;
  }
  else if (lifetime > 10_days) {
    expectedLifetime = 10_days;
  }

  auto face = make_shared<DummyFace>();
  Entry entry(*interest);

  auto inIt = entry.insertOrUpdateInRecord(*face, *interest);
  auto expiryFromNow = inIt->getExpiry() - time::steady_clock::now();
  BOOST_CHECK_GT(expiryFromNow, 0_ms);
  BOOST_CHECK_LT(time::abs(expiryFromNow - expectedLifetime), 100_ms);

  auto outIt = entry.insertOrUpdateOutRecord(*face, *interest);
  expiryFromNow = outIt->getExpiry() - time::steady_clock::now();
  BOOST_CHECK_GT(expiryFromNow, 0_ms);
  BOOST_CHECK_LT(time::abs(expiryFromNow - expectedLifetime), 100_ms);
}

BOOST_AUTO_TEST_CASE(OutRecordNack)
{
  auto face1 = make_shared<DummyFace>();
  OutRecord outR(*face1);
  BOOST_CHECK(outR.getIncomingNack() == nullptr);

  auto interest1 = makeInterest("/uWiapGjYL");
  interest1->setNonce(165);
  outR.update(*interest1);
  BOOST_CHECK(outR.getIncomingNack() == nullptr);

  auto interest2 = makeInterest("/uWiapGjYL");
  interest2->setNonce(996);
  lp::Nack nack2(*interest2);
  nack2.setReason(lp::NackReason::CONGESTION);
  BOOST_CHECK_EQUAL(outR.setIncomingNack(nack2), false);
  BOOST_CHECK(outR.getIncomingNack() == nullptr);

  lp::Nack nack1(*interest1);
  nack1.setReason(lp::NackReason::DUPLICATE);
  BOOST_CHECK_EQUAL(outR.setIncomingNack(nack1), true);
  BOOST_REQUIRE(outR.getIncomingNack() != nullptr);
  BOOST_CHECK_EQUAL(outR.getIncomingNack()->getReason(), lp::NackReason::DUPLICATE);

  outR.clearIncomingNack();
  BOOST_CHECK(outR.getIncomingNack() == nullptr);
}

BOOST_AUTO_TEST_SUITE_END() // TestPitEntry
BOOST_AUTO_TEST_SUITE_END() // Table

} // namespace nfd::tests
