blob: 7e81893a386e6e6c975a9f257486a8652ea56d54 [file] [log] [blame]
Teng Liangf995f382017-04-04 22:09:39 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, 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/** \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
36#include "tests/test-common.hpp"
37#include "topology-tester.hpp"
38#include <boost/mpl/vector.hpp>
39
40namespace nfd {
41namespace fw {
42namespace tests {
43
44using namespace nfd::tests;
45
46template<typename S>
47class AdHocForwardingFixture : public UnitTestTimeFixture
48{
49protected:
50 AdHocForwardingFixture()
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
60 auto wireless = topo.addLink("ABC", time::milliseconds(10), {nodeA, nodeB, nodeC},
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
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)
87BOOST_FIXTURE_TEST_SUITE(TestAdHocForwarding, BaseFixture)
88
89using Strategies = boost::mpl::vector<
90 AsfStrategy,
91 BestRouteStrategy2,
92 MulticastStrategy
93>;
94
95BOOST_FIXTURE_TEST_CASE_TEMPLATE(SingleNexthop, S, Strategies,
96 AdHocForwardingFixture<S>)
97{
98 // +---+---+
99 // A B C
100 //
101 // A is the consumer. C is the producer.
102 // B should relay Interest/Data between A and C.
103
104 this->topo.registerPrefix(this->nodeB, *this->faceB, "/P");
105 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", time::milliseconds(100), 10);
106 this->advanceClocks(time::milliseconds(5), time::milliseconds(1200));
107
108 // Consumer should receive Data, and B should be relaying.
109 BOOST_CHECK_EQUAL(this->faceB->getCounters().nInInterests, 10);
110 BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutInterests, 10);
111 BOOST_CHECK_EQUAL(this->appC->getForwarderFace().getCounters().nOutInterests, 10);
112 BOOST_CHECK_EQUAL(this->faceB->getCounters().nInData, 10);
113 BOOST_CHECK_EQUAL(this->faceB->getCounters().nOutData, 10);
114 BOOST_CHECK_EQUAL(this->appA->getForwarderFace().getCounters().nOutData, 10);
115}
116
117BOOST_FIXTURE_TEST_CASE_TEMPLATE(SecondNexthop, S, Strategies,
118 AdHocForwardingFixture<S>)
119{
120 // +---+---+
121 // A B C
122 // |
123 // D
124 //
125 // A is the consumer. C is the producer.
126 // B's first nexthop is D, but B-D link has failed, so B should relay Interest/Data between A and C.
127
128 TopologyNode nodeD = this->topo.addForwarder("D");
129 shared_ptr<TopologyLink> linkBD = this->topo.addLink("BD", time::milliseconds(5), {this->nodeB, nodeD});
130 this->topo.registerPrefix(this->nodeB, linkBD->getFace(this->nodeB), "/P", 5);
131 linkBD->fail();
132 this->topo.registerPrefix(this->nodeB, *this->faceB, "/P", 10);
133
134 // Two interval consumers are expressing Interests with same name 40ms apart,
135 // so that Interests from the second interval consumer are considered retransmission.
136 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", time::milliseconds(100), 50, 1);
137 this->advanceClocks(time::milliseconds(5), time::milliseconds(40));
138 this->topo.addIntervalConsumer(this->appA->getClientFace(), "/P", time::milliseconds(100), 50, 1);
139 this->advanceClocks(time::milliseconds(5), time::milliseconds(5400));
140
141 // Consumer should receive Data, and B should be relaying at least some Interest/Data.
142 BOOST_CHECK_GE(this->faceB->getCounters().nInInterests, 50);
143 BOOST_CHECK_GE(this->faceB->getCounters().nOutInterests, 25);
144 BOOST_CHECK_GE(this->appC->getForwarderFace().getCounters().nOutInterests, 25);
145 BOOST_CHECK_GE(this->faceB->getCounters().nInData, 25);
146 BOOST_CHECK_GE(this->faceB->getCounters().nOutData, 25);
147 BOOST_CHECK_GE(this->appA->getForwarderFace().getCounters().nOutData, 25);
148}
149
150BOOST_AUTO_TEST_SUITE_END() // TestAdHocForwarding
151BOOST_AUTO_TEST_SUITE_END() // Fw
152
153} // namespace tests
154} // namespace fw
155} // namespace nfd