nfd-rib-readvertise-destination.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
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
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:241
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
#define NFD_LOG_DEBUG
Definition: logger.hpp:38
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:31
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:233