NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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 
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>(
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 
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 start(const ControlParameters &parameters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
Definition: controller.hpp:74
represents the Routing Information Base
Definition: rib.hpp:59
represents parameters in a ControlCommand request or response
void withdraw(const ReadvertisedRoute &rr, std::function< void()> successCb, std::function< void(const std::string &)> failureCb) override
remove a name prefix from NFD RIB
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:55
void advertise(const ReadvertisedRoute &rr, std::function< void()> successCb, std::function< void(const std::string &)> failureCb) override
add a name prefix into NFD RIB
mgmt::ControlResponse ControlResponse
contains options for ControlCommand execution
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
state of a readvertised route
ndn::security::SigningInfo signer
signer for commands
Name prefix
readvertised prefix
NFD Management protocol client.
Definition: controller.hpp:50
Represents an absolute name.
Definition: name.hpp:42
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:260
represents a rib/unregister command
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters
represents a rib/register command
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:225
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:233
NfdRibReadvertiseDestination(ndn::nfd::Controller &controller, const Name &commandPrefix, Rib &rib)
#define NFD_LOG_INIT(name)
Definition: logger.hpp:34
CommandOptions & setPrefix(const Name &prefix)
sets command prefix