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