blob: 7ec07c7ef7466e216437d2963516c5e8a6425fbf [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/*
3 * Copyright (c) 2014-2019, 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"
33#include "fw/best-route-strategy2.hpp"
34#include "fw/multicast-strategy.hpp"
35
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040036#include "tests/daemon/global-io-fixture.hpp"
Teng Liangf995f382017-04-04 22:09:39 +000037#include "topology-tester.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038
Teng Liangf995f382017-04-04 22:09:39 +000039#include <boost/mpl/vector.hpp>
40
41namespace nfd {
42namespace fw {
43namespace tests {
44
Teng Liangf995f382017-04-04 22:09:39 +000045template<typename S>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040046class AdHocForwardingFixture : public GlobalIoTimeFixture
Teng Liangf995f382017-04-04 22:09:39 +000047{
48protected:
49 AdHocForwardingFixture()
50 {
51 nodeA = topo.addForwarder("A");
52 nodeB = topo.addForwarder("B");
53 nodeC = topo.addForwarder("C");
54
55 for (TopologyNode node : {nodeA, nodeB, nodeC}) {
56 topo.setStrategy<S>(node);
57 }
58
Davide Pesavento14e71f02019-03-28 17:35:25 -040059 auto wireless = topo.addLink("ABC", 10_ms, {nodeA, nodeB, nodeC},
Teng Liangf995f382017-04-04 22:09:39 +000060 ndn::nfd::LINK_TYPE_AD_HOC);
61 wireless->block(nodeA, nodeC);
62 wireless->block(nodeC, nodeA);
63 faceA = &wireless->getFace(nodeA);
64 faceB = &wireless->getFace(nodeB);
65 faceC = &wireless->getFace(nodeC);
66
67 appA = topo.addAppFace("consumer", nodeA);
68 topo.registerPrefix(nodeA, *faceA, "/P");
69 appC = topo.addAppFace("producer", nodeC, "/P");
70 topo.addEchoProducer(appC->getClientFace(), "/P");
71 }
72
73protected:
74 TopologyTester topo;
75 TopologyNode nodeA;
76 TopologyNode nodeB;
77 TopologyNode nodeC;
78 Face* faceA;
79 Face* faceB;
80 Face* faceC;
81 shared_ptr<TopologyAppLink> appA;
82 shared_ptr<TopologyAppLink> appC;
83};
84
85BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040086BOOST_AUTO_TEST_SUITE(TestAdHocForwarding)
Teng Liangf995f382017-04-04 22:09:39 +000087
88using Strategies = boost::mpl::vector<
89 AsfStrategy,
90 BestRouteStrategy2,
91 MulticastStrategy
92>;
93
94BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop, S, Strategies,
95 AdHocForwardingFixture<S>)
96{
97 // +---+---+
98 // A B C
99 //
100 // A is the consumer. C is the producer.
101 // B should relay Interest/Data between A and C.
102
103 this->topo.registerPrefix(this->nodeB, *this->faceB, "/P");
Davide Pesavento14e71f02019-03-28 17:35:25 -0400104 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 10);
105 this->advanceClocks(5_ms, 1200_ms);
Teng Liangf995f382017-04-04 22:09:39 +0000106
107 // Consumer should receive Data, and B should be relaying.
108 BOOST_CHECK_EQUAL(this->faceB->getCounters().nInInterests, 10);
109 BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutInterests, 10);
110 BOOST_CHECK_EQUAL(this->appC->getForwarderFace().getCounters().nOutInterests, 10);
111 BOOST_CHECK_EQUAL(this->faceB->getCounters().nInData, 10);
112 BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutData, 10);
113 BOOST_CHECK_EQUAL(this->appA->getForwarderFace().getCounters().nOutData, 10);
114}
115
116BOOST_FIXTURE_TEST_CASE_TEMPLATE(SecondNexthop, S, Strategies,
117 AdHocForwardingFixture<S>)
118{
119 // +---+---+
120 // A B C
121 // |
122 // D
123 //
124 // A is the consumer. C is the producer.
125 // B's first nexthop is D, but B-D link has failed, so B should relay Interest/Data between A and C.
126
127 TopologyNode nodeD = this->topo.addForwarder("D");
Davide Pesavento14e71f02019-03-28 17:35:25 -0400128 shared_ptr<TopologyLink> linkBD = this->topo.addLink("BD", 5_ms, {this->nodeB, nodeD});
Teng Liangf995f382017-04-04 22:09:39 +0000129 this->topo.registerPrefix(this->nodeB, linkBD->getFace(this->nodeB), "/P", 5);
130 linkBD->fail();
131 this->topo.registerPrefix(this->nodeB, *this->faceB, "/P", 10);
132
133 // Two interval consumers are expressing Interests with same name 40ms apart,
134 // so that Interests from the second interval consumer are considered retransmission.
Davide Pesavento14e71f02019-03-28 17:35:25 -0400135 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1);
136 this->advanceClocks(5_ms, 40_ms);
137 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", 100_ms, 50, 1);
138 this->advanceClocks(5_ms, 5400_ms);
Teng Liangf995f382017-04-04 22:09:39 +0000139
140 // Consumer should receive Data, and B should be relaying at least some Interest/Data.
141 BOOST_CHECK_GE(this->faceB->getCounters().nInInterests, 50);
142 BOOST_CHECK_GE(this->faceB->getCounters().nOutInterests, 25);
143 BOOST_CHECK_GE(this->appC->getForwarderFace().getCounters().nOutInterests, 25);
144 BOOST_CHECK_GE(this->faceB->getCounters().nInData, 25);
145 BOOST_CHECK_GE(this->faceB->getCounters().nOutData, 25);
146 BOOST_CHECK_GE(this->appA->getForwarderFace().getCounters().nOutData, 25);
147}
148
149BOOST_AUTO_TEST_SUITE_END() // TestAdHocForwarding
150BOOST_AUTO_TEST_SUITE_END() // Fw
151
152} // namespace tests
153} // namespace fw
154} // namespace nfd