Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 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 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 26 | #include "nfdc/forwarder-general-module.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 27 | #include <ndn-cxx/security/signing-helpers.hpp> |
| 28 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 29 | #include "status-fixture.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 33 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Nfdc) |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TestForwarderGeneralModule, StatusFixture<ForwarderGeneralModule>) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 38 | |
| 39 | class MakeNfdIdCollector |
| 40 | { |
| 41 | public: |
| 42 | unique_ptr<NfdIdCollector> |
| 43 | operator()(Face&, KeyChain&) const |
| 44 | { |
| 45 | return make_unique<NfdIdCollector>(make_unique<ValidatorNull>()); |
| 46 | }; |
| 47 | }; |
| 48 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 49 | class ForwarderGeneralStatusFixture : public StatusFixture<ForwarderGeneralModule, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 50 | MakeNfdIdCollector> |
| 51 | { |
| 52 | protected: |
| 53 | ForwarderGeneralStatusFixture() |
| 54 | { |
| 55 | module.setNfdIdCollector(*validator); |
| 56 | |
| 57 | this->systemClock->setNow(time::seconds(1468784936)); |
| 58 | BOOST_REQUIRE(this->addIdentity("/nfd-status/test-nfdid")); |
| 59 | } |
| 60 | |
| 61 | private: |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 62 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 63 | signDatasetReply(Data& data) override |
| 64 | { |
| 65 | m_keyChain.sign(data, ndn::security::signingByIdentity("/nfd-status/test-nfdid")); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | const std::string STATUS_XML = stripXmlSpaces(R"XML( |
| 70 | <generalStatus> |
| 71 | <nfdId>/nfd-status/test-nfdid/KEY/ksk-1468784936000/ID-CERT</nfdId> |
| 72 | <version>0.4.1-1-g704430c</version> |
| 73 | <startTime>2016-06-24T15:13:46.856000</startTime> |
| 74 | <currentTime>2016-07-17T17:55:54.109000</currentTime> |
| 75 | <uptime>PT1996927S</uptime> |
| 76 | <nNameTreeEntries>668</nNameTreeEntries> |
| 77 | <nFibEntries>70</nFibEntries> |
| 78 | <nPitEntries>7</nPitEntries> |
| 79 | <nMeasurementsEntries>1</nMeasurementsEntries> |
| 80 | <nCsEntries>65536</nCsEntries> |
| 81 | <packetCounters> |
| 82 | <incomingPackets> |
| 83 | <nInterests>20699052</nInterests> |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 84 | <nData>5598070</nData> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 85 | <nNacks>7230</nNacks> |
| 86 | </incomingPackets> |
| 87 | <outgoingPackets> |
| 88 | <nInterests>36501092</nInterests> |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 89 | <nData>5671942</nData> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 90 | <nNacks>26762</nNacks> |
| 91 | </outgoingPackets> |
| 92 | </packetCounters> |
| 93 | </generalStatus> |
| 94 | )XML"); |
| 95 | |
| 96 | const std::string STATUS_TEXT = std::string(R"TEXT( |
| 97 | General NFD status: |
| 98 | nfdId=/nfd-status/test-nfdid/KEY/ksk-1468784936000/ID-CERT |
| 99 | version=0.4.1-1-g704430c |
| 100 | startTime=20160624T151346.856000 |
| 101 | currentTime=20160717T175554.109000 |
| 102 | uptime=1996927 seconds |
| 103 | nNameTreeEntries=668 |
| 104 | nFibEntries=70 |
| 105 | nPitEntries=7 |
| 106 | nMeasurementsEntries=1 |
| 107 | nCsEntries=65536 |
| 108 | nInInterests=20699052 |
| 109 | nOutInterests=36501092 |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 110 | nInData=5598070 |
| 111 | nOutData=5671942 |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 112 | nInNacks=7230 |
| 113 | nOutNacks=26762 |
| 114 | )TEXT").substr(1); |
| 115 | |
| 116 | BOOST_FIXTURE_TEST_CASE(Status, ForwarderGeneralStatusFixture) |
| 117 | { |
| 118 | this->fetchStatus(); |
| 119 | ForwarderStatus payload; |
| 120 | payload.setNfdVersion("0.4.1-1-g704430c") |
| 121 | .setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(1466781226856))) |
| 122 | .setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(1468778154109))) |
| 123 | .setNNameTreeEntries(668) |
| 124 | .setNFibEntries(70) |
| 125 | .setNPitEntries(7) |
| 126 | .setNMeasurementsEntries(1) |
| 127 | .setNCsEntries(65536) |
| 128 | .setNInInterests(20699052) |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 129 | .setNInData(5598070) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 130 | .setNInNacks(7230) |
| 131 | .setNOutInterests(36501092) |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 132 | .setNOutData(5671942) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 133 | .setNOutNacks(26762); |
| 134 | this->sendDataset("/localhost/nfd/status/general", payload); |
| 135 | this->prepareStatusOutput(); |
| 136 | |
| 137 | BOOST_CHECK(statusXml.is_equal(STATUS_XML)); |
| 138 | BOOST_CHECK(statusText.is_equal(STATUS_TEXT)); |
| 139 | } |
| 140 | |
| 141 | BOOST_AUTO_TEST_CASE(StatusNoNfdId) |
| 142 | { |
| 143 | this->fetchStatus(); |
| 144 | ForwarderStatus payload; |
| 145 | payload.setNfdVersion("0.4.1-1-g704430c"); |
| 146 | this->sendDataset("/localhost/nfd/status/general", payload); |
| 147 | BOOST_CHECK_NO_THROW(this->prepareStatusOutput()); |
| 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_SUITE_END() // TestForwarderGeneralModule |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 151 | BOOST_AUTO_TEST_SUITE_END() // Nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 152 | |
| 153 | } // namespace tests |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 154 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 155 | } // namespace tools |
| 156 | } // namespace nfd |