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, |
| 62 | std::vector<shared_ptr<ValidationRequest>>& nextSteps) DECL_OVERRIDE |
| 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, |
| 75 | std::vector<shared_ptr<ValidationRequest>>& nextSteps) DECL_OVERRIDE |
| 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>"; |
| 246 | std::cout << "</incomingPackets>"; |
| 247 | std::cout << "<outgoingPackets>"; |
| 248 | std::cout << "<nInterests>" << status.getNOutInterests() |
| 249 | << "</nInterests>"; |
| 250 | std::cout << "<nDatas>" << status.getNOutDatas() |
| 251 | << "</nDatas>"; |
| 252 | std::cout << "</outgoingPackets>"; |
| 253 | std::cout << "</packetCounters>"; |
| 254 | std::cout << "</generalStatus>"; |
| 255 | } |
| 256 | else { |
| 257 | std::cout << "General NFD status:" << std::endl; |
| 258 | std::cout << " nfdId=" |
| 259 | << m_forwarderStatusValidator.nfdId << std::endl; |
| 260 | std::cout << " version=" |
| 261 | << status.getNfdVersion() << std::endl; |
| 262 | std::cout << " startTime=" |
| 263 | << time::toIsoString(status.getStartTimestamp()) << std::endl; |
| 264 | std::cout << " currentTime=" |
| 265 | << time::toIsoString(status.getCurrentTimestamp()) << std::endl; |
| 266 | std::cout << " uptime=" |
| 267 | << time::duration_cast<time::seconds>(status.getCurrentTimestamp() - |
| 268 | status.getStartTimestamp()) << std::endl; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 269 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 270 | std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl; |
| 271 | std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl; |
| 272 | std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl; |
| 273 | std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl; |
| 274 | std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl; |
| 275 | std::cout << " nInInterests=" << status.getNInInterests() << std::endl; |
| 276 | std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl; |
| 277 | std::cout << " nInDatas=" << status.getNInDatas() << std::endl; |
| 278 | std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl; |
| 279 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 280 | |
| 281 | runNextStep(); |
| 282 | } |
| 283 | |
| 284 | ////////////////////////////////////////////////////////////////////////////////// |
| 285 | ////////////////////////////////////////////////////////////////////////////////// |
| 286 | |
| 287 | void |
| 288 | fetchChannelStatusInformation() |
| 289 | { |
| 290 | m_buffer = make_shared<OBufferStream>(); |
| 291 | |
| 292 | Interest interest("/localhost/nfd/faces/channels"); |
| 293 | interest.setChildSelector(1); |
| 294 | interest.setMustBeFresh(true); |
| 295 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 296 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 297 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 298 | bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 299 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 303 | afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 304 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 305 | if (m_isOutputXml) { |
| 306 | std::cout << "<channels>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 307 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 308 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 309 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 310 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 311 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 312 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 313 | if (!isOk) { |
| 314 | std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl; |
| 315 | break; |
| 316 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 317 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 318 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 319 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 320 | nfd::ChannelStatus channelStatus(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 321 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 322 | std::cout << "<channel>"; |
| 323 | std::string localUri(channelStatus.getLocalUri()); |
| 324 | escapeSpecialCharacters(&localUri); |
| 325 | std::cout << "<localUri>" << localUri << "</localUri>"; |
| 326 | std::cout << "</channel>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 327 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 328 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 329 | std::cout << "</channels>"; |
| 330 | } |
| 331 | else { |
| 332 | std::cout << "Channels:" << std::endl; |
| 333 | |
| 334 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 335 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 336 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 337 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 338 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 339 | if (!isOk) { |
| 340 | std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl; |
| 341 | break; |
| 342 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 343 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 344 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 345 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 346 | nfd::ChannelStatus channelStatus(block); |
| 347 | std::cout << " " << channelStatus.getLocalUri() << std::endl; |
| 348 | } |
| 349 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 350 | |
| 351 | runNextStep(); |
| 352 | } |
| 353 | |
| 354 | ////////////////////////////////////////////////////////////////////////////////// |
| 355 | ////////////////////////////////////////////////////////////////////////////////// |
| 356 | |
| 357 | void |
| 358 | fetchFaceStatusInformation() |
| 359 | { |
| 360 | m_buffer = make_shared<OBufferStream>(); |
| 361 | |
| 362 | Interest interest("/localhost/nfd/faces/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 363 | interest.setChildSelector(1); |
| 364 | interest.setMustBeFresh(true); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 365 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 366 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 367 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 368 | bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 369 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 373 | afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 374 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 375 | if (m_isOutputXml) { |
| 376 | std::cout << "<faces>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 377 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 378 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 379 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 380 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 381 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 382 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 383 | if (!isOk) { |
| 384 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 385 | break; |
| 386 | } |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 387 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 388 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 389 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 390 | nfd::FaceStatus faceStatus(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 391 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 392 | std::cout << "<face>"; |
| 393 | std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 394 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 395 | std::string remoteUri(faceStatus.getRemoteUri()); |
| 396 | escapeSpecialCharacters(&remoteUri); |
| 397 | std::cout << "<remoteUri>" << remoteUri << "</remoteUri>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 398 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 399 | std::string localUri(faceStatus.getLocalUri()); |
| 400 | escapeSpecialCharacters(&localUri); |
| 401 | std::cout << "<localUri>" << localUri << "</localUri>"; |
Alexander Afanasyev | 40c61f7 | 2014-06-30 17:21:01 -0700 | [diff] [blame] | 402 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 403 | if (faceStatus.hasExpirationPeriod()) { |
| 404 | std::cout << "<expirationPeriod>PT" |
| 405 | << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod()) |
| 406 | .count() << "S" |
| 407 | << "</expirationPeriod>"; |
| 408 | } |
Alexander Afanasyev | 40c61f7 | 2014-06-30 17:21:01 -0700 | [diff] [blame] | 409 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 410 | std::cout << "<faceScope>" << faceStatus.getFaceScope() |
| 411 | << "</faceScope>"; |
| 412 | std::cout << "<facePersistency>" << faceStatus.getFacePersistency() |
| 413 | << "</facePersistency>"; |
| 414 | std::cout << "<linkType>" << faceStatus.getLinkType() |
| 415 | << "</linkType>"; |
Chengyu Fan | 27d570a | 2014-10-09 11:52:17 -0600 | [diff] [blame] | 416 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 417 | std::cout << "<packetCounters>"; |
| 418 | std::cout << "<incomingPackets>"; |
| 419 | std::cout << "<nInterests>" << faceStatus.getNInInterests() |
| 420 | << "</nInterests>"; |
| 421 | std::cout << "<nDatas>" << faceStatus.getNInDatas() |
| 422 | << "</nDatas>"; |
| 423 | std::cout << "</incomingPackets>"; |
| 424 | std::cout << "<outgoingPackets>"; |
| 425 | std::cout << "<nInterests>" << faceStatus.getNOutInterests() |
| 426 | << "</nInterests>"; |
| 427 | std::cout << "<nDatas>" << faceStatus.getNOutDatas() |
| 428 | << "</nDatas>"; |
| 429 | std::cout << "</outgoingPackets>"; |
| 430 | std::cout << "</packetCounters>"; |
Alexander Afanasyev | d3967a2 | 2014-06-30 12:22:10 -0700 | [diff] [blame] | 431 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 432 | std::cout << "<byteCounters>"; |
| 433 | std::cout << "<incomingBytes>" << faceStatus.getNInBytes() |
| 434 | << "</incomingBytes>"; |
| 435 | std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes() |
| 436 | << "</outgoingBytes>"; |
| 437 | std::cout << "</byteCounters>"; |
Chengyu Fan | 3331cfa | 2014-07-25 17:36:31 -0600 | [diff] [blame] | 438 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 439 | std::cout << "</face>"; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 440 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 441 | std::cout << "</faces>"; |
| 442 | } |
| 443 | else { |
| 444 | std::cout << "Faces:" << std::endl; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 445 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 446 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 447 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 448 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 449 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 450 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 451 | if (!isOk) { |
| 452 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 453 | break; |
| 454 | } |
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 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 457 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 458 | nfd::FaceStatus faceStatus(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 459 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 460 | std::cout << " faceid=" << faceStatus.getFaceId() |
| 461 | << " remote=" << faceStatus.getRemoteUri() |
| 462 | << " local=" << faceStatus.getLocalUri(); |
| 463 | if (faceStatus.hasExpirationPeriod()) { |
| 464 | std::cout << " expires=" |
| 465 | << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod()) |
| 466 | .count() << "s"; |
| 467 | } |
| 468 | std::cout << " counters={" |
| 469 | << "in={" << faceStatus.getNInInterests() << "i " |
| 470 | << faceStatus.getNInDatas() << "d " |
| 471 | << faceStatus.getNInBytes() << "B}" |
| 472 | << " out={" << faceStatus.getNOutInterests() << "i " |
| 473 | << faceStatus.getNOutDatas() << "d " |
| 474 | << faceStatus.getNOutBytes() << "B}" |
| 475 | << "}"; |
| 476 | std::cout << " " << faceStatus.getFaceScope() |
| 477 | << " " << faceStatus.getFacePersistency() |
| 478 | << " " << faceStatus.getLinkType(); |
| 479 | std::cout << std::endl; |
| 480 | } |
| 481 | } |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 482 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 483 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 486 | ////////////////////////////////////////////////////////////////////////////////// |
| 487 | ////////////////////////////////////////////////////////////////////////////////// |
| 488 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 489 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 490 | fetchFibEnumerationInformation() |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 491 | { |
| 492 | m_buffer = make_shared<OBufferStream>(); |
| 493 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 494 | Interest interest("/localhost/nfd/fib/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 495 | interest.setChildSelector(1); |
| 496 | interest.setMustBeFresh(true); |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 497 | |
| 498 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 499 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 500 | bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 501 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 505 | afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 506 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 507 | if (m_isOutputXml) { |
| 508 | std::cout << "<fib>"; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 509 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 510 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 511 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 512 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 513 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 514 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 515 | if (!isOk) { |
| 516 | std::cerr << "ERROR: cannot decode FibEntry TLV"; |
| 517 | break; |
| 518 | } |
| 519 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 520 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 521 | nfd::FibEntry fibEntry(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 522 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 523 | std::cout << "<fibEntry>"; |
| 524 | std::string prefix(fibEntry.getPrefix().toUri()); |
| 525 | escapeSpecialCharacters(&prefix); |
| 526 | std::cout << "<prefix>" << prefix << "</prefix>"; |
| 527 | std::cout << "<nextHops>"; |
| 528 | for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) { |
| 529 | std::cout << "<nextHop>" ; |
| 530 | std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>"; |
| 531 | std::cout << "<cost>" << nextHop.getCost() << "</cost>"; |
| 532 | std::cout << "</nextHop>"; |
| 533 | } |
| 534 | std::cout << "</nextHops>"; |
| 535 | std::cout << "</fibEntry>"; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 536 | } |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 537 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 538 | std::cout << "</fib>"; |
| 539 | } |
| 540 | else { |
| 541 | std::cout << "FIB:" << std::endl; |
| 542 | |
| 543 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 544 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 545 | bool isOk = false; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 546 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 547 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 548 | if (!isOk) { |
| 549 | std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl; |
| 550 | break; |
| 551 | } |
| 552 | offset += block.size(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 553 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 554 | nfd::FibEntry fibEntry(block); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 555 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 556 | std::cout << " " << fibEntry.getPrefix() << " nexthops={"; |
| 557 | bool isFirst = true; |
| 558 | for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) { |
| 559 | if (isFirst) |
| 560 | isFirst = false; |
| 561 | else |
| 562 | std::cout << ", "; |
| 563 | |
| 564 | std::cout << "faceid=" << nextHop.getFaceId() |
| 565 | << " (cost=" << nextHop.getCost() << ")"; |
| 566 | } |
| 567 | std::cout << "}" << std::endl; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 568 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 569 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 570 | |
| 571 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 574 | ////////////////////////////////////////////////////////////////////////////////// |
| 575 | ////////////////////////////////////////////////////////////////////////////////// |
| 576 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 577 | void |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 578 | fetchStrategyChoiceInformation() |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 579 | { |
| 580 | m_buffer = make_shared<OBufferStream>(); |
| 581 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 582 | Interest interest("/localhost/nfd/strategy-choice/list"); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 583 | interest.setChildSelector(1); |
| 584 | interest.setMustBeFresh(true); |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 585 | |
| 586 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 587 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 588 | bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 589 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 593 | afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 594 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 595 | if (m_isOutputXml) { |
| 596 | std::cout << "<strategyChoices>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 597 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 598 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 599 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 600 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 601 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 602 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 603 | if (!isOk) { |
| 604 | std::cerr << "ERROR: cannot decode StrategyChoice TLV"; |
| 605 | break; |
| 606 | } |
| 607 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 608 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 609 | nfd::StrategyChoice strategyChoice(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 610 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 611 | std::cout << "<strategyChoice>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 612 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 613 | std::string name(strategyChoice.getName().toUri()); |
| 614 | escapeSpecialCharacters(&name); |
| 615 | std::cout << "<namespace>" << name << "</namespace>"; |
| 616 | std::cout << "<strategy>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 617 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 618 | std::string strategy(strategyChoice.getStrategy().toUri()); |
| 619 | escapeSpecialCharacters(&strategy); |
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 | std::cout << "<name>" << strategy << "</name>"; |
| 622 | std::cout << "</strategy>"; |
| 623 | std::cout << "</strategyChoice>"; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 624 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 625 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 626 | std::cout << "</strategyChoices>"; |
| 627 | } |
| 628 | else { |
| 629 | std::cout << "Strategy choices:" << std::endl; |
| 630 | |
| 631 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 632 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 633 | bool isOk = false; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 634 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 635 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 636 | if (!isOk) { |
| 637 | std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl; |
| 638 | break; |
| 639 | } |
| 640 | offset += block.size(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 641 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 642 | nfd::StrategyChoice strategyChoice(block); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 643 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 644 | std::cout << " " << strategyChoice.getName() |
| 645 | << " strategy=" << strategyChoice.getStrategy() << std::endl; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 646 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 647 | } |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 648 | |
| 649 | runNextStep(); |
| 650 | } |
| 651 | |
| 652 | void |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 653 | fetchRibStatusInformation() |
| 654 | { |
| 655 | m_buffer = make_shared<OBufferStream>(); |
| 656 | |
| 657 | Interest interest("/localhost/nfd/rib/list"); |
| 658 | interest.setChildSelector(1); |
| 659 | interest.setMustBeFresh(true); |
| 660 | |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 661 | SegmentFetcher::fetch(m_face, interest, |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 662 | m_validator, |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 663 | bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1), |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 664 | bind(&NfdStatus::onFetchError, this, _1, _2)); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 668 | afterFetchedRibStatusInformation(const ConstBufferPtr& dataset) |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 669 | { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 670 | if (m_isOutputXml) { |
| 671 | std::cout << "<rib>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 672 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 673 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 674 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 675 | bool isOk = false; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 676 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 677 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 678 | if (!isOk) { |
| 679 | std::cerr << "ERROR: cannot decode RibEntry TLV"; |
| 680 | break; |
| 681 | } |
| 682 | offset += block.size(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 683 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 684 | nfd::RibEntry ribEntry(block); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 685 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 686 | std::cout << "<ribEntry>"; |
| 687 | std::string prefix(ribEntry.getName().toUri()); |
| 688 | escapeSpecialCharacters(&prefix); |
| 689 | std::cout << "<prefix>" << prefix << "</prefix>"; |
| 690 | std::cout << "<routes>"; |
| 691 | for (const nfd::Route& nextRoute : ribEntry) { |
| 692 | std::cout << "<route>" ; |
| 693 | std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>"; |
| 694 | std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>"; |
| 695 | std::cout << "<cost>" << nextRoute.getCost() << "</cost>"; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 696 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 697 | std::cout << "<flags>"; |
| 698 | if (nextRoute.isChildInherit()) |
| 699 | std::cout << "<childInherit/>"; |
| 700 | if (nextRoute.isRibCapture()) |
| 701 | std::cout << "<ribCapture/>"; |
| 702 | std::cout << "</flags>"; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 703 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 704 | if (!nextRoute.hasInfiniteExpirationPeriod()) { |
| 705 | std::cout << "<expirationPeriod>PT" |
| 706 | << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod()) |
| 707 | .count() << "S" |
| 708 | << "</expirationPeriod>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 709 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 710 | std::cout << "</route>"; |
| 711 | } |
| 712 | std::cout << "</routes>"; |
| 713 | std::cout << "</ribEntry>"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 714 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 715 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 716 | std::cout << "</rib>"; |
| 717 | } |
| 718 | else { |
| 719 | std::cout << "RIB:" << std::endl; |
| 720 | |
| 721 | size_t offset = 0; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 722 | while (offset < dataset->size()) { |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 723 | bool isOk = false; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 724 | Block block; |
Yukai Tu | 971d3c2 | 2015-06-21 12:32:03 +0800 | [diff] [blame] | 725 | std::tie(isOk, block) = Block::fromBuffer(dataset, offset); |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 726 | if (!isOk) { |
| 727 | std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl; |
| 728 | break; |
| 729 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 730 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 731 | offset += block.size(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 732 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 733 | nfd::RibEntry ribEntry(block); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 734 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 735 | std::cout << " " << ribEntry.getName().toUri() << " route={"; |
| 736 | bool isFirst = true; |
| 737 | for (const nfd::Route& nextRoute : ribEntry) { |
| 738 | if (isFirst) |
| 739 | isFirst = false; |
| 740 | else |
| 741 | std::cout << ", "; |
Chengyu Fan | 1c630ba | 2014-08-20 13:27:58 -0500 | [diff] [blame] | 742 | |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 743 | std::cout << "faceid=" << nextRoute.getFaceId() |
| 744 | << " (origin=" << nextRoute.getOrigin() |
| 745 | << " cost=" << nextRoute.getCost(); |
| 746 | if (!nextRoute.hasInfiniteExpirationPeriod()) { |
| 747 | std::cout << " expires=" |
| 748 | << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod()) |
| 749 | .count() << "s"; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 750 | } |
Junxiao Shi | 78926c9 | 2015-02-28 22:56:06 -0700 | [diff] [blame] | 751 | |
| 752 | if (nextRoute.isChildInherit()) |
| 753 | std::cout << " ChildInherit"; |
| 754 | if (nextRoute.isRibCapture()) |
| 755 | std::cout << " RibCapture"; |
| 756 | |
| 757 | std::cout << ")"; |
| 758 | } |
| 759 | std::cout << "}" << std::endl; |
| 760 | } |
| 761 | } |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 762 | |
| 763 | runNextStep(); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | void |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 768 | fetchInformation() |
| 769 | { |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 770 | if (m_isOutputXml || |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 771 | (!m_needVersionRetrieval && |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 772 | !m_needChannelStatusRetrieval && |
| 773 | !m_needFaceStatusRetrieval && |
| 774 | !m_needFibEnumerationRetrieval && |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 775 | !m_needRibStatusRetrieval && |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 776 | !m_needStrategyChoiceRetrieval)) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 777 | { |
| 778 | enableVersionRetrieval(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 779 | enableChannelStatusRetrieval(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 780 | enableFaceStatusRetrieval(); |
| 781 | enableFibEnumerationRetrieval(); |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 782 | enableRibStatusRetrieval(); |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 783 | enableStrategyChoiceRetrieval(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 786 | if (m_isOutputXml) |
| 787 | m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this)); |
| 788 | |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 789 | if (m_needVersionRetrieval) |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 790 | m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this)); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 791 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 792 | if (m_needChannelStatusRetrieval) |
| 793 | m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this)); |
| 794 | |
| 795 | if (m_needFaceStatusRetrieval) |
| 796 | m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this)); |
| 797 | |
| 798 | if (m_needFibEnumerationRetrieval) |
| 799 | m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this)); |
| 800 | |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 801 | if (m_needRibStatusRetrieval) |
| 802 | m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this)); |
| 803 | |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 804 | if (m_needStrategyChoiceRetrieval) |
| 805 | m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this)); |
| 806 | |
| 807 | if (m_isOutputXml) |
| 808 | m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this)); |
| 809 | |
| 810 | runNextStep(); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 811 | m_face.processEvents(); |
| 812 | } |
| 813 | |
| 814 | private: |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 815 | void |
| 816 | printXmlHeader() |
| 817 | { |
| 818 | std::cout << "<?xml version=\"1.0\"?>"; |
| 819 | std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">"; |
| 820 | |
| 821 | runNextStep(); |
| 822 | } |
| 823 | |
| 824 | void |
| 825 | printXmlFooter() |
| 826 | { |
| 827 | std::cout << "</nfdStatus>"; |
| 828 | |
| 829 | runNextStep(); |
| 830 | } |
| 831 | |
| 832 | void |
| 833 | runNextStep() |
| 834 | { |
| 835 | if (m_fetchSteps.empty()) |
| 836 | return; |
| 837 | |
| 838 | function<void()> nextStep = m_fetchSteps.front(); |
| 839 | m_fetchSteps.pop_front(); |
| 840 | nextStep(); |
| 841 | } |
| 842 | |
| 843 | private: |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 844 | std::string m_toolName; |
| 845 | bool m_needVersionRetrieval; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 846 | bool m_needChannelStatusRetrieval; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 847 | bool m_needFaceStatusRetrieval; |
| 848 | bool m_needFibEnumerationRetrieval; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 849 | bool m_needRibStatusRetrieval; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 850 | bool m_needStrategyChoiceRetrieval; |
| 851 | bool m_isOutputXml; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 852 | Face m_face; |
| 853 | |
| 854 | shared_ptr<OBufferStream> m_buffer; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 855 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 856 | std::deque<function<void()>> m_fetchSteps; |
Muktadir R Chowdhury | 6c4a67a | 2015-09-07 22:13:01 -0500 | [diff] [blame] | 857 | |
| 858 | ndn::ValidatorNull m_validator; |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 859 | |
| 860 | ForwarderStatusValidator m_forwarderStatusValidator; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 861 | }; |
| 862 | |
Weiwei Liu | 2c5a01a | 2016-03-24 21:55:46 -0700 | [diff] [blame] | 863 | } // namespace ndn |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 864 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 865 | int main(int argc, char* argv[]) |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 866 | { |
| 867 | int option; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 868 | ndn::NfdStatus nfdStatus(argv[0]); |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 869 | |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 870 | while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) { |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 871 | switch (option) { |
| 872 | case 'h': |
| 873 | nfdStatus.usage(); |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 874 | return 0; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 875 | case 'v': |
| 876 | nfdStatus.enableVersionRetrieval(); |
| 877 | break; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 878 | case 'c': |
| 879 | nfdStatus.enableChannelStatusRetrieval(); |
| 880 | break; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 881 | case 'f': |
| 882 | nfdStatus.enableFaceStatusRetrieval(); |
| 883 | break; |
| 884 | case 'b': |
| 885 | nfdStatus.enableFibEnumerationRetrieval(); |
| 886 | break; |
Chengyu Fan | 30aa207 | 2014-07-20 13:52:32 -0600 | [diff] [blame] | 887 | case 'r': |
| 888 | nfdStatus.enableRibStatusRetrieval(); |
| 889 | break; |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 890 | case 's': |
| 891 | nfdStatus.enableStrategyChoiceRetrieval(); |
| 892 | break; |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 893 | case 'x': |
Alexander Afanasyev | 0417d2a | 2014-06-08 10:56:43 +0300 | [diff] [blame] | 894 | nfdStatus.enableXmlOutput(); |
Chengyu Fan | 514ed5e | 2014-04-17 13:07:30 -0600 | [diff] [blame] | 895 | break; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 896 | case 'V': |
| 897 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 898 | return 0; |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 899 | default: |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 900 | nfdStatus.usage(); |
| 901 | return 1; |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
| 905 | try { |
| 906 | nfdStatus.fetchInformation(); |
| 907 | } |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 908 | catch (std::exception& e) { |
jeraldabraham | b6dde38 | 2014-03-19 18:58:09 -0700 | [diff] [blame] | 909 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 910 | return 2; |
| 911 | } |
| 912 | |
| 913 | return 0; |
| 914 | } |