NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
face-event-notification.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 #include "encoding/tlv-nfd.hpp"
25 #include "util/concepts.hpp"
26 
27 namespace ndn {
28 namespace nfd {
29 
30 //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceEventNotification>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<FaceEventNotification>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<FaceEventNotification>));
33 static_assert(std::is_base_of<tlv::Error, FaceEventNotification::Error>::value,
34  "FaceEventNotification::Error must inherit from tlv::Error");
35 
37  : m_kind(static_cast<FaceEventKind>(0))
38 {
39 }
40 
42 {
43  this->wireDecode(block);
44 }
45 
46 template<encoding::Tag TAG>
47 size_t
49 {
50  size_t totalLength = 0;
51 
52  totalLength += prependNonNegativeIntegerBlock(encoder,
54  totalLength += prependNonNegativeIntegerBlock(encoder,
56  totalLength += prependNonNegativeIntegerBlock(encoder,
58  totalLength += prependNonNegativeIntegerBlock(encoder,
60  totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri,
61  reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
62  totalLength += encoder.prependByteArrayBlock(tlv::nfd::Uri,
63  reinterpret_cast<const uint8_t*>(m_remoteUri.c_str()), m_remoteUri.size());
64  totalLength += prependNonNegativeIntegerBlock(encoder,
66  totalLength += prependNonNegativeIntegerBlock(encoder,
67  tlv::nfd::FaceEventKind, m_kind);
68 
69  totalLength += encoder.prependVarNumber(totalLength);
70  totalLength += encoder.prependVarNumber(tlv::nfd::FaceEventNotification);
71  return totalLength;
72 }
73 
74 const Block&
76 {
77  if (m_wire.hasWire())
78  return m_wire;
79 
80  EncodingEstimator estimator;
81  size_t estimatedSize = wireEncode(estimator);
82 
83  EncodingBuffer buffer(estimatedSize, 0);
84  wireEncode(buffer);
85 
86  m_wire = buffer.block();
87  return m_wire;
88 }
89 
90 void
92 {
93  if (block.type() != tlv::nfd::FaceEventNotification) {
94  BOOST_THROW_EXCEPTION(Error("expecting FaceEventNotification block"));
95  }
96  m_wire = block;
97  m_wire.parse();
99 
100  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceEventKind) {
101  m_kind = static_cast<FaceEventKind>(readNonNegativeInteger(*val));
102  ++val;
103  }
104  else {
105  BOOST_THROW_EXCEPTION(Error("missing required FaceEventKind field"));
106  }
107 
108  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
110  ++val;
111  }
112  else {
113  BOOST_THROW_EXCEPTION(Error("missing required FaceId field"));
114  }
115 
116  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
117  m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
118  ++val;
119  }
120  else {
121  BOOST_THROW_EXCEPTION(Error("missing required Uri field"));
122  }
123 
124  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
125  m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
126  ++val;
127  }
128  else {
129  BOOST_THROW_EXCEPTION(Error("missing required LocalUri field"));
130  }
131 
132  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
133  m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val));
134  ++val;
135  }
136  else {
137  BOOST_THROW_EXCEPTION(Error("missing required FaceScope field"));
138  }
139 
140  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
142  ++val;
143  }
144  else {
145  BOOST_THROW_EXCEPTION(Error("missing required FacePersistency field"));
146  }
147 
148  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
149  m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val));
150  ++val;
151  }
152  else {
153  BOOST_THROW_EXCEPTION(Error("missing required LinkType field"));
154  }
155 
156  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
158  }
159  else {
160  BOOST_THROW_EXCEPTION(Error("missing required Flags field"));
161  }
162 }
163 
166 {
167  m_wire.reset();
168  m_kind = kind;
169  return *this;
170 }
171 
172 void
174 {
175  m_wire.reset();
176 }
177 
178 std::ostream&
179 operator<<(std::ostream& os, const FaceEventNotification& notification)
180 {
181  os << "FaceEventNotification(";
182 
183  switch (notification.getKind())
184  {
185  case FACE_EVENT_CREATED:
186  os << "Kind: created, ";
187  break;
189  os << "Kind: destroyed, ";
190  break;
191  case FACE_EVENT_UP:
192  os << "Kind: up, ";
193  break;
194  case FACE_EVENT_DOWN:
195  os << "Kind: down, ";
196  break;
197  }
198 
199  os << "FaceID: " << notification.getFaceId() << ", "
200  << "RemoteUri: " << notification.getRemoteUri() << ", "
201  << "LocalUri: " << notification.getLocalUri() << ", "
202  << "FaceScope: " << notification.getFaceScope() << ", "
203  << "FacePersistency: " << notification.getFacePersistency() << ", "
204  << "LinkType: " << notification.getLinkType() << ", ";
205 
206  auto osFlags = os.flags();
207  os << "Flags: " << std::showbase << std::hex << notification.getFlags();
208  os.flags(osFlags);
209 
210  os << ")";
211  return os;
212 }
213 
214 } // namespace nfd
215 } // namespace ndn
const std::string & getLocalUri() const
Definition: face-traits.hpp:87
element_const_iterator elements_begin() const
Definition: block.cpp:589
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
Copyright (c) 2011-2015 Regents of the University of California.
face went UP (from DOWN state)
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
FacePersistency getFacePersistency() const
EncodingImpl< EstimatorTag > EncodingEstimator
element_const_iterator elements_end() const
Definition: block.cpp:595
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
represents a Face status change notification
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
FaceEventNotification & setKind(FaceEventKind kind)
FaceScope getFaceScope() const
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
const std::string & getRemoteUri() const
Definition: face-traits.hpp:73
EncodingImpl< EncoderTag > EncodingBuffer
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
element_container::const_iterator element_const_iterator
Definition: block.hpp:48
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
uint64_t getFlags() const
const Block & wireEncode() const
encode FaceEventNotification
void wireDecode(const Block &wire)
decode FaceEventNotification
face went DOWN (from UP state)
uint64_t getFaceId() const
Definition: face-traits.hpp:59
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:34
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:70
uint32_t type() const
Definition: block.hpp:324
LinkType getLinkType() const