blob: c5d22f4dac809c610828eb30f9594405f1127079 [file] [log] [blame]
Junxiao Shif2bfb442018-01-05 12:34:57 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "mgmt/cs-manager.hpp"
27#include "nfd-manager-common-fixture.hpp"
28#include <ndn-cxx/mgmt/nfd/cs-info.hpp>
29
30namespace nfd {
31namespace tests {
32
33class CsManagerFixture : public NfdManagerCommonFixture
34{
35public:
36 CsManagerFixture()
37 : m_cs(m_forwarder.getCs())
38 , m_fwCnt(const_cast<ForwarderCounters&>(m_forwarder.getCounters()))
39 , m_manager(m_cs, m_fwCnt, m_dispatcher, *m_authenticator)
40 {
41 setTopPrefix();
Junxiao Shic9b5e012018-02-07 15:04:18 +000042 setPrivilege("cs");
Junxiao Shif2bfb442018-01-05 12:34:57 +000043 }
44
45protected:
46 Cs& m_cs;
47 ForwarderCounters& m_fwCnt;
48 CsManager m_manager;
49};
50
51BOOST_AUTO_TEST_SUITE(Mgmt)
52BOOST_FIXTURE_TEST_SUITE(TestCsManager, CsManagerFixture)
53
Junxiao Shic9b5e012018-02-07 15:04:18 +000054BOOST_AUTO_TEST_CASE(Config)
55{
56 using ndn::nfd::CsFlagBit;
57 const Name cmdPrefix("/localhost/nfd/cs/config");
58
59 // setup initial CS config
60 m_cs.setLimit(22129);
61 m_cs.enableAdmit(false);
62 m_cs.enableServe(true);
63
64 // send empty cs/config command
65 auto req = makeControlCommandRequest(cmdPrefix, ControlParameters());
66 receiveInterest(req);
67
68 // response shall reflect current config
69 ControlParameters body;
70 body.setCapacity(22129);
71 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, false, false);
72 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, true, false);
73 BOOST_CHECK_EQUAL(checkResponse(0, req.getName(),
74 ControlResponse(200, "OK").setBody(body.wireEncode())),
75 CheckResponseResult::OK);
76
77 // send filled cs/config command
78 ControlParameters parameters;
79 parameters.setCapacity(18609);
80 parameters.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, true);
81 parameters.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, false);
82 req = makeControlCommandRequest(cmdPrefix, parameters);
83 receiveInterest(req);
84
85 // response shall reflect updated config
86 body.setCapacity(18609);
87 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, true, false);
88 body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, false, false);
89 BOOST_CHECK_EQUAL(checkResponse(1, req.getName(),
90 ControlResponse(200, "OK").setBody(body.wireEncode())),
91 CheckResponseResult::OK);
92
93 // CS shall have updated config
94 BOOST_CHECK_EQUAL(m_cs.getLimit(), 18609);
95 BOOST_CHECK_EQUAL(m_cs.shouldAdmit(), true);
96 BOOST_CHECK_EQUAL(m_cs.shouldServe(), false);
97}
98
Junxiao Shif2bfb442018-01-05 12:34:57 +000099BOOST_AUTO_TEST_CASE(Info)
100{
Junxiao Shi26667e12018-02-08 20:01:18 +0000101 m_cs.setLimit(2681);
102 for (int i = 0; i < 310; ++i) {
103 m_cs.insert(*makeData(Name("/Q8H4oi4g").appendSequenceNumber(i)));
104 }
105 m_cs.enableAdmit(false);
106 m_cs.enableServe(true);
Junxiao Shif2bfb442018-01-05 12:34:57 +0000107 m_fwCnt.nCsHits.set(362);
108 m_fwCnt.nCsMisses.set(1493);
109
110 receiveInterest(Interest("/localhost/nfd/cs/info"));
111 Block dataset = concatenateResponses();
112 dataset.parse();
113 BOOST_REQUIRE_EQUAL(dataset.elements_size(), 1);
114
115 ndn::nfd::CsInfo info(*dataset.elements_begin());
Junxiao Shi26667e12018-02-08 20:01:18 +0000116 BOOST_CHECK_EQUAL(info.getCapacity(), 2681);
117 BOOST_CHECK_EQUAL(info.getEnableAdmit(), false);
118 BOOST_CHECK_EQUAL(info.getEnableServe(), true);
119 BOOST_CHECK_EQUAL(info.getNEntries(), 310);
Junxiao Shif2bfb442018-01-05 12:34:57 +0000120 BOOST_CHECK_EQUAL(info.getNHits(), 362);
121 BOOST_CHECK_EQUAL(info.getNMisses(), 1493);
122}
123
124BOOST_AUTO_TEST_SUITE_END() // TestCsManager
125BOOST_AUTO_TEST_SUITE_END() // Mgmt
126
127} // namespace tests
128} // namespace nfd