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-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 
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  BOOST_THROW_EXCEPTION(Error("expecting StrategyChoice block"));
77  }
78  m_wire = block;
79  m_wire.parse();
81 
82  if (val != m_wire.elements_end() && val->type() == tlv::Name) {
83  m_name.wireDecode(*val);
84  ++val;
85  }
86  else {
87  BOOST_THROW_EXCEPTION(Error("missing required Name field"));
88  }
89 
90  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
91  val->parse();
92  if (val->elements().empty()) {
93  BOOST_THROW_EXCEPTION(Error("expecting Strategy/Name"));
94  }
95  else {
96  m_strategy.wireDecode(*val->elements_begin());
97  }
98  ++val;
99  }
100  else {
101  BOOST_THROW_EXCEPTION(Error("missing required Strategy field"));
102  }
103 }
104 
107 {
108  m_wire.reset();
109  m_name = name;
110  return *this;
111 }
112 
115 {
116  m_wire.reset();
117  m_strategy = strategy;
118  return *this;
119 }
120 
121 bool
123 {
124  return a.getName() == b.getName() && a.getStrategy() == b.getStrategy();
125 }
126 
127 std::ostream&
128 operator<<(std::ostream& os, const StrategyChoice& sc)
129 {
130  return os << "StrategyChoice("
131  << "Name: " << sc.getName() << ", "
132  << "Strategy: " << sc.getStrategy()
133  << ")";
134 }
135 
136 } // namespace nfd
137 } // 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.
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
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:333
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
const Name & getName() const
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:369
void wireDecode(const Block &wire)
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)
const Name & getStrategy() const
StrategyChoice & setStrategy(const Name &strategy)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:255
Represents an absolute name.
Definition: name.hpp:43
const Block & wireEncode() const
concept check for an item in a Status Dataset
Definition: concepts.hpp:115
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:125
represents an item in NFD StrategyChoice dataset
void wireDecode(const Block &wire)
Decode name from wire encoding.
Definition: name.cpp:158
StrategyChoice & setName(const Name &name)
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:249
EncodingImpl< EstimatorTag > EncodingEstimator