blob: e40a0ce91f35a6a846e586dddc1aa305e3bc68f1 [file] [log] [blame]
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ju Pan6eb1ac92018-10-26 16:26:15 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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
Davide Pesavento78ddcab2019-02-28 22:00:03 -050029#include "manager-common-fixture.hpp"
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070030
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070032
Davide Pesavento78ddcab2019-02-28 22:00:03 -050033class ForwarderStatusManagerFixture : public ManagerCommonFixture
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070034{
Junxiao Shi80946242015-12-29 17:53:18 -070035protected:
36 ForwarderStatusManagerFixture()
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040037 : m_forwarder(m_faceTable)
38 , m_manager(m_forwarder, m_dispatcher)
Davide Pesavento78ddcab2019-02-28 22:00:03 -050039 , m_startTime(time::system_clock::now())
Junxiao Shi80946242015-12-29 17:53:18 -070040 {
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:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040045 FaceTable m_faceTable;
Davide Pesavento78ddcab2019-02-28 22:00:03 -050046 Forwarder m_forwarder;
47 ForwarderStatusManager m_manager;
48 time::system_clock::TimePoint m_startTime;
Junxiao Shi80946242015-12-29 17:53:18 -070049};
50
Davide Pesavento97210d52016-10-14 15:45:48 +020051BOOST_AUTO_TEST_SUITE(Mgmt)
Junxiao Shi80946242015-12-29 17:53:18 -070052BOOST_FIXTURE_TEST_SUITE(TestForwarderStatusManager, ForwarderStatusManagerFixture)
53
Davide Pesavento97210d52016-10-14 15:45:48 +020054BOOST_AUTO_TEST_CASE(GeneralStatusDataset)
Junxiao Shi80946242015-12-29 17:53:18 -070055{
56 // cause counters to be non-zero
Davide Pesavento14e71f02019-03-28 17:35:25 -040057 this->advanceClocks(1_h);
Junxiao Shi80946242015-12-29 17:53:18 -070058 m_forwarder.getFib().insert("ndn:/fib1");
59 m_forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
60 m_forwarder.getPit().insert(*makeInterest("ndn:/pit2"));
61 m_forwarder.getPit().insert(*makeInterest("ndn:/pit3"));
62 m_forwarder.getPit().insert(*makeInterest("ndn:/pit4"));
63 m_forwarder.getMeasurements().get("ndn:/measurements1");
64 m_forwarder.getMeasurements().get("ndn:/measurements2");
65 m_forwarder.getMeasurements().get("ndn:/measurements3");
66 m_forwarder.getCs().insert(*makeData("ndn:/cs1"));
67 m_forwarder.getCs().insert(*makeData("ndn:/cs2"));
Ju Pan6eb1ac92018-10-26 16:26:15 +000068 shared_ptr<pit::Entry> pitA = m_forwarder.getPit().insert(*makeInterest("ndn:/pitA")).first;
69 pitA->isSatisfied = false;
70 m_forwarder.onInterestFinalize(pitA);
71 shared_ptr<pit::Entry> pitB = m_forwarder.getPit().insert(*makeInterest("ndn:/pitB")).first;
72 pitB->isSatisfied = true;
73 m_forwarder.onInterestFinalize(pitB);
74
Junxiao Shi80946242015-12-29 17:53:18 -070075 BOOST_CHECK_GE(m_forwarder.getFib().size(), 1);
76 BOOST_CHECK_GE(m_forwarder.getPit().size(), 4);
77 BOOST_CHECK_GE(m_forwarder.getMeasurements().size(), 3);
78 BOOST_CHECK_GE(m_forwarder.getCs().size(), 2);
Ju Pan6eb1ac92018-10-26 16:26:15 +000079 BOOST_CHECK_EQUAL(m_forwarder.getCounters().nSatisfiedInterests, 1);
80 BOOST_CHECK_EQUAL(m_forwarder.getCounters().nUnsatisfiedInterests, 1);
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070081
82 // request
Davide Pesavento78ddcab2019-02-28 22:00:03 -050083 auto beforeRequest = time::system_clock::now();
84 receiveInterest(Interest("/localhost/nfd/status/general").setCanBePrefix(true));
85 auto afterRequest = time::system_clock::now();
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070086
87 // verify
Junxiao Shi80946242015-12-29 17:53:18 -070088 Block response = this->concatenateResponses(0, m_responses.size());
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070089 ndn::nfd::ForwarderStatus status;
Junxiao Shi80946242015-12-29 17:53:18 -070090 BOOST_REQUIRE_NO_THROW(status.wireDecode(response));
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070091
92 BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING);
Davide Pesavento78ddcab2019-02-28 22:00:03 -050093 BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(m_startTime));
Junxiao Shi80946242015-12-29 17:53:18 -070094 BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(beforeRequest));
95 BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(afterRequest));
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070096
97 // Interest/Data toward ForwarderStatusManager don't go through Forwarder,
98 // so request and response won't affect table size
Junxiao Shi80946242015-12-29 17:53:18 -070099 BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), m_forwarder.getNameTree().size());
100 BOOST_CHECK_EQUAL(status.getNFibEntries(), m_forwarder.getFib().size());
101 BOOST_CHECK_EQUAL(status.getNPitEntries(), m_forwarder.getPit().size());
102 BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), m_forwarder.getMeasurements().size());
103 BOOST_CHECK_EQUAL(status.getNCsEntries(), m_forwarder.getCs().size());
Junxiao Shida93f1f2015-11-11 06:13:16 -0700104 // TODO#3325 check packet counter values
Ju Pan6eb1ac92018-10-26 16:26:15 +0000105
106 BOOST_CHECK_EQUAL(status.getNSatisfiedInterests(), m_forwarder.getCounters().nSatisfiedInterests);
107 BOOST_CHECK_EQUAL(status.getNUnsatisfiedInterests(), m_forwarder.getCounters().nUnsatisfiedInterests);
Yanbiao Li7cec7ea2015-08-19 16:30:16 -0700108}
109
Yanbiao Li7cec7ea2015-08-19 16:30:16 -0700110BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatusManager
111BOOST_AUTO_TEST_SUITE_END() // Mgmt
112
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400113} // namespace nfd::tests