/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2022,  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 a strategy can correctly handle a multi-access face
 *  on a broadcast medium.
 */

// Strategies that can correctly handle multi-access faces on a broadcast medium,
// sorted alphabetically.
#include "fw/asf-strategy.hpp"
#include "fw/best-route-strategy.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::tests {

using namespace nfd::fw;

template<typename S>
class BroadcastMediumFixture : public GlobalIoTimeFixture
{
protected:
  BroadcastMediumFixture()
  {
    nodeC = topo.addForwarder("C");
    nodeD = topo.addForwarder("D");
    nodeP = topo.addForwarder("P");

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

    auto w = topo.addLink("W", 10_ms, {nodeC, nodeD, nodeP}, ndn::nfd::LINK_TYPE_MULTI_ACCESS);
    faceC = &w->getFace(nodeC);
    faceD = &w->getFace(nodeD);
    faceP = &w->getFace(nodeP);

    appC = topo.addAppFace("consumer1", nodeC);
    topo.registerPrefix(nodeC, *faceC, "/P");
    topo.addIntervalConsumer(appC->getClientFace(), "/P", 0_ms, 1, 1);
    appD = topo.addAppFace("consumer2", nodeD);
    topo.registerPrefix(nodeD, *faceD, "/P");
    topo.addIntervalConsumer(appD->getClientFace(), "/P", 0_ms, 1, 1);
    appP = topo.addAppFace("producer", nodeP, "/P");
    topo.addEchoProducer(appP->getClientFace(), "/P", 100_ms);
  }

protected:
  TopologyTester topo;
  TopologyNode nodeC;
  TopologyNode nodeD;
  TopologyNode nodeP;
  Face* faceC;
  Face* faceD;
  Face* faceP;
  shared_ptr<TopologyAppLink> appC;
  shared_ptr<TopologyAppLink> appD;
  shared_ptr<TopologyAppLink> appP;
};

BOOST_AUTO_TEST_SUITE(Fw)
BOOST_AUTO_TEST_SUITE(TestStrategyBroadcastMedium)

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

BOOST_FIXTURE_TEST_CASE_TEMPLATE(SameFaceDifferentEndpoint,
                                 S, Strategies, BroadcastMediumFixture<S>)
{
  //   C   D   P
  //   |   |   |
  // --+---+---+--
  //
  // C and D are consumers. P is the producer. They communicate with each other
  // through a multi-access face over a (wired or wireless) broadcast medium.

  this->advanceClocks(10_ms, 50_ms);

  BOOST_CHECK_EQUAL(this->faceC->getCounters().nOutInterests, 1);
  BOOST_CHECK_EQUAL(this->faceD->getCounters().nOutInterests, 1);
  BOOST_CHECK_EQUAL(this->faceP->getCounters().nInInterests, 2);
  BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 0);
  BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 0);
  BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 0);

  this->advanceClocks(10_ms, 200_ms);

  BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 1);
  BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 1);
  BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 1);
}

BOOST_AUTO_TEST_SUITE_END() // TestStrategyBroadcastMedium
BOOST_AUTO_TEST_SUITE_END() // Fw

} // namespace nfd::tests
