nfd-rib-readvertise-destination.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 #include "core/logger.hpp"
28 
29 #include <ndn-cxx/mgmt/nfd/command-options.hpp>
30 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
31 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
32 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
33 
34 namespace nfd {
35 namespace rib {
36 
37 NFD_LOG_INIT("NfdRibReadvertiseDestination");
38 
39 using ndn::nfd::CommandOptions;
40 using ndn::nfd::ControlParameters;
41 using ndn::nfd::ControlResponse;
42 
44  const Name& commandPrefix,
45  Rib& rib)
46  : m_controller(controller)
47  , m_commandPrefix(commandPrefix)
48 {
49  m_ribInsertConn = rib.afterInsertEntry.connect(
50  std::bind(&NfdRibReadvertiseDestination::handleRibInsert, this, _1));
51  m_ribEraseConn = rib.afterEraseEntry.connect(
52  std::bind(&NfdRibReadvertiseDestination::handleRibErase, this, _1));
53 }
54 
55 void
57  std::function<void()> successCb,
58  std::function<void(const std::string&)> failureCb)
59 {
60  NFD_LOG_DEBUG("advertise " << rr.prefix << " on " << m_commandPrefix);
61 
62  m_controller.start<ndn::nfd::RibRegisterCommand>(
63  ControlParameters().setName(rr.prefix).setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT),
64  [=] (const ControlParameters& cp) { successCb(); },
65  [=] (const ControlResponse& cr) { failureCb(cr.getText()); },
66  CommandOptions().setPrefix(m_commandPrefix).setSigningInfo(rr.signer));
67 }
68 
69 void
71  std::function<void()> successCb,
72  std::function<void(const std::string&)> failureCb)
73 {
74  NFD_LOG_DEBUG("withdraw " << rr.prefix << " on " << m_commandPrefix);
75 
76  m_controller.start<ndn::nfd::RibUnregisterCommand>(
77  ControlParameters().setName(rr.prefix).setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT),
78  [=] (const ControlParameters& cp) { successCb(); },
79  [=] (const ControlResponse& cr) { failureCb(cr.getText()); },
80  CommandOptions().setPrefix(m_commandPrefix).setSigningInfo(rr.signer));
81 }
82 
83 void
84 NfdRibReadvertiseDestination::handleRibInsert(const ndn::Name& name)
85 {
86  if (name.isPrefixOf(m_commandPrefix)) {
87  setAvailability(true);
88  }
89 }
90 
91 void
92 NfdRibReadvertiseDestination::handleRibErase(const ndn::Name& name)
93 {
94  if (name.isPrefixOf(m_commandPrefix)) {
95  setAvailability(false);
96  }
97 }
98 
99 } // namespace rib
100 } // namespace nfd
void withdraw(const ReadvertisedRoute &rr, std::function< void()> successCb, std::function< void(const std::string &)> failureCb) override
remove a name prefix from NFD RIB
represents the Routing Information Base
Definition: rib.hpp:59
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:161
state of a readvertised route
Name prefix
readvertised prefix
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:233
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
ndn::security::SigningInfo signer
signer for commands
void advertise(const ReadvertisedRoute &rr, std::function< void()> successCb, std::function< void(const std::string &)> failureCb) override
add a name prefix into NFD RIB
#define NFD_LOG_INIT(name)
Definition: logger.hpp:122
NfdRibReadvertiseDestination(ndn::nfd::Controller &controller, const Name &commandPrefix, Rib &rib)
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:225