NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
face-manager.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_MGMT_FACE_MANAGER_HPP
27 #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP
28 
29 #include "common.hpp"
31 #include "face/local-face.hpp"
32 #include "mgmt/manager-base.hpp"
36 
37 #include <ndn-cxx/management/nfd-control-parameters.hpp>
38 #include <ndn-cxx/management/nfd-control-response.hpp>
39 
40 namespace nfd {
41 
42 const std::string FACE_MANAGER_PRIVILEGE = "faces";
43 
44 class ConfigFile;
45 class Face;
46 class FaceTable;
47 class LocalFace;
49 class ProtocolFactory;
50 
51 class FaceManager : public ManagerBase
52 {
53 public:
54  class Error : public ManagerBase::Error
55  {
56  public:
57  Error(const std::string& what) : ManagerBase::Error(what) {}
58  };
59 
63  FaceManager(FaceTable& faceTable,
64  shared_ptr<InternalFace> face,
65  ndn::KeyChain& keyChain);
66 
67  virtual
68  ~FaceManager();
69 
72  void
73  setConfigFile(ConfigFile& configFile);
74 
75  void
76  onFaceRequest(const Interest& request);
77 
79  void
80  listFaces(const Interest& request);
81 
82  void
83  listChannels(const Interest& request);
84 
85  void
86  listQueriedFaces(const Interest& request);
87 
88  shared_ptr<ProtocolFactory>
89  findFactory(const std::string& protocol);
90 
92  void
93  onValidatedFaceRequest(const shared_ptr<const Interest>& request);
94 
96  createFace(const Interest& request,
97  ControlParameters& parameters);
98 
100  destroyFace(const Interest& request,
101  ControlParameters& parameters);
102 
103  VIRTUAL_WITH_TESTS bool
104  extractLocalControlParameters(const Interest& request,
105  ControlParameters& parameters,
106  ControlCommand& command,
107  shared_ptr<LocalFace>& outFace,
108  LocalControlFeature& outFeature);
109 
110  VIRTUAL_WITH_TESTS void
111  enableLocalControl(const Interest& request,
112  ControlParameters& parambeters);
113 
114  VIRTUAL_WITH_TESTS void
115  disableLocalControl(const Interest& request,
116  ControlParameters& parameters);
117 
118  void
119  ignoreUnsignedVerb(const Interest& request);
120 
121  void
122  addCreatedFaceToForwarder(const shared_ptr<Face>& newFace);
123 
124  void
125  onCreated(const Name& requestName,
126  ControlParameters& parameters,
127  const shared_ptr<Face>& newFace);
128 
129  void
130  onConnectFailed(const Name& requestName, const std::string& reason);
131 
132  void
133  onAddFace(shared_ptr<Face> face);
134 
135  void
136  onRemoveFace(shared_ptr<Face> face);
137 
138 private:
139  void
140  onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
141 
146  bool
147  parseYesNo(const ConfigSection::const_iterator& i,
148  const std::string& optionName,
149  const std::string& sectionName);
150 
152  typedef std::map<std::string/*protocol*/, shared_ptr<ProtocolFactory>> FactoryMap;
153  FactoryMap m_factories;
154 
155 private:
156  FaceTable& m_faceTable;
157  signal::ScopedConnection m_faceAddConn;
158  signal::ScopedConnection m_faceRemoveConn;
159  FaceStatusPublisher m_faceStatusPublisher;
160  ChannelStatusPublisher m_channelStatusPublisher;
161  NotificationStream<AppFace> m_notificationStream;
162 
163  typedef function<void(FaceManager*,
164  const Interest&,
165  ControlParameters&)> SignedVerbProcessor;
166 
167  typedef std::map<Name::Component, SignedVerbProcessor> SignedVerbDispatchTable;
168  typedef std::pair<Name::Component, SignedVerbProcessor> SignedVerbAndProcessor;
169 
170  typedef function<void(FaceManager*, const Interest&)> UnsignedVerbProcessor;
171 
172  typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable;
173  typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor;
174 
175  const SignedVerbDispatchTable m_signedVerbDispatch;
176  const UnsignedVerbDispatchTable m_unsignedVerbDispatch;
177 
178  static const Name COMMAND_PREFIX; // /localhost/nfd/faces
179 
180  // number of components in an invalid signed command (i.e. should be signed, but isn't)
181  // (/localhost/nfd/faces + verb + parameters) = 5
182  static const size_t COMMAND_UNSIGNED_NCOMPS;
183 
184  // number of components in a valid signed command.
185  // (see UNSIGNED_NCOMPS), 9 with signed Interest support.
186  static const size_t COMMAND_SIGNED_NCOMPS;
187 
188  static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[];
189  static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[];
190 
191  static const Name FACES_LIST_DATASET_PREFIX;
192  static const size_t FACES_LIST_DATASET_NCOMPS;
193 
194  static const Name CHANNELS_LIST_DATASET_PREFIX;
195  static const size_t CHANNELS_LIST_DATASET_NCOMPS;
196 
197  static const Name FACES_QUERY_DATASET_PREFIX;
198  static const size_t FACES_QUERY_DATASET_NCOMPS;
199 
200  static const Name FACE_EVENTS_PREFIX;
201 };
202 
203 inline bool
204 FaceManager::parseYesNo(const ConfigSection::const_iterator& i,
205  const std::string& optionName,
206  const std::string& sectionName)
207 {
208  const std::string value = i->second.get_value<std::string>();
209  if (value == "yes")
210  {
211  return true;
212  }
213  else if (value == "no")
214  {
215  return false;
216  }
217 
218  BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
219  optionName + "\" in \"" +
220  sectionName + "\" section"));
221 }
222 
223 inline void
224 FaceManager::ignoreUnsignedVerb(const Interest& request)
225 {
226  // do nothing
227 }
228 
229 } // namespace nfd
230 
231 #endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP
FaceManager(FaceTable &faceTable, shared_ptr< InternalFace > face, ndn::KeyChain &keyChain)
void setConfigFile(ConfigFile &configFile)
Subscribe to a face management section(s) for the config file.
Error(const std::string &what)
represents parameters in a ControlCommand request or response
provides a publisher of Notification Stream
contains information about a network interface
base class of NFD ControlCommand
represents an Interest packet
Definition: interest.hpp:45
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
represents a face
Definition: face.hpp:57
container of all Faces
Definition: face-table.hpp:38
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void onFaceRequest(const Interest &request)
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:37
disconnects a Connection automatically upon destruction
const std::string FACE_MANAGER_PRIVILEGE
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual ~FaceManager()
represents a face
Definition: local-face.hpp:40
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39