A Discrete-Event Network Simulator
API
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 
43 namespace ns3
44 {
45 namespace dsr
46 {
81 class DsrFsHeader : public Header
82 {
83  public:
88  static TypeId GetTypeId();
93  TypeId GetInstanceTypeId() const override;
97  DsrFsHeader();
101  ~DsrFsHeader() override;
106  void SetNextHeader(uint8_t protocol);
111  uint8_t GetNextHeader() const;
116  void SetMessageType(uint8_t messageType);
121  uint8_t GetMessageType() const;
126  void SetSourceId(uint16_t sourceId);
131  uint16_t GetSourceId() const;
136  void SetDestId(uint16_t destId);
141  uint16_t GetDestId() const;
146  void SetPayloadLength(uint16_t length);
151  uint16_t GetPayloadLength() const;
156  void Print(std::ostream& os) const override;
161  uint32_t GetSerializedSize() const override;
166  void Serialize(Buffer::Iterator start) const override;
172  uint32_t Deserialize(Buffer::Iterator start) override;
173 
174  private:
178  uint8_t m_nextHeader;
182  uint8_t m_messageType;
186  uint16_t m_payloadLen;
190  uint16_t m_sourceId;
194  uint16_t m_destId;
199 };
200 
212 {
213  public:
218  DsrOptionField(uint32_t optionsOffset);
222  ~DsrOptionField();
227  uint32_t GetSerializedSize() const;
232  void Serialize(Buffer::Iterator start) const;
239  uint32_t Deserialize(Buffer::Iterator start, uint32_t length);
244  void AddDsrOption(const DsrOptionHeader& option);
250  uint32_t GetDsrOptionsOffset() const;
256 
257  private:
263  uint32_t CalculatePad(DsrOptionHeader::Alignment alignment) const;
271  uint32_t m_optionsOffset;
272 };
273 
279 {
280  public:
285  static TypeId GetTypeId();
290  TypeId GetInstanceTypeId() const override;
298  ~DsrRoutingHeader() override;
303  void Print(std::ostream& os) const override;
308  uint32_t GetSerializedSize() const override;
313  void Serialize(Buffer::Iterator start) const override;
319  uint32_t Deserialize(Buffer::Iterator start) override;
320 };
321 
322 static inline std::ostream&
323 operator<<(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
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
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.
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 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