blob: 868b9dc6f61e727edf122f2b982842c9a39ec42a [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");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500158 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700159 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330160 return make_shared<TesterApp>(i, this);
161 })
162 .Start(Seconds(0.01));
163
164 Simulator::Stop(Seconds(20.001));
165 Simulator::Run();
166
167 BOOST_CHECK_EQUAL(this->m_nData, 0);
168 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
169 BOOST_CHECK_EQUAL(m_nNacks, 1);
170}
171
172BOOST_AUTO_TEST_CASE(WithNetworkRegion)
173{
174 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
175
176 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
177 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500178 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700179 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330180 return make_shared<TesterApp>(i, this);
181 })
182 .Start(Seconds(0.01));
183
184 Simulator::Stop(Seconds(20.001));
185 Simulator::Run();
186
187 BOOST_CHECK_EQUAL(m_nData, 1);
188 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
189 BOOST_CHECK_EQUAL(m_nNacks, 0);
190}
191
192BOOST_AUTO_TEST_CASE(WithMoreSpecificNetworkRegion)
193{
194 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix/moreSpecific"));
195
196 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
197 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500198 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700199 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330200 return make_shared<TesterApp>(i, this);
201 })
202 .Start(Seconds(0.01));
203
204 Simulator::Stop(Seconds(20.001));
205 Simulator::Run();
206
207 BOOST_CHECK_EQUAL(m_nData, 1);
208 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
209 BOOST_CHECK_EQUAL(m_nNacks, 0);
210}
211
212BOOST_AUTO_TEST_CASE(WithLessSpecificLink)
213{
214 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
215
216 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
217 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500218 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700219 i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330220 return make_shared<TesterApp>(i, this);
221 })
222 .Start(Seconds(0.01));
223
224 Simulator::Stop(Seconds(20.001));
225 Simulator::Run();
226
227 BOOST_CHECK_EQUAL(m_nData, 0);
228 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
229 BOOST_CHECK_EQUAL(m_nNacks, 1);
230}
231
232BOOST_AUTO_TEST_SUITE_END() // MultiNode
233
234BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper
235
236} // namespace ndn
237} // namespace ns3