/* -*- 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 "fw/forwarder.hpp"
#include "common/global.hpp"

#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::tests {

class ForwarderFixture : public GlobalIoTimeFixture
{
protected:
  template<typename ...Args>
  shared_ptr<DummyFace>
  addFace(Args&&... args)
  {
    auto face = make_shared<DummyFace>(std::forward<Args>(args)...);
    faceTable.add(face);
    return face;
  }

protected:
  FaceTable faceTable;
  Forwarder forwarder{faceTable};
  const ForwarderCounters& counters{forwarder.getCounters()};
};

BOOST_AUTO_TEST_SUITE(Fw)
BOOST_FIXTURE_TEST_SUITE(TestForwarder, ForwarderFixture)

BOOST_AUTO_TEST_CASE(SimpleExchange)
{
  auto face1 = addFace();
  auto face2 = addFace();

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face2, 0);

  BOOST_CHECK_EQUAL(counters.nInInterests, 0);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 0);
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);
  BOOST_CHECK_EQUAL(counters.nCsHits, 0);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 0);

  face1->receiveInterest(*makeInterest("/A/B"));
  this->advanceClocks(100_ms, 1_s);
  BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B");
  BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
  BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId());
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nCsHits, 0);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 1);

  face2->receiveData(*makeData("/A/B"));
  this->advanceClocks(100_ms, 1_s);
  BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
  BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B");
  BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
  BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId());
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInData, 1);
  BOOST_CHECK_EQUAL(counters.nOutData, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 1);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);
  BOOST_CHECK_EQUAL(counters.nCsHits, 0);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 1);
}

BOOST_AUTO_TEST_CASE(CsHit)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace();

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face2, 0);

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

  auto data = makeData("/A/B");
  data->setTag(make_shared<lp::IncomingFaceIdTag>(face3->getId()));
  forwarder.getCs().insert(*data);

  BOOST_CHECK_EQUAL(counters.nCsHits, 0);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 0);

  face1->receiveInterest(*makeInterest("/A", true));
  this->advanceClocks(1_ms, 5_ms);
  // Interest matching ContentStore should not be forwarded
  BOOST_CHECK_EQUAL(face2->sentInterests.size(), 0);
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 0);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
  BOOST_CHECK_EQUAL(counters.nCsHits, 1);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 0);

  BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
  // IncomingFaceId field should be reset to represent CS
  BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B");
  BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
  BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face::FACEID_CONTENT_STORE);
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 1);

  this->advanceClocks(100_ms, 500_ms);
  // PIT entry should not be left behind
  BOOST_CHECK_EQUAL(pit.size(), 0);

  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 1);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);
}

BOOST_AUTO_TEST_CASE(InterestWithoutNonce)
{
  auto face1 = addFace();
  auto face2 = addFace();

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face2, 0);

  auto interest = makeInterest("/A");
  BOOST_CHECK_EQUAL(interest->hasNonce(), false);
  face1->receiveInterest(*interest);

  // Ensure Nonce added if incoming packet did not have Nonce
  BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentInterests[0].hasNonce(), true);
  BOOST_CHECK_EQUAL(face2->getCounters().nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
}

BOOST_AUTO_TEST_CASE(OutgoingInterest)
{
  auto face1 = addFace();
  auto face2 = addFace();

  Pit& pit = forwarder.getPit();
  auto interestA1 = makeInterest("/A", false, std::nullopt, 8378);
  auto pitA = pit.insert(*interestA1).first;
  pitA->insertOrUpdateInRecord(*face1, *interestA1);

  auto interestA2 = makeInterest("/A", false, std::nullopt, 1698);
  auto outA2 = forwarder.onOutgoingInterest(*interestA2, *face2, pitA);
  BOOST_REQUIRE(outA2 != nullptr);
  BOOST_CHECK_EQUAL(outA2->getLastNonce(), 1698);

  // This packet will be dropped because HopLimit=0
  auto interestA3 = makeInterest("/A", false, std::nullopt, 9876);
  interestA3->setHopLimit(0);
  auto outA3 = forwarder.onOutgoingInterest(*interestA3, *face2, pitA);
  BOOST_CHECK(outA3 == nullptr);

  BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentInterests[0].getNonce(), 1698);
  BOOST_CHECK_EQUAL(counters.nInInterests, 0);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
}

BOOST_AUTO_TEST_CASE(NextHopFaceId)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace();

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face3, 0);

  auto interest = makeInterest("/A/B");
  interest->setTag(make_shared<lp::NextHopFaceIdTag>(face2->getId()));

  face1->receiveInterest(*interest);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(face3->sentInterests.size(), 0);
  BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B");
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
}

BOOST_AUTO_TEST_CASE(HopLimit)
{
  auto faceIn = addFace();
  auto faceRemote = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_NON_LOCAL);
  auto faceLocal = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
  Fib& fib = forwarder.getFib();
  fib::Entry* entryRemote = fib.insert("/remote").first;
  fib.addOrUpdateNextHop(*entryRemote, *faceRemote, 0);
  fib::Entry* entryLocal = fib.insert("/local").first;
  fib.addOrUpdateNextHop(*entryLocal, *faceLocal, 0);

  // Incoming interest w/o HopLimit will not be dropped on send or receive paths
  auto interestNoHopLimit = makeInterest("/remote/abcdefgh");
  faceIn->receiveInterest(*interestNoHopLimit);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 0);
  BOOST_REQUIRE_EQUAL(faceRemote->sentInterests.size(), 1);
  BOOST_CHECK(!faceRemote->sentInterests[0].getHopLimit());
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);

  // Incoming interest w/ HopLimit > 1 will not be dropped on send/receive
  auto interestHopLimit2 = makeInterest("/remote/ijklmnop");
  interestHopLimit2->setHopLimit(2);
  faceIn->receiveInterest(*interestHopLimit2);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 0);
  BOOST_REQUIRE_EQUAL(faceRemote->sentInterests.size(), 2);
  BOOST_REQUIRE(faceRemote->sentInterests[1].getHopLimit());
  BOOST_CHECK_EQUAL(*faceRemote->sentInterests[1].getHopLimit(), 1);
  BOOST_CHECK_EQUAL(counters.nInInterests, 2);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 2);

  // Incoming interest w/ HopLimit == 1 will be dropped on send path if going out on remote face
  auto interestHopLimit1Remote = makeInterest("/remote/qrstuvwx");
  interestHopLimit1Remote->setHopLimit(1);
  faceIn->receiveInterest(*interestHopLimit1Remote);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 1);
  BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 2);
  BOOST_CHECK_EQUAL(counters.nInInterests, 3);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 2);

  // Incoming interest w/ HopLimit == 1 will not be dropped on send path if going out on local face
  auto interestHopLimit1Local = makeInterest("/local/abcdefgh");
  interestHopLimit1Local->setHopLimit(1);
  faceIn->receiveInterest(*interestHopLimit1Local);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(faceLocal->getCounters().nOutInterests, 1);
  BOOST_CHECK_EQUAL(faceLocal->getCounters().nInHopLimitZero, 0);
  BOOST_CHECK_EQUAL(faceLocal->getCounters().nOutHopLimitZero, 0);
  BOOST_REQUIRE_EQUAL(faceLocal->sentInterests.size(), 1);
  BOOST_REQUIRE(faceLocal->sentInterests[0].getHopLimit());
  BOOST_CHECK_EQUAL(*faceLocal->sentInterests[0].getHopLimit(), 0);
  BOOST_CHECK_EQUAL(counters.nInInterests, 4);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 3);

  // Interest w/ HopLimit == 0 will be dropped on receive path
  auto interestHopLimit0 = makeInterest("/remote/yzabcdef");
  interestHopLimit0->setHopLimit(0);
  faceIn->receiveInterest(*interestHopLimit0);
  this->advanceClocks(100_ms, 1_s);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2);
  BOOST_CHECK_EQUAL(faceIn->getCounters().nInHopLimitZero, 1);
  BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 1);
  BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 2);
  BOOST_CHECK_EQUAL(counters.nInInterests, 5);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 3);

  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
}

BOOST_AUTO_TEST_CASE(AddDefaultHopLimit)
{
  auto face = addFace();
  auto faceEndpoint = FaceEndpoint(*face);
  Pit& pit = forwarder.getPit();
  auto i1 = makeInterest("/A");
  auto pitA = pit.insert(*i1).first;

  // By default, no HopLimit should be added
  auto i2 = makeInterest("/A");
  BOOST_TEST(!i2->getHopLimit().has_value());
  forwarder.onContentStoreMiss(*i2, faceEndpoint, pitA);
  BOOST_TEST(!i2->getHopLimit().has_value());

  // Change config value to 10
  forwarder.m_config.defaultHopLimit = 10;

  // HopLimit should be set to 10 now
  auto i3 = makeInterest("/A");
  BOOST_TEST(!i3->getHopLimit().has_value());
  forwarder.onContentStoreMiss(*i3, faceEndpoint, pitA);
  BOOST_REQUIRE(i3->getHopLimit().has_value());
  BOOST_TEST(*i3->getHopLimit() == 10);

  // An existing HopLimit should be preserved
  auto i4 = makeInterest("/A");
  i4->setHopLimit(50);
  forwarder.onContentStoreMiss(*i4, faceEndpoint, pitA);
  BOOST_REQUIRE(i4->getHopLimit().has_value());
  BOOST_TEST(*i4->getHopLimit() == 50);
}

BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
{
  auto face1 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
  auto face2 = addFace(); // default is non-local

  auto& strategy = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName());
  strategy.afterReceiveInterest_count = 0;

  // local face, /localhost: OK
  auto i1 = makeInterest("/localhost/A1");
  forwarder.onIncomingInterest(*i1, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1);

  // non-local face, /localhost: violate
  auto i2 = makeInterest("/localhost/A2");
  forwarder.onIncomingInterest(*i2, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(counters.nInInterests, 2);
  BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1);

  // local face, non-/localhost: OK
  auto i3 = makeInterest("/A3");
  forwarder.onIncomingInterest(*i3, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(counters.nInInterests, 3);
  BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 2);

  // non-local face, non-/localhost: OK
  auto i4 = makeInterest("/A4");
  forwarder.onIncomingInterest(*i4, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(counters.nInInterests, 4);
  BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 3);

  BOOST_CHECK_EQUAL(counters.nOutInterests, 0);
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);

  // local face, /localhost: OK
  auto d1 = makeData("/localhost/B1");
  forwarder.onIncomingData(*d1, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(counters.nInData, 1);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 1);

  // non-local face, /localhost: violate
  auto d2 = makeData("/localhost/B2");
  forwarder.onIncomingData(*d2, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(counters.nInData, 2);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 1);

  // local face, non-/localhost: OK
  auto d3 = makeData("/B3");
  forwarder.onIncomingData(*d3, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(counters.nInData, 3);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 2);

  // non-local face, non-/localhost: OK
  auto d4 = makeData("/B4");
  forwarder.onIncomingData(*d4, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(counters.nInData, 4);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 3);

  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
}

BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch)
{
  auto face1 = addFace();
  auto face2 = addFace();

  auto& strategyA = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName());
  auto& strategyB = choose<DummyStrategy>(forwarder, "/B", DummyStrategy::getStrategyName());

  auto interest1 = makeInterest("/A/1");
  strategyA.afterReceiveInterest_count = 0;
  strategyA.interestOutFace = face2;
  forwarder.onIncomingInterest(*interest1, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveInterest_count, 1);

  auto interest2 = makeInterest("/B/2", true);
  strategyB.afterReceiveInterest_count = 0;
  strategyB.interestOutFace = face2;
  forwarder.onIncomingInterest(*interest2, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyB.afterReceiveInterest_count, 1);

  this->advanceClocks(1_ms, 5_ms);

  auto data1 = makeData("/A/1");
  strategyA.beforeSatisfyInterest_count = 0;
  forwarder.onIncomingData(*data1, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(strategyA.beforeSatisfyInterest_count, 1);

  auto data2 = makeData("/B/2/b");
  strategyB.beforeSatisfyInterest_count = 0;
  forwarder.onIncomingData(*data2, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(strategyB.beforeSatisfyInterest_count, 1);

  auto interest3 = makeInterest("/A/3", false, 30_ms);
  forwarder.onIncomingInterest(*interest3, FaceEndpoint(*face1));
  auto interest4 = makeInterest("/B/4", false, 5_s);
  forwarder.onIncomingInterest(*interest4, FaceEndpoint(*face1));

  this->advanceClocks(1_ms, 5_ms);

  BOOST_CHECK_EQUAL(counters.nInInterests, 4);
  BOOST_CHECK_EQUAL(counters.nInData, 2);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 2);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);
  BOOST_CHECK_EQUAL(counters.nCsHits, 0);
  BOOST_CHECK_EQUAL(counters.nCsMisses, 4);
}

BOOST_AUTO_TEST_CASE(IncomingData)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace();
  auto face4 = addFace();

  Pit& pit = forwarder.getPit();
  auto interestD = makeInterest("/A/B/C/D");
  auto pitD = pit.insert(*interestD).first;
  pitD->insertOrUpdateInRecord(*face1, *interestD);
  auto interestA = makeInterest("/A", true);
  auto pitA = pit.insert(*interestA).first;
  pitA->insertOrUpdateInRecord(*face2, *interestA);
  pitA->insertOrUpdateInRecord(*face3, *interestA);
  auto interestC = makeInterest("/A/B/C", true);
  auto pitC = pit.insert(*interestC).first;
  pitC->insertOrUpdateInRecord(*face3, *interestC);
  pitC->insertOrUpdateInRecord(*face4, *interestC);

  auto dataD = makeData("/A/B/C/D");
  forwarder.onIncomingData(*dataD, FaceEndpoint(*face3));
  this->advanceClocks(1_ms, 5_ms);

  BOOST_CHECK_EQUAL(face1->sentData.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentData.size(), 1);
  BOOST_CHECK_EQUAL(face3->sentData.size(), 0);
  BOOST_CHECK_EQUAL(face4->sentData.size(), 1);

  BOOST_CHECK_EQUAL(counters.nInData, 1);
  BOOST_CHECK_EQUAL(counters.nOutData, 3);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 3);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);
}

BOOST_AUTO_TEST_CASE(OutgoingData)
{
  auto face1 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
  auto face2 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_NON_LOCAL);
  auto face3 = addFace();
  face3->setId(face::INVALID_FACEID);

  auto data = makeData("/QkzAWU6K");
  auto localData = makeData("/localhost/YH8bqnbv");

  face1->sentData.clear();
  BOOST_CHECK(forwarder.onOutgoingData(*data, *face1));
  BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
  BOOST_CHECK_EQUAL(face1->sentData[0].getName(), data->getName());
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 1);

  // scope control
  face1->sentData.clear();
  face2->sentData.clear();
  BOOST_CHECK(!forwarder.onOutgoingData(*localData, *face2));
  BOOST_CHECK_EQUAL(face2->sentData.size(), 0);
  BOOST_CHECK(forwarder.onOutgoingData(*localData, *face1));
  BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
  BOOST_CHECK_EQUAL(face1->sentData[0].getName(), localData->getName());
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 2);

  // face with invalid ID
  face3->sentData.clear();
  BOOST_CHECK(!forwarder.onOutgoingData(*data, *face3));
  BOOST_CHECK_EQUAL(face3->sentData.size(), 0);
  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 2);
}

BOOST_AUTO_TEST_CASE(IncomingNack)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace("dummy://", "dummy://",
                       ndn::nfd::FACE_SCOPE_NON_LOCAL,
                       ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
                       ndn::nfd::LINK_TYPE_MULTI_ACCESS);

  auto& strategyA = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName());
  auto& strategyB = choose<DummyStrategy>(forwarder, "/B", DummyStrategy::getStrategyName());

  Pit& pit = forwarder.getPit();

  // dispatch to the correct strategy
  auto interest1 = makeInterest("/A/AYJqayrzF", false, std::nullopt, 562);
  auto pit1 = pit.insert(*interest1).first;
  pit1->insertOrUpdateOutRecord(*face1, *interest1);
  auto interest2 = makeInterest("/B/EVyP73ru", false, std::nullopt, 221);
  auto pit2 = pit.insert(*interest2).first;
  pit2->insertOrUpdateOutRecord(*face1, *interest2);

  auto nack1 = makeNack(*interest1, lp::NackReason::CONGESTION);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack1, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 1);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0);

  auto nack2 = makeNack(*interest2, lp::NackReason::CONGESTION);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack2, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 1);

  // record Nack on PIT out-record
  auto outRecord1 = pit1->findOutRecord(*face1);
  BOOST_REQUIRE(outRecord1 != pit1->out_end());
  BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr);
  BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION);

  // drop if no PIT entry
  auto nack3 = makeNack(*makeInterest("/yEcw5HhdM", false, std::nullopt, 243), lp::NackReason::CONGESTION);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack3, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0);

  // drop if no out-record
  auto interest4 = makeInterest("/Etab4KpY", false, std::nullopt, 157);
  auto pit4 = pit.insert(*interest4).first;
  pit4->insertOrUpdateOutRecord(*face1, *interest4);

  auto nack4a = makeNack(*interest4, lp::NackReason::CONGESTION);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack4a, FaceEndpoint(*face2));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0);

  // drop if Nonce does not match out-record
  auto nack4b = makeNack(*makeInterest("/Etab4KpY", false, std::nullopt, 294), lp::NackReason::CONGESTION);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack4b, FaceEndpoint(*face1));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0);

  // drop if inFace is multi-access
  pit4->insertOrUpdateOutRecord(*face3, *interest4);
  strategyA.afterReceiveNack_count = 0;
  strategyB.afterReceiveNack_count = 0;
  forwarder.onIncomingNack(nack4a, FaceEndpoint(*face3));
  BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0);
  BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0);

  this->advanceClocks(1_ms, 10_ms);

  BOOST_CHECK_EQUAL(counters.nInNacks, 6);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
  BOOST_CHECK_EQUAL(counters.nSatisfiedInterests, 0);
  BOOST_CHECK_EQUAL(counters.nUnsatisfiedInterests, 2);
}

BOOST_AUTO_TEST_CASE(OutgoingNack)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace("dummy://", "dummy://",
                       ndn::nfd::FACE_SCOPE_NON_LOCAL,
                       ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
                       ndn::nfd::LINK_TYPE_MULTI_ACCESS);
  auto face4 = addFace();
  face4->setId(face::INVALID_FACEID);

  Pit& pit = forwarder.getPit();

  lp::NackHeader nackHeader;
  nackHeader.setReason(lp::NackReason::CONGESTION);

  // don't send Nack if there's no in-record
  auto interest1 = makeInterest("/fM5IVEtC", false, std::nullopt, 719);
  auto pit1 = pit.insert(*interest1).first;
  pit1->insertOrUpdateInRecord(*face1, *interest1);

  face2->sentNacks.clear();
  BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face2, pit1));
  BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);

  // send Nack with correct Nonce
  auto interest2a = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 152);
  auto pit2 = pit.insert(*interest2a).first;
  pit2->insertOrUpdateInRecord(*face1, *interest2a);
  auto interest2b = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 808);
  pit2->insertOrUpdateInRecord(*face2, *interest2b);
  face1->sentNacks.clear();
  face2->sentNacks.clear();

  BOOST_CHECK(forwarder.onOutgoingNack(nackHeader, *face1, pit2));
  BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
  BOOST_CHECK_EQUAL(face1->sentNacks[0].getReason(), lp::NackReason::CONGESTION);
  BOOST_CHECK_EQUAL(face1->sentNacks[0].getInterest().getNonce(), 152);
  BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);

  // in-record is erased
  auto inRecord2a = pit2->findInRecord(*face1);
  BOOST_CHECK(inRecord2a == pit2->in_end());

  // send Nack with correct Nonce
  BOOST_CHECK(forwarder.onOutgoingNack(nackHeader, *face2, pit2));
  BOOST_CHECK_EQUAL(face1->sentNacks.size(), 1);
  BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentNacks[0].getReason(), lp::NackReason::CONGESTION);
  BOOST_CHECK_EQUAL(face2->sentNacks[0].getInterest().getNonce(), 808);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 2);

  // in-record is erased
  auto inRecord2b = pit2->findInRecord(*face2);
  BOOST_CHECK(inRecord2b == pit2->in_end());

  // don't send Nack to multi-access face
  auto interest2c = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 228);
  pit2->insertOrUpdateInRecord(*face3, *interest2c);

  face3->sentNacks.clear();
  BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face3, pit2));
  BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 2);

  // don't send Nack to face with invalid ID
  auto interest1b = makeInterest("/fM5IVEtC", false, std::nullopt, 553);
  pit1->insertOrUpdateInRecord(*face4, *interest1b);

  face4->sentNacks.clear();
  BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face4, pit1));
  BOOST_CHECK_EQUAL(face4->sentNacks.size(), 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 2);
}

BOOST_AUTO_TEST_CASE(InterestLoopNack)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace("dummy://", "dummy://",
                       ndn::nfd::FACE_SCOPE_NON_LOCAL,
                       ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
                       ndn::nfd::LINK_TYPE_MULTI_ACCESS);
  auto face4 = addFace();

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/zT4XwK0Hnx").first;
  fib.addOrUpdateNextHop(*entry, *face4, 0);

  // receive Interest on face1
  face1->sentNacks.clear();
  auto interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732);
  face1->receiveInterest(*interest1a);
  BOOST_CHECK(face1->sentNacks.empty());
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);

  // receive Interest with duplicate Nonce on face1: legit retransmission
  face1->sentNacks.clear();
  auto interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732);
  face1->receiveInterest(*interest1b);
  BOOST_CHECK(face1->sentNacks.empty());
  BOOST_CHECK_EQUAL(counters.nInInterests, 2);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);

  // receive Interest with duplicate Nonce on face2
  face2->sentNacks.clear();
  auto interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732);
  face2->receiveInterest(*interest2a);
  BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
  BOOST_CHECK_EQUAL(face2->sentNacks[0].getInterest().wireEncode(), interest2a->wireEncode());
  BOOST_CHECK_EQUAL(face2->sentNacks[0].getReason(), lp::NackReason::DUPLICATE);
  BOOST_CHECK_EQUAL(counters.nInInterests, 3);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);

  // receive Interest with new Nonce on face2
  face2->sentNacks.clear();
  auto interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 944);
  face2->receiveInterest(*interest2b);
  BOOST_CHECK(face2->sentNacks.empty());
  BOOST_CHECK_EQUAL(counters.nInInterests, 4);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);

  // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face
  face3->sentNacks.clear();
  auto interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732);
  face3->receiveInterest(*interest3a);
  BOOST_CHECK(face3->sentNacks.empty());
  BOOST_CHECK_EQUAL(counters.nInInterests, 5);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);
}

BOOST_AUTO_TEST_CASE(InterestLoopWithShortLifetime) // Bug 1953
{
  auto face1 = addFace();
  auto face2 = addFace();

  // cause an Interest sent out of face2 to loop back into face1 after a delay
  face2->afterSend.connect([face1, face2] (uint32_t pktType) {
    if (pktType == tlv::Interest) {
      auto interest = make_shared<Interest>(face2->sentInterests.back());
      getScheduler().schedule(170_ms, [face1, interest] { face1->receiveInterest(*interest); });
    }
  });

  Fib& fib = forwarder.getFib();
  fib::Entry* entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face2, 0);

  // receive an Interest
  auto interest = makeInterest("/A/1", false, 50_ms, 82101183);
  face1->receiveInterest(*interest);

  // Interest should be forwarded only once, as long as Nonce is in Dead Nonce List
  BOOST_ASSERT(25_ms * 40 < forwarder.getDeadNonceList().getLifetime());
  this->advanceClocks(25_ms, 40);
  BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1);
  BOOST_CHECK_EQUAL(counters.nInInterests, 2);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 1);
  BOOST_CHECK_EQUAL(counters.nInNacks, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);

  // It's unnecessary to check that Interest with duplicate Nonce can be forwarded again
  // after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List
  // is an implementation decision. The NDN protocol requires Name+Nonce to be unique,
  // without specifying when Name+Nonce could repeat. Theoretically, a forwarder is allowed
  // to suppress an Interest if its Name+Nonce has appeared at any point in the past.
}

BOOST_AUTO_TEST_CASE(PitLeak) // Bug 3484
{
  auto face1 = addFace();
  auto interest = makeInterest("/hcLSAsQ9A", false, 2_s, 61883075);

  auto& dnl = forwarder.getDeadNonceList();
  dnl.add(interest->getName(), interest->getNonce());
  auto& pit = forwarder.getPit();
  BOOST_CHECK_EQUAL(pit.size(), 0);

  forwarder.onIncomingInterest(*interest, FaceEndpoint(*face1));
  // PIT entry is never created if a loop is detected by the Dead Nonce List
  BOOST_CHECK_EQUAL(pit.size(), 0);
  BOOST_CHECK_EQUAL(counters.nInInterests, 1);
  BOOST_CHECK_EQUAL(counters.nOutInterests, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 1);
}

BOOST_AUTO_TEST_CASE(UnsolicitedData)
{
  auto face1 = addFace();
  auto data = makeData("/A");

  BOOST_CHECK_EQUAL(counters.nInData, 0);
  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 0);

  forwarder.onIncomingData(*data, FaceEndpoint(*face1));
  this->advanceClocks(1_ms, 10_ms);
  BOOST_CHECK_EQUAL(counters.nInData, 1);
  BOOST_CHECK_EQUAL(counters.nOutData, 0);
  BOOST_CHECK_EQUAL(counters.nOutNacks, 0);
  BOOST_CHECK_EQUAL(counters.nUnsolicitedData, 1);
}

BOOST_AUTO_TEST_CASE(NewNextHop)
{
  auto face1 = addFace();
  auto face2 = addFace();
  auto face3 = addFace();
  auto face4 = addFace();

  auto& strategy = choose<DummyStrategy>(forwarder, "/A", DummyStrategy::getStrategyName());

  Fib& fib = forwarder.getFib();
  Pit& pit = forwarder.getPit();

  // fib: "/", "/A/B", "/A/B/C/D/E"
  fib::Entry* entry = fib.insert("/").first;
  fib.addOrUpdateNextHop(*entry, *face1, 100);
  entry = fib.insert("/A/B").first;
  fib.addOrUpdateNextHop(*entry, *face2, 0);
  entry = fib.insert("/A/B/C/D/E").first;
  fib.addOrUpdateNextHop(*entry, *face3, 0);

  // pit: "/A", "/A/B/C", "/A/B/Z"
  auto interest1 = makeInterest("/A");
  auto pit1 = pit.insert(*interest1).first;
  pit1->insertOrUpdateInRecord(*face3, *interest1);
  auto interest2 = makeInterest("/A/B/C");
  auto pit2 = pit.insert(*interest2).first;
  pit2->insertOrUpdateInRecord(*face3, *interest2);
  auto interest3 = makeInterest("/A/B/Z");
  auto pit3 = pit.insert(*interest3).first;
  pit3->insertOrUpdateInRecord(*face3, *interest3);

  // new nexthop for "/"
  entry = fib.insert("/").first;
  fib.addOrUpdateNextHop(*entry, *face2, 50);

  // /A     --> triggered
  // /A/B/C --> not triggered
  // /A/B/Z --> not triggered
  BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 1);
  BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A");
  strategy.afterNewNextHopCalls.clear();

  // new nexthop for "/A"
  entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face4, 50);

  // /A     --> triggered
  // /A/B/C --> not triggered
  // /A/B/Z --> not triggered
  BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 1);
  BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A");
  strategy.afterNewNextHopCalls.clear();

  // new nexthop for "/A/B"
  entry = fib.insert("/A/B").first;
  fib.addOrUpdateNextHop(*entry, *face4, 0);

  // /A     --> not triggered
  // /A/B/C --> triggered
  // /A/B/Z --> triggered
  BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 2);
  BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A/B/C");
  BOOST_TEST(strategy.afterNewNextHopCalls[1] == "/A/B/Z");
  strategy.afterNewNextHopCalls.clear();

  // new nexthop for "/A/B/C/D"
  entry = fib.insert("/A/B/C/D").first;
  fib.addOrUpdateNextHop(*entry, *face1, 0);

  // nothing triggered
  BOOST_TEST(strategy.afterNewNextHopCalls.size() == 0);

  // create a second pit entry for /A
  auto interest4 = makeInterest("/A");
  interest4->setMustBeFresh(true);
  auto pit4 = pit.insert(*interest4).first;
  pit4->insertOrUpdateInRecord(*face3, *interest4);

  // new nexthop for "/A"
  entry = fib.insert("/A").first;
  fib.addOrUpdateNextHop(*entry, *face1, 0);

  // /A     --> triggered twice
  // /A/B/C --> not triggered
  // /A/B/Z --> not triggered
  BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 2);
  BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A");
  BOOST_TEST(strategy.afterNewNextHopCalls[1] == "/A");
}

BOOST_AUTO_TEST_SUITE(ProcessConfig)

BOOST_AUTO_TEST_CASE(DefaultHopLimit)
{
  ConfigFile cf;
  forwarder.setConfigFile(cf);

  std::string config = R"CONFIG(
    forwarder
    {
      default_hop_limit 10
    }
  )CONFIG";

  // The default value is 0
  BOOST_TEST(forwarder.m_config.defaultHopLimit == 0);

  // Dry run parsing should not change the default config
  cf.parse(config, true, "dummy-config");
  BOOST_TEST(forwarder.m_config.defaultHopLimit == 0);

  // Check if the actual parsing works
  cf.parse(config, false, "dummy-config");
  BOOST_TEST(forwarder.m_config.defaultHopLimit == 10);

  // After removing default_hop_limit from the config file,
  // the default value of zero should be restored
  config = R"CONFIG(
    forwarder
    {
    }
  )CONFIG";

  cf.parse(config, false, "dummy-config");
  BOOST_TEST(forwarder.m_config.defaultHopLimit == 0);
}

BOOST_AUTO_TEST_CASE(BadDefaultHopLimit)
{
  ConfigFile cf;
  forwarder.setConfigFile(cf);

  // not a number
  std::string config = R"CONFIG(
    forwarder
    {
      default_hop_limit hello
    }
  )CONFIG";

  BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error);
  BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error);

  // negative number
  config = R"CONFIG(
    forwarder
    {
      default_hop_limit -1
    }
  )CONFIG";

  BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error);
  BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error);

  // out of range
  config = R"CONFIG(
    forwarder
    {
      default_hop_limit 256
    }
  )CONFIG";

  BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error);
  BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error);
}

BOOST_AUTO_TEST_SUITE_END() // ProcessConfig

BOOST_AUTO_TEST_SUITE_END() // TestForwarder
BOOST_AUTO_TEST_SUITE_END() // Fw

} // namespace nfd::tests
