A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
9
#ifndef HEADER_H
10
#define HEADER_H
11
12
#include "
buffer.h
"
13
#include "
chunk.h
"
14
15
#include <stdint.h>
16
17
namespace
ns3
18
{
19
20
/**
21
* \ingroup packet
22
*
23
* \brief Protocol header serialization and deserialization.
24
*
25
* Every Protocol header which needs to be inserted or removed
26
* from a Packet instance must derive from this base class and
27
* implement the pure virtual methods defined here.
28
*
29
* Sample code which shows how to create a new type of Header, and how to use it,
30
* is shown in the sample file samples/main-packet-header.cc
31
*/
32
class
Header
:
public
Chunk
33
{
34
public
:
35
/**
36
* \brief Get the type ID.
37
* \return the object TypeId
38
*/
39
static
TypeId
GetTypeId
();
40
~Header
()
override
;
41
42
using
Chunk::Deserialize
;
43
/**
44
* \returns the expected size of the header.
45
*
46
* This method is used by Packet::AddHeader
47
* to store a header into the byte buffer of a packet. This method
48
* should return the number of bytes which are needed to store
49
* the full header data by Serialize.
50
*/
51
virtual
uint32_t
GetSerializedSize
()
const
= 0;
52
/**
53
* \param start an iterator which points to where the header should
54
* be written.
55
*
56
* This method is used by Packet::AddHeader to
57
* store a header into the byte buffer of a packet.
58
* The data written
59
* is expected to match bit-for-bit the representation of this
60
* header in a real network.
61
*/
62
virtual
void
Serialize
(
Buffer::Iterator
start)
const
= 0;
63
/**
64
* \param start an iterator which points to where the header should
65
* read from.
66
* \returns the number of bytes read.
67
*
68
* This method is used by Packet::RemoveHeader to
69
* re-create a header from the byte buffer of a packet.
70
* The data read is expected to
71
* match bit-for-bit the representation of this header in real
72
* networks.
73
*
74
* Note that data is not actually removed from the buffer to
75
* which the iterator points. Both Packet::RemoveHeader() and
76
* Packet::PeekHeader() call Deserialize(), but only the RemoveHeader()
77
* has additional statements to remove the header bytes from the
78
* underlying buffer and associated metadata.
79
*/
80
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
= 0;
81
/**
82
* \param os output stream
83
* This method is used by Packet::Print to print the
84
* content of a header as ascii data to a c++ output stream.
85
* Although the header is free to format its output as it
86
* wishes, it is recommended to follow a few rules to integrate
87
* with the packet pretty printer: start with flags, small field
88
* values located between a pair of parens. Values should be separated
89
* by whitespace. Follow the parens with the important fields,
90
* separated by whitespace.
91
* i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5
92
*/
93
void
Print
(std::ostream& os)
const override
= 0;
94
};
95
96
/**
97
* \brief Stream insertion operator.
98
*
99
* \param os the stream
100
* \param header the header
101
* \returns a reference to the stream
102
*/
103
std::ostream&
operator<<
(std::ostream& os,
const
Header
& header);
104
105
}
// namespace ns3
106
107
#endif
/* HEADER_H */
buffer.h
chunk.h
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Chunk
abstract base class for ns3::Header and ns3::Trailer
Definition
chunk.h:25
ns3::Chunk::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Header::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
header.cc:26
ns3::Header::~Header
~Header() override
Definition
header.cc:20
ns3::Header::GetSerializedSize
virtual uint32_t GetSerializedSize() const =0
ns3::Header::Print
void Print(std::ostream &os) const override=0
ns3::Header::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override=0
ns3::Header::Serialize
virtual void Serialize(Buffer::Iterator start) const =0
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
src
network
model
header.h
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0