A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-fs-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 * Work supported in part by NSF FIND (Future Internet Design) Program
15 * under grant CNS-0626918 (Postmodern Internet Architecture),
16 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17 * US Department of Defense (DoD), and ITTC at The University of Kansas.
18 */
19
20#ifndef DSR_FS_HEADER_H
21#define DSR_FS_HEADER_H
22
23#include "dsr-option-header.h"
24
25#include "ns3/header.h"
26#include "ns3/ipv4-address.h"
27
28#include <list>
29#include <ostream>
30#include <vector>
31
32namespace ns3
33{
34namespace dsr
35{
36/**
37 * @class DsrHeader
38 * @brief Header for Dsr Routing.
39 */
40
41/**
42* @ingroup dsr
43* @brief Dsr fixed size header Format
44 \verbatim
45 | 0 | 1 | 2 | 3 |
46 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 | Next Header |F| Reservd | Payload Length |
49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 | Options |
51 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 \endverbatim
53*/
54
55/**
56* @ingroup dsr
57* @brief The modified version of Dsr fixed size header Format
58 \verbatim
59 | 0 | 1 | 2 | 3 |
60 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
61 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 | Next Header |F| Message Type | Payload Length |
63 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 | Source Id | Dest Id |
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 | Options |
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 \endverbatim
69*/
70class DsrFsHeader : public Header
71{
72 public:
73 /**
74 * @brief Get the type identificator.
75 * @return type identificator
76 */
77 static TypeId GetTypeId();
78 /**
79 * @brief Get the instance type ID.
80 * @return instance type ID
81 */
82 TypeId GetInstanceTypeId() const override;
83 /**
84 * @brief Constructor.
85 */
87 /**
88 * @brief Destructor.
89 */
90 ~DsrFsHeader() override;
91 /**
92 * @brief Set the "Next header" field.
93 * @param protocol the next header number
94 */
95 void SetNextHeader(uint8_t protocol);
96 /**
97 * @brief Get the next header.
98 * @return the next header number
99 */
100 uint8_t GetNextHeader() const;
101 /**
102 * brief Set the message type of the header.
103 * @param messageType the message type of the header
104 */
105 void SetMessageType(uint8_t messageType);
106 /**
107 * brief Get the message type of the header.
108 * @return message type the message type of the header
109 */
110 uint8_t GetMessageType() const;
111 /**
112 * brief Set the source ID of the header.
113 * @param sourceId the source ID of the header
114 */
115 void SetSourceId(uint16_t sourceId);
116 /**
117 * brief Get the source ID of the header.
118 * @return source ID the source ID of the header
119 */
120 uint16_t GetSourceId() const;
121 /**
122 * brief Set the dest ID of the header.
123 * @param destId the destination ID of the header
124 */
125 void SetDestId(uint16_t destId);
126 /**
127 * brief Get the dest ID of the header.
128 * @return dest ID the dest ID of the header
129 */
130 uint16_t GetDestId() const;
131 /**
132 * brief Set the payload length of the header.
133 * @param length the payload length of the header in bytes
134 */
135 void SetPayloadLength(uint16_t length);
136 /**
137 * @brief Get the payload length of the header.
138 * @return the payload length of the header
139 */
140 uint16_t GetPayloadLength() const;
141 /**
142 * @brief Print some information about the packet.
143 * @param os output stream
144 */
145 void Print(std::ostream& os) const override;
146 /**
147 * @brief Get the serialized size of the packet.
148 * @return size
149 */
150 uint32_t GetSerializedSize() const override;
151 /**
152 * @brief Serialize the packet.
153 * @param start Buffer iterator
154 */
155 void Serialize(Buffer::Iterator start) const override;
156 /**
157 * @brief Deserialize the packet.
158 * @param start Buffer iterator
159 * @return size of the packet
160 */
161 uint32_t Deserialize(Buffer::Iterator start) override;
162
163 private:
164 /**
165 * @brief The "next header" field.
166 */
168 /**
169 * @brief The type of the message.
170 */
172 /**
173 * @brief The "payload length" field.
174 */
175 uint16_t m_payloadLen;
176 /**
177 * @brief The source node id
178 */
179 uint16_t m_sourceId;
180 /**
181 * @brief The destination node id
182 */
183 uint16_t m_destId;
184 /**
185 * @brief The data of the extension.
186 */
188};
189
190/**
191 * @class DsrOptionField
192 * @brief Option field for an DsrFsHeader
193 * Enables adding options to an DsrFsHeader
194 *
195 * Implementor's note: Make sure to add the result of
196 * OptionField::GetSerializedSize () to your DsrFsHeader::GetSerializedSize ()
197 * return value. Call OptionField::Serialize and OptionField::Deserialize at the
198 * end of your corresponding DsrFsHeader methods.
199 */
201{
202 public:
203 /**
204 * @brief Constructor.
205 * @param optionsOffset option offset
206 */
207 DsrOptionField(uint32_t optionsOffset);
208 /**
209 * @brief Destructor.
210 */
212 /**
213 * @brief Get the serialized size of the packet.
214 * @return size
215 */
217 /**
218 * @brief Serialize all added options.
219 * @param start Buffer iterator
220 */
221 void Serialize(Buffer::Iterator start) const;
222 /**
223 * @brief Deserialize the packet.
224 * @param start Buffer iterator
225 * @param length length
226 * @return size of the packet
227 */
229 /**
230 * @brief Serialize the option, prepending pad1 or padn option as necessary
231 * @param option the option header to serialize
232 */
233 void AddDsrOption(const DsrOptionHeader& option);
234 /**
235 * @brief Get the offset where the options begin, measured from the start of
236 * the extension header.
237 * @return the offset from the start of the extension header
238 */
240 /**
241 * @brief Get the buffer.
242 * @return buffer
243 */
245
246 private:
247 /**
248 * @brief Calculate padding.
249 * @param alignment alignment
250 * @return the number of bytes required to pad
251 */
253 /**
254 * @brief Data payload.
255 */
257 /**
258 * @brief Offset.
259 */
261};
262
263/**
264 * @class DsrRoutingHeader
265 * @brief Header of Dsr Routing
266 */
268{
269 public:
270 /**
271 * @brief Get the type identificator.
272 * @return type identificator
273 */
274 static TypeId GetTypeId();
275 /**
276 * @brief Get the instance type ID.
277 * @return instance type ID
278 */
279 TypeId GetInstanceTypeId() const override;
280 /**
281 * @brief Constructor.
282 */
284 /**
285 * @brief Destructor.
286 */
287 ~DsrRoutingHeader() override;
288 /**
289 * @brief Print some information about the packet.
290 * @param os output stream
291 */
292 void Print(std::ostream& os) const override;
293 /**
294 * @brief Get the serialized size of the packet.
295 * @return size
296 */
297 uint32_t GetSerializedSize() const override;
298 /**
299 * @brief Serialize the packet.
300 * @param start Buffer iterator
301 */
302 void Serialize(Buffer::Iterator start) const override;
303 /**
304 * @brief Deserialize the packet.
305 * @param start Buffer iterator
306 * @return size of the packet
307 */
308 uint32_t Deserialize(Buffer::Iterator start) override;
309};
310
311static inline std::ostream&
312operator<<(std::ostream& os, const DsrRoutingHeader& dsr)
313{
314 dsr.Print(os);
315 return os;
316}
317
318} // namespace dsr
319} // namespace ns3
320
321#endif /* DSR_FS_HEADER_H */
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
Dsr fixed size header Format.
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
DsrFsHeader()
Constructor.
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
uint8_t GetMessageType() const
brief Get the message type of the header.
static TypeId GetTypeId()
Get the type identificator.
uint8_t GetNextHeader() const
Get the next header.
uint16_t m_destId
The destination node id.
uint16_t m_sourceId
The source node id.
uint16_t GetSourceId() const
brief Get the source ID of the header.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint16_t GetDestId() const
brief Get the dest ID of the header.
uint8_t m_messageType
The type of the message.
uint16_t m_payloadLen
The "payload length" field.
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint16_t GetPayloadLength() const
Get the payload length of the header.
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
uint8_t m_nextHeader
The "next header" field.
Buffer m_data
The data of the extension.
void Print(std::ostream &os) const override
Print some information about the packet.
~DsrFsHeader() override
Destructor.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Option field for an DsrFsHeader Enables adding options to an DsrFsHeader.
void Serialize(Buffer::Iterator start) const
Serialize all added options.
void AddDsrOption(const DsrOptionHeader &option)
Serialize the option, prepending pad1 or padn option as necessary.
uint32_t Deserialize(Buffer::Iterator start, uint32_t length)
Deserialize the packet.
Buffer m_optionData
Data payload.
Buffer GetDsrOptionBuffer()
Get the buffer.
uint32_t m_optionsOffset
Offset.
uint32_t GetDsrOptionsOffset() const
Get the offset where the options begin, measured from the start of the extension header.
uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint32_t CalculatePad(DsrOptionHeader::Alignment alignment) const
Calculate padding.
DsrOptionField(uint32_t optionsOffset)
Constructor.
header for Dsr Options.
Header of Dsr Routing.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
~DsrRoutingHeader() override
Destructor.
void Print(std::ostream &os) const override
Print some information about the packet.
static TypeId GetTypeId()
Get the type identificator.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
static std::ostream & operator<<(std::ostream &os, const DsrRoutingHeader &dsr)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Represents the alignment requirements of an option header.