/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2016,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
 */

#include "version.hpp"
#include "common.hpp"

#include <ndn-cxx/face.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/encoding/buffer-stream.hpp>

#include <ndn-cxx/management/nfd-forwarder-status.hpp>
#include <ndn-cxx/management/nfd-channel-status.hpp>
#include <ndn-cxx/management/nfd-face-status.hpp>
#include <ndn-cxx/management/nfd-fib-entry.hpp>
#include <ndn-cxx/management/nfd-rib-entry.hpp>
#include <ndn-cxx/management/nfd-strategy-choice.hpp>
#include <ndn-cxx/util/segment-fetcher.hpp>
#include <ndn-cxx/security/validator-null.hpp>

#include <boost/algorithm/string/replace.hpp>
#include <list>

namespace ndn {

using util::SegmentFetcher;

/** \brief custom validator for the purpose of obtaining nfdId.
 */
class ForwarderStatusValidator : public Validator
{
protected:
  virtual void
  checkPolicy(const Data& data,
              int nSteps,
              const OnDataValidated& onValidated,
              const OnDataValidationFailed& onValidationFailed,
              std::vector<shared_ptr<ValidationRequest>>& nextSteps) override
  {
    const ndn::KeyLocator& locator = data.getSignature().getKeyLocator();
    if (nfdId.empty() && locator.getType() == KeyLocator::KeyLocator_Name)
      nfdId = locator.getName();
    onValidated(data.shared_from_this());
  }

  virtual void
  checkPolicy(const Interest& interest,
              int nSteps,
              const OnInterestValidated& onValidated,
              const OnInterestValidationFailed& onValidationFailed,
              std::vector<shared_ptr<ValidationRequest>>& nextSteps) override
  {
    BOOST_ASSERT(false);
  }

public:
  Name nfdId;
};


class NfdStatus
{
public:
  explicit
  NfdStatus(char* toolName)
    : m_toolName(toolName)
    , m_needVersionRetrieval(false)
    , m_needChannelStatusRetrieval(false)
    , m_needFaceStatusRetrieval(false)
    , m_needFibEnumerationRetrieval(false)
    , m_needRibStatusRetrieval(false)
    , m_needStrategyChoiceRetrieval(false)
    , m_isOutputXml(false)
  {
  }

  void
  usage()
  {
    std::cout << "Usage: \n  " << m_toolName << " [options]\n\n"
      "Show NFD version and status information\n\n"
      "Options:\n"
      "  [-h] - print this help message\n"
      "  [-v] - retrieve version information\n"
      "  [-c] - retrieve channel status information\n"
      "  [-f] - retrieve face status information\n"
      "  [-b] - retrieve FIB information\n"
      "  [-r] - retrieve RIB information\n"
      "  [-s] - retrieve configured strategy choice for NDN namespaces\n"
      "  [-x] - output NFD status information in XML format\n"
      "\n"
      "  [-V] - show version information of nfd-status and exit\n"
      "\n"
      "If no options are provided, all information is retrieved.\n"
      "If -x is provided, other options(-v, -c, etc.) are ignored, and all information is printed in XML format.\n"
      ;
  }

  void
  enableVersionRetrieval()
  {
    m_needVersionRetrieval = true;
  }

  void
  enableChannelStatusRetrieval()
  {
    m_needChannelStatusRetrieval = true;
  }

  void
  enableFaceStatusRetrieval()
  {
    m_needFaceStatusRetrieval = true;
  }

  void
  enableFibEnumerationRetrieval()
  {
    m_needFibEnumerationRetrieval = true;
  }

  void
  enableStrategyChoiceRetrieval()
  {
    m_needStrategyChoiceRetrieval = true;
  }

  void
  enableRibStatusRetrieval()
  {
    m_needRibStatusRetrieval = true;
  }

  void
  enableXmlOutput()
  {
    m_isOutputXml = true;
  }

  void
  onTimeout()
  {
    std::cerr << "Request timed out" << std::endl;

    runNextStep();
  }


  void
  onFetchError(uint32_t errorCode, const std::string& errorMsg)
  {
    std::cerr << "Error code:" << errorCode << ", message:" << errorMsg << std::endl;

    runNextStep();
  }

  void
  escapeSpecialCharacters(std::string *data)
  {
    using boost::algorithm::replace_all;
    replace_all(*data, "&",  "&amp;");
    replace_all(*data, "\"", "&quot;");
    replace_all(*data, "\'", "&apos;");
    replace_all(*data, "<",  "&lt;");
    replace_all(*data, ">",  "&gt;");
  }

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////

  void
  fetchVersionInformation()
  {
    Interest interest("/localhost/nfd/status/general");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);
    SegmentFetcher::fetch(m_face, interest,
                          m_forwarderStatusValidator,
                          bind(&NfdStatus::afterFetchedVersionInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedVersionInformation(const ConstBufferPtr& dataset)
  {
    Block block(tlv::Content, dataset);
    nfd::ForwarderStatus status(block);

    if (m_isOutputXml) {
      std::cout << "<generalStatus>";
      std::cout << "<nfdId>"
                << m_forwarderStatusValidator.nfdId << "</nfdId>";
      std::cout << "<version>"
                << status.getNfdVersion() << "</version>";
      std::cout << "<startTime>"
                << time::toString(status.getStartTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
                << "</startTime>";
      std::cout << "<currentTime>"
                << time::toString(status.getCurrentTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
                << "</currentTime>";
      std::cout << "<uptime>PT"
                << time::duration_cast<time::seconds>(status.getCurrentTimestamp() -
                                                      status.getStartTimestamp()).count()
                << "S</uptime>";
      std::cout << "<nNameTreeEntries>"     << status.getNNameTreeEntries()
                << "</nNameTreeEntries>";
      std::cout << "<nFibEntries>"          << status.getNFibEntries()
                << "</nFibEntries>";
      std::cout << "<nPitEntries>"          << status.getNPitEntries()
                << "</nPitEntries>";
      std::cout << "<nMeasurementsEntries>" << status.getNMeasurementsEntries()
                << "</nMeasurementsEntries>";
      std::cout << "<nCsEntries>"           << status.getNCsEntries()
                << "</nCsEntries>";
      std::cout << "<packetCounters>";
      std::cout << "<incomingPackets>";
      std::cout << "<nInterests>"           << status.getNInInterests()
                << "</nInterests>";
      std::cout << "<nDatas>"               << status.getNInDatas()
                << "</nDatas>";
      std::cout << "</incomingPackets>";
      std::cout << "<outgoingPackets>";
      std::cout << "<nInterests>"           << status.getNOutInterests()
                << "</nInterests>";
      std::cout << "<nDatas>"               << status.getNOutDatas()
                << "</nDatas>";
      std::cout << "</outgoingPackets>";
      std::cout << "</packetCounters>";
      std::cout << "</generalStatus>";
    }
    else {
      std::cout << "General NFD status:" << std::endl;
      std::cout << "                 nfdId="
                << m_forwarderStatusValidator.nfdId << std::endl;
      std::cout << "               version="
                << status.getNfdVersion() << std::endl;
      std::cout << "             startTime="
                << time::toIsoString(status.getStartTimestamp()) << std::endl;
      std::cout << "           currentTime="
                << time::toIsoString(status.getCurrentTimestamp()) << std::endl;
      std::cout << "                uptime="
                << time::duration_cast<time::seconds>(status.getCurrentTimestamp() -
                                                      status.getStartTimestamp()) << std::endl;

      std::cout << "      nNameTreeEntries=" << status.getNNameTreeEntries()     << std::endl;
      std::cout << "           nFibEntries=" << status.getNFibEntries()          << std::endl;
      std::cout << "           nPitEntries=" << status.getNPitEntries()          << std::endl;
      std::cout << "  nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl;
      std::cout << "            nCsEntries=" << status.getNCsEntries()           << std::endl;
      std::cout << "          nInInterests=" << status.getNInInterests()         << std::endl;
      std::cout << "         nOutInterests=" << status.getNOutInterests()        << std::endl;
      std::cout << "              nInDatas=" << status.getNInDatas()             << std::endl;
      std::cout << "             nOutDatas=" << status.getNOutDatas()            << std::endl;
    }

    runNextStep();
  }

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////

  void
  fetchChannelStatusInformation()
  {
    m_buffer = make_shared<OBufferStream>();

    Interest interest("/localhost/nfd/faces/channels");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    SegmentFetcher::fetch(m_face, interest,
                          m_validator,
                          bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset)
  {
    if (m_isOutputXml) {
      std::cout << "<channels>";

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
          break;
        }

        offset += block.size();

        nfd::ChannelStatus channelStatus(block);

        std::cout << "<channel>";
        std::string localUri(channelStatus.getLocalUri());
        escapeSpecialCharacters(&localUri);
        std::cout << "<localUri>" << localUri << "</localUri>";
        std::cout << "</channel>";
      }

      std::cout << "</channels>";
    }
    else {
      std::cout << "Channels:" << std::endl;

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
          break;
        }

        offset += block.size();

        nfd::ChannelStatus channelStatus(block);
        std::cout << "  " << channelStatus.getLocalUri() << std::endl;
      }
    }

    runNextStep();
  }

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////

  void
  fetchFaceStatusInformation()
  {
    m_buffer = make_shared<OBufferStream>();

    Interest interest("/localhost/nfd/faces/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    SegmentFetcher::fetch(m_face, interest,
                          m_validator,
                          bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset)
  {
    if (m_isOutputXml) {
      std::cout << "<faces>";

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
          break;
        }

        offset += block.size();

        nfd::FaceStatus faceStatus(block);

        std::cout << "<face>";
        std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";

        std::string remoteUri(faceStatus.getRemoteUri());
        escapeSpecialCharacters(&remoteUri);
        std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";

        std::string localUri(faceStatus.getLocalUri());
        escapeSpecialCharacters(&localUri);
        std::cout << "<localUri>" << localUri << "</localUri>";

        if (faceStatus.hasExpirationPeriod()) {
          std::cout << "<expirationPeriod>PT"
                    << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
                       .count() << "S"
                    << "</expirationPeriod>";
        }

        std::cout << "<faceScope>" << faceStatus.getFaceScope()
                  << "</faceScope>";
        std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
                  << "</facePersistency>";
        std::cout << "<linkType>" << faceStatus.getLinkType()
                  << "</linkType>";

        std::cout << "<packetCounters>";
        std::cout << "<incomingPackets>";
        std::cout << "<nInterests>"       << faceStatus.getNInInterests()
                  << "</nInterests>";
        std::cout << "<nDatas>"           << faceStatus.getNInDatas()
                  << "</nDatas>";
        std::cout << "</incomingPackets>";
        std::cout << "<outgoingPackets>";
        std::cout << "<nInterests>"       << faceStatus.getNOutInterests()
                  << "</nInterests>";
        std::cout << "<nDatas>"           << faceStatus.getNOutDatas()
                  << "</nDatas>";
        std::cout << "</outgoingPackets>";
        std::cout << "</packetCounters>";

        std::cout << "<byteCounters>";
        std::cout << "<incomingBytes>"    << faceStatus.getNInBytes()
                  << "</incomingBytes>";
        std::cout << "<outgoingBytes>"    << faceStatus.getNOutBytes()
                  << "</outgoingBytes>";
        std::cout << "</byteCounters>";

        std::cout << "</face>";
      }
      std::cout << "</faces>";
    }
    else {
      std::cout << "Faces:" << std::endl;

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
          break;
        }

        offset += block.size();

        nfd::FaceStatus faceStatus(block);

        std::cout << "  faceid=" << faceStatus.getFaceId()
                  << " remote=" << faceStatus.getRemoteUri()
                  << " local=" << faceStatus.getLocalUri();
        if (faceStatus.hasExpirationPeriod()) {
          std::cout  << " expires="
                     << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
                        .count() << "s";
        }
        std::cout << " counters={"
                  << "in={" << faceStatus.getNInInterests() << "i "
                  << faceStatus.getNInDatas() << "d "
                  << faceStatus.getNInBytes() << "B}"
                  << " out={" << faceStatus.getNOutInterests() << "i "
                  << faceStatus.getNOutDatas() << "d "
                  << faceStatus.getNOutBytes() << "B}"
                  << "}";
        std::cout << " " << faceStatus.getFaceScope()
                  << " " << faceStatus.getFacePersistency()
                  << " " << faceStatus.getLinkType();
        std::cout << std::endl;
      }
    }

    runNextStep();
  }

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////

  void
  fetchFibEnumerationInformation()
  {
    m_buffer = make_shared<OBufferStream>();

    Interest interest("/localhost/nfd/fib/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    SegmentFetcher::fetch(m_face, interest,
                          m_validator,
                          bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset)
  {
    if (m_isOutputXml) {
      std::cout << "<fib>";

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode FibEntry TLV";
          break;
        }
        offset += block.size();

        nfd::FibEntry fibEntry(block);

        std::cout << "<fibEntry>";
        std::string prefix(fibEntry.getPrefix().toUri());
        escapeSpecialCharacters(&prefix);
        std::cout << "<prefix>" << prefix << "</prefix>";
        std::cout << "<nextHops>";
        for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
          std::cout << "<nextHop>" ;
          std::cout << "<faceId>"  << nextHop.getFaceId() << "</faceId>";
          std::cout << "<cost>"    << nextHop.getCost()   << "</cost>";
          std::cout << "</nextHop>";
        }
        std::cout << "</nextHops>";
        std::cout << "</fibEntry>";
      }

      std::cout << "</fib>";
    }
    else {
      std::cout << "FIB:" << std::endl;

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
          break;
        }
        offset += block.size();

        nfd::FibEntry fibEntry(block);

        std::cout << "  " << fibEntry.getPrefix() << " nexthops={";
        bool isFirst = true;
        for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
          if (isFirst)
            isFirst = false;
          else
            std::cout << ", ";

          std::cout << "faceid=" << nextHop.getFaceId()
                    << " (cost=" << nextHop.getCost() << ")";
        }
        std::cout << "}" << std::endl;
      }
    }

    runNextStep();
  }

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////

  void
  fetchStrategyChoiceInformation()
  {
    m_buffer = make_shared<OBufferStream>();

    Interest interest("/localhost/nfd/strategy-choice/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    SegmentFetcher::fetch(m_face, interest,
                          m_validator,
                          bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset)
  {
    if (m_isOutputXml) {
      std::cout << "<strategyChoices>";

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode StrategyChoice TLV";
          break;
        }
        offset += block.size();

        nfd::StrategyChoice strategyChoice(block);

        std::cout << "<strategyChoice>";

        std::string name(strategyChoice.getName().toUri());
        escapeSpecialCharacters(&name);
        std::cout << "<namespace>" << name << "</namespace>";
        std::cout << "<strategy>";

        std::string strategy(strategyChoice.getStrategy().toUri());
        escapeSpecialCharacters(&strategy);

        std::cout << "<name>" << strategy << "</name>";
        std::cout << "</strategy>";
        std::cout << "</strategyChoice>";
      }

      std::cout << "</strategyChoices>";
    }
    else {
      std::cout << "Strategy choices:" << std::endl;

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
          break;
        }
        offset += block.size();

        nfd::StrategyChoice strategyChoice(block);

        std::cout << "  " << strategyChoice.getName()
                  << " strategy=" << strategyChoice.getStrategy() << std::endl;
      }
    }

    runNextStep();
  }

  void
  fetchRibStatusInformation()
  {
    m_buffer = make_shared<OBufferStream>();

    Interest interest("/localhost/nfd/rib/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    SegmentFetcher::fetch(m_face, interest,
                          m_validator,
                          bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1),
                          bind(&NfdStatus::onFetchError, this, _1, _2));
  }

  void
  afterFetchedRibStatusInformation(const ConstBufferPtr& dataset)
  {
    if (m_isOutputXml) {
      std::cout << "<rib>";

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode RibEntry TLV";
          break;
        }
        offset += block.size();

        nfd::RibEntry ribEntry(block);

        std::cout << "<ribEntry>";
        std::string prefix(ribEntry.getName().toUri());
        escapeSpecialCharacters(&prefix);
        std::cout << "<prefix>" << prefix << "</prefix>";
        std::cout << "<routes>";
        for (const nfd::Route& nextRoute : ribEntry) {
          std::cout << "<route>" ;
          std::cout << "<faceId>"  << nextRoute.getFaceId() << "</faceId>";
          std::cout << "<origin>"  << nextRoute.getOrigin() << "</origin>";
          std::cout << "<cost>"    << nextRoute.getCost()   << "</cost>";

          std::cout << "<flags>";
          if (nextRoute.isChildInherit())
            std::cout << "<childInherit/>";
          if (nextRoute.isRibCapture())
            std::cout << "<ribCapture/>";
          std::cout << "</flags>";

          if (!nextRoute.hasInfiniteExpirationPeriod()) {
            std::cout << "<expirationPeriod>PT"
                      << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
                         .count() << "S"
                      << "</expirationPeriod>";
          }
          std::cout << "</route>";
        }
        std::cout << "</routes>";
        std::cout << "</ribEntry>";
      }

      std::cout << "</rib>";
    }
    else {
      std::cout << "RIB:" << std::endl;

      size_t offset = 0;
      while (offset < dataset->size()) {
        bool isOk = false;
        Block block;
        std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
        if (!isOk) {
          std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
          break;
        }

        offset += block.size();

        nfd::RibEntry ribEntry(block);

        std::cout << "  " << ribEntry.getName().toUri() << " route={";
        bool isFirst = true;
        for (const nfd::Route& nextRoute : ribEntry) {
          if (isFirst)
            isFirst = false;
          else
            std::cout << ", ";

          std::cout << "faceid="   << nextRoute.getFaceId()
                    << " (origin="  << nextRoute.getOrigin()
                    << " cost="    << nextRoute.getCost();
          if (!nextRoute.hasInfiniteExpirationPeriod()) {
            std::cout << " expires="
                      << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
                         .count() << "s";
          }

          if (nextRoute.isChildInherit())
            std::cout << " ChildInherit";
          if (nextRoute.isRibCapture())
            std::cout << " RibCapture";

          std::cout << ")";
        }
        std::cout << "}" << std::endl;
      }
    }

    runNextStep();
  }


  void
  fetchInformation()
  {
    if (m_isOutputXml ||
        (!m_needVersionRetrieval &&
         !m_needChannelStatusRetrieval &&
         !m_needFaceStatusRetrieval &&
         !m_needFibEnumerationRetrieval &&
         !m_needRibStatusRetrieval &&
         !m_needStrategyChoiceRetrieval))
      {
        enableVersionRetrieval();
        enableChannelStatusRetrieval();
        enableFaceStatusRetrieval();
        enableFibEnumerationRetrieval();
        enableRibStatusRetrieval();
        enableStrategyChoiceRetrieval();
      }

    if (m_isOutputXml)
      m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this));

    if (m_needVersionRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this));

    if (m_needChannelStatusRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this));

    if (m_needFaceStatusRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this));

    if (m_needFibEnumerationRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this));

    if (m_needRibStatusRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this));

    if (m_needStrategyChoiceRetrieval)
      m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this));

    if (m_isOutputXml)
      m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this));

    runNextStep();
    m_face.processEvents();
  }

private:
  void
  printXmlHeader()
  {
    std::cout << "<?xml version=\"1.0\"?>";
    std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">";

    runNextStep();
  }

  void
  printXmlFooter()
  {
    std::cout << "</nfdStatus>";

    runNextStep();
  }

  void
  runNextStep()
  {
    if (m_fetchSteps.empty())
      return;

    function<void()> nextStep = m_fetchSteps.front();
    m_fetchSteps.pop_front();
    nextStep();
  }

private:
  std::string m_toolName;
  bool m_needVersionRetrieval;
  bool m_needChannelStatusRetrieval;
  bool m_needFaceStatusRetrieval;
  bool m_needFibEnumerationRetrieval;
  bool m_needRibStatusRetrieval;
  bool m_needStrategyChoiceRetrieval;
  bool m_isOutputXml;
  Face m_face;

  shared_ptr<OBufferStream> m_buffer;

  std::deque<function<void()>> m_fetchSteps;

  ndn::ValidatorNull m_validator;

  ForwarderStatusValidator m_forwarderStatusValidator;
};

} // namespace ndn

int main(int argc, char* argv[])
{
  int option;
  ndn::NfdStatus nfdStatus(argv[0]);

  while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) {
    switch (option) {
    case 'h':
      nfdStatus.usage();
      return 0;
    case 'v':
      nfdStatus.enableVersionRetrieval();
      break;
    case 'c':
      nfdStatus.enableChannelStatusRetrieval();
      break;
    case 'f':
      nfdStatus.enableFaceStatusRetrieval();
      break;
    case 'b':
      nfdStatus.enableFibEnumerationRetrieval();
      break;
    case 'r':
      nfdStatus.enableRibStatusRetrieval();
      break;
    case 's':
      nfdStatus.enableStrategyChoiceRetrieval();
      break;
    case 'x':
      nfdStatus.enableXmlOutput();
      break;
    case 'V':
      std::cout << NFD_VERSION_BUILD_STRING << std::endl;
      return 0;
    default:
      nfdStatus.usage();
      return 1;
    }
  }

  try {
    nfdStatus.fetchInformation();
  }
  catch (std::exception& e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 2;
  }

  return 0;
}
