NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
strategy-choice.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 
27 
28 namespace ndn {
29 namespace nfd {
30 
31 BOOST_CONCEPT_ASSERT((StatusDatasetItem<StrategyChoice>));
32 
34 
36 {
37  this->wireDecode(payload);
38 }
39 
40 template<encoding::Tag TAG>
41 size_t
43 {
44  size_t totalLength = 0;
45 
46  totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
47  totalLength += m_name.wireEncode(encoder);
48 
49  totalLength += encoder.prependVarNumber(totalLength);
50  totalLength += encoder.prependVarNumber(tlv::nfd::StrategyChoice);
51  return totalLength;
52 }
53 
55 
56 const Block&
58 {
59  if (m_wire.hasWire())
60  return m_wire;
61 
62  EncodingEstimator estimator;
63  size_t estimatedSize = wireEncode(estimator);
64 
65  EncodingBuffer buffer(estimatedSize, 0);
66  wireEncode(buffer);
67 
68  m_wire = buffer.block();
69  return m_wire;
70 }
71 
72 void
74 {
75  if (block.type() != tlv::nfd::StrategyChoice) {
76  NDN_THROW(Error("StrategyChoice", block.type()));
77  }
78 
79  m_wire = block;
80  m_wire.parse();
81  auto val = m_wire.elements_begin();
82 
83  if (val != m_wire.elements_end() && val->type() == tlv::Name) {
84  m_name.wireDecode(*val);
85  ++val;
86  }
87  else {
88  NDN_THROW(Error("missing required Name field"));
89  }
90 
91  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
92  val->parse();
93  if (val->elements().empty()) {
94  NDN_THROW(Error("expecting Strategy/Name"));
95  }
96  else {
97  m_strategy.wireDecode(*val->elements_begin());
98  }
99  ++val;
100  }
101  else {
102  NDN_THROW(Error("missing required Strategy field"));
103  }
104 }
105 
108 {
109  m_wire.reset();
110  m_name = name;
111  return *this;
112 }
113 
116 {
117  m_wire.reset();
118  m_strategy = strategy;
119  return *this;
120 }
121 
122 bool
124 {
125  return a.getName() == b.getName() && a.getStrategy() == b.getStrategy();
126 }
127 
128 std::ostream&
129 operator<<(std::ostream& os, const StrategyChoice& sc)
130 {
131  return os << "StrategyChoice("
132  << "Name: " << sc.getName() << ", "
133  << "Strategy: " << sc.getStrategy()
134  << ")";
135 }
136 
137 } // namespace nfd
138 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
size_t prependNestedBlock(EncodingImpl< TAG > &encoder, uint32_t type, const U &value)
Prepend a TLV element containing a nested TLV element.
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:324
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:221
const Name & getName() const
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:433
#define NDN_THROW(e)
Definition: exception.hpp:61
void wireDecode(const Block &wire)
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:441
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:254
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
const Name & getStrategy() const
StrategyChoice & setStrategy(const Name &strategy)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Represents an absolute name.
Definition: name.hpp:41
const Block & wireEncode() const
concept check for an item in a Status Dataset
Definition: concepts.hpp:115
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition: block.hpp:277
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:117
represents an item in NFD StrategyChoice dataset
void wireDecode(const Block &wire)
Decode name from wire encoding.
Definition: name.cpp:150
StrategyChoice & setName(const Name &name)
EncodingImpl< EncoderTag > EncodingBuffer
EncodingImpl< EstimatorTag > EncodingEstimator