TLVParser.cci
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 
14 /** \file
15  \brief TLVParser inline non-template implementation */
16 
17 //#include "TLVParser.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // MIHFIdTLVParser::binaryNAIDecoder
26 
27 prefix_ senf::MIHFIdTLVParser::binaryNAIDecoder::binaryNAIDecoder()
28  : readNextByte_( true)
29 {}
30 
31 prefix_ bool senf::MIHFIdTLVParser::binaryNAIDecoder::operator()(boost::uint8_t v)
32 {
33  readNextByte_ = readNextByte_ ? false : true;
34  return readNextByte_;
35 }
36 
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 // MIHFIdTLVParser
39 
40 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueBegin()
41  const
42 {
43  return i( idValue_offset());
44 }
45 
46 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueEnd()
47  const
48 {
49  return i( idValue_offset() + idLength());
50 }
51 
52 prefix_ std::string senf::MIHFIdTLVParser::valueAsString()
53  const
54 {
55  return std::string( valueBegin(), valueEnd());
56 }
57 
58 prefix_ senf::MACAddress senf::MIHFIdTLVParser::valueAsMACAddress()
59  const
60 {
61  if (idLength() != 6*2) throw make_WrapException(std::bad_cast())
62  << " length of MIHF_ID does not match for a MAC address (" << idLength() << ")";
63  return MACAddress::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
64 }
65 
66 prefix_ senf::INet4Address senf::MIHFIdTLVParser::valueAsINet4Address()
67  const
68 {
69  if (idLength() != 4*2) throw make_WrapException(std::bad_cast())
70  << " length of MIHF_ID does not match for an INet4 address (" << idLength() << ")";
71  return INet4Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
72 }
73 
74 prefix_ senf::INet6Address senf::MIHFIdTLVParser::valueAsINet6Address()
75  const
76 {
77  if (idLength() != 16*2) throw make_WrapException(std::bad_cast())
78  << " length of MIHF_ID does not match for an INet6 address (" << idLength() << ")";
79  return INet6Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
80 }
81 
82 prefix_ senf::EUI64 senf::MIHFIdTLVParser::valueAsEUI64()
83  const
84 {
85  if (idLength() != 8*2) throw make_WrapException(std::bad_cast())
86  << " length of MIHF_ID does not match for an EUI64 address (" << idLength() << ")";
87  return EUI64::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
88 }
89 
90 prefix_ bool senf::MIHFIdTLVParser::valueEquals( std::string const &id)
91  const
92 {
93  return id == valueAsString();
94 }
95 
96 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::MACAddress const & addr)
97  const
98 {
99  return idLength()==12 && addr==valueAsMACAddress();
100 }
101 
102 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet4Address const & addr)
103  const
104 {
105  return idLength()==8 && addr==valueAsINet4Address();
106 }
107 
108 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet6Address const & addr)
109  const
110 {
111  return idLength()==32 && addr==valueAsINet6Address();
112 }
113 
114 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::EUI64 const & addr)
115  const
116 {
117  return idLength()==16 && addr==valueAsEUI64();
118 }
119 
120 prefix_ bool senf::MIHFIdTLVParser::valueEquals( MIHFId const & id)
121  const
122 {
123  return boost::apply_visitor( ValueEqualsVisitor(*this), id);
124 }
125 
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 #undef prefix_
128 
129 
130 // Local Variables:
131 // mode: c++
132 // fill-column: 100
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u test"
137 // comment-column: 40
138 // End: