/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2016,  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/retx-suppression.hpp"
#include "fw/retx-suppression-fixed.hpp"
#include "fw/retx-suppression-exponential.hpp"

#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"

namespace nfd {
namespace fw {
namespace tests {

using namespace nfd::tests;

BOOST_AUTO_TEST_SUITE(Fw)
BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, UnitTestTimeFixture)

BOOST_AUTO_TEST_CASE(Fixed)
{
  Forwarder forwarder;
  Pit& pit = forwarder.getPit();
  static const time::milliseconds MIN_RETX_INTERVAL(200);
  RetxSuppressionFixed rs(MIN_RETX_INTERVAL);

  shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
  shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
  shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
  forwarder.addFace(face1);
  forwarder.addFace(face2);
  forwarder.addFace(face3);

  shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
  shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;

  const time::nanoseconds RETRANSMISSION_10P =
      time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);

  // @ time 0
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW);
  pitEntry->insertOrUpdateOutRecord(*face3, *interest);

  this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  pitEntry->insertOrUpdateInRecord(*face2, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS);

  this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
  pitEntry->insertOrUpdateInRecord(*face2, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::FORWARD);
  // but strategy decides not to forward

  this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
  // retransmission suppress shall still give clearance for forwarding
  pitEntry->insertOrUpdateOutRecord(*face3, *interest); // and strategy forwards

  this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  pitEntry->insertOrUpdateInRecord(*face2, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS);
}

BOOST_AUTO_TEST_CASE(Exponential)
{
  Forwarder forwarder;
  Pit& pit = forwarder.getPit();
  RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100));

  shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
  shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
  forwarder.addFace(face1);
  forwarder.addFace(face2);

  shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
  shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;

  // @ 0ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW);
  pitEntry->insertOrUpdateOutRecord(*face2, *interest);
  // suppression interval is 10ms, until 10ms

  this->advanceClocks(time::milliseconds(5)); // @ 5ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  // suppression interval is 10ms, until 10ms

  this->advanceClocks(time::milliseconds(6)); // @ 11ms
  // note: what happens at *exactly* 10ms does not matter so it's untested,
  // because in reality network timing won't be exact:
  // incoming Interest is processed either before or after 10ms point
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
  pitEntry->insertOrUpdateOutRecord(*face2, *interest);
  // suppression interval is 30ms, until 41ms

  this->advanceClocks(time::milliseconds(25)); // @ 36ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  // suppression interval is 30ms, until 41ms

  this->advanceClocks(time::milliseconds(6)); // @ 42ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
  // strategy decides not to forward, but suppression interval is increased nevertheless
  // suppression interval is 90ms, until 101ms

  this->advanceClocks(time::milliseconds(58)); // @ 100ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  // suppression interval is 90ms, until 101ms

  this->advanceClocks(time::milliseconds(3)); // @ 103ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
  pitEntry->insertOrUpdateOutRecord(*face2, *interest);
  // suppression interval is 100ms, until 203ms

  this->advanceClocks(time::milliseconds(99)); // @ 202ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS);
  // suppression interval is 100ms, until 203ms

  this->advanceClocks(time::milliseconds(2)); // @ 204ms
  pitEntry->insertOrUpdateInRecord(*face1, *interest);
  BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD);
  pitEntry->insertOrUpdateOutRecord(*face2, *interest);
  // suppression interval is 100ms, until 304ms
}

BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression
BOOST_AUTO_TEST_SUITE_END() // Fw

} // namespace tests
} // namespace fw
} // namespace nfd
