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);
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>
332  Buffer::Iterator DeserializeSequence (std::bitset<N> *optionalOrDefaultMask,
333  bool isExtensionMarkerPresent,
334  Buffer::Iterator bIterator);
342  Buffer::Iterator DeserializeSequence (std::bitset<0> *optionalOrDefaultMask,
343  bool isExtensionMarkerPresent,
344  Buffer::Iterator bIterator);
352  Buffer::Iterator DeserializeSequence (std::bitset<1> *optionalOrDefaultMask,
353  bool isExtensionMarkerPresent,
354  Buffer::Iterator bIterator);
362  Buffer::Iterator DeserializeSequence (std::bitset<2> *optionalOrDefaultMask,
363  bool isExtensionMarkerPresent,
364  Buffer::Iterator bIterator);
372  Buffer::Iterator DeserializeSequence (std::bitset<3> *optionalOrDefaultMask,
373  bool isExtensionMarkerPresent,
374  Buffer::Iterator bIterator);
382  Buffer::Iterator DeserializeSequence (std::bitset<4> *optionalOrDefaultMask,
383  bool isExtensionMarkerPresent,
384  Buffer::Iterator bIterator);
392  Buffer::Iterator DeserializeSequence (std::bitset<5> *optionalOrDefaultMask,
393  bool isExtensionMarkerPresent,
394  Buffer::Iterator bIterator);
402  Buffer::Iterator DeserializeSequence (std::bitset<6> *optionalOrDefaultMask,
403  bool isExtensionMarkerPresent,
404  Buffer::Iterator bIterator);
405 
413  Buffer::Iterator DeserializeSequence (std::bitset<7> *optionalOrDefaultMask,
414  bool isExtensionMarkerPresent,
415  Buffer::Iterator bIterator);
423  Buffer::Iterator DeserializeSequence (std::bitset<9> *optionalOrDefaultMask,
424  bool isExtensionMarkerPresent,
425  Buffer::Iterator bIterator);
433  Buffer::Iterator DeserializeSequence (std::bitset<10> *optionalOrDefaultMask,
434  bool isExtensionMarkerPresent,
435  Buffer::Iterator bIterator);
443  Buffer::Iterator DeserializeSequence (std::bitset<11> *optionalOrDefaultMask,
444  bool isExtensionMarkerPresent,
445  Buffer::Iterator bIterator);
446 
453  template <int N>
454  Buffer::Iterator DeserializeBitstring (std::bitset<N> *bitstring,
455  Buffer::Iterator bIterator);
462  Buffer::Iterator DeserializeBitstring (std::bitset<1> *bitstring,
463  Buffer::Iterator bIterator);
470  Buffer::Iterator DeserializeBitstring (std::bitset<2> *bitstring,
471  Buffer::Iterator bIterator);
478  Buffer::Iterator DeserializeBitstring (std::bitset<8> *bitstring,
479  Buffer::Iterator bIterator);
486  Buffer::Iterator DeserializeBitstring (std::bitset<10> *bitstring,
487  Buffer::Iterator bIterator);
494  Buffer::Iterator DeserializeBitstring (std::bitset<16> *bitstring,
495  Buffer::Iterator bIterator);
502  Buffer::Iterator DeserializeBitstring (std::bitset<27> *bitstring,
503  Buffer::Iterator bIterator);
510  Buffer::Iterator DeserializeBitstring (std::bitset<28> *bitstring,
511  Buffer::Iterator bIterator);
518  Buffer::Iterator DeserializeBitstring (std::bitset<32> *bitstring,
519  Buffer::Iterator bIterator);
520 
535  Buffer::Iterator DeserializeSequenceOf (int *numElems, int nMax, int nMin,
536  Buffer::Iterator bIterator);
537 };
538 
539 } // namespace ns3
540 
541 #endif // ASN1_HEADER_H
542 
This class has the purpose to encode Information Elements according to ASN.1 syntax,...
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)
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.
virtual uint32_t Deserialize(Buffer::Iterator bIterator)=0
Buffer::Iterator DeserializeInteger(int *n, int nmin, int nmax, Buffer::Iterator bIterator)
Deserialize an integer.
void SerializeBitstring(std::bitset< N > bitstring) const
Serialize a bitstring.
Buffer::Iterator DeserializeEnum(int numElems, int *selectedElem, Buffer::Iterator bIterator)
Deserialize an Enum.
virtual ~Asn1Header()
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.
void SerializeInteger(int n, int nmin, int nmax) const
Serialize an Integer.
virtual void Print(std::ostream &os) const =0
virtual void PreSerialize(void) const =0
This function serializes class attributes to m_serializationResult local Buffer.
Buffer::Iterator DeserializeBoolean(bool *value, Buffer::Iterator bIterator)
Deserialize a boolean.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
static TypeId GetTypeId(void)
Get the type ID.
void Serialize(Buffer::Iterator bIterator) const
uint32_t GetSerializedSize(void) const
uint8_t m_serializationPendingBits
pending bits
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:99
automatically resized byte buffer
Definition: buffer.h:93
Protocol header serialization and deserialization.
Definition: header.h:43
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]