From 7a36ac7d9d9ce2fe7836d4864c54bc3ed09a2937 Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Wed, 21 Mar 2018 15:23:22 +0000 Subject: [PATCH] tools: include CS config in 'nfdc cs info' Also, ForwarderGeneralModule::formatItemText now uses ItemAttributes. refs #4050 Change-Id: I1b2bde29b82e4b3910d87b41efd90e273052b18d --- docs/_static/nfd-status.xsd | 4 ++ tests/tools/nfdc/cs-module.t.cpp | 16 ++++++- tests/tools/nfdc/format-helpers.t.cpp | 8 ++++ .../nfd-status.xsl | 16 +++++++ tools/nfdc/cs-module.cpp | 36 ++++++++++++--- tools/nfdc/cs-module.hpp | 6 +++ tools/nfdc/face-module.cpp | 12 ++--- tools/nfdc/format-helpers.cpp | 9 ++++ tools/nfdc/format-helpers.hpp | 11 +++++ tools/nfdc/forwarder-general-module.cpp | 45 +++++++++++-------- tools/nfdc/forwarder-general-module.hpp | 10 ++--- 11 files changed, 131 insertions(+), 42 deletions(-) diff --git a/docs/_static/nfd-status.xsd b/docs/_static/nfd-status.xsd index bd03535f..89d07bb6 100644 --- a/docs/_static/nfd-status.xsd +++ b/docs/_static/nfd-status.xsd @@ -159,6 +159,10 @@ + + + + diff --git a/tests/tools/nfdc/cs-module.t.cpp b/tests/tools/nfdc/cs-module.t.cpp index 7191f7d1..33d846a4 100644 --- a/tests/tools/nfdc/cs-module.t.cpp +++ b/tests/tools/nfdc/cs-module.t.cpp @@ -95,6 +95,9 @@ BOOST_AUTO_TEST_SUITE_END() // ConfigCommand const std::string STATUS_XML = stripXmlSpaces(R"XML( + 31807 + + 16131 14363 27462 @@ -102,14 +105,23 @@ const std::string STATUS_XML = stripXmlSpaces(R"XML( const std::string STATUS_TEXT = std::string(R"TEXT( CS information: - nHits=14363 nMisses=27462 + capacity=31807 + admit=on + serve=off + nEntries=16131 + nHits=14363 + nMisses=27462 )TEXT").substr(1); BOOST_FIXTURE_TEST_CASE(Status, StatusFixture) { this->fetchStatus(); CsInfo payload; - payload.setNHits(14363) + payload.setCapacity(31807) + .setEnableAdmit(true) + .setEnableServe(false) + .setNEntries(16131) + .setNHits(14363) .setNMisses(27462); this->sendDataset("/localhost/nfd/cs/info", payload); this->prepareStatusOutput(); diff --git a/tests/tools/nfdc/format-helpers.t.cpp b/tests/tools/nfdc/format-helpers.t.cpp index 5de002bc..d5719ae5 100644 --- a/tests/tools/nfdc/format-helpers.t.cpp +++ b/tests/tools/nfdc/format-helpers.t.cpp @@ -48,6 +48,14 @@ BOOST_AUTO_TEST_CASE(TextEscaping) " surround XML <element> tag name")); } +BOOST_AUTO_TEST_CASE(Flag) +{ + output_test_stream os; + os << "" << xml::Flag{"B", true} << "" << xml::Flag{"D", false} << ""; + + BOOST_CHECK(os.is_equal("")); +} + BOOST_AUTO_TEST_CASE(DurationFormatting) { time::nanoseconds d1 = 53000_s + 87_ms + 3_us; diff --git a/tools/nfd-status-http-server-files/nfd-status.xsl b/tools/nfd-status-http-server-files/nfd-status.xsl index ada37d0f..725e53e8 100644 --- a/tools/nfd-status-http-server-files/nfd-status.xsl +++ b/tools/nfd-status-http-server-files/nfd-status.xsl @@ -327,12 +327,28 @@ + + + + + + diff --git a/tools/nfdc/cs-module.cpp b/tools/nfdc/cs-module.cpp index 9d288556..d42b82e5 100644 --- a/tools/nfdc/cs-module.cpp +++ b/tools/nfdc/cs-module.cpp @@ -26,6 +26,8 @@ #include "cs-module.hpp" #include "format-helpers.hpp" +#include + namespace nfd { namespace tools { namespace nfdc { @@ -93,22 +95,42 @@ CsModule::fetchStatus(Controller& controller, void CsModule::formatStatusXml(std::ostream& os) const +{ + formatItemXml(os, m_status); +} + +void +CsModule::formatItemXml(std::ostream& os, const CsInfo& item) { os << ""; - os << "" << m_status.getNHits() << ""; - os << "" << m_status.getNMisses() << ""; + os << "" << item.getCapacity() << ""; + os << xml::Flag{"admitEnabled", item.getEnableAdmit()}; + os << xml::Flag{"serveEnabled", item.getEnableServe()}; + os << "" << item.getNEntries() << ""; + os << "" << item.getNHits() << ""; + os << "" << item.getNMisses() << ""; os << ""; } void CsModule::formatStatusText(std::ostream& os) const { - os << "CS information:\n "; - text::ItemAttributes ia; - os << ia("nHits") << m_status.getNHits() - << ia("nMisses") << m_status.getNMisses() + os << "CS information:\n"; + ndn::util::IndentedStream indented(os, " "); + formatItemText(indented, m_status); +} + +void +CsModule::formatItemText(std::ostream& os, const CsInfo& item) +{ + text::ItemAttributes ia(true, 8); + os << ia("capacity") << item.getCapacity() + << ia("admit") << text::OnOff{item.getEnableAdmit()} + << ia("serve") << text::OnOff{item.getEnableServe()} + << ia("nEntries") << item.getNEntries() + << ia("nHits") << item.getNHits() + << ia("nMisses") << item.getNMisses() << ia.end(); - os << '\n'; } } // namespace nfdc diff --git a/tools/nfdc/cs-module.hpp b/tools/nfdc/cs-module.hpp index 7634d3d9..320ce095 100644 --- a/tools/nfdc/cs-module.hpp +++ b/tools/nfdc/cs-module.hpp @@ -60,9 +60,15 @@ public: void formatStatusXml(std::ostream& os) const override; + static void + formatItemXml(std::ostream& os, const CsInfo& item); + void formatStatusText(std::ostream& os) const override; + static void + formatItemText(std::ostream& os, const CsInfo& item); + private: CsInfo m_status; }; diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp index 85673a80..888a7b34 100644 --- a/tools/nfdc/face-module.cpp +++ b/tools/nfdc/face-module.cpp @@ -405,15 +405,9 @@ FaceModule::formatItemXml(std::ostream& os, const FaceStatus& item) const } else { os << ""; - if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) { - os << ""; - } - if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) { - os << ""; - } - if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) { - os << ""; - } + os << xml::Flag{"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)}; + os << xml::Flag{"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}; + os << xml::Flag{"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)}; os << ""; } diff --git a/tools/nfdc/format-helpers.cpp b/tools/nfdc/format-helpers.cpp index a329102d..d898dc3c 100644 --- a/tools/nfdc/format-helpers.cpp +++ b/tools/nfdc/format-helpers.cpp @@ -75,6 +75,15 @@ operator<<(std::ostream& os, const Text& text) return os; } +std::ostream& +operator<<(std::ostream& os, Flag v) +{ + if (!v.flag) { + return os; + } + return os << '<' << v.elementName << "/>"; +} + std::string formatDuration(time::nanoseconds d) { diff --git a/tools/nfdc/format-helpers.hpp b/tools/nfdc/format-helpers.hpp index 0d131f16..957773b9 100644 --- a/tools/nfdc/format-helpers.hpp +++ b/tools/nfdc/format-helpers.hpp @@ -50,6 +50,17 @@ struct Text std::ostream& operator<<(std::ostream& os, const Text& text); +/** \brief print true as an empty element and false as nothing + */ +struct Flag +{ + const char* elementName; + bool flag; +}; + +std::ostream& +operator<<(std::ostream& os, Flag v); + /** \return duration in XML duration format * * Definition of this format: https://www.w3.org/TR/xmlschema11-2/#duration diff --git a/tools/nfdc/forwarder-general-module.cpp b/tools/nfdc/forwarder-general-module.cpp index 4a85cddd..67093ec8 100644 --- a/tools/nfdc/forwarder-general-module.cpp +++ b/tools/nfdc/forwarder-general-module.cpp @@ -26,6 +26,8 @@ #include "forwarder-general-module.hpp" #include "format-helpers.hpp" +#include + namespace nfd { namespace tools { namespace nfdc { @@ -53,11 +55,11 @@ calculateUptime(const ForwarderStatus& status) void ForwarderGeneralModule::formatStatusXml(std::ostream& os) const { - this->formatItemXml(os, m_status); + formatItemXml(os, m_status); } void -ForwarderGeneralModule::formatItemXml(std::ostream& os, const ForwarderStatus& item) const +ForwarderGeneralModule::formatItemXml(std::ostream& os, const ForwarderStatus& item) { os << ""; @@ -93,29 +95,34 @@ void ForwarderGeneralModule::formatStatusText(std::ostream& os) const { os << "General NFD status:\n"; - this->formatItemText(os, m_status); + ndn::util::IndentedStream indented(os, " "); + formatItemText(indented, m_status); } void -ForwarderGeneralModule::formatItemText(std::ostream& os, const ForwarderStatus& item) const +ForwarderGeneralModule::formatItemText(std::ostream& os, const ForwarderStatus& item) { - os << " version=" << item.getNfdVersion() << "\n"; - os << " startTime=" << text::formatTimestamp(item.getStartTimestamp()) << "\n"; - os << " currentTime=" << text::formatTimestamp(item.getCurrentTimestamp()) << "\n"; - os << " uptime=" << text::formatDuration(calculateUptime(item), true) << "\n"; + text::ItemAttributes ia(true, 20); - os << " nNameTreeEntries=" << item.getNNameTreeEntries() << "\n"; - os << " nFibEntries=" << item.getNFibEntries() << "\n"; - os << " nPitEntries=" << item.getNPitEntries() << "\n"; - os << " nMeasurementsEntries=" << item.getNMeasurementsEntries() << "\n"; - os << " nCsEntries=" << item.getNCsEntries() << "\n"; + os << ia("version") << item.getNfdVersion() + << ia("startTime") << text::formatTimestamp(item.getStartTimestamp()) + << ia("currentTime") << text::formatTimestamp(item.getCurrentTimestamp()) + << ia("uptime") << text::formatDuration(calculateUptime(item), true); - os << " nInInterests=" << item.getNInInterests() << "\n"; - os << " nOutInterests=" << item.getNOutInterests() << "\n"; - os << " nInData=" << item.getNInData() << "\n"; - os << " nOutData=" << item.getNOutData() << "\n"; - os << " nInNacks=" << item.getNInNacks() << "\n"; - os << " nOutNacks=" << item.getNOutNacks() << "\n"; + os << ia("nNameTreeEntries") << item.getNNameTreeEntries() + << ia("nFibEntries") << item.getNFibEntries() + << ia("nPitEntries") << item.getNPitEntries() + << ia("nMeasurementsEntries") << item.getNMeasurementsEntries() + << ia("nCsEntries") << item.getNCsEntries(); + + os << ia("nInInterests") << item.getNInInterests() + << ia("nOutInterests") << item.getNOutInterests() + << ia("nInData") << item.getNInData() + << ia("nOutData") << item.getNOutData() + << ia("nInNacks") << item.getNInNacks() + << ia("nOutNacks") << item.getNOutNacks(); + + os << ia.end(); } } // namespace nfdc diff --git a/tools/nfdc/forwarder-general-module.hpp b/tools/nfdc/forwarder-general-module.hpp index 4d65c83a..4619cfa2 100644 --- a/tools/nfdc/forwarder-general-module.hpp +++ b/tools/nfdc/forwarder-general-module.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2017, Regents of the University of California, + * Copyright (c) 2014-2018, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -53,8 +53,8 @@ public: * \param os output stream * \param item status item */ - void - formatItemXml(std::ostream& os, const ForwarderStatus& item) const; + static void + formatItemXml(std::ostream& os, const ForwarderStatus& item); void formatStatusText(std::ostream& os) const override; @@ -63,8 +63,8 @@ public: * \param os output stream * \param item status item */ - void - formatItemText(std::ostream& os, const ForwarderStatus& item) const; + static void + formatItemText(std::ostream& os, const ForwarderStatus& item); private: ForwarderStatus m_status;
Enablement FlagsCapacityEntries Hits Misses
+ + admit + no-admit + + , + + serve + no-serve + +