Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, 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/forwarder-status-manager.hpp" |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 27 | #include "version.hpp" |
| 28 | |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 29 | #include "manager-common-fixture.hpp" |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace tests { |
| 33 | |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 36 | class ForwarderStatusManagerFixture : public ManagerCommonFixture |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 37 | { |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 38 | protected: |
| 39 | ForwarderStatusManagerFixture() |
| 40 | : manager(m_forwarder, m_dispatcher) |
| 41 | , startTime(time::system_clock::now()) |
| 42 | { |
| 43 | this->setTopPrefixAndPrivilege("/localhost/nfd", "status"); |
| 44 | } |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 45 | |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 46 | protected: |
| 47 | ForwarderStatusManager manager; |
| 48 | time::system_clock::TimePoint startTime; |
| 49 | }; |
| 50 | |
| 51 | BOOST_FIXTURE_TEST_SUITE(TestForwarderStatusManager, ForwarderStatusManagerFixture) |
| 52 | |
| 53 | BOOST_AUTO_TEST_CASE(GeneralStatus) |
| 54 | { |
| 55 | // cause counters to be non-zero |
| 56 | this->advanceClocks(time::seconds(3600)); |
| 57 | m_forwarder.getFib().insert("ndn:/fib1"); |
| 58 | m_forwarder.getPit().insert(*makeInterest("ndn:/pit1")); |
| 59 | m_forwarder.getPit().insert(*makeInterest("ndn:/pit2")); |
| 60 | m_forwarder.getPit().insert(*makeInterest("ndn:/pit3")); |
| 61 | m_forwarder.getPit().insert(*makeInterest("ndn:/pit4")); |
| 62 | m_forwarder.getMeasurements().get("ndn:/measurements1"); |
| 63 | m_forwarder.getMeasurements().get("ndn:/measurements2"); |
| 64 | m_forwarder.getMeasurements().get("ndn:/measurements3"); |
| 65 | m_forwarder.getCs().insert(*makeData("ndn:/cs1")); |
| 66 | m_forwarder.getCs().insert(*makeData("ndn:/cs2")); |
| 67 | BOOST_CHECK_GE(m_forwarder.getFib().size(), 1); |
| 68 | BOOST_CHECK_GE(m_forwarder.getPit().size(), 4); |
| 69 | BOOST_CHECK_GE(m_forwarder.getMeasurements().size(), 3); |
| 70 | BOOST_CHECK_GE(m_forwarder.getCs().size(), 2); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 71 | |
| 72 | // request |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 73 | time::system_clock::TimePoint beforeRequest = time::system_clock::now(); |
| 74 | auto request = makeInterest("ndn:/localhost/nfd/status/general"); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 75 | request->setMustBeFresh(true); |
| 76 | request->setChildSelector(1); |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 77 | this->receiveInterest(request); |
| 78 | time::system_clock::TimePoint afterRequest = time::system_clock::now(); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 79 | |
| 80 | // verify |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 81 | Block response = this->concatenateResponses(0, m_responses.size()); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 82 | ndn::nfd::ForwarderStatus status; |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 83 | BOOST_REQUIRE_NO_THROW(status.wireDecode(response)); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 84 | |
| 85 | BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING); |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(startTime)); |
| 87 | BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(beforeRequest)); |
| 88 | BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(afterRequest)); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 89 | |
| 90 | // Interest/Data toward ForwarderStatusManager don't go through Forwarder, |
| 91 | // so request and response won't affect table size |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), m_forwarder.getNameTree().size()); |
| 93 | BOOST_CHECK_EQUAL(status.getNFibEntries(), m_forwarder.getFib().size()); |
| 94 | BOOST_CHECK_EQUAL(status.getNPitEntries(), m_forwarder.getPit().size()); |
| 95 | BOOST_CHECK_EQUAL(status.getNMeasurementsEntries(), m_forwarder.getMeasurements().size()); |
| 96 | BOOST_CHECK_EQUAL(status.getNCsEntries(), m_forwarder.getCs().size()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 97 | // TODO#3325 check packet counter values |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Junxiao Shi | 8094624 | 2015-12-29 17:53:18 -0700 | [diff] [blame] | 100 | BOOST_AUTO_TEST_CASE(GeneralStatusLegacy) // request GeneralStatus with legacy name |
| 101 | { |
| 102 | auto request = makeInterest("ndn:/localhost/nfd/status"); |
| 103 | request->setMustBeFresh(true); |
| 104 | request->setChildSelector(1); |
| 105 | this->receiveInterest(request); |
| 106 | |
| 107 | BOOST_REQUIRE_GE(m_responses.size(), 1); |
| 108 | BOOST_CHECK(Name("ndn:/localhost/nfd/status/general").isPrefixOf(m_responses.front().getName())); |
| 109 | |
| 110 | Block response = this->concatenateResponses(0, m_responses.size()); |
| 111 | BOOST_REQUIRE_NO_THROW(ndn::nfd::ForwarderStatus(response)); |
| 112 | } |
| 113 | |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 114 | BOOST_AUTO_TEST_SUITE_END() // TestForwarderStatusManager |
| 115 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 116 | |
| 117 | } // namespace tests |
| 118 | } // namespace nfd |