A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ns3/object.h"
22 #include "ns3/log.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/double.h"
25 #include "ns3/boolean.h"
26 #include "ns3/trace-source-accessor.h"
27 #include "ns3/nstime.h"
28 #include "tcp-socket.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("TcpSocket");
31 
32 namespace ns3 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (TcpSocket);
35 
36 const char* const TcpSocket::TcpStateName[LAST_STATE] = { "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", "ESTABLISHED", "CLOSE_WAIT", "LAST_ACK", "FIN_WAIT_1", "FIN_WAIT_2", "CLOSING", "TIME_WAIT" };
37 
38 TypeId
40 {
41  static TypeId tid = TypeId ("ns3::TcpSocket")
42  .SetParent<Socket> ()
43  .AddAttribute ("SndBufSize",
44  "TcpSocket maximum transmit buffer size (bytes)",
45  UintegerValue (131072), // 128k
46  MakeUintegerAccessor (&TcpSocket::GetSndBufSize,
48  MakeUintegerChecker<uint32_t> ())
49  .AddAttribute ("RcvBufSize",
50  "TcpSocket maximum receive buffer size (bytes)",
51  UintegerValue (131072),
52  MakeUintegerAccessor (&TcpSocket::GetRcvBufSize,
54  MakeUintegerChecker<uint32_t> ())
55  .AddAttribute ("SegmentSize",
56  "TCP maximum segment size in bytes (may be adjusted based on MTU discovery)",
57  UintegerValue (536),
58  MakeUintegerAccessor (&TcpSocket::GetSegSize,
60  MakeUintegerChecker<uint32_t> ())
61  .AddAttribute ("SlowStartThreshold",
62  "TCP slow start threshold (bytes)",
63  UintegerValue (0xffff),
64  MakeUintegerAccessor (&TcpSocket::GetSSThresh,
66  MakeUintegerChecker<uint32_t> ())
67  .AddAttribute ("InitialCwnd",
68  "TCP initial congestion window size (segments)",
69  UintegerValue (1),
70  MakeUintegerAccessor (&TcpSocket::GetInitialCwnd,
72  MakeUintegerChecker<uint32_t> ())
73  .AddAttribute ("ConnTimeout",
74  "TCP retransmission timeout when opening connection (seconds)",
75  TimeValue (Seconds (3)),
76  MakeTimeAccessor (&TcpSocket::GetConnTimeout,
78  MakeTimeChecker ())
79  .AddAttribute ("ConnCount",
80  "Number of connection attempts (SYN retransmissions) before returning failure",
81  UintegerValue (6),
82  MakeUintegerAccessor (&TcpSocket::GetConnCount,
84  MakeUintegerChecker<uint32_t> ())
85  .AddAttribute ("DelAckTimeout",
86  "Timeout value for TCP delayed acks, in seconds",
87  TimeValue (Seconds (0.2)),
88  MakeTimeAccessor (&TcpSocket::GetDelAckTimeout,
90  MakeTimeChecker ())
91  .AddAttribute ("DelAckCount",
92  "Number of packets to wait before sending a TCP ack",
93  UintegerValue (2),
94  MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount,
96  MakeUintegerChecker<uint32_t> ())
97  .AddAttribute ("TcpNoDelay", "Set to true to disable Nagle's algorithm",
98  BooleanValue (true),
99  MakeBooleanAccessor (&TcpSocket::GetTcpNoDelay,
101  MakeBooleanChecker ())
102  .AddAttribute ("PersistTimeout",
103  "Persist timeout to probe for rx window",
104  TimeValue (Seconds (6)),
105  MakeTimeAccessor (&TcpSocket::GetPersistTimeout,
107  MakeTimeChecker ())
108  ;
109  return tid;
110 }
111 
113 {
115 }
116 
118 {
120 }
121 
122 } // namespace ns3
virtual void SetSndBufSize(uint32_t size)=0
Set the send buffer size.
Hold a bool native type.
Definition: boolean.h:38
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void SetSSThresh(uint32_t threshold)=0
Set the Slow Start Threshold.
virtual ~TcpSocket(void)
Definition: tcp-socket.cc:117
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void SetInitialCwnd(uint32_t cwnd)=0
Set the initial Congestion Window.
virtual void SetRcvBufSize(uint32_t size)=0
Set the receive buffer size.
virtual void SetPersistTimeout(Time timeout)=0
Set the timout for persistent connection.
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:66
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-socket.cc:39
static const char *const TcpStateName[LAST_STATE]
Literal names of TCP states for use in log messages.
Definition: tcp-socket.h:80
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual uint32_t GetSndBufSize(void) const =0
Get the send buffer size.
virtual void SetDelAckMaxCount(uint32_t count)=0
Set the number of packet to fire an ACK before delay timeout.
virtual void SetTcpNoDelay(bool noDelay)=0
Enable/Disable Nagle's algorithm.
virtual uint32_t GetSSThresh(void) const =0
Get the Slow Start Threshold.
virtual uint32_t GetRcvBufSize(void) const =0
Get the receive buffer size.
virtual void SetDelAckTimeout(Time timeout)=0
Set the time to delay an ACK.
virtual void SetConnCount(uint32_t count)=0
Set the number of connection retries before giving up.
virtual uint32_t GetSegSize(void) const =0
Get the segment size.
virtual Time GetDelAckTimeout(void) const =0
Get the time to delay an ACK.
virtual bool GetTcpNoDelay(void) const =0
Check if Nagle's algorithm is enabled or not.
virtual void SetConnTimeout(Time timeout)=0
Set the connection timeout.
virtual uint32_t GetDelAckMaxCount(void) const =0
Get the number of packet to fire an ACK before delay timeout.
virtual Time GetConnTimeout(void) const =0
Get the connection timeout.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:441
virtual void SetSegSize(uint32_t size)=0
Set the segment size.
a unique identifier for an interface.
Definition: type-id.h:49
virtual uint32_t GetInitialCwnd(void) const =0
Get the initial Congestion Window.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
virtual Time GetPersistTimeout(void) const =0
Get the timout for persistent connection.
virtual uint32_t GetConnCount(void) const =0
Get the number of connection retries before giving up.