blob: 41f205700751e6fb84b6978febdea78cc31bae0e [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"
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -070022#include <ndn-cxx/link.hpp>
Mohammad Sabet532990d2016-10-17 20:23:56 +033023
24#include "../tests-common.hpp"
25
26namespace ns3 {
27namespace ndn {
28
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -070029using ::ndn::Delegation;
30using ::ndn::DelegationList;
31
Mohammad Sabet532990d2016-10-17 20:23:56 +033032BOOST_AUTO_TEST_SUITE(HelperNdnNetworkRegionTableHelper)
33
34class BasicFixture : public ScenarioHelperWithCleanupFixture
35{
36public:
37 BasicFixture()
38 {
39 createTopology({
40 {"1"}
41 });
42 }
43
44 ~BasicFixture()
45 {
46 }
47};
48
49BOOST_FIXTURE_TEST_SUITE(Basic, BasicFixture)
50
51BOOST_AUTO_TEST_CASE(AddBase)
52{
53 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
54 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
55}
56
57BOOST_AUTO_TEST_CASE(RemoveBase){
58 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
59 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), Name("/ucla"));
60 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 0);
61}
62
63BOOST_AUTO_TEST_CASE(AddSet)
64{
65 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
66 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
67 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/att"), 1);
68 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().size(), 2);
69}
70
71BOOST_AUTO_TEST_CASE(RemoveSet)
72{
73 NetworkRegionTableHelper::AddRegionName(getNode("1"), { "/ucla", "/att" });
74 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), { "/att", "/ucla" });
75 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
76}
77
78BOOST_AUTO_TEST_CASE(Empty)
79{
80 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
81 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ndnSIM"));
82 NetworkRegionTableHelper::EmptyNetworkRegionTable(getNode("1"));
83 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
84}
85
86BOOST_AUTO_TEST_SUITE_END() // Basic
87
88class MultiNodeWithAppFixture;
89class TesterApp
90{
91public:
92 TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture);
93
94protected:
95 ::ndn::Face m_face;
96};
97
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -070098DelegationList
99makeHint(const Name& delegation)
Mohammad Sabet532990d2016-10-17 20:23:56 +0330100{
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700101 Delegation del;
102 del.name = Name(delegation);
103 del.preference = 1;
104 DelegationList list({del});
105 return list;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330106}
107
108class MultiNodeWithAppFixture : public ScenarioHelperWithCleanupFixture
109{
110public:
111 MultiNodeWithAppFixture()
112 : m_nData(0)
113 , m_nTimeouts(0)
114 , m_nNacks(0)
115 {
116 createTopology({
117 {"1", "2"}
118 });
119
120 addApps({
121 {"2", "ns3::ndn::Producer",
122 {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
123 "0s", "100s"}
124 });
125
126 addRoutes({
127 {"1", "2", "/otherPrefix", 1},
128 });
129 }
130
131public:
132 size_t m_nData;
133 size_t m_nTimeouts;
134 size_t m_nNacks;
135};
136
137TesterApp::TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture)
138{
139 m_face.expressInterest(interest,
140 std::bind([fixture] {
141 ++fixture->m_nData;
142 }),
143 std::bind([fixture] {
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700144 ++fixture->m_nNacks;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330145 }),
146 std::bind([fixture] {
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700147 ++fixture->m_nTimeouts;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330148 }));
149}
150
151
152BOOST_FIXTURE_TEST_SUITE(MultiNode, MultiNodeWithAppFixture)
153
154BOOST_AUTO_TEST_CASE(WithoutNetworkRegion)
155{
156 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
157 Interest i("/prefix/someData");
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700158 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330159 return make_shared<TesterApp>(i, this);
160 })
161 .Start(Seconds(0.01));
162
163 Simulator::Stop(Seconds(20.001));
164 Simulator::Run();
165
166 BOOST_CHECK_EQUAL(this->m_nData, 0);
167 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
168 BOOST_CHECK_EQUAL(m_nNacks, 1);
169}
170
171BOOST_AUTO_TEST_CASE(WithNetworkRegion)
172{
173 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
174
175 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
176 Interest i("/prefix/someData");
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700177 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330178 return make_shared<TesterApp>(i, this);
179 })
180 .Start(Seconds(0.01));
181
182 Simulator::Stop(Seconds(20.001));
183 Simulator::Run();
184
185 BOOST_CHECK_EQUAL(m_nData, 1);
186 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
187 BOOST_CHECK_EQUAL(m_nNacks, 0);
188}
189
190BOOST_AUTO_TEST_CASE(WithMoreSpecificNetworkRegion)
191{
192 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix/moreSpecific"));
193
194 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
195 Interest i("/prefix/someData");
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700196 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330197 return make_shared<TesterApp>(i, this);
198 })
199 .Start(Seconds(0.01));
200
201 Simulator::Stop(Seconds(20.001));
202 Simulator::Run();
203
204 BOOST_CHECK_EQUAL(m_nData, 1);
205 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
206 BOOST_CHECK_EQUAL(m_nNacks, 0);
207}
208
209BOOST_AUTO_TEST_CASE(WithLessSpecificLink)
210{
211 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
212
213 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
214 Interest i("/prefix/someData");
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700215 i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330216 return make_shared<TesterApp>(i, this);
217 })
218 .Start(Seconds(0.01));
219
220 Simulator::Stop(Seconds(20.001));
221 Simulator::Run();
222
223 BOOST_CHECK_EQUAL(m_nData, 0);
224 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
225 BOOST_CHECK_EQUAL(m_nNacks, 1);
226}
227
228BOOST_AUTO_TEST_SUITE_END() // MultiNode
229
230BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper
231
232} // namespace ndn
233} // namespace ns3