A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-option.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Adrian Sai-wah Tam
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
7 */
8
9#ifndef TCP_OPTION_H
10#define TCP_OPTION_H
11
12#include "ns3/buffer.h"
13#include "ns3/object-factory.h"
14#include "ns3/object.h"
15
16#include <stdint.h>
17
18namespace ns3
19{
20
21/**
22 * @ingroup tcp
23 *
24 * Base class for all kinds of TCP options
25 */
26class TcpOption : public Object
27{
28 public:
29 TcpOption();
30 ~TcpOption() override;
31
32 /**
33 * @brief Get the type ID.
34 * @return the object TypeId
35 */
36 static TypeId GetTypeId();
37
38 TypeId GetInstanceTypeId() const override;
39
40 /**
41 * The option Kind, as defined in the respective RFCs.
42 */
43 enum Kind
44 {
45 // Remember to extend IsKindKnown() with new value, when adding values here
46 //
47 END = 0, //!< END
48 NOP = 1, //!< NOP
49 MSS = 2, //!< MSS
50 WINSCALE = 3, //!< WINSCALE
51 SACKPERMITTED = 4, //!< SACKPERMITTED
52 SACK = 5, //!< SACK
53 TS = 8, //!< TS
54 UNKNOWN = 255 //!< not a standardized value; for unknown recv'd options
55 };
56
57 /**
58 * @brief Print the Option contents
59 * @param os the output stream
60 */
61 virtual void Print(std::ostream& os) const = 0;
62 /**
63 * @brief Serialize the Option to a buffer iterator
64 * @param start the buffer iterator
65 */
66 virtual void Serialize(Buffer::Iterator start) const = 0;
67
68 /**
69 * @brief Deserialize the Option from a buffer iterator
70 * @param start the buffer iterator
71 * @returns the number of deserialized bytes
72 */
74
75 /**
76 * @brief Get the `kind' (as in \RFC{793}) of this option
77 * @return the Option Kind
78 */
79 virtual uint8_t GetKind() const = 0;
80 /**
81 * @brief Returns number of bytes required for Option
82 * serialization.
83 *
84 * @returns number of bytes required for Option
85 * serialization
86 */
87 virtual uint32_t GetSerializedSize() const = 0;
88
89 /**
90 * @brief Creates an option
91 * @param kind the option kind
92 * @return the requested option or an ns3::UnknownOption if the option is not supported
93 */
94 static Ptr<TcpOption> CreateOption(uint8_t kind);
95
96 /**
97 * @brief Check if the option is implemented
98 * @param kind the Option kind
99 * @return true if the option is known
100 */
101 static bool IsKindKnown(uint8_t kind);
102};
103
104/**
105 * @ingroup tcp
106 *
107 * @brief An unknown TCP option.
108 *
109 * An unknown option can be deserialized and (only if deserialized previously)
110 * serialized again.
111 */
113{
114 public:
116 ~TcpOptionUnknown() override;
117
118 /**
119 * @brief Get the type ID.
120 * @return the object TypeId
121 */
122 static TypeId GetTypeId();
123 TypeId GetInstanceTypeId() const override;
124
125 void Print(std::ostream& os) const override;
126 void Serialize(Buffer::Iterator start) const override;
127 uint32_t Deserialize(Buffer::Iterator start) override;
128
129 uint8_t GetKind() const override;
130 uint32_t GetSerializedSize() const override;
131
132 private:
133 uint8_t m_kind; //!< The unknown option kind
134 uint32_t m_size; //!< The unknown option size
135 uint8_t m_content[40]; //!< The option data
136};
137
138} // namespace ns3
139
140#endif /* TCP_OPTION */
iterator in a Buffer instance
Definition buffer.h:89
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Base class for all kinds of TCP options.
Definition tcp-option.h:27
static Ptr< TcpOption > CreateOption(uint8_t kind)
Creates an option.
Definition tcp-option.cc:51
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition tcp-option.cc:45
virtual void Serialize(Buffer::Iterator start) const =0
Serialize the Option to a buffer iterator.
virtual uint8_t GetKind() const =0
Get the ‘kind’ (as in RFC 793 ) of this option.
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the Option from a buffer iterator.
~TcpOption() override
Definition tcp-option.cc:33
static bool IsKindKnown(uint8_t kind)
Check if the option is implemented.
Definition tcp-option.cc:84
virtual void Print(std::ostream &os) const =0
Print the Option contents.
Kind
The option Kind, as defined in the respective RFCs.
Definition tcp-option.h:44
@ UNKNOWN
not a standardized value; for unknown recv'd options
Definition tcp-option.h:54
@ SACKPERMITTED
SACKPERMITTED.
Definition tcp-option.h:51
@ WINSCALE
WINSCALE.
Definition tcp-option.h:50
virtual uint32_t GetSerializedSize() const =0
Returns number of bytes required for Option serialization.
static TypeId GetTypeId()
Get the type ID.
Definition tcp-option.cc:38
An unknown TCP option.
Definition tcp-option.h:113
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
uint8_t m_content[40]
The option data.
Definition tcp-option.h:135
void Print(std::ostream &os) const override
Print the Option contents.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
uint32_t m_size
The unknown option size.
Definition tcp-option.h:134
~TcpOptionUnknown() override
uint8_t m_kind
The unknown option kind.
Definition tcp-option.h:133
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.