blob: cd4605454c70aa2a989f6efbc5fa5b4f9f5eb7ac [file] [log] [blame]
/* -*- 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 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-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 AdHocTopologyFixture : public GlobalIoTimeFixture
{
protected:
AdHocTopologyFixture()
{
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(TestStrategyAdHocFace)
using Strategies = boost::mpl::vector<
AsfStrategy,
BestRouteStrategy,
MulticastStrategy,
RandomStrategy
>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop,
S, Strategies, AdHocTopologyFixture<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, AdHocTopologyFixture<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() // TestStrategyAdHocFace
BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace nfd::tests