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