A Discrete-Event Network Simulator
API
lte-asn1-header.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Lluis Parcerisa <lparcerisa@cttc.cat>
19  */
20 
21 #ifndef ASN1_HEADER_H
22 #define ASN1_HEADER_H
23 
24 #include "ns3/header.h"
25 
26 #include <bitset>
27 #include <string>
28 
29 namespace ns3 {
30 
36 class Asn1Header : public Header
37 {
38 public:
39  Asn1Header ();
40  virtual ~Asn1Header ();
41 
46  static TypeId GetTypeId (void);
47  virtual TypeId GetInstanceTypeId (void) const;
48  uint32_t GetSerializedSize (void) const;
49  void Serialize (Buffer::Iterator bIterator) const;
50 
51  // Inherited from ns3::Header base class
52  // Pure virtual methods, to be implemented in child classes
53  virtual uint32_t Deserialize (Buffer::Iterator bIterator) = 0;
54  virtual void Print (std::ostream &os) const = 0;
55 
65  virtual void PreSerialize (void) 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,
108  bool isExtensionMarkerPresent) const;
114  void SerializeEnum (int numElems, int selectedElem) const;
118  void SerializeNull () const;
122  void FinalizeSerialization () const;
123 
128  template <int N>
129  void SerializeBitset (std::bitset<N> data) const;
130 
136  template <int N>
137  void SerializeSequence (std::bitset<N> optionalOrDefaultMask,
138  bool isExtensionMarkerPresent) const;
144  void SerializeSequence (std::bitset<0> optionalOrDefaultMask,
145  bool isExtensionMarkerPresent) const;
151  void SerializeSequence (std::bitset<1> optionalOrDefaultMask,
152  bool isExtensionMarkerPresent) const;
158  void SerializeSequence (std::bitset<2> optionalOrDefaultMask,
159  bool isExtensionMarkerPresent) const;
165  void SerializeSequence (std::bitset<3> optionalOrDefaultMask,
166  bool isExtensionMarkerPresent) const;
172  void SerializeSequence (std::bitset<4> optionalOrDefaultMask,
173  bool isExtensionMarkerPresent) const;
179  void SerializeSequence (std::bitset<5> optionalOrDefaultMask,
180  bool isExtensionMarkerPresent) const;
186  void SerializeSequence (std::bitset<6> optionalOrDefaultMask,
187  bool isExtensionMarkerPresent) const;
193  void SerializeSequence (std::bitset<7> optionalOrDefaultMask,
194  bool isExtensionMarkerPresent) const;
200  void SerializeSequence (std::bitset<9> optionalOrDefaultMask,
201  bool isExtensionMarkerPresent) const;
207  void SerializeSequence (std::bitset<10> optionalOrDefaultMask,
208  bool isExtensionMarkerPresent) const;
214  void SerializeSequence (std::bitset<11> optionalOrDefaultMask,
215  bool isExtensionMarkerPresent) const;
216 
221  template <int N>
222  void SerializeBitstring (std::bitset<N> bitstring) const;
227  void SerializeBitstring (std::bitset<1> bitstring) const;
232  void SerializeBitstring (std::bitset<2> bitstring) const;
237  void SerializeBitstring (std::bitset<8> bitstring) const;
242  void SerializeBitstring (std::bitset<10> bitstring) const;
247  void SerializeBitstring (std::bitset<16> bitstring) const;
252  void SerializeBitstring (std::bitset<27> bitstring) const;
257  void SerializeBitstring (std::bitset<28> bitstring) const;
262  void SerializeBitstring (std::bitset<32> bitstring) const;
263 
264  // Deserialization functions
265 
272  template <int N>
273  Buffer::Iterator DeserializeBitset (std::bitset<N> *data,
274  Buffer::Iterator bIterator);
281  Buffer::Iterator DeserializeBitset (std::bitset<8> *data,
282  Buffer::Iterator bIterator);
283 
291  Buffer::Iterator bIterator);
300  Buffer::Iterator DeserializeInteger (int *n, int nmin, int nmax,
301  Buffer::Iterator bIterator);
310  Buffer::Iterator DeserializeChoice (int numOptions,
311  bool isExtensionMarkerPresent,
312  int *selectedOption,
313  Buffer::Iterator bIterator);
321  Buffer::Iterator DeserializeEnum (int numElems, int *selectedElem,
322  Buffer::Iterator bIterator);
323 
331  template <int N>
339  Buffer::Iterator DeserializeSequence (std::bitset<N> *optionalOrDefaultMask,
340  bool isExtensionMarkerPresent,
341  Buffer::Iterator bIterator);
349  Buffer::Iterator DeserializeSequence (std::bitset<0> *optionalOrDefaultMask,
350  bool isExtensionMarkerPresent,
351  Buffer::Iterator bIterator);
359  Buffer::Iterator DeserializeSequence (std::bitset<1> *optionalOrDefaultMask,
360  bool isExtensionMarkerPresent,
361  Buffer::Iterator bIterator);
369  Buffer::Iterator DeserializeSequence (std::bitset<2> *optionalOrDefaultMask,
370  bool isExtensionMarkerPresent,
371  Buffer::Iterator bIterator);
379  Buffer::Iterator DeserializeSequence (std::bitset<3> *optionalOrDefaultMask,
380  bool isExtensionMarkerPresent,
381  Buffer::Iterator bIterator);
389  Buffer::Iterator DeserializeSequence (std::bitset<4> *optionalOrDefaultMask,
390  bool isExtensionMarkerPresent,
391  Buffer::Iterator bIterator);
399  Buffer::Iterator DeserializeSequence (std::bitset<5> *optionalOrDefaultMask,
400  bool isExtensionMarkerPresent,
401  Buffer::Iterator bIterator);
409  Buffer::Iterator DeserializeSequence (std::bitset<6> *optionalOrDefaultMask,
410  bool isExtensionMarkerPresent,
411  Buffer::Iterator bIterator);
412 
420  Buffer::Iterator DeserializeSequence (std::bitset<7> *optionalOrDefaultMask,
421  bool isExtensionMarkerPresent,
422  Buffer::Iterator bIterator);
430  Buffer::Iterator DeserializeSequence (std::bitset<9> *optionalOrDefaultMask,
431  bool isExtensionMarkerPresent,
432  Buffer::Iterator bIterator);
440  Buffer::Iterator DeserializeSequence (std::bitset<10> *optionalOrDefaultMask,
441  bool isExtensionMarkerPresent,
442  Buffer::Iterator bIterator);
450  Buffer::Iterator DeserializeSequence (std::bitset<11> *optionalOrDefaultMask,
451  bool isExtensionMarkerPresent,
452  Buffer::Iterator bIterator);
453 
460  template <int N>
461  Buffer::Iterator DeserializeBitstring (std::bitset<N> *bitstring,
462  Buffer::Iterator bIterator);
469  Buffer::Iterator DeserializeBitstring (std::bitset<1> *bitstring,
470  Buffer::Iterator bIterator);
477  Buffer::Iterator DeserializeBitstring (std::bitset<2> *bitstring,
478  Buffer::Iterator bIterator);
485  Buffer::Iterator DeserializeBitstring (std::bitset<8> *bitstring,
486  Buffer::Iterator bIterator);
493  Buffer::Iterator DeserializeBitstring (std::bitset<10> *bitstring,
494  Buffer::Iterator bIterator);
501  Buffer::Iterator DeserializeBitstring (std::bitset<16> *bitstring,
502  Buffer::Iterator bIterator);
509  Buffer::Iterator DeserializeBitstring (std::bitset<27> *bitstring,
510  Buffer::Iterator bIterator);
517  Buffer::Iterator DeserializeBitstring (std::bitset<28> *bitstring,
518  Buffer::Iterator bIterator);
525  Buffer::Iterator DeserializeBitstring (std::bitset<32> *bitstring,
526  Buffer::Iterator bIterator);
527 
542  Buffer::Iterator DeserializeSequenceOf (int *numElems, int nMax, int nMin,
543  Buffer::Iterator bIterator);
544 };
545 
546 } // namespace ns3
547 
548 #endif // ASN1_HEADER_H
549 
Protocol header serialization and deserialization.
Definition: header.h:42
void WriteOctet(uint8_t octet) const
Function to write in m_serializationResult, after resizing its size.
void SerializeBitstring(std::bitset< N > bitstring) const
Serialize a bitstring.
void SerializeBoolean(bool value) const
Serialize a bool.
Buffer::Iterator DeserializeChoice(int numOptions, bool isExtensionMarkerPresent, int *selectedOption, Buffer::Iterator bIterator)
Deserialize a Choice (set of options)
void SerializeNull() const
Serialize nothing (null op)
automatically resized byte buffer
Definition: buffer.h:92
Buffer::Iterator DeserializeNull(Buffer::Iterator bIterator)
Deserialize nothing (null op)
uint8_t m_numSerializationPendingBits
number of pending bits
uint32_t GetSerializedSize(void) const
Buffer::Iterator DeserializeSequence(std::bitset< N > *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
Deserialize a sequence.
virtual uint32_t Deserialize(Buffer::Iterator bIterator)=0
bool m_isDataSerialized
true if data is serialized
iterator in a Buffer instance
Definition: buffer.h:98
Buffer::Iterator DeserializeBoolean(bool *value, Buffer::Iterator bIterator)
Deserialize a boolean.
virtual ~Asn1Header()
uint8_t m_serializationPendingBits
pending bits
Buffer::Iterator DeserializeEnum(int numElems, int *selectedElem, Buffer::Iterator bIterator)
Deserialize an Enum.
Buffer::Iterator DeserializeInteger(int *n, int nmin, int nmax, Buffer::Iterator bIterator)
Deserialize an integer.
uint8_t data[writeSize]
Buffer m_serializationResult
serialization result
void SerializeChoice(int numOptions, int selectedOption, bool isExtensionMarkerPresent) const
Serialize a Choice (set of options)
virtual void PreSerialize(void) const =0
This function serializes class attributes to m_serializationResult local Buffer.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SerializeSequenceOf(int numElems, int nMax, int nMin) const
Serialize a Sequence.
Buffer::Iterator DeserializeBitset(std::bitset< N > *data, Buffer::Iterator bIterator)
Deserialize a bitset.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SerializeSequence(std::bitset< N > optionalOrDefaultMask, bool isExtensionMarkerPresent) const
Serialize a sequence.
void SerializeBitset(std::bitset< N > data) const
Serialize a bitset.
void SerializeEnum(int numElems, int selectedElem) const
Serialize an Enum.
void SerializeInteger(int n, int nmin, int nmax) const
Serialize an Integer.
This class has the purpose to encode Information Elements according to ASN.1 syntax, as defined in ITU-T X-691.
virtual void Print(std::ostream &os) const =0
Buffer::Iterator DeserializeSequenceOf(int *numElems, int nMax, int nMin, Buffer::Iterator bIterator)
Deserialize a Sequence.
void Serialize(Buffer::Iterator bIterator) const
void FinalizeSerialization() const
Finalizes an in progress serialization.
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
Buffer::Iterator DeserializeBitstring(std::bitset< N > *bitstring, Buffer::Iterator bIterator)
Deserialize a bitstring.