blob: b9cade394ae132c230c05134a4e90226a61ebf43 [file] [log] [blame]
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07004 * 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/forwarder-status-manager.hpp"
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000027#include "core/version.hpp"
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070028
Yanbiao Lidf846e52016-01-30 21:53:47 -080029#include "nfd-manager-common-fixture.hpp"
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070030
31namespace nfd {
32namespace tests {
33
Yanbiao Lidf846e52016-01-30 21:53:47 -080034class ForwarderStatusManagerFixture : public NfdManagerCommonFixture
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070035{
Junxiao Shi80946242015-12-29 17:53:18 -070036protected:
37 ForwarderStatusManagerFixture()
38 : manager(m_forwarder, m_dispatcher)
39 , startTime(time::system_clock::now())
40 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000041 setTopPrefix();
Junxiao Shi80946242015-12-29 17:53:18 -070042 }
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070043
Junxiao Shi80946242015-12-29 17:53:18 -070044protected:
45 ForwarderStatusManager manager;
46 time::system_clock::TimePoint startTime;
47};
48
Davide Pesavento97210d52016-10-14 15:45:48 +020049BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shi80946242015-12-29 17:53:18 -070050BOOST_FIXTURE_TEST_SUITE(TestForwarderStatusManager, ForwarderStatusManagerFixture)
51
Davide Pesavento97210d52016-10-14 15:45:48 +020052BOOST_AUTO_TEST_CASE(GeneralStatusDataset)
Junxiao Shi80946242015-12-29 17:53:18 -070053{
54 // cause counters to be non-zero
55 this->advanceClocks(time::seconds(3600));
56 m_forwarder.getFib().insert("ndn:/fib1");
57 m_forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
58 m_forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
59 m_forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
60 m_forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
61 m_forwarder.getMeasurements().get("ndn:/measurements1");
62 m_forwarder.getMeasurements().get("ndn:/measurements2");
63 m_forwarder.getMeasurements().get("ndn:/measurements3");
64 m_forwarder.getCs().insert(*makeData("ndn:/cs1"));
65 m_forwarder.getCs().insert(*makeData("ndn:/cs2"));
66 BOOST_CHECK_GE(m_forwarder.getFib().size(), 1);
67 BOOST_CHECK_GE(m_forwarder.getPit().size(), 4);
68 BOOST_CHECK_GE(m_forwarder.getMeasurements().size(), 3);
69 BOOST_CHECK_GE(m_forwarder.getCs().size(), 2);
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070070
71 // request
Junxiao Shi80946242015-12-29 17:53:18 -070072 time::system_clock::TimePoint beforeRequest = time::system_clock::now();
73 auto request = makeInterest("ndn:/localhost/nfd/status/general");
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070074 request->setMustBeFresh(true);
75 request->setChildSelector(1);
Junxiao Shi80946242015-12-29 17:53:18 -070076 this->receiveInterest(request);
77 time::system_clock::TimePoint afterRequest = time::system_clock::now();
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070078
79 // verify
Junxiao Shi80946242015-12-29 17:53:18 -070080 Block response = this->concatenateResponses(0, m_responses.size());
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070081 ndn::nfd::ForwarderStatus status;
Junxiao Shi80946242015-12-29 17:53:18 -070082 BOOST_REQUIRE_NO_THROW(status.wireDecode(response));
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070083
84 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING);
Junxiao Shi80946242015-12-29 17:53:18 -070085 BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(startTime));
86 BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(beforeRequest));
87 BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(afterRequest));
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070088
89 // Interest/Data toward ForwarderStatusManager don't go through Forwarder,
90 // so request and response won't affect table size
Junxiao Shi80946242015-12-29 17:53:18 -070091 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), m_forwarder.getNameTree().size());
92 BOOST_CHECK_EQUAL(status.getNFibEntries(), m_forwarder.getFib().size());
93 BOOST_CHECK_EQUAL(status.getNPitEntries(), m_forwarder.getPit().size());
94 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), m_forwarder.getMeasurements().size());
95 BOOST_CHECK_EQUAL(status.getNCsEntries(), m_forwarder.getCs().size());
Junxiao Shida93f1f2015-11-11 06:13:16 -070096 // TODO#3325 check packet counter values
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070097}
98
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070099BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatusManager
100BOOST_AUTO_TEST_SUITE_END() // Mgmt
101
102} // namespace tests
103} // namespace nfd