A Discrete-Event Network Simulator
API
lte-asn1-header.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Lluis Parcerisa <lparcerisa@cttc.cat>
18  */
19 
20 #ifndef ASN1_HEADER_H
21 #define ASN1_HEADER_H
22 
23 #include "ns3/header.h"
24 
25 #include <bitset>
26 #include <string>
27 
28 namespace ns3
29 {
30 
36 class Asn1Header : public Header
37 {
38  public:
39  Asn1Header();
40  ~Asn1Header() override;
41 
46  static TypeId GetTypeId();
47  TypeId GetInstanceTypeId() const override;
48  uint32_t GetSerializedSize() const override;
49  void Serialize(Buffer::Iterator bIterator) const override;
50 
51  // Inherited from ns3::Header base class
52  // Pure virtual methods, to be implemented in child classes
53  uint32_t Deserialize(Buffer::Iterator bIterator) override = 0;
54  void Print(std::ostream& os) const override = 0;
55 
65  virtual void PreSerialize() const = 0;
66 
67  protected:
68  mutable uint8_t m_serializationPendingBits;
70  mutable bool m_isDataSerialized;
72 
77  void WriteOctet(uint8_t octet) const;
78 
79  // Serialization functions
80 
85  void SerializeBoolean(bool value) const;
92  void SerializeInteger(int n, int nmin, int nmax) const;
93  // void SerializeOctetstring (std::string s) const;
100  void SerializeSequenceOf(int numElems, int nMax, int nMin) const;
107  void SerializeChoice(int numOptions, int selectedOption, bool isExtensionMarkerPresent) const;
113  void SerializeEnum(int numElems, int selectedElem) const;
117  void SerializeNull() const;
121  void FinalizeSerialization() const;
122 
127  template <int N>
128  void SerializeBitset(std::bitset<N> data) const;
129 
135  template <int N>
136  void SerializeSequence(std::bitset<N> optionalOrDefaultMask,
137  bool isExtensionMarkerPresent) const;
143  void SerializeSequence(std::bitset<0> optionalOrDefaultMask,
144  bool isExtensionMarkerPresent) const;
150  void SerializeSequence(std::bitset<1> optionalOrDefaultMask,
151  bool isExtensionMarkerPresent) const;
157  void SerializeSequence(std::bitset<2> optionalOrDefaultMask,
158  bool isExtensionMarkerPresent) const;
164  void SerializeSequence(std::bitset<3> optionalOrDefaultMask,
165  bool isExtensionMarkerPresent) const;
171  void SerializeSequence(std::bitset<4> optionalOrDefaultMask,
172  bool isExtensionMarkerPresent) const;
178  void SerializeSequence(std::bitset<5> optionalOrDefaultMask,
179  bool isExtensionMarkerPresent) const;
185  void SerializeSequence(std::bitset<6> optionalOrDefaultMask,
186  bool isExtensionMarkerPresent) const;
192  void SerializeSequence(std::bitset<7> optionalOrDefaultMask,
193  bool isExtensionMarkerPresent) const;
199  void SerializeSequence(std::bitset<9> optionalOrDefaultMask,
200  bool isExtensionMarkerPresent) const;
206  void SerializeSequence(std::bitset<10> optionalOrDefaultMask,
207  bool isExtensionMarkerPresent) const;
213  void SerializeSequence(std::bitset<11> optionalOrDefaultMask,
214  bool isExtensionMarkerPresent) const;
215 
220  template <int N>
221  void SerializeBitstring(std::bitset<N> bitstring) const;
226  void SerializeBitstring(std::bitset<1> bitstring) const;
231  void SerializeBitstring(std::bitset<2> bitstring) const;
236  void SerializeBitstring(std::bitset<8> bitstring) const;
241  void SerializeBitstring(std::bitset<10> bitstring) const;
246  void SerializeBitstring(std::bitset<16> bitstring) const;
251  void SerializeBitstring(std::bitset<27> bitstring) const;
256  void SerializeBitstring(std::bitset<28> bitstring) const;
261  void SerializeBitstring(std::bitset<32> bitstring) const;
262 
263  // Deserialization functions
264 
271  template <int N>
272  Buffer::Iterator DeserializeBitset(std::bitset<N>* data, Buffer::Iterator bIterator);
280 
287  Buffer::Iterator DeserializeBoolean(bool* value, Buffer::Iterator bIterator);
296  Buffer::Iterator DeserializeInteger(int* n, int nmin, int nmax, Buffer::Iterator bIterator);
305  Buffer::Iterator DeserializeChoice(int numOptions,
306  bool isExtensionMarkerPresent,
307  int* selectedOption,
308  Buffer::Iterator bIterator);
316  Buffer::Iterator DeserializeEnum(int numElems, int* selectedElem, Buffer::Iterator bIterator);
317 
325  template <int N>
326  Buffer::Iterator DeserializeSequence(std::bitset<N>* optionalOrDefaultMask,
327  bool isExtensionMarkerPresent,
328  Buffer::Iterator bIterator);
336  Buffer::Iterator DeserializeSequence(std::bitset<0>* optionalOrDefaultMask,
337  bool isExtensionMarkerPresent,
338  Buffer::Iterator bIterator);
346  Buffer::Iterator DeserializeSequence(std::bitset<1>* optionalOrDefaultMask,
347  bool isExtensionMarkerPresent,
348  Buffer::Iterator bIterator);
356  Buffer::Iterator DeserializeSequence(std::bitset<2>* optionalOrDefaultMask,
357  bool isExtensionMarkerPresent,
358  Buffer::Iterator bIterator);
366  Buffer::Iterator DeserializeSequence(std::bitset<3>* optionalOrDefaultMask,
367  bool isExtensionMarkerPresent,
368  Buffer::Iterator bIterator);
376  Buffer::Iterator DeserializeSequence(std::bitset<4>* optionalOrDefaultMask,
377  bool isExtensionMarkerPresent,
378  Buffer::Iterator bIterator);
386  Buffer::Iterator DeserializeSequence(std::bitset<5>* optionalOrDefaultMask,
387  bool isExtensionMarkerPresent,
388  Buffer::Iterator bIterator);
396  Buffer::Iterator DeserializeSequence(std::bitset<6>* optionalOrDefaultMask,
397  bool isExtensionMarkerPresent,
398  Buffer::Iterator bIterator);
399 
407  Buffer::Iterator DeserializeSequence(std::bitset<7>* optionalOrDefaultMask,
408  bool isExtensionMarkerPresent,
409  Buffer::Iterator bIterator);
417  Buffer::Iterator DeserializeSequence(std::bitset<9>* optionalOrDefaultMask,
418  bool isExtensionMarkerPresent,
419  Buffer::Iterator bIterator);
427  Buffer::Iterator DeserializeSequence(std::bitset<10>* optionalOrDefaultMask,
428  bool isExtensionMarkerPresent,
429  Buffer::Iterator bIterator);
437  Buffer::Iterator DeserializeSequence(std::bitset<11>* optionalOrDefaultMask,
438  bool isExtensionMarkerPresent,
439  Buffer::Iterator bIterator);
440 
447  template <int N>
448  Buffer::Iterator DeserializeBitstring(std::bitset<N>* bitstring, Buffer::Iterator bIterator);
455  Buffer::Iterator DeserializeBitstring(std::bitset<1>* bitstring, Buffer::Iterator bIterator);
462  Buffer::Iterator DeserializeBitstring(std::bitset<2>* bitstring, Buffer::Iterator bIterator);
469  Buffer::Iterator DeserializeBitstring(std::bitset<8>* bitstring, Buffer::Iterator bIterator);
476  Buffer::Iterator DeserializeBitstring(std::bitset<10>* bitstring, Buffer::Iterator bIterator);
483  Buffer::Iterator DeserializeBitstring(std::bitset<16>* bitstring, Buffer::Iterator bIterator);
490  Buffer::Iterator DeserializeBitstring(std::bitset<27>* bitstring, Buffer::Iterator bIterator);
497  Buffer::Iterator DeserializeBitstring(std::bitset<28>* bitstring, Buffer::Iterator bIterator);
504  Buffer::Iterator DeserializeBitstring(std::bitset<32>* bitstring, Buffer::Iterator bIterator);
505 
521  int nMax,
522  int nMin,
523  Buffer::Iterator bIterator);
524 };
525 
526 } // namespace ns3
527 
528 #endif // ASN1_HEADER_H
This class has the purpose to encode Information Elements according to ASN.1 syntax,...
uint32_t Deserialize(Buffer::Iterator bIterator) override=0
Buffer::Iterator DeserializeBitset(std::bitset< N > *data, Buffer::Iterator bIterator)
Deserialize a bitset.
Buffer::Iterator DeserializeChoice(int numOptions, bool isExtensionMarkerPresent, int *selectedOption, Buffer::Iterator bIterator)
Deserialize a Choice (set of options)
static TypeId GetTypeId()
Get the type ID.
void Print(std::ostream &os) const override=0
Buffer::Iterator DeserializeSequenceOf(int *numElems, int nMax, int nMin, Buffer::Iterator bIterator)
Deserialize a Sequence.
Buffer::Iterator DeserializeNull(Buffer::Iterator bIterator)
Deserialize nothing (null op)
void WriteOctet(uint8_t octet) const
Function to write in m_serializationResult, after resizing its size.
void SerializeBitset(std::bitset< N > data) const
Serialize a bitset.
Buffer::Iterator DeserializeBitset(std::bitset< 8 > *data, Buffer::Iterator bIterator)
Deserialize a bitset.
Buffer::Iterator DeserializeInteger(int *n, int nmin, int nmax, Buffer::Iterator bIterator)
Deserialize an integer.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SerializeBitstring(std::bitset< N > bitstring) const
Serialize a bitstring.
Buffer::Iterator DeserializeEnum(int numElems, int *selectedElem, Buffer::Iterator bIterator)
Deserialize an Enum.
virtual void PreSerialize() const =0
This function serializes class attributes to m_serializationResult local Buffer.
Buffer::Iterator DeserializeSequence(std::bitset< N > *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
Deserialize a sequence.
uint8_t m_numSerializationPendingBits
number of pending bits
void SerializeSequence(std::bitset< N > optionalOrDefaultMask, bool isExtensionMarkerPresent) const
Serialize a sequence.
void SerializeChoice(int numOptions, int selectedOption, bool isExtensionMarkerPresent) const
Serialize a Choice (set of options)
Buffer m_serializationResult
serialization result
void FinalizeSerialization() const
Finalizes an in progress serialization.
~Asn1Header() override
void SerializeInteger(int n, int nmin, int nmax) const
Serialize an Integer.
Buffer::Iterator DeserializeBoolean(bool *value, Buffer::Iterator bIterator)
Deserialize a boolean.
uint8_t m_serializationPendingBits
pending bits
uint32_t GetSerializedSize() const override
void Serialize(Buffer::Iterator bIterator) const override
void SerializeBoolean(bool value) const
Serialize a bool.
Buffer::Iterator DeserializeBitstring(std::bitset< N > *bitstring, Buffer::Iterator bIterator)
Deserialize a bitstring.
void SerializeNull() const
Serialize nothing (null op)
bool m_isDataSerialized
true if data is serialized
void SerializeSequenceOf(int numElems, int nMax, int nMin) const
Serialize a Sequence.
void SerializeEnum(int numElems, int selectedElem) const
Serialize an Enum.
iterator in a Buffer instance
Definition: buffer.h:100
automatically resized byte buffer
Definition: buffer.h:94
Protocol header serialization and deserialization.
Definition: header.h:44
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]