TLVParser.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Packets_80221Bundle_TLVParser_
18 #define HH_SENF_Packets_80221Bundle_TLVParser_ 1
19 
20 // Custom includes
21 #include "TLVParserBase.hh"
22 #include "MIHTypes.hh"
23 
24 //#include "TLVParser.mpp"
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 
32  : public GenericTLVParserBase<MIHBaseTLVParser>
33  {
36 
37  void init() const {
38  defaultInit();
40  }
41 
42  using base::init;
43  using base::maxLength;
44  };
45 
46 
59  {
60  # include SENF_PARSER()
63  SENF_PARSER_LABEL ( idValue );
64  SENF_PARSER_SKIP ( idLength(), 0 );
66 
67  public:
69  //\{
70  void value( MIHFId const & id);
71 
72  void value(std::string const & id );
73  void value(senf::MACAddress const & addr);
74  void value(senf::INet4Address const & addr);
75  void value(senf::INet6Address const & addr);
76  void value(senf::EUI64 const & addr);
77  //\}
78 
80  //\{
81  MIHFId valueAs( MIHFId::Type type) const;
82 
83  std::string valueAsString() const;
84  senf::MACAddress valueAsMACAddress() const;
85  senf::INet4Address valueAsINet4Address() const;
86  senf::INet6Address valueAsINet6Address() const;
87  senf::EUI64 valueAsEUI64() const;
88  //\}
89 
91  //\{
92  bool valueEquals( MIHFId const & id) const;
93 
94  bool valueEquals(std::string const & id ) const;
95  bool valueEquals(senf::MACAddress const & addr) const;
96  bool valueEquals(senf::INet4Address const & addr) const;
97  bool valueEquals(senf::INet6Address const & addr) const;
98  bool valueEquals(senf::EUI64 const & addr) const;
99  //\}
100 
101  void dump(std::ostream & os) const;
102  void maxIdLength(boost::uint8_t maxl) const;
103  void finalize();
104 
105  private:
108 
109  data_iterator valueBegin() const;
110  data_iterator valueEnd() const;
111 
112  template <class OutputIterator>
113  struct binaryNAIEncoder {
114  binaryNAIEncoder(OutputIterator & i);
115  void operator()(boost::uint8_t v);
116  OutputIterator & i_;
117  };
118 
119  template <class OutputIterator>
120  static boost::function_output_iterator<binaryNAIEncoder<OutputIterator> >
121  getNAIEncodedOutputIterator(OutputIterator & i);
122 
123  struct binaryNAIDecoder {
124  binaryNAIDecoder();
125  bool operator()(boost::uint8_t v);
126  bool readNextByte_;
127  };
128 
129  template <class Iterator>
130  static boost::filter_iterator<binaryNAIDecoder, Iterator>
131  getNAIDecodedIterator(Iterator begin, Iterator end);
132 
133  struct ValueSetterVisitor : public boost::static_visitor<> {
135  ValueSetterVisitor( MIHFIdTLVParser & p) : parser(p) {}
136  void operator()( boost::blank ) const {
137  parser.value( std::string());
138  }
139  template <typename MIHFIdType>
140  void operator()( MIHFIdType const & id ) const {
141  parser.value( id);
142  }
143  };
144 
145  struct ValueEqualsVisitor : public boost::static_visitor<bool> {
146  MIHFIdTLVParser const & parser;
147  ValueEqualsVisitor( MIHFIdTLVParser const & p) : parser(p) {}
148  bool operator()( boost::blank ) const {
149  return parser.idLength() == 0;
150  }
151  template <typename MIHFIdType>
152  bool operator()( MIHFIdType const & id ) const {
153  return parser.valueEquals( id);
154  }
155  };
156  };
157 
161  {
163 
164  void init() const {
165  defaultInit();
166  type() << typeId+0;
167  }
168  static type_t::value_type const typeId = 1;
169  void dump(std::ostream & os) const;
170  void validate() const;
171  };
172 
176  {
178 
179  void init() const {
180  defaultInit();
181  type() << typeId+0;
182  }
183  static type_t::value_type const typeId = 2;
184  void dump(std::ostream & os) const;
185  void validate() const;
186  };
187 
189 
193  {
194  # include SENF_PARSER()
198 
200  defaultInit();
201  type() << typeId+0;
202  length_() = 1;
203  }
204  static type_t::value_type const typeId = 3;
205  void dump(std::ostream & os) const;
206  void validate() const;
207 
208  enum StatusCode {
209  Success, UnspecifiedFailure, Rejected, AuthorizationFailure, NetworkError };
210  };
211 
213  {
214  # include SENF_PARSER()
218 
220  defaultInit();
221  type() = typeId+0;
222  length_() = 1;
223  }
224  static type_t::value_type const typeId = 11;
225  void dump(std::ostream & os) const;
226  void validate() const;
227 
228  enum RequestCode { Registration, ReRegistration };
229  };
230 
232  {
233  # include SENF_PARSER()
237 
239  defaultInit();
240  type() = typeId+0;
241  length_() = 4;
242  }
243  static type_t::value_type const typeId = 12;
244  void dump(std::ostream & os) const;
245  void validate() const;
246  };
247 
248 }
249 
250 //-/////////////////////////////////////////////////////////////////////////////////////////////////
251 #include "TLVParser.cci"
252 //#include "TLVParser.ct"
253 #include "TLVParser.cti"
254 #endif
255 
256 
257 // Local Variables:
258 // mode: c++
259 // fill-column: 100
260 // c-file-style: "senf"
261 // indent-tabs-mode: nil
262 // ispell-local-dictionary: "american"
263 // compile-command: "scons -u test"
264 // comment-column: 40
265 // End:
#define SENF_PARSER_INHERIT(base)
Define parser inheritance.
MIHFSrcIdTLVParser(data_iterator i, state_type s)
Definition: TLVParser.hh:162
void maxLength(MIHLengthParser::value_type maxl) const
set maximum value of TLV length field
Parse 8bit unsigned byte aligned integer.
Definition: IntParser.hh:91
unspecified_keyword_type parser
senf::GenericTLVParserBase< MIHBaseTLVParser > base
Definition: TLVParser.hh:34
Parser for 802.21 source MIHF_ID TLV.
Definition: TLVParser.hh:160
#define SENF_PARSER_LABEL(name)
Define offset label.
Parser for 802.21 Status TLV.
Definition: TLVParser.hh:192
void finalize()
shrink size of the TLV length field to minimum
Base class for generic TLV parsers.
Definition: GenericTLV.hh:124
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
UInt8Parser type() const
boost::uint32_t value_type
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
MIHFDstIdTLVParser(data_iterator i, state_type s)
Definition: TLVParser.hh:177
void defaultInit() const
Default implementation.
bool valueEquals(MIHFId const &id) const
Packet data STL-sequence view.
Definition: PacketData.hh:61
#define SENF_PARSER_INIT()
Define parser initialization routine.
#define SENF_PARSER_FIELD_RO(name, type)
Define parser field (read-only)
boost::uint8_t value_type
Definition: IntParser.hh:99
data_iterator i() const
Return beginning of data to parse.
#define SENF_PARSER_SKIP(skip)
Skip bytes.
Parse a MIHF_ID.
Definition: TLVParser.hh:58
static value_type const max_value
void swap(MIHFSrcIdTLVParser src, MIHFDstIdTLVParser dst)
Definition: TLVParser.cc:138
Re-validating data iterator.
Definition: SafeIterator.hh:47
PacketInterpreterBase::range value() const
MIHLengthParser ::value_type idLength() const
MIHTypes public header.
TLVParserBase public header.
Parse 32bit unsigned byte aligned integer.
Definition: IntParser.hh:310
void validate(size_type size) const
Validate size of data container.
Parser for 802.21 destination MIHF_ID TLV.
Definition: TLVParser.hh:175
Parser for a generic TLV packet.
Definition: TLVParser.hh:31
Base class for MIH TLV parsers.
detail::packet::iterator data_iterator
Raw data iterator type.
void value(MIHFId const &id)
Definition: TLVParser.cc:112
MIHGenericTLVParser(data_iterator i, state_type s)
Definition: TLVParser.hh:35
MIHLengthParser length_() const