/* -*- 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(time::milliseconds(1), 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(time::milliseconds(1), 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
