/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2019,  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 {
namespace face {
namespace tests {

using namespace nfd::tests;

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

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

  static const uint8_t data[10];
};

const uint8_t LpReassemblerFixture::data[10] = {
  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(0, 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(0, 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(0, 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(0, 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(0, received1);
  BOOST_REQUIRE(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!isComplete);
  BOOST_CHECK_EQUAL(reassembler.size(), 1);

  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, 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(0, received1);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, 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(0, frag2);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag0);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag1);
  BOOST_REQUIRE(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(0, frag0);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(1, frag0);
  BOOST_REQUIRE(!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 = 11028;
  bool isComplete = false;
  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1);
  BOOST_REQUIRE(!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_EQUAL(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_REQUIRE(!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(0, received1);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3);
  BOOST_REQUIRE(!isComplete);

  advanceClocks(1_ms, 600);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!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(0, received1);
  BOOST_REQUIRE(!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(0, received1);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3);
  BOOST_REQUIRE(!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(0, received1);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2);
  BOOST_REQUIRE(!isComplete);

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3);
  BOOST_REQUIRE(!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;

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

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

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

  std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(2, frag2_1);
  BOOST_REQUIRE(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 tests
} // namespace face
} // namespace nfd
