/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2015,  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 <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;

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
  onErrorFetch(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);
    m_face.expressInterest(
                           interest,
                           bind(&NfdStatus::afterFetchedVersionInformation, this, _2),
                           bind(&NfdStatus::onTimeout, this));
  }

  void
  afterFetchedVersionInformation(const Data& data)
  {
    nfd::ForwarderStatus status(data.getContent());
    std::string nfdId;
    if (data.getSignature().hasKeyLocator())
      {
        const ndn::KeyLocator& locator = data.getSignature().getKeyLocator();
        if (locator.getType() == KeyLocator::KeyLocator_Name)
          nfdId = locator.getName().toUri();
        //todo: KeyDigest supporting
      }

    if (m_isOutputXml)
      {
        std::cout << "<generalStatus>";
        std::cout << "<nfdId>"
                  << 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="
                  << 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::onErrorFetch, 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::onErrorFetch, 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::onErrorFetch, 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::onErrorFetch, 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::onErrorFetch, 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;
};

}

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;
}
