manager-base.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "manager-base.hpp"
23 #include <iostream>
24 
25 namespace nlsr {
26 namespace update {
27 
28 INIT_LOGGER("UpdatePrefixCommandProcessor");
29 
30 ManagerBase::ManagerBase(ndn::mgmt::Dispatcher& dispatcher,
31  const std::string& module)
32  : m_dispatcher(dispatcher)
33  , m_module(module)
34 {
35 }
36 
37 ndn::PartialName
38 ManagerBase::makeRelPrefix(const std::string& verb) const
39 {
40  return ndn::PartialName(m_module).append(verb);
41 }
42 
43 CommandManagerBase::CommandManagerBase(ndn::mgmt::Dispatcher& dispatcher,
44  NamePrefixList& namePrefixList,
45  Lsdb& lsdb,
46  const std::string& module)
47  : ManagerBase(dispatcher, module)
48  , m_namePrefixList(namePrefixList)
49  , m_lsdb(lsdb)
50 {
51 }
52 
53 void
55  const ndn::Interest& interest,
56  const ndn::mgmt::ControlParameters& parameters,
57  const ndn::mgmt::CommandContinuation& done)
58 {
59  const ndn::nfd::ControlParameters& castParams =
60  static_cast<const ndn::nfd::ControlParameters&>(parameters);
61 
62  // Only build a Name LSA if the added name is new
63  if (m_namePrefixList.insert(castParams.getName())) {
64  NLSR_LOG_INFO("Advertising/Inserting name: " << castParams.getName() << "\n");
66  return done(ndn::nfd::ControlResponse(200, "OK").setBody(parameters.wireEncode()));
67  }
68 
69  return done(ndn::nfd::ControlResponse(204, "Prefix is already advetised/inserted.").setBody(parameters.wireEncode()));
70 }
71 
72 void
74  const ndn::Interest& interest,
75  const ndn::mgmt::ControlParameters& parameters,
76  const ndn::mgmt::CommandContinuation& done)
77 {
78  const ndn::nfd::ControlParameters& castParams =
79  static_cast<const ndn::nfd::ControlParameters&>(parameters);
80 
81  // Only build a Name LSA if the added name is new
82  if (m_namePrefixList.remove(castParams.getName())) {
83  NLSR_LOG_INFO("Withdrawing/Removing name: " << castParams.getName() << "\n");
85  return done(ndn::nfd::ControlResponse(200, "OK").setBody(parameters.wireEncode()));
86  }
87 
88  return done(ndn::nfd::ControlResponse(204, "Prefix is already withdrawn/removed.").setBody(parameters.wireEncode()));
89 }
90 
91 } // namespace update
92 } // namespace nlsr
bool remove(const ndn::Name &name, const std::string &source="")
removes name from NamePrefixList
bool insert(const ndn::Name &name, const std::string &source="")
inserts name into NamePrefixList
void advertiseAndInsertPrefix(const ndn::Name &prefix, const ndn::Interest &interest, const ndn::mgmt::ControlParameters &parameters, const ndn::mgmt::CommandContinuation &done)
add desired name prefix to the advertised name prefix list or insert a prefix into the FIB if paramet...
#define INIT_LOGGER(name)
Definition: logger.hpp:35
ManagerBase(ndn::mgmt::Dispatcher &m_dispatcher, const std::string &module)
#define NLSR_LOG_INFO(x)
Definition: logger.hpp:44
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
CommandManagerBase(ndn::mgmt::Dispatcher &m_dispatcher, NamePrefixList &m_namePrefixList, Lsdb &lsdb, const std::string &module)
void withdrawAndRemovePrefix(const ndn::Name &prefix, const ndn::Interest &interest, const ndn::mgmt::ControlParameters &parameters, const ndn::mgmt::CommandContinuation &done)
remove desired name prefix from the advertised name prefix list or remove a prefix from the FIB if pa...
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
Definition: lsdb.cpp:161
ndn::PartialName makeRelPrefix(const std::string &verb) const
generate the relative prefix for a handler by appending the verb name to the module name ...