Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 2 | /** |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [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. |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 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 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 28 | #include "version.hpp" |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 29 | #include "common.hpp" |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 31 | #include <ndn-cxx/face.hpp> |
| 32 | #include <ndn-cxx/name.hpp> |
| 33 | #include <ndn-cxx/interest.hpp> |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/management/nfd-forwarder-status.hpp> |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 37 | #include <ndn-cxx/management/nfd-channel-status.hpp> |
| 38 | #include <ndn-cxx/management/nfd-face-status.hpp> |
| 39 | #include <ndn-cxx/management/nfd-fib-entry.hpp> |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 40 | #include <ndn-cxx/management/nfd-rib-entry.hpp> |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 41 | #include <ndn-cxx/management/nfd-strategy-choice.hpp> |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 42 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 43 | #include <ndn-cxx/security/validator-null.hpp> |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 45 | #include <boost/algorithm/string/replace.hpp> |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 46 | #include <list> |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 47 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 48 | namespace ndn { |
| 49 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 50 | using util::SegmentFetcher; |
| 51 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 52 | /** \brief custom validator for the purpose of obtaining nfdId. |
| 53 | */ |
| 54 | class ForwarderStatusValidator : public Validator |
| 55 | { |
| 56 | protected: |
| 57 | virtual void |
| 58 | checkPolicy(const Data& data, |
| 59 | int nSteps, |
| 60 | const OnDataValidated& onValidated, |
| 61 | const OnDataValidationFailed& onValidationFailed, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 62 | std::vector<shared_ptr<ValidationRequest>>& nextSteps) override |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 63 | { |
| 64 | const ndn::KeyLocator& locator = data.getSignature().getKeyLocator(); |
| 65 | if (nfdId.empty() && locator.getType() == KeyLocator::KeyLocator_Name) |
| 66 | nfdId = locator.getName(); |
| 67 | onValidated(data.shared_from_this()); |
| 68 | } |
| 69 | |
| 70 | virtual void |
| 71 | checkPolicy(const Interest& interest, |
| 72 | int nSteps, |
| 73 | const OnInterestValidated& onValidated, |
| 74 | const OnInterestValidationFailed& onValidationFailed, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 75 | std::vector<shared_ptr<ValidationRequest>>& nextSteps) override |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 76 | { |
| 77 | BOOST_ASSERT(false); |
| 78 | } |
| 79 | |
| 80 | public: |
| 81 | Name nfdId; |
| 82 | }; |
| 83 | |
| 84 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 85 | class NfdStatus |
| 86 | { |
| 87 | public: |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 88 | explicit |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 89 | NfdStatus(char* toolName) |
| 90 | : m_toolName(toolName) |
| 91 | , m_needVersionRetrieval(false) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 92 | , m_needChannelStatusRetrieval(false) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 93 | , m_needFaceStatusRetrieval(false) |
| 94 | , m_needFibEnumerationRetrieval(false) |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 95 | , m_needRibStatusRetrieval(false) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 96 | , m_needStrategyChoiceRetrieval(false) |
| 97 | , m_isOutputXml(false) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 98 | { |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | usage() |
| 103 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 104 | std::cout << "Usage: \n " << m_toolName << " [options]\n\n" |
| 105 | "Show NFD version and status information\n\n" |
| 106 | "Options:\n" |
| 107 | " [-h] - print this help message\n" |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 108 | " [-v] - retrieve version information\n" |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 109 | " [-c] - retrieve channel status information\n" |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 110 | " [-f] - retrieve face status information\n" |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 111 | " [-b] - retrieve FIB information\n" |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 112 | " [-r] - retrieve RIB information\n" |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 113 | " [-s] - retrieve configured strategy choice for NDN namespaces\n" |
Chengyu Fan | ee92fc7 | 2014-06-21 14:58:19 -0600 | [diff] [blame] | 114 | " [-x] - output NFD status information in XML format\n" |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 115 | "\n" |
| 116 | " [-V] - show version information of nfd-status and exit\n" |
| 117 | "\n" |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 118 | "If no options are provided, all information is retrieved.\n" |
Chengyu Fan | ee92fc7 | 2014-06-21 14:58:19 -0600 | [diff] [blame] | 119 | "If -x is provided, other options(-v, -c, etc.) are ignored, and all information is printed in XML format.\n" |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 120 | ; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void |
| 124 | enableVersionRetrieval() |
| 125 | { |
| 126 | m_needVersionRetrieval = true; |
| 127 | } |
| 128 | |
| 129 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 130 | enableChannelStatusRetrieval() |
| 131 | { |
| 132 | m_needChannelStatusRetrieval = true; |
| 133 | } |
| 134 | |
| 135 | void |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 136 | enableFaceStatusRetrieval() |
| 137 | { |
| 138 | m_needFaceStatusRetrieval = true; |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | enableFibEnumerationRetrieval() |
| 143 | { |
| 144 | m_needFibEnumerationRetrieval = true; |
| 145 | } |
| 146 | |
| 147 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 148 | enableStrategyChoiceRetrieval() |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 149 | { |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 150 | m_needStrategyChoiceRetrieval = true; |
| 151 | } |
| 152 | |
| 153 | void |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 154 | enableRibStatusRetrieval() |
| 155 | { |
| 156 | m_needRibStatusRetrieval = true; |
| 157 | } |
| 158 | |
| 159 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 160 | enableXmlOutput() |
| 161 | { |
| 162 | m_isOutputXml = true; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 166 | onTimeout() |
| 167 | { |
| 168 | std::cerr << "Request timed out" << std::endl; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 169 | |
| 170 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 173 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 174 | void |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 175 | onFetchError(uint32_t errorCode, const std::string& errorMsg) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 176 | { |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 177 | std::cerr << "Error code:" << errorCode << ", message:" << errorMsg << std::endl; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 178 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 179 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 182 | void |
| 183 | escapeSpecialCharacters(std::string *data) |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 184 | { |
| 185 | using boost::algorithm::replace_all; |
| 186 | replace_all(*data, "&", "&"); |
| 187 | replace_all(*data, "\"", """); |
| 188 | replace_all(*data, "\'", "'"); |
| 189 | replace_all(*data, "<", "<"); |
| 190 | replace_all(*data, ">", ">"); |
| 191 | } |
| 192 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 193 | ////////////////////////////////////////////////////////////////////////////////// |
| 194 | ////////////////////////////////////////////////////////////////////////////////// |
| 195 | |
| 196 | void |
| 197 | fetchVersionInformation() |
| 198 | { |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 199 | Interest interest("/localhost/nfd/status/general"); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 200 | interest.setChildSelector(1); |
| 201 | interest.setMustBeFresh(true); |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 202 | SegmentFetcher::fetch(m_face, interest, |
| 203 | m_forwarderStatusValidator, |
| 204 | bind(&NfdStatus::afterFetchedVersionInformation, this, _1), |
| 205 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 206 | } |
| 207 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 208 | void |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 209 | afterFetchedVersionInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 210 | { |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 211 | Block block(tlv::Content, dataset); |
| 212 | nfd::ForwarderStatus status(block); |
Chengyu Fan | 8a53caf | 2014-08-01 14:08:37 -0600 | [diff] [blame] | 213 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 214 | if (m_isOutputXml) { |
| 215 | std::cout << "<generalStatus>"; |
| 216 | std::cout << "<nfdId>" |
| 217 | << m_forwarderStatusValidator.nfdId << "</nfdId>"; |
| 218 | std::cout << "<version>" |
| 219 | << status.getNfdVersion() << "</version>"; |
| 220 | std::cout << "<startTime>" |
| 221 | << time::toString(status.getStartTimestamp(), "%Y-%m-%dT%H:%M:%S%F") |
| 222 | << "</startTime>"; |
| 223 | std::cout << "<currentTime>" |
| 224 | << time::toString(status.getCurrentTimestamp(), "%Y-%m-%dT%H:%M:%S%F") |
| 225 | << "</currentTime>"; |
| 226 | std::cout << "<uptime>PT" |
| 227 | << time::duration_cast<time::seconds>(status.getCurrentTimestamp() - |
| 228 | status.getStartTimestamp()).count() |
| 229 | << "S</uptime>"; |
| 230 | std::cout << "<nNameTreeEntries>" << status.getNNameTreeEntries() |
| 231 | << "</nNameTreeEntries>"; |
| 232 | std::cout << "<nFibEntries>" << status.getNFibEntries() |
| 233 | << "</nFibEntries>"; |
| 234 | std::cout << "<nPitEntries>" << status.getNPitEntries() |
| 235 | << "</nPitEntries>"; |
| 236 | std::cout << "<nMeasurementsEntries>" << status.getNMeasurementsEntries() |
| 237 | << "</nMeasurementsEntries>"; |
| 238 | std::cout << "<nCsEntries>" << status.getNCsEntries() |
| 239 | << "</nCsEntries>"; |
| 240 | std::cout << "<packetCounters>"; |
| 241 | std::cout << "<incomingPackets>"; |
| 242 | std::cout << "<nInterests>" << status.getNInInterests() |
| 243 | << "</nInterests>"; |
| 244 | std::cout << "<nDatas>" << status.getNInDatas() |
| 245 | << "</nDatas>"; |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 246 | std::cout << "<nNacks>" << status.getNInNacks() |
| 247 | << "</nNacks>"; |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 248 | std::cout << "</incomingPackets>"; |
| 249 | std::cout << "<outgoingPackets>"; |
| 250 | std::cout << "<nInterests>" << status.getNOutInterests() |
| 251 | << "</nInterests>"; |
| 252 | std::cout << "<nDatas>" << status.getNOutDatas() |
| 253 | << "</nDatas>"; |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 254 | std::cout << "<nNacks>" << status.getNOutNacks() |
| 255 | << "</nNacks>"; |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 256 | std::cout << "</outgoingPackets>"; |
| 257 | std::cout << "</packetCounters>"; |
| 258 | std::cout << "</generalStatus>"; |
| 259 | } |
| 260 | else { |
| 261 | std::cout << "General NFD status:" << std::endl; |
| 262 | std::cout << " nfdId=" |
| 263 | << m_forwarderStatusValidator.nfdId << std::endl; |
| 264 | std::cout << " version=" |
| 265 | << status.getNfdVersion() << std::endl; |
| 266 | std::cout << " startTime=" |
| 267 | << time::toIsoString(status.getStartTimestamp()) << std::endl; |
| 268 | std::cout << " currentTime=" |
| 269 | << time::toIsoString(status.getCurrentTimestamp()) << std::endl; |
| 270 | std::cout << " uptime=" |
| 271 | << time::duration_cast<time::seconds>(status.getCurrentTimestamp() - |
| 272 | status.getStartTimestamp()) << std::endl; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 273 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 274 | std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl; |
| 275 | std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl; |
| 276 | std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl; |
| 277 | std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl; |
| 278 | std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl; |
| 279 | std::cout << " nInInterests=" << status.getNInInterests() << std::endl; |
| 280 | std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl; |
| 281 | std::cout << " nInDatas=" << status.getNInDatas() << std::endl; |
| 282 | std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl; |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 283 | std::cout << " nInNacks=" << status.getNInNacks() << std::endl; |
| 284 | std::cout << " nOutNacks=" << status.getNOutNacks() << std::endl; |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 285 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 286 | |
| 287 | runNextStep(); |
| 288 | } |
| 289 | |
| 290 | ////////////////////////////////////////////////////////////////////////////////// |
| 291 | ////////////////////////////////////////////////////////////////////////////////// |
| 292 | |
| 293 | void |
| 294 | fetchChannelStatusInformation() |
| 295 | { |
| 296 | m_buffer = make_shared<OBufferStream>(); |
| 297 | |
| 298 | Interest interest("/localhost/nfd/faces/channels"); |
| 299 | interest.setChildSelector(1); |
| 300 | interest.setMustBeFresh(true); |
| 301 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 302 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 303 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 304 | bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 305 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 309 | afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 310 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 311 | if (m_isOutputXml) { |
| 312 | std::cout << "<channels>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 313 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 314 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 315 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 316 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 317 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 318 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 319 | if (!isOk) { |
| 320 | std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl; |
| 321 | break; |
| 322 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 323 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 324 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 325 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 326 | nfd::ChannelStatus channelStatus(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 327 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 328 | std::cout << "<channel>"; |
| 329 | std::string localUri(channelStatus.getLocalUri()); |
| 330 | escapeSpecialCharacters(&localUri); |
| 331 | std::cout << "<localUri>" << localUri << "</localUri>"; |
| 332 | std::cout << "</channel>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 333 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 334 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 335 | std::cout << "</channels>"; |
| 336 | } |
| 337 | else { |
| 338 | std::cout << "Channels:" << std::endl; |
| 339 | |
| 340 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 341 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 342 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 343 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 344 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 345 | if (!isOk) { |
| 346 | std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl; |
| 347 | break; |
| 348 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 349 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 350 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 351 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 352 | nfd::ChannelStatus channelStatus(block); |
| 353 | std::cout << " " << channelStatus.getLocalUri() << std::endl; |
| 354 | } |
| 355 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 356 | |
| 357 | runNextStep(); |
| 358 | } |
| 359 | |
| 360 | ////////////////////////////////////////////////////////////////////////////////// |
| 361 | ////////////////////////////////////////////////////////////////////////////////// |
| 362 | |
| 363 | void |
| 364 | fetchFaceStatusInformation() |
| 365 | { |
| 366 | m_buffer = make_shared<OBufferStream>(); |
| 367 | |
| 368 | Interest interest("/localhost/nfd/faces/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 369 | interest.setChildSelector(1); |
| 370 | interest.setMustBeFresh(true); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 371 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 372 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 373 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 374 | bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 375 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 379 | afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 380 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 381 | if (m_isOutputXml) { |
| 382 | std::cout << "<faces>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 383 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 384 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 385 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 386 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 387 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 388 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 389 | if (!isOk) { |
| 390 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 391 | break; |
| 392 | } |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 393 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 394 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 395 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 396 | nfd::FaceStatus faceStatus(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 397 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 398 | std::cout << "<face>"; |
| 399 | std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 400 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 401 | std::string remoteUri(faceStatus.getRemoteUri()); |
| 402 | escapeSpecialCharacters(&remoteUri); |
| 403 | std::cout << "<remoteUri>" << remoteUri << "</remoteUri>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 404 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 405 | std::string localUri(faceStatus.getLocalUri()); |
| 406 | escapeSpecialCharacters(&localUri); |
| 407 | std::cout << "<localUri>" << localUri << "</localUri>"; |
Alexander Afanasyev | 40c61f7 | 2014-06-30 17:21:01 -0700 | [diff] [blame] | 408 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 409 | if (faceStatus.hasExpirationPeriod()) { |
| 410 | std::cout << "<expirationPeriod>PT" |
| 411 | << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod()) |
| 412 | .count() << "S" |
| 413 | << "</expirationPeriod>"; |
| 414 | } |
Alexander Afanasyev | 40c61f7 | 2014-06-30 17:21:01 -0700 | [diff] [blame] | 415 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 416 | std::cout << "<faceScope>" << faceStatus.getFaceScope() |
| 417 | << "</faceScope>"; |
| 418 | std::cout << "<facePersistency>" << faceStatus.getFacePersistency() |
| 419 | << "</facePersistency>"; |
| 420 | std::cout << "<linkType>" << faceStatus.getLinkType() |
| 421 | << "</linkType>"; |
Chengyu Fan | 27d570a | 2014-10-09 11:52:17 -0600 | [diff] [blame] | 422 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 423 | std::cout << "<packetCounters>"; |
| 424 | std::cout << "<incomingPackets>"; |
| 425 | std::cout << "<nInterests>" << faceStatus.getNInInterests() |
| 426 | << "</nInterests>"; |
| 427 | std::cout << "<nDatas>" << faceStatus.getNInDatas() |
| 428 | << "</nDatas>"; |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 429 | std::cout << "<nNacks>" << faceStatus.getNInNacks() |
| 430 | << "</nNacks>"; |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 431 | std::cout << "</incomingPackets>"; |
| 432 | std::cout << "<outgoingPackets>"; |
| 433 | std::cout << "<nInterests>" << faceStatus.getNOutInterests() |
| 434 | << "</nInterests>"; |
| 435 | std::cout << "<nDatas>" << faceStatus.getNOutDatas() |
| 436 | << "</nDatas>"; |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 437 | std::cout << "<nNacks>" << faceStatus.getNOutNacks() |
| 438 | << "</nNacks>"; |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 439 | std::cout << "</outgoingPackets>"; |
| 440 | std::cout << "</packetCounters>"; |
Alexander Afanasyev | d3967a2 | 2014-06-30 12:22:10 -0700 | [diff] [blame] | 441 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 442 | std::cout << "<byteCounters>"; |
| 443 | std::cout << "<incomingBytes>" << faceStatus.getNInBytes() |
| 444 | << "</incomingBytes>"; |
| 445 | std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes() |
| 446 | << "</outgoingBytes>"; |
| 447 | std::cout << "</byteCounters>"; |
Chengyu Fan | 3331cfa | 2014-07-25 17:36:31 -0600 | [diff] [blame] | 448 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 449 | std::cout << "</face>"; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 450 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 451 | std::cout << "</faces>"; |
| 452 | } |
| 453 | else { |
| 454 | std::cout << "Faces:" << std::endl; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 455 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 456 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 457 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 458 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 459 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 460 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 461 | if (!isOk) { |
| 462 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 463 | break; |
| 464 | } |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 465 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 466 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 467 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 468 | nfd::FaceStatus faceStatus(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 469 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 470 | std::cout << " faceid=" << faceStatus.getFaceId() |
| 471 | << " remote=" << faceStatus.getRemoteUri() |
| 472 | << " local=" << faceStatus.getLocalUri(); |
| 473 | if (faceStatus.hasExpirationPeriod()) { |
| 474 | std::cout << " expires=" |
| 475 | << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod()) |
| 476 | .count() << "s"; |
| 477 | } |
| 478 | std::cout << " counters={" |
| 479 | << "in={" << faceStatus.getNInInterests() << "i " |
| 480 | << faceStatus.getNInDatas() << "d " |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 481 | << faceStatus.getNInNacks() << "n " |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 482 | << faceStatus.getNInBytes() << "B}" |
| 483 | << " out={" << faceStatus.getNOutInterests() << "i " |
| 484 | << faceStatus.getNOutDatas() << "d " |
Weiwei Liu | ace83ac | 2016-04-25 10:16:37 -0700 | [diff] [blame] | 485 | << faceStatus.getNOutNacks() << "n " |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 486 | << faceStatus.getNOutBytes() << "B}" |
| 487 | << "}"; |
| 488 | std::cout << " " << faceStatus.getFaceScope() |
| 489 | << " " << faceStatus.getFacePersistency() |
| 490 | << " " << faceStatus.getLinkType(); |
| 491 | std::cout << std::endl; |
| 492 | } |
| 493 | } |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 494 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 495 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 498 | ////////////////////////////////////////////////////////////////////////////////// |
| 499 | ////////////////////////////////////////////////////////////////////////////////// |
| 500 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 501 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 502 | fetchFibEnumerationInformation() |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 503 | { |
| 504 | m_buffer = make_shared<OBufferStream>(); |
| 505 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 506 | Interest interest("/localhost/nfd/fib/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 507 | interest.setChildSelector(1); |
| 508 | interest.setMustBeFresh(true); |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 509 | |
| 510 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 511 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 512 | bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 513 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 517 | afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 518 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 519 | if (m_isOutputXml) { |
| 520 | std::cout << "<fib>"; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 521 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 522 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 523 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 524 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 525 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 526 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 527 | if (!isOk) { |
| 528 | std::cerr << "ERROR: cannot decode FibEntry TLV"; |
| 529 | break; |
| 530 | } |
| 531 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 532 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 533 | nfd::FibEntry fibEntry(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 534 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 535 | std::cout << "<fibEntry>"; |
| 536 | std::string prefix(fibEntry.getPrefix().toUri()); |
| 537 | escapeSpecialCharacters(&prefix); |
| 538 | std::cout << "<prefix>" << prefix << "</prefix>"; |
| 539 | std::cout << "<nextHops>"; |
| 540 | for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) { |
| 541 | std::cout << "<nextHop>" ; |
| 542 | std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>"; |
| 543 | std::cout << "<cost>" << nextHop.getCost() << "</cost>"; |
| 544 | std::cout << "</nextHop>"; |
| 545 | } |
| 546 | std::cout << "</nextHops>"; |
| 547 | std::cout << "</fibEntry>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 548 | } |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 549 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 550 | std::cout << "</fib>"; |
| 551 | } |
| 552 | else { |
| 553 | std::cout << "FIB:" << std::endl; |
| 554 | |
| 555 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 556 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 557 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 558 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 559 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 560 | if (!isOk) { |
| 561 | std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl; |
| 562 | break; |
| 563 | } |
| 564 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 565 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 566 | nfd::FibEntry fibEntry(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 567 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 568 | std::cout << " " << fibEntry.getPrefix() << " nexthops={"; |
| 569 | bool isFirst = true; |
| 570 | for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) { |
| 571 | if (isFirst) |
| 572 | isFirst = false; |
| 573 | else |
| 574 | std::cout << ", "; |
| 575 | |
| 576 | std::cout << "faceid=" << nextHop.getFaceId() |
| 577 | << " (cost=" << nextHop.getCost() << ")"; |
| 578 | } |
| 579 | std::cout << "}" << std::endl; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 580 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 581 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 582 | |
| 583 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 586 | ////////////////////////////////////////////////////////////////////////////////// |
| 587 | ////////////////////////////////////////////////////////////////////////////////// |
| 588 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 589 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 590 | fetchStrategyChoiceInformation() |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 591 | { |
| 592 | m_buffer = make_shared<OBufferStream>(); |
| 593 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 594 | Interest interest("/localhost/nfd/strategy-choice/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 595 | interest.setChildSelector(1); |
| 596 | interest.setMustBeFresh(true); |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 597 | |
| 598 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 599 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 600 | bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 601 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 605 | afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 606 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 607 | if (m_isOutputXml) { |
| 608 | std::cout << "<strategyChoices>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 609 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 610 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 611 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 612 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 613 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 614 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 615 | if (!isOk) { |
| 616 | std::cerr << "ERROR: cannot decode StrategyChoice TLV"; |
| 617 | break; |
| 618 | } |
| 619 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 620 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 621 | nfd::StrategyChoice strategyChoice(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 622 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 623 | std::cout << "<strategyChoice>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 624 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 625 | std::string name(strategyChoice.getName().toUri()); |
| 626 | escapeSpecialCharacters(&name); |
| 627 | std::cout << "<namespace>" << name << "</namespace>"; |
| 628 | std::cout << "<strategy>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 629 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 630 | std::string strategy(strategyChoice.getStrategy().toUri()); |
| 631 | escapeSpecialCharacters(&strategy); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 632 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 633 | std::cout << "<name>" << strategy << "</name>"; |
| 634 | std::cout << "</strategy>"; |
| 635 | std::cout << "</strategyChoice>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 636 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 637 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 638 | std::cout << "</strategyChoices>"; |
| 639 | } |
| 640 | else { |
| 641 | std::cout << "Strategy choices:" << std::endl; |
| 642 | |
| 643 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 644 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 645 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 646 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 647 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 648 | if (!isOk) { |
| 649 | std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl; |
| 650 | break; |
| 651 | } |
| 652 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 653 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 654 | nfd::StrategyChoice strategyChoice(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 655 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 656 | std::cout << " " << strategyChoice.getName() |
| 657 | << " strategy=" << strategyChoice.getStrategy() << std::endl; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 658 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 659 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 660 | |
| 661 | runNextStep(); |
| 662 | } |
| 663 | |
| 664 | void |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 665 | fetchRibStatusInformation() |
| 666 | { |
| 667 | m_buffer = make_shared<OBufferStream>(); |
| 668 | |
| 669 | Interest interest("/localhost/nfd/rib/list"); |
| 670 | interest.setChildSelector(1); |
| 671 | interest.setMustBeFresh(true); |
| 672 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 673 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 674 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 675 | bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 676 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 680 | afterFetchedRibStatusInformation(const ConstBufferPtr& dataset) |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 681 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 682 | if (m_isOutputXml) { |
| 683 | std::cout << "<rib>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 684 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 685 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 686 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 687 | bool isOk = false; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 688 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 689 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 690 | if (!isOk) { |
| 691 | std::cerr << "ERROR: cannot decode RibEntry TLV"; |
| 692 | break; |
| 693 | } |
| 694 | offset += block.size(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 695 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 696 | nfd::RibEntry ribEntry(block); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 697 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 698 | std::cout << "<ribEntry>"; |
| 699 | std::string prefix(ribEntry.getName().toUri()); |
| 700 | escapeSpecialCharacters(&prefix); |
| 701 | std::cout << "<prefix>" << prefix << "</prefix>"; |
| 702 | std::cout << "<routes>"; |
| 703 | for (const nfd::Route& nextRoute : ribEntry) { |
| 704 | std::cout << "<route>" ; |
| 705 | std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>"; |
| 706 | std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>"; |
| 707 | std::cout << "<cost>" << nextRoute.getCost() << "</cost>"; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 708 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 709 | std::cout << "<flags>"; |
| 710 | if (nextRoute.isChildInherit()) |
| 711 | std::cout << "<childInherit/>"; |
| 712 | if (nextRoute.isRibCapture()) |
| 713 | std::cout << "<ribCapture/>"; |
| 714 | std::cout << "</flags>"; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 715 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 716 | if (!nextRoute.hasInfiniteExpirationPeriod()) { |
| 717 | std::cout << "<expirationPeriod>PT" |
| 718 | << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod()) |
| 719 | .count() << "S" |
| 720 | << "</expirationPeriod>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 721 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 722 | std::cout << "</route>"; |
| 723 | } |
| 724 | std::cout << "</routes>"; |
| 725 | std::cout << "</ribEntry>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 726 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 727 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 728 | std::cout << "</rib>"; |
| 729 | } |
| 730 | else { |
| 731 | std::cout << "RIB:" << std::endl; |
| 732 | |
| 733 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 734 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 735 | bool isOk = false; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 736 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 737 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 738 | if (!isOk) { |
| 739 | std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl; |
| 740 | break; |
| 741 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 742 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 743 | offset += block.size(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 744 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 745 | nfd::RibEntry ribEntry(block); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 746 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 747 | std::cout << " " << ribEntry.getName().toUri() << " route={"; |
| 748 | bool isFirst = true; |
| 749 | for (const nfd::Route& nextRoute : ribEntry) { |
| 750 | if (isFirst) |
| 751 | isFirst = false; |
| 752 | else |
| 753 | std::cout << ", "; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 754 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 755 | std::cout << "faceid=" << nextRoute.getFaceId() |
| 756 | << " (origin=" << nextRoute.getOrigin() |
| 757 | << " cost=" << nextRoute.getCost(); |
| 758 | if (!nextRoute.hasInfiniteExpirationPeriod()) { |
| 759 | std::cout << " expires=" |
| 760 | << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod()) |
| 761 | .count() << "s"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 762 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 763 | |
| 764 | if (nextRoute.isChildInherit()) |
| 765 | std::cout << " ChildInherit"; |
| 766 | if (nextRoute.isRibCapture()) |
| 767 | std::cout << " RibCapture"; |
| 768 | |
| 769 | std::cout << ")"; |
| 770 | } |
| 771 | std::cout << "}" << std::endl; |
| 772 | } |
| 773 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 774 | |
| 775 | runNextStep(); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | void |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 780 | fetchInformation() |
| 781 | { |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 782 | if (m_isOutputXml || |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 783 | (!m_needVersionRetrieval && |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 784 | !m_needChannelStatusRetrieval && |
| 785 | !m_needFaceStatusRetrieval && |
| 786 | !m_needFibEnumerationRetrieval && |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 787 | !m_needRibStatusRetrieval && |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 788 | !m_needStrategyChoiceRetrieval)) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 789 | { |
| 790 | enableVersionRetrieval(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 791 | enableChannelStatusRetrieval(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 792 | enableFaceStatusRetrieval(); |
| 793 | enableFibEnumerationRetrieval(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 794 | enableRibStatusRetrieval(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 795 | enableStrategyChoiceRetrieval(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 798 | if (m_isOutputXml) |
| 799 | m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this)); |
| 800 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 801 | if (m_needVersionRetrieval) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 802 | m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 803 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 804 | if (m_needChannelStatusRetrieval) |
| 805 | m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this)); |
| 806 | |
| 807 | if (m_needFaceStatusRetrieval) |
| 808 | m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this)); |
| 809 | |
| 810 | if (m_needFibEnumerationRetrieval) |
| 811 | m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this)); |
| 812 | |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 813 | if (m_needRibStatusRetrieval) |
| 814 | m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this)); |
| 815 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 816 | if (m_needStrategyChoiceRetrieval) |
| 817 | m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this)); |
| 818 | |
| 819 | if (m_isOutputXml) |
| 820 | m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this)); |
| 821 | |
| 822 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 823 | m_face.processEvents(); |
| 824 | } |
| 825 | |
| 826 | private: |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 827 | void |
| 828 | printXmlHeader() |
| 829 | { |
| 830 | std::cout << "<?xml version=\"1.0\"?>"; |
| 831 | std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">"; |
| 832 | |
| 833 | runNextStep(); |
| 834 | } |
| 835 | |
| 836 | void |
| 837 | printXmlFooter() |
| 838 | { |
| 839 | std::cout << "</nfdStatus>"; |
| 840 | |
| 841 | runNextStep(); |
| 842 | } |
| 843 | |
| 844 | void |
| 845 | runNextStep() |
| 846 | { |
| 847 | if (m_fetchSteps.empty()) |
| 848 | return; |
| 849 | |
| 850 | function<void()> nextStep = m_fetchSteps.front(); |
| 851 | m_fetchSteps.pop_front(); |
| 852 | nextStep(); |
| 853 | } |
| 854 | |
| 855 | private: |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 856 | std::string m_toolName; |
| 857 | bool m_needVersionRetrieval; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 858 | bool m_needChannelStatusRetrieval; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 859 | bool m_needFaceStatusRetrieval; |
| 860 | bool m_needFibEnumerationRetrieval; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 861 | bool m_needRibStatusRetrieval; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 862 | bool m_needStrategyChoiceRetrieval; |
| 863 | bool m_isOutputXml; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 864 | Face m_face; |
| 865 | |
| 866 | shared_ptr<OBufferStream> m_buffer; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 867 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 868 | std::deque<function<void()>> m_fetchSteps; |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 869 | |
| 870 | ndn::ValidatorNull m_validator; |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 871 | |
| 872 | ForwarderStatusValidator m_forwarderStatusValidator; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 873 | }; |
| 874 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 875 | } // namespace ndn |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 876 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 877 | int main(int argc, char* argv[]) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 878 | { |
| 879 | int option; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 880 | ndn::NfdStatus nfdStatus(argv[0]); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 881 | |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 882 | while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) { |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 883 | switch (option) { |
| 884 | case 'h': |
| 885 | nfdStatus.usage(); |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 886 | return 0; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 887 | case 'v': |
| 888 | nfdStatus.enableVersionRetrieval(); |
| 889 | break; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 890 | case 'c': |
| 891 | nfdStatus.enableChannelStatusRetrieval(); |
| 892 | break; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 893 | case 'f': |
| 894 | nfdStatus.enableFaceStatusRetrieval(); |
| 895 | break; |
| 896 | case 'b': |
| 897 | nfdStatus.enableFibEnumerationRetrieval(); |
| 898 | break; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 899 | case 'r': |
| 900 | nfdStatus.enableRibStatusRetrieval(); |
| 901 | break; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 902 | case 's': |
| 903 | nfdStatus.enableStrategyChoiceRetrieval(); |
| 904 | break; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 905 | case 'x': |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 906 | nfdStatus.enableXmlOutput(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 907 | break; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 908 | case 'V': |
| 909 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 910 | return 0; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 911 | default: |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 912 | nfdStatus.usage(); |
| 913 | return 1; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
| 917 | try { |
| 918 | nfdStatus.fetchInformation(); |
| 919 | } |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 920 | catch (std::exception& e) { |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 921 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 922 | return 2; |
| 923 | } |
| 924 | |
| 925 | return 0; |
| 926 | } |