Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 4 | * 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 Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 26 | /** \file |
| 27 | * This test suite checks that a strategy can correctly handle a multi-access face |
| 28 | * on a broadcast medium. |
| 29 | */ |
| 30 | |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 31 | // Strategies that can correctly handle multi-access faces on a broadcast medium, |
| 32 | // sorted alphabetically. |
| 33 | #include "fw/asf-strategy.hpp" |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 34 | #include "fw/best-route-strategy.hpp" |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 35 | #include "fw/multicast-strategy.hpp" |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 36 | #include "fw/random-strategy.hpp" |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 37 | |
| 38 | #include "tests/daemon/global-io-fixture.hpp" |
| 39 | #include "topology-tester.hpp" |
| 40 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 41 | #include <boost/mp11/list.hpp> |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 42 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 43 | namespace nfd::tests { |
| 44 | |
| 45 | using namespace nfd::fw; |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 46 | |
| 47 | template<typename S> |
| 48 | class BroadcastMediumFixture : public GlobalIoTimeFixture |
| 49 | { |
| 50 | protected: |
| 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 | |
| 76 | protected: |
| 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 | |
| 89 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 90 | BOOST_AUTO_TEST_SUITE(TestStrategyBroadcastMedium) |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 91 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 92 | using Strategies = boost::mp11::mp_list< |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 93 | AsfStrategy, |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 94 | BestRouteStrategy, |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 95 | MulticastStrategy, |
| 96 | RandomStrategy |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 97 | >; |
| 98 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 99 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SameFaceDifferentEndpoint, |
| 100 | S, Strategies, BroadcastMediumFixture<S>) |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 101 | { |
| 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 Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 125 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyBroadcastMedium |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 126 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 127 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 128 | } // namespace nfd::tests |