Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [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 | |
| 26 | /** \file |
| 27 | * This test suite checks that forwarding can relay Interest and Data via ad hoc face. |
| 28 | */ |
| 29 | |
| 30 | // Strategies that can forward Interest to an ad hoc face even if it's the downstream, |
| 31 | // sorted alphabetically. |
| 32 | #include "fw/asf-strategy.hpp" |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 33 | #include "fw/best-route-strategy.hpp" |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 34 | #include "fw/multicast-strategy.hpp" |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 35 | #include "fw/random-strategy.hpp" |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 36 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 37 | #include "tests/daemon/global-io-fixture.hpp" |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 38 | #include "topology-tester.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 39 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 40 | #include <boost/mpl/vector.hpp> |
| 41 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 42 | namespace nfd::tests { |
| 43 | |
| 44 | using namespace nfd::fw; |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 45 | |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 46 | template<typename S> |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 47 | class AdHocTopologyFixture : public GlobalIoTimeFixture |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 48 | { |
| 49 | protected: |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 50 | AdHocTopologyFixture() |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 51 | { |
| 52 | nodeA = topo.addForwarder("A"); |
| 53 | nodeB = topo.addForwarder("B"); |
| 54 | nodeC = topo.addForwarder("C"); |
| 55 | |
| 56 | for (TopologyNode node : {nodeA, nodeB, nodeC}) { |
| 57 | topo.setStrategy<S>(node); |
| 58 | } |
| 59 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 60 | auto wireless = topo.addLink("ABC", 10_ms, {nodeA, nodeB, nodeC}, |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 61 | ndn::nfd::LINK_TYPE_AD_HOC); |
| 62 | wireless->block(nodeA, nodeC); |
| 63 | wireless->block(nodeC, nodeA); |
| 64 | faceA = &wireless->getFace(nodeA); |
| 65 | faceB = &wireless->getFace(nodeB); |
| 66 | faceC = &wireless->getFace(nodeC); |
| 67 | |
| 68 | appA = topo.addAppFace("consumer", nodeA); |
| 69 | topo.registerPrefix(nodeA, *faceA, "/P"); |
| 70 | appC = topo.addAppFace("producer", nodeC, "/P"); |
| 71 | topo.addEchoProducer(appC->getClientFace(), "/P"); |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | TopologyTester topo; |
| 76 | TopologyNode nodeA; |
| 77 | TopologyNode nodeB; |
| 78 | TopologyNode nodeC; |
| 79 | Face* faceA; |
| 80 | Face* faceB; |
| 81 | Face* faceC; |
| 82 | shared_ptr<TopologyAppLink> appA; |
| 83 | shared_ptr<TopologyAppLink> appC; |
| 84 | }; |
| 85 | |
| 86 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 87 | BOOST_AUTO_TEST_SUITE(TestStrategyAdHocFace) |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 88 | |
| 89 | using Strategies = boost::mpl::vector< |
| 90 | AsfStrategy, |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 91 | BestRouteStrategy, |
Klaus Schneider | cf1d0c0 | 2019-08-31 19:05:40 -0700 | [diff] [blame] | 92 | MulticastStrategy, |
| 93 | RandomStrategy |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 94 | >; |
| 95 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 96 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop, |
| 97 | S, Strategies, AdHocTopologyFixture<S>) |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 98 | { |
| 99 | // +---+---+ |
| 100 | // A B C |
| 101 | // |
| 102 | // A is the consumer. C is the producer. |
| 103 | // B should relay Interest/Data between A and C. |
| 104 | |
| 105 | this->topo.registerPrefix(this->nodeB, *this->faceB, "/P"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 106 | this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 10); |
| 107 | this->advanceClocks(5_ms, 1200_ms); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 108 | |
| 109 | // Consumer should receive Data, and B should be relaying. |
| 110 | BOOST_CHECK_EQUAL(this->faceB->getCounters().nInInterests, 10); |
| 111 | BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutInterests, 10); |
| 112 | BOOST_CHECK_EQUAL(this->appC->getForwarderFace().getCounters().nOutInterests, 10); |
| 113 | BOOST_CHECK_EQUAL(this->faceB->getCounters().nInData, 10); |
| 114 | BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutData, 10); |
| 115 | BOOST_CHECK_EQUAL(this->appA->getForwarderFace().getCounters().nOutData, 10); |
| 116 | } |
| 117 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 118 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(SecondNexthop, |
| 119 | S, Strategies, AdHocTopologyFixture<S>) |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 120 | { |
| 121 | // +---+---+ |
| 122 | // A B C |
| 123 | // | |
| 124 | // D |
| 125 | // |
| 126 | // A is the consumer. C is the producer. |
| 127 | // B's first nexthop is D, but B-D link has failed, so B should relay Interest/Data between A and C. |
| 128 | |
| 129 | TopologyNode nodeD = this->topo.addForwarder("D"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 130 | shared_ptr<TopologyLink> linkBD = this->topo.addLink("BD", 5_ms, {this->nodeB, nodeD}); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 131 | this->topo.registerPrefix(this->nodeB, linkBD->getFace(this->nodeB), "/P", 5); |
| 132 | linkBD->fail(); |
| 133 | this->topo.registerPrefix(this->nodeB, *this->faceB, "/P", 10); |
| 134 | |
| 135 | // Two interval consumers are expressing Interests with same name 40ms apart, |
| 136 | // so that Interests from the second interval consumer are considered retransmission. |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 137 | this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1); |
| 138 | this->advanceClocks(5_ms, 40_ms); |
| 139 | this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1); |
| 140 | this->advanceClocks(5_ms, 5400_ms); |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 141 | |
| 142 | // Consumer should receive Data, and B should be relaying at least some Interest/Data. |
| 143 | BOOST_CHECK_GE(this->faceB->getCounters().nInInterests, 50); |
| 144 | BOOST_CHECK_GE(this->faceB->getCounters().nOutInterests, 25); |
| 145 | BOOST_CHECK_GE(this->appC->getForwarderFace().getCounters().nOutInterests, 25); |
| 146 | BOOST_CHECK_GE(this->faceB->getCounters().nInData, 25); |
| 147 | BOOST_CHECK_GE(this->faceB->getCounters().nOutData, 25); |
| 148 | BOOST_CHECK_GE(this->appA->getForwarderFace().getCounters().nOutData, 25); |
| 149 | } |
| 150 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 151 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyAdHocFace |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 152 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 153 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 154 | } // namespace nfd::tests |