All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndnd-face-instance.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP
8 #define NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP
9 
10 #include "../encoding/tlv-ndnd.hpp"
11 #include "../encoding/block.hpp"
12 #include "../name.hpp"
13 
14 namespace ndn {
15 namespace ndnd {
16 
21 {
22 public:
23  FaceInstance(const std::string& action,
24  int64_t faceId,
25  uint32_t ipProto,
26  const std::string& host,
27  const std::string& port,
28  const std::string& multicastInterface,
29  uint32_t multicastTtl,
30  const time::milliseconds& freshnessPeriod)
31  : action_(action)
32  , faceId_(faceId)
33  , ipProto_(ipProto)
34  , host_(host)
35  , port_(port)
36  , multicastInterface_(multicastInterface)
37  , multicastTtl_(multicastTtl)
38  , freshnessPeriod_(freshnessPeriod)
39  {
40  }
41 
43  : faceId_(-1)
44  , ipProto_(-1)
45  , multicastTtl_(-1)
46  , freshnessPeriod_(time::milliseconds::min())
47  {
48  }
49 
53  explicit
54  FaceInstance(const Block& wire)
55  {
56  wireDecode(wire);
57  }
58 
59  // Action
60  const std::string&
61  getAction() const { return action_; }
62 
63  void
64  setAction(const std::string& action) { action_ = action; wire_.reset(); }
65 
66  // FaceID
67  int64_t
68  getFaceId() const { return faceId_; }
69 
70  void
71  setFaceId(int64_t faceId) { faceId_ = faceId; wire_.reset(); }
72 
73  // IPProto
74  int32_t
75  getIpProto() const { return ipProto_; }
76 
77  void
78  setIpProto(int32_t ipProto) { ipProto_ = ipProto; wire_.reset(); }
79 
80  // Host
81  const std::string&
82  getHost() const { return host_; }
83 
84  void
85  setHost(const std::string& host) { host_ = host; wire_.reset(); }
86 
87  // Port
88  const std::string&
89  getPort() const { return port_; }
90 
91  void
92  setPort(const std::string& port) { port_ = port; wire_.reset(); }
93 
94  // MulticastInterface
95  const std::string&
96  getMulticastInterface() const { return multicastInterface_; }
97 
98  void
99  setMulticastInterface(const std::string& multicastInterface)
100  {
101  multicastInterface_ = multicastInterface; wire_.reset();
102  }
103 
104  // MulticastTTL
105  int32_t
106  getMulticastTtl() const { return multicastTtl_; }
107 
108  void
109  setMulticastTtl(int32_t multicastTtl) { multicastTtl_ = multicastTtl; wire_.reset(); }
110 
111  // Freshness
112  const time::milliseconds&
113  getFreshnessPeriod() const { return freshnessPeriod_; }
114 
115  void
116  setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
117  {
118  freshnessPeriod_ = freshnessPeriod; wire_.reset();
119  }
120 
121  // Wire
122  inline const Block&
123  wireEncode() const;
124 
125  inline void
126  wireDecode(const Block& wire);
127 
128 private:
129  std::string action_;
130  int64_t faceId_;
131  int32_t ipProto_;
132  std::string host_;
133  std::string port_;
134  std::string multicastInterface_;
135  int32_t multicastTtl_;
136  time::milliseconds freshnessPeriod_;
137 
138  mutable Block wire_;
139 };
140 
141 inline const Block&
143 {
144  if (wire_.hasWire())
145  return wire_;
146 
147  // FaceInstance ::= FACE-INSTANCE-TYPE TLV-LENGTH
148  // Action?
149  // FaceID?
150  // IPProto?
151  // Host?
152  // Port?
153  // MulticastInterface?
154  // MulticastTTL?
155  // FreshnessPeriod?
156 
158 
159  // Action
160  if (!action_.empty())
161  {
162  wire_.push_back
163  (dataBlock(tlv::ndnd::Action, action_.c_str(), action_.size()));
164  }
165 
166  // FaceID
167  if (faceId_ >= 0)
168  {
169  wire_.push_back
171  }
172 
173  // IPProto
174  if (ipProto_ >= 0)
175  {
176  wire_.push_back
178  }
179 
180  // Host
181  if (!host_.empty())
182  {
183  wire_.push_back
184  (dataBlock(tlv::ndnd::Host, host_.c_str(), host_.size()));
185  }
186 
187  // Port
188  if (!port_.empty())
189  {
190  wire_.push_back
191  (dataBlock(tlv::ndnd::Port, port_.c_str(), port_.size()));
192  }
193 
194  // MulticastInterface
195  if (!multicastInterface_.empty())
196  {
197  wire_.push_back
198  (dataBlock(tlv::ndnd::MulticastInterface, multicastInterface_.c_str(), multicastInterface_.size()));
199  }
200 
201  // MulticastTTL
202  if (multicastTtl_ >= 0)
203  {
204  wire_.push_back
206  }
207 
208  // FreshnessPeriod
209  if (freshnessPeriod_ >= time::milliseconds::zero())
210  {
211  wire_.push_back
212  (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_.count()));
213  }
214 
215  wire_.encode();
216  return wire_;
217 }
218 
219 inline void
221 {
222  action_.clear();
223  faceId_ = -1;
224  ipProto_ = -1;
225  host_.clear();
226  port_.clear();
227  multicastInterface_.clear();
228  multicastTtl_ = -1;
229  freshnessPeriod_ = time::milliseconds::min();
230 
231  wire_ = wire;
232  wire_.parse();
233 
234  // FaceInstance ::= FACE-INSTANCE-TYPE TLV-LENGTH
235  // Action?
236  // FaceID?
237  // IPProto?
238  // Host?
239  // Port?
240  // MulticastInterface?
241  // MulticastTTL?
242  // FreshnessPeriod?
243 
244  // Action
246  if (val != wire_.elements_end())
247  {
248  action_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size());
249  }
250 
251  // FaceID
252  val = wire_.find(tlv::ndnd::FaceID);
253  if (val != wire_.elements_end())
254  {
255  faceId_ = readNonNegativeInteger(*val);
256  }
257 
258  // IPProto
259  val = wire_.find(tlv::ndnd::IPProto);
260  if (val != wire_.elements_end())
261  {
262  ipProto_ = readNonNegativeInteger(*val);
263  }
264 
265  // Host
266  val = wire_.find(tlv::ndnd::Host);
267  if (val != wire_.elements_end())
268  {
269  host_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size());
270  }
271 
272  // Port
273  val = wire_.find(tlv::ndnd::Port);
274  if (val != wire_.elements_end())
275  {
276  port_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size());
277  }
278 
279  // MulticastInterface
280  val = wire_.find(tlv::ndnd::MulticastInterface);
281  if (val != wire_.elements_end())
282  {
283  multicastInterface_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size());
284  }
285 
286  // MulticastTTL
287  val = wire_.find(tlv::ndnd::MulticastTTL);
288  if (val != wire_.elements_end())
289  {
290  multicastTtl_ = readNonNegativeInteger(*val);
291  }
292 
293  // FreshnessPeriod
294  val = wire_.find(Tlv::FreshnessPeriod);
295  if (val != wire_.elements_end())
296  {
297  freshnessPeriod_ = time::milliseconds(readNonNegativeInteger(*val));
298  }
299 }
300 
301 inline std::ostream&
302 operator << (std::ostream& os, const FaceInstance& entry)
303 {
304  os << "FaceInstance(";
305 
306  // Action
307  if (!entry.getAction().empty())
308  {
309  os << "Action:" << entry.getAction() << ", ";
310  }
311 
312  // FaceID
313  if (entry.getFaceId() >= 0)
314  {
315  os << "FaceID:" << entry.getFaceId() << ", ";
316  }
317 
318  // IPProto
319  if (entry.getIpProto() >= 0)
320  {
321  os << "IPProto:" << entry.getIpProto() << ", ";
322  }
323 
324  // Host
325  if (!entry.getHost().empty())
326  {
327  os << "Host:" << entry.getHost() << ", ";
328  }
329 
330  // Port
331  if (!entry.getPort().empty())
332  {
333  os << "Port:" << entry.getPort() << ", ";
334  }
335 
336  // MulticastInterface
337  if (!entry.getMulticastInterface().empty())
338  {
339  os << "MulticastInterface:" << entry.getMulticastInterface() << ", ";
340  }
341 
342  // MulticastTTL
343  if (entry.getMulticastTtl() >= 0)
344  {
345  os << "MulticastTTL:" << entry.getMulticastTtl() << ", ";
346  }
347 
348  // FreshnessPeriod
349  if (entry.getFreshnessPeriod() >= time::milliseconds::zero())
350  {
351  os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", ";
352  }
353 
354  os << ")";
355  return os;
356 }
357 
358 } // namespace ndnd
359 } // namespace ndn
360 
361 #endif // NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP
FaceInstance(const Block &wire)
Create from wire encoding.
FaceInstance(const std::string &action, int64_t faceId, uint32_t ipProto, const std::string &host, const std::string &port, const std::string &multicastInterface, uint32_t multicastTtl, const time::milliseconds &freshnessPeriod)
const std::string & getAction() const
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
const time::milliseconds & getFreshnessPeriod() const
element_const_iterator find(uint32_t type) const
Definition: block.hpp:343
const std::string & getMulticastInterface() const
void wireDecode(const Block &wire)
void setPort(const std::string &port)
void setHost(const std::string &host)
int32_t getMulticastTtl() const
Class representing wire element of the NDN packet.
Definition: block.hpp:26
void setMulticastInterface(const std::string &multicastInterface)
void setAction(const std::string &action)
uint64_t readNonNegativeInteger(const Block &block)
element_const_iterator elements_end() const
Definition: block.hpp:476
const std::string & getPort() const
void setFaceId(int64_t faceId)
An FaceInstance holds an action and Name prefix and other fields for an forwarding entry...
element_container::const_iterator element_const_iterator
Definition: block.hpp:31
void reset()
Reset wire buffer of the element.
Definition: block.hpp:300
void push_back(const Block &element)
Definition: block.hpp:390
const Block & wireEncode() const
const std::string & getHost() const
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:265
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:298
void setFreshnessPeriod(const time::milliseconds &freshnessPeriod)
Block dataBlock(uint32_t type, const char *data, size_t dataSize)
std::ostream & operator<<(std::ostream &os, const FaceInstance &entry)
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.hpp:288
void setIpProto(int32_t ipProto)
void setMulticastTtl(int32_t multicastTtl)