rib+tools: use ndn::nfd::RouteOrigin instead of uint64_t
Change-Id: Ic8cbe95491a41e1d34b66d406da8637aeb5fd9e3
Refs: #3903
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index 1ecd6e5..ca52e9b 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+ * Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -41,17 +41,12 @@
#include "core/network.hpp"
using namespace ndn::nfd;
-using ndn::Face;
-using ndn::KeyChain;
-using ndn::nfd::FaceEventNotification;
using ndn::util::FaceUri;
using ::nfd::Network;
namespace ndn {
namespace nfd_autoreg {
-namespace po = boost::program_options;
-
class AutoregServer : boost::noncopyable
{
public:
@@ -123,10 +118,9 @@
}
void
- registerPrefixesForFace(uint64_t faceId,
- const std::vector<ndn::Name>& prefixes)
+ registerPrefixesForFace(uint64_t faceId, const std::vector<Name>& prefixes)
{
- for (std::vector<ndn::Name>::const_iterator prefix = prefixes.begin();
+ for (std::vector<Name>::const_iterator prefix = prefixes.begin();
prefix != prefixes.end();
++prefix)
{
@@ -179,37 +173,35 @@
}
}
-
void
signalHandler()
{
m_face.shutdown();
}
-
void
usage(std::ostream& os,
- const po::options_description& optionDesciption,
+ const boost::program_options::options_description& desc,
const char* programName)
{
os << "Usage:\n"
<< " " << programName << " --prefix=</autoreg/prefix> [--prefix=/another/prefix] ...\n"
<< "\n";
- os << optionDesciption;
+ os << desc;
}
void
startProcessing()
{
std::cerr << "AUTOREG prefixes: " << std::endl;
- for (std::vector<ndn::Name>::const_iterator prefix = m_autoregPrefixes.begin();
+ for (std::vector<Name>::const_iterator prefix = m_autoregPrefixes.begin();
prefix != m_autoregPrefixes.end();
++prefix)
{
std::cout << " " << *prefix << std::endl;
}
std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl;
- for (std::vector<ndn::Name>::const_iterator prefix = m_allFacesPrefixes.begin();
+ for (std::vector<Name>::const_iterator prefix = m_allFacesPrefixes.begin();
prefix != m_allFacesPrefixes.end();
++prefix)
{
@@ -248,8 +240,8 @@
startFetchingFaceStatusDataset()
{
m_controller.fetch<FaceDataset>(
- [this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
- for (const ndn::nfd::FaceStatus& faceStatus : faces) {
+ [this] (const std::vector<FaceStatus>& faces) {
+ for (const auto& faceStatus : faces) {
registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()),
faceStatus.getFacePersistency());
}
@@ -260,20 +252,22 @@
int
main(int argc, char* argv[])
{
+ namespace po = boost::program_options;
+
po::options_description optionDesciption;
optionDesciption.add_options()
("help,h", "produce help message")
- ("prefix,i", po::value<std::vector<ndn::Name> >(&m_autoregPrefixes)->composing(),
+ ("prefix,i", po::value<std::vector<Name>>(&m_autoregPrefixes)->composing(),
"prefix that should be automatically registered when new a remote non-local face is "
"established")
- ("all-faces-prefix,a", po::value<std::vector<ndn::Name> >(&m_allFacesPrefixes)->composing(),
+ ("all-faces-prefix,a", po::value<std::vector<Name>>(&m_allFacesPrefixes)->composing(),
"prefix that should be automatically registered for all TCP and UDP non-local faces "
"(blacklists and whitelists do not apply to this prefix)")
("cost,c", po::value<uint64_t>(&m_cost)->default_value(255),
"FIB cost which should be assigned to autoreg nexthops")
- ("whitelist,w", po::value<std::vector<Network> >(&m_whiteList)->composing(),
+ ("whitelist,w", po::value<std::vector<Network>>(&m_whiteList)->composing(),
"Whitelisted network, e.g., 192.168.2.0/24 or ::1/128")
- ("blacklist,b", po::value<std::vector<Network> >(&m_blackList)->composing(),
+ ("blacklist,b", po::value<std::vector<Network>>(&m_blackList)->composing(),
"Blacklisted network, e.g., 192.168.2.32/30 or ::1/128")
("version,V", "show version and exit")
;
@@ -284,7 +278,7 @@
po::store(po::command_line_parser(argc, argv).options(optionDesciption).run(), options);
po::notify(options);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
usage(std::cerr, optionDesciption, argv[0]);
@@ -323,7 +317,7 @@
startFetchingFaceStatusDataset();
startProcessing();
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 2;
@@ -337,8 +331,8 @@
KeyChain m_keyChain;
Controller m_controller;
FaceMonitor m_faceMonitor;
- std::vector<ndn::Name> m_autoregPrefixes;
- std::vector<ndn::Name> m_allFacesPrefixes;
+ std::vector<Name> m_autoregPrefixes;
+ std::vector<Name> m_allFacesPrefixes;
uint64_t m_cost;
std::vector<Network> m_whiteList;
std::vector<Network> m_blackList;
diff --git a/tools/nfdc/legacy-nfdc.cpp b/tools/nfdc/legacy-nfdc.cpp
index 5f4f81f..e0e6bcd 100644
--- a/tools/nfdc/legacy-nfdc.cpp
+++ b/tools/nfdc/legacy-nfdc.cpp
@@ -341,6 +341,7 @@
bool wantCapture = false;
bool wantPermanentFace = false;
int64_t expires = -1;
+ std::underlying_type<ndn::nfd::RouteOrigin>::type origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
namespace po = boost::program_options;
po::options_description options;
@@ -349,7 +350,7 @@
(",C", po::bool_switch(&wantCapture))
(",c", po::value<uint64_t>(&p.m_cost))
(",e", po::value<int64_t>(&expires))
- (",o", po::value<uint64_t>(&p.m_origin))
+ (",o", po::value<std::underlying_type<ndn::nfd::RouteOrigin>::type>(&origin))
(",P", po::bool_switch(&wantPermanentFace));
po::variables_map vm;
std::vector<std::string> unparsed;
@@ -376,6 +377,7 @@
// accept negative values as no expiration
p.m_expires = time::milliseconds(expires);
}
+ p.m_origin = static_cast<ndn::nfd::RouteOrigin>(origin);
if (wantPermanentFace) {
p.m_facePersistency = ndn::nfd::FACE_PERSISTENCY_PERMANENT;
}
diff --git a/tools/nfdc/legacy-nfdc.hpp b/tools/nfdc/legacy-nfdc.hpp
index 6ae9abe..ada0a7d 100644
--- a/tools/nfdc/legacy-nfdc.hpp
+++ b/tools/nfdc/legacy-nfdc.hpp
@@ -27,6 +27,8 @@
#define NFD_TOOLS_NFDC_LEGACY_NFDC_HPP
#include "execute-command.hpp"
+
+#include <ndn-cxx/encoding/nfd-constants.hpp>
#include <ndn-cxx/mgmt/nfd/controller.hpp>
namespace nfd {
@@ -160,7 +162,7 @@
uint64_t m_flags;
uint64_t m_cost;
uint64_t m_faceId;
- uint64_t m_origin;
+ ndn::nfd::RouteOrigin m_origin;
time::milliseconds m_expires;
std::string m_name;
ndn::nfd::FacePersistency m_facePersistency;
diff --git a/tools/nfdc/rib-module.cpp b/tools/nfdc/rib-module.cpp
index ffcb18c..5ca7195 100644
--- a/tools/nfdc/rib-module.cpp
+++ b/tools/nfdc/rib-module.cpp
@@ -191,7 +191,7 @@
text::ItemAttributes ia;
ctx.out << ia("prefix") << resp.getName()
<< ia("nexthop") << resp.getFaceId()
- << ia("origin") << static_cast<RouteOrigin>(resp.getOrigin())
+ << ia("origin") << resp.getOrigin()
<< ia("cost") << resp.getCost()
<< ia("flags") << static_cast<ndn::nfd::RouteFlags>(resp.getFlags());
if (resp.hasExpirationPeriod()) {
@@ -245,7 +245,7 @@
text::ItemAttributes ia;
ctx.out << ia("prefix") << resp.getName()
<< ia("nexthop") << resp.getFaceId()
- << ia("origin") << static_cast<RouteOrigin>(resp.getOrigin())
+ << ia("origin") << resp.getOrigin()
<< '\n';
},
ctx.makeCommandFailureHandler("removing route"),
@@ -290,7 +290,7 @@
for (const Route& route : item.getRoutes()) {
os << "<route>"
<< "<faceId>" << route.getFaceId() << "</faceId>"
- << "<origin>" << static_cast<RouteOrigin>(route.getOrigin()) << "</origin>"
+ << "<origin>" << route.getOrigin() << "</origin>"
<< "<cost>" << route.getCost() << "</cost>";
if (route.getFlags() == ndn::nfd::ROUTE_FLAGS_NONE) {
os << "<flags/>";
@@ -352,14 +352,9 @@
os << ia("prefix") << entry.getName();
}
os << ia("nexthop") << route.getFaceId();
- os << ia("origin") << static_cast<RouteOrigin>(route.getOrigin());
+ os << ia("origin") << route.getOrigin();
os << ia("cost") << route.getCost();
os << ia("flags") << static_cast<ndn::nfd::RouteFlags>(route.getFlags());
-
- // 'origin' field is printed as a number, because printing 'origin' as string may mislead user
- // into passing strings to 'origin' command line argument which currently only accepts numbers.
- ///\todo #3987 print 'origin' with RouteOrigin stream insertion operator
-
if (route.hasExpirationPeriod()) {
os << ia("expires") << text::formatDuration(route.getExpirationPeriod());
}