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