blob: 4acc09d3943b7cbc77b73a786d1e26267ee35e72 [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
29BOOST_AUTO_TEST_SUITE(HelperNdnNetworkRegionTableHelper)
30
31class BasicFixture : public ScenarioHelperWithCleanupFixture
32{
33public:
34 BasicFixture()
35 {
36 createTopology({
37 {"1"}
38 });
39 }
40
41 ~BasicFixture()
42 {
43 }
44};
45
46BOOST_FIXTURE_TEST_SUITE(Basic, BasicFixture)
47
48BOOST_AUTO_TEST_CASE(AddBase)
49{
50 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
51 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
52}
53
54BOOST_AUTO_TEST_CASE(RemoveBase){
55 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ucla"));
56 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), Name("/ucla"));
57 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 0);
58}
59
60BOOST_AUTO_TEST_CASE(AddSet)
61{
62 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
63 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/ucla"), 1);
64 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().count("/att"), 1);
65 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().size(), 2);
66}
67
68BOOST_AUTO_TEST_CASE(RemoveSet)
69{
70 NetworkRegionTableHelper::AddRegionName(getNode("1"), { "/ucla", "/att" });
71 NetworkRegionTableHelper::RemoveRegionName(getNode("1"), { "/att", "/ucla" });
72 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
73}
74
75BOOST_AUTO_TEST_CASE(Empty)
76{
77 NetworkRegionTableHelper::AddRegionName(getNode("1"), { Name("/ucla"), Name("/att") });
78 NetworkRegionTableHelper::AddRegionName(getNode("1"), Name("/ndnSIM"));
79 NetworkRegionTableHelper::EmptyNetworkRegionTable(getNode("1"));
80 BOOST_CHECK_EQUAL(getNode("1")->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().empty(), true);
81}
82
83BOOST_AUTO_TEST_SUITE_END() // Basic
84
85class MultiNodeWithAppFixture;
86class TesterApp
87{
88public:
89 TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture);
90
91protected:
92 ::ndn::Face m_face;
93};
94
Alexander Afanasyevf007a992022-05-05 15:57:08 -040095std::vector<Name>
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -070096makeHint(const Name& delegation)
Mohammad Sabet532990d2016-10-17 20:23:56 +033097{
Alexander Afanasyevf007a992022-05-05 15:57:08 -040098 std::vector<Name> ret;
99 ret.push_back(delegation);
100 return ret;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330101}
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] {
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700139 ++fixture->m_nNacks;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330140 }),
141 std::bind([fixture] {
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700142 ++fixture->m_nTimeouts;
Mohammad Sabet532990d2016-10-17 20:23:56 +0330143 }));
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");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500153 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700154 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330155 return make_shared<TesterApp>(i, this);
156 })
157 .Start(Seconds(0.01));
158
159 Simulator::Stop(Seconds(20.001));
160 Simulator::Run();
161
162 BOOST_CHECK_EQUAL(this->m_nData, 0);
163 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
164 BOOST_CHECK_EQUAL(m_nNacks, 1);
165}
166
167BOOST_AUTO_TEST_CASE(WithNetworkRegion)
168{
169 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
170
171 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
172 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500173 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700174 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330175 return make_shared<TesterApp>(i, this);
176 })
177 .Start(Seconds(0.01));
178
179 Simulator::Stop(Seconds(20.001));
180 Simulator::Run();
181
182 BOOST_CHECK_EQUAL(m_nData, 1);
183 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
184 BOOST_CHECK_EQUAL(m_nNacks, 0);
185}
186
187BOOST_AUTO_TEST_CASE(WithMoreSpecificNetworkRegion)
188{
189 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix/moreSpecific"));
190
191 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
192 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500193 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700194 i.setForwardingHint(makeHint(Name("/otherPrefix")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330195 return make_shared<TesterApp>(i, this);
196 })
197 .Start(Seconds(0.01));
198
199 Simulator::Stop(Seconds(20.001));
200 Simulator::Run();
201
202 BOOST_CHECK_EQUAL(m_nData, 1);
203 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
204 BOOST_CHECK_EQUAL(m_nNacks, 0);
205}
206
207BOOST_AUTO_TEST_CASE(WithLessSpecificLink)
208{
209 NetworkRegionTableHelper::AddRegionName(getNode("2"), Name("/otherPrefix"));
210
211 FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> {
212 Interest i("/prefix/someData");
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500213 i.setCanBePrefix(false);
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700214 i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific")));
Mohammad Sabet532990d2016-10-17 20:23:56 +0330215 return make_shared<TesterApp>(i, this);
216 })
217 .Start(Seconds(0.01));
218
219 Simulator::Stop(Seconds(20.001));
220 Simulator::Run();
221
222 BOOST_CHECK_EQUAL(m_nData, 0);
223 BOOST_CHECK_EQUAL(m_nTimeouts, 0);
224 BOOST_CHECK_EQUAL(m_nNacks, 1);
225}
226
227BOOST_AUTO_TEST_SUITE_END() // MultiNode
228
229BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper
230
231} // namespace ndn
232} // namespace ns3