Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
| 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 | |
| 26 | // Strategies that can correctly handle multi-access faces on a broadcast medium, |
| 27 | // sorted alphabetically. |
| 28 | #include "fw/asf-strategy.hpp" |
| 29 | #include "fw/best-route-strategy2.hpp" |
| 30 | #include "fw/multicast-strategy.hpp" |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 31 | #include "fw/random-strategy.hpp" |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 32 | |
| 33 | #include "tests/daemon/global-io-fixture.hpp" |
| 34 | #include "topology-tester.hpp" |
| 35 | |
| 36 | #include <boost/mpl/vector.hpp> |
| 37 | |
| 38 | namespace nfd { |
| 39 | namespace fw { |
| 40 | namespace tests { |
| 41 | |
| 42 | template<typename S> |
| 43 | class BroadcastMediumFixture : public GlobalIoTimeFixture |
| 44 | { |
| 45 | protected: |
| 46 | BroadcastMediumFixture() |
| 47 | { |
| 48 | nodeC = topo.addForwarder("C"); |
| 49 | nodeD = topo.addForwarder("D"); |
| 50 | nodeP = topo.addForwarder("P"); |
| 51 | |
| 52 | for (TopologyNode node : {nodeC, nodeD, nodeP}) { |
| 53 | topo.setStrategy<S>(node); |
| 54 | } |
| 55 | |
| 56 | auto w = topo.addLink("W", 10_ms, {nodeC, nodeD, nodeP}, ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 57 | faceC = &w->getFace(nodeC); |
| 58 | faceD = &w->getFace(nodeD); |
| 59 | faceP = &w->getFace(nodeP); |
| 60 | |
| 61 | appC = topo.addAppFace("consumer1", nodeC); |
| 62 | topo.registerPrefix(nodeC, *faceC, "/P"); |
| 63 | topo.addIntervalConsumer(appC->getClientFace(), "/P", 0_ms, 1, 1); |
| 64 | appD = topo.addAppFace("consumer2", nodeD); |
| 65 | topo.registerPrefix(nodeD, *faceD, "/P"); |
| 66 | topo.addIntervalConsumer(appD->getClientFace(), "/P", 0_ms, 1, 1); |
| 67 | appP = topo.addAppFace("producer", nodeP, "/P"); |
| 68 | topo.addEchoProducer(appP->getClientFace(), "/P", 100_ms); |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | TopologyTester topo; |
| 73 | TopologyNode nodeC; |
| 74 | TopologyNode nodeD; |
| 75 | TopologyNode nodeP; |
| 76 | Face* faceC; |
| 77 | Face* faceD; |
| 78 | Face* faceP; |
| 79 | shared_ptr<TopologyAppLink> appC; |
| 80 | shared_ptr<TopologyAppLink> appD; |
| 81 | shared_ptr<TopologyAppLink> appP; |
| 82 | }; |
| 83 | |
| 84 | BOOST_AUTO_TEST_SUITE(Fw) |
| 85 | BOOST_AUTO_TEST_SUITE(TestBroadcastMedium) |
| 86 | |
| 87 | using Strategies = boost::mpl::vector< |
| 88 | AsfStrategy, |
| 89 | BestRouteStrategy2, |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 90 | MulticastStrategy, |
| 91 | RandomStrategy |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 92 | >; |
| 93 | |
| 94 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SameFaceDifferentEndpoint, S, Strategies, BroadcastMediumFixture<S>) |
| 95 | { |
| 96 | // C D P |
| 97 | // | | | |
| 98 | // --+---+---+-- |
| 99 | // |
| 100 | // C and D are consumers. P is the producer. They communicate with each other |
| 101 | // through a multi-access face over a (wired or wireless) broadcast medium. |
| 102 | |
| 103 | this->advanceClocks(10_ms, 50_ms); |
| 104 | |
| 105 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nOutInterests, 1); |
| 106 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nOutInterests, 1); |
| 107 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nInInterests, 2); |
| 108 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 0); |
| 109 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 0); |
| 110 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 0); |
| 111 | |
| 112 | this->advanceClocks(10_ms, 200_ms); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 1); |
| 115 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 1); |
| 116 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 1); |
| 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_SUITE_END() // TestBroadcastMedium |
| 120 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 121 | |
| 122 | } // namespace tests |
| 123 | } // namespace fw |
| 124 | } // namespace nfd |