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"); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 158 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 159 | 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 | |
| 171 | BOOST_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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 177 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 178 | 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 | |
| 190 | BOOST_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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 196 | i.setForwardingHint(makeHint(Name("/otherPrefix"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 197 | 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 | |
| 209 | BOOST_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 Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 215 | i.setForwardingHint(makeHint(Name("/otherPrefix/moreSpecific"))); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 216 | 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 | |
| 228 | BOOST_AUTO_TEST_SUITE_END() // MultiNode |
| 229 | |
| 230 | BOOST_AUTO_TEST_SUITE_END() // HelperNdnNetworkRegionTableHelper |
| 231 | |
| 232 | } // namespace ndn |
| 233 | } // namespace ns3 |