/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  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/mp11/list.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::mp11::mp_list<
  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
