A Discrete-Event Network Simulator
API
tcp-socket.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #define __STDC_LIMIT_MACROS
22 
23 #include "ns3/object.h"
24 #include "ns3/log.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/double.h"
27 #include "ns3/boolean.h"
28 #include "ns3/trace-source-accessor.h"
29 #include "ns3/nstime.h"
30 #include "tcp-socket.h"
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("TcpSocket");
35 
36 NS_OBJECT_ENSURE_REGISTERED (TcpSocket);
37 
38 const char* const
39 TcpSocket::TcpStateName[TcpSocket::LAST_STATE] = { "CLOSED", "LISTEN", "SYN_SENT",
40  "SYN_RCVD", "ESTABLISHED", "CLOSE_WAIT",
41  "LAST_ACK", "FIN_WAIT_1", "FIN_WAIT_2",
42  "CLOSING", "TIME_WAIT" };
43 
44 TypeId
46 {
47  static TypeId tid = TypeId ("ns3::TcpSocket")
48  .SetParent<Socket> ()
49  .SetGroupName ("Internet")
50  .AddAttribute ("SndBufSize",
51  "TcpSocket maximum transmit buffer size (bytes)",
52  UintegerValue (131072), // 128k
55  MakeUintegerChecker<uint32_t> ())
56  .AddAttribute ("RcvBufSize",
57  "TcpSocket maximum receive buffer size (bytes)",
58  UintegerValue (131072),
61  MakeUintegerChecker<uint32_t> ())
62  .AddAttribute ("SegmentSize",
63  "TCP maximum segment size in bytes (may be adjusted based on MTU discovery)",
64  UintegerValue (536),
67  MakeUintegerChecker<uint32_t> ())
68  .AddAttribute ("InitialSlowStartThreshold",
69  "TCP initial slow start threshold (bytes)",
73  MakeUintegerChecker<uint32_t> ())
74  .AddAttribute ("InitialCwnd",
75  "TCP initial congestion window size (segments)",
76  UintegerValue (10),
79  MakeUintegerChecker<uint32_t> ())
80  .AddAttribute ("ConnTimeout",
81  "TCP retransmission timeout when opening connection (seconds)",
82  TimeValue (Seconds (3)),
85  MakeTimeChecker ())
86  .AddAttribute ("ConnCount",
87  "Number of connection attempts (SYN retransmissions) before "
88  "returning failure",
89  UintegerValue (6),
92  MakeUintegerChecker<uint32_t> ())
93  .AddAttribute ("DataRetries",
94  "Number of data retransmission attempts",
95  UintegerValue (6),
98  MakeUintegerChecker<uint32_t> ())
99  .AddAttribute ("DelAckTimeout",
100  "Timeout value for TCP delayed acks, in seconds",
101  TimeValue (Seconds (0.2)),
104  MakeTimeChecker ())
105  .AddAttribute ("DelAckCount",
106  "Number of packets to wait before sending a TCP ack",
107  UintegerValue (2),
110  MakeUintegerChecker<uint32_t> ())
111  .AddAttribute ("TcpNoDelay", "Set to true to disable Nagle's algorithm",
112  BooleanValue (true),
116  .AddAttribute ("PersistTimeout",
117  "Persist timeout to probe for rx window",
118  TimeValue (Seconds (6)),
121  MakeTimeChecker ())
122  ;
123  return tid;
124 }
125 
127 {
128  NS_LOG_FUNCTION (this);
129 }
130 
132 {
133  NS_LOG_FUNCTION (this);
134 }
135 
136 } // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:67
virtual void SetInitialSSThresh(uint32_t threshold)=0
Set the initial Slow Start Threshold.
virtual ~TcpSocket(void)
Definition: tcp-socket.cc:131
virtual bool GetTcpNoDelay(void) const =0
Check if Nagle's algorithm is enabled or not.
virtual void SetRcvBufSize(uint32_t size)=0
Set the receive buffer size.
static const char *const TcpStateName[TcpSocket::LAST_STATE]
Literal names of TCP states for use in log messages.
Definition: tcp-socket.h:94
virtual Time GetPersistTimeout(void) const =0
Get the timeout for persistent connection.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-socket.cc:45
virtual void SetDelAckMaxCount(uint32_t count)=0
Set the number of packet to fire an ACK before delay timeout.
virtual uint32_t GetDataRetries(void) const =0
Get the number of data transmission retries before giving up.
virtual void SetPersistTimeout(Time timeout)=0
Set the timeout for persistent connection.
virtual uint32_t GetInitialSSThresh(void) const =0
Get the initial Slow Start Threshold.
virtual uint32_t GetDelAckMaxCount(void) const =0
Get the number of packet to fire an ACK before delay timeout.
virtual uint32_t GetSynRetries(void) const =0
Get the number of connection retries before giving up.
virtual uint32_t GetSegSize(void) const =0
Get the segment size.
virtual void SetSegSize(uint32_t size)=0
Set the segment size.
virtual uint32_t GetSndBufSize(void) const =0
Get the send buffer size.
virtual uint32_t GetRcvBufSize(void) const =0
Get the receive buffer size.
virtual void SetSndBufSize(uint32_t size)=0
Set the send buffer size.
virtual Time GetConnTimeout(void) const =0
Get the connection timeout.
virtual void SetDataRetries(uint32_t retries)=0
Set the number of data transmission retries before giving up.
virtual void SetDelAckTimeout(Time timeout)=0
Set the time to delay an ACK.
virtual void SetConnTimeout(Time timeout)=0
Set the connection timeout.
virtual void SetTcpNoDelay(bool noDelay)=0
Enable/Disable Nagle's algorithm.
virtual Time GetDelAckTimeout(void) const =0
Get the time to delay an ACK.
virtual uint32_t GetInitialCwnd(void) const =0
Get the initial Congestion Window.
virtual void SetInitialCwnd(uint32_t cwnd)=0
Set the initial Congestion Window.
virtual void SetSynRetries(uint32_t count)=0
Set the number of connection retries before giving up.
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: boolean.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
@ LAST_STATE
Last state, used only in debug messages
Definition: tcp-socket.h:88
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522