blob: 2863de1cd08cb1a1ebd34403ccff8aa37d3cf17e [file] [log] [blame]
spirosmastorakis0df15ba2015-11-14 08:46:24 -08001/* -*- 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
27namespace ns3 {
28namespace ndn {
29
30BOOST_FIXTURE_TEST_SUITE(ModelNdnL3Protocol, ScenarioHelperWithCleanupFixture)
31
32class TesterApp
33{
34public:
35 TesterApp(const std::function<void(::ndn::Face& face)>& func)
36 {
37 func(m_face);
38 }
39
40protected:
41 ::ndn::Face m_face;
42};
43
44class ManagerCheckFixture : public ScenarioHelperWithCleanupFixture
45{
46public:
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 Afanasyeva91aab42016-09-08 15:47:38 -070058 "/localhost/nfd/status/general"
spirosmastorakis0df15ba2015-11-14 08:46:24 -080059 };
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) {
64 face.expressInterest(dataset, [&] (const Interest& i, Data& data) {
65 BOOST_TEST_MESSAGE(data.getName());
66 receivedDatasets.insert(data.getName().getPrefix(-2));
67 },
68 std::bind([]{}));
69 }
70 });
71 })
72 .Start(Seconds(0.01));
73
74 Simulator::Stop(Seconds(1.0));
75 Simulator::Run();
76 }
77
78public:
79 std::set<Name> requestedDatasets;
80 std::set<Name> receivedDatasets;
81};
82
83BOOST_FIXTURE_TEST_SUITE(ManagerCheck, ManagerCheckFixture)
84
85BOOST_AUTO_TEST_CASE(AllEnabled)
86{
87 setupAndRun();
88
89 BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size());
90 BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(),
91 receivedDatasets.begin(), receivedDatasets.end());
92}
93
94BOOST_AUTO_TEST_CASE(DisabledRibManager)
95{
96 // Disable RIB manager
97 disableRibManager();
98
99 setupAndRun();
100
101 BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1);
102
103 requestedDatasets.erase("/localhost/nfd/rib/list");
104 BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(),
105 receivedDatasets.begin(), receivedDatasets.end());
106}
107
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700108// BOOST_AUTO_TEST_CASE(DisabledFaceManager)
109// {
110// // Disable Face manager
111// disableFaceManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800112
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700113// setupAndRun();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800114
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700115// BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800116
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700117// requestedDatasets.erase("/localhost/nfd/faces/list");
118// BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(),
119// receivedDatasets.begin(), receivedDatasets.end());
120// }
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800121
122BOOST_AUTO_TEST_CASE(DisabledStrategyChoiceManager)
123{
124 // Disable Strategy Choice Manager manager
125 disableStrategyChoiceManager();
126
127 setupAndRun();
128
129 BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1);
130
131 requestedDatasets.erase("/localhost/nfd/strategy-choice/list");
132 BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(),
133 receivedDatasets.begin(), receivedDatasets.end());
134}
135
136BOOST_AUTO_TEST_CASE(DisabledStatusServer)
137{
138 // Disable Status Server manager
139 disableStatusServer();
140
141 setupAndRun();
142
143 BOOST_CHECK_EQUAL(requestedDatasets.size(), receivedDatasets.size() + 1);
144
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700145 requestedDatasets.erase("/localhost/nfd/status/general");
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800146 BOOST_CHECK_EQUAL_COLLECTIONS(requestedDatasets.begin(), requestedDatasets.end(),
147 receivedDatasets.begin(), receivedDatasets.end());
148}
149
150BOOST_AUTO_TEST_SUITE_END() // ManagerCheck
151
152BOOST_AUTO_TEST_SUITE_END() // ModelNdnL3Protocol
153
154} // namespace ndn
155} // namespace ns3