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" |
| 31 | |
| 32 | #include "tests/daemon/global-io-fixture.hpp" |
| 33 | #include "topology-tester.hpp" |
| 34 | |
| 35 | #include <boost/mpl/vector.hpp> |
| 36 | |
| 37 | namespace nfd { |
| 38 | namespace fw { |
| 39 | namespace tests { |
| 40 | |
| 41 | template<typename S> |
| 42 | class BroadcastMediumFixture : public GlobalIoTimeFixture |
| 43 | { |
| 44 | protected: |
| 45 | BroadcastMediumFixture() |
| 46 | { |
| 47 | nodeC = topo.addForwarder("C"); |
| 48 | nodeD = topo.addForwarder("D"); |
| 49 | nodeP = topo.addForwarder("P"); |
| 50 | |
| 51 | for (TopologyNode node : {nodeC, nodeD, nodeP}) { |
| 52 | topo.setStrategy<S>(node); |
| 53 | } |
| 54 | |
| 55 | auto w = topo.addLink("W", 10_ms, {nodeC, nodeD, nodeP}, ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 56 | faceC = &w->getFace(nodeC); |
| 57 | faceD = &w->getFace(nodeD); |
| 58 | faceP = &w->getFace(nodeP); |
| 59 | |
| 60 | appC = topo.addAppFace("consumer1", nodeC); |
| 61 | topo.registerPrefix(nodeC, *faceC, "/P"); |
| 62 | topo.addIntervalConsumer(appC->getClientFace(), "/P", 0_ms, 1, 1); |
| 63 | appD = topo.addAppFace("consumer2", nodeD); |
| 64 | topo.registerPrefix(nodeD, *faceD, "/P"); |
| 65 | topo.addIntervalConsumer(appD->getClientFace(), "/P", 0_ms, 1, 1); |
| 66 | appP = topo.addAppFace("producer", nodeP, "/P"); |
| 67 | topo.addEchoProducer(appP->getClientFace(), "/P", 100_ms); |
| 68 | } |
| 69 | |
| 70 | protected: |
| 71 | TopologyTester topo; |
| 72 | TopologyNode nodeC; |
| 73 | TopologyNode nodeD; |
| 74 | TopologyNode nodeP; |
| 75 | Face* faceC; |
| 76 | Face* faceD; |
| 77 | Face* faceP; |
| 78 | shared_ptr<TopologyAppLink> appC; |
| 79 | shared_ptr<TopologyAppLink> appD; |
| 80 | shared_ptr<TopologyAppLink> appP; |
| 81 | }; |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE(Fw) |
| 84 | BOOST_AUTO_TEST_SUITE(TestBroadcastMedium) |
| 85 | |
| 86 | using Strategies = boost::mpl::vector< |
| 87 | AsfStrategy, |
| 88 | BestRouteStrategy2, |
| 89 | MulticastStrategy |
| 90 | >; |
| 91 | |
| 92 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SameFaceDifferentEndpoint, S, Strategies, BroadcastMediumFixture<S>) |
| 93 | { |
| 94 | // C D P |
| 95 | // | | | |
| 96 | // --+---+---+-- |
| 97 | // |
| 98 | // C and D are consumers. P is the producer. They communicate with each other |
| 99 | // through a multi-access face over a (wired or wireless) broadcast medium. |
| 100 | |
| 101 | this->advanceClocks(10_ms, 50_ms); |
| 102 | |
| 103 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nOutInterests, 1); |
| 104 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nOutInterests, 1); |
| 105 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nInInterests, 2); |
| 106 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 0); |
| 107 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 0); |
| 108 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 0); |
| 109 | |
| 110 | this->advanceClocks(10_ms, 200_ms); |
| 111 | |
| 112 | BOOST_CHECK_EQUAL(this->faceC->getCounters().nInData, 1); |
| 113 | BOOST_CHECK_EQUAL(this->faceD->getCounters().nInData, 1); |
| 114 | BOOST_CHECK_EQUAL(this->faceP->getCounters().nOutData, 1); |
| 115 | } |
| 116 | |
| 117 | BOOST_AUTO_TEST_SUITE_END() // TestBroadcastMedium |
| 118 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 119 | |
| 120 | } // namespace tests |
| 121 | } // namespace fw |
| 122 | } // namespace nfd |