/* -*- 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/>.
 */

/** \file
 *  This test suite checks that forwarding can relay Interest and Data via ad hoc face.
 */

// Strategies that can forward Interest to an ad hoc face even if it's the downstream,
// sorted alphabetically.
#include "fw/asf-strategy.hpp"
#include "fw/best-route-strategy2.hpp"
#include "fw/multicast-strategy.hpp"
#include "fw/random-strategy.hpp"

#include "tests/daemon/global-io-fixture.hpp"
#include "topology-tester.hpp"

#include <boost/mpl/vector.hpp>

namespace nfd {
namespace fw {
namespace tests {

template<typename S>
class AdHocForwardingFixture : public GlobalIoTimeFixture
{
protected:
  AdHocForwardingFixture()
  {
    nodeA = topo.addForwarder("A");
    nodeB = topo.addForwarder("B");
    nodeC = topo.addForwarder("C");

    for (TopologyNode node : {nodeA, nodeB, nodeC}) {
      topo.setStrategy<S>(node);
    }

    auto wireless = topo.addLink("ABC", 10_ms, {nodeA, nodeB, nodeC},
                                 ndn::nfd::LINK_TYPE_AD_HOC);
    wireless->block(nodeA, nodeC);
    wireless->block(nodeC, nodeA);
    faceA = &wireless->getFace(nodeA);
    faceB = &wireless->getFace(nodeB);
    faceC = &wireless->getFace(nodeC);

    appA = topo.addAppFace("consumer", nodeA);
    topo.registerPrefix(nodeA, *faceA, "/P");
    appC = topo.addAppFace("producer", nodeC, "/P");
    topo.addEchoProducer(appC->getClientFace(), "/P");
  }

protected:
  TopologyTester topo;
  TopologyNode nodeA;
  TopologyNode nodeB;
  TopologyNode nodeC;
  Face* faceA;
  Face* faceB;
  Face* faceC;
  shared_ptr<TopologyAppLink> appA;
  shared_ptr<TopologyAppLink> appC;
};

BOOST_AUTO_TEST_SUITE(Fw)
BOOST_AUTO_TEST_SUITE(TestAdHocForwarding)

using Strategies = boost::mpl::vector<
  AsfStrategy,
  BestRouteStrategy2,
  MulticastStrategy,
  RandomStrategy
>;

BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop, S, Strategies,
                                 AdHocForwardingFixture<S>)
{
  // +---+---+
  // A   B   C
  //
  // A is the consumer. C is the producer.
  // B should relay Interest/Data between A and C.

  this->topo.registerPrefix(this->nodeB, *this->faceB, "/P");
  this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 10);
  this->advanceClocks(5_ms, 1200_ms);

  // Consumer should receive Data, and B should be relaying.
  BOOST_CHECK_EQUAL(this->faceB->getCounters().nInInterests, 10);
  BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutInterests, 10);
  BOOST_CHECK_EQUAL(this->appC->getForwarderFace().getCounters().nOutInterests, 10);
  BOOST_CHECK_EQUAL(this->faceB->getCounters().nInData, 10);
  BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutData, 10);
  BOOST_CHECK_EQUAL(this->appA->getForwarderFace().getCounters().nOutData, 10);
}

BOOST_FIXTURE_TEST_CASE_TEMPLATE(SecondNexthop, S, Strategies,
                                 AdHocForwardingFixture<S>)
{
  // +---+---+
  // A   B   C
  //     |
  //     D
  //
  // A is the consumer. C is the producer.
  // B's first nexthop is D, but B-D link has failed, so B should relay Interest/Data between A and C.

  TopologyNode nodeD = this->topo.addForwarder("D");
  shared_ptr<TopologyLink> linkBD = this->topo.addLink("BD", 5_ms, {this->nodeB, nodeD});
  this->topo.registerPrefix(this->nodeB, linkBD->getFace(this->nodeB), "/P", 5);
  linkBD->fail();
  this->topo.registerPrefix(this->nodeB, *this->faceB, "/P", 10);

  // Two interval consumers are expressing Interests with same name 40ms apart,
  // so that Interests from the second interval consumer are considered retransmission.
  this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1);
  this->advanceClocks(5_ms, 40_ms);
  this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1);
  this->advanceClocks(5_ms, 5400_ms);

  // Consumer should receive Data, and B should be relaying at least some Interest/Data.
  BOOST_CHECK_GE(this->faceB->getCounters().nInInterests, 50);
  BOOST_CHECK_GE(this->faceB->getCounters().nOutInterests, 25);
  BOOST_CHECK_GE(this->appC->getForwarderFace().getCounters().nOutInterests, 25);
  BOOST_CHECK_GE(this->faceB->getCounters().nInData, 25);
  BOOST_CHECK_GE(this->faceB->getCounters().nOutData, 25);
  BOOST_CHECK_GE(this->appA->getForwarderFace().getCounters().nOutData, 25);
}

BOOST_AUTO_TEST_SUITE_END() // TestAdHocForwarding
BOOST_AUTO_TEST_SUITE_END() // Fw

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