Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 1 | /* -*- 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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 22 | #include <ndn-cxx/link.hpp> |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 23 | |
| 24 | #include "../tests-common.hpp" |
| 25 | |
| 26 | namespace ns3 { |
| 27 | namespace ndn { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(HelperNdnNetworkRegionTableHelper) |
| 30 | |
| 31 | class BasicFixture : public ScenarioHelperWithCleanupFixture |
| 32 | { |
| 33 | public: |
| 34 | BasicFixture() |
| 35 | { |
| 36 | createTopology({ |
| 37 | {"1"} |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | ~BasicFixture() |
| 42 | { |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | BOOST_FIXTURE_TEST_SUITE(Basic, BasicFixture) |
| 47 | |
| 48 | BOOST_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 | |
| 54 | BOOST_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 | |
| 60 | BOOST_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 | |
| 68 | BOOST_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 | |
| 75 | BOOST_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 | |
| 83 | BOOST_AUTO_TEST_SUITE_END() // Basic |
| 84 | |
| 85 | class MultiNodeWithAppFixture; |
| 86 | class TesterApp |
| 87 | { |
| 88 | public: |
| 89 | TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture); |
| 90 | |
| 91 | protected: |
| 92 | ::ndn::Face m_face; |
| 93 | }; |
| 94 | |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame^] | 95 | std::vector<Name> |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 96 | makeHint(const Name& delegation) |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 97 | { |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame^] | 98 | std::vector<Name> ret; |
| 99 | ret.push_back(delegation); |
| 100 | return ret; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | class MultiNodeWithAppFixture : public ScenarioHelperWithCleanupFixture |
| 104 | { |
| 105 | public: |
| 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 | |
| 126 | public: |
| 127 | size_t m_nData; |
| 128 | size_t m_nTimeouts; |
| 129 | size_t m_nNacks; |
| 130 | }; |
| 131 | |
| 132 | TesterApp::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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 139 | ++fixture->m_nNacks; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 140 | }), |
| 141 | std::bind([fixture] { |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 142 | ++fixture->m_nTimeouts; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 143 | })); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | BOOST_FIXTURE_TEST_SUITE(MultiNode, MultiNodeWithAppFixture) |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(WithoutNetworkRegion) |
| 150 | { |
| 151 | FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> { |
| 152 | Interest i("/prefix/someData"); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 153 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 154 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 155 | 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 | |
| 167 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 173 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 174 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 175 | 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 | |
| 187 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 193 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 194 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 195 | 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 | |
| 207 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 213 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 214 | i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 215 | 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 | |
| 227 | BOOST_AUTO_TEST_SUITE_END() // MultiNode |
| 228 | |
| 229 | BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper |
| 230 | |
| 231 | } // namespace ndn |
| 232 | } // namespace ns3 |