NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22 #include "strategy-choice.hpp"
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<StrategyChoice>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<StrategyChoice>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<StrategyChoice>));
33 static_assert(std::is_base_of<tlv::Error, StrategyChoice::Error>::value,
34  "StrategyChoice::Error must inherit from tlv::Error");
35 
37 {
38 }
39 
41 {
42  this->wireDecode(payload);
43 }
44 
45 template<encoding::Tag TAG>
46 size_t
48 {
49  size_t totalLength = 0;
50 
51  totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
52  totalLength += m_name.wireEncode(encoder);
53 
54  totalLength += encoder.prependVarNumber(totalLength);
55  totalLength += encoder.prependVarNumber(tlv::nfd::StrategyChoice);
56  return totalLength;
57 }
58 
59 template size_t
60 StrategyChoice::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>&) const;
61 
62 template size_t
63 StrategyChoice::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
64 
65 const Block&
67 {
68  if (m_wire.hasWire())
69  return m_wire;
70 
71  EncodingEstimator estimator;
72  size_t estimatedSize = wireEncode(estimator);
73 
74  EncodingBuffer buffer(estimatedSize, 0);
75  wireEncode(buffer);
76 
77  m_wire = buffer.block();
78  return m_wire;
79 }
80 
81 void
83 {
84  if (block.type() != tlv::nfd::StrategyChoice) {
85  BOOST_THROW_EXCEPTION(Error("expecting StrategyChoice block"));
86  }
87  m_wire = block;
88  m_wire.parse();
90 
91  if (val != m_wire.elements_end() && val->type() == tlv::Name) {
92  m_name.wireDecode(*val);
93  ++val;
94  }
95  else {
96  BOOST_THROW_EXCEPTION(Error("missing required Name field"));
97  }
98 
99  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
100  val->parse();
101  if (val->elements().empty()) {
102  BOOST_THROW_EXCEPTION(Error("expecting Strategy/Name"));
103  }
104  else {
105  m_strategy.wireDecode(*val->elements_begin());
106  }
107  ++val;
108  }
109  else {
110  BOOST_THROW_EXCEPTION(Error("missing required Strategy field"));
111  }
112 }
113 
116 {
117  m_wire.reset();
118  m_name = name;
119  return *this;
120 }
121 
124 {
125  m_wire.reset();
126  m_strategy = strategy;
127  return *this;
128 }
129 
130 } // namespace nfd
131 } // namespace ndn
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.
EncodingImpl< EstimatorTag > EncodingEstimator
element_const_iterator elements_end() const
Definition: block.cpp:595
size_t prependNestedBlock(EncodingImpl< TAG > &encoder, uint32_t type, const U &value)
Prepend a TLV block of type type with WireEncodable value as a value.
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
void wireDecode(const Block &wire)
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
StrategyChoice & setStrategy(const Name &strategy)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const Block & wireEncode() const
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:122
represents NFD StrategyChoice dataset
void wireDecode(const Block &wire)
Definition: name.cpp:161
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
StrategyChoice & setName(const Name &name)
uint32_t type() const
Definition: block.hpp:324