spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 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-scenario-helper.hpp" |
| 21 | #include "helper/ndn-app-helper.hpp" |
| 22 | |
| 23 | #include <ndn-cxx/face.hpp> |
| 24 | |
| 25 | #include "../tests-common.hpp" |
| 26 | |
| 27 | namespace ns3 { |
| 28 | namespace ndn { |
| 29 | |
| 30 | BOOST_FIXTURE_TEST_SUITE(ModelNdnL3Protocol, ScenarioHelperWithCleanupFixture) |
| 31 | |
| 32 | class TesterApp |
| 33 | { |
| 34 | public: |
| 35 | TesterApp(const std::function<void(::ndn::Face& face)>& func) |
| 36 | { |
| 37 | func(m_face); |
| 38 | } |
| 39 | |
| 40 | protected: |
| 41 | ::ndn::Face m_face; |
| 42 | }; |
| 43 | |
| 44 | class ManagerCheckFixture : public ScenarioHelperWithCleanupFixture |
| 45 | { |
| 46 | public: |
| 47 | void |
| 48 | setupAndRun() |
| 49 | { |
| 50 | createTopology({ |
| 51 | {"1"}, |
| 52 | }); |
| 53 | |
| 54 | requestedDatasets = { |
| 55 | "/localhost/nfd/rib/list", |
| 56 | "/localhost/nfd/faces/list", |
| 57 | "/localhost/nfd/strategy-choice/list", |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 58 | "/localhost/nfd/status/general" |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | FactoryCallbackApp::Install(getNode("1"), [this] () -> shared_ptr<void> { |
| 62 | return make_shared<TesterApp>([this] (::ndn::Face& face) { |
| 63 | for (const Name& dataset : requestedDatasets) { |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 64 | Interest i(dataset); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 65 | i.setCanBePrefix(true); |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 66 | face.expressInterest(i, [&] (const Interest& i, const Data& data) { |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 67 | BOOST_TEST_MESSAGE(data.getName()); |
| 68 | receivedDatasets.insert(data.getName().getPrefix(-2)); |
| 69 | }, |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 70 | std::bind([]{}), |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 71 | std::bind([]{})); |
| 72 | } |
| 73 | }); |
| 74 | }) |
| 75 | .Start(Seconds(0.01)); |
| 76 | |
| 77 | Simulator::Stop(Seconds(1.0)); |
| 78 | Simulator::Run(); |
| 79 | } |
| 80 | |
| 81 | public: |
| 82 | std::set<Name> requestedDatasets; |
| 83 | std::set<Name> receivedDatasets; |
| 84 | }; |
| 85 | |
| 86 | BOOST_FIXTURE_TEST_SUITE(ManagerCheck, ManagerCheckFixture) |
| 87 | |
| 88 | BOOST_AUTO_TEST_CASE(AllEnabled) |
| 89 | { |
| 90 | setupAndRun(); |
| 91 | |
| 92 | BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size()); |
| 93 | BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(), |
| 94 | receivedDatasets.begin(), receivedDatasets.end()); |
| 95 | } |
| 96 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(DisabledStrategyChoiceManager) |
| 98 | { |
| 99 | // Disable Strategy Choice Manager manager |
| 100 | disableStrategyChoiceManager(); |
| 101 | |
| 102 | setupAndRun(); |
| 103 | |
| 104 | BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1); |
| 105 | |
| 106 | requestedDatasets.erase("/localhost/nfd/strategy-choice/list"); |
| 107 | BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(), |
| 108 | receivedDatasets.begin(), receivedDatasets.end()); |
| 109 | } |
| 110 | |
Alexander Afanasyev | f326f94 | 2016-09-08 17:17:05 -0700 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(DisabledForwarderStatusManager) |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 112 | { |
Alexander Afanasyev | f326f94 | 2016-09-08 17:17:05 -0700 | [diff] [blame] | 113 | // Disable Forwarder Status Manager |
| 114 | disableForwarderStatusManager(); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 115 | |
| 116 | setupAndRun(); |
| 117 | |
| 118 | BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1); |
| 119 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 120 | requestedDatasets.erase("/localhost/nfd/status/general"); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(), |
| 122 | receivedDatasets.begin(), receivedDatasets.end()); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_SUITE_END() // ManagerCheck |
| 126 | |
| 127 | BOOST_AUTO_TEST_SUITE_END() // ModelNdnL3Protocol |
| 128 | |
| 129 | } // namespace ndn |
| 130 | } // namespace ns3 |