NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
28 
29 namespace ndn {
30 namespace nfd {
31 
32 BOOST_CONCEPT_ASSERT((NotificationStreamItem<FaceEventNotification>));
33 
35  : m_kind(FACE_EVENT_NONE)
36 {
37 }
38 
40 {
41  this->wireDecode(block);
42 }
43 
44 template<encoding::Tag TAG>
45 size_t
47 {
48  size_t totalLength = 0;
49 
50  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
54  totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
55  totalLength += prependStringBlock(encoder, tlv::nfd::Uri, m_remoteUri);
57  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceEventKind, m_kind);
58 
59  totalLength += encoder.prependVarNumber(totalLength);
60  totalLength += encoder.prependVarNumber(tlv::nfd::FaceEventNotification);
61  return totalLength;
62 }
63 
65 
66 const Block&
68 {
69  if (m_wire.hasWire())
70  return m_wire;
71 
72  EncodingEstimator estimator;
73  size_t estimatedSize = wireEncode(estimator);
74 
75  EncodingBuffer buffer(estimatedSize, 0);
76  wireEncode(buffer);
77 
78  m_wire = buffer.block();
79  return m_wire;
80 }
81 
82 void
84 {
85  if (block.type() != tlv::nfd::FaceEventNotification) {
86  NDN_THROW(Error("FaceEventNotification", block.type()));
87  }
88 
89  m_wire = block;
90  m_wire.parse();
91  auto val = m_wire.elements_begin();
92 
93  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceEventKind) {
94  m_kind = readNonNegativeIntegerAs<FaceEventKind>(*val);
95  ++val;
96  }
97  else {
98  NDN_THROW(Error("missing required FaceEventKind field"));
99  }
100 
101  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
103  ++val;
104  }
105  else {
106  NDN_THROW(Error("missing required FaceId field"));
107  }
108 
109  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
110  m_remoteUri = readString(*val);
111  ++val;
112  }
113  else {
114  NDN_THROW(Error("missing required Uri field"));
115  }
116 
117  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
118  m_localUri = readString(*val);
119  ++val;
120  }
121  else {
122  NDN_THROW(Error("missing required LocalUri field"));
123  }
124 
125  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
126  m_faceScope = readNonNegativeIntegerAs<FaceScope>(*val);
127  ++val;
128  }
129  else {
130  NDN_THROW(Error("missing required FaceScope field"));
131  }
132 
133  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
134  m_facePersistency = readNonNegativeIntegerAs<FacePersistency>(*val);
135  ++val;
136  }
137  else {
138  NDN_THROW(Error("missing required FacePersistency field"));
139  }
140 
141  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
142  m_linkType = readNonNegativeIntegerAs<LinkType>(*val);
143  ++val;
144  }
145  else {
146  NDN_THROW(Error("missing required LinkType field"));
147  }
148 
149  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
151  ++val;
152  }
153  else {
154  NDN_THROW(Error("missing required Flags field"));
155  }
156 }
157 
160 {
161  m_wire.reset();
162  m_kind = kind;
163  return *this;
164 }
165 
166 bool
168 {
169  return a.getFaceId() == b.getFaceId() &&
170  a.getRemoteUri() == b.getRemoteUri() &&
171  a.getLocalUri() == b.getLocalUri() &&
172  a.getFaceScope() == b.getFaceScope() &&
174  a.getLinkType() == b.getLinkType() &&
175  a.getFlags() == b.getFlags() &&
176  a.getKind() == b.getKind();
177 }
178 
179 std::ostream&
180 operator<<(std::ostream& os, const FaceEventNotification& notification)
181 {
182  os << "FaceEvent(Kind: " << notification.getKind() << ",\n"
183  << " FaceId: " << notification.getFaceId() << ",\n"
184  << " RemoteUri: " << notification.getRemoteUri() << ",\n"
185  << " LocalUri: " << notification.getLocalUri() << ",\n"
186  << " FaceScope: " << notification.getFaceScope() << ",\n"
187  << " FacePersistency: " << notification.getFacePersistency() << ",\n"
188  << " LinkType: " << notification.getLinkType() << ",\n"
189  << " Flags: " << AsHex{notification.getFlags()} << "\n";
190 
191  return os << " )";
192 }
193 
194 } // namespace nfd
195 } // namespace ndn
ndn::nfd::FaceTraits::getFaceScope
FaceScope getFaceScope() const
Definition: face-traits.hpp:89
ndn::nfd::FaceTraits::getRemoteUri
const std::string & getRemoteUri() const
Definition: face-traits.hpp:61
ndn::nfd::FaceTraits< FaceEventNotification >::m_remoteUri
std::string m_remoteUri
Definition: face-traits.hpp:184
string-helper.hpp
ndn::tlv::nfd::LinkType
@ LinkType
Definition: tlv-nfd.hpp:69
ndn::nfd::FaceEventNotification::setKind
FaceEventNotification & setKind(FaceEventKind kind)
Definition: face-event-notification.cpp:159
ndn::tlv::nfd::FaceId
@ FaceId
Definition: tlv-nfd.hpp:36
ndn::nfd::operator<<
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Definition: nfd-constants.cpp:36
ndn::AsHex
Helper class to convert a number to hexadecimal format, for use with stream insertion operators.
Definition: string-helper.hpp:49
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:399
ndn::nfd::FaceTraits< FaceEventNotification >::m_faceId
uint64_t m_faceId
Definition: face-traits.hpp:183
ndn::encoding::readString
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
Definition: block-helpers.cpp:122
ndn::nfd::FaceEventNotification::getKind
FaceEventKind getKind() const
Definition: face-event-notification.hpp:61
ndn::nfd::FaceTraits::getFlags
uint64_t getFlags() const
Definition: face-traits.hpp:131
concepts.hpp
ndn::Block::reset
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:250
ndn::nfd::FaceTraits::getFaceId
uint64_t getFaceId() const
Definition: face-traits.hpp:47
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition: encoding-buffer-fwd.hpp:39
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Definition: block-helpers.cpp:64
ndn::tlv::nfd::FaceEventKind
@ FaceEventKind
Definition: tlv-nfd.hpp:75
ndn::nfd::FaceEventNotification
represents a Face status change notification
Definition: face-event-notification.hpp:36
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
ndn::Block::type
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition: block.hpp:274
ndn::nfd::FaceTraits::getLocalUri
const std::string & getLocalUri() const
Definition: face-traits.hpp:75
ndn::nfd::FaceTraits< FaceEventNotification >::m_linkType
LinkType m_linkType
Definition: face-traits.hpp:188
ndn::tlv::nfd::Uri
@ Uri
Definition: tlv-nfd.hpp:37
ndn::nfd::FaceTraits< FaceEventNotification >::m_faceScope
FaceScope m_faceScope
Definition: face-traits.hpp:186
ndn::nfd::FaceTraits< FaceEventNotification >::m_localUri
std::string m_localUri
Definition: face-traits.hpp:185
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn::nfd::FaceTraits< FaceEventNotification >::m_wire
Block m_wire
Definition: face-traits.hpp:191
ndn::nfd::FACE_EVENT_NONE
@ FACE_EVENT_NONE
Definition: nfd-constants.hpp:78
ndn::tlv::nfd::FaceEventNotification
@ FaceEventNotification
Definition: tlv-nfd.hpp:74
ndn::nfd::FaceTraits< FaceEventNotification >::m_facePersistency
FacePersistency m_facePersistency
Definition: face-traits.hpp:187
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:325
ndn::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Definition: block-helpers.cpp:35
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
tlv-nfd.hpp
ndn::nfd::FaceEventKind
FaceEventKind
Definition: nfd-constants.hpp:77
block-helpers.hpp
ndn::nfd::FaceEventNotification::wireEncode
const Block & wireEncode() const
encode FaceEventNotification
Definition: face-event-notification.cpp:67
ndn::nfd::FaceTraits< FaceEventNotification >::m_flags
uint64_t m_flags
Definition: face-traits.hpp:189
ndn::tlv::nfd::FacePersistency
@ FacePersistency
Definition: tlv-nfd.hpp:68
face-event-notification.hpp
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:407
ndn::nfd::FaceTraits::getFacePersistency
FacePersistency getFacePersistency() const
Definition: face-traits.hpp:103
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:230
ndn::tlv::nfd::LocalUri
@ LocalUri
Definition: tlv-nfd.hpp:64
ndn::tlv::nfd::FaceScope
@ FaceScope
Definition: tlv-nfd.hpp:67
ndn::nfd::FaceEventNotification::FaceEventNotification
FaceEventNotification()
Definition: face-event-notification.cpp:34
ndn::nfd::operator==
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
Definition: channel-status.cpp:97
ndn::nfd::FaceEventNotification::wireDecode
void wireDecode(const Block &wire)
decode FaceEventNotification
Definition: face-event-notification.cpp:83
ndn::encoding::prependStringBlock
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
Definition: block-helpers.cpp:104
ndn::nfd::FaceTraits::getLinkType
LinkType getLinkType() const
Definition: face-traits.hpp:117
ndn::nfd::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
encoding-buffer.hpp
ndn::tlv::nfd::Flags
@ Flags
Definition: tlv-nfd.hpp:42
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition: encoding-buffer-fwd.hpp:38
ndn::NotificationStreamItem
concept check for an item in a Notification Stream
Definition: concepts.hpp:124