blob: c683ae43ef768021b922584a97f55f218b6b5223 [file] [log] [blame]
Mohammad Sabet532990d2016-10-17 20:23:56 +03301/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2016 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-network-region-table-helper.hpp"
21#include "helper/ndn-app-helper.hpp"
22
23#include "../tests-common.hpp"
24
25namespace ns3 {
26namespace ndn {
27
28BOOST_AUTO_TEST_SUITE(HelperNdnNetworkRegionTableHelper)
29
30class BasicFixture : public ScenarioHelperWithCleanupFixture
31{
32public:
33 BasicFixture()
34 {
35 createTopology({
36 {"1"}
37 });
38 }
39
40 ~BasicFixture()
41 {
42 }
43};
44
45BOOST_FIXTURE_TEST_SUITE(Basic, BasicFixture)
46
47BOOST_AUTO_TEST_CASE(AddBase)
48{
49 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
50 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
51}
52
53BOOST_AUTO_TEST_CASE(RemoveBase){
54 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
55 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), Name("/ucla"));
56 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 0);
57}
58
59BOOST_AUTO_TEST_CASE(AddSet)
60{
61 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
62 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
63 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/att"), 1);
64 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().size(), 2);
65}
66
67BOOST_AUTO_TEST_CASE(RemoveSet)
68{
69 NetworkRegionTableHelper::AddRegionName(getNode("1"), { "/ucla", "/att" });
70 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), { "/att", "/ucla" });
71 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
72}
73
74BOOST_AUTO_TEST_CASE(Empty)
75{
76 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
77 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ndnSIM"));
78 NetworkRegionTableHelper::EmptyNetworkRegionTable(getNode("1"));
79 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
80}
81
82BOOST_AUTO_TEST_SUITE_END() // Basic
83
84class MultiNodeWithAppFixture;
85class TesterApp
86{
87public:
88 TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture);
89
90protected:
91 ::ndn::Face m_face;
92};
93
94Block
95makeLink(const Name& delegation)
96{
97 ::ndn::Link link("/LINK");
98 link.addDelegation(1, delegation);
99 ndn::StackHelper::getKeyChain().sign(link, ::ndn::security::SigningInfo(::ndn::security::SigningInfo::SIGNER_TYPE_SHA256));
100 return link.wireEncode();
101}
102
103class MultiNodeWithAppFixture : public ScenarioHelperWithCleanupFixture
104{
105public:
106 MultiNodeWithAppFixture()
107 : m_nData(0)
108 , m_nTimeouts(0)
109 , m_nNacks(0)
110 {
111 createTopology({
112 {"1", "2"}
113 });
114
115 addApps({
116 {"2", "ns3::ndn::Producer",
117 {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
118 "0s", "100s"}
119 });
120
121 addRoutes({
122 {"1", "2", "/otherPrefix", 1},
123 });
124 }
125
126public:
127 size_t m_nData;
128 size_t m_nTimeouts;
129 size_t m_nNacks;
130};
131
132TesterApp::TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture)
133{
134 m_face.expressInterest(interest,
135 std::bind([fixture] {
136 ++fixture->m_nData;
137 }),
138 std::bind([fixture] {
139 ++fixture->m_nTimeouts;
140 }),
141 std::bind([fixture] {
142 ++fixture->m_nNacks;
143 }));
144}
145
146
147BOOST_FIXTURE_TEST_SUITE(MultiNode, MultiNodeWithAppFixture)
148
149BOOST_AUTO_TEST_CASE(WithoutNetworkRegion)
150{
151 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
152 Interest i("/prefix/someData");
153 i.setLink(makeLink("/otherPrefix"));
154 return make_shared<TesterApp>(i, this);
155 })
156 .Start(Seconds(0.01));
157
158 Simulator::Stop(Seconds(20.001));
159 Simulator::Run();
160
161 BOOST_CHECK_EQUAL(this->m_nData, 0);
162 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
163 BOOST_CHECK_EQUAL(m_nNacks, 1);
164}
165
166BOOST_AUTO_TEST_CASE(WithNetworkRegion)
167{
168 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
169
170 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
171 Interest i("/prefix/someData");
172 i.setLink(makeLink("/otherPrefix"));
173 return make_shared<TesterApp>(i, this);
174 })
175 .Start(Seconds(0.01));
176
177 Simulator::Stop(Seconds(20.001));
178 Simulator::Run();
179
180 BOOST_CHECK_EQUAL(m_nData, 1);
181 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
182 BOOST_CHECK_EQUAL(m_nNacks, 0);
183}
184
185BOOST_AUTO_TEST_CASE(WithMoreSpecificNetworkRegion)
186{
187 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix/moreSpecific"));
188
189 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
190 Interest i("/prefix/someData");
191 i.setLink(makeLink("/otherPrefix"));
192 return make_shared<TesterApp>(i, this);
193 })
194 .Start(Seconds(0.01));
195
196 Simulator::Stop(Seconds(20.001));
197 Simulator::Run();
198
199 BOOST_CHECK_EQUAL(m_nData, 1);
200 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
201 BOOST_CHECK_EQUAL(m_nNacks, 0);
202}
203
204BOOST_AUTO_TEST_CASE(WithLessSpecificLink)
205{
206 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
207
208 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
209 Interest i("/prefix/someData");
210 i.setLink(makeLink("/otherPrefix/moreSpecific"));
211 return make_shared<TesterApp>(i, this);
212 })
213 .Start(Seconds(0.01));
214
215 Simulator::Stop(Seconds(20.001));
216 Simulator::Run();
217
218 BOOST_CHECK_EQUAL(m_nData, 0);
219 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
220 BOOST_CHECK_EQUAL(m_nNacks, 1);
221}
222
223BOOST_AUTO_TEST_SUITE_END() // MultiNode
224
225BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper
226
227} // namespace ndn
228} // namespace ns3