/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2021,  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 "tests/test-common.hpp"
#include "tests/daemon/global-io-fixture.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "choose-strategy.hpp"
#include "dummy-strategy.hpp"

#include <ndn-cxx/lp/tags.hpp>

namespace nfd {
namespace fw {
namespace tests {

using namespace nfd::tests;

BOOST_AUTO_TEST_SUITE(Fw)
BOOST_FIXTURE_TEST_SUITE(TestPitExpiry, GlobalIoTimeFixture)

class PitExpiryTestStrategy : public DummyStrategy
{
public:
  static Name
  getStrategyName(uint64_t version)
  {
    return Name("/PitExpiryTestStrategy").appendVersion(version);
  }

  static void
  registerAs(const Name& strategyName)
  {
    registerAsImpl<PitExpiryTestStrategy>(strategyName);
  }

  explicit
  PitExpiryTestStrategy(Forwarder& forwarder, const Name& name = getStrategyName(1))
    : DummyStrategy(forwarder, name)
  {
  }

  void
  afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
                       const shared_ptr<pit::Entry>& pitEntry) override
  {
    DummyStrategy::afterReceiveInterest(interest, ingress, pitEntry);

    if (afterReceiveInterest_count <= 1) {
      setExpiryTimer(pitEntry, 190_ms);
    }
  }

  void
  afterContentStoreHit(const Data& data, const FaceEndpoint& ingress,
                       const shared_ptr<pit::Entry>& pitEntry) override
  {
    if (afterContentStoreHit_count == 0) {
      setExpiryTimer(pitEntry, 190_ms);
    }

    DummyStrategy::afterContentStoreHit(data, ingress, pitEntry);
  }

  void
  beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
                        const shared_ptr<pit::Entry>& pitEntry) override
  {
    DummyStrategy::beforeSatisfyInterest(data, ingress, pitEntry);

    if (beforeSatisfyInterest_count <= 2) {
      setExpiryTimer(pitEntry, 190_ms);
    }
  }

  void
  afterReceiveData(const Data& data, const FaceEndpoint& ingress,
                   const shared_ptr<pit::Entry>& pitEntry) override
  {
    ++afterReceiveData_count;

    if (afterReceiveData_count <= 2) {
      setExpiryTimer(pitEntry, 290_ms);
    }

    this->sendDataToAll(data, pitEntry, ingress.face);
  }

  void
  afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
                   const shared_ptr<pit::Entry>& pitEntry) override
  {
    DummyStrategy::afterReceiveNack(nack, ingress, pitEntry);

    if (afterReceiveNack_count <= 1) {
      setExpiryTimer(pitEntry, 50_ms);
    }
  }
};

BOOST_AUTO_TEST_CASE(UnsatisfiedInterest)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);

  Pit& pit = forwarder.getPit();

  auto interest1 = makeInterest("/A/0");
  auto interest2 = makeInterest("/A/1");
  interest1->setInterestLifetime(90_ms);
  interest2->setInterestLifetime(90_ms);

  face1->receiveInterest(*interest1, 0);
  face2->receiveInterest(*interest2, 0);
  BOOST_CHECK_EQUAL(pit.size(), 2);

  this->advanceClocks(100_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_CASE(SatisfiedInterest)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);

  Pit& pit = forwarder.getPit();

  auto interest = makeInterest("/A/0");
  interest->setInterestLifetime(90_ms);
  auto data = makeData("/A/0");

  face1->receiveInterest(*interest, 0);

  this->advanceClocks(30_ms);
  face2->receiveData(*data, 0);

  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_CASE(CsHit)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);

  auto strategyA = Name("/strategyA").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);

  auto interest = makeInterest("/A/0");
  interest->setInterestLifetime(90_ms);

  auto data = makeData("/A/0");
  data->setTag(make_shared<lp::IncomingFaceIdTag>(face2->getId()));

  Pit& pit = forwarder.getPit();
  BOOST_CHECK_EQUAL(pit.size(), 0);

  Cs& cs = forwarder.getCs();
  cs.insert(*data);

  face1->receiveInterest(*interest, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  this->advanceClocks(190_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);

  face1->receiveInterest(*interest, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_CASE(ReceiveNack)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  auto face3 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);
  faceTable.add(face3);

  auto strategyA = Name("/strategyA").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);

  Pit& pit = forwarder.getPit();

  auto interest = makeInterest("/A/0", false, 90_ms, 562);
  lp::Nack nack = makeNack(*interest, lp::NackReason::CONGESTION);

  face1->receiveInterest(*interest, 0);
  auto entry = pit.find(*interest);
  entry->insertOrUpdateOutRecord(*face2, *interest);
  entry->insertOrUpdateOutRecord(*face3, *interest);

  this->advanceClocks(10_ms);
  face2->receiveNack(nack, 0);

  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  this->advanceClocks(50_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_CASE(ResetTimerAfterReceiveInterest)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face = make_shared<DummyFace>();
  faceTable.add(face);

  auto strategyA = Name("/strategyA").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);

  Pit& pit = forwarder.getPit();

  auto interest = makeInterest("/A/0", false, 90_ms);

  face->receiveInterest(*interest, 0);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  this->advanceClocks(100_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  this->advanceClocks(100_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_CASE(ResetTimerBeforeSatisfyInterest)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  auto face3 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);
  faceTable.add(face3);

  auto strategyA = Name("/strategyA").appendVersion(1);
  auto strategyB = Name("/strategyB").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  PitExpiryTestStrategy::registerAs(strategyB);
  auto& sA = choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);
  auto& sB = choose<PitExpiryTestStrategy>(forwarder, "/A/0", strategyB);
  Pit& pit = forwarder.getPit();

  auto interest1 = makeInterest("/A", true, 90_ms);
  auto interest2 = makeInterest("/A/0", false, 90_ms);
  auto data = makeData("/A/0");

  face1->receiveInterest(*interest1, 0);
  face2->receiveInterest(*interest2, 0);
  BOOST_CHECK_EQUAL(pit.size(), 2);

  // beforeSatisfyInterest: the first Data prolongs PIT expiry timer by 190 ms
  this->advanceClocks(30_ms);
  face3->receiveData(*data, 0);
  this->advanceClocks(189_ms);
  BOOST_CHECK_EQUAL(pit.size(), 2);
  this->advanceClocks(2_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);

  face1->receiveInterest(*interest1, 0);
  face2->receiveInterest(*interest2, 0);

  // beforeSatisfyInterest: the second Data prolongs PIT expiry timer
  // and the third one sets the timer to now
  this->advanceClocks(30_ms);
  face3->receiveData(*data, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 2);

  this->advanceClocks(30_ms);
  face3->receiveData(*data, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);

  BOOST_CHECK_EQUAL(sA.beforeSatisfyInterest_count, 3);
  BOOST_CHECK_EQUAL(sB.beforeSatisfyInterest_count, 3);
  BOOST_CHECK_EQUAL(sA.afterReceiveData_count, 0);
  BOOST_CHECK_EQUAL(sB.afterReceiveData_count, 0);
}

BOOST_AUTO_TEST_CASE(ResetTimerAfterReceiveData)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);

  auto strategyA = Name("/strategyA").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  auto& sA = choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);

  Pit& pit = forwarder.getPit();

  auto interest = makeInterest("/A/0", false, 90_ms);
  auto data = makeData("/A/0");

  face1->receiveInterest(*interest, 0);

  // afterReceiveData: the first Data prolongs PIT expiry timer by 290 ms
  this->advanceClocks(30_ms);
  face2->receiveData(*data, 0);
  this->advanceClocks(289_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);
  this->advanceClocks(2_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);

  face1->receiveInterest(*interest, 0);

  // afterReceiveData: the second Data prolongs PIT expiry timer
  // and the third one sets the timer to now
  this->advanceClocks(30_ms);
  face2->receiveData(*data, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  this->advanceClocks(30_ms);
  face2->receiveData(*data, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);

  BOOST_CHECK_EQUAL(sA.beforeSatisfyInterest_count, 0);
  BOOST_CHECK_EQUAL(sA.afterReceiveData_count, 3);
}

BOOST_AUTO_TEST_CASE(ReceiveNackAfterResetTimer)
{
  FaceTable faceTable;
  Forwarder forwarder(faceTable);

  auto face1 = make_shared<DummyFace>();
  auto face2 = make_shared<DummyFace>();
  auto face3 = make_shared<DummyFace>();
  faceTable.add(face1);
  faceTable.add(face2);
  faceTable.add(face3);

  auto strategyA = Name("/strategyA").appendVersion(1);
  PitExpiryTestStrategy::registerAs(strategyA);
  choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA);

  Pit& pit = forwarder.getPit();

  auto interest = makeInterest("/A/0", false, 90_ms, 562);
  lp::Nack nack = makeNack(*interest, lp::NackReason::CONGESTION);

  face1->receiveInterest(*interest, 0);
  auto entry = pit.find(*interest);
  entry->insertOrUpdateOutRecord(*face2, *interest);
  entry->insertOrUpdateOutRecord(*face3, *interest);

  //pitEntry is not erased after receiving the first Nack
  this->advanceClocks(10_ms);
  face2->receiveNack(nack, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 1);

  //pitEntry is erased after receiving the second Nack
  this->advanceClocks(10_ms);
  face3->receiveNack(nack, 0);
  this->advanceClocks(1_ms);
  BOOST_CHECK_EQUAL(pit.size(), 0);
}

BOOST_AUTO_TEST_SUITE_END() // TestPitExpiry
BOOST_AUTO_TEST_SUITE_END() // Fw

} // namespace tests
} // namespace fw
} // namespace nfd
