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