src/internet-node/tcp-socket-impl.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Thu, 29 May 2008 15:10:40 +0100
changeset 3175 ff46939c1b4a
parent 3136 a59b9ce95b6b
child 3229 ec45f705b9ca
permissions -rw-r--r--
Fix TCP valgrind problem (bug #194): TcpSocketImpl::m_wouldBlock was not always being initialized.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 Georgia Tech Research Corporation
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/node.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/inet-socket-address.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/log.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/ipv4.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "tcp-socket-impl.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "tcp-l4-protocol.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ipv4-end-point.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ipv4-l4-demux.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "ns3/simulation-singleton.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "tcp-typedefs.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "ns3/simulator.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "ns3/packet.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "ns3/uinteger.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
#include "ns3/trace-source-accessor.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
#include <algorithm>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
NS_LOG_COMPONENT_DEFINE ("TcpSocketImpl");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
using namespace std;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
namespace ns3 {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
NS_OBJECT_ENSURE_REGISTERED (TcpSocketImpl);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
TypeId
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
TcpSocketImpl::GetTypeId ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
  static TypeId tid = TypeId("ns3::TcpSocketImpl")
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
    51
    .SetParent<TcpSocket> ()
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
    .AddTraceSource ("CongestionWindow",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
                     "The TCP connection's congestion window",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
                     MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
    ;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
  return tid;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  TcpSocketImpl::TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
  : m_skipRetxResched (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
    m_dupAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
    m_node (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
    m_tcp (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
    m_errno (ERROR_NOTERROR),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
    m_shutdownSend (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
    m_shutdownRecv (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
    m_connected (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
    m_state (CLOSED),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
    m_closeNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
    m_closeRequestNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
    m_closeOnEmpty (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
    m_pendingClose (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
    m_nextTxSequence (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
    m_highTxMark (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    m_highestRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    m_lastRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
    m_nextRxSequence (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
    m_pendingData (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
    m_rtt (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
    m_lastMeasuredRtt (Seconds(0.0)),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
    m_rxAvailable (0), 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
    m_wouldBlock (false) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock)
3134
1890d6ee27a1 Add abstract base class TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3132
diff changeset
    90
  : TcpSocket(sock), //copy the base class callbacks
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
    m_skipRetxResched (sock.m_skipRetxResched),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
    m_dupAckCount (sock.m_dupAckCount),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
    m_delAckMaxCount (sock.m_delAckMaxCount),
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
    95
    m_delAckTimeout (sock.m_delAckTimeout),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
    m_node (sock.m_node),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
    m_tcp (sock.m_tcp),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
    m_remoteAddress (sock.m_remoteAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
    m_remotePort (sock.m_remotePort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
    m_localAddress (sock.m_localAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
    m_localPort (sock.m_localPort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
    m_errno (sock.m_errno),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
    m_shutdownSend (sock.m_shutdownSend),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
    m_shutdownRecv (sock.m_shutdownRecv),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
    m_connected (sock.m_connected),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
    m_state (sock.m_state),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
    m_closeNotified (sock.m_closeNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    m_closeRequestNotified (sock.m_closeRequestNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
    m_closeOnEmpty (sock.m_closeOnEmpty),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
    m_pendingClose (sock.m_pendingClose),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
    m_nextTxSequence (sock.m_nextTxSequence),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    m_highTxMark (sock.m_highTxMark),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
    m_highestRxAck (sock.m_highestRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
    m_lastRxAck (sock.m_lastRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
    m_nextRxSequence (sock.m_nextRxSequence),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    m_pendingData (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
    m_segmentSize (sock.m_segmentSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    m_rxWindowSize (sock.m_rxWindowSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
    m_advertisedWindowSize (sock.m_advertisedWindowSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
    m_cWnd (sock.m_cWnd),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
    m_ssThresh (sock.m_ssThresh),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
    m_initialCWnd (sock.m_initialCWnd),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
    m_rtt (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
    m_lastMeasuredRtt (Seconds(0.0)),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
    m_cnTimeout (sock.m_cnTimeout),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
    m_cnCount (sock.m_cnCount),
3175
ff46939c1b4a Fix TCP valgrind problem (bug #194): TcpSocketImpl::m_wouldBlock was not always being initialized.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3136
diff changeset
   128
    m_rxAvailable (0),
ff46939c1b4a Fix TCP valgrind problem (bug #194): TcpSocketImpl::m_wouldBlock was not always being initialized.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3136
diff changeset
   129
    m_wouldBlock (false) 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
  NS_LOG_LOGIC("Invoked the copy constructor");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  //copy the pending data if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
  if(sock.m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
      m_pendingData = sock.m_pendingData->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
  //copy the rtt if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
  if (sock.m_rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
      m_rtt = sock.m_rtt->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  //can't "copy" the endpoint just yes, must do this when we know the peer info
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  //too; this is in SYN_ACK_TX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
TcpSocketImpl::~TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
  NS_LOG_FUNCTION(this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  if (m_endPoint != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
      NS_ASSERT (m_tcp != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
      /**
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
       * Note that this piece of code is a bit tricky:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
       * when DeAllocate is called, it will call into
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
       * Ipv4EndPointDemux::Deallocate which triggers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
       * a delete of the associated endPoint which triggers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
       * in turn a call to the method ::Destroy below
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
       * will will zero the m_endPoint field.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
       */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
      m_tcp->DeAllocate (m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
      NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  m_tcp = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  delete m_pendingData; //prevents leak
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
  m_pendingData = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
TcpSocketImpl::SetNode (Ptr<Node> node)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
  m_node = node;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   175
  // Initialize some variables 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   176
  m_cWnd = m_initialCWnd * m_segmentSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   177
  m_rxWindowSize = m_advertisedWindowSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
TcpSocketImpl::SetTcp (Ptr<TcpL4Protocol> tcp)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
  m_tcp = tcp;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
TcpSocketImpl::SetRtt (Ptr<RttEstimator> rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
  m_rtt = rtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
enum Socket::SocketErrno
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
TcpSocketImpl::GetErrno (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  return m_errno;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
Ptr<Node>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
TcpSocketImpl::GetNode (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  return m_node;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
TcpSocketImpl::Destroy (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
  m_endPoint = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
  m_tcp = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
  m_retxEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
TcpSocketImpl::FinishBind (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
  m_localAddress = m_endPoint->GetLocalAddress ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  m_localPort = m_endPoint->GetLocalPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
TcpSocketImpl::Bind (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
  m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
TcpSocketImpl::Bind (const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
  NS_LOG_FUNCTION (this<<address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
  if (!InetSocketAddress::IsMatchingType (address))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
      return ERROR_INVAL;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
  if (ipv4 == Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
      m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
      m_endPoint = m_tcp->Allocate (port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
      m_endPoint = m_tcp->Allocate (ipv4);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
      m_endPoint = m_tcp->Allocate (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
TcpSocketImpl::ShutdownSend (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
  m_shutdownSend = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
TcpSocketImpl::ShutdownRecv (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  m_shutdownRecv = false;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
TcpSocketImpl::Close (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
  if (m_state == CLOSED) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
  if (m_pendingData && m_pendingData->Size() != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
    { // App close with pending data must wait until all data transmitted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
      m_closeOnEmpty = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
      NS_LOG_LOGIC("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
                   " deferring close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
  Actions_t action  = ProcessEvent (APP_CLOSE);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
  ShutdownSend ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
TcpSocketImpl::Connect (const Address & address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
  NS_LOG_FUNCTION (this << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
      if (Bind () == -1)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
  m_remoteAddress = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
  m_remotePort = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
  uint32_t localIfIndex;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
  if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
      m_endPoint->SetLocalAddress (ipv4->GetAddress (localIfIndex));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
      m_errno = ERROR_NOROUTETOHOST;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
  Actions_t action = ProcessEvent (APP_CONNECT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
  bool success = ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
  if (success) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
TcpSocketImpl::Send (const Ptr<Packet> p) //p here is just data, no headers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
{ // TCP Does not deal with packets from app, just data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
  return Send(p->PeekData(), p->GetSize());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
int TcpSocketImpl::Send (const uint8_t* buf, uint32_t size)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
  NS_LOG_FUNCTION (this << buf << size);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
  if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
    { 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
      if (size > GetTxAvailable ())
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
          m_wouldBlock = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
          m_errno = ERROR_MSGSIZE;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
      if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
          m_pendingData = new PendingData ();   // Create if non-existent
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
          m_firstPendingSequence = m_nextTxSequence; // Note seq of first
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
      //PendingData::Add always copies the data buffer, never modifies
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
      m_pendingData->Add (size,buf);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
      NS_LOG_DEBUG("TcpSock::Send, pdsize " << m_pendingData->Size() << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
                   " state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
      Actions_t action = ProcessEvent (APP_SEND);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
      NS_LOG_DEBUG(" action " << action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
      if (!ProcessAction (action)) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
          return -1; // Failed, return zero
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
      return size;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
    m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
    return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
  NS_LOG_FUNCTION (this << p << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
  return DoSendTo (p, ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
  NS_LOG_FUNCTION (this << p << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
      if (Bind () == -1)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
	{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
	  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
	}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
  if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
      m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
  m_tcp->Send (p, m_endPoint->GetLocalAddress (), ipv4,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
                  m_endPoint->GetLocalPort (), port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
  NotifyDataSent (p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
TcpSocketImpl::SendTo (Ptr<Packet> p, const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
  NS_LOG_FUNCTION (this << address << p);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
  if (!m_connected)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
      m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
      return Send (p); //drop the address according to BSD manpages
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
TcpSocketImpl::GetTxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
  if (m_pendingData != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
      uint32_t unAckedDataSize = 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
        m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck);
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   443
      NS_ASSERT (m_sndBufSize >= unAckedDataSize); //else a logical error
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   444
      return m_sndBufSize-unAckedDataSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   447
    {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   448
      return m_sndBufSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
TcpSocketImpl::Listen (uint32_t q)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
  NS_LOG_FUNCTION (this << q);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
  Actions_t action = ProcessEvent (APP_LISTEN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
Ptr<Packet>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
TcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
  if (m_deliveryQueue.empty() )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
  Ptr<Packet> p = m_deliveryQueue.front ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
  if (p->GetSize () <= maxSize)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
      m_deliveryQueue.pop ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
      m_rxAvailable -= p->GetSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
      p = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
  return p;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
TcpSocketImpl::GetRxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
  // We separately maintain this state to avoid walking the queue 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
  // every time this might be called
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
  return m_rxAvailable;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
               " dport " << m_endPoint->GetLocalPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
               " daddr " << m_endPoint->GetLocalAddress() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
               " sport " << m_endPoint->GetPeerPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
               " saddr " << m_endPoint->GetPeerAddress());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
  if (m_shutdownRecv)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
  packet->RemoveHeader (tcpHeader);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
      Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
      if (m != Seconds (0.0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
          m_lastMeasuredRtt = m;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
  Actions_t action = ProcessEvent (event); //updates the state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
  Address address = InetSocketAddress (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
  NS_LOG_DEBUG("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
               " processing pkt action, " << action <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
               " current state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
  ProcessPacketAction (action, packet, tcpHeader, address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
  NS_LOG_FUNCTION (this << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
  States_t saveState = m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " processing event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
  // simulation singleton is a way to get a single global static instance of a
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
  // class intended to be a singleton; see simulation-singleton.h
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
  SA stateAction = SimulationSingleton<TcpStateMachine>::Get ()->Lookup (m_state,e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
  // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
  if (stateAction.action == RST_TX)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
              << saveState << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
  bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
    && e != TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
  m_state = stateAction.state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " moved from state " << saveState 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
    << " to state " <<m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " pendingData " << m_pendingData);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
  //extra event logic is here for RX events
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
  //e = SYN_ACK_RX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
  if (saveState == SYN_SENT && m_state == ESTABLISHED)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   550
    // this means the application side has completed its portion of 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
    // the handshaking
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   553
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   554
      //NotifyConnectionSucceeded ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   555
      m_connected = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   556
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   557
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
  if (needCloseNotify && !m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   562
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   563
               << m_state << " event " << e << " closeNot " << m_closeNotified
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   564
               << " action " << stateAction.action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   565
      NotifyCloseCompleted ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
              << " origState " << saveState
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
              << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
          << m_state << " event " << e
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
          << " set CloseNotif ");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
  return stateAction.action;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   576
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
  NS_LOG_FUNCTION (this << flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
  Ptr<Packet> p = Create<Packet> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
  TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   583
  header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
  header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
  header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
  header.SetSourcePort (m_endPoint->GetLocalPort ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
  header.SetDestinationPort (m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
  header.SetWindowSize (m_advertisedWindowSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
    m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
  Time rto = m_rtt->RetransmitTimeout ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   592
  if (flags & TcpHeader::SYN)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   593
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
      rto = m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
      m_cnTimeout = m_cnTimeout + m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
      m_cnCount--;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   597
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   598
  if (m_retxEvent.IsExpired () ) //no outstanding timer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   599
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
    NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
    m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
bool TcpSocketImpl::ProcessAction (Actions_t a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
{ // These actions do not require a packet or any TCP Headers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
  NS_LOG_FUNCTION (this << a);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
    case NO_ACT:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action: NO_ACT");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
    case ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   619
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
    case RST_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RST_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
      SendEmptyPacket (TcpHeader::RST);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
    case SYN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
      // is the above correct? we're SENDING a syn, not acking back -- Raj
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
      // commented out for now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   630
      // m_nextTxSequence+= 1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   631
      SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   632
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
      ++m_nextRxSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   637
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   638
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   639
    case FIN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
      SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   642
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
    case FIN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   644
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   645
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   646
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   647
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
    case RETX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RETX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   656
    case TX_DATA:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   657
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action TX_DATA");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   658
      SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   659
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   660
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   661
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action PEER_CLOSE");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
    case APP_CLOSED:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_CLOSED");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
    case CANCEL_TM:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action CANCEL_TM");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
    case APP_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   676
    case LAST_ACTION:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action LAST_ACTION");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   682
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   683
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   684
                                     const TcpHeader& tcpHeader,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   685
                                     const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
  uint32_t localIfIndex;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   689
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   690
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
//      m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
//      m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
//       if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   697
//         {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   698
//           m_localAddress = ipv4->GetAddress (localIfIndex);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
//         }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   700
      if (m_state == LISTEN) //this means we should fork a new TcpSocketImpl
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   701
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   702
          NS_LOG_DEBUG("In SYN_ACK_TX, m_state is LISTEN, this " << this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   703
          //notify the server that we got a SYN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
          // If server refuses connection do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
          if (!NotifyConnectionRequest(fromAddress)) return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
          // Clone the socket
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
          Ptr<TcpSocketImpl> newSock = Copy ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
          //this listening socket should do nothing more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
                                  p, tcpHeader,fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
        // This is the cloned endpoint
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
        m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
        if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
          {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
            m_localAddress = ipv4->GetAddress (localIfIndex);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
            m_endPoint->SetLocalAddress (m_localAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
            // Leave local addr in the portmap to any, as the path from
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
            // remote can change and packets can arrive on different interfaces
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
            //m_endPoint->SetLocalAddress (Ipv4Address::GetAny());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
          }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
        // TCP SYN consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
        m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
        SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   728
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
      // TCP SYN consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
      m_nextTxSequence = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
                    " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
      m_rxWindowSize = tcpHeader.GetWindowSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
        m_highestRxAck = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   741
        // Data freed from the send buffer; notify any blocked sender
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
        if (m_wouldBlock)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
          {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
            NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
            m_wouldBlock = false;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
          }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
      }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   748
      SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   749
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   750
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   751
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   752
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   753
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   754
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   755
      }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   756
      if (tcpHeader.GetAckNumber () == m_highestRxAck && 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
         tcpHeader.GetAckNumber ()  < m_nextTxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
        DupAck (tcpHeader, ++m_dupAckCount);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
      }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
      if (tcpHeader.GetAckNumber () > m_highestRxAck)  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
          m_dupAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
      NewAck (tcpHeader.GetAckNumber ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   768
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   769
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   770
      NewRx (p, tcpHeader, fromAddress); // Process new data received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   771
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   772
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   773
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   774
      // First we have to be sure the FIN packet was not received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   775
      // out of sequence.  If so, note pending close and process
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   776
      // new sequence rx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   777
      if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   778
        { // process close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   779
          m_pendingClose = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   780
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   781
            << " rxseq " << tcpHeader.GetSequenceNumber () 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   782
            << " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   783
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   784
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   785
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   786
      // Now we need to see if any data came with the FIN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
      // if so, call NewRx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
      if (p->GetSize () != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   789
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   790
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
      States_t saveState = m_state; // Used to see if app responds
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   794
          << " peer close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   795
      if (!m_closeRequestNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   796
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   797
          NS_LOG_LOGIC ("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   798
              << " calling AppCloseRequest");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   799
          NotifyCloseRequested(); 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   800
          m_closeRequestNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   801
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   802
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
          << " peer close, state after " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   804
      if (m_state == saveState)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
        { // Need to ack, the application will close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   806
          SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   807
//               // Also need to re-tx the ack if we
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   808
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   809
      if (m_state == LAST_ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   810
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   811
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " scheduling LATO1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   812
          m_lastAckEvent = Simulator::Schedule (m_rtt->RetransmitTimeout (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   813
                                                &TcpSocketImpl::LastAckTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   814
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   815
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   816
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   818
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   819
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   820
      NotifyNewConnectionCreated (this, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   821
      m_connected = true; // ! This is bogus; fix when we clone the tcp
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
      //treat the connection orientation final ack as a newack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
      CommonNewAck (tcpHeader.GetAckNumber (), true);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
    default:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   827
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   832
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   834
  // Get port and address from peer (connecting host)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   835
  m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   836
  m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
  m_endPoint = m_tcp->Allocate (m_localAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   838
                                m_localPort,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   839
                                m_remoteAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   840
                                m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
  //the cloned socket with be in listen state, so manually change state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
  m_state = SYN_RCVD;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   843
  //equivalent to FinishBind
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   845
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   847
 }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   849
void TcpSocketImpl::ConnectionSucceeded()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   850
{ // We would preferred to have scheduled an event directly to
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   851
  // NotifyConnectionSucceeded, but (sigh) these are protected
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
  // and we can get the address of it :(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
  NotifyConnectionSucceeded();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
bool TcpSocketImpl::SendPendingData (bool withAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
  NS_LOG_FUNCTION (this << withAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
  NS_LOG_LOGIC ("ENTERING SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
      return false; // No data exists
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
  uint32_t nPacketsSent = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
  while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
      uint32_t w = AvailableWindow ();// Get available window size
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " SendPendingData"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
           << " w " << w 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
           << " rxwin " << m_rxWindowSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
           << " segsize " << m_segmentSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
           << " nextTxSeq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
           << " highestRxAck " << m_highestRxAck 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
           << " pd->Size " << m_pendingData->Size ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
           << " pd->SFS " << m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
      if (w < m_segmentSize && m_pendingData->Size () > w)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
          break; // No more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
      uint32_t s = std::min (w, m_segmentSize);  // Send no more than window
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
      Ptr<Packet> p = m_pendingData->CopyFromSeq (s, m_firstPendingSequence, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
        m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
      NS_LOG_LOGIC("TcpSocketImpl " << this << " sendPendingData"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
                   << " txseq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
                   << " s " << s 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
                   << " datasize " << p->GetSize() );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
      uint8_t flags = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
      if (withAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
          flags |= TcpHeader::ACK;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
      uint32_t sz = p->GetSize (); // Size of packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
      uint32_t remainingData = m_pendingData->SizeFromSeq(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
          m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
          m_nextTxSequence + SequenceNumber (sz));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
      if (m_closeOnEmpty && (remainingData == 0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
          flags = TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
          m_state = FIN_WAIT_1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
      TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
      header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
      header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
      header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
      header.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
      header.SetDestinationPort (m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
      if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
          m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
      
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
      if (m_retxEvent.IsExpired () ) //go ahead and schedule the retransmit
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
            Time rto = m_rtt->RetransmitTimeout (); 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   920
            NS_LOG_LOGIC ("Schedule retransmission timeout at time " << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
              Simulator::Now ().GetSeconds () << " to expire at time " <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
              (Simulator::Now () + rto).GetSeconds () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
          m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   926
      m_tcp->SendPacket (p, header,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
                         m_endPoint->GetLocalAddress (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
                         m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   930
      // Notify the application
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   931
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   932
      nPacketsSent++;                             // Count sent this loop
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
      m_nextTxSequence += sz;                     // Advance next tx sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
      // Note the high water mark
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
      m_highTxMark = std::max (m_nextTxSequence, m_highTxMark);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
  NS_LOG_LOGIC ("Sent "<<nPacketsSent<<" packets");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
  NS_LOG_LOGIC("RETURN SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
  return (nPacketsSent>0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
uint32_t  TcpSocketImpl::UnAckDataCount ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
  return m_nextTxSequence - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
uint32_t  TcpSocketImpl::BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   950
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
  return m_highTxMark - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   952
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
uint32_t  TcpSocketImpl::Window ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   956
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   957
  NS_LOG_LOGIC ("TcpSocketImpl::Window() "<<this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   958
  return std::min (m_rxWindowSize, m_cWnd.Get());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
uint32_t  TcpSocketImpl::AvailableWindow ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   963
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   964
  uint32_t unack = UnAckDataCount (); // Number of outstanding bytes
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
  uint32_t win = Window ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   966
  if (win < unack) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   967
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   968
      return 0;  // No space available
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   969
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   970
  return (win - unack);       // Amount of window space available
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   971
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   972
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   973
void TcpSocketImpl::NewRx (Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   974
                        const TcpHeader& tcpHeader, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   975
                        const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   976
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   977
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   978
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
                << " seq " << tcpHeader.GetSequenceNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   980
                << " ack " << tcpHeader.GetAckNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
                << " p.size is " << p->GetSize () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
  NS_LOG_DEBUG ("TcpSocketImpl " << this <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
                " NewRx," <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
                " seq " << tcpHeader.GetSequenceNumber() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
                " ack " << tcpHeader.GetAckNumber() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
                " p.size is " << p->GetSize());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
  States_t origState = m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
  uint32_t s = p->GetSize ();  // Size of associated data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
  if (s == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
    {// Nothing to do if no associated data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
  // Log sequence received if enabled
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
  // NoteTimeSeq(LOG_SEQ_RX, h->sequenceNumber);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
  // Three possibilities
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
  // 1) Received seq is expected, deliver this and any buffered data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
  // 2) Received seq is < expected, just re-ack previous
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
  // 3) Received seq is > expected, just re-ack previous and buffer data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
  if (tcpHeader.GetSequenceNumber () == m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
    { // If seq is expected seq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
      // 1) Update nextRxSeq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
      // 2) Deliver to application this packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
      // 3) See if any buffered can be delivered
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
      // 4) Send the ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1005
      m_nextRxSequence += s;           // Advance next expected sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
      //bytesReceived += s;       // Statistics
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
      NS_LOG_LOGIC("Case 1, advanced nrxs to " << m_nextRxSequence );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1008
      SocketRxAddressTag tag;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1009
      tag.SetAddress (fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1010
      p->AddTag (tag);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1011
      m_deliveryQueue.push (p);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
      m_rxAvailable += p->GetSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
      NotifyDataRecv ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
      if (m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
          NS_LOG_LOGIC ("Tcp " << this << " HuH?  Got data after closeNotif");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq by " << s);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
      // Look for buffered data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1020
      UnAckData_t::iterator i;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1021
      // Note that the bufferedData list DOES contain the tcp header
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1022
      while (!m_bufferedData.empty ())
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1023
        { // Check the buffered data for delivery
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1024
          NS_LOG_LOGIC("TCP " << this << " bufferedData.size() " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
              << m_bufferedData.size () 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
              << " time " << Simulator::Now ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
          i = m_bufferedData.begin ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
          Ptr<Packet> p1 = i->second;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
          SequenceNumber s1 = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
          if (i->first > m_nextRxSequence) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
            {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
              break;  // Not next expected
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
            }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
          // already have the header as a param
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
          //TCPHeader* h = dynamic_cast<TCPHeader*>(p1->PopPDU());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
          // Check non-null here...
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
          uint8_t flags = tcpHeader.GetFlags ();           // Flags (used below)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
          if (i->first < m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
            { // remove already delivered data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
              // Two cases here.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
              // 1) seq + length <= nextRxSeq, just discard
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
              // 2) seq + length > nextRxSeq, can deliver partial
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
              s1 = p->GetSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
              if (i->first + s1 < m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1045
                { // Just remove from list
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1046
                  //bufferedData.erase(i);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1047
                  p1 = 0; // Nothing to deliver
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1048
                }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1049
              else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
                { // Remove partial data to prepare for delivery
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
                  uint32_t dup = m_nextRxSequence - i->first;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
                  i->second = p1->CreateFragment (0, p1->GetSize () - dup);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
                  p1 = i->second;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1054
                }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1055
            }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
          else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
            { // At this point i->first must equal nextRxSeq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1058
              if (i->first != m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
                {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
                  NS_FATAL_ERROR ("HuH?  NexRx failure, first " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
                      << i->first << " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
                }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
              s1 = p1->GetSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1064
            }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
          SocketRxAddressTag tag;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1066
          tag.SetAddress (fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
          p1->AddTag (tag);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
          m_deliveryQueue.push (p1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
          m_rxAvailable += p->GetSize ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1070
          NotifyDataRecv ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq1 by " << s1 );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1073
          m_nextRxSequence += s1;           // Note data received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1074
          m_bufferedData.erase (i);     // Remove from list
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1075
          if (flags & TcpHeader::FIN)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1076
            NS_LOG_LOGIC("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
                    << " found FIN in buffered");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1079
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
      if (m_pendingClose || (origState > ESTABLISHED))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
        { // See if we can close now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
          if (m_bufferedData.empty())
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1083
            {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1084
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1085
            }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1086
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
  else if (SequenceNumber (tcpHeader.GetSequenceNumber ()) >= m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
    { // Need to buffer this one
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1090
      NS_LOG_LOGIC ("Case 2, buffering " << tcpHeader.GetSequenceNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
      UnAckData_t::iterator i = 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1092
        m_bufferedData.find (tcpHeader.GetSequenceNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1093
      if (i != m_bufferedData.end () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1095
          i->second = 0; // relase reference to already buffered
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1096
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1097
      // Save for later delivery
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1098
      m_bufferedData[tcpHeader.GetSequenceNumber () ] = p;  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1099
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1100
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
    { // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1102
      NS_LOG_LOGIC("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1103
               << " got seq " << tcpHeader.GetSequenceNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1104
               << " expected " << m_nextRxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1105
               << "       flags " << tcpHeader.GetFlags ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1107
  // Now send a new ack packet acknowledging all received and delivered data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1108
  if(++m_delAckCount >= m_delAckMaxCount)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1110
    m_delAckEvent.Cancel();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1111
    m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1112
    SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1113
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1114
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
  {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1116
    m_delAckEvent = Simulator::Schedule (m_delAckTimeout, &TcpSocketImpl::DelAckTimeout, this);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1117
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1118
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1119
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
void TcpSocketImpl::DelAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1121
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1122
  m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1123
  SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1124
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1125
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1127
{ // CommonNewAck is called only for "New" (non-duplicate) acks
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
  // and MUST be called by any subclass, from the NewAck function
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
  // Always cancel any pending re-tx timer on new acknowledgement
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1130
  NS_LOG_FUNCTION (this << ack << skipTimer); 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1131
  //DEBUG(1,(cout << "TCP " << this << "Cancelling retx timer " << endl));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1132
  if (!skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
      m_retxEvent.Cancel ();  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1135
      //On recieving a "New" ack we restart retransmission timer .. RFC 2988
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1136
      Time rto = m_rtt->RetransmitTimeout ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1137
      NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1138
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1139
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1140
    m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1141
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
  NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
           << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
  m_highestRxAck = ack;         // Note the highest recieved Ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1145
  if (m_wouldBlock)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1146
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
      // m_highestRxAck advancing means some data was acked, and the size 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
      // of free space in the buffer has increased
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
      NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
      m_wouldBlock = false;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1152
  if (ack > m_nextTxSequence) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1154
      m_nextTxSequence = ack; // If advanced
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1155
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
  // See if all pending ack'ed; if so we can delete the data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
  if (m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
    { // Data exists, see if can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1159
      if (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck) == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
        { // All pending acked, can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1161
          m_pendingData->Clear ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1162
          delete m_pendingData;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
          m_pendingData = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1164
          // Insure no re-tx timer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1165
          m_retxEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1167
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1168
  // Try to send more data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1169
  SendPendingData();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1170
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1171
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1172
Ptr<TcpSocketImpl> TcpSocketImpl::Copy ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1173
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1174
  return CopyObject<TcpSocketImpl> (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1175
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1176
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1177
void TcpSocketImpl::NewAck (SequenceNumber seq)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1178
{ // New acknowledgement up to sequence number "seq"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1179
  // Adjust congestion window in response to new ack's received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1180
  NS_LOG_FUNCTION (this << seq);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1181
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewAck "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1182
           << " seq " << seq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1183
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1184
           << " ssThresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1185
  if (m_cWnd < m_ssThresh)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1186
    { // Slow start mode, add one segSize to cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1187
      m_cWnd += m_segmentSize;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1188
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewCWnd SlowStart, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1189
          << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1190
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1191
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1192
    { // Congestion avoidance mode, adjust by (ackBytes*segSize) / cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1193
      double adder =  ((double) m_segmentSize * m_segmentSize) / m_cWnd.Get();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1194
      if (adder < 1.0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1195
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1196
          adder = 1.0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1197
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1198
      m_cWnd += (uint32_t) adder;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1199
      NS_LOG_LOGIC ("NewCWnd CongAvoid, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1200
           << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1201
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1202
  CommonNewAck (seq, false);           // Complete newAck processing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1203
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1204
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1205
void TcpSocketImpl::DupAck (const TcpHeader& t, uint32_t count)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1206
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1207
  NS_LOG_FUNCTION (this << "t " << count);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1208
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " DupAck " <<  t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1209
      << ", count " << count
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1210
      << ", time " << Simulator::Now ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1211
  if (count == 3)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1212
  { // Count of three indicates triple duplicate ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1213
    m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1214
    m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1215
    NS_LOG_LOGIC("TcpSocketImpl " << this << "Tahoe TDA, time " << Simulator::Now ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1216
        << " seq " << t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1217
        << " in flight " << BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1218
        << " new ssthresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1219
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1220
    m_cWnd = m_segmentSize; // Collapse cwnd (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1221
    // For Tahoe, we also reset nextTxSeq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1222
    m_nextTxSequence = m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1223
    SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1224
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1225
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1226
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1227
void TcpSocketImpl::ReTxTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1228
{ // Retransmit timeout
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1229
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1230
  m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1231
  m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1232
  // Set cWnd to segSize on timeout,  per rfc2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1233
  // Collapse congestion window (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1234
  m_cWnd = m_segmentSize;           
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1235
  m_nextTxSequence = m_highestRxAck; // Start from highest Ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1236
  m_rtt->IncreaseMultiplier (); // DoubleValue timeout value for next retx timer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1237
  Retransmit ();             // Retransmit the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1238
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1239
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1240
void TcpSocketImpl::LastAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1241
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1242
  m_lastAckEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1243
  if (m_state == LAST_ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1244
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1245
      Actions_t action = ProcessEvent (TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1246
      ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1247
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1248
  if (!m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1249
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1250
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1251
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1252
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1253
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
void TcpSocketImpl::Retransmit ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
  uint8_t flags = TcpHeader::NONE;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1258
  if (m_state == SYN_SENT) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1259
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
      if (m_cnCount > 0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1261
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1262
          SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1263
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1265
      else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1266
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1267
          NotifyConnectionFailed ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1268
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1269
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1270
    } 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1271
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1272
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1273
      if (m_state == FIN_WAIT_1 || m_state == FIN_WAIT_2)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1274
        { // Must have lost FIN, re-send
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1275
          SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1276
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1277
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1278
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1279
  Ptr<Packet> p = m_pendingData->CopyFromSeq (m_segmentSize,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1280
                                            m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1281
                                            m_highestRxAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1282
  // Calculate remaining data for COE check
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1283
  uint32_t remainingData = m_pendingData->SizeFromSeq (
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1284
      m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1285
      m_nextTxSequence + SequenceNumber(p->GetSize ()));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1286
  if (m_closeOnEmpty && remainingData == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1287
    { // Add the FIN flag
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1288
      flags = flags | TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1289
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1290
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1291
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " retxing seq " << m_highestRxAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1292
  if (m_retxEvent.IsExpired () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1293
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1294
      Time rto = m_rtt->RetransmitTimeout ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1295
      NS_LOG_LOGIC ("Schedule retransmission timeout at time "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1296
          << Simulator::Now ().GetSeconds () << " to expire at time "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1297
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1298
      m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1299
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1300
  m_rtt->SentSeq (m_highestRxAck,p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1301
  // And send the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1302
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1303
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1304
  tcpHeader.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1305
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1306
  tcpHeader.SetDestinationPort (m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1307
  tcpHeader.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1308
  tcpHeader.SetWindowSize (m_advertisedWindowSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1309
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1310
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1311
    m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1314
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1315
TcpSocketImpl::SetSndBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1316
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1317
  m_sndBufSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1318
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1319
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1320
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1321
TcpSocketImpl::GetSndBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1322
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1323
  return m_sndBufSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1324
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1325
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1326
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1327
TcpSocketImpl::SetRcvBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1328
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1329
  m_rcvBufSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1330
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1331
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1332
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1333
TcpSocketImpl::GetRcvBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1334
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1335
  return m_rcvBufSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1336
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1337
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1338
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1339
TcpSocketImpl::SetSegSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1340
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1341
  m_segmentSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1342
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1343
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1344
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1345
TcpSocketImpl::GetSegSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1346
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1347
  return m_segmentSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1348
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1349
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1350
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1351
TcpSocketImpl::SetAdvWin (uint32_t window)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1352
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1353
  m_advertisedWindowSize = window;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1354
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1355
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1356
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1357
TcpSocketImpl::GetAdvWin (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1358
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1359
  return m_advertisedWindowSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1360
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1361
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1362
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1363
TcpSocketImpl::SetSSThresh (uint32_t threshold)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1364
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1365
  m_ssThresh = threshold;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1366
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1367
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1368
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1369
TcpSocketImpl::GetSSThresh (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1370
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1371
  return m_ssThresh;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1372
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1373
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1374
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1375
TcpSocketImpl::SetInitialCwnd (uint32_t cwnd)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1376
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1377
  m_initialCWnd = cwnd;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1378
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1379
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1380
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1381
TcpSocketImpl::GetInitialCwnd (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1382
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1383
  return m_initialCWnd;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1384
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1385
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1386
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1387
TcpSocketImpl::SetConnTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1388
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1389
  m_cnTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1390
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1391
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1392
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1393
TcpSocketImpl::GetConnTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1394
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1395
  return m_cnTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1396
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1397
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1398
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1399
TcpSocketImpl::SetConnCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1400
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1401
  m_cnCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1402
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1403
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1404
uint32_t 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1405
TcpSocketImpl::GetConnCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1406
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1407
  return m_cnCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1408
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1409
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1410
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1411
TcpSocketImpl::SetDelAckTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1412
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1413
  m_delAckTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1414
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1415
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1416
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1417
TcpSocketImpl::GetDelAckTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1418
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1419
  return m_delAckTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1420
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1421
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1422
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1423
TcpSocketImpl::SetDelAckMaxCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1424
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1425
  m_delAckMaxCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1426
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1427
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1428
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1429
TcpSocketImpl::GetDelAckMaxCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1430
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1431
  return m_delAckMaxCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1432
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1433
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1434
}//namespace ns3