NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
channel-status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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 
26 
27 namespace ndn {
28 namespace nfd {
29 
30 BOOST_CONCEPT_ASSERT((StatusDatasetItem<ChannelStatus>));
31 
33 
35 {
36  this->wireDecode(payload);
37 }
38 
39 template<encoding::Tag TAG>
40 size_t
42 {
43  size_t totalLength = 0;
44  totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
45  totalLength += encoder.prependVarNumber(totalLength);
46  totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus);
47  return totalLength;
48 }
49 
51 
52 const Block&
54 {
55  if (m_wire.hasWire())
56  return m_wire;
57 
58  EncodingEstimator estimator;
59  size_t estimatedSize = wireEncode(estimator);
60 
61  EncodingBuffer buffer(estimatedSize, 0);
62  wireEncode(buffer);
63 
64  m_wire = buffer.block();
65  return m_wire;
66 }
67 
68 void
70 {
71  if (block.type() != tlv::nfd::ChannelStatus) {
72  BOOST_THROW_EXCEPTION(Error("Expecting ChannelStatus block"));
73  }
74  m_wire = block;
75  m_wire.parse();
77 
78  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
79  m_localUri = readString(*val);
80  ++val;
81  }
82  else {
83  BOOST_THROW_EXCEPTION(Error("Missing required LocalUri field"));
84  }
85 }
86 
88 ChannelStatus::setLocalUri(const std::string localUri)
89 {
90  m_wire.reset();
91  m_localUri = localUri;
92  return *this;
93 }
94 
95 bool
97 {
98  return a.getLocalUri() == b.getLocalUri();
99 }
100 
101 std::ostream&
102 operator<<(std::ostream& os, const ChannelStatus& status)
103 {
104  return os << "Channel(LocalUri: " << status.getLocalUri() << ")";
105 }
106 
107 } // namespace nfd
108 } // namespace ndn
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:249
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getLocalUri() const
const Block & wireEncode() const
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
void parse() const
Parse TLV-VALUE into sub elements.
Definition: block.cpp:333
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:369
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:377
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:255
concept check for an item in a Status Dataset
Definition: concepts.hpp:115
represents an item in NFD Channel dataset
void wireDecode(const Block &wire)
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:249
EncodingImpl< EstimatorTag > EncodingEstimator
ChannelStatus & setLocalUri(const std::string localUri)