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