A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Lluis Parcerisa <lparcerisa@cttc.cat>
7 */
8
9#ifndef ASN1_HEADER_H
10#define ASN1_HEADER_H
11
12#include "ns3/header.h"
13
14#include <bitset>
15#include <string>
16
17namespace ns3
18{
19
20/**
21 * This class has the purpose to encode Information Elements according
22 * to ASN.1 syntax, as defined in ITU-T X-691.
23 * IMPORTANT: The encoding is done following the UNALIGNED variant.
24 */
25class Asn1Header : public Header
26{
27 public:
28 Asn1Header();
29 ~Asn1Header() override;
30
31 /**
32 * \brief Get the type ID.
33 * \return the object TypeId
34 */
35 static TypeId GetTypeId();
36 TypeId GetInstanceTypeId() const override;
37 uint32_t GetSerializedSize() const override;
38 void Serialize(Buffer::Iterator bIterator) const override;
39
40 // Inherited from ns3::Header base class
41 // Pure virtual methods, to be implemented in child classes
42 uint32_t Deserialize(Buffer::Iterator bIterator) override = 0;
43 void Print(std::ostream& os) const override = 0;
44
45 /**
46 * This function serializes class attributes to m_serializationResult
47 * local Buffer. As ASN1 encoding produces a bitstream that does not have
48 * a fixed length, this function is needed to store the result, so
49 * its length can be retrieved with Header::GetSerializedSize() function.
50 * This method is pure virtual in this class (needs to be implemented
51 * in child classes) as the meaningful information elements are in
52 * the subclasses.
53 */
54 virtual void PreSerialize() const = 0;
55
56 protected:
57 mutable uint8_t m_serializationPendingBits; //!< pending bits
58 mutable uint8_t m_numSerializationPendingBits; //!< number of pending bits
59 mutable bool m_isDataSerialized; //!< true if data is serialized
60 mutable Buffer m_serializationResult; //!< serialization result
61
62 /**
63 * Function to write in m_serializationResult, after resizing its size
64 * \param octet bits to write
65 */
66 void WriteOctet(uint8_t octet) const;
67
68 // Serialization functions
69
70 /**
71 * Serialize a bool
72 * \param value value to serialize
73 */
74 void SerializeBoolean(bool value) const;
75 /**
76 * Serialize an Integer
77 * \param n value to serialize
78 * \param nmin min value to serialize
79 * \param nmax max value to serialize
80 */
81 void SerializeInteger(int n, int nmin, int nmax) const;
82 // void SerializeOctetstring (std::string s) const;
83 /**
84 * Serialize a Sequence
85 * \param numElems element number to serialize
86 * \param nMax max value to serialize
87 * \param nMin min value to serialize
88 */
89 void SerializeSequenceOf(int numElems, int nMax, int nMin) const;
90 /**
91 * Serialize a Choice (set of options)
92 * \param numOptions number of options
93 * \param selectedOption selected option
94 * \param isExtensionMarkerPresent true if extension mark is present
95 */
96 void SerializeChoice(int numOptions, int selectedOption, bool isExtensionMarkerPresent) const;
97 /**
98 * Serialize an Enum
99 * \param numElems number of elements in the enum
100 * \param selectedElem selected element
101 */
102 void SerializeEnum(int numElems, int selectedElem) const;
103 /**
104 * Serialize nothing (null op)
105 */
106 void SerializeNull() const;
107 /**
108 * Finalizes an in progress serialization.
109 */
110 void FinalizeSerialization() const;
111
112 /**
113 * Serialize a bitset
114 * \param data data to serialize
115 */
116 template <int N>
117 void SerializeBitset(std::bitset<N> data) const;
118
119 /**
120 * Serialize a sequence
121 * \param optionalOrDefaultMask Mask to serialize
122 * \param isExtensionMarkerPresent true if Extension Marker is present
123 */
124 template <int N>
125 void SerializeSequence(std::bitset<N> optionalOrDefaultMask,
126 bool isExtensionMarkerPresent) const;
127 /**
128 * Serialize a sequence
129 * \param optionalOrDefaultMask Mask to serialize
130 * \param isExtensionMarkerPresent true if Extension Marker is present
131 */
132 void SerializeSequence(std::bitset<0> optionalOrDefaultMask,
133 bool isExtensionMarkerPresent) const;
134 /**
135 * Serialize a sequence
136 * \param optionalOrDefaultMask Mask to serialize
137 * \param isExtensionMarkerPresent true if Extension Marker is present
138 */
139 void SerializeSequence(std::bitset<1> optionalOrDefaultMask,
140 bool isExtensionMarkerPresent) const;
141 /**
142 * Serialize a sequence
143 * \param optionalOrDefaultMask Mask to serialize
144 * \param isExtensionMarkerPresent true if Extension Marker is present
145 */
146 void SerializeSequence(std::bitset<2> optionalOrDefaultMask,
147 bool isExtensionMarkerPresent) const;
148 /**
149 * Serialize a sequence
150 * \param optionalOrDefaultMask Mask to serialize
151 * \param isExtensionMarkerPresent true if Extension Marker is present
152 */
153 void SerializeSequence(std::bitset<3> optionalOrDefaultMask,
154 bool isExtensionMarkerPresent) const;
155 /**
156 * Serialize a sequence
157 * \param optionalOrDefaultMask Mask to serialize
158 * \param isExtensionMarkerPresent true if Extension Marker is present
159 */
160 void SerializeSequence(std::bitset<4> optionalOrDefaultMask,
161 bool isExtensionMarkerPresent) const;
162 /**
163 * Serialize a sequence
164 * \param optionalOrDefaultMask Mask to serialize
165 * \param isExtensionMarkerPresent true if Extension Marker is present
166 */
167 void SerializeSequence(std::bitset<5> optionalOrDefaultMask,
168 bool isExtensionMarkerPresent) const;
169 /**
170 * Serialize a sequence
171 * \param optionalOrDefaultMask Mask to serialize
172 * \param isExtensionMarkerPresent true if Extension Marker is present
173 */
174 void SerializeSequence(std::bitset<6> optionalOrDefaultMask,
175 bool isExtensionMarkerPresent) const;
176 /**
177 * Serialize a sequence
178 * \param optionalOrDefaultMask Mask to serialize
179 * \param isExtensionMarkerPresent true if Extension Marker is present
180 */
181 void SerializeSequence(std::bitset<7> optionalOrDefaultMask,
182 bool isExtensionMarkerPresent) const;
183 /**
184 * Serialize a sequence
185 * \param optionalOrDefaultMask Mask to serialize
186 * \param isExtensionMarkerPresent true if Extension Marker is present
187 */
188 void SerializeSequence(std::bitset<9> optionalOrDefaultMask,
189 bool isExtensionMarkerPresent) const;
190 /**
191 * Serialize a sequence
192 * \param optionalOrDefaultMask Mask to serialize
193 * \param isExtensionMarkerPresent true if Extension Marker is present
194 */
195 void SerializeSequence(std::bitset<10> optionalOrDefaultMask,
196 bool isExtensionMarkerPresent) const;
197 /**
198 * Serialize a sequence
199 * \param optionalOrDefaultMask Mask to serialize
200 * \param isExtensionMarkerPresent true if Extension Marker is present
201 */
202 void SerializeSequence(std::bitset<11> optionalOrDefaultMask,
203 bool isExtensionMarkerPresent) const;
204
205 /**
206 * Serialize a bitstring
207 * \param bitstring bitstring to serialize
208 */
209 template <int N>
210 void SerializeBitstring(std::bitset<N> bitstring) const;
211 /**
212 * Serialize a bitstring
213 * \param bitstring bitstring to serialize
214 */
215 void SerializeBitstring(std::bitset<1> bitstring) const;
216 /**
217 * Serialize a bitstring
218 * \param bitstring bitstring to serialize
219 */
220 void SerializeBitstring(std::bitset<2> bitstring) const;
221 /**
222 * Serialize a bitstring
223 * \param bitstring bitstring to serialize
224 */
225 void SerializeBitstring(std::bitset<8> bitstring) const;
226 /**
227 * Serialize a bitstring
228 * \param bitstring bitstring to serialize
229 */
230 void SerializeBitstring(std::bitset<10> bitstring) const;
231 /**
232 * Serialize a bitstring
233 * \param bitstring bitstring to serialize
234 */
235 void SerializeBitstring(std::bitset<16> bitstring) const;
236 /**
237 * Serialize a bitstring
238 * \param bitstring bitstring to serialize
239 */
240 void SerializeBitstring(std::bitset<27> bitstring) const;
241 /**
242 * Serialize a bitstring
243 * \param bitstring bitstring to serialize
244 */
245 void SerializeBitstring(std::bitset<28> bitstring) const;
246 /**
247 * Serialize a bitstring
248 * \param bitstring bitstring to serialize
249 */
250 void SerializeBitstring(std::bitset<32> bitstring) const;
251
252 // Deserialization functions
253
254 /**
255 * Deserialize a bitset
256 * \param data buffer to store the result
257 * \param bIterator buffer iterator
258 * \returns the modified buffer iterator
259 */
260 template <int N>
261 Buffer::Iterator DeserializeBitset(std::bitset<N>* data, Buffer::Iterator bIterator);
262 /**
263 * Deserialize a bitset
264 * \param data buffer to store the result
265 * \param bIterator buffer iterator
266 * \returns the modified buffer iterator
267 */
269
270 /**
271 * Deserialize a boolean
272 * \param value buffer to store the result
273 * \param bIterator buffer iterator
274 * \returns the modified buffer iterator
275 */
277 /**
278 * Deserialize an integer
279 * \param n buffer to store the result
280 * \param nmin min value to serialize
281 * \param nmax max value to serialize
282 * \param bIterator buffer iterator
283 * \returns the modified buffer iterator
284 */
285 Buffer::Iterator DeserializeInteger(int* n, int nmin, int nmax, Buffer::Iterator bIterator);
286 /**
287 * Deserialize a Choice (set of options)
288 * \param numOptions number of options
289 * \param isExtensionMarkerPresent true if extension mark is present
290 * \param selectedOption buffer to store the result
291 * \param bIterator buffer iterator
292 * \returns the modified buffer iterator
293 */
294 Buffer::Iterator DeserializeChoice(int numOptions,
295 bool isExtensionMarkerPresent,
296 int* selectedOption,
297 Buffer::Iterator bIterator);
298 /**
299 * Deserialize an Enum
300 * \param numElems number of elements in the enum
301 * \param selectedElem buffer to store the result
302 * \param bIterator buffer iterator
303 * \returns the modified buffer iterator
304 */
305 Buffer::Iterator DeserializeEnum(int numElems, int* selectedElem, Buffer::Iterator bIterator);
306
307 /**
308 * Deserialize a sequence
309 * \param optionalOrDefaultMask buffer to store the result
310 * \param isExtensionMarkerPresent true if Extension Marker is present
311 * \param bIterator buffer iterator
312 * \returns the modified buffer iterator
313 */
314 template <int N>
315 Buffer::Iterator DeserializeSequence(std::bitset<N>* optionalOrDefaultMask,
316 bool isExtensionMarkerPresent,
317 Buffer::Iterator bIterator);
318 /**
319 * Deserialize a sequence
320 * \param optionalOrDefaultMask buffer to store the result
321 * \param isExtensionMarkerPresent true if Extension Marker is present
322 * \param bIterator buffer iterator
323 * \returns the modified buffer iterator
324 */
325 Buffer::Iterator DeserializeSequence(std::bitset<0>* optionalOrDefaultMask,
326 bool isExtensionMarkerPresent,
327 Buffer::Iterator bIterator);
328 /**
329 * Deserialize a sequence
330 * \param optionalOrDefaultMask buffer to store the result
331 * \param isExtensionMarkerPresent true if Extension Marker is present
332 * \param bIterator buffer iterator
333 * \returns the modified buffer iterator
334 */
335 Buffer::Iterator DeserializeSequence(std::bitset<1>* optionalOrDefaultMask,
336 bool isExtensionMarkerPresent,
337 Buffer::Iterator bIterator);
338 /**
339 * Deserialize a sequence
340 * \param optionalOrDefaultMask buffer to store the result
341 * \param isExtensionMarkerPresent true if Extension Marker is present
342 * \param bIterator buffer iterator
343 * \returns the modified buffer iterator
344 */
345 Buffer::Iterator DeserializeSequence(std::bitset<2>* optionalOrDefaultMask,
346 bool isExtensionMarkerPresent,
347 Buffer::Iterator bIterator);
348 /**
349 * Deserialize a sequence
350 * \param optionalOrDefaultMask buffer to store the result
351 * \param isExtensionMarkerPresent true if Extension Marker is present
352 * \param bIterator buffer iterator
353 * \returns the modified buffer iterator
354 */
355 Buffer::Iterator DeserializeSequence(std::bitset<3>* optionalOrDefaultMask,
356 bool isExtensionMarkerPresent,
357 Buffer::Iterator bIterator);
358 /**
359 * Deserialize a sequence
360 * \param optionalOrDefaultMask buffer to store the result
361 * \param isExtensionMarkerPresent true if Extension Marker is present
362 * \param bIterator buffer iterator
363 * \returns the modified buffer iterator
364 */
365 Buffer::Iterator DeserializeSequence(std::bitset<4>* optionalOrDefaultMask,
366 bool isExtensionMarkerPresent,
367 Buffer::Iterator bIterator);
368 /**
369 * Deserialize a sequence
370 * \param optionalOrDefaultMask buffer to store the result
371 * \param isExtensionMarkerPresent true if Extension Marker is present
372 * \param bIterator buffer iterator
373 * \returns the modified buffer iterator
374 */
375 Buffer::Iterator DeserializeSequence(std::bitset<5>* optionalOrDefaultMask,
376 bool isExtensionMarkerPresent,
377 Buffer::Iterator bIterator);
378 /**
379 * Deserialize a sequence
380 * \param optionalOrDefaultMask buffer to store the result
381 * \param isExtensionMarkerPresent true if Extension Marker is present
382 * \param bIterator buffer iterator
383 * \returns the modified buffer iterator
384 */
385 Buffer::Iterator DeserializeSequence(std::bitset<6>* optionalOrDefaultMask,
386 bool isExtensionMarkerPresent,
387 Buffer::Iterator bIterator);
388
389 /**
390 * Deserialize a sequence
391 * \param optionalOrDefaultMask buffer to store the result
392 * \param isExtensionMarkerPresent true if Extension Marker is present
393 * \param bIterator buffer iterator
394 * \returns the modified buffer iterator
395 */
396 Buffer::Iterator DeserializeSequence(std::bitset<7>* optionalOrDefaultMask,
397 bool isExtensionMarkerPresent,
398 Buffer::Iterator bIterator);
399 /**
400 * Deserialize a sequence
401 * \param optionalOrDefaultMask buffer to store the result
402 * \param isExtensionMarkerPresent true if Extension Marker is present
403 * \param bIterator buffer iterator
404 * \returns the modified buffer iterator
405 */
406 Buffer::Iterator DeserializeSequence(std::bitset<9>* optionalOrDefaultMask,
407 bool isExtensionMarkerPresent,
408 Buffer::Iterator bIterator);
409 /**
410 * Deserialize a sequence
411 * \param optionalOrDefaultMask buffer to store the result
412 * \param isExtensionMarkerPresent true if Extension Marker is present
413 * \param bIterator buffer iterator
414 * \returns the modified buffer iterator
415 */
416 Buffer::Iterator DeserializeSequence(std::bitset<10>* optionalOrDefaultMask,
417 bool isExtensionMarkerPresent,
418 Buffer::Iterator bIterator);
419 /**
420 * Deserialize a sequence
421 * \param optionalOrDefaultMask buffer to store the result
422 * \param isExtensionMarkerPresent true if Extension Marker is present
423 * \param bIterator buffer iterator
424 * \returns the modified buffer iterator
425 */
426 Buffer::Iterator DeserializeSequence(std::bitset<11>* optionalOrDefaultMask,
427 bool isExtensionMarkerPresent,
428 Buffer::Iterator bIterator);
429
430 /**
431 * Deserialize a bitstring
432 * \param bitstring buffer to store the result
433 * \param bIterator buffer iterator
434 * \returns the modified buffer iterator
435 */
436 template <int N>
437 Buffer::Iterator DeserializeBitstring(std::bitset<N>* bitstring, Buffer::Iterator bIterator);
438 /**
439 * Deserialize a bitstring
440 * \param bitstring buffer to store the result
441 * \param bIterator buffer iterator
442 * \returns the modified buffer iterator
443 */
444 Buffer::Iterator DeserializeBitstring(std::bitset<1>* bitstring, Buffer::Iterator bIterator);
445 /**
446 * Deserialize a bitstring
447 * \param bitstring buffer to store the result
448 * \param bIterator buffer iterator
449 * \returns the modified buffer iterator
450 */
451 Buffer::Iterator DeserializeBitstring(std::bitset<2>* bitstring, Buffer::Iterator bIterator);
452 /**
453 * Deserialize a bitstring
454 * \param bitstring buffer to store the result
455 * \param bIterator buffer iterator
456 * \returns the modified buffer iterator
457 */
458 Buffer::Iterator DeserializeBitstring(std::bitset<8>* bitstring, Buffer::Iterator bIterator);
459 /**
460 * Deserialize a bitstring
461 * \param bitstring buffer to store the result
462 * \param bIterator buffer iterator
463 * \returns the modified buffer iterator
464 */
465 Buffer::Iterator DeserializeBitstring(std::bitset<10>* bitstring, Buffer::Iterator bIterator);
466 /**
467 * Deserialize a bitstring
468 * \param bitstring buffer to store the result
469 * \param bIterator buffer iterator
470 * \returns the modified buffer iterator
471 */
472 Buffer::Iterator DeserializeBitstring(std::bitset<16>* bitstring, Buffer::Iterator bIterator);
473 /**
474 * Deserialize a bitstring
475 * \param bitstring buffer to store the result
476 * \param bIterator buffer iterator
477 * \returns the modified buffer iterator
478 */
479 Buffer::Iterator DeserializeBitstring(std::bitset<27>* bitstring, Buffer::Iterator bIterator);
480 /**
481 * Deserialize a bitstring
482 * \param bitstring buffer to store the result
483 * \param bIterator buffer iterator
484 * \returns the modified buffer iterator
485 */
486 Buffer::Iterator DeserializeBitstring(std::bitset<28>* bitstring, Buffer::Iterator bIterator);
487 /**
488 * Deserialize a bitstring
489 * \param bitstring buffer to store the result
490 * \param bIterator buffer iterator
491 * \returns the modified buffer iterator
492 */
493 Buffer::Iterator DeserializeBitstring(std::bitset<32>* bitstring, Buffer::Iterator bIterator);
494
495 /**
496 * Deserialize nothing (null op)
497 * \param bIterator buffer iterator
498 * \returns the modified buffer iterator
499 */
501 /**
502 * Deserialize a Sequence
503 * \param numElems buffer to store the result
504 * \param nMax max value to serialize
505 * \param nMin min value to serialize
506 * \param bIterator buffer iterator
507 * \returns the modified buffer iterator
508 */
510 int nMax,
511 int nMin,
512 Buffer::Iterator bIterator);
513};
514
515} // namespace ns3
516
517#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:89
automatically resized byte buffer
Definition buffer.h:83
Protocol header serialization and deserialization.
Definition header.h:33
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]