src/node/tcp-socket.cc
author Lalith Suresh <suresh.lalith@gmail.com>
Sun, 18 Jul 2010 13:29:13 +0530
changeset 6339 366418369bda
parent 6197 ebe303de4725
permissions -rw-r--r--
Click now handles all packets pertaining to Mac High models
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "ns3/object.h"
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/log.h"
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/uinteger.h"
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    24
#include "ns3/double.h"
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/trace-source-accessor.h"
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    26
#include "ns3/nstime.h"
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "tcp-socket.h"
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
NS_LOG_COMPONENT_DEFINE ("TcpSocket");
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
namespace ns3 {
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
NS_OBJECT_ENSURE_REGISTERED (TcpSocket);
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
TypeId
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
TcpSocket::GetTypeId (void)
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
{
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
  static TypeId tid = TypeId ("ns3::TcpSocket")
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
    .SetParent<Socket> ()
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    40
    .AddAttribute ("SndBufSize",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    41
                   "TcpSocket maximum transmit buffer size (bytes)",
4611
eb6e86305f4f bug 596: unbounded tcp queue is evil
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 3644
diff changeset
    42
                   UintegerValue (131072), // 128k
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    43
                   MakeUintegerAccessor (&TcpSocket::GetSndBufSize,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    44
                                         &TcpSocket::SetSndBufSize),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    45
                   MakeUintegerChecker<uint32_t> ())
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
    .AddAttribute ("RcvBufSize",
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
                   "TcpSocket maximum receive buffer size (bytes)",
6197
ebe303de4725 Bug 835 - Unlimited receive queues in sockets == evil
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4611
diff changeset
    48
                   UintegerValue (131072),
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
                   MakeUintegerAccessor (&TcpSocket::GetRcvBufSize,
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
                                         &TcpSocket::SetRcvBufSize),
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
                   MakeUintegerChecker<uint32_t> ())
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    52
    .AddAttribute ("SegmentSize",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    53
                   "TCP maximum segment size in bytes (may be adjusted based on MTU discovery)",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    54
                   UintegerValue (536),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    55
                   MakeUintegerAccessor (&TcpSocket::GetSegSize,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    56
                                         &TcpSocket::SetSegSize),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    57
                   MakeUintegerChecker<uint32_t> ())
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    58
    .AddAttribute ("SlowStartThreshold",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    59
                   "TCP slow start threshold (bytes)",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    60
                   UintegerValue (0xffff),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    61
                   MakeUintegerAccessor (&TcpSocket::GetSSThresh,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    62
                                         &TcpSocket::SetSSThresh),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    63
                   MakeUintegerChecker<uint32_t> ())
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    64
    .AddAttribute ("InitialCwnd",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    65
                   "TCP initial congestion window size (segments)",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    66
                   UintegerValue (1),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    67
                   MakeUintegerAccessor (&TcpSocket::GetInitialCwnd,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    68
                                         &TcpSocket::SetInitialCwnd),
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
                   MakeUintegerChecker<uint32_t> ())
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    70
    .AddAttribute ("ConnTimeout",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    71
                   "TCP retransmission timeout when opening connection (seconds)",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    72
                   TimeValue (Seconds (3)),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    73
                   MakeTimeAccessor (&TcpSocket::GetConnTimeout,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    74
                                     &TcpSocket::SetConnTimeout),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    75
                   MakeTimeChecker ())
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    76
    .AddAttribute ("ConnCount",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    77
                   "Number of connection attempts (SYN retransmissions) before returning failure",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    78
                   UintegerValue (6),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    79
                   MakeUintegerAccessor (&TcpSocket::GetConnCount,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    80
                                         &TcpSocket::SetConnCount),
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
                   MakeUintegerChecker<uint32_t> ())
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    82
    .AddAttribute ("DelAckTimeout",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    83
                   "Timeout value for TCP delayed acks, in seconds",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    84
                   TimeValue (Seconds (0.2)),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    85
                   MakeTimeAccessor (&TcpSocket::GetDelAckTimeout,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    86
                                       &TcpSocket::SetDelAckTimeout),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    87
                   MakeTimeChecker ())
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    88
    .AddAttribute ("DelAckCount",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    89
                   "Number of packets to wait before sending a TCP ack",
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    90
                   UintegerValue (2),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    91
                   MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount,
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    92
                                         &TcpSocket::SetDelAckMaxCount),
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3135
diff changeset
    93
                   MakeUintegerChecker<uint32_t> ())
3135
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
    ;
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
  return tid;
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
}
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
TcpSocket::TcpSocket ()
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
{
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  NS_LOG_FUNCTION_NOARGS ();
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
}
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
TcpSocket::~TcpSocket ()
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
{
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  NS_LOG_FUNCTION_NOARGS ();
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
}
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
2ae291cb16ae Add missing files
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
}; // namespace ns3