/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2018,  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-fragmenter.hpp"
#include "face/transport.hpp"

#include "tests/test-common.hpp"

namespace nfd {
namespace face {
namespace tests {

using namespace nfd::tests;

class LpFragmenterFixture : public BaseFixture
{
protected:
  LpFragmenter fragmenter{{}};
};

BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestLpFragmenter, LpFragmenterFixture)

BOOST_AUTO_TEST_CASE(FragmentSingleFragment)
{
  size_t mtu = 256;

  lp::Packet packet;
  packet.add<lp::IncomingFaceIdField>(123);

  shared_ptr<Data> data = makeData("/test/data1");
  BOOST_REQUIRE_EQUAL(data->wireEncode().size(), 30);
  packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(),
                                               data->wireEncode().end()));

  bool isOk = false;
  std::vector<lp::Packet> frags;
  std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);

  BOOST_REQUIRE(isOk);
  BOOST_REQUIRE_EQUAL(frags.size(), 1);
  BOOST_CHECK(frags[0].has<lp::FragmentField>());
  BOOST_CHECK_EQUAL(frags[0].get<lp::IncomingFaceIdField>(), 123);
  BOOST_CHECK(!frags[0].has<lp::FragIndexField>());
  BOOST_CHECK(!frags[0].has<lp::FragCountField>());
  BOOST_CHECK_LE(frags[0].wireEncode().size(), mtu);

  ndn::Buffer::const_iterator fragBegin, fragEnd;
  std::tie(fragBegin, fragEnd) = frags[0].get<lp::FragmentField>();
  BOOST_CHECK_EQUAL_COLLECTIONS(data->wireEncode().begin(), data->wireEncode().end(),
                                fragBegin, fragEnd);
}

BOOST_AUTO_TEST_CASE(FragmentMultipleFragments)
{
  size_t mtu = Transport::MIN_MTU;

  lp::Packet packet;
  packet.add<lp::IncomingFaceIdField>(123);

  shared_ptr<Data> data = makeData("/test/data1/123456789/987654321/123456789");
  BOOST_REQUIRE_EQUAL(data->wireEncode().size(), 63);
  packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(),
                                               data->wireEncode().end()));

  bool isOk = false;
  std::vector<lp::Packet> frags;
  std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);

  BOOST_REQUIRE(isOk);
  BOOST_REQUIRE_EQUAL(frags.size(), 5);

  ndn::Buffer reassembledPayload(63);

  BOOST_CHECK(frags[0].has<lp::FragmentField>());
  BOOST_CHECK_EQUAL(frags[0].get<lp::IncomingFaceIdField>(), 123);
  BOOST_CHECK_EQUAL(frags[0].get<lp::FragIndexField>(), 0);
  BOOST_CHECK_EQUAL(frags[0].get<lp::FragCountField>(), 5);
  BOOST_CHECK_LE(frags[0].wireEncode().size(), mtu);
  ndn::Buffer::const_iterator frag0Begin, frag0End;
  std::tie(frag0Begin, frag0End) = frags[0].get<lp::FragmentField>();
  BOOST_REQUIRE_LE(std::distance(frag0Begin, frag0End), reassembledPayload.size());
  auto reassembledPos = std::copy(frag0Begin, frag0End, reassembledPayload.begin());

  BOOST_CHECK(frags[1].has<lp::FragmentField>());
  BOOST_CHECK(!frags[1].has<lp::IncomingFaceIdField>());
  BOOST_CHECK_EQUAL(frags[1].get<lp::FragIndexField>(), 1);
  BOOST_CHECK_EQUAL(frags[1].get<lp::FragCountField>(), 5);
  BOOST_CHECK_LE(frags[1].wireEncode().size(), mtu);
  ndn::Buffer::const_iterator frag1Begin, frag1End;
  std::tie(frag1Begin, frag1End) = frags[1].get<lp::FragmentField>();
  BOOST_REQUIRE_LE(std::distance(frag1Begin, frag1End),
                   std::distance(reassembledPos, reassembledPayload.end()));
  reassembledPos = std::copy(frag1Begin, frag1End, reassembledPos);

  BOOST_CHECK(frags[2].has<lp::FragmentField>());
  BOOST_CHECK(!frags[2].has<lp::IncomingFaceIdField>());
  BOOST_CHECK_EQUAL(frags[2].get<lp::FragIndexField>(), 2);
  BOOST_CHECK_EQUAL(frags[2].get<lp::FragCountField>(), 5);
  BOOST_CHECK_LE(frags[2].wireEncode().size(), mtu);
  ndn::Buffer::const_iterator frag2Begin, frag2End;
  std::tie(frag2Begin, frag2End) = frags[2].get<lp::FragmentField>();
  BOOST_REQUIRE_LE(std::distance(frag2Begin, frag2End),
                   std::distance(reassembledPos, reassembledPayload.end()));
  reassembledPos = std::copy(frag2Begin, frag2End, reassembledPos);

  BOOST_CHECK(frags[3].has<lp::FragmentField>());
  BOOST_CHECK(!frags[3].has<lp::IncomingFaceIdField>());
  BOOST_CHECK_EQUAL(frags[3].get<lp::FragIndexField>(), 3);
  BOOST_CHECK_EQUAL(frags[3].get<lp::FragCountField>(), 5);
  BOOST_CHECK_LE(frags[3].wireEncode().size(), mtu);
  ndn::Buffer::const_iterator frag3Begin, frag3End;
  std::tie(frag3Begin, frag3End) = frags[3].get<lp::FragmentField>();
  BOOST_REQUIRE_LE(std::distance(frag3Begin, frag3End),
                   std::distance(reassembledPos, reassembledPayload.end()));
  reassembledPos = std::copy(frag3Begin, frag3End, reassembledPos);

  BOOST_CHECK(frags[4].has<lp::FragmentField>());
  BOOST_CHECK(!frags[4].has<lp::IncomingFaceIdField>());
  BOOST_CHECK_EQUAL(frags[4].get<lp::FragIndexField>(), 4);
  BOOST_CHECK_EQUAL(frags[4].get<lp::FragCountField>(), 5);
  BOOST_CHECK_LE(frags[4].wireEncode().size(), mtu);
  ndn::Buffer::const_iterator frag4Begin, frag4End;
  std::tie(frag4Begin, frag4End) = frags[4].get<lp::FragmentField>();
  BOOST_REQUIRE_LE(std::distance(frag4Begin, frag4End),
                   std::distance(reassembledPos, reassembledPayload.end()));
  std::copy(frag4Begin, frag4End, reassembledPos);

  BOOST_CHECK_EQUAL_COLLECTIONS(data->wireEncode().begin(), data->wireEncode().end(),
                                reassembledPayload.begin(), reassembledPayload.end());
}

BOOST_AUTO_TEST_CASE(FragmentMtuTooSmall)
{
  size_t mtu = 20;
  BOOST_ASSERT(mtu < Transport::MIN_MTU);

  lp::Packet packet;
  packet.add<lp::IncomingFaceIdField>(123);

  shared_ptr<Data> data = makeData("/test/data1/123456789/987654321/123456789");
  packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(),
                                               data->wireEncode().end()));

  bool isOk = false;
  std::tie(isOk, std::ignore) = fragmenter.fragmentPacket(packet, mtu);
  BOOST_REQUIRE(!isOk);
}

BOOST_AUTO_TEST_CASE(FragmentOverFragCount)
{
  LpFragmenter::Options options;
  options.nMaxFragments = 2;
  fragmenter.setOptions(options);

  size_t mtu = 70;

  lp::Packet packet;
  packet.add<lp::IncomingFaceIdField>(123);

  shared_ptr<Data> data = makeData("/test/data1/123456789/987654321/123456789");
  packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(),
                                               data->wireEncode().end()));

  bool isOk = false;
  std::tie(isOk, std::ignore) = fragmenter.fragmentPacket(packet, mtu);
  BOOST_REQUIRE(!isOk);
}

BOOST_AUTO_TEST_SUITE_END() // TestLpFragmentation
BOOST_AUTO_TEST_SUITE_END() // Face

} // namespace tests
} // namespace face
} // namespace nfd
