src/internet-stack/tcp-socket-impl.cc
author Antti Mäkelä <zarhan@cc.hut.fi>
Tue, 15 Dec 2009 20:41:36 -0800
changeset 5856 7fd20c798a7d
parent 5378 7bc9c7bd4d8f
child 5887 50e5de0b03db
permissions -rw-r--r--
bug 742: Implementation of SO_BINDTODEVICE
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
4622
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
    22
#include "ns3/abort.h"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/node.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/inet-socket-address.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/log.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/ipv4.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    27
#include "ns3/ipv4-interface-address.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    28
#include "ns3/ipv4-route.h"
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    29
#include "ns3/ipv4-routing-protocol.h"
3131
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 "ns3/simulator.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "ns3/packet.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "ns3/uinteger.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "ns3/trace-source-accessor.h"
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    35
#include "tcp-typedefs.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    36
#include "tcp-socket-impl.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    37
#include "tcp-l4-protocol.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    38
#include "ipv4-end-point.h"
4740
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4627
diff changeset
    39
#include "tcp-header.h"
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4627
diff changeset
    40
#include "rtt-estimator.h"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
#include <algorithm>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
NS_LOG_COMPONENT_DEFINE ("TcpSocketImpl");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
using namespace std;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
namespace ns3 {
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
NS_OBJECT_ENSURE_REGISTERED (TcpSocketImpl);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
TypeId
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
TcpSocketImpl::GetTypeId ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
  static TypeId tid = TypeId("ns3::TcpSocketImpl")
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
    56
    .SetParent<TcpSocket> ()
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
    .AddTraceSource ("CongestionWindow",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
                     "The TCP connection's congestion window",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
                     MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
    ;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
  return tid;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
  TcpSocketImpl::TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
  : m_skipRetxResched (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
    m_dupAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
    m_node (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
    m_tcp (0),
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
    71
    m_localAddress (Ipv4Address::GetZero ()),
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
    72
    m_localPort (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
    m_errno (ERROR_NOTERROR),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
    m_shutdownSend (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
    m_shutdownRecv (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
    m_connected (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    m_state (CLOSED),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    m_closeNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
    m_closeRequestNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
    m_closeOnEmpty (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
    m_pendingClose (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
    m_nextTxSequence (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
    m_highTxMark (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
    m_highestRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
    m_lastRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
    m_nextRxSequence (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    87
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    88
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
    m_pendingData (0),
4627
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
    90
    m_segmentSize (0),          // For attribute initialization consistency (quiet valgrind)
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    91
    m_rxWindowSize (0),
4627
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
    92
    m_initialCWnd (0),          // For attribute initialization consistency (quiet valgrind)
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    93
    m_persistTime (Seconds(6)), //XXX hook this into attributes?
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
    m_rtt (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    95
    m_lastMeasuredRtt (Seconds(0.0))
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock)
3475
8523b98f949c Make PacketSink multitasking for TCP (closes bug 244)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
   101
  : TcpSocket(sock), //copy object::m_tid, copy socket::callbacks
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
    m_skipRetxResched (sock.m_skipRetxResched),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
    m_dupAckCount (sock.m_dupAckCount),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
    m_delAckMaxCount (sock.m_delAckMaxCount),
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   106
    m_delAckTimeout (sock.m_delAckTimeout),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
    m_node (sock.m_node),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    m_tcp (sock.m_tcp),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
    m_remoteAddress (sock.m_remoteAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
    m_remotePort (sock.m_remotePort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
    m_localAddress (sock.m_localAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    m_localPort (sock.m_localPort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
    m_errno (sock.m_errno),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
    m_shutdownSend (sock.m_shutdownSend),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
    m_shutdownRecv (sock.m_shutdownRecv),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    m_connected (sock.m_connected),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
    m_state (sock.m_state),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    m_closeNotified (sock.m_closeNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
    m_closeRequestNotified (sock.m_closeRequestNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
    m_closeOnEmpty (sock.m_closeOnEmpty),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
    m_pendingClose (sock.m_pendingClose),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
    m_nextTxSequence (sock.m_nextTxSequence),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
    m_highTxMark (sock.m_highTxMark),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
    m_highestRxAck (sock.m_highestRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
    m_lastRxAck (sock.m_lastRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
    m_nextRxSequence (sock.m_nextRxSequence),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   128
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   129
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
    m_pendingData (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
    m_segmentSize (sock.m_segmentSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
    m_rxWindowSize (sock.m_rxWindowSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
    m_cWnd (sock.m_cWnd),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
    m_ssThresh (sock.m_ssThresh),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
    m_initialCWnd (sock.m_initialCWnd),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   136
    m_persistTime (sock.m_persistTime),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
    m_rtt (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
    m_lastMeasuredRtt (Seconds(0.0)),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
    m_cnTimeout (sock.m_cnTimeout),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
    m_cnCount (sock.m_cnCount),
3251
19471cb55c9c Part of bug 198
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3250
diff changeset
   141
    m_sndBufSize (sock.m_sndBufSize),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   142
    m_rxBufMaxSize(sock.m_rxBufMaxSize)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
  NS_LOG_LOGIC("Invoked the copy constructor");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  //copy the pending data if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  if(sock.m_pendingData)
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
      m_pendingData = sock.m_pendingData->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  //copy the rtt if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
  if (sock.m_rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
      m_rtt = sock.m_rtt->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
    }
4014
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   156
  //null out the socket base class callbacks,
3475
8523b98f949c Make PacketSink multitasking for TCP (closes bug 244)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
   157
  //make user of the socket register this explicitly
4014
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   158
  Callback<void, Ptr< Socket > > vPS =
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   159
      MakeNullCallback<void, Ptr<Socket> > ();
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   160
  Callback<void, Ptr<Socket>, const Address &> vPSA =
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   161
      MakeNullCallback<void, Ptr<Socket>, const Address &> ();
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   162
  Callback<void, Ptr<Socket>, uint32_t> vPSUI =
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   163
      MakeNullCallback<void, Ptr<Socket>, uint32_t> ();
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   164
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   165
  SetConnectCallback (vPS, vPS);
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   166
  SetDataSentCallback (vPSUI);
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   167
  SetSendCallback (vPSUI);
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   168
  SetRecvCallback (vPS);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  //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
   170
  //too; this is in SYN_ACK_TX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
TcpSocketImpl::~TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  NS_LOG_FUNCTION(this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
  if (m_endPoint != 0)
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
      NS_ASSERT (m_tcp != 0);
4621
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   180
      /*
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   181
       * Note that this piece of code is seriously convoluted: When we do a 
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   182
       * Bind we allocate an Ipv4Endpoint.  Immediately thereafter we always do
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   183
       * a FinishBind which sets the DestroyCallback of that endpoint to be
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   184
       * TcpSocketImpl::Destroy, below.  When m_tcp->DeAllocate is called, it 
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   185
       * will in turn call into Ipv4EndpointDemux::DeAllocate with the endpoint
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   186
       * (m_endPoint).  The demux will look up the endpoint and destroy it (the
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   187
       * corollary is that we don't own the object pointed to by m_endpoint, we
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   188
       * just borrowed it).  The destructor for the endpoint will call the 
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   189
       * DestroyCallback which will then invoke TcpSocketImpl::Destroy below. 
4627
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
   190
       * Destroy will zero m_node, m_tcp and m_endpoint.  The zero of m_node and
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
   191
       * m_tcp need to be here also in case the endpoint is deallocated before 
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
   192
       * shutdown.
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
       */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
      m_tcp->DeAllocate (m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
      NS_ASSERT (m_endPoint == 0);
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
  m_tcp = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
  delete m_pendingData; //prevents leak
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  m_pendingData = 0;
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   201
  CancelAllTimers();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
TcpSocketImpl::SetNode (Ptr<Node> node)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
  m_node = node;
4622
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   208
  /*
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   209
   * Set the congestion window to IW.  This method is called from the L4 
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   210
   * Protocol after it creates the socket.  The Attribute system takes
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   211
   * care of setting m_initialCWnd and m_segmentSize to their default
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   212
   * values.  m_cWnd depends on m_initialCwnd and m_segmentSize so it
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   213
   * also needs to be updated in SetInitialCwnd and SetSegSize.
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   214
   */
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   215
  m_cWnd = m_initialCWnd * m_segmentSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
}
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
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
TcpSocketImpl::SetTcp (Ptr<TcpL4Protocol> tcp)
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
  m_tcp = tcp;
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
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
TcpSocketImpl::SetRtt (Ptr<RttEstimator> rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  m_rtt = rtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
}
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
enum Socket::SocketErrno
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
TcpSocketImpl::GetErrno (void) const
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
  return m_errno;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
}
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
Ptr<Node>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
TcpSocketImpl::GetNode (void) const
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_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
  return m_node;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
TcpSocketImpl::Destroy (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
  m_endPoint = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
  m_tcp = 0;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   251
  NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   252
                << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   253
                Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   254
  CancelAllTimers();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
}
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   256
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
TcpSocketImpl::FinishBind (void)
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
  if (m_endPoint == 0)
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
      return -1;
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->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
  m_localAddress = m_endPoint->GetLocalAddress ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
  m_localPort = m_endPoint->GetLocalPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
  return 0;
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::Bind (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_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  return FinishBind ();
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::Bind (const Address &address)
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 (this<<address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  if (!InetSocketAddress::IsMatchingType (address))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
    {
3846
265004d6dc15 apply patch for bug 390 (SocketImpl::Bind returns something other than -1)
raj.b@gatech.edu
parents: 3818
diff changeset
   285
      m_errno = ERROR_INVAL;
265004d6dc15 apply patch for bug 390 (SocketImpl::Bind returns something other than -1)
raj.b@gatech.edu
parents: 3818
diff changeset
   286
      return -1;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
  if (ipv4 == Ipv4Address::GetAny () && port == 0)
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
      m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
      m_endPoint = m_tcp->Allocate (port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
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
      m_endPoint = m_tcp->Allocate (ipv4);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
  else if (ipv4 != Ipv4Address::GetAny () && port != 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
      m_endPoint = m_tcp->Allocate (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
    }
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
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
}
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
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
TcpSocketImpl::ShutdownSend (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
  m_shutdownSend = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
  return 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
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
TcpSocketImpl::ShutdownRecv (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
  NS_LOG_FUNCTION_NOARGS ();
4491
893d48fcf7f3 bug 535: UDP/TCP ShutdownRecv incorrect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   326
  m_shutdownRecv = true;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
  return 0;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
TcpSocketImpl::Close (void)
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
  NS_LOG_FUNCTION_NOARGS ();
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   334
  // First we check to see if there is any unread rx data
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   335
  // Bug number 426 claims we should send reset in this case.
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   336
  if (!m_bufferedData.empty())
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   337
    {
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   338
      SendRST();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   339
      return 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   340
    }
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   341
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   342
  uint32_t remainingData = 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   343
  if (m_pendingData)
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   344
    {
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   345
      remainingData = m_pendingData->SizeFromSeq (m_firstPendingSequence,
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   346
                                                  m_nextTxSequence);
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   347
    }
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   348
  
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   349
  if (remainingData != 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
    { // App close with pending data must wait until all data transmitted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
      m_closeOnEmpty = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
      NS_LOG_LOGIC("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
                   " deferring close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
  Actions_t action  = ProcessEvent (APP_CLOSE);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
  return 0;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
TcpSocketImpl::Connect (const Address & address)
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
  NS_LOG_FUNCTION (this << address);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   365
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   366
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   367
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
      if (Bind () == -1)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
      NS_ASSERT (m_endPoint != 0);
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
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
  m_remoteAddress = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
  m_remotePort = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
  
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   381
  if (ipv4->GetRoutingProtocol () != 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   383
      Ipv4Header header;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   384
      header.SetDestination (m_remoteAddress);
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   385
      Socket::SocketErrno errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   386
      Ptr<Ipv4Route> route;
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   387
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   388
      // XXX here, cache the route in the endpoint?
4603
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4567
diff changeset
   389
      route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   390
      if (route != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   391
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   392
          NS_LOG_LOGIC ("Route exists");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   393
          m_endPoint->SetLocalAddress (route->GetSource ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   394
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   395
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   396
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   397
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_remoteAddress << " does not exist");
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   398
          NS_LOG_ERROR (errno_);
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   399
          m_errno = errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   400
          return -1;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   401
        }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   405
      NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
3131
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
  Actions_t action = ProcessEvent (APP_CONNECT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
  bool success = ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
  if (success) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
      return 0;
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
  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
}
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   416
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   417
//p here is just data, no headers
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   419
TcpSocketImpl::Send (Ptr<Packet> p, uint32_t flags) 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
{
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   421
  NS_LOG_FUNCTION (this << p);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
  if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT)
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   423
  {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   424
    if (p->GetSize() > GetTxAvailable ())
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   425
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   426
      m_errno = ERROR_MSGSIZE;
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   427
      return -1;
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   428
    }
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   429
    if (!m_pendingData)
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   430
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   431
      m_pendingData = new PendingData ();   // Create if non-existent
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   432
      m_firstPendingSequence = m_nextTxSequence; // Note seq of first
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
    }
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   434
    //PendingData::Add stores a copy of the Ptr p
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   435
    m_pendingData->Add (p);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   436
    NS_LOG_DEBUG("TcpSock::Send, pdsize " << m_pendingData->Size() << 
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   437
        " state " << m_state);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   438
    Actions_t action = ProcessEvent (APP_SEND);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   439
    NS_LOG_DEBUG(" action " << action);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   440
    if (!ProcessAction (action)) 
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   441
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   442
      return -1; // Failed, return zero
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   443
    }
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   444
    return p->GetSize();
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   445
  }
3131
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
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
    m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
    return -1;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
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 << p << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
  return DoSendTo (p, ipv4, port);
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port)
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 (this << p << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
  if (m_endPoint == 0)
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
      if (Bind () == -1)
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
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
	  return -1;
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
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
  if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
      m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
    }
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   479
  // Get the size before sending to tcp, as the sent callback cares
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   480
  // about payload sent, not with headers
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   481
  uint32_t sentSize = p->GetSize();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
  m_tcp->Send (p, m_endPoint->GetLocalAddress (), ipv4,
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   483
                  m_endPoint->GetLocalPort (), port, m_boundnetdevice);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   484
  NotifyDataSent (sentSize);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   489
TcpSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address)
3131
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
  NS_LOG_FUNCTION (this << address << p);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
  if (!m_connected)
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
      m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
    {
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   499
      return Send (p, flags); //drop the address according to BSD manpages
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
}
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
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
TcpSocketImpl::GetTxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
  if (m_pendingData != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
      uint32_t unAckedDataSize = 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
        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
   511
      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
   512
      return m_sndBufSize-unAckedDataSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
    {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   516
      return m_sndBufSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
int
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   521
TcpSocketImpl::Listen (void)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
{
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   523
  NS_LOG_FUNCTION (this);
3966
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   524
  // Linux quits EINVAL if we're not closed, so match what they do
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   525
  if (m_state != CLOSED)
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   526
    {
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   527
      m_errno = ERROR_INVAL;
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   528
      return -1;
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   529
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
  Actions_t action = ProcessEvent (APP_LISTEN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
Ptr<Packet>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
TcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
  NS_LOG_FUNCTION_NOARGS ();
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   539
  if(m_bufferedData.empty())
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
    {
4014
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   541
      if(m_state == CLOSE_WAIT) //means EOF
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   542
        {
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   543
          return Create<Packet>();
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   544
        }
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   545
      //else, means nothing to read
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   548
  UnAckData_t out; //serves as buffer to return up to the user
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   549
  UnAckData_t::iterator i;
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   550
  while (!m_bufferedData.empty ())
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   551
    { // Check the buffered data for delivery
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   552
      NS_LOG_LOGIC("TCP " << this << " bufferedData.size() " 
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   553
        << m_bufferedData.size () 
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   554
        << " time " << Simulator::Now ());
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   555
      i = m_bufferedData.begin ();
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   556
      SequenceNumber s1 = 0;
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   557
      if (i->first > m_nextRxSequence) 
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   558
        {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   559
          break;  // we're done, no more in-sequence data exits
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   560
        }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   561
      else // (i->first <= m_nextRxSequence)
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   562
        { // Two cases here.
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   563
          // 1) seq + length > nextRxSeq, can deliver partial
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   564
          // 2) seq + length <= nextRxSeq, deliver whole
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   565
          s1 = i->second->GetSize ();
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   566
          if (i->first + s1 > m_nextRxSequence)
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   567
            { // Remove partial data to prepare for delivery
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   568
              uint32_t avail = s1 + i->first - m_nextRxSequence;
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   569
              i->second = i->second->CreateFragment (0, avail);
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   570
            }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   571
          // else this packet is okay to deliver whole
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   572
          // so don't do anything else and output it
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   573
          out[i->first]  = i->second;
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   574
        }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   575
      m_rxAvailable -= i->second->GetSize ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   576
      m_rxBufSize -= i->second->GetSize ();
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   577
      m_bufferedData.erase (i);     // Remove from list
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
    }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   579
  if (out.size() == 0)
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   580
    {
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   581
      return 0;
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   582
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   583
  Ptr<Packet> outPacket = Create<Packet>();
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   584
  for(i = out.begin(); i!=out.end(); ++i)
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   585
  {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   586
    if (outPacket->GetSize() + i->second->GetSize() <= maxSize )
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
    {
3248
39f736210ab2 Merge with ns-3-dev
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3246 3229
diff changeset
   588
      outPacket->AddAtEnd(i->second);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   590
    else
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
    {
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   592
      //only append as much as will fit
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   593
      uint32_t avail = maxSize - outPacket->GetSize();
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   594
      outPacket->AddAtEnd(i->second->CreateFragment(0,avail));
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   595
      //put the rest back into the buffer
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   596
      m_bufferedData[i->first+SequenceNumber(avail)] 
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   597
          = i->second->CreateFragment(avail,i->second->GetSize()-avail);
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   598
      m_rxAvailable += i->second->GetSize()-avail;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   599
      m_rxBufSize += i->second->GetSize()-avail;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   601
  }
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   602
  SocketAddressTag tag;
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   603
  tag.SetAddress (InetSocketAddress (m_remoteAddress, m_remotePort));
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   604
  outPacket->AddPacketTag (tag);
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   605
  return outPacket;
3131
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
TcpSocketImpl::GetRxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
  // We separately maintain this state to avoid walking the queue 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
  // every time this might be called
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
  return m_rxAvailable;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   617
Ptr<Packet>
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   618
TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   619
                         Address &fromAddress)
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   620
{
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   621
  NS_LOG_FUNCTION (this << maxSize << flags);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   622
  Ptr<Packet> packet = Recv (maxSize, flags);
4014
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   623
  //Null packet means no data to read, and an empty packet indicates EOF
b6349d9c007e Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3975
diff changeset
   624
  if (packet != 0 && packet->GetSize() != 0)
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   625
    {
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   626
      SocketAddressTag tag;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   627
      bool found;
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   628
      found = packet->PeekPacketTag (tag);
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   629
      NS_ASSERT (found);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   630
      fromAddress = tag.GetAddress ();
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   631
    }
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   632
  return packet;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   633
}
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   634
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   635
int
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   636
TcpSocketImpl::GetSockName (Address &address) const
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   637
{
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   638
  NS_LOG_FUNCTION_NOARGS ();
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   639
  address = InetSocketAddress(m_localAddress, m_localPort);
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   640
  return 0;
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   641
}
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   642
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
void
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   644
TcpSocketImpl::BindToNetDevice (Ptr<NetDevice> netdevice)
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   645
{
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   646
  NS_LOG_FUNCTION (netdevice);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   647
  Socket::BindToNetDevice (netdevice); // Includes sanity check
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   648
  if (m_endPoint == 0)
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   649
    {
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   650
      if (Bind () == -1)
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   651
       {
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   652
         NS_ASSERT (m_endPoint == 0);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   653
         return;
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   654
       }
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   655
      NS_ASSERT (m_endPoint != 0);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   656
    }
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   657
  m_endPoint->BindToNetDevice (netdevice);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   658
  return;
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   659
}
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   660
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   661
void
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
               " dport " << m_endPoint->GetLocalPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
               " daddr " << m_endPoint->GetLocalAddress() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
               " sport " << m_endPoint->GetPeerPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
               " saddr " << m_endPoint->GetPeerAddress());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
  if (m_shutdownRecv)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   676
  packet->RemoveHeader (tcpHeader);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   678
  if (tcpHeader.GetFlags () & TcpHeader::RST)
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   679
    { // Got an RST, just shut everything down
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   680
      NotifyErrorClose();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   681
      CancelAllTimers();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   682
      m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   683
      m_tcp->DeAllocate (m_endPoint);
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   684
      m_endPoint = 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   685
      return;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   686
    }
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   687
      
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   689
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   690
      Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
      if (m != Seconds (0.0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
          m_lastMeasuredRtt = m;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   697
  if (m_rxWindowSize == 0 && tcpHeader.GetWindowSize () != 0) 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   698
    { //persist probes end
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   699
      NS_LOG_LOGIC (this<<" Leaving zerowindow persist state");
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   700
      m_persistEvent.Cancel ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   701
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   702
  m_rxWindowSize = tcpHeader.GetWindowSize (); //update the flow control window
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   703
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
  Actions_t action = ProcessEvent (event); //updates the state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
  Address address = InetSocketAddress (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
  NS_LOG_DEBUG("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
               " processing pkt action, " << action <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
               " current state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
  ProcessPacketAction (action, packet, tcpHeader, address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
  NS_LOG_FUNCTION (this << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
  States_t saveState = m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " processing event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
  // 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
   719
  // class intended to be a singleton; see simulation-singleton.h
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
  SA stateAction = SimulationSingleton<TcpStateMachine>::Get ()->Lookup (m_state,e);
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   721
  NS_LOG_LOGIC ("TcpSocketImpl::ProcessEvent stateAction " << stateAction.action);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
  // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
  if (stateAction.action == RST_TX)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
              << saveState << " event " << e);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   727
      SendRST();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   728
      return NO_ACT;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
  bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
    && e != TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
  m_state = stateAction.state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " moved from state " << saveState 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
    << " to state " <<m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " pendingData " << m_pendingData);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
  //extra event logic is here for RX events
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
  //e = SYN_ACK_RX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
  if (saveState == SYN_SENT && m_state == ESTABLISHED)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
    // this means the application side has completed its portion of 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   741
    // the handshaking
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
      m_connected = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
    }
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   748
  if (saveState < CLOSING && (m_state == CLOSING || m_state == TIMED_WAIT) )
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   749
    {
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   750
      NS_LOG_LOGIC ("TcpSocketImpl peer closing, send EOF to application");
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   751
      NotifyDataRecv ();
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   752
    }
3131
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
  if (needCloseNotify && !m_closeNotified)
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
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
               << m_state << " event " << e << " closeNot " << m_closeNotified
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
               << " action " << stateAction.action);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   759
      NotifyNormalClose();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
              << " origState " << saveState
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
              << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
          << m_state << " event " << e
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
          << " set CloseNotif ");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
    }
4621
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   768
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   769
  if (m_state == CLOSED && saveState != CLOSED && m_endPoint != 0)
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   770
    {
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   771
      NS_ASSERT (m_tcp != 0);
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   772
      /*
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   773
       * We want to deallocate the endpoint now.  We can't just naively call
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   774
       * Deallocate (see the comment in TcpSocketImpl::~TcpSocketImpl), we 
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   775
       * have to turn off the DestroyCallback to keep it from calling back 
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   776
       * into TcpSocketImpl::Destroy and closing pretty much everything down.
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   777
       * Once we have the callback disconnected, we can DeAllocate the
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   778
       * endpoint which actually deals with destroying the actual endpoint,
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   779
       * and then zero our member varible on general principles.
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   780
       */
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   781
      m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   782
      m_tcp->DeAllocate (m_endPoint);
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   783
      m_endPoint = 0;
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   784
      CancelAllTimers();
4621
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   785
    }
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   786
    
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
  return stateAction.action;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
}
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
void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   792
  NS_LOG_FUNCTION (this << (uint32_t)flags);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
  Ptr<Packet> p = Create<Packet> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   794
  TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   795
4270
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   796
  if (flags & TcpHeader::FIN)
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   797
    {
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   798
      flags |= TcpHeader::ACK;
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   799
    }
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   800
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   801
  header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   802
  header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
  header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   804
  header.SetSourcePort (m_endPoint->GetLocalPort ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
  header.SetDestinationPort (m_remotePort);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   806
  header.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   807
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   808
    m_remoteAddress, m_boundnetdevice);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   809
  Time rto = m_rtt->RetransmitTimeout ();
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   810
  bool hasSyn = flags & TcpHeader::SYN;
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   811
  bool hasFin = flags & TcpHeader::FIN;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   812
  bool isAck = flags == TcpHeader::ACK;
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   813
  if (hasSyn)
3131
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
      rto = m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   816
      m_cnTimeout = m_cnTimeout + m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
      m_cnCount--;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   818
    }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   819
  if (m_retxEvent.IsExpired () && (hasSyn || hasFin) && !isAck )
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   820
  //no outstanding timer
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   821
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
    NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
    m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   827
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   829
// This function closes the endpoint completely
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   830
void TcpSocketImpl::SendRST()
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   831
{
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   832
  SendEmptyPacket(TcpHeader::RST);
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   833
  NotifyErrorClose();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   834
  CancelAllTimers();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   835
  m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   836
  m_tcp->DeAllocate (m_endPoint);
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   837
  m_endPoint = 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   838
}
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   839
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   840
  
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
bool TcpSocketImpl::ProcessAction (Actions_t a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
{ // These actions do not require a packet or any TCP Headers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   843
  NS_LOG_FUNCTION (this << a);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   845
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
    case NO_ACT:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   847
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action: NO_ACT");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   849
    case ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   850
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   851
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
    case RST_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RST_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
      SendEmptyPacket (TcpHeader::RST);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
    case SYN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
      // 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
   863
      // commented out for now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
      // m_nextTxSequence+= 1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
      SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
      ++m_nextRxSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
    case FIN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
      SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
    case FIN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
    case RETX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RETX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
    case TX_DATA:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action TX_DATA");
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
   892
      SendPendingData (m_connected);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action PEER_CLOSE");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
    case APP_CLOSED:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_CLOSED");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
    case CANCEL_TM:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action CANCEL_TM");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
    case APP_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
    case LAST_ACTION:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action LAST_ACTION");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
  return true;
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
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
                                     const TcpHeader& tcpHeader,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
                                     const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   920
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   923
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
  {
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   926
    case ACK_TX:
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   927
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX");
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   928
      if(tcpHeader.GetFlags() & TcpHeader::FIN)
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   929
      {
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   930
        ++m_nextRxSequence; //bump this to account for the FIN
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   931
      }
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   932
      SendEmptyPacket (TcpHeader::ACK);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   933
      break;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
      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
   937
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
          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
   939
          //notify the server that we got a SYN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
          // If server refuses connection do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
          if (!NotifyConnectionRequest(fromAddress)) return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
          // Clone the socket
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
          Ptr<TcpSocketImpl> newSock = Copy ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
          //this listening socket should do nothing more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
                                  p, tcpHeader,fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
        }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   950
        // This is the cloned endpoint
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   951
        m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   952
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   953
        // Look up the source address
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   954
        if (ipv4->GetRoutingProtocol () != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   955
          {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   956
            Ipv4Header header;
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   957
            Socket::SocketErrno errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   958
            Ptr<Ipv4Route> route;
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   959
            Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   960
            header.SetDestination (m_remoteAddress);
4603
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4567
diff changeset
   961
            route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   962
            if (route != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   963
              {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   964
                NS_LOG_LOGIC ("Route exists");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   965
                m_endPoint->SetLocalAddress (route->GetSource ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   966
              }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   967
            else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   968
              {
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   969
                NS_LOG_ERROR (errno_);
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   970
                m_errno = errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   971
                return -1;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   972
              }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   973
          }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   974
        else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   975
          {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   976
            NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   977
          }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   978
        // TCP SYN consumes one byte
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   979
        m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   980
        SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
      // TCP SYN consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
      m_nextTxSequence = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
                    " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
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
        m_highestRxAck = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
        // Data freed from the send buffer; notify any blocked sender
3327
ea16c44eb90d Apply Patch for Bug 237
Craig Dowell <craigdo@ee.washington.edu>
parents: 3291
diff changeset
   995
        if (GetTxAvailable () > 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
          {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
            NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
          }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
      }
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1000
      SendPendingData (m_connected); //send acks if we are connected
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_ACK_TX");
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1004
      //check to see of the ACK had data with it; if so, pass it along
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1005
      //to NEW_SEQ_RX
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1006
      if(p->GetSize () > 0)
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1007
        {
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1008
          Simulator::ScheduleNow(&TcpSocketImpl::ProcessPacketAction,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1009
                                 this,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1010
                                 NEW_SEQ_RX,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1011
                                 p,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1012
                                 tcpHeader,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1013
                                 fromAddress);
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1014
        }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1019
      if (tcpHeader.GetAckNumber () == m_highestRxAck)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1020
      {
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1021
        if (tcpHeader.GetAckNumber ()  < m_nextTxSequence)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1022
        {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1023
          DupAck (tcpHeader, ++m_dupAckCount);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1024
        }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1025
        NS_ASSERT(tcpHeader.GetAckNumber ()  <= m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1026
        //if the ack is precisely equal to the nextTxSequence
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1029
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
          m_dupAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
      NewAck (tcpHeader.GetAckNumber ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
      NewRx (p, tcpHeader, fromAddress); // Process new data received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
    {
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1041
      NS_LOG_LOGIC("Got Peer Close");
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
      // 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
  1043
      // out of sequence.  If so, note pending close and process
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
      // new sequence rx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1045
      if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1046
        { // process close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1047
          m_pendingClose = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1048
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1049
            << " rxseq " << tcpHeader.GetSequenceNumber () 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
            << " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1054
      // 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
  1055
      // if so, call NewRx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
      if (p->GetSize () != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1058
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
        }
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
  1060
      ++m_nextRxSequence; //bump this to account for the FIN
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
      States_t saveState = m_state; // Used to see if app responds
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
          << " peer close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1064
      if (!m_closeRequestNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1066
          NS_LOG_LOGIC ("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
              << " calling AppCloseRequest");
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1068
          NotifyNormalClose();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
          m_closeRequestNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1070
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
          << " peer close, state after " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1073
      if (m_state == saveState)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1074
        { // Need to ack, the application will close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1075
          SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1076
//               // Also need to re-tx the ack if we
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
      if (m_state == LAST_ACK)
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
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " scheduling LATO1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
          m_lastAckEvent = Simulator::Schedule (m_rtt->RetransmitTimeout (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
                                                &TcpSocketImpl::LastAckTimeout,this);
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
      break;
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
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
      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
  1090
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
      //treat the connection orientation final ack as a newack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1092
      CommonNewAck (tcpHeader.GetAckNumber (), true);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1093
      NotifyNewConnectionCreated (this, fromAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1095
    default:
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
  1096
      return ProcessAction (a);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1097
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1098
  return true;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
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
  1102
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1103
  // Get port and address from peer (connecting host)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1104
  m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1105
  m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
  m_endPoint = m_tcp->Allocate (m_localAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1107
                                m_localPort,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1108
                                m_remoteAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
                                m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1110
  //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
  1111
  m_state = SYN_RCVD;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1112
  //equivalent to FinishBind
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1113
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1114
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1116
 }
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
void TcpSocketImpl::ConnectionSucceeded()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1119
{ // We would preferred to have scheduled an event directly to
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
  // NotifyConnectionSucceeded, but (sigh) these are protected
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1121
  // and we can get the address of it :(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1122
  NotifyConnectionSucceeded();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1123
}
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
bool TcpSocketImpl::SendPendingData (bool withAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1127
  NS_LOG_FUNCTION (this << withAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
  NS_LOG_LOGIC ("ENTERING SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1130
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1131
      return false; // No data exists
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1132
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
  uint32_t nPacketsSent = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
  while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1135
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1136
      uint32_t w = AvailableWindow ();// Get available window size
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1137
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " SendPendingData"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1138
           << " w " << w 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1139
           << " rxwin " << m_rxWindowSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1140
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1141
           << " segsize " << m_segmentSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
           << " nextTxSeq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
           << " highestRxAck " << m_highestRxAck 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
           << " pd->Size " << m_pendingData->Size ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1145
           << " pd->SFS " << m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence));
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1146
//XXX pd->Size is probably a bug, should be SizeFromSeq(...)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
      if (w < m_segmentSize && m_pendingData->Size () > w)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
          break; // No more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
      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
  1152
      Ptr<Packet> p = m_pendingData->CopyFromSeq (s, m_firstPendingSequence, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
        m_nextTxSequence);
3246
d734f62d4921 Change log output to be more consistent
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3245
diff changeset
  1154
      NS_LOG_LOGIC("TcpSocketImpl " << this << " SendPendingData"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1155
                   << " txseq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
                   << " s " << s 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
                   << " datasize " << p->GetSize() );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
      uint8_t flags = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1159
      uint32_t sz = p->GetSize (); // Size of packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
      uint32_t remainingData = m_pendingData->SizeFromSeq(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1161
          m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1162
          m_nextTxSequence + SequenceNumber (sz));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
      if (m_closeOnEmpty && (remainingData == 0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1164
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1165
          flags = TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
          m_state = FIN_WAIT_1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1167
        }
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1168
      if (withAck)
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1169
        {
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1170
          flags |= TcpHeader::ACK;
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1171
        }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1172
      TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1173
      header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1174
      header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1175
      header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1176
      header.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1177
      header.SetDestinationPort (m_remotePort);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1178
      header.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1179
      if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1180
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1181
          m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1182
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1183
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1184
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1185
      
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1186
      if (m_retxEvent.IsExpired () ) //go ahead and schedule the retransmit
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1187
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1188
            Time rto = m_rtt->RetransmitTimeout (); 
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1189
            NS_LOG_LOGIC (this<<" SendPendingData Schedule ReTxTimeout at time " << 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1190
              Simulator::Now ().GetSeconds () << " to expire at time " <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1191
              (Simulator::Now () + rto).GetSeconds () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1192
          m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1193
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1194
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1195
      m_tcp->SendPacket (p, header,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1196
                         m_endPoint->GetLocalAddress (),
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
  1197
                         m_remoteAddress, m_boundnetdevice);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1198
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1199
      // Notify the application of the data being sent
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1200
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1201
      nPacketsSent++;                             // Count sent this loop
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1202
      m_nextTxSequence += sz;                     // Advance next tx sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1203
      // Note the high water mark
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1204
      m_highTxMark = std::max (m_nextTxSequence, m_highTxMark);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1205
    }
3246
d734f62d4921 Change log output to be more consistent
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3245
diff changeset
  1206
    NS_LOG_LOGIC ("SendPendingData Sent "<<nPacketsSent<<" packets");
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1207
  NS_LOG_LOGIC("RETURN SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1208
  return (nPacketsSent>0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1209
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1210
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1211
uint32_t  TcpSocketImpl::UnAckDataCount ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1212
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1213
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1214
  return m_nextTxSequence - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1215
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1216
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1217
uint32_t  TcpSocketImpl::BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1218
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1219
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1220
  return m_highTxMark - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1221
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1222
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1223
uint32_t  TcpSocketImpl::Window ()
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1226
  NS_LOG_LOGIC ("TcpSocketImpl::Window() "<<this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1227
  return std::min (m_rxWindowSize, m_cWnd.Get());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1228
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1229
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1230
uint32_t  TcpSocketImpl::AvailableWindow ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1231
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1232
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1233
  uint32_t unack = UnAckDataCount (); // Number of outstanding bytes
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1234
  uint32_t win = Window ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1235
  if (win < unack) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1236
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1237
      return 0;  // No space available
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
  return (win - unack);       // Amount of window space available
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1240
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1241
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1242
uint32_t TcpSocketImpl::RxBufferFreeSpace()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1243
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1244
  return m_rxBufMaxSize - m_rxBufSize;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1245
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1246
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1247
uint16_t TcpSocketImpl::AdvertisedWindowSize()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1248
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1249
  uint32_t max = 0xffff;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1250
  return std::min(RxBufferFreeSpace(), max);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1251
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1252
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1253
void TcpSocketImpl::NewRx (Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
                        const TcpHeader& tcpHeader, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
                        const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1258
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1259
                << " seq " << tcpHeader.GetSequenceNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
                << " ack " << tcpHeader.GetAckNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1261
                << " p.size is " << p->GetSize () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1262
  States_t origState = m_state;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1263
  if (RxBufferFreeSpace() < p->GetSize()) 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1264
    { //if not enough room, fragment
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1265
      p = p->CreateFragment(0, RxBufferFreeSpace());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1266
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1267
  //XXX
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1268
  //fragmenting here MIGHT not be the right thing to do, since possibly we trim
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1269
  //the front and back off the packet below if it isn't all new data, so the 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1270
  //check against RxBufferFreeSpace and fragmentation should ideally occur
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1271
  //just before insertion into m_bufferedData, but this strategy is more
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1272
  //agressive in rejecting oversized packets and still gives acceptable TCP
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1273
  uint32_t s = p->GetSize ();  // Size of associated data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1274
  if (s == 0)
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1275
    {//if there is no data or no rx buffer space, just ack anyway
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1276
      SendEmptyPacket (TcpHeader::ACK);
3131
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
  // Log sequence received if enabled
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1280
  // NoteTimeSeq(LOG_SEQ_RX, h->sequenceNumber);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1281
  // Three possibilities
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1282
  // 1) Received seq is expected, buffer this, update rxAvailable, and ack
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1283
  // 2) Received seq is < expected, just re-ack previous
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1284
  // 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
  1285
  if (tcpHeader.GetSequenceNumber () == m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1286
    { // If seq is expected seq
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1287
      // Trim the end if necessary
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1288
      // 1) Update nextRxSeq
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1289
      // 2) Buffer this packet so Recv can read it
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1290
      // 3) Send the ack
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1291
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1292
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1293
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1294
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1295
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1296
        {//tail end isn't all new, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1297
          s = nextBufferedSeq - m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1298
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1299
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1300
      p = p->CreateFragment (0,s);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1301
      m_nextRxSequence += s;           // Advance next expected sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1302
      NS_LOG_LOGIC("Case 1, advanced nrxs to " << m_nextRxSequence );
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1303
      //buffer this, it'll be read by call to Recv
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1304
      UnAckData_t::iterator i = 
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1305
          m_bufferedData.find (tcpHeader.GetSequenceNumber () );
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1306
      NS_ASSERT(i == m_bufferedData.end ()); //no way it should have been found
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1307
      // Save for later delivery if there is room
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1308
      m_bufferedData[tcpHeader.GetSequenceNumber () ] = p;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1309
      m_rxAvailable += p->GetSize ();
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1310
      RxBufFinishInsert (tcpHeader.GetSequenceNumber ());
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1311
      m_rxBufSize += p->GetSize ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
      NotifyDataRecv ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
      if (m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1314
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1315
          NS_LOG_LOGIC ("Tcp " << this << " HuH?  Got data after closeNotif");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1316
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1317
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq by " << s);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1318
      if (m_pendingClose || (origState > ESTABLISHED))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1319
        { // See if we can close now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1320
          if (m_bufferedData.empty())
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1321
            {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1322
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1323
            }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1324
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1325
    }
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1326
  else if (tcpHeader.GetSequenceNumber () > m_nextRxSequence)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1327
    { // Need to buffer this one, but trim off the front and back if necessary
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1328
      NS_LOG_LOGIC ("Case 2, buffering " << tcpHeader.GetSequenceNumber () );
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1329
      UnAckData_t::iterator previous =
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1330
          m_bufferedData.lower_bound (tcpHeader.GetSequenceNumber ());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1331
      SequenceNumber startSeq = tcpHeader.GetSequenceNumber();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1332
      if (previous != m_bufferedData.begin ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1333
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1334
          --previous;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1335
          startSeq = previous->first + SequenceNumber(previous->second->GetSize());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1336
          if (startSeq > tcpHeader.GetSequenceNumber ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1337
            {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1338
              s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - startSeq;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1339
            }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1340
          else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1341
            {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1342
              startSeq = tcpHeader.GetSequenceNumber();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1343
            }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1344
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1345
      //possibly trim off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1346
      UnAckData_t::iterator next = m_bufferedData.upper_bound (tcpHeader.GetSequenceNumber());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1347
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1348
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1349
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1350
        if (startSeq + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1351
        {//tail end isn't all new either, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1352
          s = nextBufferedSeq - startSeq;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1353
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1354
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1355
      p = p->CreateFragment (startSeq - tcpHeader.GetSequenceNumber (),s);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1356
      UnAckData_t::iterator i = 
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1357
          m_bufferedData.find (startSeq);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1358
      if (i != m_bufferedData.end () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1359
        {
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1360
          if(p->GetSize() > i->second->GetSize())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1361
          {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1362
            i->second = 0; // relase reference to already buffered
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1363
          }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1364
          else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1365
          {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1366
            p = i->second;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1367
          }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1368
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1369
      // Save for later delivery
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1370
      m_bufferedData[startSeq] = p;  
5378
7bc9c7bd4d8f Fix for bug 647
Josh Pelkey <jpelkey@gatech.edu>
parents: 5377
diff changeset
  1371
      m_rxBufSize += p->GetSize();
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1372
      i = m_bufferedData.find (startSeq);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1373
      next = i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1374
      ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1375
      if(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1376
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1377
          NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1378
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1379
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1380
  else if (tcpHeader.GetSequenceNumber () + SequenceNumber(s) > m_nextRxSequence)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1381
    {//parial new data case, only part of the packet is new data
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1382
      //trim the beginning
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1383
      s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - m_nextRxSequence; //how much new
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1384
      //possibly trim off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1385
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1386
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1387
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1388
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1389
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1390
        {//tail end isn't all new either, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1391
          s = nextBufferedSeq - m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1392
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1393
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1394
      p = p->CreateFragment (m_nextRxSequence - tcpHeader.GetSequenceNumber (),s);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1395
      SequenceNumber start = m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1396
      m_nextRxSequence += s;           // Advance next expected sequence
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1397
      //buffer the new fragment, it'll be read by call to Recv
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1398
      UnAckData_t::iterator i = m_bufferedData.find (start);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1399
      if (i != m_bufferedData.end () ) //we found it already in the buffer
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1400
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1401
          i->second = 0; // relase reference to already buffered
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1402
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1403
      // Save for later delivery
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1404
      m_bufferedData[start] = p;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1405
      m_rxAvailable += p->GetSize ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1406
      m_rxBufSize += p->GetSize();
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1407
      RxBufFinishInsert(start);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1408
      NotifyDataRecv ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1409
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1410
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1411
    { // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1412
      NS_LOG_LOGIC("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1413
               << " got seq " << tcpHeader.GetSequenceNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1414
               << " expected " << m_nextRxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1415
               << "       flags " << tcpHeader.GetFlags ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1416
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1417
  // 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
  1418
  if(++m_delAckCount >= m_delAckMaxCount)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1419
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1420
    m_delAckEvent.Cancel();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1421
    m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1422
    SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1423
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1424
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1425
  {
3975
7a636112d9cd Support TCP delackcount>2 (bug 250)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3966
diff changeset
  1426
    if (m_delAckEvent.IsExpired())
7a636112d9cd Support TCP delackcount>2 (bug 250)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3966
diff changeset
  1427
    {
7a636112d9cd Support TCP delackcount>2 (bug 250)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3966
diff changeset
  1428
      m_delAckEvent = Simulator::Schedule (m_delAckTimeout, &TcpSocketImpl::DelAckTimeout, this);
7a636112d9cd Support TCP delackcount>2 (bug 250)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3966
diff changeset
  1429
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1430
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1431
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1432
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1433
void TcpSocketImpl::RxBufFinishInsert (SequenceNumber seq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1434
{
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1435
  //putting data into the buffer might have filled in a sequence gap so we have
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1436
  //to iterate through the list to find the largest contiguous sequenced chunk,
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1437
  //and update m_rxAvailable and m_nextRxSequence appropriately
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1438
  UnAckData_t::iterator i = m_bufferedData.find (seq);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1439
  UnAckData_t::iterator next = i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1440
  ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1441
  //make sure the buffer is logically sequenced
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1442
  if(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1443
  {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1444
    NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1445
  }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1446
  while(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1447
  {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1448
    if(i->first + SequenceNumber(i->second->GetSize ()) == next->first)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1449
    {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1450
      //next packet is in sequence, count it
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1451
      m_rxAvailable += next->second->GetSize();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1452
      m_nextRxSequence += next->second->GetSize();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1453
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1454
    else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1455
    {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1456
      break; //no more in this contiguous chunk
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1457
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1458
    ++i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1459
    ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1460
  }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1461
}
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1462
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1463
void TcpSocketImpl::DelAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1464
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1465
  m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1466
  SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1467
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1468
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1469
void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1470
{ // CommonNewAck is called only for "New" (non-duplicate) acks
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1471
  // and MUST be called by any subclass, from the NewAck function
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1472
  // Always cancel any pending re-tx timer on new acknowledgement
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1473
  NS_LOG_FUNCTION (this << ack << skipTimer); 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1474
  if (!skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1475
    {
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1476
      NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1477
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1478
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1479
      m_retxEvent.Cancel ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1480
      //On recieving a "New" ack we restart retransmission timer .. RFC 2988
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1481
      Time rto = m_rtt->RetransmitTimeout ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1482
      NS_LOG_LOGIC (this<<" Schedule ReTxTimeout at time " 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1483
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1484
          << (Simulator::Now () + rto).GetSeconds ());
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1485
      m_retxEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1486
          Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1487
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1488
  if (m_rxWindowSize == 0 && m_persistEvent.IsExpired ()) //zerowindow
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1489
    {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1490
      NS_LOG_LOGIC (this<<"Enter zerowindow persist state");
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1491
      NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1492
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1493
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1494
      m_retxEvent.Cancel ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1495
      NS_LOG_LOGIC ("Schedule persist timeout at time " 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1496
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1497
                    << (Simulator::Now () + m_persistTime).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1498
      m_persistEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1499
      Simulator::Schedule (m_persistTime, &TcpSocketImpl::PersistTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1500
      NS_ASSERT (m_persistTime == Simulator::GetDelayLeft (m_persistEvent));
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1501
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1502
  NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1503
           << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1504
  m_highestRxAck = ack;         // Note the highest recieved Ack
3327
ea16c44eb90d Apply Patch for Bug 237
Craig Dowell <craigdo@ee.washington.edu>
parents: 3291
diff changeset
  1505
  if (GetTxAvailable () > 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1506
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1507
      NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1508
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1509
  if (ack > m_nextTxSequence) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1510
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1511
      m_nextTxSequence = ack; // If advanced
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1512
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1513
  // 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
  1514
  if (m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1515
    { // Data exists, see if can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1516
      if (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck) == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1517
        { // All pending acked, can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1518
          m_pendingData->Clear ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1519
          delete m_pendingData;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1520
          m_pendingData = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1521
          // Insure no re-tx timer
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1522
          NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1523
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1524
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1525
          m_retxEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1526
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1527
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1528
  // Try to send more data
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1529
  SendPendingData (m_connected);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1530
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1531
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1532
void TcpSocketImpl::CancelAllTimers()
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1533
{
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1534
  m_retxEvent.Cancel ();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1535
  m_persistEvent.Cancel ();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1536
  m_delAckEvent.Cancel();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1537
  m_lastAckEvent.Cancel ();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1538
}
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1539
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1540
Ptr<TcpSocketImpl> TcpSocketImpl::Copy ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1541
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1542
  return CopyObject<TcpSocketImpl> (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1543
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1544
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1545
void TcpSocketImpl::NewAck (SequenceNumber seq)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1546
{ // New acknowledgement up to sequence number "seq"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1547
  // Adjust congestion window in response to new ack's received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1548
  NS_LOG_FUNCTION (this << seq);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1549
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewAck "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1550
           << " seq " << seq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1551
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1552
           << " ssThresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1553
  if (m_cWnd < m_ssThresh)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1554
    { // Slow start mode, add one segSize to cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1555
      m_cWnd += m_segmentSize;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1556
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewCWnd SlowStart, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1557
          << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1558
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1559
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1560
    { // Congestion avoidance mode, adjust by (ackBytes*segSize) / cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1561
      double adder =  ((double) m_segmentSize * m_segmentSize) / m_cWnd.Get();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1562
      if (adder < 1.0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1563
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1564
          adder = 1.0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1565
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1566
      m_cWnd += (uint32_t) adder;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1567
      NS_LOG_LOGIC ("NewCWnd CongAvoid, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1568
           << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1569
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1570
  CommonNewAck (seq, false);           // Complete newAck processing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1571
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1572
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1573
void TcpSocketImpl::DupAck (const TcpHeader& t, uint32_t count)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1574
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1575
  NS_LOG_FUNCTION (this << "t " << count);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1576
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " DupAck " <<  t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1577
      << ", count " << count
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1578
      << ", time " << Simulator::Now ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1579
  if (count == 3)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1580
  { // Count of three indicates triple duplicate ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1581
    m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1582
    m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1583
    NS_LOG_LOGIC("TcpSocketImpl " << this << "Tahoe TDA, time " << Simulator::Now ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1584
        << " seq " << t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1585
        << " in flight " << BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1586
        << " new ssthresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1587
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1588
    m_cWnd = m_segmentSize; // Collapse cwnd (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1589
    // For Tahoe, we also reset nextTxSeq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1590
    m_nextTxSequence = m_highestRxAck;
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1591
    SendPendingData (m_connected);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1592
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1593
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1594
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1595
void TcpSocketImpl::ReTxTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1596
{ // Retransmit timeout
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1597
  NS_LOG_FUNCTION (this);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1598
  NS_LOG_LOGIC (this<<" ReTxTimeout Expired at time "<<Simulator::Now ().GetSeconds());
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1599
  // If erroneous timeout in closed/timed-wait state, just return
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1600
  if (m_state == CLOSED || m_state == TIMED_WAIT) return;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1601
  
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1602
  m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1603
  m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1604
  // Set cWnd to segSize on timeout,  per rfc2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1605
  // Collapse congestion window (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1606
  m_cWnd = m_segmentSize;           
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1607
  m_nextTxSequence = m_highestRxAck; // Start from highest Ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1608
  m_rtt->IncreaseMultiplier (); // DoubleValue timeout value for next retx timer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1609
  Retransmit ();             // Retransmit the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1610
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1611
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1612
void TcpSocketImpl::LastAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1613
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1614
  m_lastAckEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1615
  if (m_state == LAST_ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1616
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1617
      Actions_t action = ProcessEvent (TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1618
      ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1619
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1620
  if (!m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1621
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1622
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1623
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1624
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1625
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1626
void TcpSocketImpl::PersistTimeout ()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1627
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1628
  NS_LOG_LOGIC ("PersistTimeout expired at "<<Simulator::Now ().GetSeconds ());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1629
  m_persistTime = Scalar(2)*m_persistTime;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1630
  m_persistTime = std::min(Seconds(60),m_persistTime); //maxes out at 60
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1631
  //the persist timeout sends exactly one byte probes
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1632
  //this is explicit in stevens, and kind of in rfc793 p42, rfc1122 sec4.2.2.17
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1633
  Ptr<Packet> p =
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1634
    m_pendingData->CopyFromSeq(1,m_firstPendingSequence,m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1635
  TcpHeader tcpHeader;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1636
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1637
  tcpHeader.SetAckNumber (m_nextRxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1638
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1639
  tcpHeader.SetDestinationPort (m_remotePort);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1640
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1641
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1642
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
  1643
    m_remoteAddress, m_boundnetdevice);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1644
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1645
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1646
                    << (Simulator::Now () + m_persistTime).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1647
  m_persistEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1648
    Simulator::Schedule (m_persistTime, &TcpSocketImpl::PersistTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1649
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1650
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1651
void TcpSocketImpl::Retransmit ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1652
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1653
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1654
  uint8_t flags = TcpHeader::NONE;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1655
  if (m_state == SYN_SENT) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1656
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1657
      if (m_cnCount > 0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1658
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1659
          SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1660
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1661
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1662
      else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1663
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1664
          NotifyConnectionFailed ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1665
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1666
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1667
    } 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1668
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1669
    {
3276
8869a79a391f Changes for bug 205, unlisted FIN bug
Craig Dowell <craigdo@ee.washington.edu>
parents: 3272
diff changeset
  1670
      if (m_state == FIN_WAIT_1)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1671
        { // Must have lost FIN, re-send
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1672
          SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1673
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1674
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1675
    }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1676
  NS_ASSERT(m_nextTxSequence == m_highestRxAck);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1677
  Ptr<Packet> p = m_pendingData->CopyFromSeq (m_segmentSize,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1678
                                            m_firstPendingSequence,
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1679
                                            m_nextTxSequence);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1680
  // Calculate remaining data for COE check
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1681
  uint32_t remainingData = m_pendingData->SizeFromSeq (
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1682
      m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1683
      m_nextTxSequence + SequenceNumber(p->GetSize ()));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1684
  if (m_closeOnEmpty && remainingData == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1685
    { // Add the FIN flag
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1686
      flags = flags | TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1687
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1688
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1689
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " retxing seq " << m_highestRxAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1690
  if (m_retxEvent.IsExpired () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1691
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1692
      Time rto = m_rtt->RetransmitTimeout ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1693
      NS_LOG_LOGIC (this<<" Schedule ReTxTimeout at time "
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1694
          << Simulator::Now ().GetSeconds () << " to expire at time "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1695
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1696
      m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1697
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1698
  m_rtt->SentSeq (m_highestRxAck,p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1699
  // And send the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1700
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1701
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1702
  tcpHeader.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1703
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1704
  tcpHeader.SetDestinationPort (m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1705
  tcpHeader.SetFlags (flags);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1706
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1707
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1708
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
  1709
    m_remoteAddress, m_boundnetdevice);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1710
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1711
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1712
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1713
TcpSocketImpl::SetSndBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1714
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1715
  m_sndBufSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1716
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1717
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1718
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1719
TcpSocketImpl::GetSndBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1720
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1721
  return m_sndBufSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1722
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1723
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1724
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1725
TcpSocketImpl::SetRcvBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1726
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1727
  m_rxBufMaxSize = size;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1728
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1729
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1730
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1731
TcpSocketImpl::GetRcvBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1732
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1733
  return m_rxBufMaxSize;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1734
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1735
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1736
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1737
TcpSocketImpl::SetSegSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1738
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1739
  m_segmentSize = size;
4622
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1740
  /*
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1741
   * Make sure that the congestion window is initialized for IW properly.  We
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1742
   * can't do this after the connection starts up or would would most likely 
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1743
   * change m_cWnd out from under the protocol.  That would be Bad (TM).
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1744
   */
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1745
  NS_ABORT_MSG_UNLESS (m_state == CLOSED, "TcpSocketImpl::SetSegSize(): Cannot change segment size dynamically.");
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1746
  m_cWnd = m_initialCWnd * m_segmentSize;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1747
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1748
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1749
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1750
TcpSocketImpl::GetSegSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1751
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1752
  return m_segmentSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1753
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1754
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1755
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1756
TcpSocketImpl::SetSSThresh (uint32_t threshold)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1757
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1758
  m_ssThresh = threshold;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1759
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1760
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1761
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1762
TcpSocketImpl::GetSSThresh (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1763
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1764
  return m_ssThresh;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1765
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1766
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1767
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1768
TcpSocketImpl::SetInitialCwnd (uint32_t cwnd)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1769
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1770
  m_initialCWnd = cwnd;
4622
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1771
  /*
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1772
   * Make sure that the congestion window is initialized for IW properly.  We
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1773
   * can't do this after the connection starts up or would would most likely 
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1774
   * change m_cWnd out from under the protocol.  That would be Bad (TM).
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1775
   */
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1776
  NS_ABORT_MSG_UNLESS (m_state == CLOSED, "TcpSocketImpl::SetInitialCwnd(): Cannot change initial cwnd dynamically.");
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
  1777
  m_cWnd = m_initialCWnd * m_segmentSize;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1778
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1779
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1780
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1781
TcpSocketImpl::GetInitialCwnd (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1782
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1783
  return m_initialCWnd;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1784
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1785
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1786
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1787
TcpSocketImpl::SetConnTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1788
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1789
  m_cnTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1790
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1791
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1792
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1793
TcpSocketImpl::GetConnTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1794
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1795
  return m_cnTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1796
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1797
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1798
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1799
TcpSocketImpl::SetConnCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1800
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1801
  m_cnCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1802
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1803
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1804
uint32_t 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1805
TcpSocketImpl::GetConnCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1806
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1807
  return m_cnCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1808
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1809
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1810
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1811
TcpSocketImpl::SetDelAckTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1812
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1813
  m_delAckTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1814
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1815
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1816
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1817
TcpSocketImpl::GetDelAckTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1818
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1819
  return m_delAckTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1820
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1821
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1822
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1823
TcpSocketImpl::SetDelAckMaxCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1824
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1825
  m_delAckMaxCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1826
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1827
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1828
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1829
TcpSocketImpl::GetDelAckMaxCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1830
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1831
  return m_delAckMaxCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1832
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1833
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1834
}//namespace ns3
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1835
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1836