NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
strategy-choice-manager.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
28 #include <ndn-cxx/mgmt/nfd/strategy-choice.hpp>
29 
30 namespace nfd {
31 
32 NFD_LOG_INIT("StrategyChoiceManager");
33 
35  Dispatcher& dispatcher,
36  CommandAuthenticator& authenticator)
37  : NfdManagerBase(dispatcher, authenticator, "strategy-choice")
38  , m_table(strategyChoice)
39 {
40  registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>("set",
41  bind(&StrategyChoiceManager::setStrategy, this, _2, _3, _4, _5));
42  registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>("unset",
43  bind(&StrategyChoiceManager::unsetStrategy, this, _2, _3, _4, _5));
44 
46  bind(&StrategyChoiceManager::listChoices, this, _1, _2, _3));
47 }
48 
49 void
50 StrategyChoiceManager::setStrategy(const Name& topPrefix, const Interest& interest,
51  ControlParameters parameters,
53 {
54  const Name& prefix = parameters.getName();
55  const Name& selectedStrategy = parameters.getStrategy();
56 
57  if (!m_table.hasStrategy(selectedStrategy)) {
58  NFD_LOG_DEBUG("strategy-choice result: FAIL reason: unknown-strategy: "
59  << parameters.getStrategy());
60  return done(ControlResponse(504, "Unsupported strategy"));
61  }
62 
63  if (m_table.insert(prefix, selectedStrategy)) {
64  NFD_LOG_DEBUG("strategy-choice result: SUCCESS");
65  auto currentStrategyChoice = m_table.get(prefix);
66  BOOST_ASSERT(currentStrategyChoice.first);
67  parameters.setStrategy(currentStrategyChoice.second);
68  return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
69  }
70  else {
71  NFD_LOG_DEBUG("strategy-choice result: FAIL reason: not-installed");
72  return done(ControlResponse(405, "Strategy not installed"));
73  }
74 }
75 
76 void
77 StrategyChoiceManager::unsetStrategy(const Name& topPrefix, const Interest& interest,
78  ControlParameters parameters,
80 {
81  m_table.erase(parameters.getName());
82 
83  NFD_LOG_DEBUG("strategy-choice result: SUCCESS");
84  done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
85 }
86 
87 void
88 StrategyChoiceManager::listChoices(const Name& topPrefix, const Interest& interest,
90 {
91  for (auto&& i : m_table) {
93  entry.setName(i.getPrefix()).setStrategy(i.getStrategyName());
94  context.append(entry.wireEncode());
95  }
96  context.end();
97 }
98 
99 } // namespace nfd
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
StrategyChoiceManager(strategy_choice::StrategyChoice &table, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:129
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
size_t wireEncode(EncodingImpl< TAG > &encoder) const
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
represents an Interest packet
Definition: interest.hpp:42
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:55
ControlParameters & setStrategy(const Name &strategy)
ndn::mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void end()
end the response successfully after appending zero or more blocks
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Name abstraction to represent an absolute name.
Definition: name.hpp:46
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
provides ControlCommand authorization according to NFD configuration file
represents the Strategy Choice table
void append(const Block &block)
append a Block to the response
represents NFD StrategyChoice dataset
provides a context for generating response to a StatusDataset request
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
#define NFD_LOG_INIT(name)
Definition: logger.hpp:34
const Name & getStrategy() const
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
StrategyChoice & setName(const Name &name)