blob: 7191f7d1c30c0da76c1e0f031399e6f314e8feb5 [file] [log] [blame]
Junxiao Shi3160a3f2018-01-09 21:25:15 +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 "nfdc/cs-module.hpp"
27
28#include "status-fixture.hpp"
Junxiao Shicdf78452018-03-02 23:14:15 +000029#include "execute-command-fixture.hpp"
Junxiao Shi3160a3f2018-01-09 21:25:15 +000030
31namespace nfd {
32namespace tools {
33namespace nfdc {
34namespace tests {
35
36BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shicdf78452018-03-02 23:14:15 +000037BOOST_AUTO_TEST_SUITE(TestCsModule)
38
39BOOST_FIXTURE_TEST_SUITE(ConfigCommand, ExecuteCommandFixture)
40
41BOOST_AUTO_TEST_CASE(Normal)
42{
43 this->processInterest = [this] (const Interest& interest) {
44 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/cs/config");
45 BOOST_REQUIRE(req.hasCapacity());
46 BOOST_CHECK_EQUAL(req.getCapacity(), 29850);
47 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT));
48 BOOST_CHECK_EQUAL(req.getFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT), false);
49 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE));
50 BOOST_CHECK_EQUAL(req.getFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE), true);
51
52 ControlParameters resp(req);
53 resp.unsetMask();
54 this->succeedCommand(interest, resp);
55 };
56
57 this->execute("cs config admit off serve on capacity 29850");
58 BOOST_CHECK_EQUAL(exitCode, 0);
59 BOOST_CHECK(out.is_equal("cs-config-updated capacity=29850 admit=off serve=on\n"));
60 BOOST_CHECK(err.is_empty());
61}
62
63BOOST_AUTO_TEST_CASE(NoUpdate)
64{
65 this->processInterest = [this] (const Interest& interest) {
66 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/cs/config");
67 BOOST_CHECK(!req.hasCapacity());
68 BOOST_CHECK(!req.hasFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT));
69 BOOST_CHECK(!req.hasFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE));
70
71 ControlParameters resp;
72 resp.setCapacity(573599);
73 resp.setFlagBit(ndn::nfd::BIT_CS_ENABLE_ADMIT, true, false);
74 resp.setFlagBit(ndn::nfd::BIT_CS_ENABLE_SERVE, false, false);
75 this->succeedCommand(interest, resp);
76 };
77
78 this->execute("cs config");
79 BOOST_CHECK_EQUAL(exitCode, 0);
80 BOOST_CHECK(out.is_equal("cs-config-updated capacity=573599 admit=on serve=off\n"));
81 BOOST_CHECK(err.is_empty());
82}
83
84BOOST_AUTO_TEST_CASE(ErrorCommand)
85{
86 this->processInterest = nullptr; // no response to command
87
88 this->execute("cs config capacity 19956");
89 BOOST_CHECK_EQUAL(exitCode, 1);
90 BOOST_CHECK(out.is_empty());
91 BOOST_CHECK(err.is_equal("Error 10060 when updating CS config: request timed out\n"));
92}
93
94BOOST_AUTO_TEST_SUITE_END() // ConfigCommand
Junxiao Shi3160a3f2018-01-09 21:25:15 +000095
96const std::string STATUS_XML = stripXmlSpaces(R"XML(
97 <cs>
98 <nHits>14363</nHits>
99 <nMisses>27462</nMisses>
100 </cs>
101)XML");
102
103const std::string STATUS_TEXT = std::string(R"TEXT(
104CS information:
105 nHits=14363 nMisses=27462
106)TEXT").substr(1);
107
Junxiao Shicdf78452018-03-02 23:14:15 +0000108BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<CsModule>)
Junxiao Shi3160a3f2018-01-09 21:25:15 +0000109{
110 this->fetchStatus();
111 CsInfo payload;
112 payload.setNHits(14363)
113 .setNMisses(27462);
114 this->sendDataset("/localhost/nfd/cs/info", payload);
115 this->prepareStatusOutput();
116
117 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
118 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
119}
120
121BOOST_AUTO_TEST_SUITE_END() // TestCsModule
122BOOST_AUTO_TEST_SUITE_END() // Nfdc
123
124} // namespace tests
125} // namespace nfdc
126} // namespace tools
127} // namespace nfd