blob: 113faf567a834990c3d910163885bcc7f88f961c [file] [log] [blame]
Davide Pesaventob31206e2019-04-20 22:34:12 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesaventob31206e2019-04-20 22:34:12 -04004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Davide Pesavento7922d122021-03-05 22:41:23 -050026/** \file
27 * This test suite checks that a strategy can correctly handle a multi-access face
28 * on a broadcast medium.
29 */
30
Davide Pesaventob31206e2019-04-20 22:34:12 -040031// Strategies that can correctly handle multi-access faces on a broadcast medium,
32// sorted alphabetically.
33#include "fw/asf-strategy.hpp"
Davide Pesavento7922d122021-03-05 22:41:23 -050034#include "fw/best-route-strategy.hpp"
Davide Pesaventob31206e2019-04-20 22:34:12 -040035#include "fw/multicast-strategy.hpp"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070036#include "fw/random-strategy.hpp"
Davide Pesaventob31206e2019-04-20 22:34:12 -040037
38#include "tests/daemon/global-io-fixture.hpp"
39#include "topology-tester.hpp"
40
41#include <boost/mpl/vector.hpp>
42
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040043namespace nfd::tests {
44
45using namespace nfd::fw;
Davide Pesaventob31206e2019-04-20 22:34:12 -040046
47template<typename S>
48class BroadcastMediumFixture : public GlobalIoTimeFixture
49{
50protected:
51 BroadcastMediumFixture()
52 {
53 nodeC = topo.addForwarder("C");
54 nodeD = topo.addForwarder("D");
55 nodeP = topo.addForwarder("P");
56
57 for (TopologyNode node : {nodeC, nodeD, nodeP}) {
58 topo.setStrategy<S>(node);
59 }
60
61 auto w = topo.addLink("W", 10_ms, {nodeC, nodeD, nodeP}, ndn::nfd::LINK_TYPE_MULTI_ACCESS);
62 faceC = &w->getFace(nodeC);
63 faceD = &w->getFace(nodeD);
64 faceP = &w->getFace(nodeP);
65
66 appC = topo.addAppFace("consumer1", nodeC);
67 topo.registerPrefix(nodeC, *faceC, "/P");
68 topo.addIntervalConsumer(appC->getClientFace(), "/P", 0_ms, 1, 1);
69 appD = topo.addAppFace("consumer2", nodeD);
70 topo.registerPrefix(nodeD, *faceD, "/P");
71 topo.addIntervalConsumer(appD->getClientFace(), "/P", 0_ms, 1, 1);
72 appP = topo.addAppFace("producer", nodeP, "/P");
73 topo.addEchoProducer(appP->getClientFace(), "/P", 100_ms);
74 }
75
76protected:
77 TopologyTester topo;
78 TopologyNode nodeC;
79 TopologyNode nodeD;
80 TopologyNode nodeP;
81 Face* faceC;
82 Face* faceD;
83 Face* faceP;
84 shared_ptr<TopologyAppLink> appC;
85 shared_ptr<TopologyAppLink> appD;
86 shared_ptr<TopologyAppLink> appP;
87};
88
89BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesavento7922d122021-03-05 22:41:23 -050090BOOST_AUTO_TEST_SUITE(TestStrategyBroadcastMedium)
Davide Pesaventob31206e2019-04-20 22:34:12 -040091
92using Strategies = boost::mpl::vector<
93 AsfStrategy,
Davide Pesavento7922d122021-03-05 22:41:23 -050094 BestRouteStrategy,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070095 MulticastStrategy,
96 RandomStrategy
Davide Pesaventob31206e2019-04-20 22:34:12 -040097>;
98
Davide Pesavento7922d122021-03-05 22:41:23 -050099BOOST_FIXTURE_TEST_CASE_TEMPLATE(SameFaceDifferentEndpoint,
100 S, Strategies, BroadcastMediumFixture<S>)
Davide Pesaventob31206e2019-04-20 22:34:12 -0400101{
102 // C D P
103 // | | |
104 // --+---+---+--
105 //
106 // C and D are consumers. P is the producer. They communicate with each other
107 // through a multi-access face over a (wired or wireless) broadcast medium.
108
109 this->advanceClocks(10_ms, 50_ms);
110
111 BOOST_CHECK_EQUAL(this->faceC->getCounters().nOutInterests, 1);
112 BOOST_CHECK_EQUAL(this->faceD->getCounters().nOutInterests, 1);
113 BOOST_CHECK_EQUAL(this->faceP->getCounters().nInInterests, 2);
114 BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 0);
115 BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 0);
116 BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 0);
117
118 this->advanceClocks(10_ms, 200_ms);
119
120 BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 1);
121 BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 1);
122 BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 1);
123}
124
Davide Pesavento7922d122021-03-05 22:41:23 -0500125BOOST_AUTO_TEST_SUITE_END() // TestStrategyBroadcastMedium
Davide Pesaventob31206e2019-04-20 22:34:12 -0400126BOOST_AUTO_TEST_SUITE_END() // Fw
127
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400128} // namespace nfd::tests