blob: d5f14ee35877b51404bfcab99bb593a15e9266e7 [file] [log] [blame]
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#include "helper/ndn-strategy-choice-helper.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070021
22#include "../tests-common.hpp"
23
24namespace ns3 {
25namespace ndn {
26
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070027class StrategyChoiceHelperFixture : public ScenarioHelperWithCleanupFixture
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070028{
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070029public:
30 StrategyChoiceHelperFixture()
31 {
32 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
33 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
34 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("500"));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070035
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070036 // Creating two 3 node topologies: //
37 // //
38 // +----+ +----+ //
39 // +- | B1 | +- | B2 | //
40 // / +----+ / +----+ //
41 // +----+ / +----+ / //
42 // | | --+ | | --+ //
43 // | A1 | | A2 | //
44 // | | --+ | | --+ //
45 // +----+ \ +----+ \ //
46 // \ +----+ \ +----+ //
47 // +- | C1 | +- | C2 | //
48 // +----+ +----+ //
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070049
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070050 createTopology({
51 {"A1", "B1"},
52 {"A1", "C1"},
53 {"A2", "B2"},
54 {"A2", "C2"}
55 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070056
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070057 addRoutes({
58 {"A1", "B1", "/prefix", 200},
59 {"A1", "C1", "/prefix", 100},
60 {"A2", "B2", "/prefix", 100},
61 {"A2", "C2", "/prefix", 200}
62 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070063
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070064 addApps({
65 {"A1", "ns3::ndn::ConsumerCbr",
66 {{"Prefix", "/prefix"}, {"Frequency", "1"}},
67 "0s", "100s"},
68 {"A2", "ns3::ndn::ConsumerCbr",
69 {{"Prefix", "/prefix"}, {"Frequency", "1"}},
70 "0s", "100s"},
71 });
72 }
73};
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070074
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070075BOOST_FIXTURE_TEST_SUITE(TestStrategyChoiceHelper, StrategyChoiceHelperFixture)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070076
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070077BOOST_AUTO_TEST_CASE(DefaultStrategies)
78{
79 Simulator::Stop(Seconds(5.0));
80 Simulator::Run();
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070081
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070082 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 0);
83 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 5);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070084
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070085 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 5);
86 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 0);
87}
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070088
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070089// static void
90// Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
91BOOST_AUTO_TEST_CASE(InstallBuiltInStrategyOnNode)
92{
93 StrategyChoiceHelper::Install(getNode("A2"), "/prefix", "/localhost/nfd/strategy/broadcast");
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070094
95 Simulator::Stop(Seconds(5.0));
96 Simulator::Run();
97
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070098 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 0);
99 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 5);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700100
Alexander Afanasyevc512dba2015-08-13 16:51:26 -0700101 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 5);
102 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 5);
103}
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700104
Alexander Afanasyevc512dba2015-08-13 16:51:26 -0700105// static void
106// Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
107BOOST_AUTO_TEST_CASE(InstallBuiltInStrategyOnNodeContainer)
108{
109 NodeContainer nodes;
110 nodes.Add(getNode("A1"));
111 nodes.Add(getNode("A2"));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700112
Alexander Afanasyevc512dba2015-08-13 16:51:26 -0700113 StrategyChoiceHelper::Install(nodes, "/prefix", "/localhost/nfd/strategy/broadcast");
114
115 Simulator::Stop(Seconds(5.0));
116 Simulator::Run();
117
118 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 5);
119 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 5);
120
121 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 5);
122 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 5);
123}
124
125// static void
126// InstallAll(const Name& namePrefix, const Name& strategy);
127BOOST_AUTO_TEST_CASE(InstallAllBuiltInStrategy)
128{
129 StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast");
130
131 Simulator::Stop(Seconds(5.0));
132 Simulator::Run();
133
134 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 5);
135 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 5);
136
137 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 5);
138 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 5);
139}
140
141
142class NullStrategy : public nfd::fw::Strategy {
143public:
144 NullStrategy(nfd::Forwarder& forwarder)
145 : Strategy(forwarder, STRATEGY_NAME)
146 {
147 }
148
149 virtual void
150 afterReceiveInterest(const Face& inFace, const Interest& interest,
151 shared_ptr<nfd::fib::Entry> fibEntry, shared_ptr<nfd::pit::Entry> pitEntry)
152 {
153 // this strategy doesn't forward interests
154 }
155
156public:
157 static const Name STRATEGY_NAME;
158};
159
160const Name NullStrategy::STRATEGY_NAME = "ndn:/localhost/nfd/strategy/unit-tests/null-strategy";
161
162// template<class Strategy>
163// static void
164// Install(Ptr<Node> node, const Name& namePrefix);
165BOOST_AUTO_TEST_CASE(InstallCustomStrategyOnNode)
166{
167 StrategyChoiceHelper::Install<NullStrategy>(getNode("A2"), "/prefix");
168
169 Simulator::Stop(Seconds(5.0));
170 Simulator::Run();
171
172 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 0);
173 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 5);
174
175 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 0);
176 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 0);
177}
178
179// template<class Strategy>
180// static void
181// Install(const NodeContainer& c, const Name& namePrefix);
182BOOST_AUTO_TEST_CASE(InstallCustomStrategyOnNodeContainer)
183{
184 NodeContainer nodes;
185 nodes.Add(getNode("A1"));
186 nodes.Add(getNode("A2"));
187
188 StrategyChoiceHelper::Install<NullStrategy>(nodes, "/prefix");
189
190 Simulator::Stop(Seconds(5.0));
191 Simulator::Run();
192
193 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 0);
194 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 0);
195
196 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 0);
197 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 0);
198}
199
200// template<class Strategy>
201// static void
202// InstallAll(const Name& namePrefix);
203BOOST_AUTO_TEST_CASE(InstallAllCustomStrategy)
204{
205 StrategyChoiceHelper::InstallAll<NullStrategy>("/prefix");
206
207 Simulator::Stop(Seconds(5.0));
208 Simulator::Run();
209
210 BOOST_CHECK_EQUAL(getFace("A1", "B1")->getFaceStatus().getNOutInterests(), 0);
211 BOOST_CHECK_EQUAL(getFace("A1", "C1")->getFaceStatus().getNOutInterests(), 0);
212
213 BOOST_CHECK_EQUAL(getFace("A2", "B2")->getFaceStatus().getNOutInterests(), 0);
214 BOOST_CHECK_EQUAL(getFace("A2", "C2")->getFaceStatus().getNOutInterests(), 0);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700215}
216
217BOOST_AUTO_TEST_SUITE_END()
218
219} // namespace ndn
220} // namespace ns3