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 | |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 29 | using ::ndn::Delegation; |
| 30 | using ::ndn::DelegationList; |
| 31 | |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(HelperNdnNetworkRegionTableHelper) |
| 33 | |
| 34 | class BasicFixture : public ScenarioHelperWithCleanupFixture |
| 35 | { |
| 36 | public: |
| 37 | BasicFixture() |
| 38 | { |
| 39 | createTopology({ |
| 40 | {"1"} |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | ~BasicFixture() |
| 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | BOOST_FIXTURE_TEST_SUITE(Basic, BasicFixture) |
| 50 | |
| 51 | BOOST_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 | |
| 57 | BOOST_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 | |
| 63 | BOOST_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 | |
| 71 | BOOST_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 | |
| 78 | BOOST_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 | |
| 86 | BOOST_AUTO_TEST_SUITE_END() // Basic |
| 87 | |
| 88 | class MultiNodeWithAppFixture; |
| 89 | class TesterApp |
| 90 | { |
| 91 | public: |
| 92 | TesterApp(const Interest& interest, MultiNodeWithAppFixture* fixture); |
| 93 | |
| 94 | protected: |
| 95 | ::ndn::Face m_face; |
| 96 | }; |
| 97 | |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 98 | DelegationList |
| 99 | makeHint(const Name& delegation) |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 100 | { |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 101 | Delegation del; |
| 102 | del.name = Name(delegation); |
| 103 | del.preference = 1; |
| 104 | DelegationList list({del}); |
| 105 | return list; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | class MultiNodeWithAppFixture : public ScenarioHelperWithCleanupFixture |
| 109 | { |
| 110 | public: |
| 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 | |
| 131 | public: |
| 132 | size_t m_nData; |
| 133 | size_t m_nTimeouts; |
| 134 | size_t m_nNacks; |
| 135 | }; |
| 136 | |
| 137 | TesterApp::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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 144 | ++fixture->m_nNacks; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 145 | }), |
| 146 | std::bind([fixture] { |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 147 | ++fixture->m_nTimeouts; |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 148 | })); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | BOOST_FIXTURE_TEST_SUITE(MultiNode, MultiNodeWithAppFixture) |
| 153 | |
| 154 | BOOST_AUTO_TEST_CASE(WithoutNetworkRegion) |
| 155 | { |
| 156 | FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> { |
| 157 | Interest i("/prefix/someData"); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 158 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 159 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 160 | 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 | |
| 172 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 178 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 179 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 180 | 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 | |
| 192 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 198 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 199 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 200 | 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 | |
| 212 | BOOST_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 Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 218 | i.setCanBePrefix(false); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 219 | i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 220 | 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 | |
| 232 | BOOST_AUTO_TEST_SUITE_END() // MultiNode |
| 233 | |
| 234 | BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper |
| 235 | |
| 236 | } // namespace ndn |
| 237 | } // namespace ns3 |