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