37 #include <boost/property_tree/info_parser.hpp> 38 #include <ndn-cxx/transport/tcp-transport.hpp> 39 #include <ndn-cxx/transport/unix-transport.hpp> 46 Service* Service::s_instance =
nullptr;
60 boost::property_tree::read_info(filename, config);
68 static shared_ptr<ndn::Transport>
71 if (config.get_child_optional(
"face_system.unix")) {
73 auto path = config.get<std::string>(
"face_system.unix.path",
"/var/run/nfd.sock");
74 return make_shared<ndn::UnixTransport>(path);
76 else if (config.get_child_optional(
"face_system.tcp") &&
77 config.get<std::string>(
"face_system.tcp.listen",
"yes") ==
"yes") {
79 auto port = config.get<std::string>(
"face_system.tcp.port",
"6363");
80 return make_shared<ndn::TcpTransport>(
"localhost", port);
83 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"No transport is available to communicate with NFD"));
89 [&configFile] (
ConfigFile& config, bool isDryRun) {
90 config.parse(configFile, isDryRun);
97 [&configSection] (
ConfigFile& config, bool isDryRun) {
98 config.parse(configSection, isDryRun,
"internal://nfd.conf");
103 template<
typename ConfigParseFunc>
104 Service::Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport,
105 const ConfigParseFunc& configParse)
106 : m_keyChain(keyChain)
108 , m_nfdController(m_face, m_keyChain)
109 , m_fibUpdater(m_rib, m_nfdController)
110 , m_dispatcher(m_face, m_keyChain)
111 , m_ribManager(m_rib, m_face, m_nfdController, m_dispatcher)
113 if (s_instance !=
nullptr) {
114 BOOST_THROW_EXCEPTION(std::logic_error(
"RIB service cannot be instantiated more than once"));
117 BOOST_THROW_EXCEPTION(std::logic_error(
"RIB service must run on RIB thread"));
122 config.
addSectionHandler(CFG_SECTION, bind(&Service::processConfig,
this, _1, _2, _3));
123 configParse(config,
true);
124 configParse(config,
false);
132 s_instance =
nullptr;
138 if (s_instance ==
nullptr) {
139 BOOST_THROW_EXCEPTION(std::logic_error(
"RIB service is not instantiated"));
142 BOOST_THROW_EXCEPTION(std::logic_error(
"Must get RIB service on RIB thread"));
148 Service::processConfig(
const ConfigSection& section,
bool isDryRun,
const std::string& filename)
151 checkConfig(section, filename);
154 applyConfig(section, filename);
159 Service::checkConfig(
const ConfigSection& section,
const std::string& filename)
161 for (
const auto& item : section) {
162 const std::string& key = item.first;
164 if (key == CFG_LOCALHOST_SECURITY || key == CFG_LOCALHOP_SECURITY) {
165 ndn::security::v2::validator_config::ValidationPolicyConfig policy;
166 policy.load(value, filename);
168 else if (key == CFG_PREFIX_PROPAGATE) {
171 else if (key == CFG_READVERTISE_NLSR) {
175 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option " + CFG_SECTION +
"." + key));
181 Service::applyConfig(
const ConfigSection& section,
const std::string& filename)
183 bool wantPrefixPropagate =
false;
184 bool wantReadvertiseNlsr =
false;
186 for (
const auto& item : section) {
187 const std::string& key = item.first;
189 if (key == CFG_LOCALHOST_SECURITY) {
192 else if (key == CFG_LOCALHOP_SECURITY) {
195 else if (key == CFG_PREFIX_PROPAGATE) {
196 if (m_prefixPropagator ==
nullptr) {
197 m_prefixPropagator = make_unique<AutoPrefixPropagator>(m_nfdController, m_keyChain, m_rib);
199 m_prefixPropagator->loadConfig(item.second);
200 m_prefixPropagator->enable();
201 wantPrefixPropagate =
true;
203 else if (key == CFG_READVERTISE_NLSR) {
207 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option " + CFG_SECTION +
"." + key));
211 if (!wantPrefixPropagate && m_prefixPropagator !=
nullptr) {
212 m_prefixPropagator->disable();
215 if (wantReadvertiseNlsr && m_readvertiseNlsr ==
nullptr) {
217 m_readvertiseNlsr = make_unique<Readvertise>(
219 make_unique<ClientToNlsrReadvertisePolicy>(),
220 make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib));
222 else if (!wantReadvertiseNlsr && m_readvertiseNlsr !=
nullptr) {
224 m_readvertiseNlsr.reset();
static const Name READVERTISE_NLSR_PREFIX
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
static Service & get()
Get a reference to the only instance of this class.
static const std::string CFG_SECTION
configuration file parsing utility
static ConfigSection loadConfigSectionFromFile(const std::string &filename)
static const std::string CFG_LOCALHOST_SECURITY
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
static const std::string CFG_READVERTISE_NLSR
void enableLocalhop(const ConfigSection §ion, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix...
void registerWithNfd()
Start accepting commands and dataset requests.
void applyLocalhostConfig(const ConfigSection §ion, const std::string &filename)
Apply localhost_security configuration.
static shared_ptr< ndn::Transport > makeLocalNfdTransport(const ConfigSection &config)
Look into the config file and construct appropriate transport to communicate with NFD If NFD-RIB inst...
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands. ...
boost::asio::io_service & getRibIoService()
Service(const std::string &configFile, ndn::KeyChain &keyChain)
create NFD-RIB service
boost::property_tree::ptree ConfigSection
a config file section
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
static const std::string CFG_LOCALHOP_SECURITY
#define NFD_LOG_INIT(name)
static const std::string CFG_PREFIX_PROPAGATE
initializes and executes NFD-RIB service thread
static void ignoreUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
boost::asio::io_service & getGlobalIoService()