/* -*- 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 "face/lp-reassembler.hpp"

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

namespace nfd::tests {

using namespace nfd::face;

class LpReassemblerFixture : public GlobalIoTimeFixture
{
protected:
  LpReassemblerFixture()
  {
    reassembler.beforeTimeout.connect(
      [this] (const EndpointId& remoteEp, size_t nDroppedFragments) {
        timeoutHistory.emplace_back(remoteEp, nDroppedFragments);
      });
  }

protected:
  LpReassembler reassembler{{}};
  std::vector<std::pair<EndpointId, size_t>> timeoutHistory;

  static constexpr uint8_t data[] = {
    0x06, 0x08, // Data
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  };
};

BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture)

BOOST_AUTO_TEST_SUITE(SingleFragment)

BOOST_AUTO_TEST_CASE(Normal)
{
  ndn::Buffer dataBuffer(data, sizeof(data));

  lp::Packet received;
  received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
  received.add<lp::FragIndexField>(0);
  received.add<lp::FragCountField>(1);
  received.add<lp::SequenceField>(1000);
  received.add<lp::NextHopFaceIdField>(200);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;
  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);

  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
  BOOST_CHECK_EQUAL(reassembler.size(), 0);
}

BOOST_AUTO_TEST_CASE(OmitFragIndex)
{
  ndn::Buffer dataBuffer(data, sizeof(data));

  lp::Packet received;
  received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
  received.add<lp::FragCountField>(1);
  received.add<lp::SequenceField>(1000);
  received.add<lp::NextHopFaceIdField>(200);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;
  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);

  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
}

BOOST_AUTO_TEST_CASE(OmitFragCount)
{
  ndn::Buffer dataBuffer(data, sizeof(data));

  lp::Packet received;
  received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
  received.add<lp::FragIndexField>(0);
  received.add<lp::SequenceField>(1000);
  received.add<lp::NextHopFaceIdField>(200);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;
  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);

  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
}

BOOST_AUTO_TEST_CASE(OmitFragIndexAndFragCount)
{
  ndn::Buffer dataBuffer(data, sizeof(data));

  lp::Packet received;
  received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
  received.add<lp::SequenceField>(1000);
  received.add<lp::NextHopFaceIdField>(200);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;
  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);

  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
}

BOOST_AUTO_TEST_SUITE_END() // SingleFragment

BOOST_AUTO_TEST_SUITE(MultiFragment)

BOOST_AUTO_TEST_CASE(Normal)
{
  ndn::Buffer data1Buffer(data, 4);
  ndn::Buffer data2Buffer(data + 4, 4);
  ndn::Buffer data3Buffer(data + 8, 2);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(3);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(3);
  received2.add<lp::SequenceField>(1001);

  lp::Packet received3;
  received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
  received3.add<lp::FragIndexField>(2);
  received3.add<lp::FragCountField>(3);
  received3.add<lp::SequenceField>(1002);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
  BOOST_CHECK_EQUAL(reassembler.size(), 0);
}

BOOST_AUTO_TEST_CASE(OmitFragIndex0)
{
  ndn::Buffer data1Buffer(data, 4);
  ndn::Buffer data2Buffer(data + 4, 4);
  ndn::Buffer data3Buffer(data + 8, 2);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragCountField>(3);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(3);
  received2.add<lp::SequenceField>(1001);

  lp::Packet received3;
  received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
  received3.add<lp::FragIndexField>(2);
  received3.add<lp::FragCountField>(3);
  received3.add<lp::SequenceField>(1002);

  bool isComplete = false;
  Block netPacket;
  lp::Packet packet;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
  BOOST_REQUIRE(isComplete);
  BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
  BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
}

BOOST_AUTO_TEST_CASE(OutOfOrder)
{
  ndn::Buffer data0Buffer(data, 4);
  ndn::Buffer data1Buffer(data + 4, 4);
  ndn::Buffer data2Buffer(data + 8, 2);

  lp::Packet frag0;
  frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
  frag0.add<lp::FragIndexField>(0);
  frag0.add<lp::FragCountField>(3);
  frag0.add<lp::SequenceField>(1000);
  frag0.add<lp::NextHopFaceIdField>(200);

  lp::Packet frag1;
  frag1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  frag1.add<lp::FragIndexField>(1);
  frag1.add<lp::FragCountField>(3);
  frag1.add<lp::SequenceField>(1001);

  lp::Packet frag2;
  frag2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  frag2.add<lp::FragIndexField>(2);
  frag2.add<lp::FragCountField>(3);
  frag2.add<lp::SequenceField>(1002);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag2);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag1);
  BOOST_TEST(isComplete);
}

BOOST_AUTO_TEST_CASE(Duplicate)
{
  ndn::Buffer data0Buffer(data, 5);

  lp::Packet frag0;
  frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
  frag0.add<lp::FragIndexField>(0);
  frag0.add<lp::FragCountField>(2);
  frag0.add<lp::SequenceField>(1000);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_CASE(Timeout)
{
  ndn::Buffer data1Buffer(data, 5);
  ndn::Buffer data2Buffer(data + 5, 5);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(2);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(2);
  received2.add<lp::SequenceField>(1001);

  const EndpointId REMOTE_EP = ethernet::getDefaultMulticastAddress();
  bool isComplete = false;
  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1);
  BOOST_TEST(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);
  BOOST_CHECK(timeoutHistory.empty());

  advanceClocks(1_ms, 600);
  BOOST_CHECK_EQUAL(reassembler.size(), 0);
  BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1);
  BOOST_CHECK(std::get<0>(timeoutHistory.back()) == REMOTE_EP);
  BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_CASE(MissingSequence)
{
  ndn::Buffer data1Buffer(data, 4);
  ndn::Buffer data2Buffer(data + 4, 4);
  ndn::Buffer data3Buffer(data + 8, 2);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(3);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(3);

  lp::Packet received3;
  received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
  received3.add<lp::FragIndexField>(2);
  received3.add<lp::FragCountField>(3);
  received3.add<lp::SequenceField>(1002);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
  BOOST_TEST(!isComplete);

  advanceClocks(1_ms, 600);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_CASE(FragCountOverLimit)
{
  ndn::Buffer data1Buffer(data, sizeof(data));

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(256);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_CASE(MissingFragCount)
{
  ndn::Buffer data1Buffer(data, 4);
  ndn::Buffer data2Buffer(data + 4, 4);
  ndn::Buffer data3Buffer(data + 8, 2);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(3);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(50);
  received2.add<lp::SequenceField>(1001);

  lp::Packet received3;
  received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
  received3.add<lp::FragIndexField>(2);
  received3.add<lp::FragCountField>(3);
  received3.add<lp::SequenceField>(1002);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_CASE(OverFragCount)
{
  LpReassembler::Options options;
  options.nMaxFragments = 2;
  reassembler.setOptions(options);

  ndn::Buffer data1Buffer(data, 4);
  ndn::Buffer data2Buffer(data + 4, 4);
  ndn::Buffer data3Buffer(data + 8, 2);

  lp::Packet received1;
  received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  received1.add<lp::FragIndexField>(0);
  received1.add<lp::FragCountField>(3);
  received1.add<lp::SequenceField>(1000);
  received1.add<lp::NextHopFaceIdField>(200);

  lp::Packet received2;
  received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  received2.add<lp::FragIndexField>(1);
  received2.add<lp::FragCountField>(3);
  received2.add<lp::SequenceField>(1001);

  lp::Packet received3;
  received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
  received3.add<lp::FragIndexField>(2);
  received3.add<lp::FragCountField>(3);
  received3.add<lp::SequenceField>(1002);

  bool isComplete = false;

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
  BOOST_TEST(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
  BOOST_TEST(!isComplete);
}

BOOST_AUTO_TEST_SUITE_END() // MultiFragment

BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints)

BOOST_AUTO_TEST_CASE(Normal)
{
  ndn::Buffer data1Buffer(data, 5);
  ndn::Buffer data2Buffer(data + 5, 5);

  lp::Packet frag1_1;
  frag1_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  frag1_1.add<lp::FragIndexField>(0);
  frag1_1.add<lp::FragCountField>(2);
  frag1_1.add<lp::SequenceField>(2000);
  frag1_1.add<lp::NextHopFaceIdField>(200);

  lp::Packet frag1_2;
  frag1_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  frag1_2.add<lp::FragIndexField>(1);
  frag1_2.add<lp::FragCountField>(2);
  frag1_2.add<lp::SequenceField>(2001);

  lp::Packet frag2_1;
  frag2_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
  frag2_1.add<lp::FragIndexField>(0);
  frag2_1.add<lp::FragCountField>(2);
  frag2_1.add<lp::SequenceField>(2000);
  frag2_1.add<lp::NextHopFaceIdField>(200);

  lp::Packet frag2_2;
  frag2_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
  frag2_2.add<lp::FragIndexField>(1);
  frag2_2.add<lp::FragCountField>(2);
  frag2_2.add<lp::SequenceField>(2001);

  bool isComplete = false;

  const EndpointId REMOTE_EP_1 = ethernet::Address::fromString("11:22:33:45:67:89");
  const EndpointId REMOTE_EP_2 = ethernet::Address::fromString("11:22:33:ab:cd:ef");

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_1);
  BOOST_TEST(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_2);
  BOOST_TEST(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 2);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_2);
  BOOST_TEST(isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_1);
  BOOST_TEST(isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 0);
}

BOOST_AUTO_TEST_SUITE_END() // MultipleRemoteEndpoints

BOOST_AUTO_TEST_SUITE_END() // TestLpReassembler
BOOST_AUTO_TEST_SUITE_END() // Face

} // namespace nfd::tests
