blob: bdf0cb6e20b7f040c87943fced10eda2496652ba [file] [log] [blame]
Teng Liangf995f382017-04-04 22:09:39 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04002/*
Davide Pesavento7922d122021-03-05 22:41:23 -05003 * Copyright (c) 2014-2021, Regents of the University of California,
Teng Liangf995f382017-04-04 22:09:39 +00004 * 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 Pesavento7922d122021-03-05 22:41:23 -050033#include "fw/best-route-strategy.hpp"
Teng Liangf995f382017-04-04 22:09:39 +000034#include "fw/multicast-strategy.hpp"
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070035#include "fw/random-strategy.hpp"
Teng Liangf995f382017-04-04 22:09:39 +000036
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040037#include "tests/daemon/global-io-fixture.hpp"
Teng Liangf995f382017-04-04 22:09:39 +000038#include "topology-tester.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040039
Teng Liangf995f382017-04-04 22:09:39 +000040#include <boost/mpl/vector.hpp>
41
42namespace nfd {
43namespace fw {
44namespace tests {
45
Teng Liangf995f382017-04-04 22:09:39 +000046template<typename S>
Davide Pesavento7922d122021-03-05 22:41:23 -050047class AdHocTopologyFixture : public GlobalIoTimeFixture
Teng Liangf995f382017-04-04 22:09:39 +000048{
49protected:
Davide Pesavento7922d122021-03-05 22:41:23 -050050 AdHocTopologyFixture()
Teng Liangf995f382017-04-04 22:09:39 +000051 {
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 Pesavento14e71f02019-03-28 17:35:25 -040060 auto wireless = topo.addLink("ABC", 10_ms, {nodeA, nodeB, nodeC},
Teng Liangf995f382017-04-04 22:09:39 +000061 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
74protected:
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
86BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesavento7922d122021-03-05 22:41:23 -050087BOOST_AUTO_TEST_SUITE(TestStrategyAdHocFace)
Teng Liangf995f382017-04-04 22:09:39 +000088
89using Strategies = boost::mpl::vector<
90 AsfStrategy,
Davide Pesavento7922d122021-03-05 22:41:23 -050091 BestRouteStrategy,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070092 MulticastStrategy,
93 RandomStrategy
Teng Liangf995f382017-04-04 22:09:39 +000094>;
95
Davide Pesavento7922d122021-03-05 22:41:23 -050096BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop,
97 S, Strategies, AdHocTopologyFixture<S>)
Teng Liangf995f382017-04-04 22:09:39 +000098{
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 Pesavento14e71f02019-03-28 17:35:25 -0400106 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 10);
107 this->advanceClocks(5_ms, 1200_ms);
Teng Liangf995f382017-04-04 22:09:39 +0000108
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 Pesavento7922d122021-03-05 22:41:23 -0500118BOOST_FIXTURE_TEST_CASE_TEMPLATE(SecondNexthop,
119 S, Strategies, AdHocTopologyFixture<S>)
Teng Liangf995f382017-04-04 22:09:39 +0000120{
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 Pesavento14e71f02019-03-28 17:35:25 -0400130 shared_ptr<TopologyLink> linkBD = this->topo.addLink("BD", 5_ms, {this->nodeB, nodeD});
Teng Liangf995f382017-04-04 22:09:39 +0000131 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 Pesavento14e71f02019-03-28 17:35:25 -0400137 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 Liangf995f382017-04-04 22:09:39 +0000141
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 Pesavento7922d122021-03-05 22:41:23 -0500151BOOST_AUTO_TEST_SUITE_END() // TestStrategyAdHocFace
Teng Liangf995f382017-04-04 22:09:39 +0000152BOOST_AUTO_TEST_SUITE_END() // Fw
153
154} // namespace tests
155} // namespace fw
156} // namespace nfd