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